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.Contains(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();
// Optional: Define a log delegate for convenience
d.setLogger(delegate(string s) {
Echo("Log: "+s);
});
d.addHandler("foo", delegate() {
Echo("Custom Foo Action");
});
d.dispatch(arg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment