Skip to content

Commit

Permalink
Release 3.2.0a1 (#309)
Browse files Browse the repository at this point in the history
* feat: game skill (#306)

* feat: game skill

add new base class to make it easy to implement voice games

* add resume handler

* resume

* adjust timeout

* Apply suggestions from code review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* better stop handling

* rename method for clarity

* implement pause/resume

* dont require save/load methods to be implemented

* implement autosave setting

* tweak when autosave happens

* pause game default dialogs«

* fix - cant use self.speak_dialog for bundled resource files from ovos-workshop

* improve non-decorator usage callback handling

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Increment Version to 3.2.0a1

* Update Changelog

---------

Co-authored-by: JarbasAI <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: JarbasAl <[email protected]>
  • Loading branch information
4 people authored Dec 18, 2024
1 parent 74aa74d commit dc51ea7
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 24 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changelog

## [3.1.3a1](https://github.com/OpenVoiceOS/OVOS-workshop/tree/3.1.3a1) (2024-12-18)
## [3.2.0a1](https://github.com/OpenVoiceOS/OVOS-workshop/tree/3.2.0a1) (2024-12-18)

[Full Changelog](https://github.com/OpenVoiceOS/OVOS-workshop/compare/3.1.2...3.1.3a1)
[Full Changelog](https://github.com/OpenVoiceOS/OVOS-workshop/compare/3.1.3...3.2.0a1)

**Merged pull requests:**

- fix: intent layers [\#307](https://github.com/OpenVoiceOS/OVOS-workshop/pull/307) ([JarbasAl](https://github.com/JarbasAl))
- feat: game skill [\#306](https://github.com/OpenVoiceOS/OVOS-workshop/pull/306) ([JarbasAl](https://github.com/JarbasAl))



Expand Down
1 change: 1 addition & 0 deletions ovos_workshop/locale/en/cant_load_game.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the game can't be loaded
1 change: 1 addition & 0 deletions ovos_workshop/locale/en/cant_save_game.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the game can't be saved
1 change: 1 addition & 0 deletions ovos_workshop/locale/en/game_pause.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
game paused
2 changes: 2 additions & 0 deletions ovos_workshop/locale/en/game_unpause.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unpausing game
resuming game
57 changes: 41 additions & 16 deletions ovos_workshop/skills/common_play.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os
from inspect import signature
from threading import Event
from typing import List

from ovos_utils import camel_case_split
from ovos_utils.log import LOG
from typing import List, Callable, Optional

from ovos_bus_client import Message
from ovos_config.locations import get_xdg_cache_save_path
from ovos_utils import camel_case_split
from ovos_utils.log import LOG
from ovos_workshop.skills.ovos import OVOSSkill

# backwards compat imports, do not delete, skills import from here
Expand Down Expand Up @@ -56,23 +55,30 @@ def ...
vocab for starting playback is needed.
"""

def __init__(self, supported_media: List[MediaType] = None,
def __init__(self, *args,
supported_media: List[MediaType] = None,
skill_icon: str = "",
skill_voc_filename: str = "",
*args, **kwargs):
playback_handler: Optional[Callable[[Optional[Message]], None]] = None,
pause_handler: Optional[Callable[[Optional[Message]], None]] = None,
next_handler: Optional[Callable[[Optional[Message]], None]] = None,
prev_handler: Optional[Callable[[Optional[Message]], None]] = None,
resume_handler: Optional[Callable[[Optional[Message]], None]] = None,
**kwargs):
self.supported_media = supported_media or [MediaType.GENERIC]
self.skill_aliases = []
self.skill_voc_filename = skill_voc_filename
self._search_handlers = [] # added via decorators
self._featured_handlers = [] # added via decorators
self._current_query = None
self.__playback_handler = None
self.__pause_handler = None
self.__next_handler = None
self.__prev_handler = None
self.__resume_handler = None
self.__playback_handler = playback_handler
self.__pause_handler = pause_handler
self.__next_handler = next_handler
self.__prev_handler = prev_handler
self.__resume_handler = resume_handler
self._stop_event = Event()
self._playing = Event()
self._paused = Event()
# TODO new default icon
self.skill_icon = skill_icon or ""

Expand Down Expand Up @@ -387,26 +393,35 @@ def play_media(self, media, disambiguation=None, playlist=None):
# @killable_event("ovos.common_play.stop", react_to_stop=True)
def __handle_ocp_play(self, message):
if self.__playback_handler:
self.__playback_handler(message)
params = signature(self.__playback_handler).parameters
kwargs = {"message": message} if "message" in params else {}
self.__playback_handler(**kwargs)
self.bus.emit(Message("ovos.common_play.player.state",
{"state": PlayerState.PLAYING}))
self._playing.set()
self._paused.clear()
else:
LOG.error(f"Playback requested but {self.skill_id} handler not "
"implemented")

def __handle_ocp_pause(self, message):
self._paused.set()
if self.__pause_handler:
if self.__pause_handler(message):
params = signature(self.__playback_handler).parameters
kwargs = {"message": message} if "message" in params else {}
if self.__pause_handler(**kwargs):
self.bus.emit(Message("ovos.common_play.player.state",
{"state": PlayerState.PAUSED}))
else:
LOG.error(f"Pause requested but {self.skill_id} handler not "
"implemented")

def __handle_ocp_resume(self, message):
self._paused.clear()
if self.__resume_handler:
if self.__resume_handler(message):
params = signature(self.__playback_handler).parameters
kwargs = {"message": message} if "message" in params else {}
if self.__resume_handler(**kwargs):
self.bus.emit(Message("ovos.common_play.player.state",
{"state": PlayerState.PLAYING}))
else:
Expand All @@ -415,21 +430,26 @@ def __handle_ocp_resume(self, message):

def __handle_ocp_next(self, message):
if self.__next_handler:
self.__next_handler(message)
params = signature(self.__playback_handler).parameters
kwargs = {"message": message} if "message" in params else {}
self.__next_handler(**kwargs)
else:
LOG.error(f"Play Next requested but {self.skill_id} handler not "
"implemented")

def __handle_ocp_prev(self, message):
if self.__prev_handler:
self.__prev_handler(message)
params = signature(self.__playback_handler).parameters
kwargs = {"message": message} if "message" in params else {}
self.__prev_handler(**kwargs)
else:
LOG.error(f"Play Next requested but {self.skill_id} handler not "
"implemented")

def __handle_ocp_stop(self, message):
# for skills managing their own playback
if self._playing.is_set():
self._paused.clear()
self.stop()
self.gui.release()
self.bus.emit(Message("ovos.common_play.player.state",
Expand Down Expand Up @@ -543,6 +563,11 @@ def __handle_ocp_featured(self, message):
"thumbnail": self.skill_icon,
"playlist": results}))

def _handle_stop(self, message):
self._playing.clear()
self._paused.clear()
super()._handle_stop(message)

def default_shutdown(self):
self.bus.emit(
Message('ovos.common_play.skills.detach',
Expand Down
Loading

0 comments on commit dc51ea7

Please sign in to comment.