Skip to content

Commit

Permalink
Lutris: Add some util functions for conditional game list parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic2kk committed Mar 9, 2024
1 parent 6cf1def commit da5113c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
25 changes: 25 additions & 0 deletions pupgui2/lutrisutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,28 @@ def get_lutris_game_list(install_loc) -> List[LutrisGame]:
except Exception as e:
print('Error: Could not get lutris game list:', e)
return lgs


def is_lutris_game_using_runner(game: LutrisGame, runner: str) -> bool:

""" Determine if a LutrisGame is using a given runner. """

is_runner_name_valid = game.runner is not None and len(game.runner) > 0
is_using_runner = game.runner == runner

return is_runner_name_valid and is_using_runner


def is_lutris_game_using_wine(game: LutrisGame, wine_version: str = '') -> bool:

""" Determine if a LutrisGame is using a given wine_version string. """

is_using_wine = is_lutris_game_using_runner(game, 'wine')

# Only check wine_version if it is passed
if len(wine_version) > 0:
is_using_wine_version = game.get_game_config().get('wine', {}).get('version', '') == wine_version
else:
is_using_wine_version = True

return is_using_wine and is_using_wine_version
4 changes: 2 additions & 2 deletions pupgui2/pupgui2ctinfodialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pupgui2.constants import STEAM_APP_PAGE_URL
from pupgui2.datastructures import BasicCompatTool, CTType, SteamApp, LutrisGame, HeroicGame
from pupgui2.lutrisutil import get_lutris_game_list
from pupgui2.lutrisutil import get_lutris_game_list, is_lutris_game_using_wine
from pupgui2.pupgui2ctbatchupdatedialog import PupguiCtBatchUpdateDialog
from pupgui2.steamutil import get_steam_game_list
from pupgui2.util import open_webbrowser_thread, get_random_game_name
Expand Down Expand Up @@ -93,7 +93,7 @@ def update_game_list_steam(self, cached=True):
self.batch_update_complete.emit(True)

def update_game_list_lutris(self):
self.games = [game for game in get_lutris_game_list(self.install_loc) if game.runner == 'wine' and game.get_game_config().get('wine', {}).get('version') == self.ctool.displayname]
self.games = [game for game in get_lutris_game_list(self.install_loc) if is_lutris_game_using_wine(game, self.ctool.displayname)]

self.setup_game_list(len(self.games), [self.tr('Slug'), self.tr('Name')])

Expand Down
4 changes: 2 additions & 2 deletions pupgui2/pupgui2gamelistdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pupgui2.constants import PROTONDB_COLORS, STEAM_APP_PAGE_URL, AWACY_WEB_URL, PROTONDB_APP_PAGE_URL, LUTRIS_WEB_URL
from pupgui2.datastructures import AWACYStatus, SteamApp, SteamDeckCompatEnum, LutrisGame, HeroicGame
from pupgui2.lutrisutil import get_lutris_game_list
from pupgui2.lutrisutil import get_lutris_game_list, is_lutris_game_using_runner
from pupgui2.pupgui2shortcutdialog import PupguiShortcutDialog
from pupgui2.steamutil import steam_update_ctools, get_steam_game_list
from pupgui2.steamutil import is_steam_running, get_steam_ctool_list
Expand Down Expand Up @@ -175,7 +175,7 @@ def update_game_list_lutris(self):
""" update the game list for the Lutris launcher """
# Filter blank runners and Steam games, because we can't change any compat tool options for Steam games via Lutris
# Steam games can be seen from the Steam games list, so no need to duplicate it here
self.games = list(filter(lambda lutris_game: (lutris_game.runner is not None and lutris_game.runner != 'steam' and len(lutris_game.runner) > 0), get_lutris_game_list(self.install_loc)))
self.games = [game for game in get_lutris_game_list(self.install_loc) if not is_lutris_game_using_runner(game, 'steam')]

self.ui.tableGames.setRowCount(len(self.games))

Expand Down

0 comments on commit da5113c

Please sign in to comment.