Remove string appearance keys (#10114)
This commit is contained in:
@@ -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<bool>("powered", out var powered))
|
||||
if (component.TryGetData<bool>(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<Vector2>("offset", out Vector2 offset))
|
||||
if (component.TryGetData<Vector2>(AtmosMonitorVisuals.Offset, out Vector2 offset))
|
||||
{
|
||||
sprite.Offset = offset;
|
||||
}
|
||||
|
||||
if (component.TryGetData<AtmosMonitorAlarmType>("alarmType", out var alarmType)
|
||||
if (component.TryGetData<AtmosMonitorAlarmType>(AtmosMonitorVisuals.AlarmType, out var alarmType)
|
||||
&& powered)
|
||||
if (_alarmStates.TryGetValue(alarmType, out var state))
|
||||
sprite.LayerSetState(layer, new RSI.StateId(state));
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Content.Client.Damage
|
||||
/// completely invisible.
|
||||
/// </remarks>
|
||||
[DataField("targetLayers")]
|
||||
private List<string>? _targetLayers;
|
||||
private List<Enum>? _targetLayers;
|
||||
|
||||
/// <summary>
|
||||
/// 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<IReflectionManager>().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
|
||||
/// </summary>
|
||||
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<bool>(layerEnum, out var layerStateEnum))
|
||||
layerStatus = layerStateEnum;
|
||||
break;
|
||||
case string layerString:
|
||||
if (component.TryGetData<bool>(layerString, out var layerStateString))
|
||||
layerStatus = layerStateString;
|
||||
break;
|
||||
}
|
||||
if (component.TryGetData<bool>(layer, out var layerStateEnum))
|
||||
layerStatus = layerStateEnum;
|
||||
|
||||
if (layerStatus == null)
|
||||
continue;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Content.Client.Damage
|
||||
[RegisterComponent]
|
||||
public sealed class DamageVisualizerDataComponent : Component
|
||||
{
|
||||
public List<object> TargetLayerMapKeys = new();
|
||||
public List<Enum> TargetLayerMapKeys = new();
|
||||
public bool Disabled = false;
|
||||
public bool Valid = true;
|
||||
public FixedPoint2 LastDamageThreshold = FixedPoint2.Zero;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace Content.Server.Buckle.Components
|
||||
// Update the visuals of the strap object
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent>(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<IEntityManager>().TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
{
|
||||
appearance.SetData("StrapState", false);
|
||||
appearance.SetData(StrapVisuals.State, false);
|
||||
}
|
||||
|
||||
_occupiedSize -= buckle.Size;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,4 +249,10 @@ namespace Content.Shared.Atmos.Monitor
|
||||
Pressure,
|
||||
Gas
|
||||
}
|
||||
|
||||
public enum AtmosMonitorVisuals : byte
|
||||
{
|
||||
Offset,
|
||||
AlarmType,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ namespace Content.Shared.Buckle.Components
|
||||
public enum StrapVisuals : byte
|
||||
{
|
||||
RotationAngle,
|
||||
BuckledState
|
||||
BuckledState,
|
||||
State
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
/// </summary>
|
||||
[DataField("visibleLayers", customTypeSerializer:typeof(CustomHashSetSerializer<object, AppearanceKeySerializer>))]
|
||||
public HashSet<object> VisibleLayers = new() { SubfloorLayers.FirstLayer };
|
||||
[DataField("visibleLayers")]
|
||||
public HashSet<Enum> VisibleLayers = new() { SubfloorLayers.FirstLayer };
|
||||
|
||||
/// <summary>
|
||||
/// The entities this subfloor is revealed by.
|
||||
|
||||
@@ -4,8 +4,23 @@ namespace Content.Shared.Toggleable;
|
||||
|
||||
// Appearance Data key
|
||||
[Serializable, NetSerializable]
|
||||
public enum ToggleableLightVisuals
|
||||
public enum ToggleableLightVisuals : byte
|
||||
{
|
||||
Enabled,
|
||||
Color
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generic sprite layer keys.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public enum LightLayers : byte
|
||||
{
|
||||
Light,
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
Unshaded,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user