Skip to content

Instantly share code, notes, and snippets.

@YarekTyshchenko
Last active January 16, 2023 23:45
Show Gist options
  • Select an option

  • Save YarekTyshchenko/8d5760966fc1b5d56c20 to your computer and use it in GitHub Desktop.

Select an option

Save YarekTyshchenko/8d5760966fc1b5d56c20 to your computer and use it in GitHub Desktop.
Collection of Space Engineers C# Scripts
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;
}
}
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);
}
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;
}
}
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