Files
RobustToolbox/Robust.Client/Replays/Commands/ReplayCommand.cs
T
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

83 lines
2.3 KiB
C#

using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using Robust.Client.Replays.Playback;
using Robust.Shared.Console;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Replays;
namespace Robust.Client.Replays.Commands;
public abstract partial class BaseReplayCommand : LocalizedCommands
{
[Dependency] protected IReplayPlaybackManager PlaybackManager = default!;
public override string Description => Loc.GetString($"cmd-{Command.Replace('_', '-')}-desc");
public override string Help => Loc.GetString($"cmd-{Command.Replace('_', '-')}-help");
protected bool AssertPlaying(IConsoleShell shell, [NotNullWhen(true)] out ReplayData? replay)
{
if (PlaybackManager.Replay != null)
{
replay = PlaybackManager.Replay;
return true;
}
replay = null;
shell.WriteError(Loc.GetString("cmd-replay-error-no-replay"));
return false;
}
protected bool AssertPlaying(IConsoleShell shell)
=> AssertPlaying(shell, out _);
}
[UsedImplicitly]
public sealed class ReplayPlayCommand : BaseReplayCommand
{
public override string Command => IReplayPlaybackManager.PlayCommand;
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (AssertPlaying(shell))
PlaybackManager.Playing = true;
}
}
[UsedImplicitly]
public sealed class ReplayPauseCommand : BaseReplayCommand
{
public override string Command => IReplayPlaybackManager.PauseCommand;
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (AssertPlaying(shell))
PlaybackManager.Playing = false;
}
}
[UsedImplicitly]
public sealed class ReplayToggleCommand : BaseReplayCommand
{
public override string Command => IReplayPlaybackManager.ToggleCommand;
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (AssertPlaying(shell))
PlaybackManager.Playing = !PlaybackManager.Playing;
}
}
[UsedImplicitly]
public sealed class ReplayStopCommand : BaseReplayCommand
{
public override string Command => IReplayPlaybackManager.StopCommand;
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (AssertPlaying(shell))
PlaybackManager.StopReplay();
}
}