]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Resolves LightBulbVisualizer is Obsolete (#13889)
authorTemporalOroboros <TemporalOroboros@gmail.com>
Tue, 14 Feb 2023 03:43:51 +0000 (19:43 -0800)
committerGitHub <noreply@github.com>
Tue, 14 Feb 2023 03:43:51 +0000 (23:43 -0400)
Content.Client/Light/EntitySystems/LightBulbSystem.cs [new file with mode: 0644]
Content.Client/Light/Visualizers/LightBulbVisualizer.cs [deleted file]
Content.Server/Light/Components/LightBulbComponent.cs [deleted file]
Content.Server/Light/Components/LightReplacerComponent.cs
Content.Server/Light/Components/PoweredLightComponent.cs
Content.Server/Light/EntitySystems/LightBulbSystem.cs
Content.Server/Light/EntitySystems/LightReplacerSystem.cs
Content.Server/Light/EntitySystems/PoweredLightSystem.cs
Content.Shared/Light/Component/LightBulbComponent.cs [new file with mode: 0644]
Content.Shared/Light/SharedLightBulb.cs [deleted file]
Resources/Prototypes/Entities/Objects/Power/lights.yml

diff --git a/Content.Client/Light/EntitySystems/LightBulbSystem.cs b/Content.Client/Light/EntitySystems/LightBulbSystem.cs
new file mode 100644 (file)
index 0000000..5130308
--- /dev/null
@@ -0,0 +1,36 @@
+using Content.Shared.Light.Component;
+using Robust.Client.GameObjects;
+
+namespace Content.Client.Light.Visualizers;
+
+public sealed class LightBulbSystem : VisualizerSystem<LightBulbComponent>
+{
+    protected override void OnAppearanceChange(EntityUid uid, LightBulbComponent comp, ref AppearanceChangeEvent args)
+    {
+        if (args.Sprite == null)
+            return;
+
+        // update sprite state
+        if (AppearanceSystem.TryGetData<LightBulbState>(uid, LightBulbVisuals.State, out var state, args.Component))
+        {
+            switch (state)
+            {
+                case LightBulbState.Normal:
+                    args.Sprite.LayerSetState(LightBulbVisualLayers.Base, comp.NormalSpriteState);
+                    break;
+                case LightBulbState.Broken:
+                    args.Sprite.LayerSetState(LightBulbVisualLayers.Base, comp.BrokenSpriteState);
+                    break;
+                case LightBulbState.Burned:
+                    args.Sprite.LayerSetState(LightBulbVisualLayers.Base, comp.BurnedSpriteState);
+                    break;
+            }
+        }
+
+        // also update sprites color
+        if (AppearanceSystem.TryGetData<Color>(uid, LightBulbVisuals.Color, out var color, args.Component))
+        {
+            args.Sprite.Color = color;
+        }
+    }
+}
diff --git a/Content.Client/Light/Visualizers/LightBulbVisualizer.cs b/Content.Client/Light/Visualizers/LightBulbVisualizer.cs
deleted file mode 100644 (file)
index 228f2e5..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-using Content.Shared.Light;
-using JetBrains.Annotations;
-using Robust.Client.GameObjects;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Maths;
-
-namespace Content.Client.Light.Visualizers
-{
-    [UsedImplicitly]
-    public sealed class LightBulbVisualizer : AppearanceVisualizer
-    {
-        [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 SpriteComponent? sprite))
-                return;
-
-            // update sprite state
-            if (component.TryGetData(LightBulbVisuals.State, out LightBulbState state))
-            {
-                switch (state)
-                {
-                    case LightBulbState.Normal:
-                        sprite.LayerSetState(0, "normal");
-                        break;
-                    case LightBulbState.Broken:
-                        sprite.LayerSetState(0, "broken");
-                        break;
-                    case LightBulbState.Burned:
-                        sprite.LayerSetState(0, "burned");
-                        break;
-                }
-            }
-
-            // also update sprites color
-            if (component.TryGetData(LightBulbVisuals.Color, out Color color))
-            {
-                sprite.Color = color;
-            }
-        }
-    }
-}
diff --git a/Content.Server/Light/Components/LightBulbComponent.cs b/Content.Server/Light/Components/LightBulbComponent.cs
deleted file mode 100644 (file)
index 39b3025..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-using Content.Server.Light.EntitySystems;
-using Content.Shared.Light;
-using Robust.Shared.Audio;
-
-namespace Content.Server.Light.Components
-{
-    /// <summary>
-    ///     Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless.
-    /// </summary>
-    [RegisterComponent, Access(typeof(LightBulbSystem))]
-    public sealed class LightBulbComponent : Component
-    {
-        [DataField("color")]
-        public Color Color = Color.White;
-
-        [DataField("bulb")]
-        public LightBulbType Type = LightBulbType.Tube;
-
-        [DataField("startingState")]
-        public LightBulbState State = LightBulbState.Normal;
-
-        [DataField("BurningTemperature")]
-        public int BurningTemperature = 1400;
-
-        [DataField("lightEnergy")]
-        public float LightEnergy = 0.8f;
-
-        [DataField("lightRadius")]
-        public float LightRadius = 10;
-
-        [DataField("lightSoftness")]
-        public float LightSoftness = 1;
-
-        [DataField("PowerUse")]
-        public int PowerUse = 60;
-
-        [DataField("breakSound")]
-        public SoundSpecifier BreakSound = new SoundCollectionSpecifier("GlassBreak");
-    }
-}
index de10898dee8f028af30bf310a10bb3975ebe8f70..8835fb0c84b9cd2b0e81983c72459a7739a16054 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Shared.Light;
+using Content.Shared.Light.Component;
 using Robust.Shared.Audio;
 using Robust.Shared.Containers;
 using Robust.Shared.Prototypes;
