]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
LockVisualizer (#25224)
authorMilenVolf <63782763+MilenVolf@users.noreply.github.com>
Fri, 16 Feb 2024 23:52:31 +0000 (02:52 +0300)
committerGitHub <noreply@github.com>
Fri, 16 Feb 2024 23:52:31 +0000 (16:52 -0700)
* 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

27 files changed:
Content.Client/Lock/Visualizers/LockVisualizerSystem.cs [new file with mode: 0644]
Content.Client/Lock/Visualizers/LockVisualsComponent.cs [new file with mode: 0644]
Content.Client/Singularity/Systems/EmitterSystem.cs
Content.Client/Storage/Visualizers/EntityStorageVisualizerSystem.cs
Content.Client/Storage/Visualizers/EntityStorageVisualsComponent.cs
Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs
Content.Shared/Atmos/Piping/Binary/Components/SharedGasCanisterComponent.cs
Content.Shared/Lock/LockComponent.cs
Content.Shared/Lock/LockSystem.cs
Content.Shared/Security/DeployableBarrierVisuals.cs [deleted file]
Content.Shared/Security/Systems/DeployableBarrierSystem.cs
Content.Shared/Storage/StorageComponent.cs
Resources/Prototypes/Entities/Objects/Specific/Security/barrier.yml
Resources/Prototypes/Entities/Objects/Specific/Xenoarchaeology/artifact_equipment.yml
Resources/Prototypes/Entities/Structures/Machines/anomaly_equipment.yml
Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/emitter.yml
Resources/Prototypes/Entities/Structures/Storage/Canisters/gas_canisters.yml
Resources/Prototypes/Entities/Structures/Storage/Closets/Lockers/base_structurelockers.yml
Resources/Prototypes/Entities/Structures/Storage/Closets/base_structureclosets.yml
Resources/Prototypes/Entities/Structures/Storage/Crates/base_structurecrates.yml
Resources/Textures/Objects/Specific/Security/barrier.rsi/locked.png [moved from Resources/Textures/Objects/Specific/Security/barrier.rsi/deployed.png with 100% similarity]
Resources/Textures/Objects/Specific/Security/barrier.rsi/meta.json
Resources/Textures/Structures/Power/Generation/Singularity/emitter.rsi/locked.png [moved from Resources/Textures/Structures/Power/Generation/Singularity/emitter.rsi/lock.png with 100% similarity]
Resources/Textures/Structures/Power/Generation/Singularity/emitter.rsi/meta.json
Resources/Textures/Structures/Storage/canister.rsi/locked.png [moved from Resources/Textures/Structures/Storage/canister.rsi/can-locked.png with 100% similarity]
Resources/Textures/Structures/Storage/canister.rsi/meta.json
Resources/Textures/Structures/Storage/canister.rsi/unlocked.png [moved from Resources/Textures/Structures/Storage/canister.rsi/can-unlocked.png with 100% similarity]

diff --git a/Content.Client/Lock/Visualizers/LockVisualizerSystem.cs b/Content.Client/Lock/Visualizers/LockVisualizerSystem.cs
new file mode 100644 (file)
index 0000000..1329a69
--- /dev/null
@@ -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
+}
diff --git a/Content.Client/Lock/Visualizers/LockVisualsComponent.cs b/Content.Client/Lock/Visualizers/LockVisualsComponent.cs
new file mode 100644 (file)
index 0000000..93844d6
--- /dev/null
@@ -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";
+}
index 5eb80928d88d872f013d2ddea02364c5c8b1ff6c..e3396d74a299991b73c083c010bafb972d147ef3 100644 (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;
 
index 772f516a6920114a53920263d175ae89d1a50283..ee4f2fdfd6cb55519d556936380c9319f3205b93 100644 (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
 }
index dc171d6c54e0dc7a5cc0d1d9683f96e6dc347c57..2215d8cd70d0840ff106207fddcb8bf342904c42 100644 (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>
index e1e7b2a7013decf5b125fa4167a2b27142d7cd30..64d02d793bc0c9b244505e08e0bff40787552900 100644 (file)
@@ -17,7 +17,6 @@ using Content.Shared.Hands.EntitySystems;
 using Content.Shared.Interaction;
 using Content.Shared.Lock;
 using Robust.Server.GameObjects;
-using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
 using Robust.Shared.Player;
@@ -54,7 +53,6 @@ public sealed class GasCanisterSystem : EntitySystem
         SubscribeLocalEvent<GasCanisterComponent, GasCanisterHoldingTankEjectMessage>(OnHoldingTankEjectMessage);
         SubscribeLocalEvent<GasCanisterComponent, GasCanisterChangeReleasePressureMessage>(OnCanisterChangeReleasePressure);
         SubscribeLocalEvent<GasCanisterComponent, GasCanisterChangeReleaseValveMessage>(OnCanisterChangeReleaseValve);
-        SubscribeLocalEvent<GasCanisterComponent, LockToggledEvent>(OnLockToggled);
     }
 
     /// <summary>
@@ -78,11 +76,6 @@ public sealed class GasCanisterSystem : EntitySystem
     {
         // Ensure container
         _slots.AddItemSlot(uid, comp.ContainerName, comp.GasTankSlot);
-
-        if (TryComp<LockComponent>(uid, out var lockComp))
-        {
-            _appearance.SetData(uid, GasCanisterVisuals.Locked, lockComp.Locked);
-        }
     }
 
     private void DirtyUI(EntityUid uid,
@@ -309,11 +302,6 @@ public sealed class GasCanisterSystem : EntitySystem
         args.GasMixtures = new Dictionary<string, GasMixture?> { {Name(uid), component.Air} };
     }
 
-    private void OnLockToggled(EntityUid uid, GasCanisterComponent component, ref LockToggledEvent args)
-    {
-        _appearance.SetData(uid, GasCanisterVisuals.Locked, args.Locked);
-    }
-
     /// <summary>
     /// Check if the canister is locked, playing its sound and popup if so.
     /// </summary>
index 23300cb2a01bc13e824136b9ae1a9104f9b84ff9..1203639e0928b48b87ad278f94feff5cd7bcd1b0 100644 (file)
@@ -21,8 +21,7 @@ namespace Content.Shared.Atmos.Piping.Binary.Components
     public enum GasCanisterVisuals
     {
         PressureState,
-        TankInserted,
-        Locked
+        TankInserted
     }
 
     #endregion
index b3c46597498ad21ccf64de784aee18e340872935..5587fc2698badd2d3f96406cdebd308387db5e6b 100644 (file)
@@ -113,3 +113,10 @@ public sealed partial class UnlockDoAfter : DoAfterEvent
         return this;
     }
 }
