Add a new toolshed command spawn:in (#6021)

* added spawn:in command.

* better annotations

* use EntityManager.System

* ftl

* make it lazy cached.

* Fix typo (it's -> its)

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
Walker Fowlkes
2025-06-15 05:05:27 -07:00
committed by GitHub
parent a8227f7faa
commit 324606e5a3
2 changed files with 40 additions and 0 deletions

View File

@@ -195,6 +195,8 @@ command-description-spawn-at =
Spawns an entity at the given coordinates.
command-description-spawn-on =
Spawns an entity on the given entity, at it's coordinates.
command-description-spawn-in =
Spawns an entity in the given container on the given entity, dropping it at its coordinates if it doesn't fit
command-description-spawn-attached =
Spawns an entity attached to the given entity, at (0 0) relative to it.
command-description-mappos =

View File

@@ -1,8 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Robust.Shared.IoC;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
namespace Robust.Shared.Toolshed.Commands.Entities;
@@ -10,7 +13,10 @@ namespace Robust.Shared.Toolshed.Commands.Entities;
[ToolshedCommand]
internal sealed class SpawnCommand : ToolshedCommand
{
private SharedContainerSystem? sharedContainerSystem = null;
#region spawn:at implementations
[CommandImplementation("at")]
public EntityUid SpawnAt([PipedArgument] EntityCoordinates target, EntProtoId proto)
{
@@ -20,9 +26,11 @@ internal sealed class SpawnCommand : ToolshedCommand
[CommandImplementation("at")]
public IEnumerable<EntityUid> SpawnAt([PipedArgument] IEnumerable<EntityCoordinates> target, EntProtoId proto)
=> target.Select(x => SpawnAt(x, proto));
#endregion
#region spawn:on implementations
[CommandImplementation("on")]
public EntityUid SpawnOn([PipedArgument] EntityUid target, EntProtoId proto)
{
@@ -32,9 +40,38 @@ internal sealed class SpawnCommand : ToolshedCommand
[CommandImplementation("on")]
public IEnumerable<EntityUid> SpawnOn([PipedArgument] IEnumerable<EntityUid> target, EntProtoId proto)
=> target.Select(x => SpawnOn(x, proto));
#endregion
#region spawn:in implementations
[CommandImplementation("in")]
public EntityUid SpawnIn([PipedArgument] EntityUid target, string containerId, EntProtoId proto)
{
var spawned = SpawnOn(target, proto);
if (!TryComp<TransformComponent>(spawned, out var transformComponent) ||
!TryComp<MetaDataComponent>(spawned, out var metaDataComp) ||
!TryComp<PhysicsComponent>(spawned, out var physicsComponent))
return spawned;
sharedContainerSystem ??= EntityManager.System<SharedContainerSystem>();
var container = sharedContainerSystem.GetContainer(target, containerId);
sharedContainerSystem.InsertOrDrop((spawned, transformComponent, metaDataComp, physicsComponent),
container
);
return spawned;
}
[CommandImplementation("in")]
public IEnumerable<EntityUid> SpawnIn(
[PipedArgument] IEnumerable<EntityUid> target,
string containerId,
EntProtoId proto)
=> target.Select(x => SpawnIn(x, containerId, proto));
#endregion
#region spawn:attached implementations
[CommandImplementation("attached")]
public EntityUid SpawnIn([PipedArgument] EntityUid target, EntProtoId proto)
{
@@ -44,5 +81,6 @@ internal sealed class SpawnCommand : ToolshedCommand
[CommandImplementation("attached")]
public IEnumerable<EntityUid> SpawnIn([PipedArgument] IEnumerable<EntityUid> target, EntProtoId proto)
=> target.Select(x => SpawnIn(x, proto));
#endregion
}