From 8cf907653cad08effb401ce0818c09bff634ef0a Mon Sep 17 00:00:00 2001 From: cynic Date: Thu, 16 Dec 2021 14:15:52 -0500 Subject: [PATCH] first commit --- .gitignore | 1 + events_def.py | 4 ++++ main.py | 21 +++++++++++++++++++++ scripts/script1.py | 4 ++++ scripts/script2.py | 6 ++++++ 5 files changed, 36 insertions(+) create mode 100644 .gitignore create mode 100644 events_def.py create mode 100644 main.py create mode 100644 scripts/script1.py create mode 100644 scripts/script2.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/events_def.py b/events_def.py new file mode 100644 index 0000000..e101e41 --- /dev/null +++ b/events_def.py @@ -0,0 +1,4 @@ +from enum import Enum +class events(Enum): + ONCE = 0, #once, on program start + PER_TICK = 1 #once per tick \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..a9dcacd --- /dev/null +++ b/main.py @@ -0,0 +1,21 @@ +import os +import sys +import time +from events_def import events + +sys.path.append("./scripts") + +plugins = list(map(lambda n : n.split(".py")[0], filter(lambda n : n[-3:] == ".py", os.listdir("./scripts")))) +plugins_loaded = [] + +print(plugins) +for plugin in plugins: + module = __import__(plugin) + plugins_loaded.append(module) + if events.ONCE in module.triggers: + getattr(module, "run")(None) + +for tick_count in range(1, 10): + for plugin in plugins_loaded: + if events.PER_TICK in plugin.triggers: + getattr(plugin, "run")(tick_count) \ No newline at end of file diff --git a/scripts/script1.py b/scripts/script1.py new file mode 100644 index 0000000..e0cf7e9 --- /dev/null +++ b/scripts/script1.py @@ -0,0 +1,4 @@ +from events_def import events +triggers = [events.ONCE] +def run(ctx): + print("wooooo, script1!") \ No newline at end of file diff --git a/scripts/script2.py b/scripts/script2.py new file mode 100644 index 0000000..541868a --- /dev/null +++ b/scripts/script2.py @@ -0,0 +1,6 @@ +from events_def import events +triggers = [events.PER_TICK, events.ONCE] +def run(ctx): + print("woooo, script2!") + if ctx: + print("run on tick:", ctx) \ No newline at end of file