diff options
Diffstat (limited to 'web/web_scoreboard.c')
-rw-r--r-- | web/web_scoreboard.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 6be1cd4..34ee4c5 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -12,8 +12,7 @@ #include <emscripten/emscripten.h> struct player_info { - char *name, *rem, *sugg; - double avg; + char *name, *rem, *sugg, *avg; }; struct player_info buffered_info[2], flushed_info[2]; @@ -46,7 +45,9 @@ void scoreboard_set_player_sugg(int pn, char *str) void scoreboard_set_player_avg(int pn, double avg) { - buffered_info[pn-1].avg = avg; + char *str = malloc(8); + sprintf(str, "%.2f", avg); + buffer_str(str, &buffered_info[pn-1].avg, flushed_info[pn-1].avg); } static inline bool buffered_str_changed(char *buffered, char *flushed) @@ -63,24 +64,38 @@ static inline void free_flushed_str(char *flushed, char *buffered) void scoreboard_flush_player_info(int pn) { + char sel[64]; + int len = sprintf(sel, "#p%d-", pn); + if (buffered_str_changed(buffered_info[pn-1].name, - flushed_info[pn-1].name)) - EM_ASM({updatePlayerName($0, $1)}, pn, buffered_info[pn-1].name); + flushed_info[pn-1].name)) { + strcpy(sel + len, "name"); + EM_ASM({elemSetContent($0, $1)}, sel, buffered_info[pn-1].name); + } if (buffered_str_changed(buffered_info[pn-1].rem, - flushed_info[pn-1].rem)) - EM_ASM({updatePlayerRem($0, $1)}, pn, buffered_info[pn-1].rem); + flushed_info[pn-1].rem)) { + strcpy(sel + len, "rem"); + EM_ASM({elemSetContent($0, $1)}, sel, buffered_info[pn-1].rem); + } if (buffered_str_changed(buffered_info[pn-1].sugg, - flushed_info[pn-1].sugg)) - EM_ASM({updatePlayerSugg($0, $1)}, pn, buffered_info[pn-1].sugg); + flushed_info[pn-1].sugg)) { + strcpy(sel + len, "sugg"); + EM_ASM({elemSetContent($0, $1)}, sel, buffered_info[pn-1].sugg); + } - if (buffered_info[pn-1].avg != flushed_info[pn-1].avg) - EM_ASM({updatePlayerAvg($0, $1)}, pn, buffered_info[pn-1].avg); + if (buffered_str_changed(buffered_info[pn-1].avg, + flushed_info[pn-1].avg)) { + strcpy(sel + len, "avg"); + EM_ASM({elemSetContent($0, $1)}, sel, buffered_info[pn-1].avg); + } free_flushed_str(flushed_info[pn-1].name, buffered_info[pn-1].name); free_flushed_str(flushed_info[pn-1].rem, buffered_info[pn-1].rem); free_flushed_str(flushed_info[pn-1].sugg, buffered_info[pn-1].sugg); + free_flushed_str(flushed_info[pn-1].avg, buffered_info[pn-1].avg); + flushed_info[pn-1] = buffered_info[pn-1]; } @@ -144,7 +159,7 @@ void clear_player_info(int pn) void draw_visits() { - EM_ASM({clearVisits()}); + EM_ASM({elemSetContent($0, $1)}, "#visits", NULL); char visit_no[10], p1_pts[10], p1_rem[10], p2_pts[10], p2_rem[10], p2_darts[100]; |