From 446a32d0e301285e54fa1030fb2138b0169d3fae Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 2 May 2022 05:53:27 -0700 Subject: web: move control logic to separate file --- web/web_prompt.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'web/web_prompt.c') 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 -// 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()}); -- cgit v1.2.3-70-g09d2