This commit is contained in:
kramo
2023-04-18 19:07:49 +02:00
parent f8bb111939
commit bc9192e83b
12 changed files with 144 additions and 183 deletions

View File

@@ -26,9 +26,9 @@ from gi.repository import Adw, Gio, GLib, GObject, Gtk
from PIL import Image
from .create_dialog import create_dialog
from .game import Game
from .game_cover import GameCover
from .save_cover import resize_cover, save_cover
from .save_game import save_game
from .steamgriddb import SGDBSave
@@ -62,7 +62,7 @@ def create_details_window(win, game_id=None):
nonlocal game_cover
nonlocal cover_changed
game_cover.new_pixbuf()
game_cover.new_cover()
cover_button_delete_revealer.set_reveal_child(False)
cover_changed = True
@@ -89,7 +89,7 @@ def create_details_window(win, game_id=None):
)
apply_button = Gtk.Button.new_with_label(_("Apply"))
game_cover.new_pixbuf(win.games[game_id].get_cover_path())
game_cover.new_cover(win.games[game_id].get_cover_path())
if game_cover.get_pixbuf():
cover_button_delete_revealer.set_reveal_child(True)
else:
@@ -233,7 +233,7 @@ def create_details_window(win, game_id=None):
cover_button_delete_revealer.set_reveal_child(True)
cover_changed = True
game_cover.new_pixbuf(resize_cover(win, path))
game_cover.new_cover(resize_cover(win, path))
def close_window(_widget, _callback=None):
window.close()
@@ -323,16 +323,10 @@ def create_details_window(win, game_id=None):
game_cover.path,
)
path = win.games_dir / f"{game_id}.json"
if path.exists():
data = json.load(path.open())
data.update(values)
save_game(win, data)
if game_id in win.games:
win.games[game_id].update_values(values)
else:
save_game(win, values)
win.update_games({game_id})
Game(win, values).save()
if not game_cover.get_pixbuf():
SGDBSave(win, {(game_id, values["name"])})

View File

@@ -20,16 +20,10 @@
import json
def get_games(win, game_ids=None):
def get_games(win):
games = {}
game_files = (
{win.games_dir / f"{game_id}.json" for game_id in game_ids}
if game_ids
else win.games_dir.iterdir()
)
for open_file in game_files:
for open_file in win.games_dir.iterdir():
if open_file.exists():
data = json.load(open_file.open())
games[data["game_id"]] = data

View File

@@ -22,8 +22,8 @@ from pathlib import Path
from gi.repository import Adw, Gtk
from .create_dialog import create_dialog
from .game import Game
from .save_cover import resize_cover, save_cover
from .save_game import save_game
from .steamgriddb import SGDBSave
@@ -56,7 +56,7 @@ class Importer:
def save_game(self, values=None, cover_path=None):
if values:
save_game(self.win, values)
Game(self.win, values).save()
if cover_path:
save_cover(
@@ -66,7 +66,7 @@ class Importer:
self.games.add((values["game_id"], values["name"]))
self.games_no += 1
if "blacklisted" in values:
if values.get("blacklisted"):
self.games_no -= 1
self.queue -= 1

View File

@@ -27,7 +27,7 @@ from PIL import Image, ImageSequence
def resize_cover(win, cover_path=None, pixbuf=None):
if not cover_path and not pixbuf:
return
return None
if pixbuf:
cover_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
@@ -65,6 +65,9 @@ def resize_cover(win, cover_path=None, pixbuf=None):
def save_cover(win, game_id, cover_path):
if not cover_path:
return
win.covers_dir.mkdir(parents=True, exist_ok=True)
animated_path = win.covers_dir / f"{game_id}.gif"
@@ -80,7 +83,6 @@ def save_cover(win, game_id, cover_path):
)
if game_id in win.game_covers:
win.game_covers[game_id].new_pixbuf(
win.game_covers[game_id].new_cover(
animated_path if cover_path.suffix == ".gif" else static_path
)
return

View File

@@ -1,28 +0,0 @@
# save_game.py
#
# Copyright 2022-2023 kramo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import json
def save_game(win, game):
win.games_dir.mkdir(parents=True, exist_ok=True)
(win.games_dir / f'{game["game_id"]}.json').write_text(
json.dumps(game, indent=4, sort_keys=True), "utf-8"
)

View File

@@ -111,8 +111,10 @@ class SGDBSave:
_("Preferences"),
).connect("response", self.response)
game_id = result.propagate_value()[1]
self.win.update_games({game_id})
if not self.importer:
game = self.win.games[result.propagate_value()[1]]
game.set_loading(-1)
game.update()
def response(self, _widget, response):
if response == "open_preferences":