Files
tbd-station-14/Content.Client/Light/EntitySystems/LightBehaviorSystem.cs
Pieter-Jan Briers 8d015f5c9f Fix animation looping bugs. (#29457)
Summary of the problem is in the corresponding engine commit: a4ea5a4620

This commit requires engine master right now.

I think #29144 is probably the most severe one, but I touched Jittering and RotatingLight too since they seemed sus too.

Fixes #29144

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2024-07-04 18:02:43 +10:00

59 lines
1.9 KiB
C#

using System.Linq;
using Content.Client.Light.Components;
using Robust.Client.GameObjects;
using Robust.Shared.Random;
namespace Content.Client.Light.EntitySystems;
public sealed class LightBehaviorSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AnimationPlayerSystem _player = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<LightBehaviourComponent, ComponentStartup>(OnLightStartup);
SubscribeLocalEvent<LightBehaviourComponent, AnimationCompletedEvent>(OnBehaviorAnimationCompleted);
}
private void OnBehaviorAnimationCompleted(EntityUid uid, LightBehaviourComponent component, AnimationCompletedEvent args)
{
if (!args.Finished)
return;
var container = component.Animations.FirstOrDefault(x => x.FullKey == args.Key);
if (container == null)
{
return;
}
if (container.LightBehaviour.IsLooped)
{
container.LightBehaviour.UpdatePlaybackValues(container.Animation);
_player.Play(uid, container.Animation, container.FullKey);
}
}
private void OnLightStartup(EntityUid uid, LightBehaviourComponent component, ComponentStartup args)
{
// TODO: Do NOT ensure component here. And use eventbus events instead...
EnsureComp<AnimationPlayerComponent>(uid);
foreach (var container in component.Animations)
{
container.LightBehaviour.Initialize(uid, _random, EntityManager);
}
// we need to initialize all behaviours before starting any
foreach (var container in component.Animations)
{
if (container.LightBehaviour.Enabled)
{
component.StartLightBehaviour(container.LightBehaviour.ID);
}
}
}
}