Refactor
This commit is contained in:
@@ -78,8 +78,7 @@ def bottles_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "bottles_" + game["id"]
|
||||
|
||||
if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[
|
||||
values["game_id"]].keys():
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
values["name"] = game["name"]
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
def create_details_window(parent_widget, game_id = None):
|
||||
import time
|
||||
import time, os, json
|
||||
from gi.repository import Adw, Gtk, Gio, GLib, GdkPixbuf
|
||||
from .create_dialog import create_dialog
|
||||
from .save_games import save_games
|
||||
@@ -31,7 +31,7 @@ def create_details_window(parent_widget, game_id = None):
|
||||
transient_for = parent_widget
|
||||
)
|
||||
|
||||
games = parent_widget.games
|
||||
games = parent_widget.games_temp
|
||||
pixbuf = None
|
||||
|
||||
if game_id == None:
|
||||
@@ -43,8 +43,8 @@ def create_details_window(parent_widget, game_id = None):
|
||||
else:
|
||||
window.set_title(_("Edit Game Details"))
|
||||
cover = Gtk.Picture.new_for_pixbuf((parent_widget.visible_widgets | parent_widget.hidden_widgets)[game_id].pixbuf)
|
||||
name = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new(games[game_id]["name"], -1))
|
||||
executable = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new((games[game_id]["executable"]), -1))
|
||||
name = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new(games[game_id].name, -1))
|
||||
executable = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new((games[game_id].executable), -1))
|
||||
apply_button = Gtk.Button.new_with_label(_("Apply"))
|
||||
|
||||
image_filter = Gtk.FileFilter(
|
||||
@@ -157,8 +157,6 @@ def create_details_window(parent_widget, game_id = None):
|
||||
|
||||
game_id = "imported_" + str(max(numbers)+1)
|
||||
|
||||
games[game_id] = {}
|
||||
|
||||
values["game_id"] = game_id
|
||||
values["hidden"] = False
|
||||
values["source"] = "imported"
|
||||
@@ -180,8 +178,17 @@ def create_details_window(parent_widget, game_id = None):
|
||||
values["name"] = final_name
|
||||
values["executable"] = final_executable
|
||||
|
||||
games[game_id].update(values)
|
||||
save_games(games)
|
||||
path = os.path.join(os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games", game_id + ".json"))
|
||||
|
||||
if os.path.exists(path):
|
||||
open_file = open(path, "r")
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
data.update(values)
|
||||
save_games({game_id : data})
|
||||
else:
|
||||
save_games({game_id : values})
|
||||
|
||||
parent_widget.update_games([game_id])
|
||||
if parent_widget.stack.get_visible_child() == parent_widget.overview:
|
||||
parent_widget.show_overview(None, game_id)
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
def get_cover(game, parent_widget):
|
||||
def get_cover(game_id, pixbuf_options, parent_widget):
|
||||
from gi.repository import GdkPixbuf
|
||||
import os, zlib
|
||||
|
||||
cover_path = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game["game_id"] + ".dat")
|
||||
cover_path = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game_id + ".dat")
|
||||
|
||||
if os.path.isfile(cover_path) == False:
|
||||
return parent_widget.placeholder_pixbuf
|
||||
@@ -29,7 +29,5 @@ def get_cover(game, parent_widget):
|
||||
open_file = open(cover_path, "rb")
|
||||
data = zlib.decompress(open_file.read())
|
||||
open_file.close()
|
||||
try:
|
||||
return GdkPixbuf.Pixbuf.new_from_data(data, *parent_widget.games[game["game_id"]]["pixbuf_options"])
|
||||
except KeyError:
|
||||
return parent_widget.placeholder_pixbuf
|
||||
|
||||
return GdkPixbuf.Pixbuf.new_from_data(data, *pixbuf_options)
|
||||
|
||||
@@ -83,7 +83,7 @@ def heroic_parser(parent_widget, action):
|
||||
app_name = game["app_name"]
|
||||
values["game_id"] = "heroic_epic_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[values["game_id"]].keys():
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
values["name"] = game["title"]
|
||||
@@ -113,8 +113,7 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "heroic_gog_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[
|
||||
values["game_id"]].keys():
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
# Get game title from library.json as it's not present in installed.json
|
||||
@@ -153,8 +152,7 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "heroic_sideload_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[
|
||||
values["game_id"]].keys():
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
values["name"] = item["title"]
|
||||
|
||||
@@ -87,7 +87,7 @@ def steam_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "steam_" + values["appid"]
|
||||
|
||||
if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[values["game_id"]].keys():
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
values["executable"] = "xdg-open steam://rungameid/" + values["appid"]
|
||||
|
||||
Reference in New Issue
Block a user