Fix adding games manually

This commit is contained in:
GeoffreyCoulaud
2023-06-17 16:15:53 +02:00
parent eb91586216
commit cff2a4ae6c
2 changed files with 15 additions and 7 deletions

View File

@@ -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()

View File

@@ -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