CatStation/Content.Client/Trigger/Systems/TimerTriggerVisualizerSystem.cs
Whatstone d9ffbf1d03
Cleanup: AppearanceSystem.TryGetData to AppearanceChangeEvent.TryGetData (#45373)
* First impl. of appearance TryGetData cleanup

* Handful of fixes

* DamageVisuals: fix HandleDamage call, inheritdoc

* bunch of unused AppearanceSystem instances

* Handful more unused appearance systems, inheritdoc

* JetpackSystem: Ent<T>

* cleanup roundup, more Ent<T>

* a few lingering AppearanceSystem.TryGetData calls

* more lingering AppearanceData access

* Remove unnecessary inheritdoc

* once again, with feeling
2026-10-05 00:45:37 +00:00

66 lines
2.3 KiB
C#

using Content.Client.Trigger.Components;
using Content.Shared.Trigger;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Audio.Systems;
namespace Content.Client.Trigger.Systems;
public sealed partial class TimerTriggerVisualizerSystem : VisualizerSystem<TimerTriggerVisualsComponent>
{
[Dependency] private SharedAudioSystem _audioSystem = default!;
[SubscribeLocalEvent]
private void OnComponentInit(Entity<TimerTriggerVisualsComponent> ent, ref ComponentInit args)
{
ent.Comp.PrimingAnimation = new Animation
{
Length = TimeSpan.MaxValue,
AnimationTracks = {
new AnimationTrackSpriteFlick()
{
LayerKey = TriggerVisualLayers.Base,
KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame(ent.Comp.PrimingSprite, 0f) }
}
},
};
if (ent.Comp.PrimingSound != null)
{
ent.Comp.PrimingAnimation.AnimationTracks.Add(
new AnimationTrackPlaySound()
{
KeyFrames = { new AnimationTrackPlaySound.KeyFrame(_audioSystem.ResolveSound(ent.Comp.PrimingSound), 0, () => ent.Comp.PrimingSound.Params) }
}
);
}
}
protected override void OnAppearanceChange(EntityUid uid, TimerTriggerVisualsComponent comp, ref AppearanceChangeEvent args)
{
if (args.Sprite == null
|| !TryComp<AnimationPlayerComponent>(uid, out var animPlayer))
return;
if (!args.TryGetData<TriggerVisualState>(TriggerVisuals.VisualState, out var state))
state = TriggerVisualState.Unprimed;
switch (state)
{
case TriggerVisualState.Primed:
if (!AnimationSystem.HasRunningAnimation(uid, animPlayer, TimerTriggerVisualsComponent.AnimationKey))
AnimationSystem.Play((uid, animPlayer), comp.PrimingAnimation, TimerTriggerVisualsComponent.AnimationKey);
break;
case TriggerVisualState.Unprimed:
SpriteSystem.LayerSetRsiState((uid, args.Sprite), TriggerVisualLayers.Base, comp.UnprimedSprite);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
public enum TriggerVisualLayers : byte
{
Base
}