From d31b800c35595428790905b21b771bbc187488ab Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 23 Apr 2022 17:53:11 -0700 Subject: web: fix undo state carrying over into next match --- web/dartboat_wasm.c | 11 +++++------ web/static/index.html | 2 +- web/static/style.css | 4 +++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c index e624c67..9c838bd 100644 --- a/web/dartboat_wasm.c +++ b/web/dartboat_wasm.c @@ -17,11 +17,10 @@ int delay_ms = 1000; struct match_state { struct leg *l1, *l2; + int undone_count; int complete; }; -int undone_count = 0; - struct match_state *state; void set_user_active() { @@ -166,8 +165,8 @@ EMSCRIPTEN_KEEPALIVE void boat_visit() { EM_ASM({promptMsgL($0)}, "Bot is throwing…"); struct leg *l = state->l2; - if (undone_count) { - --undone_count; + if (state->undone_count) { + --state->undone_count; l->rem = l->visits[l->n_visits++].rem; } else { comp_visit(l); @@ -253,7 +252,7 @@ EMSCRIPTEN_KEEPALIVE bool user_undo() { struct visit *v = l->visits + --l->n_visits; l->rem += v->points; state->l2->rem += state->l2->visits[--state->l2->n_visits].points; - ++undone_count; + ++state->undone_count; EM_ASM({updatePlayerAvg($0, $1)}, P_USER, l->n_visits ? (double)(l->start-l->rem)/l->n_visits : 0); @@ -325,7 +324,7 @@ void init_boat() { EMSCRIPTEN_KEEPALIVE void free_match() { leg_free(state->l1); - state->l2->n_visits += undone_count; // FIXME messy way to avoid memory leak + state->l2->n_visits += state->undone_count; // FIXME messy way to avoid memory leak leg_free(state->l2); free(state); state = NULL; diff --git a/web/static/index.html b/web/static/index.html index d2d6bb4..dbd2b6e 100644 --- a/web/static/index.html +++ b/web/static/index.html @@ -44,7 +44,7 @@
0
OK
UNDO
-
REM
+
REMAINING
dartboat™
diff --git a/web/static/style.css b/web/static/style.css index b644439..397d5f8 100644 --- a/web/static/style.css +++ b/web/static/style.css @@ -40,7 +40,7 @@ div#oi { visibility: hidden; background-color: #6c0d0d; - font-size: 2em; + font-size: 3em; height: 1.2em; width: 3ch; @@ -190,6 +190,8 @@ div.key.num { div.key.ok { grid-row-end: span 2; + + font-size: 2.5em; } div#settings-bar { -- cgit v1.2.3-70-g09d2