]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Resolves ExpendableLightVisualizer is Obsolete (#13888)
authorTemporalOroboros <TemporalOroboros@gmail.com>
Mon, 1 May 2023 15:03:26 +0000 (08:03 -0700)
committerGitHub <noreply@github.com>
Mon, 1 May 2023 15:03:26 +0000 (11:03 -0400)
Content.Client/Light/Components/ExpendableLightComponent.cs
Content.Client/Light/EntitySystems/ExpendableLightSystem.cs
Content.Client/Light/Visualizers/ExpendableLightVisualizer.cs [deleted file]
Resources/Prototypes/Entities/Objects/Misc/torch.yml
Resources/Prototypes/Entities/Objects/Tools/flare.yml
Resources/Prototypes/Entities/Objects/Tools/glowstick.yml

index d2cc535cf42c2e942c7925f925b7558d9f1e8ab3..6d22bdf161608a9778ee64cf9127fb13bfaf8ba1 100644 (file)
@@ -1,14 +1,55 @@
+using Content.Client.Light.EntitySystems;
 using Content.Shared.Light.Component;
 using Robust.Shared.Audio;
 
-namespace Content.Client.Light.Components
+namespace Content.Client.Light.Components;
+
+/// <summary>
+/// Component that represents a handheld expendable light which can be activated and eventually dies over time.
+/// </summary>
+[RegisterComponent]
+public sealed class ExpendableLightComponent : SharedExpendableLightComponent
 {
     /// <summary>
-    ///     Component that represents a handheld expendable light which can be activated and eventually dies over time.
+    /// The icon state used by expendable lights when the they have been completely expended.
+    /// </summary>
+    [DataField("iconStateSpent")]
+    public string? IconStateSpent;
+
+    /// <summary>
+    /// The icon state used by expendable lights while they are lit.
+    /// </summary>
+    [DataField("iconStateLit")]
+    public string? IconStateLit;
+
+    /// <summary>
+    /// The sprite layer shader used while the expendable light is lit.
+    /// </summary>
+    [DataField("spriteShaderLit")]
+    public string? SpriteShaderLit = null;
+
+    /// <summary>
+    /// The sprite layer shader used after the expendable light has burnt out.
     /// </summary>
-    [RegisterComponent]
-    public sealed class ExpendableLightComponent : SharedExpendableLightComponent
-    {
-        public IPlayingAudioStream? PlayingStream { get; set; }
-    }
+    [DataField("spriteShaderSpent")]
+    public string? SpriteShaderSpent = null;
+
+    /// <summary>
+    /// The sprite layer shader used after the expendable light has burnt out.
+    /// </summary>
+    [DataField("glowColorLit")]
+    public Color? GlowColorLit = null;
+
+    /// <summary>
+    /// The sound that plays when the expendable light is lit.
+    /// </summary>
+    [Access(typeof(ExpendableLightSystem))]
+    public IPlayingAudioStream? PlayingStream;
+}
+
+public enum ExpendableLightVisualLayers : byte
+{
+    Base = 0,
+    Glow = 1,
+    Overlay = 2,
 }
index c982f5c46376b0795db73ac210f407db0e85773a..d180f430db9c781d7fdd5b981fa7ea7e25888852 100644 (file)
@@ -1,9 +1,15 @@
 using Content.Client.Light.Components;
+using Content.Shared.Light.Component;
+using Robust.Client.GameObjects;
+using Robust.Client.Graphics;
 
 namespace Content.Client.Light.EntitySystems;
 
-public sealed class ExpendableLightSystem : EntitySystem
+public sealed class ExpendableLightSystem : VisualizerSystem<ExpendableLightComponent>
 {
+    [Dependency] private readonly PointLightSystem _pointLightSystem = default!;
+    [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
+
     public override void Initialize()
     {
         base.Initialize();
@@ -15,4 +21,71 @@ public sealed class ExpendableLightSystem : EntitySystem
     {
         component.PlayingStream?.Stop();
     }
+
+    protected override void OnAppearanceChange(EntityUid uid, ExpendableLightComponent comp, ref AppearanceChangeEvent args)
+    {
+        if (args.Sprite == null)
+            return;
+
+        if (AppearanceSystem.TryGetData<string>(uid, ExpendableLightVisuals.Behavior, out var lightBehaviourID, args.Component)
+        &&  TryComp<LightBehaviourComponent>(uid, out var lightBehaviour))
+        {
+            lightBehaviour.StopLightBehaviour();
+
+            if (!string.IsNullOrEmpty(lightBehaviourID))
+            {
+                lightBehaviour.StartLightBehaviour(lightBehaviourID);
+            }
+            else if (TryComp<PointLightComponent>(uid, out var light))
+            {
+                _pointLightSystem.SetEnabled(uid, false, light);
+            }
+        }
+
+        if (!AppearanceSystem.TryGetData<ExpendableLightState>(uid, ExpendableLightVisuals.State, out var state, args.Component))
+            return;
+
+        switch (state)
+        {
+            case ExpendableLightState.Lit:
+                comp.PlayingStream?.Stop();
+                comp.PlayingStream = _audioSystem.PlayPvs(
+                    comp.LoopedSound,
+                    uid,
+                    SharedExpendableLightComponent.LoopedSoundParams
+                );
+                if (args.Sprite.LayerMapTryGet(ExpendableLightVisualLayers.Overlay, out var layerIdx, true))
+                {
+                    if (!string.IsNullOrWhiteSpace(comp.IconStateLit))
+                        args.Sprite.LayerSetState(layerIdx, comp.IconStateLit);
+                    if (!string.IsNullOrWhiteSpace(comp.SpriteShaderLit))
+                        args.Sprite.LayerSetShader(layerIdx, comp.SpriteShaderLit);
+                    else
+                        args.Sprite.LayerSetShader(layerIdx, null, null);
+                    if (comp.GlowColorLit.HasValue)
+                        args.Sprite.LayerSetColor(layerIdx, comp.GlowColorLit.Value);
+                    args.Sprite.LayerSetVisible(layerIdx, true);
+                }
+
+                if (comp.GlowColorLit.HasValue)
+                    args.Sprite.LayerSetColor(ExpendableLightVisualLayers.Glow, comp.GlowColorLit.Value);
+                args.Sprite.LayerSetVisible(ExpendableLightVisualLayers.Glow, true);
+
+                break;
+            case ExpendableLightState.Dead:
+                comp.PlayingStream?.Stop();
+                if (args.Sprite.LayerMapTryGet(ExpendableLightVisualLayers.Overlay, out layerIdx, true))
+                {
+                    if (!string.IsNullOrWhiteSpace(comp.IconStateSpent))
+                        args.Sprite.LayerSetState(layerIdx, comp.IconStateSpent);
+                    if (!string.IsNullOrWhiteSpace(comp.SpriteShaderSpent))
+                        args.Sprite.LayerSetShader(layerIdx, comp.SpriteShaderSpent);
+                    else
+                        args.Sprite.LayerSetShader(layerIdx, null, null);
+                }
+
+                args.Sprite.LayerSetVisible(ExpendableLightVisualLayers.Glow, false);
+                break;
+        }
+    }
 }
diff --git a/Content.Client/Light/Visualizers/ExpendableLightVisualizer.cs b/Content.Client/Light/Visualizers/ExpendableLightVisualizer.cs
deleted file mode 100644 (file)
index 012e918..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-using Content.Client.Light.Components;
-using Content.Shared.Light.Component;
-using JetBrains.Annotations;
-using Robust.Client.GameObjects;
-
-namespace Content.Client.Light.Visualizers
-{
-    [UsedImplicitly]
-    public sealed class ExpendableLightVisualizer : AppearanceVisualizer
-    {
-        [DataField("iconStateSpent")]
-        public string? IconStateSpent { get; set; }
-
-        [DataField("iconStateOn")]
-        public string? IconStateLit { get; set; }
-
-        [Obsolete("Subscribe to AppearanceChangeEvent instead.")]
-        public override void OnChangeData(AppearanceComponent component)
-        {
-            base.OnChangeData(component);
-
-            var entities = IoCManager.Resolve<IEntityManager>();
-
-            if (!entities.TryGetComponent(component.Owner, out ExpendableLightComponent? expendableLight))
-                    return;
-
-            if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite))
-                    return;
-
-            if (component.TryGetData(ExpendableLightVisuals.Behavior, out string lightBehaviourID))
-            {
-                if (entities.TryGetComponent(component.Owner, out LightBehaviourComponent? lightBehaviour))
-                {
-                    lightBehaviour.StopLightBehaviour();
-
-                    if (lightBehaviourID != string.Empty)
-                    {
-                        lightBehaviour.StartLightBehaviour(lightBehaviourID);
-                    }
-                    else if (entities.TryGetComponent(component.Owner, out PointLightComponent? light))
-                    {
-                        light.Enabled = false;
-                    }
-                }
-            }
-
-            if (!component.TryGetData(ExpendableLightVisuals.State, out ExpendableLightState state))
-                return;
-
-            switch (state)
-            {
-                case ExpendableLightState.Lit:
-                    expendableLight.PlayingStream?.Stop();
-                    expendableLight.PlayingStream = entities.EntitySysManager.GetEntitySystem<SharedAudioSystem>().PlayPvs(
-                        expendableLight.LoopedSound,
-                        expendableLight.Owner,
-                        SharedExpendableLightComponent.LoopedSoundParams);
-                    if (!string.IsNullOrWhiteSpace(IconStateLit))
-                    {
-                        sprite.LayerSetState(2, IconStateLit);
-                        sprite.LayerSetShader(2, "shaded");
-                    }
-
-                    sprite.LayerSetVisible(1, true);
-
-                    break;
-                case ExpendableLightState.Dead:
-                    expendableLight.PlayingStream?.Stop();
-                    if (!string.IsNullOrWhiteSpace(IconStateSpent))
-                    {
-                        sprite.LayerSetState(0, IconStateSpent);
-                        sprite.LayerSetShader(0, "shaded");
-                    }
-
-                    sprite.LayerSetVisible(1, false);
-                    break;
-            }
-        }
-    }
-}
index 7cff2072d2152b41ec3e58e39262aae587895d69..c014d72ee00a606251ec381466d0d4e5dcc98484 100644 (file)
     - type: Sprite
       sprite: Objects/Misc/torch.rsi
       layers:
-        - state: torch_unlit
-        - state: lit_overlay
+        - map: [ enum.ExpendableLightVisualLayers.Base ]
+          state: torch_unlit
+        - map: [ enum.ExpendableLightVisualLayers.Glow ]
+          state: lit_overlay
           color: "#FFFFFF"
           visible: false
           shader: unshaded
@@ -33,8 +35,6 @@
       graph: LightTorch
       node: torch
     - type: Appearance
-      visuals:
-        - type: ExpendableLightVisualizer
     - type: PointLight
       enabled: false
       color: "#E25822"
index e8fb33e73e56208c81c4f23ecc3fcabc487f5010..169cc911db2466b9cc2d65d13aeca034d1c076d3 100644 (file)
   - type: Sprite
     sprite: Objects/Misc/flare.rsi
     layers:
-      - state: flare_base
-      - state: flare_burn
+      - map: [ enum.ExpendableLightVisualLayers.Base ]
+        state: flare_base
+      - map: [ enum.ExpendableLightVisualLayers.Glow ]
+        state: flare_burn
         color: "#FFFFFF"
         visible: false
         shader: unshaded
-      - state: flare_unlit
+      - map: [ enum.ExpendableLightVisualLayers.Overlay ]
+        state: flare_unlit
         color: "#FF0000"
   - type: Icon
     sprite: Objects/Misc/flare.rsi
@@ -38,8 +41,6 @@
     sprite: Objects/Misc/flare.rsi
     heldPrefix: unlit
   - type: Appearance
-    visuals:
-      - type: ExpendableLightVisualizer
   - type: PointLight
     enabled: false
     color: "#FF8080"
index 41919ddce6c96928b0de5f8c7f81b62ad89c4f86..3d7041829c9b3340883317e4cd8494f1935d65df 100644 (file)
@@ -9,29 +9,29 @@
       spentName: expendable-light-spent-green-glowstick-name
       spentDesc: expendable-light-spent-glowstick-desc
       glowDuration: 900 # time in seconds
+      glowColorLit: "#00FF00"
       fadeOutDuration: 300
       turnOnBehaviourID: turn_on
       fadeOutBehaviourID: fade_out
+      iconStateLit: glowstick_lit
+      iconStateSpent: glowstick_unlit
       litSound:
         path: /Audio/Items/Handcuffs/rope_breakout.ogg
     - type: Sprite
       sprite: Objects/Misc/glowstick.rsi
       layers:
-        - state: glowstick_base
-        - state: glowstick_glow
-          color: "#00FF00"
-          visible: false
-          shader: unshaded
-        - state: glowstick_unlit
-          color: "#00FF00"
+      - map: [ enum.ExpendableLightVisualLayers.Base ]
+        state: glowstick_base
+      - map: [ enum.ExpendableLightVisualLayers.Glow ]
+        state: glowstick_glow
+        visible: false
+        shader: unshaded
+      - map: [ enum.ExpendableLightVisualLayers.Overlay ]
+        state: glowstick_unlit
     - type: Item
       sprite: Objects/Misc/glowstick.rsi
       heldPrefix: unlit
     - type: Appearance
-      visuals:
-        - type: ExpendableLightVisualizer
-          iconStateOn: glowstick_lit
-          iconStateSpent: glowstick_unlit
     - type: PointLight
       enabled: false
       color: "#00FF00"
     - type: ExpendableLight
       spentName: expendable-light-spent-red-glowstick-name
       glowDuration: 10 # time in seconds
+      glowColorLit: "#FF0000"
       fadeOutDuration: 5
-    - type: Sprite
-      layers:
-        - state: glowstick_base
-        - state: glowstick_glow
-          color: "#FF0000"
-          visible: false
-          shader: unshaded
-        - state: glowstick_unlit
-          color: "#FF0000"
     - type: PointLight
-      enabled: false
       color: "#FF0000"
-      radius: 5
-      energy: 0
 
 - type: entity
   name: purple glowstick
   components:
     - type: ExpendableLight
       spentName: expendable-light-spent-purple-glowstick-name
-    - type: Sprite
-      layers:
-        - state: glowstick_base
-        - state: glowstick_glow
-          color: "#FF00FF"
-          visible: false
-          shader: unshaded
-        - state: glowstick_unlit
-          color: "#FF00FF"
+      glowColorLit: "#FF00FF"
     - type: PointLight
-      enabled: false
       color: "#FF00FF"
-      radius: 5
-      energy: 0
 
 - type: entity
   name: yellow glowstick
   components:
     - type: ExpendableLight
       spentName: expendable-light-spent-yellow-glowstick-name
-    - type: Sprite
-      sprite: Objects/Misc/glowstick.rsi
-      layers:
-        - state: glowstick_base
-        - state: glowstick_glow
-          color: "#FFFF00"
-          visible: false
-          shader: unshaded
-        - state: glowstick_unlit
-          color: "#FFFF00"
+      glowColorLit: "#FFFF00"
     - type: PointLight
-      enabled: false
       color: "#FFFF00"
-      radius: 5
-      energy: 0
 
 - type: entity
   name: blue glowstick
   components:
     - type: ExpendableLight
       spentName: expendable-light-spent-blue-glowstick-name
-    - type: Sprite
-      sprite: Objects/Misc/glowstick.rsi
-      layers:
-        - state: glowstick_base
-        - state: glowstick_glow
-          color: "#0000FF"
-          visible: false
-          shader: unshaded
-        - state: glowstick_unlit
-          color: "#0000FF"
-      heldPrefix: unlit
+      glowColorLit: "#0000FF"
     - type: PointLight
-      enabled: false
       color: "#0000FF"
-      radius: 5
-      energy: 0
 
 # ----------------------------------------------------------------------------
 # THE FOLLOWING ARE ALL DUMMY ENTITIES USED TO TEST THE LIGHT BEHAVIOUR SYSTEM