From: TemporalOroboros Date: Sun, 7 May 2023 13:37:28 +0000 (-0700) Subject: Resolves ThrusterVisualizer is Obsolete (#13904) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=8536756db5b6f829539bd9138dc5a1b92a6ce565;p=space-station-14.git Resolves ThrusterVisualizer is Obsolete (#13904) Co-authored-by: metalgearsloth --- diff --git a/Content.Client/Shuttles/ThrusterComponent.cs b/Content.Client/Shuttles/ThrusterComponent.cs new file mode 100644 index 0000000000..85795b24a8 --- /dev/null +++ b/Content.Client/Shuttles/ThrusterComponent.cs @@ -0,0 +1,12 @@ +using Robust.Shared.GameStates; + +namespace Content.Client.Shuttles; + +/// +/// A component that emits a visible exhaust plume if the entity is an active thruster. +/// Managed by +/// +[RegisterComponent, NetworkedComponent, Access(typeof(ThrusterSystem))] +public sealed class ThrusterComponent : Component +{ +} diff --git a/Content.Client/Shuttles/ThrusterSystem.cs b/Content.Client/Shuttles/ThrusterSystem.cs new file mode 100644 index 0000000000..afa5b773db --- /dev/null +++ b/Content.Client/Shuttles/ThrusterSystem.cs @@ -0,0 +1,51 @@ +using Content.Shared.Shuttles.Components; +using Robust.Client.GameObjects; + +namespace Content.Client.Shuttles; + +/// +/// Handles making a thruster visibly turn on/emit an exhaust plume according to its state. +/// +public sealed class ThrusterSystem : VisualizerSystem +{ + /// + /// Updates whether or not the thruster is visibly active/thrusting. + /// + protected override void OnAppearanceChange(EntityUid uid, ThrusterComponent comp, ref AppearanceChangeEvent args) + { + if (args.Sprite == null + || !AppearanceSystem.TryGetData(uid, ThrusterVisualState.State, out var state, args.Component)) + return; + + args.Sprite.LayerSetVisible(ThrusterVisualLayers.ThrustOn, state); + SetThrusting( + uid, + state && AppearanceSystem.TryGetData(uid, ThrusterVisualState.Thrusting, out var thrusting, args.Component) && thrusting, + args.Sprite + ); + } + + /// + /// Sets whether or not the exhaust plume of the thruster is visible or not. + /// + private static void SetThrusting(EntityUid _, bool value, SpriteComponent sprite) + { + if (sprite.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out var thrustingLayer)) + { + sprite.LayerSetVisible(thrustingLayer, value); + } + + if (sprite.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out var unshadedLayer)) + { + sprite.LayerSetVisible(unshadedLayer, value); + } + } +} + +public enum ThrusterVisualLayers : byte +{ + Base, + ThrustOn, + Thrusting, + ThrustingUnshaded, +} diff --git a/Content.Client/Shuttles/ThrusterVisualizer.cs b/Content.Client/Shuttles/ThrusterVisualizer.cs deleted file mode 100644 index 3e56ef4c0d..0000000000 --- a/Content.Client/Shuttles/ThrusterVisualizer.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Content.Shared.Shuttles.Components; -using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; - -namespace Content.Client.Shuttles -{ - public sealed class ThrusterVisualizer : 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? spriteComponent)) return; - - component.TryGetData(ThrusterVisualState.State, out bool state); - - switch (state) - { - case true: - spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustOn, true); - - if (component.TryGetData(ThrusterVisualState.Thrusting, out bool thrusting) && thrusting) - { - if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out _)) - { - spriteComponent.LayerSetVisible(ThrusterVisualLayers.Thrusting, true); - } - - if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out _)) - { - spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustingUnshaded, true); - } - } - else - { - DisableThrusting(component, spriteComponent); - } - - break; - case false: - spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustOn, false); - DisableThrusting(component, spriteComponent); - break; - } - } - - private void DisableThrusting(AppearanceComponent component, SpriteComponent spriteComponent) - { - if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out _)) - { - spriteComponent.LayerSetVisible(ThrusterVisualLayers.Thrusting, false); - } - - if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out _)) - { - spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustingUnshaded, false); - } - } - } - - public enum ThrusterVisualLayers : byte - { - Base, - ThrustOn, - Thrusting, - ThrustingUnshaded, - } -} diff --git a/Content.Server/Shuttles/Components/ThrusterComponent.cs b/Content.Server/Shuttles/Components/ThrusterComponent.cs index a7713473c0..4adf3d7b80 100644 --- a/Content.Server/Shuttles/Components/ThrusterComponent.cs +++ b/Content.Server/Shuttles/Components/ThrusterComponent.cs @@ -1,12 +1,13 @@ using Content.Server.Shuttles.Systems; using Content.Shared.Construction.Prototypes; using Content.Shared.Damage; +using Robust.Shared.GameStates; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Server.Shuttles.Components { - [RegisterComponent] + [RegisterComponent, NetworkedComponent] [Access(typeof(ThrusterSystem))] public sealed class ThrusterComponent : Component { diff --git a/Resources/Prototypes/Entities/Structures/Shuttles/thrusters.yml b/Resources/Prototypes/Entities/Structures/Shuttles/thrusters.yml index f423f2b8e0..c50c67adb7 100644 --- a/Resources/Prototypes/Entities/Structures/Shuttles/thrusters.yml +++ b/Resources/Prototypes/Entities/Structures/Shuttles/thrusters.yml @@ -23,8 +23,7 @@ - type: Sprite netsync: false - type: Appearance - visuals: - - type: ThrusterVisualizer + - type: ThrusterVisuals - type: ApcPowerReceiver powerLoad: 1500 - type: ExtensionCableReceiver @@ -59,9 +58,11 @@ - state: thrust map: ["enum.ThrusterVisualLayers.ThrustOn"] shader: unshaded + visible: false - state: thrust_burn_unshaded map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"] shader: unshaded + visible: false offset: 0, 1 - type: entity @@ -82,9 +83,11 @@ - state: thrust map: ["enum.ThrusterVisualLayers.ThrustOn"] shader: unshaded + visible: false - state: thrust_burn_unshaded map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"] shader: unshaded + visible: false offset: 0, 1 - type: entity @@ -107,11 +110,14 @@ - state: thrust map: ["enum.ThrusterVisualLayers.ThrustOn"] shader: unshaded + visible: false - state: thrust_burn map: [ "enum.ThrusterVisualLayers.Thrusting" ] + visible: false - state: thrust_burn_unshaded map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"] shader: unshaded + visible: false - type: PointLight radius: 1.3 energy: 0.8 @@ -150,7 +156,9 @@ - state: thrust map: ["enum.ThrusterVisualLayers.ThrustOn"] shader: unshaded + visible: false - state: thrust_burn_unshaded map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"] shader: unshaded + visible: false offset: 0, 1