Latest changes.

This commit is contained in:
Storm Dragon
2026-02-24 23:11:47 -05:00
parent 7531eacf64
commit 59f2880498
3 changed files with 63 additions and 16 deletions
+25 -8
View File
@@ -5,6 +5,18 @@ string[] speechHistory;
int speechHistoryMaxEntries = 10;
int speechHistoryCurrentIndex = -1;
bool speechHistoryDeduplicate = true;
funcdef string speech_history_message_transform_callback(const string& in message);
speech_history_message_transform_callback @speechHistoryMessageTransform = null;
void speech_history_set_message_transform_callback(speech_history_message_transform_callback @callback) {
@speechHistoryMessageTransform = @callback;
}
string speech_history_transform_message(const string& in message) {
if (@speechHistoryMessageTransform is null)
return message;
return speechHistoryMessageTransform(message);
}
void speech_history_set_max_entries(int maxEntries) {
if (maxEntries < 1) {
@@ -55,27 +67,30 @@ void speech_history_add(const string& in message) {
}
void speak_with_history(const string& in message, bool interrupt) {
speech_history_add(message);
screen_reader_speak(message, interrupt);
string transformedMessage = speech_history_transform_message(message);
speech_history_add(transformedMessage);
screen_reader_speak(transformedMessage, interrupt);
}
void check_speech_history_keys() {
// Comma: older.
if (key_pressed(KEY_COMMA)) {
if (speechHistory.length() == 0) {
screen_reader_speak("No speech history.", true);
screen_reader_speak(speech_history_transform_message("No speech history."), true);
return;
}
speechHistoryCurrentIndex--;
if (speechHistoryCurrentIndex < 0) {
speechHistoryCurrentIndex = 0;
screen_reader_speak("Oldest message. " + speechHistory[speechHistoryCurrentIndex], true);
screen_reader_speak(speech_history_transform_message("Oldest message. " + speechHistory[speechHistoryCurrentIndex]),
true);
return;
}
int position = speechHistoryCurrentIndex + 1;
screen_reader_speak(speechHistory[speechHistoryCurrentIndex] + " " + position + " of " + speechHistory.length(),
screen_reader_speak(speech_history_transform_message(speechHistory[speechHistoryCurrentIndex] + " " + position +
" of " + speechHistory.length()),
true);
return;
}
@@ -83,19 +98,21 @@ void check_speech_history_keys() {
// Period: newer.
if (key_pressed(KEY_PERIOD)) {
if (speechHistory.length() == 0) {
screen_reader_speak("No speech history.", true);
screen_reader_speak(speech_history_transform_message("No speech history."), true);
return;
}
speechHistoryCurrentIndex++;
if (speechHistoryCurrentIndex >= int(speechHistory.length())) {
speechHistoryCurrentIndex = speechHistory.length() - 1;
screen_reader_speak("Newest message. " + speechHistory[speechHistoryCurrentIndex], true);
screen_reader_speak(speech_history_transform_message("Newest message. " + speechHistory[speechHistoryCurrentIndex]),
true);
return;
}
int position = speechHistoryCurrentIndex + 1;
screen_reader_speak(speechHistory[speechHistoryCurrentIndex] + " " + position + " of " + speechHistory.length(),
screen_reader_speak(speech_history_transform_message(speechHistory[speechHistoryCurrentIndex] + " " + position +
" of " + speechHistory.length()),
true);
}
}