summaryrefslogtreecommitdiff
path: root/web/web_scoreboard.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-23 15:23:48 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-23 15:25:07 -0700
commit15ff00e056a98ab4210dde3d4461a88849d6c1d4 (patch)
tree280b8d248baee5d2ae0dcc2117e3f2b309d128ec /web/web_scoreboard.c
parentc93897ed2013f20d6ece33815971d206fd0d056e (diff)
downloaddartboat-15ff00e056a98ab4210dde3d4461a88849d6c1d4.tar.gz
dartboat-15ff00e056a98ab4210dde3d4461a88849d6c1d4.tar.xz
move a bunch of general match logic from web to lib
Diffstat (limited to 'web/web_scoreboard.c')
-rw-r--r--web/web_scoreboard.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c
index 2916ae8..907b1e5 100644
--- a/web/web_scoreboard.c
+++ b/web/web_scoreboard.c
@@ -75,7 +75,7 @@ void scoreboard_prev_slot()
for (int i = NUM_SLOTS; i > 1; --i)
set_slot_player(i, slots[i - 2]);
int prev = slots[0];
- set_slot_player(1, prev == 1 ? match_num_players() : prev - 1);
+ set_slot_player(1, prev == 1 ? state->m->n_players : prev - 1);
set_slot_active(player_slot(active_pn));
}
@@ -85,7 +85,7 @@ void scoreboard_next_slot()
for (int i = 1; i < NUM_SLOTS; ++i)
set_slot_player(i, slots[i]);
int prev = slots[NUM_SLOTS - 1];
- set_slot_player(NUM_SLOTS, prev == match_num_players() ? 1 : prev + 1);
+ set_slot_player(NUM_SLOTS, prev == state->m->n_players ? 1 : prev + 1);
set_slot_active(player_slot(active_pn));
}
@@ -98,7 +98,7 @@ void scoreboard_set_player_active(int pn)
return;
}
- int np = match_num_players();
+ int np = state->m->n_players;
if (np > NUM_SLOTS) {
for (int i = 0; i < NUM_SLOTS; ++i)
set_slot_player(i + 1, ((pn + i - 1) % np) + 1);
@@ -202,7 +202,7 @@ static double calc_avg(struct leg *l, int n_darts) {
void update_player_avg(int pn, int n_darts)
{
- struct leg *l = state->legs[pn-1];
+ struct leg *l = state->m->legs[pn-1];
scoreboard_set_player_avg(pn, calc_avg(l, n_darts));
}
@@ -284,13 +284,13 @@ void draw_visits_dense()
dom_set_content("#visits", NULL);
dom_add_class("#visits", "dense");
- int np = match_num_players();
+ int np = state->m->n_players;
dom_set_style_property_int("--num-players", np);
int n_visits = 0;
for (int i = 0; i < np; ++i) {
- if (state->legs[i]->n_visits > n_visits)
- n_visits = state->legs[i]->n_visits;
+ if (state->m->legs[i]->n_visits > n_visits)
+ n_visits = state->m->legs[i]->n_visits;
}
struct dom_elem **elemv = malloc(
@@ -301,7 +301,7 @@ void draw_visits_dense()
elemv[elemc++] = create_div("", "");
for (int i = 0; i < np; ++i) {
sprintf(buf, "visit-name visit-name-%d", i + 1);
- elemv[elemc++] = create_div(state->legs[i]->name, buf);
+ elemv[elemc++] = create_div(state->m->players[i].name, buf);
}
elemv[elemc++] = create_div("0", "visit-n");
@@ -310,7 +310,7 @@ void draw_visits_dense()
elemv[elemc++] = create_div("", "throws-first");
else
elemv[elemc++] = create_div("", "");
- snprintf(buf, sizeof(buf), "%d", state->legs[i]->start);
+ snprintf(buf, sizeof(buf), "%d", state->m->legs[i]->start);
elemv[elemc++] = create_div(buf, "");
}
@@ -319,13 +319,13 @@ void draw_visits_dense()
elemv[elemc++] = create_div(buf, "visit-n");
for (int j = 0; j < np; ++j) {
- if (i >= state->legs[j]->n_visits) {
+ if (i >= state->m->legs[j]->n_visits) {
elemv[elemc++] = create_div("", "");
elemv[elemc++] = create_div("", "");
continue;
}
- struct visit *v = state->legs[j]->visits + i;
+ struct visit *v = state->m->legs[j]->visits + i;
snprintf(buf, sizeof(buf), "%d", v->points);
snprintf(buf2, sizeof(buf2), "%s",
@@ -338,21 +338,21 @@ void draw_visits_dense()
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)
+ if (i < state->m->legs[j]->n_visits &&
+ state->m->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) {
+ if (i >= state->m->legs[j]->n_visits) {
elemv[elemc++] = create_div("",
"visit-dense-darts");
continue;
}
- struct visit *v = state->legs[j]->visits + i;
+ struct visit *v = state->m->legs[j]->visits + i;
if (v->n_darts) {
buf_darts(buf, sizeof(buf), v);
@@ -371,14 +371,15 @@ void draw_visits_dense()
free(elemv);
dom_scroll_to_bottom("#visits");
- int pn = match_is_over() ? state->active_player : match_next_player();
+ int pn = match_winning_player(state->m);
+ if (!pn) pn = match_next_player(state->m);
sprintf(buf, ".visit-name-%d", pn);
dom_scroll_to_center_child("#visits", buf);
}
void draw_visits()
{
- if (match_num_players() > 2) {
+ if (state->m->n_players > 2) {
draw_visits_dense();
return;
}
@@ -386,29 +387,30 @@ void draw_visits()
dom_set_content("#visits", NULL);
dom_remove_class("#visits", "dense");
- int n_visits = state->legs[0]->n_visits;
- if (match_num_players() != 1 && state->legs[1]->n_visits > n_visits)
- n_visits = state->legs[1]->n_visits;
+ int n_visits = state->m->legs[0]->n_visits;
+ if (state->m->n_players != 1 && state->m->legs[1]->n_visits > n_visits)
+ n_visits = state->m->legs[1]->n_visits;
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,
+ elemv[elemc++] = create_div(state->m->players[0].name,
+ "visit-p1-name");
+ if (state->m->n_players != 1)
+ elemv[elemc++] = create_div(state->m->players[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);
+ snprintf(buf, sizeof(buf), "%d", state->m->legs[0]->start);
if (match_opts->throws_first == 1)
elemv[elemc++] = create_div("", // content added via CSS
"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) {
- snprintf(buf, sizeof(buf), "%d", state->legs[1]->start);
+ if (state->m->n_players != 1) {
+ snprintf(buf, sizeof(buf), "%d", state->m->legs[1]->start);
elemv[elemc++] = create_div(buf, "visit-p2-rem");
if (match_opts->throws_first == 2)
elemv[elemc++] = create_div("",
@@ -418,9 +420,9 @@ void draw_visits()
for (int i = 0; i < n_visits; ++i) {
struct visit *v;
- if (i >= state->legs[0]->n_visits)
+ if (i >= state->m->legs[0]->n_visits)
goto p2;
- v = state->legs[0]->visits + i;
+ v = state->m->legs[0]->visits + i;
if (v->n_darts) {
buf_darts(buf, sizeof(buf), v);
@@ -439,9 +441,10 @@ p2:
snprintf(buf, sizeof(buf), "%d", i + 1);
elemv[elemc++] = create_div(buf, "visit-n");
- if (match_num_players() == 1 || i >= state->legs[1]->n_visits)
+ if (state->m->n_players == 1 ||
+ i >= state->m->legs[1]->n_visits)
continue;
- v = state->legs[1]->visits + i;
+ v = state->m->legs[1]->visits + i;
snprintf(buf, sizeof(buf), "%d", v->rem);
elemv[elemc++] = create_div(buf, "visit-p2-rem");