Re-organize all projects (#4166)
This commit is contained in:
64
Content.Client/Chemistry/Visualizers/FoamVisualizer.cs
Normal file
64
Content.Client/Chemistry/Visualizers/FoamVisualizer.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using Content.Shared.Foam;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Chemistry.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class FoamVisualizer : AppearanceVisualizer, ISerializationHooks
|
||||
{
|
||||
private const string AnimationKey = "foamdissolve_animation";
|
||||
|
||||
[DataField("animationTime")]
|
||||
private float _delay = 0.6f;
|
||||
|
||||
[DataField("animationState")]
|
||||
private string _state = "foam-dissolve";
|
||||
|
||||
private Animation _foamDissolve = new();
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
_foamDissolve = new Animation {Length = TimeSpan.FromSeconds(_delay)};
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
_foamDissolve.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = FoamVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(_state, 0f));
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (component.TryGetData<bool>(FoamVisuals.State, out var state))
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
if (component.Owner.TryGetComponent(out AnimationPlayerComponent? animPlayer))
|
||||
{
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
animPlayer.Play(_foamDissolve, AnimationKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (component.TryGetData<Color>(FoamVisuals.Color, out var color))
|
||||
{
|
||||
if (component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
||||
{
|
||||
sprite.Color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum FoamVisualLayers : byte
|
||||
{
|
||||
Base
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user