From e8592a80976919681d92a0d6ff89bae6d5fb992f Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 22 Apr 2022 15:17:01 -0700 Subject: handle web remaining state from c code --- web/static/dartboat.js | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'web/static/dartboat.js') diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 292c50d..2a26a0c 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -45,9 +45,9 @@ let prompt_handlers = { }, submit_rem() { - let pts = _promptGetAndClear(); - if (pts) - Module.ccall('user_visit', 'number', ['number'], [user_rem - pts]); + let rem = _promptGetAndClear(); + if (rem) + Module.ccall('user_visit_to_rem', 'number', ['number'], [rem]); } }, num_darts: { @@ -127,22 +127,12 @@ function clearOi() { } } -let user_rem; -function updateUserRem(rem) { - user_rem = rem; - updateUserStateRem(rem); +function updateUserStateRem(ptr) { + document.getElementById('p1-rem').textContent = UTF8ToString(ptr); } -function updateUserStateRem(rem) { - let elem = document.getElementById('p1-rem'); - elem.textContent = rem < 0 || rem == 1 ? 'BUST' : rem; - Module.ccall('get_suggested', null, ['number', 'number'], [rem, 1]); -} - -function updateBoatStateRem(rem) { - let elem = document.getElementById('p2-rem'); - elem.textContent = rem < 0 || rem == 1 ? 'BUST' : rem; - Module.ccall('get_suggested', null, ['number', 'number'], [rem, 2]); +function updateBoatStateRem(ptr) { + document.getElementById('p2-rem').textContent = UTF8ToString(ptr); } function updateUserName(p) { @@ -182,10 +172,7 @@ function promptSugg(p) { } function promptUpdateRem() { - let elem = document.getElementById('p1-rem'); - let pts = _promptGet(); - - updateUserStateRem(pts ? user_rem - pts : user_rem); + Module.ccall('update_user_rem_from_pts', null, ['number'], [_promptGet()]); } function setUserActive() { -- cgit v1.2.3-70-g09d2