diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-23 00:28:21 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-23 00:28:21 -0700 |
commit | 39b76b0e432077f9777e66bb1e4d3486db5edbf0 (patch) | |
tree | cdd018df9f67924bb7b2fe6f31589f3d953936cc /web/static | |
parent | 07f0616f88553e0a4b3a5c23b0024e78d94d9d7e (diff) | |
download | dartboat-39b76b0e432077f9777e66bb1e4d3486db5edbf0.tar.gz dartboat-39b76b0e432077f9777e66bb1e4d3486db5edbf0.tar.xz |
use common functions for updating player states
Diffstat (limited to 'web/static')
-rw-r--r-- | web/static/dartboat.js | 48 |
1 files changed, 11 insertions, 37 deletions
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 = []; |