From 39b76b0e432077f9777e66bb1e4d3486db5edbf0 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 23 Apr 2022 00:28:21 -0700 Subject: use common functions for updating player states --- web/static/dartboat.js | 48 +++++++++++------------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) (limited to 'web/static/dartboat.js') diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 0014d3a..a47b845 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -127,36 +127,25 @@ function clearOi() { } } -function updateUserStateRem(ptr) { - document.getElementById('p1-rem').textContent = UTF8ToString(ptr); +function setPlayerActive(n) { + document.querySelectorAll('[id$=-state]').forEach(e => + e.classList[n && e.id == `p${n}-state` ? 'add' : 'remove']('active')); } -function updateBoatStateRem(ptr) { - document.getElementById('p2-rem').textContent = UTF8ToString(ptr); +function updatePlayerRem(n, ptr) { + document.getElementById(`p${n}-rem`).textContent = UTF8ToString(ptr); } -function updateUserName(p) { - document.getElementById('p1-name').textContent = UTF8ToString(p); +function updatePlayerName(n, ptr) { + document.getElementById(`p${n}-name`).textContent = UTF8ToString(ptr); } -function updateBoatName(p) { - document.getElementById('p2-name').textContent = UTF8ToString(p); +function updatePlayerSugg(n, ptr) { + document.getElementById(`p${n}-sugg`).textContent = UTF8ToString(ptr); } -function userSugg(p) { - document.getElementById('p1-sugg').textContent = UTF8ToString(p); -} - -function boatSugg(p) { - document.getElementById('p2-sugg').textContent = UTF8ToString(p); -} - -function updateUserAvg(avg) { - document.getElementById('p1-avg').textContent = avg.toFixed(2); -} - -function updateBoatAvg(avg) { - document.getElementById('p2-avg').textContent = avg.toFixed(2); +function updatePlayerAvg(n, avg) { + document.getElementById(`p${n}-avg`).textContent = avg.toFixed(2); } function setPromptText(ptr) { @@ -175,21 +164,6 @@ function promptUpdateRem() { Module.ccall('update_user_rem_from_pts', null, ['number'], [_promptGet()]); } -function setUserActive() { - document.getElementById('p2-state').classList.remove('active'); - document.getElementById('p1-state').classList.add('active'); -} - -function setBoatActive() { - document.getElementById('p1-state').classList.remove('active'); - document.getElementById('p2-state').classList.add('active'); -} - -function setNoneActive() { - document.getElementById('p1-state').classList.remove('active'); - document.getElementById('p2-state').classList.remove('active'); -} - function scheduleCCall(f, ms, ...args) { let types = []; let vals = []; -- cgit v1.2.3-70-g09d2