🎨 Moved things to managers

This commit is contained in:
GeoffreyCoulaud
2023-05-23 16:49:37 +02:00
parent abe41635fd
commit 95524563bb
5 changed files with 34 additions and 77 deletions

View File

@@ -1,11 +1,15 @@
import src.shared as shared
from src.store.manager import Manager
from src.game import Game
from src.store.manager import Manager
from src.store.sgdb_manager import SGDBManager
from src.store.steam_api_manager import SteamAPIManager
class DisplayManager(Manager):
"""Manager in charge of adding a game to the UI"""
run_after = set((SteamAPIManager, SGDBManager))
def run(self, game: Game) -> None:
# TODO decouple a game from its widget
shared.win.games[game.game_id] = game

View File

@@ -1,10 +1,14 @@
from src.store.manager import Manager
from src.game import Game
from src.store.manager import Manager
from src.store.sgdb_manager import SGDBManager
from src.store.steam_api_manager import SteamAPIManager
class FileManager(Manager):
"""Manager in charge of saving a game to a file"""
run_after = set((SteamAPIManager, SGDBManager))
def run(self, game: Game) -> None:
# TODO make game.save (disk) not trigger game.update (UI)
game.save()

View File

@@ -1,11 +1,27 @@
from src.store.manager import Manager
from requests import HTTPError, JSONDecodeError
from src.game import Game
from src.utils.steam import SteamHelper
from src.store.manager import Manager
from src.utils.steam import SteamGameNotFoundError, SteamHelper, SteamNotAGameError
class SteamAPIManager(Manager):
"""Manager in charge of completing a game's data from the Steam API"""
def run(self, game: Game) -> None:
# TODO
pass
# Skip non-steam games
if not game.source.startswith("steam_"):
return
# Get online metadata
appid = str(game.game_id).split("_")[-1]
steam = SteamHelper()
try:
online_data = steam.get_api_data(appid=appid)
except (HTTPError, JSONDecodeError) as error:
# On minor error, just report it
self.report_error(error)
except (SteamNotAGameError, SteamGameNotFoundError):
game.update_values({"blacklisted": True})
else:
game.update_values(online_data)