Toolshed (#17895)
* ogh * i should save my work * ogh * hhcdfhjbghshbxdfhghshc - lots of bugs in parsing still - invocation is a stub * expr parsing works * awawa * Saving work * Improve APIs a bit all around, add shortcuts. * awa * awa * AAAAAA * save work * Move shit to engine * lord * bql is kill * forgot the fucking bike rack * bql is kill for real * pjb will kill me * aughfhbdj * adgddf * gdsgvfvxshngfgh * b * hfsjhghj * a * tf you mean i have to document it * follow C# standards * Assorted cleanup and documentation pass, minor bugfix in ValueRefParser. * Start porting old commands, remove that pesky prefix in favor of integrating with the shell. * bw * Fix valueref up a bit, improve autocomplete for it. * awa * fix tests * git shut up * Arithmetic commands. * parse improvements * Update engine. --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
24
Content.Server/Administration/Toolshed/AdminsCommand.cs
Normal file
24
Content.Server/Administration/Toolshed/AdminsCommand.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Toolshed;
|
||||
|
||||
namespace Content.Server.Administration.Toolshed;
|
||||
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.Admin)]
|
||||
public sealed class AdminsCommand : ToolshedCommand
|
||||
{
|
||||
[Dependency] private readonly IAdminManager _admin = default!;
|
||||
|
||||
[CommandImplementation("active")]
|
||||
public IEnumerable<IPlayerSession> Active()
|
||||
{
|
||||
return _admin.ActiveAdmins;
|
||||
}
|
||||
|
||||
[CommandImplementation("all")]
|
||||
public IEnumerable<IPlayerSession> All()
|
||||
{
|
||||
return _admin.AllAdmins;
|
||||
}
|
||||
}
|
||||
16
Content.Server/Administration/Toolshed/MarkedCommand.cs
Normal file
16
Content.Server/Administration/Toolshed/MarkedCommand.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Toolshed;
|
||||
|
||||
namespace Content.Server.Administration.Toolshed;
|
||||
|
||||
[ToolshedCommand, AnyCommand]
|
||||
public sealed class MarkedCommand : ToolshedCommand
|
||||
{
|
||||
[CommandImplementation]
|
||||
public IEnumerable<EntityUid> Marked([CommandInvocationContext] IInvocationContext ctx)
|
||||
{
|
||||
var res = (IEnumerable<EntityUid>?)ctx.ReadVar("marked");
|
||||
res ??= Array.Empty<EntityUid>();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
22
Content.Server/Administration/Toolshed/RejuvenateCommand.cs
Normal file
22
Content.Server/Administration/Toolshed/RejuvenateCommand.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Content.Server.Administration.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Toolshed;
|
||||
|
||||
namespace Content.Server.Administration.Toolshed;
|
||||
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.Admin)]
|
||||
public sealed class RejuvenateCommand : ToolshedCommand
|
||||
{
|
||||
private RejuvenateSystem? _rejuvenate;
|
||||
[CommandImplementation]
|
||||
public IEnumerable<EntityUid> Rejuvenate([PipedArgument] IEnumerable<EntityUid> input)
|
||||
{
|
||||
_rejuvenate ??= GetSys<RejuvenateSystem>();
|
||||
|
||||
foreach (var i in input)
|
||||
{
|
||||
_rejuvenate.PerformRejuvenate(i);
|
||||
yield return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Content.Server/Administration/Toolshed/SolutionCommand.cs
Normal file
49
Content.Server/Administration/Toolshed/SolutionCommand.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Robust.Shared.Toolshed;
|
||||
using Robust.Shared.Toolshed.Syntax;
|
||||
|
||||
namespace Content.Server.Administration.Toolshed;
|
||||
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.Debug)]
|
||||
public sealed class SolutionCommand : ToolshedCommand
|
||||
{
|
||||
private SolutionContainerSystem? _solutionContainer;
|
||||
|
||||
[CommandImplementation("get")]
|
||||
public SolutionRef? Get(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] ValueRef<string> name
|
||||
)
|
||||
{
|
||||
_solutionContainer ??= GetSys<SolutionContainerSystem>();
|
||||
|
||||
_solutionContainer.TryGetSolution(input, name.Evaluate(ctx)!, out var solution);
|
||||
|
||||
if (solution is not null)
|
||||
return new SolutionRef(input, solution);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[CommandImplementation("get")]
|
||||
public IEnumerable<SolutionRef> Get(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] IEnumerable<EntityUid> input,
|
||||
[CommandArgument] ValueRef<string> name
|
||||
)
|
||||
{
|
||||
return input.Select(x => Get(ctx, x, name)).Where(x => x is not null).Cast<SolutionRef>();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly record struct SolutionRef(EntityUid Owner, Solution Solution)
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Owner} {Solution}";
|
||||
}
|
||||
}
|
||||
106
Content.Server/Administration/Toolshed/TagCommand.cs
Normal file
106
Content.Server/Administration/Toolshed/TagCommand.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Toolshed;
|
||||
using Robust.Shared.Toolshed.Syntax;
|
||||
using Robust.Shared.Toolshed.TypeParsers;
|
||||
|
||||
namespace Content.Server.Administration.Toolshed;
|
||||
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.Debug)]
|
||||
public sealed class TagCommand : ToolshedCommand
|
||||
{
|
||||
private TagSystem? _tag;
|
||||
|
||||
[CommandImplementation("list")]
|
||||
public IEnumerable<string> List([PipedArgument] IEnumerable<EntityUid> ent)
|
||||
{
|
||||
return ent.SelectMany(x =>
|
||||
{
|
||||
if (TryComp<TagComponent>(x, out var tags))
|
||||
// Note: Cast is required for C# to figure out the type signature.
|
||||
return (IEnumerable<string>)tags.Tags;
|
||||
return Array.Empty<string>();
|
||||
});
|
||||
}
|
||||
|
||||
[CommandImplementation("add")]
|
||||
public EntityUid Add(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
|
||||
)
|
||||
{
|
||||
_tag ??= GetSys<TagSystem>();
|
||||
_tag.AddTag(input, @ref.Evaluate(ctx)!);
|
||||
return input;
|
||||
}
|
||||
|
||||
[CommandImplementation("add")]
|
||||
public IEnumerable<EntityUid> Add(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] IEnumerable<EntityUid> input,
|
||||
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
|
||||
)
|
||||
=> input.Select(x => Add(ctx, x, @ref));
|
||||
|
||||
[CommandImplementation("rm")]
|
||||
public EntityUid Rm(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
|
||||
)
|
||||
{
|
||||
_tag ??= GetSys<TagSystem>();
|
||||
_tag.RemoveTag(input, @ref.Evaluate(ctx)!);
|
||||
return input;
|
||||
}
|
||||
|
||||
[CommandImplementation("rm")]
|
||||
public IEnumerable<EntityUid> Rm(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] IEnumerable<EntityUid> input,
|
||||
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
|
||||
)
|
||||
=> input.Select(x => Rm(ctx, x, @ref));
|
||||
|
||||
[CommandImplementation("addmany")]
|
||||
public EntityUid AddMany(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
|
||||
)
|
||||
{
|
||||
_tag ??= GetSys<TagSystem>();
|
||||
_tag.AddTags(input, @ref.Evaluate(ctx)!);
|
||||
return input;
|
||||
}
|
||||
|
||||
[CommandImplementation("addmany")]
|
||||
public IEnumerable<EntityUid> AddMany(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] IEnumerable<EntityUid> input,
|
||||
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
|
||||
)
|
||||
=> input.Select(x => AddMany(ctx, x, @ref));
|
||||
|
||||
[CommandImplementation("rmmany")]
|
||||
public EntityUid RmMany(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
|
||||
)
|
||||
{
|
||||
_tag ??= GetSys<TagSystem>();
|
||||
_tag.RemoveTags(input, @ref.Evaluate(ctx)!);
|
||||
return input;
|
||||
}
|
||||
|
||||
[CommandImplementation("rmmany")]
|
||||
public IEnumerable<EntityUid> RmMany(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] IEnumerable<EntityUid> input,
|
||||
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
|
||||
)
|
||||
=> input.Select(x => RmMany(ctx, x, @ref));
|
||||
}
|
||||
Reference in New Issue
Block a user