Cleanups
This commit is contained in:
@@ -101,9 +101,7 @@ class Game(Gtk.Box):
|
|||||||
self.app.quit()
|
self.app.quit()
|
||||||
|
|
||||||
def toggle_hidden(self):
|
def toggle_hidden(self):
|
||||||
data = json.loads(
|
data = json.load((self.win.games_dir / f"{self.game_id}.json").open())
|
||||||
(self.win.games_dir / f"{self.game_id}.json").read_text("utf-8")
|
|
||||||
)
|
|
||||||
|
|
||||||
data["hidden"] = not data["hidden"]
|
data["hidden"] = not data["hidden"]
|
||||||
|
|
||||||
|
|||||||
@@ -63,10 +63,9 @@ def heroic_importer(win):
|
|||||||
if not win.schema.get_boolean("heroic-import-epic"):
|
if not win.schema.get_boolean("heroic-import-epic"):
|
||||||
pass
|
pass
|
||||||
elif (heroic_dir / "store_cache" / "legendary_library.json").exists():
|
elif (heroic_dir / "store_cache" / "legendary_library.json").exists():
|
||||||
data = (heroic_dir / "store_cache" / "legendary_library.json").read_text(
|
library = json.load(
|
||||||
"utf-8"
|
(heroic_dir / "store_cache" / "legendary_library.json").open()
|
||||||
)
|
)
|
||||||
library = json.loads(data)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for game in library["library"]:
|
for game in library["library"]:
|
||||||
@@ -117,8 +116,7 @@ def heroic_importer(win):
|
|||||||
if not win.schema.get_boolean("heroic-import-gog"):
|
if not win.schema.get_boolean("heroic-import-gog"):
|
||||||
pass
|
pass
|
||||||
elif (heroic_dir / "gog_store" / "installed.json").exists():
|
elif (heroic_dir / "gog_store" / "installed.json").exists():
|
||||||
data = (heroic_dir / "gog_store" / "installed.json").read_text("utf-8")
|
installed = json.load((heroic_dir / "gog_store" / "installed.json").open())
|
||||||
installed = json.loads(data)
|
|
||||||
|
|
||||||
importer.total_queue += len(installed["installed"])
|
importer.total_queue += len(installed["installed"])
|
||||||
importer.queue += len(installed["installed"])
|
importer.queue += len(installed["installed"])
|
||||||
@@ -137,8 +135,7 @@ def heroic_importer(win):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Get game title and developer from library.json as they are not present in installed.json
|
# Get game title and developer from library.json as they are not present in installed.json
|
||||||
data = (heroic_dir / "gog_store" / "library.json").read_text("utf-8")
|
library = json.load((heroic_dir / "gog_store" / "library.json").open())
|
||||||
library = json.loads(data)
|
|
||||||
for game in library["games"]:
|
for game in library["games"]:
|
||||||
if game["app_name"] == app_name:
|
if game["app_name"] == app_name:
|
||||||
values["developer"] = game["developer"]
|
values["developer"] = game["developer"]
|
||||||
@@ -165,8 +162,7 @@ def heroic_importer(win):
|
|||||||
if not win.schema.get_boolean("heroic-import-sideload"):
|
if not win.schema.get_boolean("heroic-import-sideload"):
|
||||||
pass
|
pass
|
||||||
elif (heroic_dir / "sideload_apps" / "library.json").exists():
|
elif (heroic_dir / "sideload_apps" / "library.json").exists():
|
||||||
data = (heroic_dir / "sideload_apps" / "library.json").read_text("utf-8")
|
library = json.load((heroic_dir / "sideload_apps" / "library.json").open())
|
||||||
library = json.loads(data)
|
|
||||||
|
|
||||||
importer.total_queue += len(library["games"])
|
importer.total_queue += len(library["games"])
|
||||||
importer.queue += len(library["games"])
|
importer.queue += len(library["games"])
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ def create_details_window(win, game_id=None):
|
|||||||
path = win.games_dir / f"{game_id}.json"
|
path = win.games_dir / f"{game_id}.json"
|
||||||
|
|
||||||
if path.exists():
|
if path.exists():
|
||||||
data = json.loads(path.read_text("utf-8"))
|
data = json.load(path.open())
|
||||||
data.update(values)
|
data.update(values)
|
||||||
save_game(win, data)
|
save_game(win, data)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -26,13 +26,14 @@ def get_games(win, game_ids=None):
|
|||||||
if not win.games_dir.exists():
|
if not win.games_dir.exists():
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
if game_ids:
|
game_files = (
|
||||||
game_files = [win.games_dir / f"{game_id}.json" for game_id in game_ids]
|
[win.games_dir / f"{game_id}.json" for game_id in game_ids]
|
||||||
else:
|
if game_ids
|
||||||
game_files = win.games_dir.iterdir()
|
else win.games_dir.iterdir()
|
||||||
|
)
|
||||||
|
|
||||||
for game in game_files:
|
for open_file in game_files:
|
||||||
data = json.loads(game.read_text("utf-8"))
|
data = json.load(open_file.open())
|
||||||
games[data["game_id"]] = data
|
games[data["game_id"]] = data
|
||||||
|
|
||||||
return games
|
return games
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
active_game_id = None
|
active_game_id = None
|
||||||
scaled_pixbuf = None
|
scaled_pixbuf = None
|
||||||
details_view_game_cover = None
|
details_view_game_cover = None
|
||||||
|
sort_state = "a-z"
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
@@ -126,6 +127,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
self.library.set_filter_func(self.search_filter)
|
self.library.set_filter_func(self.search_filter)
|
||||||
self.hidden_library.set_filter_func(self.hidden_search_filter)
|
self.hidden_library.set_filter_func(self.hidden_search_filter)
|
||||||
|
|
||||||
|
self.library.set_sort_func(self.sort_func)
|
||||||
|
self.hidden_library.set_sort_func(self.sort_func)
|
||||||
|
|
||||||
self.update_games(get_games(self))
|
self.update_games(get_games(self))
|
||||||
|
|
||||||
# Connect signals
|
# Connect signals
|
||||||
@@ -358,44 +362,24 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
0.2 + (sum(luminances) / len(luminances) + min(luminances)) / 2
|
0.2 + (sum(luminances) / len(luminances) + min(luminances)) / 2
|
||||||
)
|
)
|
||||||
|
|
||||||
def a_z_sort(self, child1, child2):
|
def sort_func(self, child1, child2):
|
||||||
name1 = child1.get_first_child().name.lower()
|
games = (child1.get_first_child(), child2.get_first_child())
|
||||||
name2 = child2.get_first_child().name.lower()
|
var, order = "name", True
|
||||||
if name1 > name2:
|
|
||||||
return 1
|
|
||||||
if name1 < name2:
|
|
||||||
return -1
|
|
||||||
if child1.get_first_child().game_id > child2.get_first_child().game_id:
|
|
||||||
return 1
|
|
||||||
return -1
|
|
||||||
|
|
||||||
def z_a_sort(self, child1, child2):
|
if self.sort_state in ("newest", "oldest"):
|
||||||
name1 = child1.get_first_child().name.lower()
|
var, order = "added", self.sort_state == "newest"
|
||||||
name2 = child2.get_first_child().name.lower()
|
elif self.sort_state == "last_played":
|
||||||
if name1 > name2:
|
var = "last_played"
|
||||||
return -1
|
elif self.sort_state == "a-z":
|
||||||
return 1 if name1 < name2 else self.a_z_sort(child1, child2)
|
order = False
|
||||||
|
|
||||||
def newest_sort(self, child1, child2):
|
def get_value(index):
|
||||||
time1 = self.games[child1.get_first_child().game_id].added
|
return str(getattr(games[index], var)).lower()
|
||||||
time2 = self.games[child2.get_first_child().game_id].added
|
|
||||||
if time1 > time2:
|
|
||||||
return -1
|
|
||||||
return 1 if time1 < time2 else self.a_z_sort(child1, child2)
|
|
||||||
|
|
||||||
def oldest_sort(self, child1, child2):
|
if var != "name" and get_value(0) == get_value(1):
|
||||||
time1 = self.games[child1.get_first_child().game_id].added
|
var, order = "name", True
|
||||||
time2 = self.games[child2.get_first_child().game_id].added
|
|
||||||
if time1 > time2:
|
|
||||||
return 1
|
|
||||||
return -1 if time1 < time2 else self.a_z_sort(child1, child2)
|
|
||||||
|
|
||||||
def last_played_sort(self, child1, child2):
|
return ((get_value(0) > get_value(1)) ^ order) * 2 - 1
|
||||||
time1 = self.games[child1.get_first_child().game_id].last_played
|
|
||||||
time2 = self.games[child2.get_first_child().game_id].last_played
|
|
||||||
if time1 > time2:
|
|
||||||
return -1
|
|
||||||
return 1 if time1 < time2 else self.a_z_sort(child1, child2)
|
|
||||||
|
|
||||||
def on_go_back_action(self, _widget, _unused, _x=None, _y=None):
|
def on_go_back_action(self, _widget, _unused, _x=None, _y=None):
|
||||||
if self.stack.get_visible_child() == self.hidden_library_view:
|
if self.stack.get_visible_child() == self.hidden_library_view:
|
||||||
@@ -427,28 +411,12 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
def on_sort_action(self, action, state):
|
def on_sort_action(self, action, state):
|
||||||
action.set_state(state)
|
action.set_state(state)
|
||||||
state = str(state).strip("'")
|
self.sort_state = str(state).strip("'")
|
||||||
|
self.library.invalidate_sort()
|
||||||
if state == "a-z":
|
|
||||||
sort_func = self.a_z_sort
|
|
||||||
|
|
||||||
elif state == "z-a":
|
|
||||||
sort_func = self.z_a_sort
|
|
||||||
|
|
||||||
elif state == "newest":
|
|
||||||
sort_func = self.newest_sort
|
|
||||||
|
|
||||||
elif state == "oldest":
|
|
||||||
sort_func = self.oldest_sort
|
|
||||||
|
|
||||||
else:
|
|
||||||
sort_func = self.last_played_sort
|
|
||||||
|
|
||||||
Gio.Settings(schema_id="hu.kramo.Cartridge.State").set_string(
|
Gio.Settings(schema_id="hu.kramo.Cartridge.State").set_string(
|
||||||
"sort-mode", state
|
"sort-mode", self.sort_state
|
||||||
)
|
)
|
||||||
self.library.set_sort_func(sort_func)
|
|
||||||
self.hidden_library.set_sort_func(sort_func)
|
|
||||||
|
|
||||||
def on_toggle_search_action(self, _widget, _unused):
|
def on_toggle_search_action(self, _widget, _unused):
|
||||||
if self.stack.get_visible_child() == self.library_view:
|
if self.stack.get_visible_child() == self.library_view:
|
||||||
|
|||||||
Reference in New Issue
Block a user