diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/static/sw.js | 2 | ||||
-rw-r--r-- | web/web_prompt.c | 137 | ||||
-rw-r--r-- | web/web_prompt.h | 2 |
3 files changed, 61 insertions, 80 deletions
diff --git a/web/static/sw.js b/web/static/sw.js index a181cc0..3b2d49b 100644 --- a/web/static/sw.js +++ b/web/static/sw.js @@ -1,5 +1,5 @@ const CACHE_PREFIX = 'dartboat-' -const CACHE_VERSION = '20'; +const CACHE_VERSION = '21'; const CACHE_NAME = `${CACHE_PREFIX}${CACHE_VERSION}`; const CACHE_FILES = [ diff --git a/web/web_prompt.c b/web/web_prompt.c index 5c5659c..86cc97f 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -11,7 +11,7 @@ #include <emscripten/emscripten.h> -int oi_timeout; +static int oi_timeout; enum prompt_mode { PM_DARTBOARD, @@ -22,6 +22,10 @@ enum prompt_mode { }; enum prompt_mode pm; +static struct { + bufstr msgl, msgr, input; +} bufs; + enum menu { MENU_MAIN, MENU_MATCH_OPTS, @@ -41,10 +45,6 @@ struct menu_opt { static struct menu_opt menu_optv[20]; static int menu_optc; -static struct { - bufstr msgl, msgr, input; -} bufs; - void oi() { dom_add_class("#oi", "visible"); @@ -87,8 +87,10 @@ void prompt_flush() dom_set_content("#prompt-input", bufstr_flush(&bufs.input)); } -void set_prompt_mode(enum prompt_mode mode) +static void set_prompt_mode(enum prompt_mode mode) { + if (pm == mode) return; + pm = mode; if (pm != PM_DARTBOARD) @@ -162,24 +164,24 @@ static void flush_menu_opts() free(elemv); } -static void menu_push(enum menu m); -static void menu_push_int(int m) { menu_push(m); }; +static void menu_push(int m); static void menu_pop(); +static void menu_display(); enum match_mode { - MM_1P1C, + MM_PVC, MM_1P, MM_2P, - MM_2C, - MM_8C + MM_CUST }; -void select_match_mode(int mode) +static int custom_users_added, custom_comps_added; +static void select_mode(int mm) { match_opts_new(); - switch((enum match_mode)mode) { - case MM_1P1C: + switch ((enum match_mode)mm) { + case MM_PVC: match_opts_add_player(PT_USER, "Player"); match_opts_add_player(PT_COMP, "Computer"); break; @@ -190,48 +192,25 @@ void select_match_mode(int mode) match_opts_add_player(PT_USER, "Player 1"); match_opts_add_player(PT_USER, "Player 2"); break; - case MM_2C: - match_opts_add_player(PT_COMP, "Computer 1"); - match_opts_add_player(PT_COMP, "Computer 2"); - break; - case MM_8C:; - char buf[32]; - for (int i = 1; i <= 8; ++i) { - sprintf(buf, "Computer %d", i); - match_opts_add_player(PT_COMP, buf); - } + case MM_CUST: + custom_users_added = custom_comps_added = 0; break; } - menu_push(MENU_MATCH_OPTS); + menu_push(mm == MM_CUST ? MENU_CUSTOM_MATCH_OPTS : MENU_MATCH_OPTS); } -static int custom_users_added, custom_comps_added; -void select_custom_match() -{ - match_opts_new(); - custom_users_added = custom_comps_added = 0; - menu_push(MENU_CUSTOM_MATCH_OPTS); -} - -void menu_display_main() +static void menu_display_main() { prompt_set_msgl("Select match mode:"); - add_menu_opti("Play against computer", - select_match_mode, MM_1P1C); - add_menu_opti("One-player scoreboard", - select_match_mode, MM_1P); - add_menu_opti("Two-player scoreboard", - select_match_mode, MM_2P); - add_menu_opti("Computer vs computer", - select_match_mode, MM_2C); - add_menu_opti("Battle of the computers", - select_match_mode, MM_8C); - add_menu_opt("Custom", select_custom_match); + add_menu_opti("Play against computer", select_mode, MM_PVC); + add_menu_opti("One-player scoreboard", select_mode, MM_1P); + add_menu_opti("Two-player scoreboard", select_mode, MM_2P); + add_menu_opti("Custom", select_mode, MM_CUST); } -void menu_display_match_opts() +static void menu_display_match_opts() { prompt_set_msgl("Match options:"); @@ -239,10 +218,10 @@ void menu_display_match_opts() char buf[64]; sprintf(buf, "Starting points: %d", match_opts->start_pts); - add_menu_opti(buf, menu_push_int, MENU_START_PTS); + add_menu_opti(buf, menu_push, MENU_START_PTS); sprintf(buf, "Throws first: %s", match_opts->players[match_opts->throws_first - 1].name); - add_menu_opti(buf, menu_push_int, MENU_THROWS_FIRST); + add_menu_opti(buf, menu_push, MENU_THROWS_FIRST); add_menu_opt("Back", menu_pop); } @@ -254,7 +233,7 @@ static void custom_start_match() else oi(); } -void menu_display(); + static void custom_add_player(int type) { if (match_opts->num_players >= 10) { @@ -269,6 +248,7 @@ static void custom_add_player(int type) match_opts_add_player(type, buf); menu_display(); } + static void custom_remove_player(int pn) { match_opts_remove_player(pn); @@ -283,16 +263,16 @@ static void menu_display_custom_match_opts() char buf[64]; sprintf(buf, "Starting points: %d", match_opts->start_pts); - add_menu_opti(buf, menu_push_int, MENU_START_PTS); + add_menu_opti(buf, menu_push, MENU_START_PTS); sprintf(buf, "Throws first: %s", match_opts->throws_first ? match_opts->players[ match_opts->throws_first - 1].name : "(no players added)"); - add_menu_opti(buf, menu_push_int, MENU_THROWS_FIRST); + add_menu_opti(buf, menu_push, MENU_THROWS_FIRST); + add_menu_opti("Add user player", custom_add_player, PT_USER); add_menu_opti("Add computer player", custom_add_player, PT_COMP); - for (int i = 0; i < match_opts->num_players; ++i) { sprintf(buf, "Remove player: %s", match_opts->players[i].name); add_menu_opti(buf, custom_remove_player, i + 1); @@ -307,7 +287,7 @@ static void set_start_pts(int pts) menu_pop(); } -void menu_display_start_pts() +static void menu_display_start_pts() { prompt_set_msgl("Starting points:"); @@ -325,7 +305,7 @@ static void set_throws_first(int pn) menu_pop(); } -void menu_display_throws_first() +static void menu_display_throws_first() { prompt_set_msgl("Throws first:"); @@ -336,10 +316,9 @@ void menu_display_throws_first() add_menu_opt("Back", menu_pop); } -void menu_display() +static void menu_display() { - if (pm != PM_MENU) - set_prompt_mode(PM_MENU); + set_prompt_mode(PM_MENU); prompt_set_msgl(NULL); prompt_set_msgr(NULL); @@ -373,7 +352,7 @@ static void menu_pop() menu_display(); } -static void menu_push(enum menu m) +static void menu_push(int m) { menu_stack[++menu_depth] = m; menu_display(); @@ -396,18 +375,18 @@ static void menu_submit(int opt) void prompt_main_menu() { - scoreboard_hide_info(); - dom_set_content("#visits", NULL); - menu_depth = 0; menu_stack[0] = MENU_MAIN; - menu_display(); + + scoreboard_hide_info(); + dom_set_content("#visits", NULL); } void prompt_user_visit() { set_prompt_mode(PM_VISIT); + prompt_set_msgl("Enter points:"); prompt_set_msgr(NULL); @@ -428,55 +407,57 @@ void prompt_comp_visit() void prompt_num_darts() { set_prompt_mode(PM_NUM_DARTS); + prompt_set_msgl("Darts needed?"); prompt_set_msgr(NULL); + dom_set_content("#key-submit", "OK"); dom_set_content("#key-rem", "REMAINING"); } void prompt_end_match() { - scoreboard_set_player_active(0); + set_prompt_mode(PM_END_MATCH); char buf[64]; sprintf(buf, "%s wins.", state->legs[match_winning_player() - 1]->name); - - set_prompt_mode(PM_END_MATCH); prompt_set_msgl(buf); prompt_set_msgr(NULL); dom_set_content("#key-submit", "END MATCH"); dom_set_content("#key-rem", "REMATCH"); + + scoreboard_set_player_active(0); } -bool key_is_active(char *k) +static bool key_is_active(char *k) { char sel[64]; sprintf(sel, "#key-%s", k); return dom_has_class(sel, "active"); } -void toggle_key(char *k) +static void toggle_key(char *k) { char sel[64]; sprintf(sel, "#key-%s", k); dom_toggle_class(sel, "active"); } -void deactivate_key(char *k) +static void deactivate_key(char *k) { char sel[64]; sprintf(sel, "#key-%s", k); dom_remove_class(sel, "active"); } -char *prompt_get() +static char *prompt_get() { return dom_get_content("#prompt-input"); } -void prompt_handle_pre(char *command) +static void prompt_handle_pre(char *command) { if (pm == PM_DARTBOARD) return; @@ -497,7 +478,7 @@ void prompt_handle_pre(char *command) deactivate_key("exit"); } -void prompt_handle_on_change() +static void prompt_handle_on_change() { prompt_flush(); @@ -509,7 +490,7 @@ void prompt_handle_on_change() free(str); } -void prompt_handle_append(char *data) +static void prompt_handle_append(char *data) { if (pm != PM_MENU && pm != PM_VISIT && @@ -528,7 +509,7 @@ void prompt_handle_append(char *data) free(str); } -void prompt_handle_backspace() +static void prompt_handle_backspace() { if (pm == PM_DARTBOARD) return; @@ -543,7 +524,7 @@ void prompt_handle_backspace() free(str); } -void prompt_handle_clear() +static void prompt_handle_clear() { if (pm == PM_DARTBOARD) return; @@ -552,7 +533,7 @@ void prompt_handle_clear() prompt_handle_on_change(); } -void prompt_handle_submit() +static void prompt_handle_submit() { if (pm == PM_END_MATCH) { if (key_is_active("submit")) @@ -580,7 +561,7 @@ void prompt_handle_submit() free(str); } -void prompt_handle_rem() +static void prompt_handle_rem() { if (pm == PM_END_MATCH) { if (key_is_active("rem")) @@ -599,7 +580,7 @@ void prompt_handle_rem() free(str); } -void prompt_handle_undo() +static void prompt_handle_undo() { if (pm != PM_VISIT && pm != PM_NUM_DARTS && pm != PM_END_MATCH) return; @@ -610,7 +591,7 @@ void prompt_handle_undo() toggle_key("undo"); } -void prompt_handle_exit() +static void prompt_handle_exit() { if (key_is_active("exit")) end_match(); diff --git a/web/web_prompt.h b/web/web_prompt.h index 7843998..78f2e97 100644 --- a/web/web_prompt.h +++ b/web/web_prompt.h @@ -8,10 +8,10 @@ void prompt_set_msgr(char *str); void prompt_set_input(char *str); void prompt_flush(); +void prompt_main_menu(); void prompt_user_visit(); void prompt_comp_visit(); void prompt_num_darts(); void prompt_end_match(); -void prompt_main_menu(); #endif |