diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-23 21:36:10 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-23 21:36:10 -0700 |
commit | e3afbd56399e12beb37246a879dcf817de9b4ca1 (patch) | |
tree | 42d6492064a411450a1cf9ecea4aca0593d8a71d | |
parent | e2fe11469394c9827a0cdea9966188c833d93197 (diff) | |
download | dartboat-e3afbd56399e12beb37246a879dcf817de9b4ca1.tar.gz dartboat-e3afbd56399e12beb37246a879dcf817de9b4ca1.tar.xz |
web: allow undo for complete matches
-rw-r--r-- | web/dartboat_wasm.c | 12 | ||||
-rw-r--r-- | web/static/dartboat.js | 11 |
2 files changed, 20 insertions, 3 deletions
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c index 006ec1e..5aa38bc 100644 --- a/web/dartboat_wasm.c +++ b/web/dartboat_wasm.c @@ -274,13 +274,17 @@ EMSCRIPTEN_KEEPALIVE bool user_undo() { return false; } - if (state->mode == M_PVP) - switch_active_user(); + if (state->mode == M_PVP) { + if (is_match_over()) + EM_ASM({setPlayerActive($0)}, state->active_p); + else + switch_active_user(); + } struct leg *l = state->active_l; struct visit *v = l->visits + --l->n_visits; l->rem += v->points; - if (state->mode == M_PVC) { + if (state->mode == M_PVC && state->l2->n_visits > l->n_visits) { state->l2->rem += state->l2->visits[--state->l2->n_visits].points; ++state->undone_count; } @@ -297,6 +301,8 @@ EMSCRIPTEN_KEEPALIVE bool user_undo() { memcpy(v, 0, sizeof(*v)); EM_ASM({clearVisits()}); + EM_ASM({promptMsgR($0)}, ""); + EM_ASM({setPromptHandler($0)}, "visit"); draw_match(); return true; diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 016742b..358446a 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -125,9 +125,20 @@ let prompt_handlers = { }, match_over: { + undo() { + let cl = document.getElementById('key_undo').classList; + if (cl.contains('active')) + Module.ccall('user_undo'); + cl.toggle('active'); + }, + submit() { Module.ccall('match_init'); }, + + pre(action) { + clearOi(); + } }, init: { |