mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
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 (cherry picked from commit c7870882f6f956eea07cbb4738ae45c8805c8ce6)
This commit is contained in:
38
Content.Client/Lock/Visualizers/LockVisualizerSystem.cs
Normal file
38
Content.Client/Lock/Visualizers/LockVisualizerSystem.cs
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user