diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-23 15:50:36 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-23 15:54:12 -0700 |
commit | ee146e45b9ccc7f3b5dfd34973df538a42772b84 (patch) | |
tree | 3b91beb43a2cac1ad16eefa43b21c6d991d49ac1 | |
parent | 15ff00e056a98ab4210dde3d4461a88849d6c1d4 (diff) | |
download | dartboat-ee146e45b9ccc7f3b5dfd34973df538a42772b84.tar.gz dartboat-ee146e45b9ccc7f3b5dfd34973df538a42772b84.tar.xz |
store starting player as part of match data
-rw-r--r-- | match.c | 5 | ||||
-rw-r--r-- | match.h | 4 | ||||
-rw-r--r-- | web/static/sw.js | 2 | ||||
-rw-r--r-- | web/web_control.c | 7 | ||||
-rw-r--r-- | web/web_scoreboard.c | 6 |
5 files changed, 14 insertions, 10 deletions
@@ -85,7 +85,10 @@ void match_add_player(struct match *m, enum player_type type, char *name, { if (m->n_players == m->size_players) match_grow_players(m); + int i = m->n_players++; + if (!m->starting_player) + m->starting_player = i; struct player *p = m->players + i; p->type = type; @@ -110,7 +113,7 @@ int match_prev_player(struct match *m) return m->active_player - 1; } -int match_last_player_to_throw(struct match *m) +int match_prev_throw_player(struct match *m) { int p = match_winning_player(m); return p ? p : match_prev_player(m); @@ -32,7 +32,7 @@ struct leg { struct match { struct player *players; int n_players, size_players; - int active_player; + int starting_player, active_player; struct leg **legs; }; @@ -51,7 +51,7 @@ void match_add_player(struct match *m, enum player_type type, char *name, int match_next_player(struct match *m); int match_prev_player(struct match *m); -int match_last_player_to_throw(struct match *m); +int match_prev_throw_player(struct match *m); int match_winning_player(struct match *m); bool is_points_valid(int pts, int rem); diff --git a/web/static/sw.js b/web/static/sw.js index 56f5626..5760aaf 100644 --- a/web/static/sw.js +++ b/web/static/sw.js @@ -1,5 +1,5 @@ const CACHE_PREFIX = 'dartboat-' -const CACHE_VERSION = '22'; +const CACHE_VERSION = '23'; const CACHE_NAME = `${CACHE_PREFIX}${CACHE_VERSION}`; const CACHE_FILES = [ diff --git a/web/web_control.c b/web/web_control.c index d06e17e..96c455e 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -135,7 +135,7 @@ void handle_next() if (state->m->active_player) set_active_player(match_next_player(state->m)); else - set_active_player(match_opts->throws_first); + set_active_player(state->m->starting_player); if (match_player_is_comp(state->m->active_player)) boat_visit(); @@ -181,7 +181,7 @@ static void undo_active() update_player_avg(state->m->active_player, 0); update_player_rem(state->m->active_player, l->rem); - state->m->active_player = match_last_player_to_throw(state->m); + state->m->active_player = match_prev_throw_player(state->m); } void user_undo() @@ -202,7 +202,7 @@ void user_undo() return; } - state->m->active_player = match_last_player_to_throw(state->m); + state->m->active_player = match_prev_throw_player(state->m); while (match_player_is_comp(state->m->active_player)) undo_active(); undo_active(); @@ -233,6 +233,7 @@ void start_match() match_opts->players[i].type, match_opts->players[i].name, match_opts->start_pts); + state->m->starting_player = match_opts->throws_first; scoreboard_show_info(state->m->n_players); for (int i = 1; i <= state->m->n_players; ++i) { diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 907b1e5..657c326 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -306,7 +306,7 @@ void draw_visits_dense() elemv[elemc++] = create_div("0", "visit-n"); for (int i = 0; i < np; ++i) { - if (i + 1 == match_opts->throws_first) + if (i + 1 == state->m->starting_player) elemv[elemc++] = create_div("", "throws-first"); else elemv[elemc++] = create_div("", ""); @@ -404,7 +404,7 @@ void draw_visits() char buf[32], buf2[32]; snprintf(buf, sizeof(buf), "%d", state->m->legs[0]->start); - if (match_opts->throws_first == 1) + if (state->m->starting_player == 1) elemv[elemc++] = create_div("", // content added via CSS "visit-p1-pts throws-first"); elemv[elemc++] = create_div(buf, "visit-p1-rem"); @@ -412,7 +412,7 @@ void draw_visits() 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) + if (state->m->starting_player == 2) elemv[elemc++] = create_div("", "visit-p2-pts throws-first"); } |