🚧 More work on managers
This commit is contained in:
@@ -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,)
|
||||
)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
12
src/store/display_manager.py
Normal file
12
src/store/display_manager.py
Normal file
@@ -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()
|
||||
10
src/store/file_manager.py
Normal file
10
src/store/file_manager.py
Normal file
@@ -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()
|
||||
11
src/store/sgdb_manager.py
Normal file
11
src/store/sgdb_manager.py
Normal file
@@ -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
|
||||
11
src/store/steam_api_manager.py
Normal file
11
src/store/steam_api_manager.py
Normal file
@@ -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
|
||||
@@ -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 = {}
|
||||
|
||||
Reference in New Issue
Block a user