Skip to content

Commit

Permalink
implement autosave setting
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Dec 18, 2024
1 parent f43b977 commit 8035186
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ovos_workshop/skills/game_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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()

0 comments on commit 8035186

Please sign in to comment.