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:
129
Content.Server/Station/Commands/JobsCommand.cs
Normal file
129
Content.Server/Station/Commands/JobsCommand.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Toolshed;
|
||||
using Robust.Shared.Toolshed.Syntax;
|
||||
using Robust.Shared.Toolshed.TypeParsers;
|
||||
|
||||
namespace Content.Server.Station.Commands;
|
||||
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.VarEdit)]
|
||||
public sealed class JobsCommand : ToolshedCommand
|
||||
{
|
||||
private StationJobsSystem? _jobs;
|
||||
|
||||
[CommandImplementation("jobs")]
|
||||
public IEnumerable<JobSlotRef> Jobs([PipedArgument] EntityUid station)
|
||||
{
|
||||
_jobs ??= GetSys<StationJobsSystem>();
|
||||
|
||||
foreach (var (job, _) in _jobs.GetJobs(station))
|
||||
{
|
||||
yield return new JobSlotRef(job, station, _jobs, EntityManager);
|
||||
}
|
||||
}
|
||||
|
||||
[CommandImplementation("jobs")]
|
||||
public IEnumerable<JobSlotRef> Jobs([PipedArgument] IEnumerable<EntityUid> stations)
|
||||
=> stations.SelectMany(Jobs);
|
||||
|
||||
[CommandImplementation("job")]
|
||||
public JobSlotRef Job([PipedArgument] EntityUid station, [CommandArgument] Prototype<JobPrototype> job)
|
||||
{
|
||||
_jobs ??= GetSys<StationJobsSystem>();
|
||||
|
||||
return new JobSlotRef(job.Value.ID, station, _jobs, EntityManager);
|
||||
}
|
||||
|
||||
[CommandImplementation("job")]
|
||||
public IEnumerable<JobSlotRef> Job([PipedArgument] IEnumerable<EntityUid> stations, [CommandArgument] Prototype<JobPrototype> job)
|
||||
=> stations.Select(x => Job(x, job));
|
||||
|
||||
[CommandImplementation("isinfinite")]
|
||||
public bool IsInfinite([PipedArgument] JobSlotRef job, [CommandInverted] bool inverted)
|
||||
=> job.Infinite() ^ inverted;
|
||||
|
||||
[CommandImplementation("isinfinite")]
|
||||
public IEnumerable<bool> IsInfinite([PipedArgument] IEnumerable<JobSlotRef> jobs, [CommandInverted] bool inverted)
|
||||
=> jobs.Select(x => IsInfinite(x, inverted));
|
||||
|
||||
[CommandImplementation("adjust")]
|
||||
public JobSlotRef Adjust(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] JobSlotRef @ref,
|
||||
[CommandArgument] ValueRef<int> by
|
||||
)
|
||||
{
|
||||
_jobs ??= GetSys<StationJobsSystem>();
|
||||
_jobs.TryAdjustJobSlot(@ref.Station, @ref.Job, by.Evaluate(ctx), true, true);
|
||||
return @ref;
|
||||
}
|
||||
|
||||
[CommandImplementation("adjust")]
|
||||
public IEnumerable<JobSlotRef> Adjust(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] IEnumerable<JobSlotRef> @ref,
|
||||
[CommandArgument] ValueRef<int> by
|
||||
)
|
||||
=> @ref.Select(x => Adjust(ctx, x, by));
|
||||
|
||||
|
||||
[CommandImplementation("set")]
|
||||
public JobSlotRef Set(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] JobSlotRef @ref,
|
||||
[CommandArgument] ValueRef<int> by
|
||||
)
|
||||
{
|
||||
_jobs ??= GetSys<StationJobsSystem>();
|
||||
_jobs.TrySetJobSlot(@ref.Station, @ref.Job, by.Evaluate(ctx), true);
|
||||
return @ref;
|
||||
}
|
||||
|
||||
[CommandImplementation("set")]
|
||||
public IEnumerable<JobSlotRef> Set(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] IEnumerable<JobSlotRef> @ref,
|
||||
[CommandArgument] ValueRef<int> by
|
||||
)
|
||||
=> @ref.Select(x => Set(ctx, x, by));
|
||||
|
||||
[CommandImplementation("amount")]
|
||||
public int Amount(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] JobSlotRef @ref
|
||||
)
|
||||
{
|
||||
_jobs ??= GetSys<StationJobsSystem>();
|
||||
_jobs.TryGetJobSlot(@ref.Station, @ref.Job, out var slots);
|
||||
return (int)(slots ?? 0);
|
||||
}
|
||||
|
||||
[CommandImplementation("amount")]
|
||||
public IEnumerable<int> Amount(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] IEnumerable<JobSlotRef> @ref
|
||||
)
|
||||
=> @ref.Select(x => Amount(ctx, x));
|
||||
}
|
||||
|
||||
// Used for Toolshed queries.
|
||||
public readonly record struct JobSlotRef(string Job, EntityUid Station, StationJobsSystem Jobs, IEntityManager EntityManager)
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
if (!Jobs.TryGetJobSlot(Station, Job, out var slot))
|
||||
{
|
||||
return $"{EntityManager.ToPrettyString(Station)} job {Job} : (not a slot)";
|
||||
}
|
||||
|
||||
return $"{EntityManager.ToPrettyString(Station)} job {Job} : {slot?.ToString() ?? "infinite"}";
|
||||
}
|
||||
|
||||
public bool Infinite()
|
||||
{
|
||||
return Jobs.TryGetJobSlot(Station, Job, out var slot) && slot is null;
|
||||
}
|
||||
}
|
||||
126
Content.Server/Station/Commands/StationCommand.cs
Normal file
126
Content.Server/Station/Commands/StationCommand.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Toolshed;
|
||||
using Robust.Shared.Toolshed.Errors;
|
||||
using Robust.Shared.Toolshed.Syntax;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Station.Commands;
|
||||
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.Admin)]
|
||||
public sealed class StationsCommand : ToolshedCommand
|
||||
{
|
||||
private StationSystem? _station;
|
||||
|
||||
[CommandImplementation("list")]
|
||||
public IEnumerable<EntityUid> List()
|
||||
{
|
||||
_station ??= GetSys<StationSystem>();
|
||||
|
||||
return _station.GetStationsSet();
|
||||
}
|
||||
|
||||
[CommandImplementation("get")]
|
||||
public EntityUid Get([CommandInvocationContext] IInvocationContext ctx)
|
||||
{
|
||||
_station ??= GetSys<StationSystem>();
|
||||
|
||||
var set = _station.GetStationsSet();
|
||||
if (set.Count > 1 || set.Count == 0)
|
||||
ctx.ReportError(new OnlyOneStationsError());
|
||||
|
||||
return set.FirstOrDefault();
|
||||
}
|
||||
|
||||
[CommandImplementation("getowningstation")]
|
||||
public IEnumerable<EntityUid?> GetOwningStation([PipedArgument] IEnumerable<EntityUid> input)
|
||||
=> input.Select(GetOwningStation);
|
||||
|
||||
[CommandImplementation("getowningstation")]
|
||||
public EntityUid? GetOwningStation([PipedArgument] EntityUid input)
|
||||
{
|
||||
_station ??= GetSys<StationSystem>();
|
||||
|
||||
return _station.GetOwningStation(input);
|
||||
}
|
||||
|
||||
[CommandImplementation("largestgrid")]
|
||||
public EntityUid? LargestGrid([PipedArgument] EntityUid input)
|
||||
{
|
||||
_station ??= GetSys<StationSystem>();
|
||||
|
||||
return _station.GetLargestGrid(Comp<StationDataComponent>(input));
|
||||
}
|
||||
|
||||
[CommandImplementation("largestgrid")]
|
||||
public IEnumerable<EntityUid?> LargestGrid([PipedArgument] IEnumerable<EntityUid> input)
|
||||
=> input.Select(LargestGrid);
|
||||
|
||||
|
||||
[CommandImplementation("grids")]
|
||||
public IEnumerable<EntityUid> Grids([PipedArgument] EntityUid input)
|
||||
=> Comp<StationDataComponent>(input).Grids;
|
||||
|
||||
[CommandImplementation("grids")]
|
||||
public IEnumerable<EntityUid> Grids([PipedArgument] IEnumerable<EntityUid> input)
|
||||
=> input.SelectMany(Grids);
|
||||
|
||||
[CommandImplementation("config")]
|
||||
public StationConfig? Config([PipedArgument] EntityUid input)
|
||||
=> Comp<StationDataComponent>(input).StationConfig;
|
||||
|
||||
[CommandImplementation("config")]
|
||||
public IEnumerable<StationConfig?> Config([PipedArgument] IEnumerable<EntityUid> input)
|
||||
=> input.Select(Config);
|
||||
|
||||
[CommandImplementation("addgrid")]
|
||||
public void AddGrid(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] ValueRef<EntityUid> grid
|
||||
)
|
||||
{
|
||||
_station ??= GetSys<StationSystem>();
|
||||
|
||||
_station.AddGridToStation(input, grid.Evaluate(ctx));
|
||||
}
|
||||
|
||||
[CommandImplementation("rmgrid")]
|
||||
public void RmGrid(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] ValueRef<EntityUid> grid
|
||||
)
|
||||
{
|
||||
_station ??= GetSys<StationSystem>();
|
||||
|
||||
_station.RemoveGridFromStation(input, grid.Evaluate(ctx));
|
||||
}
|
||||
|
||||
[CommandImplementation("rename")]
|
||||
public void Rename([CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] ValueRef<string> name
|
||||
)
|
||||
{
|
||||
_station ??= GetSys<StationSystem>();
|
||||
|
||||
_station.RenameStation(input, name.Evaluate(ctx)!);
|
||||
}
|
||||
}
|
||||
|
||||
public record struct OnlyOneStationsError : IConError
|
||||
{
|
||||
public FormattedMessage DescribeInner()
|
||||
{
|
||||
return FormattedMessage.FromMarkup("This command doesn't function if there is more than one or no stations, explicitly specify a station with the ent command or similar.");
|
||||
}
|
||||
|
||||
public string? Expression { get; set; }
|
||||
public Vector2i? IssueSpan { get; set; }
|
||||
public StackTrace? Trace { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user