2021-03-10 14:48:29 +01:00
|
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Foam;
|
2021-02-03 11:26:46 -03:00
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
using Robust.Client.Animations;
|
|
|
|
|
|
using Robust.Client.GameObjects;
|
2021-11-22 23:22:59 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-05 18:09:01 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
2021-02-03 11:26:46 -03:00
|
|
|
|
using Robust.Shared.Maths;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-02-03 11:26:46 -03:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Chemistry.Visualizers
|
2021-02-03 11:26:46 -03:00
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class FoamVisualizer : AppearanceVisualizer, ISerializationHooks
|
2021-02-03 11:26:46 -03:00
|
|
|
|
{
|
|
|
|
|
|
private const string AnimationKey = "foamdissolve_animation";
|
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("animationTime")]
|
|
|
|
|
|
private float _delay = 0.6f;
|
2021-02-03 11:26:46 -03:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("animationState")]
|
|
|
|
|
|
private string _state = "foam-dissolve";
|
2021-02-03 11:26:46 -03:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
private Animation _foamDissolve = new();
|
2021-02-03 11:26:46 -03:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
void ISerializationHooks.AfterDeserialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
_foamDissolve = new Animation {Length = TimeSpan.FromSeconds(_delay)};
|
2021-02-03 11:26:46 -03:00
|
|
|
|
var flick = new AnimationTrackSpriteFlick();
|
|
|
|
|
|
_foamDissolve.AnimationTracks.Add(flick);
|
|
|
|
|
|
flick.LayerKey = FoamVisualLayers.Base;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(_state, 0f));
|
2021-02-03 11:26:46 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnChangeData(component);
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
var entities = IoCManager.Resolve<IEntityManager>();
|
2021-02-03 11:26:46 -03:00
|
|
|
|
if (component.TryGetData<bool>(FoamVisuals.State, out var state))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (state)
|
|
|
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (entities.TryGetComponent(component.Owner, out AnimationPlayerComponent? animPlayer))
|
2021-02-03 11:26:46 -03:00
|
|
|
|
{
|
|
|
|
|
|
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
|
|
|
|
|
animPlayer.Play(_foamDissolve, AnimationKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (component.TryGetData<Color>(FoamVisuals.Color, out var color))
|
|
|
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite))
|
2021-02-03 11:26:46 -03:00
|
|
|
|
{
|
|
|
|
|
|
sprite.Color = color;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum FoamVisualLayers : byte
|
|
|
|
|
|
{
|
|
|
|
|
|
Base
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|