From 34825464dcbeb71e0de6f9029a0a11f13aebc26f Mon Sep 17 00:00:00 2001 From: Kyle Tyo <36606155+VerinSenpai@users.noreply.github.com> Date: Sun, 29 Jun 2025 21:41:55 -0400 Subject: [PATCH] Power stat and nuke codes commands get some LEC love. (#38585) * commit * requested changes. --- .../Nuke/Commands/SendNukeCodesCommand.cs | 75 +++++++++---------- .../Power/Commands/PowerStatCommand.cs | 33 ++++---- .../en-US/commands/nukecodes-command.ftl | 2 + .../en-US/commands/powerstat-command.ftl | 6 ++ 4 files changed, 57 insertions(+), 59 deletions(-) create mode 100644 Resources/Locale/en-US/commands/nukecodes-command.ftl create mode 100644 Resources/Locale/en-US/commands/powerstat-command.ftl diff --git a/Content.Server/Nuke/Commands/SendNukeCodesCommand.cs b/Content.Server/Nuke/Commands/SendNukeCodesCommand.cs index d0e83e4f75..8ac4f95a97 100644 --- a/Content.Server/Nuke/Commands/SendNukeCodesCommand.cs +++ b/Content.Server/Nuke/Commands/SendNukeCodesCommand.cs @@ -1,55 +1,48 @@ using Content.Server.Administration; using Content.Server.Station.Components; using Content.Shared.Administration; -using JetBrains.Annotations; using Robust.Shared.Console; -namespace Content.Server.Nuke.Commands +namespace Content.Server.Nuke.Commands; + +[AdminCommand(AdminFlags.Fun)] +public sealed class SendNukeCodesCommand : LocalizedEntityCommands { - [UsedImplicitly] - [AdminCommand(AdminFlags.Fun)] - public sealed class SendNukeCodesCommand : IConsoleCommand + [Dependency] private readonly NukeCodePaperSystem _nukeCodeSystem = default!; + + public override string Command => "nukecodes"; + + public override void Execute(IConsoleShell shell, string argStr, string[] args) { - public string Command => "nukecodes"; - public string Description => "Send nuke codes to a station's communication consoles"; - public string Help => "nukecodes [station EntityUid]"; - - [Dependency] private readonly IEntityManager _entityManager = default!; - - public void Execute(IConsoleShell shell, string argStr, string[] args) + if (args.Length != 1) { - if (args.Length != 1) - { - shell.WriteError(Loc.GetString("shell-need-exactly-one-argument")); - return; - } - - if (!NetEntity.TryParse(args[0], out var uidNet) || !_entityManager.TryGetEntity(uidNet, out var uid)) - { - shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number")); - return; - } - - _entityManager.System().SendNukeCodes(uid.Value); + shell.WriteError(Loc.GetString("shell-need-exactly-one-argument")); + return; } - public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + if (!NetEntity.TryParse(args[0], out var uidNet) || !EntityManager.TryGetEntity(uidNet, out var uid)) { - if (args.Length != 1) - { - return CompletionResult.Empty; - } - - var stations = new List(); - var query = _entityManager.EntityQueryEnumerator(); - while (query.MoveNext(out var uid, out var stationData)) - { - var meta = _entityManager.GetComponent(uid); - - stations.Add(new CompletionOption(uid.ToString(), meta.EntityName)); - } - - return CompletionResult.FromHintOptions(stations, null); + shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number")); + return; } + + _nukeCodeSystem.SendNukeCodes(uid.Value); + } + + public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + if (args.Length != 1) + return CompletionResult.Empty; + + var stations = new List(); + var query = EntityManager.EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out _)) + { + var meta = EntityManager.GetComponent(uid); + + stations.Add(new CompletionOption(uid.ToString(), meta.EntityName)); + } + + return CompletionResult.FromHintOptions(stations, null); } } diff --git a/Content.Server/Power/Commands/PowerStatCommand.cs b/Content.Server/Power/Commands/PowerStatCommand.cs index 127050393a..b9d71ee9bc 100644 --- a/Content.Server/Power/Commands/PowerStatCommand.cs +++ b/Content.Server/Power/Commands/PowerStatCommand.cs @@ -3,25 +3,22 @@ using Content.Server.Power.EntitySystems; using Content.Shared.Administration; using Robust.Shared.Console; -namespace Content.Server.Power.Commands +namespace Content.Server.Power.Commands; + +[AdminCommand(AdminFlags.Debug)] +public sealed class PowerStatCommand : LocalizedEntityCommands { - [AdminCommand(AdminFlags.Debug)] - public sealed class PowerStatCommand : IConsoleCommand + [Dependency] private readonly PowerNetSystem _powerNet = default!; + + public override string Command => "powerstat"; + + public override void Execute(IConsoleShell shell, string argStr, string[] args) { - [Dependency] private readonly IEntityManager _e = default!; - - public string Command => "powerstat"; - public string Description => "Shows statistics for pow3r"; - public string Help => "Usage: powerstat"; - - public void Execute(IConsoleShell shell, string argStr, string[] args) - { - var stats = _e.System().GetStatistics(); - - shell.WriteLine($"networks: {stats.CountNetworks}"); - shell.WriteLine($"loads: {stats.CountLoads}"); - shell.WriteLine($"supplies: {stats.CountSupplies}"); - shell.WriteLine($"batteries: {stats.CountBatteries}"); - } + var stats = _powerNet.GetStatistics(); + shell.WriteLine(Loc.GetString("cmd-powerstat-output", + ("networks", stats.CountNetworks), + ("loads", stats.CountLoads), + ("supplies", stats.CountSupplies), + ("batteries", stats.CountBatteries))); } } diff --git a/Resources/Locale/en-US/commands/nukecodes-command.ftl b/Resources/Locale/en-US/commands/nukecodes-command.ftl new file mode 100644 index 0000000000..50e324c524 --- /dev/null +++ b/Resources/Locale/en-US/commands/nukecodes-command.ftl @@ -0,0 +1,2 @@ +cmd-nukecodes-desc = Send nuke codes to a station's communication consoles. +cmd-nukecodes-help = Usage: nukecodes diff --git a/Resources/Locale/en-US/commands/powerstat-command.ftl b/Resources/Locale/en-US/commands/powerstat-command.ftl new file mode 100644 index 0000000000..c22cd5e22a --- /dev/null +++ b/Resources/Locale/en-US/commands/powerstat-command.ftl @@ -0,0 +1,6 @@ +cmd-powerstat-desc = Shows statistics for pow3r. +cmd-powerstat-help = Usage: powerstat +cmd-powerstat-output = Networks: {$networks} + Loads: {$loads} + Supplies: {$supplies} + Batteries: {$batteries}