Skip to content

Commit

Permalink
heroic_util: Add further type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic2kk committed Aug 12, 2024
1 parent e402a86 commit b031204
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pupgui2/heroicutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
import re

from typing import Any

from pupgui2.datastructures import HeroicGame
from pupgui2.constants import EPIC_STORE_URL

Expand All @@ -19,16 +21,18 @@ def get_heroic_game_list(heroic_path: str) -> list[HeroicGame]:
store_paths: list[str] = [ os.path.join(heroic_path, 'sideload_apps', 'library.json'), os.path.join(heroic_path, 'gog_store', 'library.json'), os.path.join(heroic_path, 'store_cache', 'nile_library.json') ]
legendary_path: str = os.path.abspath(os.path.join(heroic_path, '..', 'legendary', 'installed.json'))

games_json: list = []
games_json: list[dict[str, Any]] = []
for sp in store_paths:
if os.path.isfile(sp):
games_json_file = json.load(open(sp))
games_json_file: dict[str, Any] = json.load(open(sp))

# 'games' and 'library' is a JSON array containing objects representing each game
games_json += games_json_file.get('games', []) # GOG + sideload use 'games' as top-level object
games_json += games_json_file.get('library', []) # Nile uses 'library' as top-level object

hgs: list[HeroicGame] = []
for game in games_json:
game: dict[str, Any]
hg = HeroicGame()

hg.runner = game.get('runner', '')
Expand Down Expand Up @@ -56,7 +60,7 @@ def get_heroic_game_list(heroic_path: str) -> list[HeroicGame]:

# Legendary Games uses a separate structure, so build separately
if os.path.isfile(legendary_path):
legendary_json = json.load(open(legendary_path))
legendary_json: dict[str, Any] = json.load(open(legendary_path))
for app_name, game_data in legendary_json.items():
lg = HeroicGame()

Expand Down Expand Up @@ -93,7 +97,7 @@ def is_gog_game_installed(game: HeroicGame) -> bool:
return bool(get_gog_installed_game_entry(game))


def get_gog_installed_game_entry(game: HeroicGame) -> dict:
def get_gog_installed_game_entry(game: HeroicGame) -> dict[str, Any]:
""" Return JSON entry as dict for an installed GOG game from heroic/gog_store/installed.json """

gog_installed_json_path = os.path.join(game.heroic_path, 'gog_store', 'installed.json')
Expand Down Expand Up @@ -122,9 +126,9 @@ def get_gog_game_executable(game: HeroicGame) -> str:
if not os.path.isfile(gog_gameinfo_json_path) or not game.runner.lower() == 'gog':
return ''

gog_gameinfo_json = json.load(open(gog_gameinfo_json_path))
gog_gameinfo_name = gog_gameinfo_json.get('name', '')
gog_gameinfo_playtasks = gog_gameinfo_json.get('playTasks', {})
gog_gameinfo_json: dict[str, Any] = json.load(open(gog_gameinfo_json_path))
gog_gameinfo_name: str = gog_gameinfo_json.get('name', '')
gog_gameinfo_playtasks: dict[str, Any] = gog_gameinfo_json.get('playTasks', {})
for playtasks in gog_gameinfo_playtasks:
if playtasks.get('name', '').lower() == gog_gameinfo_name.lower():
return playtasks.get('path', '')
Expand Down

0 comments on commit b031204

Please sign in to comment.