DebugPathfindingCommand.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Content.Client.NPC;
  2. using Content.Shared.NPC;
  3. using JetBrains.Annotations;
  4. using Robust.Shared.Console;
  5. using System.Linq;
  6. namespace Content.Client.Commands;
  7. [UsedImplicitly]
  8. public sealed class DebugPathfindingCommand : LocalizedCommands
  9. {
  10. [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
  11. public override string Command => "pathfinder";
  12. public override string Help => LocalizationManager.GetString($"cmd-{Command}-help", ("command", Command));
  13. public override void Execute(IConsoleShell shell, string argStr, string[] args)
  14. {
  15. var system = _entitySystemManager.GetEntitySystem<PathfindingSystem>();
  16. if (args.Length == 0)
  17. {
  18. system.Modes = PathfindingDebugMode.None;
  19. return;
  20. }
  21. foreach (var arg in args)
  22. {
  23. if (!Enum.TryParse<PathfindingDebugMode>(arg, out var mode))
  24. {
  25. shell.WriteError(LocalizationManager.GetString($"cmd-{Command}-error", ("arg", arg)));
  26. continue;
  27. }
  28. system.Modes ^= mode;
  29. shell.WriteLine(LocalizationManager.GetString($"cmd-{Command}-notify", ("arg", arg), ("newMode", (system.Modes & mode) != 0x0)));
  30. }
  31. }
  32. public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  33. {
  34. if (args.Length > 1)
  35. {
  36. return CompletionResult.Empty;
  37. }
  38. var values = Enum.GetValues<PathfindingDebugMode>().ToList();
  39. var options = new List<CompletionOption>();
  40. foreach (var val in values)
  41. {
  42. if (val == PathfindingDebugMode.None)
  43. continue;
  44. options.Add(new CompletionOption(val.ToString()));
  45. }
  46. return CompletionResult.FromOptions(options);
  47. }
  48. }