summaryrefslogtreecommitdiff
path: root/web/dartboat_wasm.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/dartboat_wasm.c')
-rw-r--r--web/dartboat_wasm.c60
1 files changed, 49 insertions, 11 deletions
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c
index a083780..f8a076d 100644
--- a/web/dartboat_wasm.c
+++ b/web/dartboat_wasm.c
@@ -59,9 +59,13 @@ void set_active_player(int pn)
if (state->mode == M_PVC && pn == 2) {
EM_ASM({promptMsgL($0)}, "Bot is throwing…");
+ EM_ASM({setKeyLabelSubmit($0)}, "OK");
+ EM_ASM({setKeyLabelRem($0)}, "REMAINING");
set_prompt_mode(PM_NONE);
} else {
EM_ASM({promptMsgL($0)}, "Enter points:");
+ EM_ASM({setKeyLabelSubmit($0)}, "OK");
+ EM_ASM({setKeyLabelRem($0)}, "REMAINING");
set_prompt_mode(PM_VISIT);
}
EM_ASM({promptMsgR($0)}, "");
@@ -231,6 +235,8 @@ void prompt_num_darts()
set_prompt_mode(PM_NUM_DARTS);
EM_ASM({promptMsgL($0)}, "Darts needed?");
EM_ASM({promptMsgR($0)}, "");
+ EM_ASM({setKeyLabelSubmit($0)}, "OK");
+ EM_ASM({setKeyLabelRem($0)}, "REMAINING");
}
void prompt_end_match()
@@ -240,10 +246,12 @@ void prompt_end_match()
EM_ASM({promptMsgL($0)},
state->mode == M_PVC && state->legs[1]->rem <= 0 ? "Bot wins. :(" :
"You win! :)");
- EM_ASM({promptMsgR($0)}, "Press OK to end match.");
+ EM_ASM({promptMsgR($0)}, "");
+ EM_ASM({setKeyLabelSubmit($0)}, "END MATCH");
+ EM_ASM({setKeyLabelRem($0)}, "REMATCH");
}
-EMSCRIPTEN_KEEPALIVE void prompt_select_mode()
+void prompt_select_mode()
{
for (int pn = 1; pn < 3; ++pn) {
EM_ASM({hidePlayerInfo($0)}, pn);
@@ -299,7 +307,7 @@ EMSCRIPTEN_KEEPALIVE void user_visit(int points)
points == 175 || points == 173 || points == 172 || points == 169 ||
points == 166 || points == 163 ||
(state->active_leg->rem - points == 0 &&
- (points == 168 || points == 165 || points == 162 ||
+ (points > 170 || points == 168 || points == 165 || points == 162 ||
points == 159))) {
EM_ASM(oi());
return;
@@ -405,7 +413,7 @@ EMSCRIPTEN_KEEPALIVE void start_match(int mode)
return;
}
- if (state) free_state(); // this should never happen
+ if (state) free_state(); // rematch gets us here
state = calloc(1, sizeof(*state));
state->mode = mode;
state->legs[0] = leg_init(501, mode == M_PVP ? "Player 1" : "User");
@@ -454,6 +462,21 @@ void init_boat()
EM_ASM({updateStdev($0)}, horizontal_stdev);
}
+bool is_key_active(char *k)
+{
+ return (EM_ASM_INT({return isKeyActive($0)}, k));
+}
+
+void toggle_key(char *k)
+{
+ EM_ASM({toggleKey($0)}, k);
+}
+
+void deactivate_key(char *k)
+{
+ EM_ASM({deactivateKey($0)}, k);
+}
+
char *prompt_get()
{
return (char *)EM_ASM_INT({return promptGet()});
@@ -468,7 +491,13 @@ void prompt_handle_pre(char *action)
if ((pm == PM_VISIT || pm == PM_NUM_DARTS || pm == PM_END_MATCH) &&
strcmp(action, "undo"))
- EM_ASM(deactivateUndo());
+ deactivate_key("undo");
+
+ if (pm == PM_END_MATCH && strcmp(action, "rem"))
+ deactivate_key("rem");
+
+ if (pm == PM_END_MATCH && strcmp(action, "submit"))
+ deactivate_key("submit");
}
void prompt_handle_on_change()
@@ -525,7 +554,9 @@ void prompt_handle_clear()
void prompt_handle_submit()
{
if (pm == PM_END_MATCH) {
- end_match();
+ if (is_key_active("submit"))
+ end_match();
+ toggle_key("submit");
return;
}
@@ -546,8 +577,15 @@ void prompt_handle_submit()
free(str);
}
-void prompt_handle_submit_rem()
+void prompt_handle_rem()
{
+ if (pm == PM_END_MATCH) {
+ if (is_key_active("rem"))
+ start_match(state->mode);
+ toggle_key("rem");
+ return;
+ }
+
if (pm != PM_VISIT)
return;
@@ -564,9 +602,9 @@ void prompt_handle_undo()
return;
prompt_handle_clear();
- if (EM_ASM_INT({return isUndoActive()}))
+ if (is_key_active("undo"))
user_undo();
- EM_ASM(toggleUndo());
+ toggle_key("undo");
}
EMSCRIPTEN_KEEPALIVE void prompt_handle(char *action, char *data)
@@ -581,8 +619,8 @@ EMSCRIPTEN_KEEPALIVE void prompt_handle(char *action, char *data)
prompt_handle_clear();
else if (!strcmp(action, "submit"))
prompt_handle_submit();
- else if (!strcmp(action, "submit_rem"))
- prompt_handle_submit_rem();
+ else if (!strcmp(action, "rem"))
+ prompt_handle_rem();
else if (!strcmp(action, "undo"))
prompt_handle_undo();
}