diff options
Diffstat (limited to 'web/static/dartboat.js')
-rw-r--r-- | web/static/dartboat.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 015c541..c1a197a 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -1,5 +1,6 @@ let match_active = false; let prompt_disable = false; +let prompt_num_darts = false; let match_state, user_rem, boat_rem; let oi_timeout; let delay_ms = 1000; @@ -80,6 +81,14 @@ function updateBoatStateRem(rem) { Module.ccall('get_suggested', null, ['number', 'number'], [rem, 2]); } +function updateUserAvg(avg) { + document.getElementById('user-avg').textContent = avg.toFixed(2); +} + +function updateBoatAvg(avg) { + document.getElementById('boat-avg').textContent = avg.toFixed(2); +} + function promptUpdateRem() { let elem = document.getElementById('user-rem'); let pts = document.getElementById('prompt').textContent; @@ -100,7 +109,8 @@ function promptAppend(val) { let elem = document.getElementById('prompt'); if (elem.textContent.length < 3) { elem.textContent += val; - promptUpdateRem(); + if (!prompt_num_darts) + promptUpdateRem(); } } @@ -121,6 +131,11 @@ function promptBackspace() { promptUpdateRem(); } +function promptNumDarts() { + promptMsgStr('Darts needed?'); + prompt_num_darts = true; +} + function setBoatActive() { document.getElementById('user-state').className = ''; document.getElementById('boat-state').className = 'active'; @@ -147,6 +162,15 @@ function promptSubmit(remaining) { if (!p_user) return; promptClear(); + if (prompt_num_darts) { + if (!stcall('resp_numdarts', null, ['number'], [p_user])) { + oi(); + return; + } + prompt_num_darts = false; + return; + } + if (remaining) p_user = user_rem - p_user; @@ -165,7 +189,7 @@ function promptSubmit(remaining) { } } -function boatVisitRes(rem, n, p1, p2, p3, ptr1, ptr2, ptr3) { +function boatVisitRes(rem, n, p1, p2, p3, ptr1, ptr2, ptr3, avg) { // cannot convert in timeout func because strings are freed in c func let s1 = UTF8ToString(ptr1); let s2 = UTF8ToString(ptr2); @@ -173,6 +197,7 @@ function boatVisitRes(rem, n, p1, p2, p3, ptr1, ptr2, ptr3) { if (delay_ms == 0) { updateBoatRem(rem); + updateBoatAvg(avg); document.getElementById('match').textContent = ''; stcall('draw_match'); setUserActive(); @@ -189,6 +214,7 @@ function boatVisitRes(rem, n, p1, p2, p3, ptr1, ptr2, ptr3) { setTimeout(function() { updateBoatRem(rem); + updateBoatAvg(avg); document.getElementById('prompt').textContent = ''; document.getElementById('match').textContent = ''; stcall('draw_match'); |