diff --git a/Content.Server/Containers/ContainerCommand.cs b/Content.Server/Containers/ContainerCommand.cs new file mode 100644 index 0000000000..914c9025a0 --- /dev/null +++ b/Content.Server/Containers/ContainerCommand.cs @@ -0,0 +1,87 @@ +using System.Linq; +using Content.Server.Administration; +using Content.Shared.Administration; +using Robust.Shared.Containers; +using Robust.Shared.Toolshed; + +namespace Content.Server.Containers; + +[ToolshedCommand, AdminCommand(AdminFlags.Debug)] +public sealed class ContainerCommand : ToolshedCommand +{ + private SharedContainerSystem? _container; + + [CommandImplementation("contents")] + public IEnumerable ContainerQuery([PipedArgument] IEnumerable storageEnts, string id) => + storageEnts.SelectMany(x => ContainerQueryBase(x, id)); + + + public IEnumerable ContainerQueryBase(EntityUid ent, string id) + { + _container ??= GetSys(); + + if (!_container.TryGetContainer(ent, id, out var container)) + return []; + + return container.ContainedEntities; + } + + [CommandImplementation("get")] + public IEnumerable ContainerGet([PipedArgument] IEnumerable storageEnts, string id) => + storageEnts.Select(x => ContainerGetBase(x, id)).Where(s => s != null).Select(s => s!); + + [CommandImplementation("id")] + public IEnumerable ContainerId([PipedArgument] IEnumerable containers) => + containers.Select(x => x.ID); + + + public BaseContainer? ContainerGetBase(EntityUid ent, string id) + { + _container ??= GetSys(); + + if (!_container.TryGetContainer(ent, id, out var container)) + return null; + + return container; + } + + [CommandImplementation("insertmultiple")] + public BaseContainer ContainerInsert([PipedArgument] BaseContainer container, bool doForce, IEnumerable ents) + { + _container ??= GetSys(); + + foreach (var ent in ents) + { + if (doForce) + { + _container.Insert(ent, container, null, true); + } + else + { + _container.InsertOrDrop(ent, container); + } + } + return container; + } + + [CommandImplementation("insert")] + public BaseContainer ContainerInsert([PipedArgument] BaseContainer container, bool doForce, EntityUid ent) + { + return ContainerInsert(container, doForce, [ent]); + } + + [CommandImplementation("list")] + public IEnumerable ContainerList([PipedArgument] EntityUid ent) + { + _container ??= GetSys(); + + return _container.GetAllContainers(ent).Select(container => container.ID); + } + [CommandImplementation("getall")] + public IEnumerable ContainerGetAll([PipedArgument] EntityUid ent) + { + _container ??= GetSys(); + + return _container.GetAllContainers(ent); + } +} diff --git a/Content.Server/Inventory/InventoryCommand.cs b/Content.Server/Inventory/InventoryCommand.cs index e628ee6e01..2a7bcab909 100644 --- a/Content.Server/Inventory/InventoryCommand.cs +++ b/Content.Server/Inventory/InventoryCommand.cs @@ -12,7 +12,7 @@ public sealed class InventoryCommand : ToolshedCommand { private InventorySystem? _inventorySystem; - [CommandImplementation("query")] + [CommandImplementation("contents")] public IEnumerable InventoryQuery([PipedArgument] IEnumerable entities) => entities.SelectMany(InventoryQuery); diff --git a/Content.Server/Storage/StorageCommand.cs b/Content.Server/Storage/StorageCommand.cs index 1c39801622..d5855388fa 100644 --- a/Content.Server/Storage/StorageCommand.cs +++ b/Content.Server/Storage/StorageCommand.cs @@ -52,7 +52,7 @@ public sealed class StorageCommand : ToolshedCommand return null; } - [CommandImplementation("query")] + [CommandImplementation("contents")] public IEnumerable StorageQuery([PipedArgument] IEnumerable storageEnts, bool recursive) => storageEnts.SelectMany(x => StorageQueryRecursiveBase(x, recursive)); diff --git a/Resources/Locale/en-US/commands/toolshed/container-command.ftl b/Resources/Locale/en-US/commands/toolshed/container-command.ftl new file mode 100644 index 0000000000..077c1439a3 --- /dev/null +++ b/Resources/Locale/en-US/commands/toolshed/container-command.ftl @@ -0,0 +1,14 @@ +command-description-container-contents = + Gets all entities inside a container on an entity via the container's ID. +command-description-container-get = + Gets a container on an entity via the container's ID. +command-description-container-insert = + Puts an entity inside the piped container. +command-description-container-insertmultiple = + Put multiple entities inside the piped container. +command-description-container-list = + Gets the IDs of all containers in an entity. +command-description-container-getall = + Gets all containers in an entity. +command-description-container-id = + Gets the string id of the piped in containers. diff --git a/Resources/Locale/en-US/commands/toolshed/inventory-command.ftl b/Resources/Locale/en-US/commands/toolshed/inventory-command.ftl index f430197495..667db5166f 100644 --- a/Resources/Locale/en-US/commands/toolshed/inventory-command.ftl +++ b/Resources/Locale/en-US/commands/toolshed/inventory-command.ftl @@ -18,5 +18,5 @@ command-description-inventory-ensure = Puts a given entity on the first piped entity that has a slot matching the given flag if none exists, passing through the UID of whatever is in the slot by the end. command-description-inventory-ensurespawn = Spawns a given prototype on the first piped entity that has a slot matching the given flag if none exists, passing through the UID of whatever is in the slot by the end. -command-description-inventory-query = +command-description-inventory-contents = Gets the entities in the inventory slots of the piped entities and passes them along. diff --git a/Resources/Locale/en-US/commands/toolshed/storage-command.ftl b/Resources/Locale/en-US/commands/toolshed/storage-command.ftl index 154196fbb1..c912df4d76 100644 --- a/Resources/Locale/en-US/commands/toolshed/storage-command.ftl +++ b/Resources/Locale/en-US/commands/toolshed/storage-command.ftl @@ -2,5 +2,5 @@ command-description-storage-fasttake = Takes the most recently placed item from the piped storage entity. command-description-storage-insert = Inserts the piped entity into the given storage entity. -command-description-storage-query = +command-description-storage-contents = Gets the entities in the storagebase of the piped entities and passes them along.