diff options
-rw-r--r-- | web/web_control.c | 20 | ||||
-rw-r--r-- | web/web_prompt.c | 15 | ||||
-rw-r--r-- | web/web_ui.c | 77 | ||||
-rw-r--r-- | web/web_ui.h | 5 |
4 files changed, 56 insertions, 61 deletions
diff --git a/web/web_control.c b/web/web_control.c index 4f78d67..6c51167 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -2,6 +2,7 @@ #include "web_match.h" #include "web_opts.h" #include "web_prompt.h" +#include "web_svg.h" #include "web_ui.h" #include "comp.h" @@ -50,6 +51,25 @@ void end_boat_visit(int rem, double avg) } EMSCRIPTEN_KEEPALIVE +void draw_boat_throwing(int pts, char *str, double x, double y) +{ + char pts_str[10]; + sprintf(pts_str, "%d", pts); + + int rem = state->legs[1]->n_visits > 1 ? + state->legs[1]->visits[state->legs[1]->n_visits-2].rem : + state->legs[1]->start; + + svg_draw_point(x, y); + update_player_rem(2, rem - pts); + EM_ASM({setPromptInput($0)}, pts_str); + EM_ASM({promptMsgR($0)}, str); + free(str); + + ui_flush_player_info(2); // FIXME bot hard-coded as player 2 +} + +EMSCRIPTEN_KEEPALIVE void boat_visit() { struct leg *l = state->legs[1]; diff --git a/web/web_prompt.c b/web/web_prompt.c index 7f65f6d..4a2b829 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -73,6 +73,21 @@ void prompt_select_mode() EM_ASM({promptMsgR($0)}, ""); } +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()}); diff --git a/web/web_ui.c b/web/web_ui.c index 070b898..14b0ee6 100644 --- a/web/web_ui.c +++ b/web/web_ui.c @@ -1,5 +1,4 @@ #include "web_match.h" -#include "web_svg.h" #include "web_ui.h" #include "checkouts.h" @@ -122,6 +121,27 @@ void update_player_avg(int pn, int n_darts) 0); } +void update_player_rem(int pn, int rem) +{ + char str[5]; + if (rem < 0 || rem == 1) + strcpy(str, "BUST"); + else + sprintf(str, "%d", rem); + + ui_set_player_rem(pn, str); + if (pn == 1 || state->mode != M_PVC) + update_player_sugg(pn, rem); +} + +void clear_player_info(int pn) +{ + ui_set_player_name(pn, NULL); + ui_set_player_rem(pn, NULL); + ui_set_player_sugg(pn, NULL); + ui_set_player_avg(pn, 0); +} + void draw_visits() { EM_ASM({clearVisits()}); @@ -163,58 +183,3 @@ void draw_visits() visit_no, p1_pts, p1_rem, p2_pts, p2_rem, p2_darts); } } - -void update_player_rem(int pn, int rem) -{ - char str[5]; - if (rem < 0 || rem == 1) - strcpy(str, "BUST"); - else - sprintf(str, "%d", rem); - - ui_set_player_rem(pn, str); - if (pn == 1 || state->mode != M_PVC) - update_player_sugg(pn, rem); -} - -void clear_player_info(int pn) -{ - ui_set_player_name(pn, ""); - ui_set_player_rem(pn, ""); - ui_set_player_sugg(pn, ""); - ui_set_player_avg(pn, 0); -} - -EMSCRIPTEN_KEEPALIVE -void draw_boat_throwing(int pts, char *str, double x, double y) -{ - char pts_str[10]; - sprintf(pts_str, "%d", pts); - - int rem = state->legs[1]->n_visits > 1 ? - state->legs[1]->visits[state->legs[1]->n_visits-2].rem : - state->legs[1]->start; - - svg_draw_point(x, y); - update_player_rem(2, rem - pts); - EM_ASM({setPromptInput($0)}, pts_str); - EM_ASM({promptMsgR($0)}, str); - free(str); - - ui_flush_player_info(2); // FIXME bot hard-coded as player 2 -} - -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); -} diff --git a/web/web_ui.h b/web/web_ui.h index a302e0a..831e3dd 100644 --- a/web/web_ui.h +++ b/web/web_ui.h @@ -15,10 +15,5 @@ void update_player_rem(int pn, int rem); void clear_player_info(int pn); void draw_visits(); -void draw_boat_throwing(int pts, char *str, double x, double y); - -bool is_key_active(char *k); -void toggle_key(char *k); -void deactivate_key(char *k); #endif |