+
+[NetSerializable]
+[Serializable]
+public enum LockVisuals : byte
+{
+    Locked
+}
index e5f53b4080e96670fb9ded19a3c524bdfbdd1bc2..a01c5ace4d4dffbae3fe554d355b67622fdc406f 100644 (file)
@@ -7,11 +7,9 @@ using Content.Shared.Hands.Components;
 using Content.Shared.IdentityManagement;
 using Content.Shared.Interaction;
 using Content.Shared.Popups;
-using Content.Shared.Storage;
 using Content.Shared.Storage.Components;
 using Content.Shared.Verbs;
 using JetBrains.Annotations;
-using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Utility;
 
@@ -46,8 +44,7 @@ public sealed class LockSystem : EntitySystem
 
     private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args)
     {
-        _appearanceSystem.SetData(uid, StorageVisuals.CanLock, true);
-        _appearanceSystem.SetData(uid, StorageVisuals.Locked, lockComp.Locked);
+        _appearanceSystem.SetData(uid, LockVisuals.Locked, lockComp.Locked);
     }
 
     private void OnActivated(EntityUid uid, LockComponent lockComp, ActivateInWorldEvent args)
@@ -124,7 +121,7 @@ public sealed class LockSystem : EntitySystem
         _audio.PlayPredicted(lockComp.LockSound, uid, user);
 
         lockComp.Locked = true;
-        _appearanceSystem.SetData(uid, StorageVisuals.Locked, true);
+        _appearanceSystem.SetData(uid, LockVisuals.Locked, true);
         Dirty(uid, lockComp);
 
         var ev = new LockToggledEvent(true);
@@ -155,7 +152,7 @@ public sealed class LockSystem : EntitySystem
         _audio.PlayPredicted(lockComp.UnlockSound, uid, user);
 
         lockComp.Locked = false;
-        _appearanceSystem.SetData(uid, StorageVisuals.Locked, false);
+        _appearanceSystem.SetData(uid, LockVisuals.Locked, false);
         Dirty(uid, lockComp);
 
         var ev = new LockToggledEvent(false);
@@ -250,7 +247,7 @@ public sealed class LockSystem : EntitySystem
         if (!component.Locked || !component.BreakOnEmag)
             return;
         _audio.PlayPredicted(component.UnlockSound, uid, null);
-        _appearanceSystem.SetData(uid, StorageVisuals.Locked, false);
+        _appearanceSystem.SetData(uid, LockVisuals.Locked, false);
         RemComp<LockComponent>(uid); //Literally destroys the lock as a tell it was emagged
         args.Handled = true;
     }