index 2c0e6ba052d848e069b67dbb9623250f421779bb..0088aad3353ebaee136c03697d9d8bde866ae272 100644 (file)
@@ -1,7 +1,7 @@
 using System.Threading;
 using Content.Server.Light.EntitySystems;
 using Content.Shared.Damage;
-using Content.Shared.Light;
+using Content.Shared.Light.Component;
 using Content.Shared.MachineLinking;
 using Robust.Shared.Audio;
 using Robust.Shared.Containers;
index 4c00830c98d040ac402011ccc8cef40af7da2688..75e34fca36cba7cace204994dc01ac70603f5219 100644 (file)
@@ -1,6 +1,6 @@
 using Content.Server.Light.Components;
 using Content.Shared.Destructible;
-using Content.Shared.Light;
+using Content.Shared.Light.Component;
 using Content.Shared.Throwing;
 using Robust.Server.GameObjects;
 using Robust.Shared.Audio;
index 1e70c3b078350ca468d231f5d8c2e9d174cb3b25..2f7a6d07a56885cca4abb0ad2c08bc592ad6dda6 100644 (file)
@@ -2,7 +2,7 @@ using System.Linq;
 using Content.Server.Light.Components;
 using Content.Server.Storage.Components;
 using Content.Shared.Interaction;
-using Content.Shared.Light;
+using Content.Shared.Light.Component;
 using Content.Shared.Popups;
 using JetBrains.Annotations;
 using Robust.Shared.Audio;
index c671db4219fd570e073d671b60376d754d9168ff..cfcbf97bc1d9e0546f8fcabf19a64216549d04ed 100644 (file)
@@ -14,6 +14,7 @@ using Content.Shared.Database;
 using Content.Shared.Hands.EntitySystems;
 using Content.Shared.Interaction;
 using Content.Shared.Light;
+using Content.Shared.Light.Component;
 using Content.Shared.Popups;
 using Robust.Server.GameObjects;
 using Robust.Shared.Audio;
