diff options
Diffstat (limited to 'web/web_prompt.c')
-rw-r--r-- | web/web_prompt.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/web/web_prompt.c b/web/web_prompt.c index 201bd7b..7607009 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -3,6 +3,7 @@ #include "web_match.h" #include "web_scoreboard.h" +#include <stdio.h> #include <stdlib.h> #include <string.h> @@ -57,11 +58,14 @@ static inline void free_flushed_str(char *flushed, char *buffered) void prompt_flush() { if (buffered_str_changed(prompt_buffered.msgl, prompt_flushed.msgl)) - EM_ASM({setPromptMsgL($0)}, prompt_buffered.msgl); + EM_ASM({elemSetContent($0, $1)}, + "#prompt-msg-l", prompt_buffered.msgl); if (buffered_str_changed(prompt_buffered.msgr, prompt_flushed.msgr)) - EM_ASM({setPromptMsgR($0)}, prompt_buffered.msgr); + EM_ASM({elemSetContent($0, $1)}, + "#prompt-msg-r", prompt_buffered.msgr); if (buffered_str_changed(prompt_buffered.input, prompt_flushed.input)) - EM_ASM({setPromptInput($0)}, prompt_buffered.input); + EM_ASM({elemSetContent($0, $1)}, + "#prompt-input", prompt_buffered.input); free_flushed_str(prompt_flushed.msgl, prompt_buffered.msgl); free_flushed_str(prompt_flushed.msgr, prompt_buffered.msgr); @@ -75,9 +79,9 @@ void set_prompt_mode(enum prompt_mode mode) pm = mode; if (pm != PM_DARTBOARD) - EM_ASM(setPromptActive()); + EM_ASM({elemAddClass($0, $1)}, "#prompt", "active"); else - EM_ASM(setPromptInactive()); + EM_ASM({elemRemoveClass($0, $1)}, "#prompt", "active"); EM_ASM({setKeypad($0)}, pm == PM_DARTBOARD ? "dartboard" : pm == PM_SELECT_MODE ? "select_mode" : "default"); @@ -88,8 +92,8 @@ void prompt_visit() set_prompt_mode(PM_VISIT); prompt_set_msgl("Enter points:"); prompt_set_msgr(NULL); - EM_ASM({setKeyLabel($0, $1)}, "submit", "OK"); - EM_ASM({setKeyLabel($0, $1)}, "rem", "REMAINING"); + EM_ASM({elemSetContent($0, $1)}, "#key-submit", "OK"); + EM_ASM({elemSetContent($0, $1)}, "#key-rem", "REMAINING"); } void prompt_bot_visit() @@ -104,8 +108,8 @@ void prompt_num_darts() set_prompt_mode(PM_NUM_DARTS); prompt_set_msgl("Darts needed?"); prompt_set_msgr(NULL); - EM_ASM({setKeyLabel($0, $1)}, "submit", "OK"); - EM_ASM({setKeyLabel($0, $1)}, "rem", "REMAINING"); + EM_ASM({elemSetContent($0, $1)}, "#key-submit", "OK"); + EM_ASM({elemSetContent($0, $1)}, "#key-rem", "REMAINING"); } void prompt_end_match() @@ -116,8 +120,8 @@ void prompt_end_match() state->mode == M_PVC && state->legs[1]->rem <= 0 ? "Bot wins. :(" : "You win! :)"); prompt_set_msgr(NULL); - EM_ASM({setKeyLabel($0, $1)}, "submit", "END MATCH"); - EM_ASM({setKeyLabel($0, $1)}, "rem", "REMATCH"); + EM_ASM({elemSetContent($0, $1)}, "#key-submit", "OK"); + EM_ASM({elemSetContent($0, $1)}, "#key-rem", "REMATCH"); } void prompt_select_mode() @@ -126,7 +130,7 @@ void prompt_select_mode() EM_ASM({hidePlayerInfo($0)}, pn); clear_player_info(pn); } - EM_ASM(clearVisits()); + EM_ASM({elemSetContent($0, $1)}, "#visits", NULL); set_prompt_mode(PM_SELECT_MODE); prompt_set_msgl("Select match mode:"); @@ -135,22 +139,28 @@ void prompt_select_mode() bool is_key_active(char *k) { - return (EM_ASM_INT({return isKeyActive($0)}, k)); + char sel[64]; + sprintf(sel, "#key-%s", k); + return EM_ASM_INT({return elemHasClass($0, $1)}, sel, "active"); } void toggle_key(char *k) { - EM_ASM({toggleKey($0)}, k); + char sel[64]; + sprintf(sel, "#key-%s", k); + EM_ASM({elemToggleClass($0, $1)}, sel, "active"); } void deactivate_key(char *k) { - EM_ASM({deactivateKey($0)}, k); + char sel[64]; + sprintf(sel, "#key-%s", k); + EM_ASM({elemRemoveClass($0, $1)}, sel, "active"); } char *prompt_get() { - return (char *)EM_ASM_INT({return promptGet()}); + return (char *)EM_ASM_INT({return elemGetContent($0)}, "#prompt-input"); } void prompt_handle_pre(char *command) |