diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/web_control.c | 2 | ||||
-rw-r--r-- | web/web_match.c | 4 | ||||
-rw-r--r-- | web/web_prompt.c | 2 | ||||
-rw-r--r-- | web/web_scoreboard.c | 40 |
4 files changed, 22 insertions, 26 deletions
diff --git a/web/web_control.c b/web/web_control.c index 5389a23..b0a777c 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -297,7 +297,7 @@ void end_match() // clean up in case match was ended early svg_clear_points(); prompt_set_input(NULL); - scoreboard_set_player_active(-1); + scoreboard_set_player_active(0); dom_remove_class("#key-exit", "visible"); dom_enable_exit_dialogue(false); diff --git a/web/web_match.c b/web/web_match.c index 793aedd..f200f11 100644 --- a/web/web_match.c +++ b/web/web_match.c @@ -82,12 +82,12 @@ int match_winning_player() return i + 1; } - return -1; + return 0; } bool match_is_over() { - return match_winning_player() != -1; + return match_winning_player() != 0; } int match_prev_player() diff --git a/web/web_prompt.c b/web/web_prompt.c index ad907bc..f7bfe8d 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -169,7 +169,7 @@ void prompt_num_darts() void prompt_end_match() { - scoreboard_set_player_active(-1); + scoreboard_set_player_active(0); char buf[64]; sprintf(buf, "%s wins.", diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 57090fb..7dc4b8e 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -15,16 +15,16 @@ static struct { bufstr name, rem, sugg, avg; -} bufs[4]; +} *bufs; #define NUM_SLOTS 2 static int slots[NUM_SLOTS]; -static int active_pn = -1; +static int active_pn; static void flush_slot(int slot) { int pn = slots[slot - 1]; - if (pn == -1) return; + if (!pn) return; // FIXME: should be combined with flushing player info char sel[32]; @@ -46,7 +46,7 @@ static int player_slot(int pn) return i + 1; } - return -1; + return 0; } static void set_slot_player(int slot, int pn) @@ -61,10 +61,10 @@ static void set_slot_active(int slot) { char buf[64], *sel = buf; - if (slot == -1) - sel = NULL; - else + if (slot) sprintf(sel, "#info-slot-%d", slot); + else + sel = NULL; dom_set_uniq_class(sel, "active", ".info-slot"); } @@ -89,8 +89,8 @@ void scoreboard_set_player_active(int pn) { active_pn = pn; - if (pn == -1) { - set_slot_active(-1); + if (!pn) { + set_slot_active(0); return; } @@ -98,7 +98,7 @@ void scoreboard_set_player_active(int pn) int slot1, slot2, pslot; if (np == 1) { slot1 = 1; - slot2 = -1; + slot2 = 0; pslot = 1; } else if (np == 2) { slot1 = 1; @@ -140,7 +140,7 @@ void scoreboard_set_player_avg(int pn, double avg) void scoreboard_flush_player_info(int pn) { int slot = player_slot(pn); - if (slot == -1) return; + if (!slot) return; char sel[32]; int len = sprintf(sel, "#info-slot-%d .", slot); @@ -224,6 +224,9 @@ void update_player_rem(int pn, int rem) void scoreboard_show_info(int num_players) { + if (bufs) free(bufs); + bufs = calloc(num_players, sizeof(*bufs)); + set_slot_player(1, 1); dom_add_class("#info-slot-1 .inner", "visible"); @@ -238,20 +241,13 @@ void scoreboard_show_info(int num_players) } } -static void clear_player_info(int pn) -{ - scoreboard_set_player_name(pn, NULL); - scoreboard_set_player_rem(pn, NULL); - scoreboard_set_player_sugg(pn, NULL); - scoreboard_set_player_avg(pn, 0); -} - void scoreboard_hide_info() { - dom_set_uniq_class(NULL, "visible", ".info-slot .inner"); - for (int pn = 1; pn < 4; ++pn) // FIXME - clear_player_info(pn); + free(bufs); + bufs = NULL; + memset(slots, 0, sizeof(slots)); + dom_set_uniq_class(NULL, "visible", ".info-slot .inner"); dom_remove_class("#info-slot-prev", "visible"); dom_remove_class("#info-slot-next", "visible"); } |