mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
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:
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user