From 193b9f467dd03cdfb72c3b063b88a5dd367fa28a Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 8 Aug 2022 13:44:16 +1200 Subject: [PATCH] Remove string appearance keys (#10114) --- .../Atmos/Monitor/AtmosMonitorVisualizer.cs | 7 +++-- Content.Client/Damage/DamageVisualizer.cs | 29 ++++--------------- .../Damage/DamageVisualizerComponent.cs | 2 +- .../Visualizer/FoldableVisualizer.cs | 3 +- .../Visualizer/RollerbedVisualizer.cs | 5 ++-- .../Monitor/Systems/AtmosMonitoringSystem.cs | 11 +++---- .../Buckle/Components/StrapComponent.cs | 4 +-- .../Completions/VisualizerDataInt.cs | 6 +--- .../Monitor/AtmosAlarmThresholdPrototype.cs | 6 ++++ .../Buckle/Components/SharedStrapComponent.cs | 3 +- .../Foldable/SharedFoldableSystem.cs | 9 ++++-- .../SubFloor/SubFloorHideComponent.cs | 4 +-- .../Toggleable/ToggleableLightVisuals.cs | 17 ++++++++++- .../Structures/Piping/Atmospherics/unary.yml | 4 +-- 14 files changed, 56 insertions(+), 54 deletions(-) diff --git a/Content.Client/Atmos/Monitor/AtmosMonitorVisualizer.cs b/Content.Client/Atmos/Monitor/AtmosMonitorVisualizer.cs index 1a1a6d458d..76591b6ffc 100644 --- a/Content.Client/Atmos/Monitor/AtmosMonitorVisualizer.cs +++ b/Content.Client/Atmos/Monitor/AtmosMonitorVisualizer.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Content.Shared.Atmos.Monitor; +using Content.Shared.Power; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Shared.GameObjects; @@ -40,7 +41,7 @@ namespace Content.Client.Atmos.Monitor if (!sprite.LayerMapTryGet(_layerMap, out int layer)) return; - if (component.TryGetData("powered", out var powered)) + if (component.TryGetData(PowerDeviceVisuals.Powered, out var powered)) { if (_hideOnDepowered != null) foreach (var visLayer in _hideOnDepowered) @@ -53,12 +54,12 @@ namespace Content.Client.Atmos.Monitor sprite.LayerSetState(setStateLayer, new RSI.StateId(state)); } - if (component.TryGetData("offset", out Vector2 offset)) + if (component.TryGetData(AtmosMonitorVisuals.Offset, out Vector2 offset)) { sprite.Offset = offset; } - if (component.TryGetData("alarmType", out var alarmType) + if (component.TryGetData(AtmosMonitorVisuals.AlarmType, out var alarmType) && powered) if (_alarmStates.TryGetValue(alarmType, out var state)) sprite.LayerSetState(layer, new RSI.StateId(state)); diff --git a/Content.Client/Damage/DamageVisualizer.cs b/Content.Client/Damage/DamageVisualizer.cs index 6fbabe15ac..bc45972dce 100644 --- a/Content.Client/Damage/DamageVisualizer.cs +++ b/Content.Client/Damage/DamageVisualizer.cs @@ -82,7 +82,7 @@ namespace Content.Client.Damage /// completely invisible. /// [DataField("targetLayers")] - private List? _targetLayers; + private List? _targetLayers; /// /// The actual sprites for every damage group @@ -383,18 +383,8 @@ namespace Content.Client.Damage // // If the layer doesn't have a base state, or // the layer key just doesn't exist, we skip it. - foreach (var keyString in _targetLayers) + foreach (var key in _targetLayers) { - object key; - if (IoCManager.Resolve().TryParseEnumReference(keyString, out var @enum)) - { - key = @enum; - } - else - { - key = keyString; - } - if (!spriteComponent.LayerMapTryGet(key, out int index) || spriteComponent.LayerGetState(index).ToString() == null) { @@ -562,20 +552,11 @@ namespace Content.Client.Damage /// private void UpdateDisabledLayers(SpriteComponent spriteComponent, AppearanceComponent component, DamageVisualizerDataComponent damageData) { - foreach (object layer in damageData.TargetLayerMapKeys) + foreach (var layer in damageData.TargetLayerMapKeys) { bool? layerStatus = null; - switch (layer) - { - case Enum layerEnum: - if (component.TryGetData(layerEnum, out var layerStateEnum)) - layerStatus = layerStateEnum; - break; - case string layerString: - if (component.TryGetData(layerString, out var layerStateString)) - layerStatus = layerStateString; - break; - } + if (component.TryGetData(layer, out var layerStateEnum)) + layerStatus = layerStateEnum; if (layerStatus == null) continue; diff --git a/Content.Client/Damage/DamageVisualizerComponent.cs b/Content.Client/Damage/DamageVisualizerComponent.cs index cd4b401251..984cf0e2aa 100644 --- a/Content.Client/Damage/DamageVisualizerComponent.cs +++ b/Content.Client/Damage/DamageVisualizerComponent.cs @@ -13,7 +13,7 @@ namespace Content.Client.Damage [RegisterComponent] public sealed class DamageVisualizerDataComponent : Component { - public List TargetLayerMapKeys = new(); + public List TargetLayerMapKeys = new(); public bool Disabled = false; public bool Valid = true; public FixedPoint2 LastDamageThreshold = FixedPoint2.Zero; diff --git a/Content.Client/Visualizer/FoldableVisualizer.cs b/Content.Client/Visualizer/FoldableVisualizer.cs index 6b2861dc7b..0e10f70b02 100644 --- a/Content.Client/Visualizer/FoldableVisualizer.cs +++ b/Content.Client/Visualizer/FoldableVisualizer.cs @@ -2,6 +2,7 @@ using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Serialization.Manager.Attributes; +using static Content.Shared.Foldable.SharedFoldableSystem; namespace Content.Client.Visualizer; @@ -19,7 +20,7 @@ public sealed class FoldableVisualizer : AppearanceVisualizer if (!entManager.TryGetComponent(appearance.Owner, out SpriteComponent? sprite)) return; - if (appearance.TryGetData("FoldedState", out bool folded) && folded) + if (appearance.TryGetData(FoldedVisuals.State, out bool folded) && folded) { sprite.LayerSetState(FoldableVisualLayers.Base, $"{_key}_folded"); } diff --git a/Content.Client/Visualizer/RollerbedVisualizer.cs b/Content.Client/Visualizer/RollerbedVisualizer.cs index 053d521d57..c93ae7ac6e 100644 --- a/Content.Client/Visualizer/RollerbedVisualizer.cs +++ b/Content.Client/Visualizer/RollerbedVisualizer.cs @@ -1,4 +1,5 @@ -using JetBrains.Annotations; +using Content.Shared.Buckle.Components; +using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -20,7 +21,7 @@ namespace Content.Client.Visualizer if (!entManager.TryGetComponent(appearance.Owner, out SpriteComponent? sprite)) return; - if (appearance.TryGetData("StrapState", out bool strapped) && strapped) + if (appearance.TryGetData(StrapVisuals.State, out bool strapped) && strapped) { sprite.LayerSetState(0, $"{_key}_buckled"); } diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs index 8a443c412d..c3f3300d11 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs @@ -139,7 +139,7 @@ namespace Content.Server.Atmos.Monitor.Systems coords = coords.Offset(rotPos); transform.Coordinates = coords; - appearance.SetData("offset", - new Vector2i(0, -1)); + appearance.SetData(AtmosMonitorVisuals.Offset, - new Vector2i(0, -1)); transform.Anchored = true; } @@ -192,7 +192,7 @@ namespace Content.Server.Atmos.Monitor.Systems if (component.DisplayMaxAlarmInNet) { if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent)) - appearanceComponent.SetData("alarmType", component.HighestAlarmInNetwork); + appearanceComponent.SetData(AtmosMonitorVisuals.AlarmType, component.HighestAlarmInNetwork); if (component.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger) PlayAlertSound(uid, component); } @@ -227,10 +227,7 @@ namespace Content.Server.Atmos.Monitor.Systems } if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent)) - { - appearanceComponent.SetData("powered", args.Powered); - appearanceComponent.SetData("alarmType", component.LastAlarmState); - } + appearanceComponent.SetData(AtmosMonitorVisuals.AlarmType, component.LastAlarmState); } private void OnFireEvent(EntityUid uid, AtmosMonitorComponent component, ref TileFireEvent args) @@ -341,7 +338,7 @@ namespace Content.Server.Atmos.Monitor.Systems if (!Resolve(uid, ref monitor)) return; monitor.LastAlarmState = state; if (EntityManager.TryGetComponent(monitor.Owner, out AppearanceComponent? appearanceComponent)) - appearanceComponent.SetData("alarmType", monitor.LastAlarmState); + appearanceComponent.SetData(AtmosMonitorVisuals.AlarmType, monitor.LastAlarmState); BroadcastAlertPacket(monitor, alarms); diff --git a/Content.Server/Buckle/Components/StrapComponent.cs b/Content.Server/Buckle/Components/StrapComponent.cs index 97cdf70e96..5432c19ae6 100644 --- a/Content.Server/Buckle/Components/StrapComponent.cs +++ b/Content.Server/Buckle/Components/StrapComponent.cs @@ -115,7 +115,7 @@ namespace Content.Server.Buckle.Components // Update the visuals of the strap object if (IoCManager.Resolve().TryGetComponent(Owner, out var appearance)) { - appearance.SetData("StrapState", true); + appearance.SetData(StrapVisuals.State, true); } Dirty(); @@ -133,7 +133,7 @@ namespace Content.Server.Buckle.Components { if (IoCManager.Resolve().TryGetComponent(Owner, out var appearance)) { - appearance.SetData("StrapState", false); + appearance.SetData(StrapVisuals.State, false); } _occupiedSize -= buckle.Size; diff --git a/Content.Server/Construction/Completions/VisualizerDataInt.cs b/Content.Server/Construction/Completions/VisualizerDataInt.cs index bfbd838ca3..1ffe619345 100644 --- a/Content.Server/Construction/Completions/VisualizerDataInt.cs +++ b/Content.Server/Construction/Completions/VisualizerDataInt.cs @@ -1,4 +1,4 @@ -using Content.Shared.Construction; +using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.Reflection; using Robust.Shared.Serialization; @@ -22,10 +22,6 @@ namespace Content.Server.Construction.Completions { appearance.SetData(@enum, Data); } - else - { - appearance.SetData(Key, Data); - } } } } diff --git a/Content.Shared/Atmos/Monitor/AtmosAlarmThresholdPrototype.cs b/Content.Shared/Atmos/Monitor/AtmosAlarmThresholdPrototype.cs index a671a1817d..794aa2fa55 100644 --- a/Content.Shared/Atmos/Monitor/AtmosAlarmThresholdPrototype.cs +++ b/Content.Shared/Atmos/Monitor/AtmosAlarmThresholdPrototype.cs @@ -249,4 +249,10 @@ namespace Content.Shared.Atmos.Monitor Pressure, Gas } + + public enum AtmosMonitorVisuals : byte + { + Offset, + AlarmType, + } } diff --git a/Content.Shared/Buckle/Components/SharedStrapComponent.cs b/Content.Shared/Buckle/Components/SharedStrapComponent.cs index 74d3d4ecc1..5f9c5574be 100644 --- a/Content.Shared/Buckle/Components/SharedStrapComponent.cs +++ b/Content.Shared/Buckle/Components/SharedStrapComponent.cs @@ -96,6 +96,7 @@ namespace Content.Shared.Buckle.Components public enum StrapVisuals : byte { RotationAngle, - BuckledState + BuckledState, + State } } diff --git a/Content.Shared/Foldable/SharedFoldableSystem.cs b/Content.Shared/Foldable/SharedFoldableSystem.cs index 27603d4f2d..c4479bb40d 100644 --- a/Content.Shared/Foldable/SharedFoldableSystem.cs +++ b/Content.Shared/Foldable/SharedFoldableSystem.cs @@ -7,8 +7,6 @@ namespace Content.Shared.Foldable; [UsedImplicitly] public abstract class SharedFoldableSystem : EntitySystem { - private const string FoldKey = "FoldedState"; - public override void Initialize() { base.Initialize(); @@ -50,7 +48,7 @@ public abstract class SharedFoldableSystem : EntitySystem Dirty(component); if (TryComp(component.Owner, out AppearanceComponent? appearance)) - appearance.SetData(FoldKey, folded); + appearance.SetData(FoldedVisuals.State, folded); } private void OnInsertEvent(EntityUid uid, FoldableComponent component, ContainerGettingInsertedAttemptEvent args) @@ -58,4 +56,9 @@ public abstract class SharedFoldableSystem : EntitySystem if (!component.IsFolded) args.Cancel(); } + + public enum FoldedVisuals : byte + { + State + } } diff --git a/Content.Shared/SubFloor/SubFloorHideComponent.cs b/Content.Shared/SubFloor/SubFloorHideComponent.cs index b9c581d4e4..e3a170b89d 100644 --- a/Content.Shared/SubFloor/SubFloorHideComponent.cs +++ b/Content.Shared/SubFloor/SubFloorHideComponent.cs @@ -49,8 +49,8 @@ namespace Content.Shared.SubFloor /// Sprite layer keys for the layers that are always visible, even if the entity is below a floor tile. E.g., /// the vent part of a vent is always visible, even though the piping is hidden. /// - [DataField("visibleLayers", customTypeSerializer:typeof(CustomHashSetSerializer))] - public HashSet VisibleLayers = new() { SubfloorLayers.FirstLayer }; + [DataField("visibleLayers")] + public HashSet VisibleLayers = new() { SubfloorLayers.FirstLayer }; /// /// The entities this subfloor is revealed by. diff --git a/Content.Shared/Toggleable/ToggleableLightVisuals.cs b/Content.Shared/Toggleable/ToggleableLightVisuals.cs index ab96d16b26..72e8ed4926 100644 --- a/Content.Shared/Toggleable/ToggleableLightVisuals.cs +++ b/Content.Shared/Toggleable/ToggleableLightVisuals.cs @@ -4,8 +4,23 @@ namespace Content.Shared.Toggleable; // Appearance Data key [Serializable, NetSerializable] -public enum ToggleableLightVisuals +public enum ToggleableLightVisuals : byte { Enabled, Color } + +/// +/// Generic sprite layer keys. +/// +[Serializable, NetSerializable] +public enum LightLayers : byte +{ + Light, + + /// + /// Used as a key for generic unshaded layers. Not necessarily related to an entity with an actual light source. + /// Use this instead of creating a unique single-purpose "unshaded" enum for every visualizer. + /// + Unshaded, +} diff --git a/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml b/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml index f408df273b..2963e17f6f 100644 --- a/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml +++ b/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml @@ -163,7 +163,7 @@ map: [ "enum.SubfloorLayers.FirstLayer" ] - state: injector-unshaded shader: unshaded - map: [ "unshaded" ] + map: [ "enum.LightLayers.Unshaded" ] color: "#990000" - type: GenericVisualizer visuals: @@ -181,7 +181,7 @@ - type: SubFloorHide visibleLayers: - enum.SubfloorLayers.FirstLayer - - unshaded + - enum.LightLayers.Unshaded - type: entity parent: BaseMachinePowered