]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Resolves SmesVisualizer is Obsolete (#13899)
authorTemporalOroboros <TemporalOroboros@gmail.com>
Sun, 7 May 2023 03:43:41 +0000 (20:43 -0700)
committerGitHub <noreply@github.com>
Sun, 7 May 2023 03:43:41 +0000 (13:43 +1000)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Client/Power/SMES/SmesComponent.cs [new file with mode: 0644]
Content.Client/Power/SMES/SmesSystem.cs [new file with mode: 0644]
Content.Client/Power/SMES/SmesVisualizer.cs [deleted file]
Content.Server/Power/SMES/SmesComponent.cs
Content.Server/Power/SMES/SmesSystem.cs
Content.Shared/Power/SharedPower.cs
Content.Shared/SMES/SharedSmesComponent.cs
Resources/Prototypes/Entities/Structures/Power/smes.yml

diff --git a/Content.Client/Power/SMES/SmesComponent.cs b/Content.Client/Power/SMES/SmesComponent.cs
new file mode 100644 (file)
index 0000000..155a40c
--- /dev/null
@@ -0,0 +1,28 @@
+namespace Content.Client.Power.SMES;
+
+[RegisterComponent]
+public sealed class SmesComponent : Component
+{
+    /// <summary>
+    /// The prefix used for the RSI states of the sprite layers indicating the charge level of the SMES.
+    /// </summary>
+    [DataField("chargeOverlayPrefix")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string ChargeOverlayPrefix = "smes-og";
+    
+    /// <summary>
+    /// The prefix used for the RSI states of the sprite layers indicating the input state of the SMES.
+    /// Actually bundled together with the output indicator light.
+    /// </summary>
+    [DataField("inputOverlayPrefix")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string InputOverlayPrefix = "smes-oc";
+    
+    /// <summary>
+    /// The prefix used for the RSI states of the sprite layers indicating the output state of the SMES.
+    /// Actually bundled together with the input indicator light.
+    /// </summary>
+    [DataField("outputOverlayPrefix")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string OutputOverlayPrefix = "smes-op";
+}
diff --git a/Content.Client/Power/SMES/SmesSystem.cs b/Content.Client/Power/SMES/SmesSystem.cs
new file mode 100644 (file)
index 0000000..a555bed
--- /dev/null
@@ -0,0 +1,50 @@
+using Content.Shared.Power;
+using Content.Shared.SMES;
+using Robust.Client.GameObjects;
+
+namespace Content.Client.Power.SMES;
+
+public sealed class SmesVisualizerSystem : VisualizerSystem<SmesComponent>
+{
+    protected override void OnAppearanceChange(EntityUid uid, SmesComponent comp, ref AppearanceChangeEvent args)
+    {
+        if (args.Sprite == null)
+            return;
+
+        if (!AppearanceSystem.TryGetData<int>(uid, SmesVisuals.LastChargeLevel, out var level, args.Component) || level == 0)
+        {
+            args.Sprite.LayerSetVisible(SmesVisualLayers.Charge, false);
+        }
+        else
+        {
+            args.Sprite.LayerSetVisible(SmesVisualLayers.Charge, true);
+            args.Sprite.LayerSetState(SmesVisualLayers.Charge, $"{comp.ChargeOverlayPrefix}{level}");
+        }
+
+        if (!AppearanceSystem.TryGetData<ChargeState>(uid, SmesVisuals.LastChargeState, out var state, args.Component))
+            state = ChargeState.Still;
+
+        switch (state)
+        {
+            case ChargeState.Still:
+                args.Sprite.LayerSetState(SmesVisualLayers.Input, $"{comp.InputOverlayPrefix}0");
+                args.Sprite.LayerSetState(SmesVisualLayers.Output, $"{comp.OutputOverlayPrefix}1");
+                break;
+            case ChargeState.Charging:
+                args.Sprite.LayerSetState(SmesVisualLayers.Input, $"{comp.InputOverlayPrefix}1");
+                args.Sprite.LayerSetState(SmesVisualLayers.Output, $"{comp.OutputOverlayPrefix}1");
+                break;
+            case ChargeState.Discharging:
+                args.Sprite.LayerSetState(SmesVisualLayers.Input, $"{comp.InputOverlayPrefix}0");
+                args.Sprite.LayerSetState(SmesVisualLayers.Output, $"{comp.OutputOverlayPrefix}2");
+                break;
+        }
+    }
+}
+
+enum SmesVisualLayers : byte
+{
+    Input,
+    Charge,
+    Output,
+}
diff --git a/Content.Client/Power/SMES/SmesVisualizer.cs b/Content.Client/Power/SMES/SmesVisualizer.cs
deleted file mode 100644 (file)
index 7682671..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-using Content.Shared.Power;
-using Content.Shared.SMES;
-using JetBrains.Annotations;
-using Robust.Client.GameObjects;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-
-namespace Content.Client.Power.SMES
-{
-    [UsedImplicitly]
-    public sealed class SmesVisualizer : AppearanceVisualizer
-    {
-        [Obsolete("Subscribe to your component being initialised instead.")]
-        public override void InitializeEntity(EntityUid entity)
-        {
-            base.InitializeEntity(entity);
-
-            var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<SpriteComponent>(entity);
-
-            sprite.LayerMapSet(Layers.Input, sprite.AddLayerState("smes-oc0"));
-            sprite.LayerSetShader(Layers.Input, "unshaded");
-            sprite.LayerMapSet(Layers.Charge, sprite.AddLayerState("smes-og1"));
-            sprite.LayerSetShader(Layers.Charge, "unshaded");
-            sprite.LayerSetVisible(Layers.Charge, false);
-            sprite.LayerMapSet(Layers.Output, sprite.AddLayerState("smes-op0"));
-            sprite.LayerSetShader(Layers.Output, "unshaded");
-        }
-
-        [Obsolete("Subscribe to AppearanceChangeEvent instead.")]
-        public override void OnChangeData(AppearanceComponent component)
-        {
-            base.OnChangeData(component);
-
-            var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<SpriteComponent>(component.Owner);
-            if (!component.TryGetData<int>(SmesVisuals.LastChargeLevel, out var level) || level == 0)
-            {
-                sprite.LayerSetVisible(Layers.Charge, false);
-            }
-            else
-            {
-                sprite.LayerSetVisible(Layers.Charge, true);
-                sprite.LayerSetState(Layers.Charge, $"smes-og{level}");
-            }
-
-            if (component.TryGetData<ChargeState>(SmesVisuals.LastChargeState, out var state))
-            {
-                switch (state)
-                {
-                    case ChargeState.Still:
-                        sprite.LayerSetState(Layers.Input, "smes-oc0");
-                        sprite.LayerSetState(Layers.Output, "smes-op1");
-                        break;
-                    case ChargeState.Charging:
-                        sprite.LayerSetState(Layers.Input, "smes-oc1");
-                        sprite.LayerSetState(Layers.Output, "smes-op1");
-                        break;
-                    case ChargeState.Discharging:
-                        sprite.LayerSetState(Layers.Input, "smes-oc0");
-                        sprite.LayerSetState(Layers.Output, "smes-op2");
-                        break;
-                }
-            }
-            else
-            {
-                sprite.LayerSetState(Layers.Input, "smes-oc0");
-                sprite.LayerSetState(Layers.Output, "smes-op1");
-            }
-        }
-
-        enum Layers : byte
-        {
-            Input,
-            Charge,
-            Output,
-        }
-    }
-}
index c812fc9836e25e1889fcd421843d4cb826423e92..29e1dbd7cbe1a49aca7cd25a867f195db211384c 100644 (file)
@@ -1,16 +1,12 @@
 using Content.Server.Power.Components;
 using Content.Shared.Power;
-using Content.Shared.Rounding;
-using Content.Shared.SMES;
-using Robust.Server.GameObjects;
-using Robust.Shared.Timing;
 
 namespace Content.Server.Power.SMES;
 
 /// <summary>
 ///     Handles the "user-facing" side of the actual SMES object.
 ///     This is operations that are specific to the SMES, like UI and visuals.
-///     Logic is handled in <see cref="PowerSmesSystem"/>
+///     Logic is handled in <see cref="SmesSystem"/>
 ///     Code interfacing with the powernet is handled in <see cref="BatteryStorageComponent"/> and <see cref="BatteryDischargerComponent"/>.
 /// </summary>
 [RegisterComponent, Access(typeof(SmesSystem))]
@@ -26,4 +22,23 @@ public sealed class SmesComponent : Component
     public TimeSpan LastChargeLevelTime;
     [ViewVariables]
     public TimeSpan VisualsChangeDelay = TimeSpan.FromSeconds(1);
+
+    /// <summary>
+    /// The number of distinct charge levels a SMES has.
+    /// 0 is empty max is full.
+    /// </summary>
+    [DataField("numChargeLevels")]
+    public int NumChargeLevels = 6;
+
+    /// <summary>
+    /// The charge level of the SMES as of the most recent update.
+    /// </summary>
+    [ViewVariables]
+    public int ChargeLevel = 0;
+
+    /// <summary>
+    /// Whether the SMES is being charged/discharged/neither.
+    /// </summary>
+    [ViewVariables]
+    public ChargeState ChargeState = ChargeState.Still;
 }
index e9a07fa03e4af7300ecd746bd74947b907d700e8..7da8eb068811590d045523e9fb58083c4b5491d1 100644 (file)
@@ -57,7 +57,7 @@ internal sealed class SmesSystem : EntitySystem
 
     private int CalcChargeLevel(EntityUid uid, BatteryComponent? battery = null)
     {
-        if (!Resolve<BatteryComponent>(uid, ref battery))
+        if (!Resolve(uid, ref battery))
             return 0;
 
         return ContentHelpers.RoundToLevels(battery.CurrentCharge, battery.MaxCharge, 6);
@@ -65,7 +65,7 @@ internal sealed class SmesSystem : EntitySystem
 
     private ChargeState CalcChargeState(EntityUid uid, PowerNetworkBatteryComponent? netBattery = null)
     {
-        if (!Resolve<PowerNetworkBatteryComponent>(uid, ref netBattery))
+        if (!Resolve(uid, ref netBattery))
             return ChargeState.Still;
 
         return (netBattery.CurrentSupply - netBattery.CurrentReceiving) switch
index 481dcf7dc9e44a7ef55188b3a6fea09c2eeed3e3..5dd366fd6855c43ed5b772d2dd01727eef0186dd 100644 (file)
@@ -3,11 +3,11 @@
 namespace Content.Shared.Power
 {
     [Serializable, NetSerializable]
-    public enum ChargeState
+    public enum ChargeState : byte
     {
-        Still,
-        Charging,
-        Discharging,
+        Still = 0,
+        Charging = 1,
+        Discharging = 2,
     }
 
     [Serializable, NetSerializable]
index 720e346a79ed21d52b1df75c2f7296e7984eace3..3fe9dd8f5f390be6a512cdb01db0850c4d9ad0f5 100644 (file)
@@ -1,11 +1,10 @@
 using Robust.Shared.Serialization;
 
-namespace Content.Shared.SMES
+namespace Content.Shared.SMES;
+
+[Serializable, NetSerializable]
+public enum SmesVisuals
 {
-    [Serializable, NetSerializable]
-    public enum SmesVisuals
-    {
-        LastChargeState,
-        LastChargeLevel,
-    }
+    LastChargeState,
+    LastChargeLevel,
 }
index 54f9270fd76216ebc8080db3c82e8d7ea4ef9803..9b934dea02f7c2b3fba3fbe30324c899cb38a860 100644 (file)
       snapCardinals: true
       layers:
         - state: smes
+        - map: ["enum.SmesVisualLayers.Charge"]
+          state: "smes-og1" # -og0 does not exist
+          shader: unshaded
+          visible: false
+        - map: ["enum.SmesVisualLayers.Input"]
+          state: "smes-oc0"
+          shader: unshaded
+        - map: ["enum.SmesVisualLayers.Output"]
+          state: "smes-op1"
+          shader: unshaded
     - type: Smes
     - type: UpgradeBattery
       maxChargeMultiplier: 2
       baseMaxCharge: 8000000
     - type: Appearance
-      visuals:
-        - type: SmesVisualizer
     - type: Battery
       startingCharge: 0
     - type: ExaminableBattery