diff --git a/Content.Shared/Security/DeployableBarrierVisuals.cs b/Content.Shared/Security/DeployableBarrierVisuals.cs
deleted file mode 100644 (file)
index 147ae23..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-using Robust.Shared.Serialization;
-
-namespace Content.Shared.Security
-{
-    [Serializable, NetSerializable]
-    public enum DeployableBarrierVisuals : byte
-    {
-        State
-    }
-
-
-    [Serializable, NetSerializable]
-    public enum DeployableBarrierState : byte
-    {
-        Idle,
-        Deployed
-    }
-}
index 9d021c52194d452dca6ad5e84bc0030e29d3b7b8..7b9ce841a9939b1813ee959f1d1038c32420a280 100644 (file)
@@ -8,7 +8,6 @@ namespace Content.Shared.Security.Systems;
 
 public sealed class DeployableBarrierSystem : EntitySystem
 {
-    [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly FixtureSystem _fixtures = default!;
     [Dependency] private readonly SharedPointLightSystem _pointLight = default!;
     [Dependency] private readonly SharedPhysicsSystem _physics = default!;
@@ -55,9 +54,6 @@ public sealed class DeployableBarrierSystem : EntitySystem
                 _physics.SetHard(uid, fixture, false);
         }
 
-        var state = isDeployed ? DeployableBarrierState.Deployed : DeployableBarrierState.Idle;
-        _appearance.SetData(uid, DeployableBarrierVisuals.State, state);
-
         if (TryComp(uid, out SharedPullableComponent? pullable))
             _pulling.TryStopPull(pullable);
 
index fa06e333e80a3dd44306ac8c8b81e490fbe04a0b..35f7955349cf3dd03ec3722592fcc6e1c217f8fc 100644 (file)
@@ -207,8 +207,6 @@ namespace Content.Shared.Storage
     {
         Open,
         HasContents,
-        CanLock,
-        Locked,
         StorageUsed,
         Capacity
     }
index 3a31edf7f149389263ccc6dd1a91175be1b11555..9277497e4f42d17d9210cc8ee93159c0e3bba410 100644 (file)
   - type: Sprite
     sprite: Objects/Specific/Security/barrier.rsi
     layers:
-    - state: "idle"
-      map: ["deployableBarrierBase"]
+    - state: idle
+    - state: locked
+      map: ["enum.LockVisualLayers.Lock"]
   - type: Appearance
-  - type: GenericVisualizer
-    visuals:
-      enum.DeployableBarrierVisuals.State:
-        deployableBarrierBase:
-          enum.DeployableBarrierState.Idle: {state: "idle"}
-          enum.DeployableBarrierState.Deployed: {state: "deployed"}
+  - type: LockVisuals
   - type: InteractionOutline
   - type: Physics
     bodyType: Dynamic
index 659145562f54399bf91655c030e1b9f80c472ad9..531a530441540336dc2e37ada97efa8735e8ecd7 100644 (file)
@@ -22,7 +22,7 @@
         visible: false
         map: ["enum.WeldableLayers.BaseWelded"]
       - state: locked
-        map: ["enum.StorageVisualLayers.Lock"]
+        map: ["enum.LockVisualLayers.Lock"]
         shader: unshaded
     - type: InteractionOutline
     - type: Physics
@@ -73,6 +73,7 @@
     - type: EntityStorageVisuals
       stateDoorOpen: artifact_container_open
       stateDoorClosed: artifact_container_door
+    - type: LockVisuals
     - type: ItemSlots
     - type: ContainerContainer
       containers:
index 2697e00a7000ea15ad307d94373b04d05a13ab19..cc9f8035fe712034e9ffdf4d68de5c9cf9a6de03 100644 (file)
     - state: locked
       shader: unshaded
       visible: false
-      map: ["enum.StorageVisualLayers.Lock"]
+      map: ["enum.LockVisualLayers.Lock"]
   - type: Transform
     noRot: false
   - type: Fixtures
         enum.PowerDeviceVisualLayers.Powered:
           True: { visible: true }
           False: { visible: false }
+  - type: LockVisuals
   - type: DeviceNetwork
     deviceNetId: Wireless
     receiveFrequencyId: BasicDevice
index e5604bea080b5e372f007a532785725f2d6742f9..52698f62cc0b38df0e382330ff0209f687e87449 100644 (file)
       shader: unshaded
       visible: false
       map: ["enum.EmitterVisualLayers.Lights"]
-    - state: lock
+    - state: locked
       shader: unshaded
       visible: false
-      map: ["enum.StorageVisualLayers.Lock"]
+      map: ["enum.LockVisualLayers.Lock"]
   - type: Emitter
   - type: Gun
     showExamineText: false
@@ -83,6 +83,7 @@
   - type: Appearance
   - type: Lock
     locked: false
+  - type: LockVisuals
   - type: AccessReader
     access: [[ "Engineering" ]]
   - type: Machine
index 760eb31755b78bf8494ef23d67dffe05df0d898b..897b7be6ffb2097ed606a4ed1052ed893ad74f29 100644 (file)
           tankInserted:
             False: { state: can-open, visible: false }
             True: { state: can-open, visible: true }
-        enum.GasCanisterVisuals.Locked:
+        enum.LockVisuals.Locked:
           locked:
-            False: { state: can-unlocked, shader: "unshaded" }
-            True: { state: can-locked, shader: "unshaded" }
+            False: { state: unlocked, shader: "unshaded" }
+            True: { state: locked, shader: "unshaded" }
         enum.GasCanisterVisuals.PressureState:
           pressureLight:
             0: { state: can-o0, shader: "unshaded" }
index 4448d551e33cc17b2fd7c369fc10fe74a13308f9..7ab24f6b5ca7e67f6244a6647a2c22b2f58a0ffb 100644 (file)
@@ -5,6 +5,7 @@
   components:
   - type: AccessReader
   - type: Lock
+  - type: LockVisuals
   - type: Sprite
     sprite: Structures/Storage/closet.rsi
     noRot: true
@@ -14,7 +15,7 @@
     - state: generic_door
       map: ["enum.StorageVisualLayers.Door"]
     - state: locked
-      map: ["enum.StorageVisualLayers.Lock"]
+      map: ["enum.LockVisualLayers.Lock"]
       shader: unshaded
     - state: welded
       visible: false
index d1a60566d4e5f2d68a78bb5b2d6b27632cc0cf8f..46ec7cbf6aa3e05d5abc1e544bc2b6b2d2b35c1c 100644 (file)
   components:
   - type: AccessReader
   - type: Lock
+  - type: LockVisuals
   - type: Sprite
     sprite: Structures/Storage/wall_locker.rsi
     layers:
     - state: generic_door
       map: ["enum.StorageVisualLayers.Door"]
     - state: locked
-      map: ["enum.StorageVisualLayers.Lock"]
+      map: ["enum.LockVisualLayers.Lock"]
       shader: unshaded
     - state: welded
       visible: false
       visible: false
       map: ["enum.WeldableLayers.BaseWelded"]
     - state: locked
-      map: ["enum.StorageVisualLayers.Lock"]
+      map: ["enum.LockVisualLayers.Lock"]
       shader: unshaded
   - type: MovedByPressure
   - type: DamageOnHighSpeedImpact
   - type: Appearance
   - type: EntityStorageVisuals
     stateBase: base
-    stateLocked: locked
-    stateUnlocked: unlocked
     stateDoorOpen: base
     stateDoorClosed: door
+  - type: LockVisuals
index 76a88e7858f903dce333e1afb501f5811a40b848..acf4fd2149e99a635988176803db41321b78f38f 100644 (file)
@@ -87,6 +87,7 @@
   id: CrateBaseSecure
   components:
   - type: Lock
+  - type: LockVisuals
   - type: AccessReader
   - type: Icon
     sprite: Structures/Storage/Crates/secure.rsi
       visible: false
       map: ["enum.WeldableLayers.BaseWelded"]
     - state: locked
-      map: ["enum.StorageVisualLayers.Lock"]
+      map: ["enum.LockVisualLayers.Lock"]
       shader: unshaded
   - type: Damageable
     damageContainer: StructuralInorganic
index 8142924b683cfc026a8ac4eb34b0335ad529ed76..5cd7cffb0352a28f0c3cc1d1c554b82fb4f118c0 100644 (file)
@@ -11,7 +11,7 @@
             "name": "idle"
         },
         {
-            "name": "deployed",
+            "name": "locked",
             "delays": [
                 [
                     0.1,
index 0456b99ffabd78c5d0a5b1286a24f7666dda85e3..5b5b51257aceeb72faab0bd91f2641bea8db70c4 100644 (file)
@@ -34,7 +34,7 @@
       ]
     },
     {
-      "name": "lock",
+      "name": "locked",
       "directions": 4
     },
     {
index 7f9dfe234026b57a51f0a5868b74b68aa58907e2..95d67cc8ae18e3c52f59da74c07f78d2feeb52ad 100644 (file)
       "name": "can-connector"
     },
     {
-      "name": "can-locked"
+      "name": "locked"
     },
     {
-      "name": "can-unlocked"
+      "name": "unlocked"
     },
     {
       "name": "can-o0",