LockVisualizer (#25224)

* LockVisualizer

* Fix state

* Clean some code

* Make it component, fix tests fail

* Fix for StateUnlocked

Now it is possible to manually set the unlocked state and it will work!

* Optimize LockVisualizer, add check for unlocked state

* No todo I guess
This commit is contained in:
MilenVolf
2024-02-17 02:52:31 +03:00
committed by GitHub
parent 19a7b0592c
commit c7870882f6
27 changed files with 98 additions and 110 deletions

View File

@@ -0,0 +1,38 @@
using Content.Shared.Storage;
using Content.Shared.Lock;
using Robust.Client.GameObjects;
namespace Content.Client.Lock.Visualizers;
public sealed class LockVisualizerSystem : VisualizerSystem<LockVisualsComponent>
{
protected override void OnAppearanceChange(EntityUid uid, LockVisualsComponent comp, ref AppearanceChangeEvent args)
{
if (args.Sprite == null
|| !AppearanceSystem.TryGetData<bool>(uid, LockVisuals.Locked, out _, args.Component))
return;
// Lock state for the entity.
if (!AppearanceSystem.TryGetData<bool>(uid, LockVisuals.Locked, out var locked, args.Component))
locked = true;
var unlockedStateExist = args.Sprite.BaseRSI?.TryGetState(comp.StateUnlocked, out _);
if (AppearanceSystem.TryGetData<bool>(uid, StorageVisuals.Open, out var open, args.Component))
{
args.Sprite.LayerSetVisible(LockVisualLayers.Lock, !open);
}
else if (!(bool) unlockedStateExist!)
args.Sprite.LayerSetVisible(LockVisualLayers.Lock, locked);
if (!open && (bool) unlockedStateExist!)
{
args.Sprite.LayerSetState(LockVisualLayers.Lock, locked ? comp.StateLocked : comp.StateUnlocked);
}
}
}
public enum LockVisualLayers : byte
{
Lock
}

View File

@@ -0,0 +1,20 @@
namespace Content.Client.Lock.Visualizers;
[RegisterComponent]
[Access(typeof(LockVisualizerSystem))]
public sealed partial class LockVisualsComponent : Component
{
/// <summary>
/// The RSI state used for the lock indicator while the entity is locked.
/// </summary>
[DataField("stateLocked")]
[ViewVariables(VVAccess.ReadWrite)]
public string? StateLocked = "locked";
/// <summary>
/// The RSI state used for the lock indicator entity is unlocked.
/// </summary>
[DataField("stateUnlocked")]
[ViewVariables(VVAccess.ReadWrite)]
public string? StateUnlocked = "unlocked";
}

View File

@@ -1,7 +1,5 @@
using Content.Client.Storage.Visualizers;
using Content.Shared.Singularity.Components;
using Content.Shared.Singularity.Components;
using Content.Shared.Singularity.EntitySystems;
using Content.Shared.Storage;
using Robust.Client.GameObjects;
namespace Content.Client.Singularity.Systems;
@@ -21,14 +19,6 @@ public sealed class EmitterSystem : SharedEmitterSystem
if (args.Sprite == null)
return;
if (args.Sprite.LayerMapTryGet(StorageVisualLayers.Lock, out var lockLayer))
{
if (!_appearance.TryGetData<bool>(uid, StorageVisuals.Locked, out var locked, args.Component))
locked = false;
args.Sprite.LayerSetVisible(lockLayer, locked);
}
if (!_appearance.TryGetData<EmitterVisualState>(uid, EmitterVisuals.VisualState, out var state, args.Component))
state = EmitterVisualState.Off;

View File

@@ -70,25 +70,11 @@ public sealed class EntityStorageVisualizerSystem : VisualizerSystem<EntityStora
args.Sprite.LayerSetState(StorageVisualLayers.Base, comp.StateBaseClosed);
}
}
// Lock state for the storage entity. TODO: Split into its own visualizer.
if (AppearanceSystem.TryGetData<bool>(uid, StorageVisuals.CanLock, out var canLock, args.Component) && canLock)
{
if (!AppearanceSystem.TryGetData<bool>(uid, StorageVisuals.Locked, out var locked, args.Component))
locked = true;
args.Sprite.LayerSetVisible(StorageVisualLayers.Lock, !open);
if (!open)
{
args.Sprite.LayerSetState(StorageVisualLayers.Lock, locked ? comp.StateLocked : comp.StateUnlocked);
}
}
}
}
public enum StorageVisualLayers : byte
{
Base,
Door,
Lock
Door
}

View File

@@ -32,20 +32,6 @@ public sealed partial class EntityStorageVisualsComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
public string? StateDoorClosed;
/// <summary>
/// The RSI state used for the lock indicator while the storage is locked.
/// </summary>
[DataField("stateLocked")]
[ViewVariables(VVAccess.ReadWrite)]
public string? StateLocked = "locked";
/// <summary>
/// The RSI state used for the lock indicator while the storage is unlocked.
/// </summary>
[DataField("stateUnlocked")]
[ViewVariables(VVAccess.ReadWrite)]
public string? StateUnlocked = "unlocked";
/// <summary>
/// The drawdepth the object has when it's open
/// </summary>