diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/web_scoreboard.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 769d68e..3543d0f 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -72,16 +72,20 @@ static void set_slot_active(int slot) EMSCRIPTEN_KEEPALIVE void scoreboard_prev_slot() { - set_slot_player(2, slots[0]); - set_slot_player(1, slots[1] == 1 ? match_num_players() : slots[1] - 1); + 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_active(player_slot(active_pn)); } EMSCRIPTEN_KEEPALIVE void scoreboard_next_slot() { - set_slot_player(1, slots[1]); - set_slot_player(2, slots[0] == match_num_players() ? 1 : slots[0] + 1); + 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_active(player_slot(active_pn)); } @@ -95,24 +99,13 @@ void scoreboard_set_player_active(int pn) } int np = match_num_players(); - int slot1, slot2, pslot; - if (np == 1) { - slot1 = 1; - slot2 = 0; - pslot = 1; - } else if (np == 2) { - slot1 = 1; - slot2 = 2; - pslot = pn == 1 ? 1 : 2; + if (np > NUM_SLOTS) { + for (int i = 0; i < NUM_SLOTS; ++i) + set_slot_player(i + 1, ((pn + i - 1) % np) + 1); + set_slot_active(1); } else { - slot1 = pn; - slot2 = pn == np ? 1 : pn + 1; - pslot = 1; + set_slot_active(pn); } - - set_slot_player(1, slot1); - set_slot_player(2, slot2); - set_slot_active(pslot); } void scoreboard_set_player_name(int pn, char *str) @@ -168,8 +161,12 @@ void scoreboard_flush_player_info(int pn) void scoreboard_flush() { - scoreboard_flush_player_info(1); - scoreboard_flush_player_info(2); + // FIXME unnecessary slot lookups + for (int i = 0; i < NUM_SLOTS; ++i) { + int pn = slots[i]; + if (pn) + scoreboard_flush_player_info(pn); + } } void update_player_name(int pn, char *str) |