Toolshed part 2 (#18997)
* fixe * Save work. * Rune-aware parser. * oogh * pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests * Publicizes a lot of common generic commands, so custom toolshed envs can include them. * i think i might implode * Tests. * a * b * awa --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
@@ -248,22 +248,22 @@ namespace Content.Server.Polymorph.Systems
|
||||
/// </summary>
|
||||
/// <param name="uid">The entityuid of the entity being reverted</param>
|
||||
/// <param name="component"></param>
|
||||
public void Revert(EntityUid uid, PolymorphedEntityComponent? component = null)
|
||||
public EntityUid? Revert(EntityUid uid, PolymorphedEntityComponent? component = null)
|
||||
{
|
||||
if (Deleted(uid))
|
||||
return;
|
||||
return null;
|
||||
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
return null;
|
||||
|
||||
var parent = component.Parent;
|
||||
if (Deleted(parent))
|
||||
return;
|
||||
return null;
|
||||
|
||||
if (!_proto.TryIndex(component.Prototype, out PolymorphPrototype? proto))
|
||||
{
|
||||
_sawmill.Error($"{nameof(PolymorphSystem)} encountered an improperly initialized polymorph component while reverting. Entity {ToPrettyString(uid)}. Prototype: {component.Prototype}");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
var uidXform = Transform(uid);
|
||||
@@ -317,6 +317,8 @@ namespace Content.Server.Polymorph.Systems
|
||||
("child", Identity.Entity(parent, EntityManager))),
|
||||
parent);
|
||||
QueueDel(uid);
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
36
Content.Server/Polymorph/Toolshed/PolymorphCommand.cs
Normal file
36
Content.Server/Polymorph/Toolshed/PolymorphCommand.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Polymorph.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Polymorph;
|
||||
using Robust.Shared.Toolshed;
|
||||
using Robust.Shared.Toolshed.TypeParsers;
|
||||
|
||||
namespace Content.Server.Polymorph.Toolshed;
|
||||
|
||||
/// <summary>
|
||||
/// Polymorphs the given entity(s) into the target morph.
|
||||
/// </summary>
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.Fun)]
|
||||
public sealed class PolymorphCommand : ToolshedCommand
|
||||
{
|
||||
private PolymorphSystem? _system;
|
||||
|
||||
[CommandImplementation]
|
||||
public EntityUid? Polymorph(
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] Prototype<PolymorphPrototype> prototype
|
||||
)
|
||||
{
|
||||
_system ??= GetSys<PolymorphSystem>();
|
||||
|
||||
return _system.PolymorphEntity(input, prototype.Value);
|
||||
}
|
||||
|
||||
[CommandImplementation]
|
||||
public IEnumerable<EntityUid> Polymorph(
|
||||
[PipedArgument] IEnumerable<EntityUid> input,
|
||||
[CommandArgument] Prototype<PolymorphPrototype> prototype
|
||||
)
|
||||
=> input.Select(x => Polymorph(x, prototype)).Where(x => x is not null).Select(x => (EntityUid)x!);
|
||||
}
|
||||
30
Content.Server/Polymorph/Toolshed/UnpolymorphCommand.cs
Normal file
30
Content.Server/Polymorph/Toolshed/UnpolymorphCommand.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Polymorph.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Polymorph;
|
||||
using Robust.Shared.Toolshed;
|
||||
using Robust.Shared.Toolshed.TypeParsers;
|
||||
|
||||
namespace Content.Server.Polymorph.Toolshed;
|
||||
|
||||
/// <summary>
|
||||
/// Undoes a polymorph, reverting the target to it's original form.
|
||||
/// </summary>
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.Fun)]
|
||||
public sealed class UnpolymorphCommand : ToolshedCommand
|
||||
{
|
||||
private PolymorphSystem? _system;
|
||||
|
||||
[CommandImplementation]
|
||||
public EntityUid? Unpolymorph([PipedArgument] EntityUid input)
|
||||
{
|
||||
_system ??= GetSys<PolymorphSystem>();
|
||||
|
||||
return _system.Revert(input);
|
||||
}
|
||||
|
||||
[CommandImplementation]
|
||||
public IEnumerable<EntityUid> Unpolymorph([PipedArgument] IEnumerable<EntityUid> input)
|
||||
=> input.Select(Unpolymorph).Where(x => x is not null).Select(x => (EntityUid)x!);
|
||||
}
|
||||
Reference in New Issue
Block a user