mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Container toolshed commands (#43098)
* First commit. * container:id * contents * locale --------- Co-authored-by: UpAndLeaves <92269094+Alpha-Two@users.noreply.github.com> Co-authored-by: ScarKy0 <scarky0@onet.eu>
This commit is contained in:
parent
f6b458f761
commit
c8b8369756
6 changed files with 105 additions and 4 deletions
87
Content.Server/Containers/ContainerCommand.cs
Normal file
87
Content.Server/Containers/ContainerCommand.cs
Normal file
|
|
@ -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<EntityUid> ContainerQuery([PipedArgument] IEnumerable<EntityUid> storageEnts, string id) =>
|
||||
storageEnts.SelectMany(x => ContainerQueryBase(x, id));
|
||||
|
||||
|
||||
public IEnumerable<EntityUid> ContainerQueryBase(EntityUid ent, string id)
|
||||
{
|
||||
_container ??= GetSys<SharedContainerSystem>();
|
||||
|
||||
if (!_container.TryGetContainer(ent, id, out var container))
|
||||
return [];
|
||||
|
||||
return container.ContainedEntities;
|
||||
}
|
||||
|
||||
[CommandImplementation("get")]
|
||||
public IEnumerable<BaseContainer> ContainerGet([PipedArgument] IEnumerable<EntityUid> storageEnts, string id) =>
|
||||
storageEnts.Select(x => ContainerGetBase(x, id)).Where(s => s != null).Select(s => s!);
|
||||
|
||||
[CommandImplementation("id")]
|
||||
public IEnumerable<string> ContainerId([PipedArgument] IEnumerable<BaseContainer> containers) =>
|
||||
containers.Select(x => x.ID);
|
||||
|
||||
|
||||
public BaseContainer? ContainerGetBase(EntityUid ent, string id)
|
||||
{
|
||||
_container ??= GetSys<SharedContainerSystem>();
|
||||
|
||||
if (!_container.TryGetContainer(ent, id, out var container))
|
||||
return null;
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
[CommandImplementation("insertmultiple")]
|
||||
public BaseContainer ContainerInsert([PipedArgument] BaseContainer container, bool doForce, IEnumerable<EntityUid> ents)
|
||||
{
|
||||
_container ??= GetSys<SharedContainerSystem>();
|
||||
|
||||
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<string> ContainerList([PipedArgument] EntityUid ent)
|
||||
{
|
||||
_container ??= GetSys<SharedContainerSystem>();
|
||||
|
||||
return _container.GetAllContainers(ent).Select(container => container.ID);
|
||||
}
|
||||
[CommandImplementation("getall")]
|
||||
public IEnumerable<BaseContainer> ContainerGetAll([PipedArgument] EntityUid ent)
|
||||
{
|
||||
_container ??= GetSys<SharedContainerSystem>();
|
||||
|
||||
return _container.GetAllContainers(ent);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ public sealed class InventoryCommand : ToolshedCommand
|
|||
{
|
||||
private InventorySystem? _inventorySystem;
|
||||
|
||||
[CommandImplementation("query")]
|
||||
[CommandImplementation("contents")]
|
||||
public IEnumerable<EntityUid> InventoryQuery([PipedArgument] IEnumerable<EntityUid> entities) =>
|
||||
entities.SelectMany(InventoryQuery);
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public sealed class StorageCommand : ToolshedCommand
|
|||
return null;
|
||||
}
|
||||
|
||||
[CommandImplementation("query")]
|
||||
[CommandImplementation("contents")]
|
||||
public IEnumerable<EntityUid> StorageQuery([PipedArgument] IEnumerable<EntityUid> storageEnts, bool recursive) =>
|
||||
storageEnts.SelectMany(x => StorageQueryRecursiveBase(x, recursive));
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue