First pass at implementing a speech history option for games.
This commit is contained in:
61
utils.py
61
utils.py
@@ -156,19 +156,76 @@ class Game:
|
||||
# No logo image found, just play audio
|
||||
self.sound.cut_scene(audioKey)
|
||||
|
||||
def speak(self, text, interrupt=True):
|
||||
def speak(self, text, interrupt=True, priority="normal"):
|
||||
"""Speak text using the speech system.
|
||||
|
||||
Args:
|
||||
text (str): Text to speak
|
||||
interrupt (bool): Whether to interrupt current speech
|
||||
priority (str): Speech priority - "important", "normal", or "notification"
|
||||
|
||||
Returns:
|
||||
Game: Self for method chaining
|
||||
"""
|
||||
self.speech.speak(text, interrupt)
|
||||
self.speech.speak(text, interrupt, priority)
|
||||
return self
|
||||
|
||||
def speak_previous(self):
|
||||
"""Navigate to and speak the previous message in speech history.
|
||||
|
||||
Returns:
|
||||
Game: Self for method chaining
|
||||
"""
|
||||
from .speech import speak_previous
|
||||
speak_previous()
|
||||
return self
|
||||
|
||||
def speak_current(self):
|
||||
"""Repeat the current message in speech history.
|
||||
|
||||
Returns:
|
||||
Game: Self for method chaining
|
||||
"""
|
||||
from .speech import speak_current
|
||||
speak_current()
|
||||
return self
|
||||
|
||||
def speak_next(self):
|
||||
"""Navigate to and speak the next message in speech history.
|
||||
|
||||
Returns:
|
||||
Game: Self for method chaining
|
||||
"""
|
||||
from .speech import speak_next
|
||||
speak_next()
|
||||
return self
|
||||
|
||||
def setup_speech_history_keys(self, previous_key=None, current_key=None, next_key=None):
|
||||
"""Set up convenient key bindings for speech history navigation.
|
||||
|
||||
Args:
|
||||
previous_key (int, optional): Key code for previous message (default: F1)
|
||||
current_key (int, optional): Key code for current message (default: F2)
|
||||
next_key (int, optional): Key code for next message (default: F3)
|
||||
|
||||
Returns:
|
||||
dict: Dictionary mapping key codes to speech history functions
|
||||
"""
|
||||
# Set default keys if not provided
|
||||
if previous_key is None:
|
||||
previous_key = pygame.K_F1
|
||||
if current_key is None:
|
||||
current_key = pygame.K_F2
|
||||
if next_key is None:
|
||||
next_key = pygame.K_F3
|
||||
|
||||
# Return a dictionary that games can use in their event loops
|
||||
return {
|
||||
previous_key: self.speak_previous,
|
||||
current_key: self.speak_current,
|
||||
next_key: self.speak_next
|
||||
}
|
||||
|
||||
def play_bgm(self, musicFile):
|
||||
"""Play background music.
|
||||
|
||||
|
Reference in New Issue
Block a user