summaryrefslogtreecommitdiff
path: root/web/web_prompt.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-02 05:53:27 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-02 05:53:27 -0700
commit446a32d0e301285e54fa1030fb2138b0169d3fae (patch)
treebfae5ee543e920e7b4e2e0df2b481c6d244fe992 /web/web_prompt.c
parent4383f26c4ede32e1d32b851a2da6efa2cffcdaf2 (diff)
downloaddartboat-446a32d0e301285e54fa1030fb2138b0169d3fae.tar.gz
dartboat-446a32d0e301285e54fa1030fb2138b0169d3fae.tar.xz
web: move control logic to separate file
Diffstat (limited to 'web/web_prompt.c')
-rw-r--r--web/web_prompt.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/web/web_prompt.c b/web/web_prompt.c
index 64a23fd..abc5a05 100644
--- a/web/web_prompt.c
+++ b/web/web_prompt.c
@@ -1,3 +1,4 @@
+#include "web_control.h"
#include "web_prompt.h"
#include "web_match.h"
#include "web_ui.h"
@@ -7,17 +8,55 @@
#include <emscripten/emscripten.h>
-// FIXME forward declaring these until the code is better modularised
-void start_match(int mode);
-void user_num_darts(int n);
-void user_visit(int points);
-void user_visit_to_rem(int rem);
-void end_match();
-void update_user_rem_from_pts(int pts);
-void user_undo();
-
enum prompt_mode pm;
+void set_prompt_mode(enum prompt_mode mode)
+{
+ pm = mode;
+
+ if (pm != PM_DARTBOARD)
+ EM_ASM(setPromptActive());
+ else
+ EM_ASM(setPromptInactive());
+
+ EM_ASM({setKeypad($0)}, pm == PM_DARTBOARD ? "dartboard" :
+ pm == PM_SELECT_MODE ? "select_mode" : "default");
+}
+
+void prompt_num_darts()
+{
+ set_prompt_mode(PM_NUM_DARTS);
+ EM_ASM({promptMsgL($0)}, "Darts needed?");
+ EM_ASM({promptMsgR($0)}, "");
+ EM_ASM({setKeyLabel($0, $1)}, "submit", "OK");
+ EM_ASM({setKeyLabel($0, $1)}, "rem", "REMAINING");
+}
+
+void prompt_end_match()
+{
+ EM_ASM(setPlayerActive()); // sets all inactive
+ set_prompt_mode(PM_END_MATCH);
+ EM_ASM({promptMsgL($0)},
+ state->mode == M_PVC && state->legs[1]->rem <= 0 ? "Bot wins. :(" :
+ "You win! :)");
+ EM_ASM({promptMsgR($0)}, "");
+ EM_ASM({setKeyLabel($0, $1)}, "submit", "END MATCH");
+ EM_ASM({setKeyLabel($0, $1)}, "rem", "REMATCH");
+}
+
+void prompt_select_mode()
+{
+ for (int pn = 1; pn < 3; ++pn) {
+ EM_ASM({hidePlayerInfo($0)}, pn);
+ clear_player_info(pn);
+ }
+ EM_ASM(clearVisits());
+
+ set_prompt_mode(PM_SELECT_MODE);
+ EM_ASM({promptMsgL($0)}, "Select match mode:");
+ EM_ASM({promptMsgR($0)}, "");
+}
+
char *prompt_get()
{
return (char *)EM_ASM_INT({return promptGet()});