2023-09-15 19:35:32 -05:00
|
|
|
# pyright: reportUnboundVariable=false
|
2020-06-10 23:22:53 +02:00
|
|
|
|
|
|
|
|
import glob
|
2021-07-18 10:33:08 +02:00
|
|
|
import importlib
|
2020-06-10 23:22:53 +02:00
|
|
|
import os
|
2021-07-18 10:33:36 +02:00
|
|
|
import site
|
2020-06-11 23:00:25 +02:00
|
|
|
import sys
|
2020-06-10 23:22:53 +02:00
|
|
|
import typing
|
|
|
|
|
|
|
|
|
|
from .basic_game import BasicGame
|
|
|
|
|
from .basic_game_ini import BasicIniGame
|
|
|
|
|
|
2021-07-18 10:33:36 +02:00
|
|
|
site.addsitedir(os.path.join(os.path.dirname(__file__), "lib"))
|
|
|
|
|
|
|
|
|
|
|
2020-06-11 22:31:09 +02:00
|
|
|
BasicGame.setup()
|
|
|
|
|
|
2020-06-10 23:22:53 +02:00
|
|
|
|
|
|
|
|
def createPlugins():
|
2020-12-18 19:38:40 +01:00
|
|
|
# List of game class from python:
|
|
|
|
|
game_plugins: typing.List[BasicGame] = []
|
|
|
|
|
|
|
|
|
|
# We are going to list all game plugins:
|
|
|
|
|
curpath = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
|
# List all the .ini files:
|
|
|
|
|
for file in glob.glob(os.path.join(curpath, "games", "*.ini")):
|
|
|
|
|
game_plugins.append(BasicIniGame(file))
|
|
|
|
|
|
|
|
|
|
# List all the python plugins:
|
|
|
|
|
for file in glob.glob(os.path.join(curpath, "games", "*.py")):
|
|
|
|
|
module_p = os.path.relpath(file, os.path.join(curpath, "games"))
|
|
|
|
|
if module_p == "__init__.py":
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Import the module:
|
|
|
|
|
try:
|
|
|
|
|
module = importlib.import_module(".games." + module_p[:-3], __package__)
|
|
|
|
|
except ImportError as e:
|
|
|
|
|
print("Failed to import module {}: {}".format(module_p, e), file=sys.stderr)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print("Failed to import module {}: {}".format(module_p, e), file=sys.stderr)
|
|
|
|
|
|
|
|
|
|
# Lookup game plugins:
|
|
|
|
|
for name in dir(module):
|
|
|
|
|
if hasattr(module, name):
|
|
|
|
|
obj = getattr(module, name)
|
|
|
|
|
if (
|
|
|
|
|
isinstance(obj, type)
|
|
|
|
|
and issubclass(obj, BasicGame)
|
|
|
|
|
and obj is not BasicGame
|
|
|
|
|
):
|
|
|
|
|
try:
|
|
|
|
|
game_plugins.append(obj())
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(
|
|
|
|
|
"Failed to instantiate {}: {}".format(name, e),
|
|
|
|
|
file=sys.stderr,
|
|
|
|
|
)
|
|
|
|
|
|
2020-06-10 23:22:53 +02:00
|
|
|
return game_plugins
|