import yaml from .gameconfig import config class GameDB: def __init__(self): database_path = config.get_games_database_path() with open(database_path, 'rb') as fdin: self.db = yaml.safe_load(fdin) self.last_game_info = None def get_game_info(self, game_id=None): if self.last_game_info and self.last_game_info['id'] == game_id: return self.last_game_info game_info = next(game_info for game_info in self.db['games'] if game_info['id'] == game_id) self.last_game_info = game_info return game_info def get_game_env(self, profile_id, game_id=None): # TODO raise Error def get_game_command(self, profile_id, game_id=None): game_info = self.get_game_info(game_id) game_mods = game_info.get('mods', []) #game_mods += ['locked-run-profiledir'] #game_dir = config.get_games_install_basedir() / game_info['id'] ## note: glob('*/') globs regular files too, thus I filter on is_dir. #game_dir = list(item # for item in game_dir.glob('*') if item.is_dir())[-1] tools_bin_path = config.get_games_saves_tools_bin_path() #profile_dir = config.get_profile_dir(profile_id) command_from_game_info = [ f'{tools_bin_path}/runners/{game_info["command"][0]}', *game_info['command'][1:], ] if game_info.get('command') else [ f'{tools_bin_path}/runners/run-{game_info["id"]}', ] command = [ # mods *[f'{tools_bin_path}/mod-{item}' for item in game_mods], # runner *command_from_game_info, ] return command def get_ids(self): for game_info in self.db['games']: yield game_info['id'] def get_idtitles(self): for game_info in self.db['games']: yield game_info['id'], game_info['title'] def get_info(self, game_id): return next(game_info for game_info in self.db['games'] if game_info['id'] == game_id)