make admin interacts with storages silent (#35417)

* make admin interacts with storages silent

* review

* silent insert and transfer

* i love code

---------

Co-authored-by: ScarKy0 <scarky0@onet.eu>
This commit is contained in:
lzk
2025-03-27 18:42:57 +01:00
committed by GitHub
parent f9320aacd7
commit 8f049f174d
4 changed files with 31 additions and 8 deletions

View File

@@ -22,6 +22,7 @@ using Content.Shared.Placeable;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Stacks; using Content.Shared.Stacks;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Content.Shared.Tag;
using Content.Shared.Timing; using Content.Shared.Timing;
using Content.Shared.Storage.Events; using Content.Shared.Storage.Events;
using Content.Shared.Verbs; using Content.Shared.Verbs;
@@ -66,6 +67,7 @@ public abstract class SharedStorageSystem : EntitySystem
[Dependency] private readonly SharedStackSystem _stack = default!; [Dependency] private readonly SharedStackSystem _stack = default!;
[Dependency] protected readonly SharedTransformSystem TransformSystem = default!; [Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
[Dependency] protected readonly SharedUserInterfaceSystem UI = default!; [Dependency] protected readonly SharedUserInterfaceSystem UI = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] protected readonly UseDelaySystem UseDelay = default!; [Dependency] protected readonly UseDelaySystem UseDelay = default!;
private EntityQuery<ItemComponent> _itemQuery; private EntityQuery<ItemComponent> _itemQuery;
@@ -276,6 +278,7 @@ public abstract class SharedStorageSystem : EntitySystem
if (!UI.IsUiOpen(uid, args.UiKey)) if (!UI.IsUiOpen(uid, args.UiKey))
{ {
UpdateAppearance((uid, storageComp, null)); UpdateAppearance((uid, storageComp, null));
if (!_tag.HasTag(args.Actor, storageComp.SilentStorageUserTag))
Audio.PlayPredicted(storageComp.StorageCloseSound, uid, args.Actor); Audio.PlayPredicted(storageComp.StorageCloseSound, uid, args.Actor);
} }
} }
@@ -357,7 +360,7 @@ public abstract class SharedStorageSystem : EntitySystem
if (!UI.TryOpenUi(uid, StorageComponent.StorageUiKey.Key, entity)) if (!UI.TryOpenUi(uid, StorageComponent.StorageUiKey.Key, entity))
return; return;
if (!silent) if (!silent && !_tag.HasTag(entity, storageComp.SilentStorageUserTag))
{ {
Audio.PlayPredicted(storageComp.StorageOpenSound, uid, entity); Audio.PlayPredicted(storageComp.StorageOpenSound, uid, entity);
@@ -602,6 +605,7 @@ public abstract class SharedStorageSystem : EntitySystem
// If we picked up at least one thing, play a sound and do a cool animation! // If we picked up at least one thing, play a sound and do a cool animation!
if (successfullyInserted.Count > 0) if (successfullyInserted.Count > 0)
{ {
if (!_tag.HasTag(args.User, component.SilentStorageUserTag))
Audio.PlayPredicted(component.StorageInsertSound, uid, args.User, _audioParams); Audio.PlayPredicted(component.StorageInsertSound, uid, args.User, _audioParams);
EntityManager.RaiseSharedEvent(new AnimateInsertingEntitiesEvent( EntityManager.RaiseSharedEvent(new AnimateInsertingEntitiesEvent(
GetNetEntity(uid), GetNetEntity(uid),
@@ -645,7 +649,8 @@ public abstract class SharedStorageSystem : EntitySystem
$"{ToPrettyString(player):player} is attempting to take {ToPrettyString(item):item} out of {ToPrettyString(storage):storage}"); $"{ToPrettyString(player):player} is attempting to take {ToPrettyString(item):item} out of {ToPrettyString(storage):storage}");
if (_sharedHandsSystem.TryPickupAnyHand(player, item, handsComp: player.Comp) if (_sharedHandsSystem.TryPickupAnyHand(player, item, handsComp: player.Comp)
&& storage.Comp.StorageRemoveSound != null) && storage.Comp.StorageRemoveSound != null
&& !_tag.HasTag(player, storage.Comp.SilentStorageUserTag))
{ {
Audio.PlayPredicted(storage.Comp.StorageRemoveSound, storage, player, _audioParams); Audio.PlayPredicted(storage.Comp.StorageRemoveSound, storage, player, _audioParams);
} }
@@ -903,7 +908,9 @@ public abstract class SharedStorageSystem : EntitySystem
{ {
Insert(target, entity, out _, user: user, targetComp, playSound: false); Insert(target, entity, out _, user: user, targetComp, playSound: false);
} }
if (user != null
&& (!_tag.HasTag(user.Value, sourceComp.SilentStorageUserTag)
|| !_tag.HasTag(user.Value, targetComp.SilentStorageUserTag)))
Audio.PlayPredicted(sourceComp.StorageInsertSound, target, user, _audioParams); Audio.PlayPredicted(sourceComp.StorageInsertSound, target, user, _audioParams);
} }
@@ -1077,12 +1084,17 @@ public abstract class SharedStorageSystem : EntitySystem
* For now we just treat items as always being the same size regardless of stack count. * For now we just treat items as always being the same size regardless of stack count.
*/ */
// Check if the sound is expected to play.
// If there is an user, the sound will not play if they have the SilentStorageUserTag
// If there is no user, only playSound is checked.
var canPlaySound = playSound && (user == null || !_tag.HasTag(user.Value, storageComp.SilentStorageUserTag));
if (!stackAutomatically || !_stackQuery.TryGetComponent(insertEnt, out var insertStack)) if (!stackAutomatically || !_stackQuery.TryGetComponent(insertEnt, out var insertStack))
{ {
if (!ContainerSystem.Insert(insertEnt, storageComp.Container)) if (!ContainerSystem.Insert(insertEnt, storageComp.Container))
return false; return false;
if (playSound) if (canPlaySound)
Audio.PlayPredicted(storageComp.StorageInsertSound, uid, user, _audioParams); Audio.PlayPredicted(storageComp.StorageInsertSound, uid, user, _audioParams);
return true; return true;
@@ -1112,7 +1124,7 @@ public abstract class SharedStorageSystem : EntitySystem
return false; return false;
} }
if (playSound) if (canPlaySound)
Audio.PlayPredicted(storageComp.StorageInsertSound, uid, user, _audioParams); Audio.PlayPredicted(storageComp.StorageInsertSound, uid, user, _audioParams);
return true; return true;

View File

@@ -1,5 +1,6 @@
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Storage.EntitySystems; using Content.Shared.Storage.EntitySystems;
using Content.Shared.Tag;
using Content.Shared.Whitelist; using Content.Shared.Whitelist;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Containers; using Robust.Shared.Containers;
@@ -141,6 +142,12 @@ namespace Content.Shared.Storage
[DataField] [DataField]
public bool HideStackVisualsWhenClosed = true; public bool HideStackVisualsWhenClosed = true;
/// <summary>
/// Entities with this tag won't trigger storage sound.
/// </summary>
[DataField]
public ProtoId<TagPrototype> SilentStorageUserTag = "SilentStorageUser";
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum StorageUiKey : byte public enum StorageUiKey : byte
{ {

View File

@@ -13,6 +13,7 @@
- BypassInteractionRangeChecks - BypassInteractionRangeChecks
- BypassDropChecks - BypassDropChecks
- NoConsoleSound - NoConsoleSound
- SilentStorageUser
- type: Input - type: Input
context: "aghost" context: "aghost"
- type: Ghost - type: Ghost

View File

@@ -1165,6 +1165,9 @@
- type: Tag - type: Tag
id: SignalTrigger id: SignalTrigger
- type: Tag
id: SilentStorageUser # used in SharedStorageSystem, so the entity will do all silently
- type: Tag - type: Tag
id: SkeletonMotorcycleKeys id: SkeletonMotorcycleKeys