]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
cleanup LockOnTriggerComponent (#39720)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Mon, 18 Aug 2025 20:21:33 +0000 (22:21 +0200)
committerGitHub <noreply@github.com>
Mon, 18 Aug 2025 20:21:33 +0000 (13:21 -0700)
* cleanup LockOnTriggerComponent

* comment

* indentation

Content.Shared/Trigger/Components/Effects/LockOnTriggerComponent.cs
Content.Shared/Trigger/Systems/LockOnTriggerSystem.cs

index 38eea0a4613b67bf1cf27ca027033f5b5863d370..6dbec86c5dccdb06c1d88e361bd33206ce62586b 100644 (file)
@@ -1,19 +1,27 @@
+using Content.Shared.Lock;
 using Robust.Shared.GameStates;
 using Robust.Shared.Serialization;
 
 namespace Content.Shared.Trigger.Components.Effects;
 
+/// <summary>
+/// Will lock, unlock or toggle an entity with the <see cref="LockComponent"/>.
+/// If TargetUser is true then they will be (un)locked instead.
+/// </summary>
 [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
 public sealed partial class LockOnTriggerComponent : BaseXOnTriggerComponent
 {
+    /// <summary>
+    /// If the trigger will lock, unlock or toggle the lock.
+    /// </summary>
     [DataField, AutoNetworkedField]
-    public LockAction LockOnTrigger = LockAction.Toggle;
+    public LockAction LockMode = LockAction.Toggle;
 }
 
 [Serializable, NetSerializable]
 public enum LockAction
 {
-    Lock   = 0,
+    Lock = 0,
     Unlock = 1,
     Toggle = 2,
 }
index 8726ede899c7df73388dbc876a7e235ac64570ac..2056d5fe5120f9780bf6c3d07b878538c45abd5a 100644 (file)
@@ -19,16 +19,21 @@ public sealed class LockOnTriggerSystem : EntitySystem
         if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
             return;
 
-        switch (ent.Comp.LockOnTrigger)
+        var target = ent.Comp.TargetUser ? args.User : ent.Owner;
+
+        if (!TryComp<LockComponent>(target, out var lockComp))
+            return; // prevent the Resolve in Lock/Unlock/ToggleLock from logging errors in case the user does not have the component
+
+        switch (ent.Comp.LockMode)
         {
             case LockAction.Lock:
-                _lock.Lock(ent.Owner, args.User);
+                _lock.Lock(target.Value, args.User, lockComp);
                 break;
             case LockAction.Unlock:
-                _lock.Unlock(ent, args.User);
+                _lock.Unlock(target.Value, args.User, lockComp);
                 break;
             case LockAction.Toggle:
-                _lock.ToggleLock(ent, args.User);
+                _lock.ToggleLock(target.Value, args.User, lockComp);
                 break;
         }
     }