diff options
Diffstat (limited to 'gamechestcli/gamechest/gamedb.py')
-rw-r--r-- | gamechestcli/gamechest/gamedb.py | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/gamechestcli/gamechest/gamedb.py b/gamechestcli/gamechest/gamedb.py index d932438..2000c52 100644 --- a/gamechestcli/gamechest/gamedb.py +++ b/gamechestcli/gamechest/gamedb.py @@ -9,9 +9,35 @@ class GameDB: database_path = paths.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_info(self, game_id): - return next(game_info - for game_info in self.db['games'] - if game_info['id'] == game_id) + 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 = paths.get_games_install_basedir() / game_info['id'] + # note: glob('*/') globs regular files too, thus I filter on is_dir. + game_dir = next(item for item in game_dir.glob('*') if item.is_dir()) + + tools_bin_path = paths.get_games_saves_tools_bin_path() + profile_dir = paths.get_profile_dir(profile_id) + + command = [ + *[f'{tools_bin_path}/mod-{item}' for item in game_mods], + profile_dir, + game_dir, + *[item if index > 0 else f'{tools_bin_path}/{item}' + for index, item in enumerate(game_info['command'])], + ] + + return command |