cleanup LockOnTriggerComponent (#39720)

* cleanup LockOnTriggerComponent

* comment

* indentation
This commit is contained in:
slarticodefast
2025-08-18 22:21:33 +02:00
committed by GitHub
parent fedba2425b
commit d737e39a98
2 changed files with 19 additions and 6 deletions

View File

@@ -1,19 +1,27 @@
using Content.Shared.Lock;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Shared.Trigger.Components.Effects; 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] [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class LockOnTriggerComponent : BaseXOnTriggerComponent public sealed partial class LockOnTriggerComponent : BaseXOnTriggerComponent
{ {
/// <summary>
/// If the trigger will lock, unlock or toggle the lock.
/// </summary>
[DataField, AutoNetworkedField] [DataField, AutoNetworkedField]
public LockAction LockOnTrigger = LockAction.Toggle; public LockAction LockMode = LockAction.Toggle;
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum LockAction public enum LockAction
{ {
Lock = 0, Lock = 0,
Unlock = 1, Unlock = 1,
Toggle = 2, Toggle = 2,
} }

View File

@@ -19,16 +19,21 @@ public sealed class LockOnTriggerSystem : EntitySystem
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key)) if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
return; 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: case LockAction.Lock:
_lock.Lock(ent.Owner, args.User); _lock.Lock(target.Value, args.User, lockComp);
break; break;
case LockAction.Unlock: case LockAction.Unlock:
_lock.Unlock(ent, args.User); _lock.Unlock(target.Value, args.User, lockComp);
break; break;
case LockAction.Toggle: case LockAction.Toggle:
_lock.ToggleLock(ent, args.User); _lock.ToggleLock(target.Value, args.User, lockComp);
break; break;
} }
} }