summaryrefslogtreecommitdiff
path: root/web/web_scoreboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/web_scoreboard.c')
-rw-r--r--web/web_scoreboard.c124
1 files changed, 63 insertions, 61 deletions
diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c
index 1d28cbf..f5afcc5 100644
--- a/web/web_scoreboard.c
+++ b/web/web_scoreboard.c
@@ -27,7 +27,7 @@ void scoreboard_set_player_active(int pn)
else
sprintf(sel, "#p%d-info", pn);
- dom_elem_set_uniq_class(psel, "active", "[id$=-info]");
+ dom_set_uniq_class(psel, "active", "[id$=-info]");
}
static inline void buffer_str(char *str, char **buffer, char *flushed)
@@ -83,25 +83,25 @@ void scoreboard_flush_player_info(int pn)
if (buffered_str_changed(buffered_info[pn-1].name,
flushed_info[pn-1].name)) {
strcpy(sel + len, "name");
- dom_elem_set_content(sel, buffered_info[pn-1].name);
+ dom_set_content(sel, buffered_info[pn-1].name);
}
if (buffered_str_changed(buffered_info[pn-1].rem,
flushed_info[pn-1].rem)) {
strcpy(sel + len, "rem");
- dom_elem_set_content(sel, buffered_info[pn-1].rem);
+ dom_set_content(sel, buffered_info[pn-1].rem);
}
if (buffered_str_changed(buffered_info[pn-1].sugg,
flushed_info[pn-1].sugg)) {
strcpy(sel + len, "sugg");
- dom_elem_set_content(sel, buffered_info[pn-1].sugg);
+ dom_set_content(sel, buffered_info[pn-1].sugg);
}
if (buffered_str_changed(buffered_info[pn-1].avg,
flushed_info[pn-1].avg)) {
strcpy(sel + len, "avg");
- dom_elem_set_content(sel, buffered_info[pn-1].avg);
+ dom_set_content(sel, buffered_info[pn-1].avg);
}
free_flushed_str(flushed_info[pn-1].name, buffered_info[pn-1].name);
@@ -172,7 +172,7 @@ void show_player_info(int pn)
{
char sel[64];
sprintf(sel, "#p%d-info-inner", pn);
- dom_elem_add_class(sel, "visible");
+ dom_add_class(sel, "visible");
}
void clear_player_info(int pn)
@@ -183,83 +183,85 @@ void clear_player_info(int pn)
scoreboard_set_player_avg(pn, 0);
}
-struct elem *gen_div(char *str, char *class)
+static struct dom_elem *create_div(char *str, char *class)
{
- struct elem *e = elem_init(NULL, "div", 1);
+ struct dom_elem *e = dom_elem_init(NULL, "div", 1);
e->content = strdup(str);
- elem_add_attr(e, "class", class);
+ dom_elem_add_attr(e, "class", class);
return e;
}
-void add_colour_class(char *buf, int pts)
+static const char *points_class(int pts)
{
- if (pts >= 180)
- strcat(buf, " p180");
- else if (pts >= 140)
- strcat(buf, " p140");
- else if (pts >= 100)
- strcat(buf, " p100");
- else if (pts >= 60)
- strcat(buf, " p60");
- else if (pts >= 40)
- strcat(buf, " p40");
- else if (pts >= 20)
- strcat(buf, " p20");
- else
- strcat(buf, " p0");
+ return (pts >= 180) ? "p180" :
+ (pts >= 140) ? "p140" :
+ (pts >= 100) ? "p100" :
+ (pts >= 60) ? "p60" :
+ (pts >= 40) ? "p40" :
+ (pts >= 20) ? "p20" :
+ "p0";
}
void draw_visits()
{
- dom_elem_set_content("#visits", NULL);
+ dom_set_content("#visits", NULL);
int n_visits = state->legs[0]->n_visits > state->legs[1]->n_visits ?
state->legs[0]->n_visits : state->legs[1]->n_visits;
- struct elem **elemv = malloc(6 * n_visits * sizeof(*elemv));
+ struct dom_elem **elemv = malloc(6 * n_visits * sizeof(*elemv));
int elemc = 0;
+ char buf[32], buf2[32];
+ snprintf(buf, sizeof(buf), "%d", state->legs[0]->start);
+ elemv[elemc++] = create_div(buf, "visit-col2");
+ elemv[elemc++] = create_div("0", "visit-col3");
+ if (state->mode != M_P) {
+ snprintf(buf, sizeof(buf), "%d", state->legs[1]->start);
+ elemv[elemc++] = create_div(buf, "visit-col4");
+ }
+
for (int i = 0; i < n_visits; ++i) {
- char buf[32], buf2[32];
struct visit *v = state->legs[0]->visits + i;
- sprintf(buf, "%d", v->points);
- strcpy(buf2, "visit-col1");
- add_colour_class(buf2, v->points);
- elemv[elemc++] = gen_div(buf, buf2);
- sprintf(buf, "%d", v->rem);
- elemv[elemc++] = gen_div(buf, "visit-col2");
-
- sprintf(buf, "%d", i + 1);
- elemv[elemc++] = gen_div(buf, "visit-col3");
-
- if (i < state->legs[1]->n_visits) {
- v = state->legs[1]->visits + i;
- sprintf(buf, "%d", v->rem);
- elemv[elemc++] = gen_div(buf, "visit-col4");
- sprintf(buf, "%d", v->points);
- strcpy(buf2, "visit-col5");
- add_colour_class(buf2, v->points);
- elemv[elemc++] = gen_div(buf, buf2);
-
- strcpy(buf, "… ");
- for (int j = 0; j < v->n_darts; ++j) {
- char *n = segment_name(v->darts[j]);
- sprintf(buf + strlen(buf),
- j == 0 ? "%4s" : " %4s", n); // FIXME
- free(n);
- }
- elemv[elemc++] = gen_div(buf, "visit-col6");
- } else {
- elemv[elemc++] = gen_div("", "visit-col4");
- elemv[elemc++] = gen_div("", "visit-col5");
- elemv[elemc++] = gen_div("", "visit-col6");
+
+ snprintf(buf, sizeof(buf), "%d", v->points);
+ snprintf(buf2, sizeof(buf2), "%s %s",
+ "visit-col1", points_class(v->points));
+ elemv[elemc++] = create_div(buf, buf2);
+
+ snprintf(buf, sizeof(buf), "%d", v->rem);
+ elemv[elemc++] = create_div(buf, "visit-col2");
+
+ snprintf(buf, sizeof(buf), "%d", i + 1);
+ elemv[elemc++] = create_div(buf, "visit-col3");
+
+ if (i >= state->legs[1]->n_visits)
+ continue;
+ v = state->legs[1]->visits + i;
+
+ snprintf(buf, sizeof(buf), "%d", v->rem);
+ elemv[elemc++] = create_div(buf, "visit-col4");
+
+ snprintf(buf, sizeof(buf), "%d", v->points);
+ snprintf(buf2, sizeof(buf2), "%s %s",
+ "visit-col5", points_class(v->points));
+ elemv[elemc++] = create_div(buf, buf2);
+
+ char *pbuf = stpcpy(buf, "…");
+ for (int j = 0; j < v->n_darts; ++j) {
+ char *n = segment_name(v->darts[j]);
+ snprintf(pbuf + (j * 5),
+ sizeof(buf) - (pbuf + (j * 5) - buf),
+ " %4s", n);
+ free(n);
}
+ elemv[elemc++] = create_div(buf, "visit-col6");
}
- append_elemv("#visits", elemc, elemv);
+ dom_append_elemv("#visits", elemc, elemv);
for (int i = 0; i < elemc; ++i)
- elem_free(elemv[i]);
+ dom_elem_free(elemv[i]);
free(elemv);
- dom_elem_scroll_to_bottom("#visits");
+ dom_scroll_to_bottom("#visits");
}