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

57 lines
1.3 KiB
Python
Raw Normal View History

2023-12-02 16:45:16 +00:00
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,
)
2023-12-21 23:43:01 +00:00
from lmm.games.lc import (
GAME_NAME as LC,
LethalCompanyGame,
)
2023-12-02 16:45:16 +00:00
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,
2023-12-21 23:43:01 +00:00
LC: LethalCompanyGame,
2023-12-02 16:45:16 +00:00
}.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}")
2023-12-02 16:46:48 +00:00
return games