Moar Gamecraft commands!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.5KB

  1. using System;
  2. using RobocraftX.GUI.CommandLine;
  3. using RobocraftX.Multiplayer;
  4. using RobocraftX.StateSync;
  5. using RobocraftX.Character;
  6. using Svelto.ECS;
  7. using Unity.Entities;
  8. using UnityEngine;
  9. using uREPL;
  10. using Svelto.Context;
  11. using RobocraftX;
  12. namespace ExtraCommands.Basics
  13. {
  14. [CustomCommand]
  15. class ChainCommandEngine : CustomCommandEngine
  16. {
  17. public ChainCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
  18. {
  19. }
  20. public override void Ready()
  21. {
  22. CustomCommandUtility.Register<string, string>("Chain", ChainCommand, "Run two commands, one after the other");
  23. CustomCommandUtility.Register<string, string>("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid");
  24. CustomCommandUtility.Register<string, string>("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly");
  25. }
  26. private void ChainCommand(string command1, string command2)
  27. {
  28. string command1a = decomma(command1);
  29. string command2a = decomma(command2);
  30. bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success;
  31. if (!success1) {
  32. uREPL.Log.Error("First command was not executed successfully");
  33. return;
  34. }
  35. bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success;
  36. if (!success2) {
  37. uREPL.Log.Error("Second command was not executed successfully");
  38. }
  39. }
  40. private void ChainNoFailCommand(string command1, string command2)
  41. {
  42. string command1a = decomma(command1);
  43. string command2a = decomma(command2);
  44. bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success;
  45. if (!success1) {
  46. uREPL.Log.Error("First command was not executed successfully");
  47. }
  48. bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success;
  49. if (!success2) {
  50. uREPL.Log.Error("Second command was not executed successfully");
  51. }
  52. }
  53. private void ChainQuietCommand(string command1, string command2)
  54. {
  55. string command1a = decomma(command1);
  56. string command2a = decomma(command2);
  57. uREPL.Evaluator.Evaluate(command1a);
  58. uREPL.Evaluator.Evaluate(command2a);
  59. }
  60. private string decomma(string strIn)
  61. {
  62. string strOut = "";
  63. bool wasCommaLast = false;
  64. foreach (char c in strIn)
  65. {
  66. if (wasCommaLast)
  67. {
  68. wasCommaLast = false;
  69. if (c == ' ')
  70. {
  71. strOut = strOut.Substring(0, strOut.Length - 1);
  72. }
  73. }
  74. if (c == ',')
  75. {
  76. wasCommaLast = true;
  77. }
  78. strOut += c;
  79. }
  80. return strOut;
  81. }
  82. public override void Dispose()
  83. {
  84. CustomCommandUtility.Unregister("Chain");
  85. CustomCommandUtility.Unregister("ChainNoFail");
  86. CustomCommandUtility.Unregister("ChainQuiet");
  87. }
  88. }
  89. }