diff options
author | vg <vgm+dev@devys.org> | 2023-01-02 18:23:33 +0100 |
---|---|---|
committer | vg <vgm+dev@devys.org> | 2023-01-02 18:23:33 +0100 |
commit | 59f21d6c7e97e7eb1ad70d31523929d398d27972 (patch) | |
tree | 48b1fb25a459c6b9cf444dc883fb54c3b9945495 /gamechestcli | |
parent | 096312be3165c9f6775c2a082aeaabd24aaaed53 (diff) | |
download | gamechest-59f21d6c7e97e7eb1ad70d31523929d398d27972.tar.gz gamechest-59f21d6c7e97e7eb1ad70d31523929d398d27972.tar.bz2 gamechest-59f21d6c7e97e7eb1ad70d31523929d398d27972.zip |
git-sync on dita
Diffstat (limited to 'gamechestcli')
-rw-r--r-- | gamechestcli/gamechest/gameconfig.py | 42 |
1 files changed, 42 insertions, 0 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() |