mirror of
https://github.com/lutris/lutris
synced 2024-11-02 08:20:51 +00:00
Download media for lutris installers + adjust sizes of EGS media
This commit is contained in:
parent
85985a0672
commit
cd41942406
4 changed files with 53 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
|||
"""Main window for the Lutris interface."""
|
||||
# pylint: disable=no-member
|
||||
from lutris.services import service_media
|
||||
import os
|
||||
from collections import namedtuple
|
||||
from gettext import gettext as _
|
||||
|
@ -24,6 +25,7 @@ from lutris.gui.widgets.game_bar import GameBar
|
|||
from lutris.gui.widgets.gi_composites import GtkTemplate
|
||||
from lutris.gui.widgets.sidebar import LutrisSidebar
|
||||
from lutris.gui.widgets.utils import load_icon_theme, open_uri
|
||||
from lutris.gui.views.media_loader import download_icons
|
||||
from lutris.services.base import BaseService
|
||||
from lutris.services.lutris import LutrisBanner, LutrisIcon, LutrisService
|
||||
from lutris.util import datapath
|
||||
|
@ -276,11 +278,25 @@ class LutrisWindow(Gtk.ApplicationWindow): # pylint: disable=too-many-public-me
|
|||
return []
|
||||
api_games = api.search_games(self.filters["text"])
|
||||
if "icon" in self.icon_type:
|
||||
GLib.idle_add(self.load_icons, {g["slug"]: g["icon_url"] for g in api_games}, LutrisIcon)
|
||||
api_field = "icon_url"
|
||||
_service_media = LutrisIcon
|
||||
else:
|
||||
GLib.idle_add(self.load_icons, {g["slug"]: g["banner_url"] for g in api_games}, LutrisBanner)
|
||||
api_field = "banner_url"
|
||||
_service_media = LutrisBanner
|
||||
AsyncCall(
|
||||
download_icons,
|
||||
self.icons_download_cb,
|
||||
{g["slug"]: g[api_field] for g in api_games},
|
||||
_service_media()
|
||||
)
|
||||
return api_games
|
||||
|
||||
def icons_download_cb(self, result, error):
|
||||
if error:
|
||||
logger.error("Failed to download icons: %s", error)
|
||||
return
|
||||
self.game_store.update_icons(result)
|
||||
|
||||
def game_matches(self, game):
|
||||
if self.filters.get("installed"):
|
||||
if game["appid"] not in games_db.get_service_games(self.service.id):
|
||||
|
|
|
@ -4,6 +4,7 @@ import time
|
|||
from gi.repository import GLib, GObject, Gtk
|
||||
from gi.repository.GdkPixbuf import Pixbuf
|
||||
|
||||
from lutris.gui.widgets.utils import get_pixbuf
|
||||
from lutris import settings
|
||||
from lutris.database import sql
|
||||
from lutris.database.games import get_games
|
||||
|
@ -98,6 +99,11 @@ class GameStore(GObject.Object):
|
|||
for game in list(games):
|
||||
GLib.idle_add(self.add_game, game)
|
||||
|
||||
def get_row_by_slug(self, slug):
|
||||
for model_row in self.store:
|
||||
if model_row[COL_SLUG] == slug:
|
||||
return model_row
|
||||
|
||||
def get_row_by_id(self, _id):
|
||||
if not _id:
|
||||
return
|
||||
|
@ -181,3 +187,12 @@ class GameStore(GObject.Object):
|
|||
for db_game in db_games:
|
||||
GLib.idle_add(self.update, db_game)
|
||||
return True
|
||||
|
||||
def update_icons(self, icon_updates):
|
||||
"""Updates the store with new icon paths keyed by slug"""
|
||||
for slug in icon_updates:
|
||||
row = self.get_row_by_slug(slug)
|
||||
if not row:
|
||||
continue
|
||||
installed = slug in self.installed_game_slugs
|
||||
row[COL_ICON] = get_pixbuf(icon_updates[slug], self.service_media.size, is_installed=installed)
|
||||
|
|
|
@ -30,6 +30,7 @@ def get_services():
|
|||
"xdg": XDGService,
|
||||
"gog": GOGService,
|
||||
"humblebundle": HumbleBundleService,
|
||||
"egs": EpicGamesStoreService,
|
||||
}
|
||||
if LINUX_SYSTEM.has_steam:
|
||||
_services["steam"] = SteamService
|
||||
|
@ -46,7 +47,6 @@ SERVICES = get_services()
|
|||
WIP_SERVICES = {
|
||||
"battlenet": BattleNetService,
|
||||
"bethesda": BethesdaService,
|
||||
"egs": EpicGamesStoreService,
|
||||
"itchio": ItchIoService,
|
||||
"mame": MAMEService,
|
||||
"origin": OriginService,
|
||||
|
|
|
@ -25,21 +25,28 @@ class DieselGameMedia(ServiceMedia):
|
|||
def get_media_url(self, detail):
|
||||
for image in detail.get("keyImages", []):
|
||||
if image["type"] == self.api_field:
|
||||
return image["url"]
|
||||
return image["url"] + "?w=%s&resize=1&h=%s" % (self.size[0], self.size[1])
|
||||
|
||||
|
||||
class DieselGameBoxTall(DieselGameMedia):
|
||||
"""EGS tall game box"""
|
||||
size = (256, 284)
|
||||
size = (200, 267)
|
||||
dest_path = os.path.join(settings.CACHE_DIR, "egs/game_box_tall")
|
||||
api_field = "DieselGameBoxTall"
|
||||
|
||||
|
||||
class DieselGameBox(DieselGameMedia):
|
||||
"""EGS game box"""
|
||||
size = (256, 144)
|
||||
size = (316, 178)
|
||||
dest_path = os.path.join(settings.CACHE_DIR, "egs/game_box")
|
||||
api_field = "DieselGameBoxTall"
|
||||
api_field = "DieselGameBox"
|
||||
|
||||
|
||||
class DieselGameBoxLogo(DieselGameMedia):
|
||||
"""EGS game box"""
|
||||
size = (200, 100)
|
||||
dest_path = os.path.join(settings.CACHE_DIR, "egs/game_logo")
|
||||
api_field = "DieselGameBoxLogo"
|
||||
|
||||
|
||||
class EGSGame(ServiceGame):
|
||||
|
@ -67,8 +74,9 @@ class EpicGamesStoreService(OnlineService):
|
|||
medias = {
|
||||
"game_box": DieselGameBox,
|
||||
"box_tall": DieselGameBoxTall,
|
||||
"logo": DieselGameBoxLogo,
|
||||
}
|
||||
default_format = "game_box"
|
||||
default_format = "box_tall"
|
||||
requires_login_page = True
|
||||
cookies_path = os.path.join(settings.CACHE_DIR, ".egs.auth")
|
||||
token_path = os.path.join(settings.CACHE_DIR, ".egs.token")
|
||||
|
@ -234,9 +242,13 @@ class EpicGamesStoreService(OnlineService):
|
|||
def install_from_egs(self, egs_game, manifest):
|
||||
"""Create a new Lutris game based on an existing EGS install"""
|
||||
app_name = manifest["AppName"]
|
||||
logger.info("Installing %s", app_name)
|
||||
service_game = ServiceGameCollection.get_game("egs", app_name)
|
||||
if not service_game:
|
||||
logger.error("Can't find the game %s", app_name)
|
||||
return
|
||||
lutris_game_id = "egs-" + app_name
|
||||
existing_game = get_game_by_field(lutris_game_id, "slug")
|
||||
existing_game = get_game_by_field(lutris_game_id, "installer_slug")
|
||||
if existing_game:
|
||||
return
|
||||
game_config = LutrisConfig(game_config_id=egs_game["configpath"]).game_level
|
||||
|
@ -248,7 +260,7 @@ class EpicGamesStoreService(OnlineService):
|
|||
slug=slugify(service_game["name"]),
|
||||
directory=egs_game["directory"],
|
||||
installed=1,
|
||||
installer_slug="egs-" + app_name,
|
||||
installer_slug=lutris_game_id,
|
||||
configpath=configpath,
|
||||
service=self.id,
|
||||
service_id=app_name,
|
||||
|
|
Loading…
Reference in a new issue