Files
RobustToolbox/Robust.Shared/Console/LocalizedCommands.cs
83c2a1be11 [Dependency] source generator part 2 (#6550)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Apply dependencies generator changes to all code

* Release notes

* Preprocessor got hands

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:33 +02:00

65 lines
2.2 KiB
C#

using System.Threading;
using System.Threading.Tasks;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Toolshed;
namespace Robust.Shared.Console;
/// <summary>
/// A variant on <see cref="IConsoleCommand"/> that has some built-in default localization strings.
/// </summary>
/// <remarks>
/// For server commands, it is much preferred to use <see cref="ToolshedCommand"/>.
/// </remarks>
public abstract partial class LocalizedCommands : IConsoleCommand
{
[Dependency] protected ILocalizationManager LocalizationManager = default!;
public ILocalizationManager Loc => LocalizationManager;
/// <inheritdoc />
public abstract string Command { get; }
/// <inheritdoc />
public virtual string Description => LocalizationManager.TryGetString($"cmd-{Command}-desc", out var val) ? val : "";
/// <inheritdoc />
public virtual string Help => LocalizationManager.TryGetString($"cmd-{Command}-help", out var val, ("command", Command)) ? val : "";
/// <inheritdoc />
public virtual bool RequireServerOrSingleplayer => false;
/// <inheritdoc />
public abstract void Execute(IConsoleShell shell, string argStr, string[] args);
/// <inheritdoc />
public virtual CompletionResult GetCompletion(IConsoleShell shell, string[] args) => CompletionResult.Empty;
/// <inheritdoc />
public virtual ValueTask<CompletionResult> GetCompletionAsync(IConsoleShell shell, string[] args, string argStr,
CancellationToken cancel)
{
return ValueTask.FromResult(GetCompletion(shell, args));
}
}
/// <summary>
/// Base class for localized console commands that run in "entity space".
/// </summary>
/// <remarks>
/// <para>
/// This type of command is registered only while the entity system is active.
/// On the client this means that the commands are only available while connected to a server or in single player.
/// </para>
/// <para>
/// These commands are allowed to take dependencies on entity systems, reducing boilerplate for many usages.
/// </para>
/// </remarks>
public abstract partial class LocalizedEntityCommands : LocalizedCommands, IEntityConsoleCommand
{
[Dependency]
protected EntityManager EntityManager = default!;
}