Last active
January 16, 2023 23:45
-
-
Save YarekTyshchenko/8d5760966fc1b5d56c20 to your computer and use it in GitHub Desktop.
Collection of Space Engineers C# Scripts
This file contains hidden or 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
| class Dispatch { | |
| Action<string> log = delegate(string s) {}; | |
| Dictionary<string, Action> methods = new Dictionary<string, Action>(); | |
| public void addHandler(string method, Action action) { | |
| methods.Add(method, action); | |
| } | |
| public void dispatch(string argument) { | |
| if (! methods.ContainsKey(argument)) { | |
| log("Argument '"+argument+"' doesn't exist in collection"); | |
| return; | |
| } | |
| Action action = methods[argument]; | |
| action(); | |
| } | |
| public void setLogger(Action<string> logger) { | |
| this.log = logger; | |
| } | |
| } |
This file contains hidden or 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
| void Main(string arg) { | |
| Dispatch d = new Dispatch(); | |
| d.setLogger(delegate(string s) { | |
| Echo("Log: "+s); | |
| }); | |
| d.addHandler("foo", delegate() { | |
| Echo("Custom Foo action"); | |
| }); | |
| d.addHandler("", delegate() { | |
| Echo("Default action"); | |
| }); | |
| d.dispatch(arg); | |
| } |
This file contains hidden or 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
| public class LCD { | |
| IMyTextPanel lcd; | |
| // Grid terminal system is needed here so the search happens in the right grid | |
| public LCD(IMyGridTerminalSystem gts, string panelName) { | |
| this.lcd = gts.GetBlockWithName(panelName) as IMyTextPanel; | |
| this.lcd.ShowPublicTextOnScreen(); | |
| } | |
| public LCD writeText(string text) { | |
| this.lcd.WritePublicText(text, true); | |
| return this; | |
| } | |
| public LCD writeLine(string line) { | |
| this.writeText(line+"\n"); | |
| return this; | |
| } | |
| public LCD clear() { | |
| this.lcd.WritePublicText("", false); | |
| return this; | |
| } | |
| } |
This file contains hidden or 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
| void Main(string arg) { | |
| // Second parameter is the name of the panel to search for | |
| LCD lcd = new LCD(GridTerminalSystem, "LCD Panel").clear(); | |
| lcd.writeLine("Speed: "+10); | |
| lcd.writeLine("Seconds Delta: "+2); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment