summaryrefslogtreecommitdiff
path: root/web/static/dartboat.js
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-22 15:17:01 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-22 15:17:01 -0700
commite8592a80976919681d92a0d6ff89bae6d5fb992f (patch)
treecdd8390891637b5802f6c75dfaef85205555a298 /web/static/dartboat.js
parentbd54e83d6e21f9eaab830095663a7ddad4c70c5c (diff)
downloaddartboat-e8592a80976919681d92a0d6ff89bae6d5fb992f.tar.gz
dartboat-e8592a80976919681d92a0d6ff89bae6d5fb992f.tar.xz
handle web remaining state from c code
Diffstat (limited to 'web/static/dartboat.js')
-rw-r--r--web/static/dartboat.js29
1 files changed, 8 insertions, 21 deletions
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() {