linux-mod-manager/lmm/games/config.py

57 lines
1.3 KiB
Python

import json
import os
from lmm.const import LMM_GAMES_PATH
from lmm.games.game import Game
from lmm.games.bg3 import (
GAME_NAME as BG3,
BaldursGate3Game,
)
from lmm.games.pdmm import (
GAME_NAME as PDMM,
ProjectDivaMegaMixGame,
)
from lmm.games.ron import (
GAME_NAME as RON,
ReadyOrNotGame,
)
from lmm.games.lc import (
GAME_NAME as LC,
LethalCompanyGame,
)
import yaml
def load_game_configs() -> list[Game]:
games = []
for item in os.listdir(LMM_GAMES_PATH):
path = LMM_GAMES_PATH / item
if not path.is_dir():
continue
config = path / "config.yaml"
if not config.exists():
continue
game_cls = {
BG3: BaldursGate3Game,
PDMM: ProjectDivaMegaMixGame,
RON: ReadyOrNotGame,
LC: LethalCompanyGame,
}.get(item, None)
if game_cls is None:
print(f"Unknown game {item}")
continue
with open(config, "r") as f:
try:
config_data = yaml.load(f, Loader=yaml.CLoader)
games.append(
game_cls.from_dict(config_data),
)
except Exception as ex:
print(f"Failed to load game {item}: {ex}")
return games