diff --git a/Content.Client/Light/EntitySystems/LightBulbSystem.cs b/Content.Client/Light/EntitySystems/LightBulbSystem.cs new file mode 100644 index 0000000000..5130308c93 --- /dev/null +++ b/Content.Client/Light/EntitySystems/LightBulbSystem.cs @@ -0,0 +1,36 @@ +using Content.Shared.Light.Component; +using Robust.Client.GameObjects; + +namespace Content.Client.Light.Visualizers; + +public sealed class LightBulbSystem : VisualizerSystem +{ + protected override void OnAppearanceChange(EntityUid uid, LightBulbComponent comp, ref AppearanceChangeEvent args) + { + if (args.Sprite == null) + return; + + // update sprite state + if (AppearanceSystem.TryGetData(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(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 index 228f2e57ee..0000000000 --- a/Content.Client/Light/Visualizers/LightBulbVisualizer.cs +++ /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(); - 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 index 39b3025446..0000000000 --- a/Content.Server/Light/Components/LightBulbComponent.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Content.Server.Light.EntitySystems; -using Content.Shared.Light; -using Robust.Shared.Audio; - -namespace Content.Server.Light.Components -{ - /// - /// Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless. - /// - [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"); - } -} diff --git a/Content.Server/Light/Components/LightReplacerComponent.cs b/Content.Server/Light/Components/LightReplacerComponent.cs index de10898dee..8835fb0c84 100644 --- a/Content.Server/Light/Components/LightReplacerComponent.cs +++ b/Content.Server/Light/Components/LightReplacerComponent.cs @@ -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; diff --git a/Content.Server/Light/Components/PoweredLightComponent.cs b/Content.Server/Light/Components/PoweredLightComponent.cs index 2c0e6ba052..0088aad335 100644 --- a/Content.Server/Light/Components/PoweredLightComponent.cs +++ b/Content.Server/Light/Components/PoweredLightComponent.cs @@ -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; diff --git a/Content.Server/Light/EntitySystems/LightBulbSystem.cs b/Content.Server/Light/EntitySystems/LightBulbSystem.cs index 4c00830c98..75e34fca36 100644 --- a/Content.Server/Light/EntitySystems/LightBulbSystem.cs +++ b/Content.Server/Light/EntitySystems/LightBulbSystem.cs @@ -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; diff --git a/Content.Server/Light/EntitySystems/LightReplacerSystem.cs b/Content.Server/Light/EntitySystems/LightReplacerSystem.cs index 1e70c3b078..2f7a6d07a5 100644 --- a/Content.Server/Light/EntitySystems/LightReplacerSystem.cs +++ b/Content.Server/Light/EntitySystems/LightReplacerSystem.cs @@ -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; diff --git a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs index c671db4219..cfcbf97bc1 100644 --- a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs +++ b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs @@ -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 index 0000000000..aa3a0f0be7 --- /dev/null +++ b/Content.Shared/Light/Component/LightBulbComponent.cs @@ -0,0 +1,129 @@ +using Robust.Shared.Audio; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; + +namespace Content.Shared.Light.Component; + +/// +/// 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. +/// +[RegisterComponent] +[NetworkedComponent] +public sealed class LightBulbComponent : Robust.Shared.GameObjects.Component +{ + /// + /// The color of the lightbulb and the light it produces. + /// + [DataField("color")] + [ViewVariables(VVAccess.ReadWrite)] + public Color Color = Color.White; + + /// + /// The type of lightbulb. Tube/bulb/etc... + /// + [DataField("bulb")] + [ViewVariables(VVAccess.ReadWrite)] + public LightBulbType Type = LightBulbType.Tube; + + /// + /// The initial state of the lightbulb. + /// + [DataField("startingState")] + public LightBulbState State = LightBulbState.Normal; + + /// + /// The temperature the air around the lightbulb is exposed to when the lightbulb burns out. + /// + [DataField("BurningTemperature")] + [ViewVariables(VVAccess.ReadWrite)] + public int BurningTemperature = 1400; + + /// + /// Relates to how bright the light produced by the lightbulb is. + /// + [DataField("lightEnergy")] + [ViewVariables(VVAccess.ReadWrite)] + public float LightEnergy = 0.8f; + + /// + /// The maximum radius of the point light source this light produces. + /// + [DataField("lightRadius")] + [ViewVariables(VVAccess.ReadWrite)] + public float LightRadius = 10; + + /// + /// Relates to the falloff constant of the light produced by the lightbulb. + /// + [DataField("lightSoftness")] + [ViewVariables(VVAccess.ReadWrite)] + public float LightSoftness = 1; + + /// + /// The amount of power used by the lightbulb when it's active. + /// + [DataField("PowerUse")] + [ViewVariables(VVAccess.ReadWrite)] + public int PowerUse = 60; + + /// + /// The sound produced when the lightbulb breaks. + /// + [DataField("breakSound")] + [ViewVariables(VVAccess.ReadWrite)] + public SoundSpecifier BreakSound = new SoundCollectionSpecifier("GlassBreak"); + + #region Appearance + + /// + /// The sprite state used when the lightbulb is intact. + /// + [DataField("normalSpriteState")] + [ViewVariables(VVAccess.ReadWrite)] + public string NormalSpriteState = "normal"; + + /// + /// The sprite state used when the lightbulb is broken. + /// + [DataField("brokenSpriteState")] + [ViewVariables(VVAccess.ReadWrite)] + public string BrokenSpriteState = "broken"; + + /// + /// The sprite state used when the lightbulb is burned. + /// + [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 index 7599c3340b..0000000000 --- a/Content.Shared/Light/SharedLightBulb.cs +++ /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, - } -} diff --git a/Resources/Prototypes/Entities/Objects/Power/lights.yml b/Resources/Prototypes/Entities/Objects/Power/lights.yml index 586f09fe20..a0aa6b4330 100644 --- a/Resources/Prototypes/Entities/Objects/Power/lights.yml +++ b/Resources/Prototypes/Entities/Objects/Power/lights.yml @@ -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 @@ -55,14 +57,22 @@ - !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/ @@ -78,77 +88,58 @@ 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