From 6fb1750b923b97a377d6ef8ad4a25b501e65b39d Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 20 May 2022 15:03:44 -0700 Subject: web: support visit log for 3+ player matches The new match modes are for testing. They'll eventually be removed in favour of true configurability. --- web/web_scoreboard.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 3 deletions(-) (limited to 'web/web_scoreboard.c') diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 3543d0f..f298dfe 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -279,9 +279,108 @@ static void buf_darts(char *buf, size_t size, struct visit *v) } } +void draw_visits_dense() +{ + dom_set_content("#visits", NULL); + dom_add_class("#visits", "dense"); + + int np = match_num_players(); + dom_set_style_property_int("--num-players", np); + + // FIXME + 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( + (np * 2 + 1) * (2 * n_visits + 2) * sizeof(*elemv)); + int elemc = 0; + + elemv[elemc++] = create_div("", ""); + for (int i = 0; i < np; ++i) { + elemv[elemc++] = create_div(state->legs[i]->name, + "visit-name"); + } + + char buf[32], buf2[32]; + elemv[elemc++] = create_div("0", "visit-n"); + for (int i = 0; i < np; ++i) { + if (i + 1 == match_opts->throws_first) + elemv[elemc++] = create_div("", "throws-first"); + else + elemv[elemc++] = create_div("", ""); + snprintf(buf, sizeof(buf), "%d", state->legs[i]->start); + elemv[elemc++] = create_div(buf, ""); + } + + for (int i = 0; i < n_visits; ++i) { + snprintf(buf, sizeof(buf), "%d", i + 1); + elemv[elemc++] = create_div(buf, "visit-n"); + + for (int j = 0; j < np; ++j) { + if (i >= state->legs[j]->n_visits) { + elemv[elemc++] = create_div("", ""); + elemv[elemc++] = create_div("", ""); + continue; + } + + struct visit *v = state->legs[j]->visits + i; + + snprintf(buf, sizeof(buf), "%d", v->points); + snprintf(buf2, sizeof(buf2), "%s", + points_class(v->points)); + elemv[elemc++] = create_div(buf, buf2); + + snprintf(buf, sizeof(buf), "%d", v->rem); + elemv[elemc++] = create_div(buf, ""); + } + + bool n_darts = false; + for (int j = 0; j < np; ++j) { + if (i < state->legs[j]->n_visits && + state->legs[j]->visits[i].n_darts) + n_darts = true; + } + if (!n_darts) continue; + + elemv[elemc++] = create_div("", ""); + for (int j = 0; j < np; ++j) { + if (i >= state->legs[j]->n_visits) { + elemv[elemc++] = create_div("", + "visit-dense-darts"); + continue; + } + + struct visit *v = state->legs[j]->visits + i; + + if (v->n_darts) { + buf_darts(buf, sizeof(buf), v); + elemv[elemc++] = create_div(buf, + "visit-dense-darts"); + } else { + elemv[elemc++] = create_div("", + "visit-dense-darts"); + } + } + } + + dom_append_elemv("#visits", elemc, elemv); + for (int i = 0; i < elemc; ++i) + dom_elem_free(elemv[i]); + free(elemv); + + dom_scroll_to_bottom("#visits"); + dom_scroll_to_center_child("#visits", ".visit-n"); +} + void draw_visits() { + if (match_num_players() > 2) { + draw_visits_dense(); + return; + } + dom_set_content("#visits", NULL); + dom_remove_class("#visits", "dense"); int n_visits = state->legs[0]->n_visits > state->legs[1]->n_visits ? state->legs[0]->n_visits : state->legs[1]->n_visits; @@ -300,7 +399,7 @@ void draw_visits() snprintf(buf, sizeof(buf), "%d", state->legs[0]->start); if (match_opts->throws_first == 1) elemv[elemc++] = create_div("", // content added via CSS - "visit-p1-pts throws-first icon"); + "visit-p1-pts throws-first"); elemv[elemc++] = create_div(buf, "visit-p1-rem"); elemv[elemc++] = create_div("0", "visit-n"); if (match_num_players() != 1) { @@ -308,7 +407,7 @@ void draw_visits() elemv[elemc++] = create_div(buf, "visit-p2-rem"); if (match_opts->throws_first == 2) elemv[elemc++] = create_div("", - "visit-p2-pts throws-first icon"); + "visit-p2-pts throws-first"); } for (int i = 0; i < n_visits; ++i) { @@ -331,10 +430,10 @@ void draw_visits() snprintf(buf, sizeof(buf), "%d", v->rem); elemv[elemc++] = create_div(buf, "visit-p1-rem"); +p2: snprintf(buf, sizeof(buf), "%d", i + 1); elemv[elemc++] = create_div(buf, "visit-n"); -p2: if (i >= state->legs[1]->n_visits) continue; v = state->legs[1]->visits + i; -- cgit v1.2.3-70-g09d2