From 59f21d6c7e97e7eb1ad70d31523929d398d27972 Mon Sep 17 00:00:00 2001 From: vg Date: Mon, 2 Jan 2023 18:23:33 +0100 Subject: git-sync on dita --- gamechestcli/gamechest/gameconfig.py | 42 ++++++++++++++++++++++++++++++++++++ pygame/Makefile | 6 +++--- pygame/__init__.py | 11 ++++++++-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/gamechestcli/gamechest/gameconfig.py b/gamechestcli/gamechest/gameconfig.py index 3a53837..5e46efa 100644 --- a/gamechestcli/gamechest/gameconfig.py +++ b/gamechestcli/gamechest/gameconfig.py @@ -104,3 +104,45 @@ class GameConfig: # default instance of gameconfig, same instance intended to be shared through # all modules which needs it. config = GameConfig() + +class GameStatus: + + def load_yaml(self): + with contextlib.ExitStack() as stack: + stack.enter_context(contextlib.suppress(FileNotFoundError)) + fdin = stack.enter_context(open(self.yaml_path, 'r', + encoding='utf8')) + data = yaml.safe_load(fdin) + self.last_loaded_profile = data.get('last_loaded_profile', + self.last_loaded_profile) + self.last_loaded_game = data.get('last_loaded_game', + self.last_loaded_game) + + def write_yaml(self): + with contextlib.ExitStack() as stack: + stack.enter_context(contextlib.suppress(FileNotFoundError)) + fdout = stack.enter_context(open(self.yaml_path, 'w', + encoding='utf8')) + data = { + 'last_loaded_profile': self.last_loaded_profile, + 'last_loaded_game': self.last_loaded_game, + } + yaml.safe_dump(data, fdout) + + def __init__(self): + self.yaml_path = ( + xdg_data_home() / consts.XDG_RESOURCE_NAME / 'status.yaml' + ) + self.last_loaded_profile = config.get_profile_id() + self.last_loaded_game = None + self.load_yaml() + + def set_last_loaded_profile(self, profile): + self.last_loaded_profile = profile + self.write_yaml() + + def set_last_loaded_game(self, game): + self.last_loaded_game = game + self.write_yaml() + +status = GameStatus() diff --git a/pygame/Makefile b/pygame/Makefile index 36729a7..3ca825c 100644 --- a/pygame/Makefile +++ b/pygame/Makefile @@ -14,10 +14,10 @@ all: deploy .PHONY: deploy deploy: - rm -rf ~/games/.saves/tools/bin/libs/gamechestgui + #rm -rf ~/games/.saves/tools/bin/libs/gamechestgui mkdir -p ~/games/.saves/tools/bin/libs/gamechestgui - pip3 install --target ~/games/.saves/tools/bin/libs/gamechestgui -r ../gamechestcli/requirements.txt - pip3 install --target ~/games/.saves/tools/bin/libs/gamechestgui -r requirements.txt + pip3 install -U --target ~/games/.saves/tools/bin/libs/gamechestgui -r ../gamechestcli/requirements.txt + pip3 install -U --target ~/games/.saves/tools/bin/libs/gamechestgui -r requirements.txt rsync -Pa ../gamechestcli/gamechest ~/games/.saves/tools/bin/libs/gamechestgui/. rsync -Pa __init__.py profiledb.py ~/games/.saves/tools/bin/libs/gamechestgui/. rsync -Pa gamechestgui ~/games/.saves/tools/bin/. diff --git a/pygame/__init__.py b/pygame/__init__.py index 04bc45a..8dae792 100755 --- a/pygame/__init__.py +++ b/pygame/__init__.py @@ -15,7 +15,7 @@ from .profiledb import ProfileDB from .gamechest.cliactions import run from .gamechest.gamedb import GameDB from .gamechest.statusdb import StatusDB -from .gamechest.gameconfig import config +from .gamechest.gameconfig import config, status from .gamechest.runners.install import Install from .gamechest.runners.remove import Remove @@ -175,8 +175,9 @@ class ProfileData(ObservedSubject): self.profiles_len = len(self.profiledb.get_profiles()) self.current_profile_index = 0 configured_default_profile = config.get_profile_id() + last_loaded_profile = status.last_loaded_profile or configured_default_profile for index, profile in enumerate(self.profiledb.get_profiles()): - if profile['name'] == configured_default_profile: + if profile['name'] == last_loaded_profile: self.current_profile_index = index def change_active_profile(self, new_index): @@ -261,6 +262,10 @@ class GameData(ObservedSubject): self.games_idtitles = list(self.game_db.get_idtitles()) self.games_len = len(self.games_idtitles) self.game_index = 0 + last_loaded_game = status.last_loaded_game + for index, (game_id, _) in enumerate(self.games_idtitles): + if game_id == last_loaded_game: + self.game_index = index def change_active_game(self, new_index): if new_index < 0: @@ -621,6 +626,8 @@ class GuiAppSub1(GuiApp): if not self.status_db.is_installed(game_info): print('Game', game_id, 'is not installed, aborting.', file=sys.stderr) else: + status.set_last_loaded_game(game_id) + status.set_last_loaded_profile(profile_id) command = self.game_db.get_game_command(profile_id, game_id) subprocess.run(command) elif action == 'install': -- cgit v1.2.3