mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Inventory + Storage toolshed query commands (#40813)
* Add inventory and storage query toolshed commands * Forgot FTL * Fix stuff! * Make requested changes and stop STACK MAX SIZE ERROR * cleaning --------- Co-authored-by: ScarKy0 <scarky0@onet.eu>
This commit is contained in:
parent
d9d0cd92ae
commit
8cb0664f94
4 changed files with 54 additions and 4 deletions
|
|
@ -12,6 +12,27 @@ public sealed class InventoryCommand : ToolshedCommand
|
|||
{
|
||||
private InventorySystem? _inventorySystem;
|
||||
|
||||
[CommandImplementation("query")]
|
||||
public IEnumerable<EntityUid> InventoryQuery([PipedArgument] IEnumerable<EntityUid> entities) =>
|
||||
entities.SelectMany(InventoryQuery);
|
||||
|
||||
private IEnumerable<EntityUid> InventoryQuery(EntityUid entity)
|
||||
{
|
||||
_inventorySystem ??= GetSys<InventorySystem>();
|
||||
|
||||
if (!EntityManager.TryGetComponent<InventoryComponent>(entity, out var inventory))
|
||||
return [];
|
||||
|
||||
List<EntityUid> result = new();
|
||||
|
||||
foreach (var slot in inventory.Slots)
|
||||
{
|
||||
if (_inventorySystem.TryGetSlotEntity(entity, slot.Name, out var item, inventory))
|
||||
result.Add(item.Value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandImplementation("getflags")]
|
||||
public IEnumerable<EntityUid> InventoryGetFlags([PipedArgument] IEnumerable<EntityUid> ents, SlotFlags slotFlag)
|
||||
{
|
||||
|
|
@ -44,7 +65,6 @@ public sealed class InventoryCommand : ToolshedCommand
|
|||
return items;
|
||||
}
|
||||
|
||||
|
||||
[CommandImplementation("getnamed")]
|
||||
public IEnumerable<EntityUid> InventoryGetNamed([PipedArgument] IEnumerable<EntityUid> ents, string slotName)
|
||||
{
|
||||
|
|
@ -81,6 +101,7 @@ public sealed class InventoryCommand : ToolshedCommand
|
|||
public EntityUid? InventoryForcePut([PipedArgument] IEnumerable<EntityUid> ents,
|
||||
EntityUid itemEnt,
|
||||
SlotFlags slotFlag) => InventoryPutEnumerableBase(ents, itemEnt, slotFlag, PutType.ForcePut);
|
||||
|
||||
[CommandImplementation("forcespawn")]
|
||||
public EntityUid? InventoryForceSpawn([PipedArgument] IEnumerable<EntityUid> ents,
|
||||
EntProtoId itemEnt,
|
||||
|
|
@ -90,6 +111,7 @@ public sealed class InventoryCommand : ToolshedCommand
|
|||
public EntityUid? InventoryPut([PipedArgument] IEnumerable<EntityUid> ents,
|
||||
EntityUid itemEnt,
|
||||
SlotFlags slotFlag) => InventoryPutEnumerableBase(ents, itemEnt, slotFlag, PutType.Put);
|
||||
|
||||
[CommandImplementation("spawn")]
|
||||
public EntityUid? InventorySpawn([PipedArgument] IEnumerable<EntityUid> ents,
|
||||
EntProtoId itemEnt,
|
||||
|
|
@ -99,6 +121,7 @@ public sealed class InventoryCommand : ToolshedCommand
|
|||
public EntityUid? InventoryTryPut([PipedArgument] IEnumerable<EntityUid> ents,
|
||||
EntityUid itemEnt,
|
||||
SlotFlags slotFlag) => InventoryPutEnumerableBase(ents, itemEnt, slotFlag, PutType.Put);
|
||||
|
||||
[CommandImplementation("tryspawn")]
|
||||
public EntityUid? InventoryTrySpawn([PipedArgument] IEnumerable<EntityUid> ents,
|
||||
EntProtoId itemEnt,
|
||||
|
|
@ -108,12 +131,12 @@ public sealed class InventoryCommand : ToolshedCommand
|
|||
public EntityUid? InventoryEnsure([PipedArgument] IEnumerable<EntityUid> ents,
|
||||
EntityUid itemEnt,
|
||||
SlotFlags slotFlag) => InventoryPutEnumerableBase(ents, itemEnt, slotFlag, PutType.Ensure);
|
||||
|
||||
[CommandImplementation("ensurespawn")]
|
||||
public EntityUid? InventoryEnsureSpawn([PipedArgument] IEnumerable<EntityUid> ents,
|
||||
EntProtoId itemEnt,
|
||||
SlotFlags slotFlag) => InventorySpawnEnumerableBase(ents, itemEnt, slotFlag, PutType.Ensure);
|
||||
|
||||
|
||||
private EntityUid? InventorySpawnEnumerableBase(IEnumerable<EntityUid> targetEnts,
|
||||
EntProtoId itemToInsert,
|
||||
SlotFlags slotFlags,
|
||||
|
|
@ -136,6 +159,7 @@ public sealed class InventoryCommand : ToolshedCommand
|
|||
Del(spawnedItem);
|
||||
return null;
|
||||
}
|
||||
|
||||
private EntityUid? InventoryPutEnumerableBase(IEnumerable<EntityUid> targetEnts,
|
||||
EntityUid itemToInsert,
|
||||
SlotFlags slotFlags,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public sealed class StorageCommand : ToolshedCommand
|
|||
public IEnumerable<EntityUid> StorageInsert([PipedArgument] IEnumerable<EntityUid> entsToInsert,
|
||||
EntityUid targetEnt) => entsToInsert.Where(x => StorageInsert(x, targetEnt) != null);
|
||||
|
||||
public EntityUid? StorageInsert(EntityUid entToInsert, EntityUid targetEnt)
|
||||
private EntityUid? StorageInsert(EntityUid entToInsert, EntityUid targetEnt)
|
||||
{
|
||||
_storage ??= GetSys<SharedStorageSystem>();
|
||||
|
||||
|
|
@ -32,7 +32,6 @@ public sealed class StorageCommand : ToolshedCommand
|
|||
: null;
|
||||
}
|
||||
|
||||
|
||||
[CommandImplementation("fasttake")]
|
||||
public IEnumerable<EntityUid> StorageFastTake([PipedArgument] IEnumerable<EntityUid> storageEnts) =>
|
||||
storageEnts.Select(StorageFastTake).OfType<EntityUid>();
|
||||
|
|
@ -53,6 +52,29 @@ public sealed class StorageCommand : ToolshedCommand
|
|||
return null;
|
||||
}
|
||||
|
||||
[CommandImplementation("query")]
|
||||
public IEnumerable<EntityUid> StorageQuery([PipedArgument] IEnumerable<EntityUid> storageEnts, bool recursive) =>
|
||||
storageEnts.SelectMany(x => StorageQueryRecursiveBase(x, recursive));
|
||||
|
||||
public IEnumerable<EntityUid> StorageQueryRecursiveBase(EntityUid storageEnt, bool recursive)
|
||||
{
|
||||
_storage ??= GetSys<SharedStorageSystem>();
|
||||
_container ??= GetSys<SharedContainerSystem>();
|
||||
|
||||
if (!EntityManager.TryGetComponent<StorageComponent>(storageEnt, out var storage))
|
||||
return [];
|
||||
|
||||
IEnumerable<EntityUid> containedEntities = storage.Container.ContainedEntities;
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
foreach (var ent in containedEntities)
|
||||
{
|
||||
containedEntities = containedEntities.Concat(StorageQueryRecursiveBase(ent, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return containedEntities;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,3 +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 =
|
||||
Gets the entities in the inventory slots of the piped entities and passes them along.
|
||||
|
|
|
|||
|
|
@ -2,3 +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 =
|
||||
Gets the entities in the storagebase of the piped entities and passes them along.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue