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):
EngineEvent = modules['engineevents'].EngineEvent
from engineevents import EngineEvent
def init(aoEngineEvents):
aoEngineEvents.append(EngineEvent('level', lambda _: []))

View File

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

View File

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

14
main.py
View File

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