🎨 Reorganized game loading from disk
This commit is contained in:
@@ -59,13 +59,13 @@ class Game(Gtk.Box):
|
||||
removed = None
|
||||
blacklisted = None
|
||||
game_cover = None
|
||||
version = None
|
||||
|
||||
def __init__(self, data, allow_side_effects=True, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.win = shared.win
|
||||
self.app = self.win.get_application()
|
||||
self.version = shared.spec_version
|
||||
|
||||
self.update_values(data)
|
||||
|
||||
@@ -145,13 +145,6 @@ class Game(Gtk.Box):
|
||||
"version",
|
||||
)
|
||||
|
||||
# TODO: remove for 2.0
|
||||
attrs = list(attrs)
|
||||
if not self.removed:
|
||||
attrs.remove("removed")
|
||||
if not self.blacklisted:
|
||||
attrs.remove("blacklisted")
|
||||
|
||||
json.dump(
|
||||
{attr: getattr(self, attr) for attr in attrs if attr},
|
||||
(shared.games_dir / f"{self.game_id}.json").open("w"),
|
||||
|
||||
@@ -68,6 +68,7 @@ class LutrisSourceIterator(SourceIterator):
|
||||
|
||||
# Create game
|
||||
values = {
|
||||
"version": shared.spec_version,
|
||||
"added": int(time()),
|
||||
"hidden": row[4],
|
||||
"name": row[1],
|
||||
|
||||
@@ -4,6 +4,7 @@ from pathlib import Path
|
||||
from time import time
|
||||
from typing import Iterator
|
||||
|
||||
from src import shared
|
||||
from src.game import Game
|
||||
from src.importer.sources.source import Source, SourceIterator
|
||||
from src.utils.decorators import (
|
||||
@@ -71,6 +72,7 @@ class SteamSourceIterator(SourceIterator):
|
||||
# Build game from local data
|
||||
appid = local_data["appid"]
|
||||
values = {
|
||||
"version": shared.spec_version,
|
||||
"added": int(time()),
|
||||
"name": local_data["name"],
|
||||
"source": self.source.id,
|
||||
|
||||
@@ -43,6 +43,7 @@ from src.importer.sources.steam_source import (
|
||||
from src.preferences import PreferencesWindow
|
||||
from src.store.managers.display_manager import DisplayManager
|
||||
from src.store.managers.file_manager import FileManager
|
||||
from store.managers.format_update_manager import FormatUpdateManager
|
||||
from src.store.managers.sgdb_manager import SGDBManager
|
||||
from src.store.managers.steam_api_manager import SteamAPIManager
|
||||
from src.store.store import Store
|
||||
@@ -76,9 +77,10 @@ class CartridgesApplication(Adw.Application):
|
||||
"is-maximized", self.win, "maximized", Gio.SettingsBindFlags.DEFAULT
|
||||
)
|
||||
|
||||
# Create the games store with bare minimum managers
|
||||
# Create the games store ready to load games from disk
|
||||
if not shared.store:
|
||||
shared.store = Store()
|
||||
shared.store.add_manager(FormatUpdateManager())
|
||||
shared.store.add_manager(DisplayManager())
|
||||
|
||||
# Load games from disk
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
from src import shared
|
||||
from src.game import Game
|
||||
from src.store.managers.file_manager import FileManager
|
||||
from src.store.managers.manager import Manager
|
||||
from src.store.managers.sgdb_manager import SGDBManager
|
||||
from src.store.managers.steam_api_manager import SteamAPIManager
|
||||
|
||||
|
||||
class DisplayManager(Manager):
|
||||
"""Manager in charge of adding a game to the UI"""
|
||||
|
||||
run_after = set((SteamAPIManager, SGDBManager))
|
||||
run_after = set((FileManager,))
|
||||
|
||||
def run(self, game: Game) -> None:
|
||||
# TODO decouple a game from its widget
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from src.game import Game
|
||||
from src.store.managers.format_update_manager import FormatUpdateManager
|
||||
from src.store.managers.manager import Manager
|
||||
from src.store.managers.sgdb_manager import SGDBManager
|
||||
from src.store.managers.steam_api_manager import SteamAPIManager
|
||||
@@ -7,7 +8,7 @@ from src.store.managers.steam_api_manager import SteamAPIManager
|
||||
class FileManager(Manager):
|
||||
"""Manager in charge of saving a game to a file"""
|
||||
|
||||
run_after = set((SteamAPIManager, SGDBManager))
|
||||
run_after = set((SteamAPIManager, SGDBManager, FormatUpdateManager))
|
||||
|
||||
def run(self, game: Game) -> None:
|
||||
# TODO make game.save (disk) not trigger game.update (UI)
|
||||
|
||||
20
src/store/managers/format_update_manager.py
Normal file
20
src/store/managers/format_update_manager.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from src.store.managers.manager import Manager
|
||||
from src.game import Game
|
||||
|
||||
|
||||
class FormatUpdateManager(Manager):
|
||||
"""Class in charge of migrating a game from an older format"""
|
||||
|
||||
def v1_5_to_v2_0(self, game: Game) -> None:
|
||||
"""Convert a game from v1.5 format to v2.0 format"""
|
||||
if game.blacklisted is None:
|
||||
game.blacklisted = False
|
||||
if game.removed is None:
|
||||
game.removed = False
|
||||
game.version = 2.0
|
||||
|
||||
def run(self, game: Game) -> None:
|
||||
if game.version is None:
|
||||
self.v1_5_to_v2_0(game)
|
||||
# TODO make game.save (disk) not trigger game.update (UI)
|
||||
game.save()
|
||||
@@ -103,7 +103,7 @@ class Store:
|
||||
"""
|
||||
|
||||
# Ignore games from a newer spec version
|
||||
if (version := game.get("version")) and version > shared.spec_version:
|
||||
if game.version > shared.spec_version:
|
||||
return None
|
||||
|
||||
# Ignore games that are already there
|
||||
|
||||
Reference in New Issue
Block a user