From 80351866c3cbca32550294d7fc45d619de87a529 Mon Sep 17 00:00:00 2001 From: miro Date: Wed, 18 Dec 2024 12:36:17 +0000 Subject: [PATCH] implement autosave setting --- ovos_workshop/skills/game_skill.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ovos_workshop/skills/game_skill.py b/ovos_workshop/skills/game_skill.py index 766bb25f..225ccc6a 100644 --- a/ovos_workshop/skills/game_skill.py +++ b/ovos_workshop/skills/game_skill.py @@ -198,9 +198,22 @@ def skill_will_trigger(self, utterance: str, lang: str, skill_id: Optional[str] skill_id = intent["skill_id"] if intent else "" return skill_id == id_to_check + @property + def save_is_implemented(self) -> bool: + """ + True if this skill implements a `save` method + """ + return self.__class__.on_save_game is not ConversationalGameSkill.on_save_game + + def _autosave(self): + """helper to save the game automatically if enabled in settings.json and implemented by skill""" + if self.settings.get("auto_save", False) and self.save_is_implemented: + self.on_save_game() + def converse(self, message: Message): try: if self.is_paused: + self._autosave() # let ocp_pipeline unpause as appropriate return False @@ -225,6 +238,7 @@ def handle_deactivate(self, message: Message): means the user didn't interact with the game for a long time and intent parser will be released """ try: + self._autosave() if self.is_paused: self.log.info("Game is paused, keeping it active") self.activate() # keep the game in active skills list so it can still converse @@ -234,3 +248,7 @@ def handle_deactivate(self, message: Message): self.on_stop_game() except Exception as e: self.log.exception(f"Error during game deactivation: {e}") + + def stop(self) -> bool: + self._autosave() + return super().stop()