diff --git a/Content.Shared/Light/Component/LightBulbComponent.cs b/Content.Shared/Light/Component/LightBulbComponent.cs
new file mode 100644 (file)
index 0000000..aa3a0f0
--- /dev/null
@@ -0,0 +1,129 @@
+using Robust.Shared.Audio;
+using Robust.Shared.GameStates;
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.Light.Component;
+
+/// <summary>
+/// Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless.
+/// TODO: Breaking and burning should probably be moved to another component eventually.
+/// </summary>
+[RegisterComponent]
+[NetworkedComponent]
+public sealed class LightBulbComponent : Robust.Shared.GameObjects.Component
+{
+    /// <summary>
+    /// The color of the lightbulb and the light it produces.
+    /// </summary>
+    [DataField("color")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public Color Color = Color.White;
+
+    /// <summary>
+    /// The type of lightbulb. Tube/bulb/etc...
+    /// </summary>
+    [DataField("bulb")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public LightBulbType Type = LightBulbType.Tube;
+
+    /// <summary>
+    /// The initial state of the lightbulb.
+    /// </summary>
+    [DataField("startingState")]
+    public LightBulbState State = LightBulbState.Normal;
+
+    /// <summary>
+    /// The temperature the air around the lightbulb is exposed to when the lightbulb burns out.
+    /// </summary>
+    [DataField("BurningTemperature")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public int BurningTemperature = 1400;
+
+    /// <summary>
+    /// Relates to how bright the light produced by the lightbulb is.
+    /// </summary>
+    [DataField("lightEnergy")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public float LightEnergy = 0.8f;
+
+    /// <summary>
+    /// The maximum radius of the point light source this light produces.
+    /// </summary>
+    [DataField("lightRadius")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public float LightRadius = 10;
+
+    /// <summary>
+    /// Relates to the falloff constant of the light produced by the lightbulb.
+    /// </summary>
+    [DataField("lightSoftness")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public float LightSoftness = 1;
+
+    /// <summary>
+    /// The amount of power used by the lightbulb when it's active.
+    /// </summary>
+    [DataField("PowerUse")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public int PowerUse = 60;
+
+    /// <summary>
+    /// The sound produced when the lightbulb breaks.
+    /// </summary>
+    [DataField("breakSound")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public SoundSpecifier BreakSound = new SoundCollectionSpecifier("GlassBreak");
+
+    #region Appearance
+
+    /// <summary>
+    /// The sprite state used when the lightbulb is intact.
+    /// </summary>
+    [DataField("normalSpriteState")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string NormalSpriteState = "normal";
+
+    /// <summary>
+    /// The sprite state used when the lightbulb is broken.
+    /// </summary>
+    [DataField("brokenSpriteState")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string BrokenSpriteState = "broken";
+
+    /// <summary>
+    /// The sprite state used when the lightbulb is burned.
+    /// </summary>
+    [DataField("burnedSpriteState")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string BurnedSpriteState = "burned";
+
+    #endregion Appearance
+}
+
+[Serializable, NetSerializable]
+public enum LightBulbState : byte
+{
+    Normal,
+    Broken,
+    Burned,
+}
+
+[Serializable, NetSerializable]
+public enum LightBulbVisuals : byte
+{
+    State,
+    Color
+}
+
+[Serializable, NetSerializable]
+public enum LightBulbType : byte
+{
+    Bulb,
+    Tube,
+}
+
+[Serializable, NetSerializable]
+public enum LightBulbVisualLayers : byte
+{
+    Base,
+}
diff --git a/Content.Shared/Light/SharedLightBulb.cs b/Content.Shared/Light/SharedLightBulb.cs
deleted file mode 100644 (file)
index 7599c33..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-using Robust.Shared.Serialization;
-
-namespace Content.Shared.Light
-{
-    [Serializable, NetSerializable]
-    public enum LightBulbState : byte
-    {
-        Normal,
-        Broken,
-        Burned,
-    }
-
-    [Serializable, NetSerializable]
-    public enum LightBulbVisuals : byte
-    {
-        State,
-        Color
-    }
-
-    [Serializable, NetSerializable]
-    public enum LightBulbType : byte
-    {
-        Bulb,
-        Tube,
-    }
-}
index 586f09fe20bf40330edc412771feb8e8998a369a..a0aa6b4330d0794e4bdbe6e6b12b2fe4d30e5a0e 100644 (file)
@@ -11,7 +11,9 @@
   - type: Sprite
     netsync: false
     sprite: Objects/Power/light_bulb.rsi
-    state: normal
+    layers:
+      - map: [ enum.LightBulbVisualLayers.Base ]
+        state: normal
   - type: LightBulb
   - type: Damageable
     damageContainer: Inorganic
       - !type:DoActsBehavior
         acts: [ "Destruction" ]
   - type: Appearance
-    visuals:
-    - type: LightBulbVisualizer
   - type: Tag
     tags:
     - Trash
   - type: Recyclable
   - type: SpaceGarbage
 
+- type: entity
+  parent: BaseLightbulb
+  id: BaseLightTube
+  abstract: true
+  components:
+  - type: Sprite
+    sprite:  Objects/Power/light_tube.rsi
+  - type: LightBulb
+    bulb: Tube
+
 # Lighting color values gathered from
 # https://andi-siess.de/rgb-to-color-temperature/
 # https://academo.org/demos/colour-temperature-relationship/
     lightEnergy: 1.0
     lightRadius: 6
     lightSoftness: 1.1
-  - type: Sprite
-    sprite: Objects/Power/light_bulb.rsi
-    state: normal
 
 - type: entity
-  parent: BaseLightbulb
+  parent: BaseLightTube
   name: fluorescent light tube
   id: LightTube
   description: A light fixture.
   components:
   - type: LightBulb
-    bulb: Tube
     color: "#FFE4CE" # 5000K color temp
     lightEnergy: 0.8
     lightRadius: 10
     lightSoftness: 1
     PowerUse: 25
-  - type: Sprite
-    sprite:  Objects/Power/light_tube.rsi
-    state: normal
 
 - type: entity
-  parent: BaseLightbulb
+  parent: BaseLightTube
   name: led light tube
   description: A high power high energy bulb.
   id: LedLightTube
   components:
   - type: LightBulb
-    bulb: Tube
     color: "#EEEEFF"
     lightEnergy: 1
     lightRadius: 15
     lightSoftness: 0.9
     BurningTemperature: 350
     PowerUse: 12
-  - type: Sprite
-    sprite:  Objects/Power/light_tube.rsi
-    state: normal
 
 - type: entity
-  parent: BaseLightbulb
+  parent: BaseLightTube
   name: exterior light tube
   description: A high power high energy bulb for the depths of space. May contain mercury.
   id: ExteriorLightTube
   components:
   - type: LightBulb
-    bulb: Tube
     color: "#B4FCF0"
     lightEnergy: 4.5
     lightRadius: 12
     lightSoftness: 0.5
     BurningTemperature: 350
     PowerUse: 100
-  - type: Sprite
-    sprite:  Objects/Power/light_tube.rsi
-    state: normal
 
 - type: entity
-  parent: BaseLightbulb
+  parent: BaseLightTube
   name: sodium light tube
   description: A high power high energy bulb for the depths of space. Salty.
   id: SodiumLightTube
   components:
   - type: LightBulb
-    bulb: Tube
     color: "#FFAF38"
     lightEnergy: 4
     lightRadius: 10
     lightSoftness: 0.5
     BurningTemperature: 350
     PowerUse: 100
-  - type: Sprite
-    sprite:  Objects/Power/light_tube.rsi
-    state: normal