Add texthook_suppress option

For suppressing text hook on specified scenario pages.
This commit is contained in:
kichikuou
2024-12-06 10:24:36 +09:00
parent 1e7a59f9cd
commit 0b04f5f334
7 changed files with 47 additions and 0 deletions
+31
View File
@@ -1,5 +1,8 @@
#include <string>
#include <unordered_set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL.h>
#include "texthook.h"
@@ -129,6 +132,12 @@ private:
} copy;
TextHookHandler *handler = &none;
std::unordered_set<int> suppression_set;
enum {
INIT,
SUPPRESSING,
EMITTING,
} suppression_state = INIT;
} // namespace
@@ -146,20 +155,42 @@ void texthook_set_mode(TexthookMode mode) {
}
}
// suppressions is a comma-separated list of page numbers to suppress.
void texthook_set_suppression_list(const char *suppressions) {
suppression_set.clear();
if (!suppressions || !*suppressions)
return;
char *buf = strdup(suppressions);
char *token = strtok(buf, ",");
while (token) {
suppression_set.insert(atoi(token));
token = strtok(NULL, ",");
}
free(buf);
}
void texthook_character(int page, int c) {
if (suppression_state == INIT)
suppression_state = suppression_set.count(page) ? SUPPRESSING : EMITTING;
if (suppression_state == SUPPRESSING)
return;
handler->character(page, c);
}
void texthook_newline(void) {
handler->newline();
suppression_state = INIT;
}
void texthook_nextpage(void) {
handler->nextpage();
suppression_state = INIT;
}
void texthook_keywait(void) {
handler->keywait();
suppression_state = INIT;
}
#endif