From 2886add52aeed172289f3bddd995eda0b0c92a67 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Thu, 19 May 2022 15:24:06 -0700 Subject: web: display darts for comp as player 1 --- web/web_scoreboard.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'web/web_scoreboard.c') diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index d1bfa7e..fa1a672 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -167,6 +167,17 @@ static const char *points_class(int pts) "p0"; } +static void buf_darts(char *buf, size_t size, struct visit *v) +{ + char *ptr = buf; + for (int j = 0; j < v->n_darts; ++j) { + char *n = segment_name(v->darts[j]); + ptr += snprintf(ptr, size - (ptr - buf), + j == 0 ? "%s" : "-%s", n); + free(n); + } +} + void draw_visits() { dom_set_content("#visits", NULL); @@ -174,13 +185,15 @@ void draw_visits() int n_visits = state->legs[0]->n_visits > state->legs[1]->n_visits ? state->legs[0]->n_visits : state->legs[1]->n_visits; - struct dom_elem **elemv = malloc(6 * (n_visits + 1) * sizeof(*elemv)); + struct dom_elem **elemv = malloc(7 * (n_visits + 1) * sizeof(*elemv)); int elemc = 0; + elemv[elemc++] = create_div("", "visit-p1-spacer"); elemv[elemc++] = create_div(state->legs[0]->name, "visit-p1-name"); if (match_num_players() != 1) elemv[elemc++] = create_div(state->legs[1]->name, "visit-p2-name"); + elemv[elemc++] = create_div("", "visit-p2-spacer"); char buf[32], buf2[32]; snprintf(buf, sizeof(buf), "%d", state->legs[0]->start); @@ -204,6 +217,11 @@ void draw_visits() goto p2; v = state->legs[0]->visits + i; + if (v->n_darts) { + buf_darts(buf, sizeof(buf), v); + elemv[elemc++] = create_div(buf, "visit-p1-darts"); + } + snprintf(buf, sizeof(buf), "%d", v->points); snprintf(buf2, sizeof(buf2), "%s %s", "visit-p1-pts", points_class(v->points)); @@ -229,13 +247,7 @@ p2: elemv[elemc++] = create_div(buf, buf2); if (v->n_darts) { - char *ptr = buf; - for (int j = 0; j < v->n_darts; ++j) { - char *n = segment_name(v->darts[j]); - ptr += snprintf(ptr, sizeof(buf) - (ptr - buf), - j == 0 ? "%s" : "-%s", n); - free(n); - } + buf_darts(buf, sizeof(buf), v); elemv[elemc++] = create_div(buf, "visit-p2-darts"); } } @@ -246,4 +258,5 @@ p2: free(elemv); dom_scroll_to_bottom("#visits"); + dom_scroll_to_center_child("#visits", ".visit-n"); } -- cgit v1.2.3-70-g09d2