generated from Distractic/LethalCompanyTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Changes to API and Vanillin Shell to allow for commands to acc…
…ept input
- Loading branch information
1 parent
c92c121
commit dbe84a0
Showing
11 changed files
with
101 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Computerdores; | ||
|
||
public struct CommandResult { | ||
public string output; | ||
public bool clearScreen; | ||
public bool success; | ||
|
||
public CommandResult(string output, bool clearScreen, bool success) { | ||
this.output = output; | ||
this.clearScreen = clearScreen; | ||
this.success = success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
namespace Computerdores; | ||
using System; | ||
|
||
public interface ICommand { | ||
namespace Computerdores; | ||
|
||
public interface ICommand : ICloneable { | ||
public string GetName(); | ||
|
||
public string PredictArguments(string partialArgumentsText); | ||
|
||
public (string output, bool clearScreen, bool success) Execute(string finalArgumentsText, ITerminal terminal); | ||
public CommandResult Execute(string input, ITerminal terminal, out bool wantsMoreInput); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Computerdores.Vanillin; | ||
|
||
public abstract class ASimpleCommand { | ||
|
||
public CommandResult Execute(string input, ITerminal terminal, out bool wantsMoreInput) { | ||
wantsMoreInput = false; | ||
return Execute(input, terminal); | ||
} | ||
|
||
protected abstract CommandResult Execute(string input, ITerminal terminal); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
namespace Computerdores.Vanillin; | ||
|
||
public class HelpCommand : ICommand { | ||
public class HelpCommand : ASimpleCommand, ICommand { | ||
public string GetName() => "help"; | ||
|
||
public string PredictArguments(string partialArgumentsText) { | ||
return partialArgumentsText; | ||
} | ||
|
||
public (string output, bool clearScreen, bool success) Execute(string finalArgumentsText, ITerminal terminal) { | ||
protected override CommandResult Execute(string input, ITerminal terminal) { | ||
Terminal vT = terminal.GetDriver().VanillaTerminal; | ||
return (Util.GetSpecialNode(vT, 13).displayText. | ||
return new CommandResult(Util.GetSpecialNode(vT, 13).displayText. | ||
Replace("[numberOfItemsOnRoute]", | ||
vT.numberOfItemsInDropship > 0 | ||
? $"{vT.numberOfItemsInDropship} purchased items on route." | ||
: "" | ||
), | ||
true, true); | ||
} | ||
|
||
public object Clone() => new HelpCommand(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
namespace Computerdores.Vanillin; | ||
|
||
public class OtherCommand : ICommand { | ||
public class OtherCommand : ASimpleCommand, ICommand { | ||
public string GetName() => "other"; | ||
|
||
public string PredictArguments(string partialArgumentsText) { | ||
return partialArgumentsText; | ||
} | ||
|
||
public (string output, bool clearScreen, bool success) Execute(string finalArgumentsText, ITerminal terminal) { | ||
return ( | ||
protected override CommandResult Execute(string input, ITerminal terminal) { | ||
return new CommandResult( | ||
Util.FindNoun(terminal.GetDriver().VanillaTerminal, "other").specialKeywordResult.displayText, | ||
true, true | ||
); | ||
} | ||
|
||
public object Clone() => new OtherCommand(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
namespace Computerdores.Vanillin; | ||
|
||
public class ScanCommand : ICommand { | ||
public class ScanCommand : ASimpleCommand, ICommand { | ||
public string GetName() => "scan"; | ||
|
||
public string PredictArguments(string partialArgumentsText) => partialArgumentsText; | ||
|
||
public (string output, bool clearScreen, bool success) Execute(string finalArgumentsText, ITerminal terminal) { | ||
protected override CommandResult Execute(string input, ITerminal terminal) { | ||
Terminal vT = terminal.GetDriver().VanillaTerminal; | ||
TerminalNode node = Util.FindNoun(terminal.GetDriver().VanillaTerminal, "scan").specialKeywordResult; | ||
return (vT.TextPostProcess(node.displayText, node), true, true); | ||
return new CommandResult(vT.TextPostProcess(node.displayText, node), true, true); | ||
} | ||
|
||
public object Clone() => new ScanCommand(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
namespace Computerdores.Vanillin; | ||
|
||
public class SwitchCommand : ICommand { | ||
public class SwitchCommand : ASimpleCommand, ICommand { | ||
public string GetName() => "switch"; | ||
|
||
public string PredictArguments(string partialArgumentsText) { // untested | ||
int index = Util.GetPlayerIndexByName(partialArgumentsText); | ||
return index != -1 ? StartOfRound.Instance.mapScreen.radarTargets[index].name : partialArgumentsText; | ||
} | ||
|
||
public (string output, bool clearScreen, bool success) Execute(string finalArgumentsText, ITerminal terminal) { | ||
int index = Util.GetPlayerIndexByName(finalArgumentsText); | ||
if (index == -1 && finalArgumentsText != "") return ("", false, false); | ||
protected override CommandResult Execute(string input, ITerminal terminal) { | ||
int index = Util.GetPlayerIndexByName(input); | ||
if (index == -1 && input != "") return new CommandResult("", false, false); | ||
if (index != -1) { | ||
StartOfRound.Instance.mapScreen.SwitchRadarTargetAndSync(index); | ||
} else { | ||
StartOfRound.Instance.mapScreen.SwitchRadarTargetForward(true); | ||
} | ||
return (Util.FindNoun(terminal.GetDriver().VanillaTerminal, "switch").specialKeywordResult.displayText, true, true); | ||
return new CommandResult( | ||
Util.FindNoun(terminal.GetDriver().VanillaTerminal, "switch").specialKeywordResult.displayText, | ||
true, true | ||
); | ||
} | ||
|
||
public object Clone() => new SwitchCommand(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters