From fcc02efbff337c05bf448231cd8bfbe016939f8a Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Thu, 28 Apr 2022 13:13:14 -0700 Subject: web: the bot should have his own dartboard --- web/static/dartboat.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'web/static/dartboat.js') diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 51570b4..98bbb37 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -23,10 +23,10 @@ function scheduleCCall(f, ms, ...args) { } function toCString(str) { // caller must free - const len = lengthBytesUTF8(str) + 1; - const cstr = _malloc(len); - stringToUTF8(str, cstr, len); - return cstr; + const size = lengthBytesUTF8(str) + 1; + const ptr = _malloc(size); + stringToUTF8(str, ptr, size); + return ptr; } function promptGet() { // caller must free @@ -64,8 +64,8 @@ function promptMsgR(ptr) { function setKeypad(keypad) { const keypad_id = `keypad-${UTF8ToString(keypad)}`; - $$('.keypad').forEach(e => { - e.style.display = e.id === keypad_id ? '' : 'none'; }); + $$('.keypad').forEach(e => + e.style.display = e.id === keypad_id ? '' : 'none'); } function isKeyActive(k) { @@ -119,13 +119,13 @@ function clearVisits() { const POINT_CLASSES = [180, 140, 100, 60, 40, 20, 0]; function drawVisit(visit_no, p1_pts, p1_rem, p2_pts, p2_rem, p2_darts) { - let e = $('#visits'); + const e = $('#visits'); - for (let [i, ptr] of [ + for (const [i, ptr] of [ p1_pts, p1_rem, visit_no, p2_rem, p2_pts, p2_darts].entries()) { - let div = e.appendChild(document.createElement('div')); - let v = div.textContent = UTF8ToString(ptr); + const div = e.appendChild(document.createElement('div')); + const v = div.textContent = UTF8ToString(ptr); div.classList.add(`visit-col${i+1}`); if (i == 0 || i == 4) div.classList.add(`p${POINT_CLASSES.find(x => x <= v)}`); @@ -161,6 +161,13 @@ function readOpts() { setOpt('stdev', val, false); } +function boatAfloat() { + if (document.readyState === 'loading') + document.addEventListener('DOMContentLoaded', () => _init()); + else + _init(); +} + document.addEventListener('DOMContentLoaded', () => { let f; @@ -173,7 +180,8 @@ document.addEventListener('DOMContentLoaded', () => { f = e => $(`#${e.target.dataset.modal}`).style.display = 'block'; $$('[data-modal]').forEach(x => x.addEventListener('click', f)); - f = e => e.target.style.display = 'none'; + f = e => { + if (e.target === e.currentTarget) e.target.style.display = 'none'; }; $$('.modal').forEach(x => x.addEventListener('click', f)); }); @@ -194,10 +202,3 @@ document.addEventListener('keydown', e => { else if (e.key == 'u') promptHandle('undo'); }); - -function boatAfloat() { - if (document.readyState === 'loading') - document.addEventListener('DOMContentLoaded', () => _init()); - else - _init(); -} -- cgit v1.2.3-70-g09d2