diff --git a/src/importer/importer.py b/src/importer/importer.py index 50f2bd5..cc26ca3 100644 --- a/src/importer/importer.py +++ b/src/importer/importer.py @@ -118,23 +118,13 @@ class Importer: if game is None: continue - # TODO register in store instead of dict - - # Avoid duplicates - if ( - game.game_id in shared.win.games - and not shared.win.games[game.game_id].removed - ): - continue - # Register game - logging.info("New game registered %s (%s)", game.name, game.game_id) - shared.win.games[game.game_id] = game - game.save() + logging.info("Imported %s (%s)", game.name, game.game_id) + shared.store.add_game(game) self.n_games_added += 1 # Start sgdb lookup for game - # HACK move to its own manager + # TODO move to its own manager task = Task.new( None, self.sgdb_cancellable, self.sgdb_task_callback, (game,) ) diff --git a/src/main.py b/src/main.py index 647fb14..0cbb3a7 100644 --- a/src/main.py +++ b/src/main.py @@ -30,6 +30,7 @@ gi.require_version("Adw", "1") from gi.repository import Adw, Gio, GLib, Gtk import src.shared as shared +from src.store.store import Store from src.details_window import DetailsWindow from src.importer.importer import Importer from src.importer.sources.lutris_source import ( @@ -47,6 +48,7 @@ from src.window import CartridgesWindow class CartridgesApplication(Adw.Application): win = None + store = None def __init__(self): super().__init__( @@ -54,6 +56,11 @@ class CartridgesApplication(Adw.Application): ) def do_activate(self): # pylint: disable=arguments-differ + # Create the games store + if not self.store: + # TODO add managers to the store + self.store = Store() + # Create the main window self.win = self.props.active_window # pylint: disable=no-member if not self.win: diff --git a/src/shared.py b/src/shared.py index 9cf54d5..0417d64 100644 --- a/src/shared.py +++ b/src/shared.py @@ -52,4 +52,5 @@ image_size = (200 * scale_factor, 300 * scale_factor) # pylint: disable=invalid-name win = None importer = None +store = None spec_version = 1.5 # The version of the game_id.json spec diff --git a/src/store/display_manager.py b/src/store/display_manager.py new file mode 100644 index 0000000..88537e7 --- /dev/null +++ b/src/store/display_manager.py @@ -0,0 +1,12 @@ +import src.shared as shared +from src.store.manager import Manager +from src.game import Game + + +class DisplayManager(Manager): + """Manager in charge of adding a game to the UI""" + + def run(self, game: Game) -> None: + # TODO decouple a game from its widget + shared.win.games[game.game_id] = game + game.update() diff --git a/src/store/file_manager.py b/src/store/file_manager.py new file mode 100644 index 0000000..75c8e58 --- /dev/null +++ b/src/store/file_manager.py @@ -0,0 +1,10 @@ +from src.store.manager import Manager +from src.game import Game + + +class FileManager(Manager): + """Manager in charge of saving a game to a file""" + + def run(self, game: Game) -> None: + # TODO make game.save (disk) not trigger game.update (UI) + game.save() diff --git a/src/store/sgdb_manager.py b/src/store/sgdb_manager.py new file mode 100644 index 0000000..22f5699 --- /dev/null +++ b/src/store/sgdb_manager.py @@ -0,0 +1,11 @@ +from src.store.manager import Manager +from src.game import Game +from src.utils.steamgriddb import SGDBHelper + + +class SGDBManager(Manager): + """Manager in charge of downloading a game's cover from steamgriddb""" + + def run(self, game: Game) -> None: + # TODO + pass diff --git a/src/store/steam_api_manager.py b/src/store/steam_api_manager.py new file mode 100644 index 0000000..30f3c42 --- /dev/null +++ b/src/store/steam_api_manager.py @@ -0,0 +1,11 @@ +from src.store.manager import Manager +from src.game import Game +from src.utils.steam import SteamHelper + + +class SteamAPIManager(Manager): + """Manager in charge of completing a game's data from the Steam API""" + + def run(self, game: Game) -> None: + # TODO + pass diff --git a/src/store/store.py b/src/store/store.py index 288b175..1c80032 100644 --- a/src/store/store.py +++ b/src/store/store.py @@ -1,3 +1,4 @@ +import src.shared as shared from src.game import Game from src.store.manager import Manager from src.utils.task import Task @@ -32,6 +33,7 @@ class Store: games: dict[str, Game] def __init__(self) -> None: + shared.store = self self.managers = set() self.games = {} self.pipelines = {}