Skip to content

Commit

Permalink
fix(VanillinTerminal): Execution of a command will now be terminated …
Browse files Browse the repository at this point in the history
…if execution fails instead of forcing the player to reopen the terminal.
  • Loading branch information
Computerdores committed Apr 8, 2024
1 parent efbf5b9 commit 24dc0f5
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions AdvancedTerminalAPI/Vanillin/VanillinTerminal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using BepInEx.Logging;
using HarmonyLib;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class VanillinTerminal : ITerminal {
foreach (TerminalKeyword terminalKeyword in _driver.VanillaTerminal.terminalNodes.allKeywords.Where(keyword => keyword.accessTerminalObjects)) {
AddBuiltinCommand(new AccessibleObjectCommand(terminalKeyword.word));
}
foreach (BuyItemCommand command in BuyItemCommand.GetAll(this)) {
AddBuiltinCommand(command);
}
}

public InputFieldDriver GetDriver() => _driver;
Expand All @@ -58,11 +62,22 @@ public class VanillinTerminal : ITerminal {
}
if (_currentCommand is {} command) {
Log.LogInfo($"Executing Command ({_currentCommand.GetName()}) for input : '{text}'");
CommandResult result = command.Execute(input, this, out bool more);
CommandResult result;
bool more;
try {
result = command.Execute(input, this, out more);
} catch (Exception e) {
result = new CommandResult(
"An Error occured while executing the command.\nPlease contact the author of the mod that the command is from.\n\n",
true, true
);
more = false;
Log.LogInfo($"An error occurred during execution of '{_currentCommand.GetName()}': {e}");
}
if (result.success) {
_driver.DisplayText(result.output, result.clearScreen);
} else {
Log.LogInfo($"Command execution failed for input ({_currentCommand.GetName()}): '{text}'");
Log.LogInfo($"Command execution was not successful for input ({_currentCommand.GetName()}): '{text}'");
_driver.DisplayText(SpecialText(11), true);
}
if (!more) _currentCommand = null;
Expand Down

0 comments on commit 24dc0f5

Please sign in to comment.