From d4db32ccb4db541ef98ac7db3022c5ec831f813b Mon Sep 17 00:00:00 2001 From: NGnius Date: Tue, 22 Oct 2019 22:37:23 -0400 Subject: [PATCH] Test and fix basic commands --- extracommands/ChainCommandEngine.cs | 45 +++++++++++++++---- .../SetTargetFramerateCommandEngine.cs | 4 +- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/extracommands/ChainCommandEngine.cs b/extracommands/ChainCommandEngine.cs index 000d51b..6404e1a 100644 --- a/extracommands/ChainCommandEngine.cs +++ b/extracommands/ChainCommandEngine.cs @@ -24,18 +24,20 @@ namespace ExtraCommands.Basics public override void Ready() { uREPL.RuntimeCommands.Register("Chain", ChainCommand, "Run two commands, one after the other"); - uREPL.RuntimeCommands.Register("ChainNoFail", ChainCommand, "Run two commands, one after the other even if the first one is invalid"); - uREPL.RuntimeCommands.Register("ChainQuiet", ChainCommand, "Run two commands, one after the other quietly"); + uREPL.RuntimeCommands.Register("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid"); + uREPL.RuntimeCommands.Register("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly"); } private void ChainCommand(string command1, string command2) { - bool success1 = uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command1); + string command1a = decomma(command1); + string command2a = decomma(command2); + bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success; if (!success1) { uREPL.Log.Error("First command was not executed successfully"); return; } - bool success2 = uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command2); + bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success; if (!success2) { uREPL.Log.Error("Second command was not executed successfully"); } @@ -43,11 +45,13 @@ namespace ExtraCommands.Basics private void ChainNoFailCommand(string command1, string command2) { - bool success1 = uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command1); + string command1a = decomma(command1); + string command2a = decomma(command2); + bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success; if (!success1) { uREPL.Log.Error("First command was not executed successfully"); } - bool success2 = uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command2); + bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success; if (!success2) { uREPL.Log.Error("Second command was not executed successfully"); } @@ -55,8 +59,33 @@ namespace ExtraCommands.Basics private void ChainQuietCommand(string command1, string command2) { - uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command1); - uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command2); + string command1a = decomma(command1); + string command2a = decomma(command2); + uREPL.Evaluator.Evaluate(command1a); + uREPL.Evaluator.Evaluate(command2a); + } + + private string decomma(string strIn) + { + string strOut = ""; + bool wasCommaLast = false; + foreach (char c in strIn) + { + if (wasCommaLast) + { + wasCommaLast = false; + if (c == ' ') + { + strOut = strOut.Substring(0, strOut.Length - 1); + } + } + if (c == ',') + { + wasCommaLast = true; + } + strOut += c; + } + return strOut; } public override void Dispose() diff --git a/extracommands/SetTargetFramerateCommandEngine.cs b/extracommands/SetTargetFramerateCommandEngine.cs index f05e98c..4d863e8 100644 --- a/extracommands/SetTargetFramerateCommandEngine.cs +++ b/extracommands/SetTargetFramerateCommandEngine.cs @@ -15,13 +15,13 @@ namespace ExtraCommands.Basics [CustomCommand("SetTargetFPS", "Set Gamecraft's target FPS")] class SetTargetFramerateCommandEngine : CustomCommandEngine { - public SetFOVCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) + public SetTargetFramerateCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) { } public override void Ready() { - uREPL.RuntimeCommands.Register("SetTargetFPS", SetFramerateCommand, "Set Gamecraft's target FPS"); + uREPL.RuntimeCommands.Register("SetTargetFPS", SetFramerateCommand, "Set Gamecraft's target FPS"); } private void SetFramerateCommand(int newFoV)