From cff2a4ae6c932623b741b76aafb084658156bd3f Mon Sep 17 00:00:00 2001 From: GeoffreyCoulaud Date: Sat, 17 Jun 2023 16:15:53 +0200 Subject: [PATCH] Fix adding games manually --- src/details_window.py | 16 ++++++++++------ src/store/store.py | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/details_window.py b/src/details_window.py index bde6132..e4d7797 100644 --- a/src/details_window.py +++ b/src/details_window.py @@ -150,20 +150,23 @@ class DetailsWindow(Adw.Window): return # Increment the number after the game id (eg. imported_1, imported_2) - numbers = [0] - - for current_game in self.win.games: - if "imported_" in current_game: - numbers.append(int(current_game.replace("imported_", ""))) + game_id: str + for game_id in shared.store.games: + prefix = "imported_" + if not game_id.startswith(prefix): + continue + numbers.append(int(game_id.replace(prefix, "", count=1))) + game_number = max(numbers) + 1 self.game = Game( { - "game_id": f"imported_{str(max(numbers) + 1)}", + "game_id": f"imported_{game_number}", "hidden": False, "source": "imported", "added": int(time()), }, + allow_side_effects=False, ) else: @@ -198,6 +201,7 @@ class DetailsWindow(Adw.Window): self.game_cover.path, ) + shared.store.add_game(self.game, {}, run_pipeline=False) self.game.save() self.game.update() diff --git a/src/store/store.py b/src/store/store.py index 2b8cbe5..86e623b 100644 --- a/src/store/store.py +++ b/src/store/store.py @@ -40,7 +40,9 @@ class Store: ): path.unlink(missing_ok=True) - def add_game(self, game: Game, additional_data: dict) -> Pipeline | None: + def add_game( + self, game: Game, additional_data: dict, run_pipeline=True + ) -> Pipeline | None: """Add a game to the app""" # Ignore games from a newer spec version @@ -76,6 +78,8 @@ class Store: game.connect(signal, manager.execute_resilient_manager_logic) # Run the pipeline for the game + if not run_pipeline: + return None pipeline = Pipeline(game, additional_data, self.pipeline_managers) self.games[game.game_id] = game self.pipelines[game.game_id] = pipeline