]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Converted BurnState Visualizer (#15661)
authorBixkitts <72874643+Bixkitts@users.noreply.github.com>
Sat, 29 Apr 2023 09:09:11 +0000 (11:09 +0200)
committerGitHub <noreply@github.com>
Sat, 29 Apr 2023 09:09:11 +0000 (19:09 +1000)
Content.Client/Smoking/BurnStateVisualizer.cs [deleted file]
Content.Client/Smoking/BurnStateVisualizerSystem.cs [new file with mode: 0644]
Content.Client/Smoking/BurnStateVisualsComponent.cs [new file with mode: 0644]
Content.Shared/Smoking/SmokableState.cs
Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Pipes/pipe.yml
Resources/Prototypes/Entities/Objects/Consumable/Smokeables/base_smokeables.yml
Resources/Prototypes/Entities/Objects/Tools/matches.yml

diff --git a/Content.Client/Smoking/BurnStateVisualizer.cs b/Content.Client/Smoking/BurnStateVisualizer.cs
deleted file mode 100644 (file)
index a67f156..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-using Content.Shared.Smoking;
-using JetBrains.Annotations;
-using Robust.Client.GameObjects;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Serialization;
-using Robust.Shared.Serialization.Manager.Attributes;
-
-namespace Content.Client.Smoking
-{
-    [UsedImplicitly]
-    public sealed class BurnStateVisualizer : AppearanceVisualizer, ISerializationHooks
-    {
-        [Dependency] private readonly IEntityManager _entMan = default!;
-
-        [DataField("burntIcon")]
-        private string _burntIcon = "burnt-icon";
-        [DataField("litIcon")]
-        private string _litIcon = "lit-icon";
-        [DataField("unlitIcon")]
-        private string _unlitIcon = "icon";
-
-        void ISerializationHooks.AfterDeserialization()
-        {
-            IoCManager.InjectDependencies(this);
-        }
-
-        [Obsolete("Subscribe to AppearanceChangeEvent instead.")]
-        public override void OnChangeData(AppearanceComponent component)
-        {
-            base.OnChangeData(component);
-
-            if (!_entMan.TryGetComponent(component.Owner, out SpriteComponent? sprite))
-                return;
-
-            if (!component.TryGetData<SmokableState>(SmokingVisuals.Smoking, out var burnState))
-                return;
-
-            var state = burnState switch
-            {
-                SmokableState.Lit => _litIcon,
-                SmokableState.Burnt => _burntIcon,
-                _ => _unlitIcon
-            };
-
-            sprite.LayerSetState(0, state);
-        }
-    }
-}
diff --git a/Content.Client/Smoking/BurnStateVisualizerSystem.cs b/Content.Client/Smoking/BurnStateVisualizerSystem.cs
new file mode 100644 (file)
index 0000000..d0aa9a4
--- /dev/null
@@ -0,0 +1,25 @@
+using Robust.Client.GameObjects;
+using Content.Shared.Smoking;
+
+namespace Content.Client.Smoking;
+
+public sealed class BurnStateVisualizerSystem : VisualizerSystem<BurnStateVisualsComponent>
+{
+    protected override void OnAppearanceChange(EntityUid uid, BurnStateVisualsComponent component, ref AppearanceChangeEvent args)
+    {
+        if (args.Sprite == null)
+            return;
+        if (!args.AppearanceData.TryGetValue(SmokingVisuals.Smoking, out var burnState))
+            return;
+
+        var state = burnState switch
+        {
+            SmokableState.Lit => component.LitIcon,
+            SmokableState.Burnt => component.BurntIcon,
+            _ => component.UnlitIcon
+        };
+
+        args.Sprite.LayerSetState(0, state);
+    }
+}
+
diff --git a/Content.Client/Smoking/BurnStateVisualsComponent.cs b/Content.Client/Smoking/BurnStateVisualsComponent.cs
new file mode 100644 (file)
index 0000000..42eb026
--- /dev/null
@@ -0,0 +1,13 @@
+namespace Content.Client.Smoking;
+
+[RegisterComponent]
+public sealed class BurnStateVisualsComponent : Component
+{
+    [DataField("burntIcon")]
+    public string BurntIcon = "burnt-icon";
+    [DataField("litIcon")]
+    public string LitIcon = "lit-icon";
+    [DataField("unlitIcon")]
+    public string UnlitIcon = "icon";
+}
+
index 3206acb15be6239f33d33b0e33b648699cd623cb..016dc587c01d35692cc58f7255245bfe83096bd8 100644 (file)
@@ -1,4 +1,4 @@
-using Robust.Shared.Serialization;
+using Robust.Shared.Serialization;
 
 namespace Content.Shared.Smoking
 {
index 171fb874782ae5cace15124c6820d14696cb1a10..009bc9880c0d596098e89d2adc1d3ceb16a613a9 100644 (file)
@@ -16,9 +16,8 @@
     size: 3
     sprite: Objects/Consumable/Smokeables/Pipes/pipe.rsi
   - type: Appearance
-    visuals:
-      - type: BurnStateVisualizer
-        unlitIcon: unlit-icon
+  - type: BurnStateVisuals
+    unlitIcon: unlit-icon
 
 - type: entity
   id: SmokingPipeFilledTobacco
       bowl_slot: !type:ContainerSlot
   - type: ItemSlots
   - type: SmokingPipe
-    bowl_slot: 
+    bowl_slot:
       name: Bowl
       startingItem: GroundTobacco
       whitelist:
         tags:
           - Smokable
-      insertSound: 
+      insertSound:
         path: /Audio/Weapons/Guns/Empty/empty.ogg
-      ejectSound: 
+      ejectSound:
         path: /Audio/Weapons/Guns/Empty/empty.ogg
 
 - type: entity
       bowl_slot: !type:ContainerSlot
   - type: ItemSlots
   - type: SmokingPipe
-    bowl_slot: 
+    bowl_slot:
       name: Bowl
       startingItem: GroundCannabis
       whitelist:
         tags:
           - Smokable
-      insertSound: 
+      insertSound:
+        path: /Audio/Weapons/Guns/Empty/empty.ogg
+      ejectSound:
         path: /Audio/Weapons/Guns/Empty/empty.ogg
-      ejectSound: 
-        path: /Audio/Weapons/Guns/Empty/empty.ogg
\ No newline at end of file
index c534b730940e116925a9c645b2f07b9deb27b92b..419ab7639152a822788d274e44ec02aecb12ffdf 100644 (file)
@@ -8,8 +8,7 @@
   - type: Sprite
     netsync: false
   - type: Appearance
-    visuals:
-      - type: BurnStateVisualizer
+  - type: BurnStateVisuals
   - type: Tag
     tags:
     - Trash
index 3700a1bfb163015a05284706561cd49fc097c57d..d7ece96c7d36196254489a3ad26d1825449c3f65 100644 (file)
@@ -1,4 +1,4 @@
-- type: entity
+- type: entity
   id: SmallboxItem
   parent: BaseStorageItem
   abstract: true
     radius: 1.1
     color: darkorange
   - type: Appearance
-    visuals:
-      - type: BurnStateVisualizer
-        unlitIcon: match_unlit
-        litIcon: match_lit
-        burntIcon: match_burnt
+  - type: BurnStateVisuals
+    unlitIcon: match_unlit
+    litIcon: match_lit
+    burntIcon: match_burnt
 
 - type: entity
   parent: Matchstick