]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Resolves VaporVisualizer is Obsolete (#13882)
authorTemporalOroboros <TemporalOroboros@gmail.com>
Tue, 7 Feb 2023 20:46:49 +0000 (12:46 -0800)
committerGitHub <noreply@github.com>
Tue, 7 Feb 2023 20:46:49 +0000 (16:46 -0400)
Content.Client/Chemistry/Visualizers/VaporVisualizer.cs [deleted file]
Content.Client/Chemistry/Visualizers/VaporVisualizerSystem.cs [new file with mode: 0644]
Content.Client/Chemistry/Visualizers/VaporVisualsComponent.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml
Resources/Prototypes/Entities/Objects/Specific/Janitorial/spray.yml

diff --git a/Content.Client/Chemistry/Visualizers/VaporVisualizer.cs b/Content.Client/Chemistry/Visualizers/VaporVisualizer.cs
deleted file mode 100644 (file)
index 3b40a17..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-using System;
-using Content.Shared.Vapor;
-using JetBrains.Annotations;
-using Robust.Client.Animations;
-using Robust.Client.GameObjects;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Maths;
-using Robust.Shared.Serialization;
-using Robust.Shared.Serialization.Manager.Attributes;
-
-namespace Content.Client.Chemistry.Visualizers
-{
-    [UsedImplicitly]
-    public sealed class VaporVisualizer : AppearanceVisualizer, ISerializationHooks
-    {
-        private const string AnimationKey = "flick_animation";
-
-        [DataField("animation_time")]
-        private float _delay = 0.25f;
-
-        [DataField("animation_state")]
-        private string _state = "chempuff";
-
-        private Animation VaporFlick = default!;
-
-        void ISerializationHooks.AfterDeserialization()
-        {
-            VaporFlick = new Animation {Length = TimeSpan.FromSeconds(_delay)};
-            {
-                var flick = new AnimationTrackSpriteFlick();
-                VaporFlick.AnimationTracks.Add(flick);
-                flick.LayerKey = VaporVisualLayers.Base;
-                flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(_state, 0f));
-            }
-        }
-
-        [Obsolete("Subscribe to AppearanceChangeEvent instead.")]
-        public override void OnChangeData(AppearanceComponent component)
-        {
-            base.OnChangeData(component);
-
-            if (component.TryGetData<Color>(VaporVisuals.Color, out var color))
-            {
-                SetColor(component, color);
-            }
-
-            if (component.TryGetData<bool>(VaporVisuals.State, out var state))
-            {
-                SetState(component, state);
-            }
-        }
-
-        private void SetState(AppearanceComponent component, bool state)
-        {
-            if (!state) return;
-
-            var animPlayer = IoCManager.Resolve<IEntityManager>().GetComponent<AnimationPlayerComponent>(component.Owner);
-
-            if(!animPlayer.HasRunningAnimation(AnimationKey))
-                animPlayer.Play(VaporFlick, AnimationKey);
-        }
-
-        private void SetColor(AppearanceComponent component, Color color)
-        {
-            var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<SpriteComponent>(component.Owner);
-
-            sprite.Color = color;
-        }
-    }
-
-    public enum VaporVisualLayers : byte
-    {
-        Base
-    }
-}
diff --git a/Content.Client/Chemistry/Visualizers/VaporVisualizerSystem.cs b/Content.Client/Chemistry/Visualizers/VaporVisualizerSystem.cs
new file mode 100644 (file)
index 0000000..42e8f40
--- /dev/null
@@ -0,0 +1,62 @@
+using Content.Shared.Vapor;
+using Robust.Client.Animations;
+using Robust.Client.GameObjects;
+
+namespace Content.Client.Chemistry.Visualizers;
+
+/// <summary>
+/// Handles vapor playing the 'being sprayed' animation if necessary.
+/// </summary>
+public sealed class VaporVisualizerSystem : VisualizerSystem<VaporVisualsComponent>
+{
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<VaporVisualsComponent, ComponentInit>(OnComponentInit);
+    }
+
+    /// <summary>
+    /// Constructs the 'being sprayed' animation for the vapor entity.
+    /// </summary>
+    private void OnComponentInit(EntityUid uid, VaporVisualsComponent comp, ComponentInit args)
+    {
+        comp.VaporFlick = new Animation()
+        {
+            Length = TimeSpan.FromSeconds(comp.AnimationTime),
+            AnimationTracks =
+            {
+                new AnimationTrackSpriteFlick()
+                {
+                    LayerKey = VaporVisualLayers.Base,
+                    KeyFrames =
+                    {
+                        new AnimationTrackSpriteFlick.KeyFrame(comp.AnimationState, 0f)
+                    }
+                }
+            }
+        };
+    }
+
+    /// <summary>
+    /// Ensures that the vapor entity plays its 'being sprayed' animation if necessary.
+    /// </summary>
+    protected override void OnAppearanceChange(EntityUid uid, VaporVisualsComponent comp, ref AppearanceChangeEvent args)
+    {
+        if (AppearanceSystem.TryGetData<Color>(uid, VaporVisuals.Color, out var color, args.Component) && args.Sprite != null)
+        {
+            args.Sprite.Color = color;
+        }
+
+        if ((AppearanceSystem.TryGetData<bool>(uid, VaporVisuals.State, out var state, args.Component) && state) &&
+            TryComp<AnimationPlayerComponent>(uid, out var animPlayer) &&
+           !AnimationSystem.HasRunningAnimation(uid, animPlayer, VaporVisualsComponent.AnimationKey))
+        {
+            AnimationSystem.Play(uid, animPlayer, comp.VaporFlick, VaporVisualsComponent.AnimationKey);
+        }
+    }
+}
+
+public enum VaporVisualLayers : byte
+{
+    Base
+}
diff --git a/Content.Client/Chemistry/Visualizers/VaporVisualsComponent.cs b/Content.Client/Chemistry/Visualizers/VaporVisualsComponent.cs
new file mode 100644 (file)
index 0000000..82e004e
--- /dev/null
@@ -0,0 +1,34 @@
+using Robust.Client.Animations;
+
+namespace Content.Client.Chemistry.Visualizers;
+
+/// <summary>
+/// A component that plays an animation when it is sprayed.
+/// </summary>
+[RegisterComponent]
+[Access(typeof(VaporVisualizerSystem))]
+public sealed class VaporVisualsComponent : Component
+{
+    /// <summary>
+    /// The id of the animation played when the vapor spawns in.
+    /// </summary>
+    public const string AnimationKey = "flick_animation";
+
+    /// <summary>
+    /// The amount of time over which the spray animation is played.
+    /// </summary>
+    [DataField("animationTime")]
+    public float AnimationTime = 0.25f;
+
+    /// <summary>
+    /// The RSI state that is flicked when the vapor is sprayed.
+    /// </summary>
+    [DataField("animationState")]
+    public string AnimationState = "chempuff";
+
+    /// <summary>
+    /// The animation that plays when the vapor is sprayed.
+    /// Generated in <see cref="VaporVisualizerSystem.OnComponentInit"/>
+    /// </summary>
+    public Animation VaporFlick = default!;
+}
index 2805c8f58186c03982046ad2e68ad268ce365e88..9918e03592ca7237524ea53ab393b986fad78b5a 100644 (file)
@@ -65,7 +65,6 @@
   - type: Physics
     bodyType: Dynamic
   - type: Appearance
-    visuals:
-      - type: VaporVisualizer
-        animation_delay: 0.8
-        animation_state: extinguish
+  - type: VaporVisuals
+    animationTime: 0.8
+    animationState: extinguish
index 5fcb6712a8059f0ec6e501fe8cf625b279244b9d..3bb9c97fd9cfb83a3dc1f2f1f9c2c0ca7fc1a17f 100644 (file)
       - FullTileMask
       - Opaque
   - type: Appearance
-    visuals:
-    - type: VaporVisualizer
+  - type: VaporVisuals