It didn't occur to me for some reason that reviewing messages would also add those messages to history lol. Hopefully fixed now.

This commit is contained in:
Storm Dragon
2025-09-23 17:37:51 -04:00
parent aed7ba523d
commit c257128948
3 changed files with 64 additions and 22 deletions

View File

@@ -406,3 +406,33 @@ class SpeechHistoryService:
int: Number of messages in history
"""
return len(self.history)
def is_at_first(self):
"""Check if currently at the first (oldest) message in history.
Returns:
bool: True if at the first message
"""
if not self.history:
return False
return self.current_index == 0
def is_at_last(self):
"""Check if currently at the last (newest) message in history.
Returns:
bool: True if at the last message or viewing most recent
"""
if not self.history:
return False
return self.current_index == -1 or self.current_index == len(self.history) - 1
def get_most_recent(self):
"""Get the most recent message (what F2 should always say).
Returns:
str or None: Most recent message text, or None if no history
"""
if not self.history:
return None
return self.history[-1]['text']

View File

@@ -61,13 +61,14 @@ class Speech:
# No speech providers found
print("No speech providers found.")
def speak(self, text, interrupt=True, priority="normal"):
def speak(self, text, interrupt=True, priority="normal", add_to_history=True):
"""Speak text using the configured speech provider and display on screen.
Args:
text (str): Text to speak and display
interrupt (bool): Whether to interrupt current speech (default: True)
priority (str): Speech priority - "important", "normal", or "notification"
add_to_history (bool): Whether to add this message to speech history (default: True)
"""
if not self.provider:
return
@@ -84,12 +85,13 @@ class Speech:
self.lastSpoken["time"] = currentTime
# Add to speech history (import here to avoid circular imports)
try:
from .services import SpeechHistoryService
history_service = SpeechHistoryService.get_instance()
history_service.add_message(text)
except ImportError:
pass
if add_to_history:
try:
from .services import SpeechHistoryService
history_service = SpeechHistoryService.get_instance()
history_service.add_message(text)
except ImportError:
pass
# Proceed with speech based on provider and priority
if self.providerName == "speechd":
@@ -154,18 +156,19 @@ class Speech:
# Global instance for backward compatibility
_speechInstance = None
def speak(text, interrupt=True, priority="normal"):
def speak(text, interrupt=True, priority="normal", add_to_history=True):
"""Speak text using the global speech instance.
Args:
text (str): Text to speak and display
interrupt (bool): Whether to interrupt current speech (default: True)
priority (str): Speech priority - "important", "normal", or "notification"
add_to_history (bool): Whether to add this message to speech history (default: True)
"""
global _speechInstance
if _speechInstance is None:
_speechInstance = Speech.get_instance()
_speechInstance.speak(text, interrupt, priority)
_speechInstance.speak(text, interrupt, priority, add_to_history)
def messagebox(text, sounds=None):
"""Enhanced messagebox with dialog support.
@@ -356,25 +359,29 @@ def speak_previous():
history_service = SpeechHistoryService.get_instance()
message = history_service.move_previous()
if message:
speak(message, interrupt=True, priority="important")
# Add position indicator
prefix = ""
if history_service.is_at_first():
prefix = "First: "
speak(prefix + message, interrupt=True, priority="important", add_to_history=False)
else:
speak("No previous messages", interrupt=True, priority="important")
speak("No previous messages", interrupt=True, priority="important", add_to_history=False)
except ImportError:
speak("Speech history not available", interrupt=True, priority="important")
speak("Speech history not available", interrupt=True, priority="important", add_to_history=False)
def speak_current():
"""Repeat the current message in speech history."""
"""Repeat the most recent message in speech history (F2 always speaks last message)."""
try:
from .services import SpeechHistoryService
history_service = SpeechHistoryService.get_instance()
message = history_service.get_current()
message = history_service.get_most_recent()
if message:
speak(message, interrupt=True, priority="important")
speak("Last: " + message, interrupt=True, priority="important", add_to_history=False)
else:
speak("No current message", interrupt=True, priority="important")
speak("No messages in history", interrupt=True, priority="important", add_to_history=False)
except ImportError:
speak("Speech history not available", interrupt=True, priority="important")
speak("Speech history not available", interrupt=True, priority="important", add_to_history=False)
def speak_next():
@@ -384,8 +391,12 @@ def speak_next():
history_service = SpeechHistoryService.get_instance()
message = history_service.move_next()
if message:
speak(message, interrupt=True, priority="important")
# Add position indicator
prefix = ""
if history_service.is_at_last():
prefix = "Last: "
speak(prefix + message, interrupt=True, priority="important", add_to_history=False)
else:
speak("No next messages", interrupt=True, priority="important")
speak("No next messages", interrupt=True, priority="important", add_to_history=False)
except ImportError:
speak("Speech history not available", interrupt=True, priority="important")
speak("Speech history not available", interrupt=True, priority="important", add_to_history=False)

View File

@@ -156,18 +156,19 @@ class Game:
# No logo image found, just play audio
self.sound.cut_scene(audioKey)
def speak(self, text, interrupt=True, priority="normal"):
def speak(self, text, interrupt=True, priority="normal", add_to_history=True):
"""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"
add_to_history (bool): Whether to add this message to speech history (default: True)
Returns:
Game: Self for method chaining
"""
self.speech.speak(text, interrupt, priority)
self.speech.speak(text, interrupt, priority, add_to_history)
return self
def speak_previous(self):