Make module loading in game more sane.

This commit is contained in:
bʰedoh₂ swé 2024-04-07 23:42:27 +05:00
parent f93dfb1fb2
commit eb6b4b987c
4 changed files with 12 additions and 19 deletions

View File

@ -1,3 +1,4 @@
def init(modules, aoEngineEvents): from engineevents import EngineEvent
EngineEvent = modules['engineevents'].EngineEvent
def init(aoEngineEvents):
aoEngineEvents.append(EngineEvent('level', lambda _: [])) aoEngineEvents.append(EngineEvent('level', lambda _: []))

View File

@ -1,10 +1,10 @@
import importlib.resources as impr import importlib.resources as impr
import sys import sys
import json import json
import serialize
from engineevents import EngineEvent
def init(modules, aoEngineEvents): def init(aoEngineEvents):
serialize = modules['serialize']
EngineEvent = modules['engineevents'].EngineEvent
curm = sys.modules[__name__] curm = sys.modules[__name__]
files = impr.files(curm) files = impr.files(curm)
level = None level = None

View File

@ -1,10 +1,10 @@
import importlib.resources as impr import importlib.resources as impr
import sys import sys
import json import json
import serialize
from engineevents import EngineEvent
def init(modules, aoEngineEvents): def init(aoEngineEvents):
serialize = modules['serialize']
EngineEvent = modules['engineevents'].EngineEvent
curm = sys.modules[__name__] curm = sys.modules[__name__]
files = impr.files(curm) files = impr.files(curm)
level = None level = None

14
main.py
View File

@ -2,6 +2,7 @@
from math import copysign, pi, acos from math import copysign, pi, acos
import sys import sys
import os
from importlib import import_module from importlib import import_module
import pygame import pygame
@ -123,17 +124,7 @@ def mainLoop():
except IndexError: except IndexError:
game = import_module("games.squareroom") game = import_module("games.squareroom")
game.init( game.init(aoEngineEvents)
{
'serialize': import_module('serialize'),
'alert': import_module('alert'),
'gyro': import_module('gyro'),
'engineevents': import_module('engineevents'),
'constants': import_module('constants'),
'lines': import_module('lines'),
},
aoEngineEvents
)
processevents() processevents()
while bCont: while bCont:
@ -184,5 +175,6 @@ def main():
return retstatus return retstatus
if __name__ == "__main__": if __name__ == "__main__":
sys.path.append(os.path.realpath(__file__))
if not main(): if not main():
print("An error occured") print("An error occured")