From e3afbd56399e12beb37246a879dcf817de9b4ca1 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 23 Apr 2022 21:36:10 -0700 Subject: web: allow undo for complete matches --- web/dartboat_wasm.c | 12 +++++++++--- 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: { -- cgit v1.2.3-70-g09d2