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 List() { _station ??= GetSys(); return _station.GetStationsSet(); } [CommandImplementation("get")] public EntityUid Get([CommandInvocationContext] IInvocationContext ctx) { _station ??= GetSys(); var set = _station.GetStationsSet(); if (set.Count > 1 || set.Count == 0) ctx.ReportError(new OnlyOneStationsError()); return set.FirstOrDefault(); } [CommandImplementation("getowningstation")] public IEnumerable GetOwningStation([PipedArgument] IEnumerable input) => input.Select(GetOwningStation); [CommandImplementation("getowningstation")] public EntityUid? GetOwningStation([PipedArgument] EntityUid input) { _station ??= GetSys(); return _station.GetOwningStation(input); } [CommandImplementation("largestgrid")] public EntityUid? LargestGrid([PipedArgument] EntityUid input) { _station ??= GetSys(); return _station.GetLargestGrid(Comp(input)); } [CommandImplementation("largestgrid")] public IEnumerable LargestGrid([PipedArgument] IEnumerable input) => input.Select(LargestGrid); [CommandImplementation("grids")] public IEnumerable Grids([PipedArgument] EntityUid input) => Comp(input).Grids; [CommandImplementation("grids")] public IEnumerable Grids([PipedArgument] IEnumerable input) => input.SelectMany(Grids); [CommandImplementation("config")] public StationConfig? Config([PipedArgument] EntityUid input) => Comp(input).StationConfig; [CommandImplementation("config")] public IEnumerable Config([PipedArgument] IEnumerable input) => input.Select(Config); [CommandImplementation("addgrid")] public void AddGrid( [CommandInvocationContext] IInvocationContext ctx, [PipedArgument] EntityUid input, [CommandArgument] ValueRef grid ) { _station ??= GetSys(); _station.AddGridToStation(input, grid.Evaluate(ctx)); } [CommandImplementation("rmgrid")] public void RmGrid( [CommandInvocationContext] IInvocationContext ctx, [PipedArgument] EntityUid input, [CommandArgument] ValueRef grid ) { _station ??= GetSys(); _station.RemoveGridFromStation(input, grid.Evaluate(ctx)); } [CommandImplementation("rename")] public void Rename([CommandInvocationContext] IInvocationContext ctx, [PipedArgument] EntityUid input, [CommandArgument] ValueRef name ) { _station ??= GetSys(); _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; } }