diff options
Diffstat (limited to 'web/static')
-rw-r--r-- | web/static/dartboat.js | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 2a26a0c..0014d3a 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -190,20 +190,16 @@ function setNoneActive() { document.getElementById('p2-state').classList.remove('active'); } -function scheduleBoatThrowing(pts, ptr, delay_ms) { - // ptr to c string must be copied before returning - let str = UTF8ToString(ptr); - setTimeout( - function() { Module.ccall('draw_boat_throwing', null, - ['number', 'string'], [pts, str]) }, - delay_ms); -} +function scheduleCCall(f, ms, ...args) { + let types = []; + let vals = []; + + for (let i = 0; i < args.length/2; i++) + vals[i] = (types[i] = UTF8ToString(args[i*2])) == 'string' ? + UTF8ToString(args[i*2+1]) : args[i*2+1]; -function scheduleEndBoatThrowing(rem, avg, delay_ms) { - setTimeout( - function() { Module.ccall('end_boat_throwing', null, - ['number', 'number'], [rem, avg]) }, - delay_ms); + let func = UTF8ToString(f); + setTimeout(function() { Module.ccall(func, null, types, vals) }, ms); } const POINT_CLASSES = [180, 140, 100, 60, 40, 20, 1, 0]; @@ -213,11 +209,10 @@ function drawVisit(visit_no, u_pts, u_rem, b_pts, b_rem, b_darts) { for (let [i, ptr] of [u_pts, u_rem, visit_no, b_rem, b_pts, b_darts].entries()) { let div = document.createElement('div'); let v = div.textContent = UTF8ToString(ptr); - if (i == 0 || i == 4) { + if (i == 0 || i == 4) div.className = `p${POINT_CLASSES.find(x => x <= v)}`; - } else if (i == 5) { - if (v) div.textContent = `… ${v}`; - } + else if (i == 5 && v) + div.textContent = `… ${v}`; div.className += ` visit-col${i+1}`; elem.append(div); } |