Moved main.py to serve.py, implemented modularization and added control module
This commit is contained in:
parent
ad6190b46a
commit
e185786959
6 changed files with 138 additions and 21 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from threading import Thread
|
||||
from typing import Callable
|
||||
from inspect import stack
|
||||
from re import compile
|
||||
|
||||
import libcommon
|
||||
|
|
@ -10,16 +11,19 @@ def reader() -> None:
|
|||
for line in libcommon.minecraftProc.stdout:
|
||||
line = line.rstrip("\n")
|
||||
print(line)
|
||||
for pattern, func in libcommon.minecraftOutputBinds:
|
||||
match = pattern.match(line)
|
||||
if match:
|
||||
func(*match.groups())
|
||||
break
|
||||
for module in libcommon.loadedMods:
|
||||
if module in libcommon.minecraftOutputBinds:
|
||||
for pattern, func in libcommon.minecraftOutputBinds[module]:
|
||||
match = pattern.match(line)
|
||||
if match:
|
||||
func(*match.groups())
|
||||
break
|
||||
|
||||
|
||||
def onConsoleOutput(pattern: str) -> Callable:
|
||||
def decorator(func: Callable) -> Callable:
|
||||
libcommon.minecraftOutputBinds.append((compile(pattern), func))
|
||||
module = stack()[1].filename.split("/")[-1][:-3]
|
||||
libcommon.minecraftOutputBinds[module].append((compile(pattern), func))
|
||||
return func
|
||||
return decorator
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue