diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-04 01:59:39 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-04 01:59:39 -0700 |
commit | 3492c24cc533e9088e8b12f929f5d922c8787cba (patch) | |
tree | 32565b49bd46ff1e2d2ae6954240593ac4a5427c /web/static | |
parent | 2709b070c5fde766c0e9fe98ade169a865e6c9ad (diff) | |
download | dartboat-3492c24cc533e9088e8b12f929f5d922c8787cba.tar.gz dartboat-3492c24cc533e9088e8b12f929f5d922c8787cba.tar.xz |
web: move opt logic to c
Diffstat (limited to 'web/static')
-rw-r--r-- | web/static/dartboat.js | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js index eaf76da..70e4677 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -7,6 +7,8 @@ function scheduleCCall(f, ms, ...args) { } function toCString(str) { // caller must free + if (!str) return 0; + const size = lengthBytesUTF8(str) + 1; const ptr = _malloc(size); stringToUTF8(str, ptr, size); @@ -90,21 +92,12 @@ function promptHandle(command, data) { if (str_d) _free(str_d); } -function setOpt(opt, val, update_opts = true) { - if (update_opts) localStorage.setItem(`dartboat_${opt}`, val); - - if (opt === 'delay' || opt === 'stdev') - Module[`_set_${opt}`](Number(val)); +function readOpt(opt) { // caller must free + return toCString(localStorage.getItem(UTF8ToString(opt))); } -function readOpts() { - let val; - - if ((val = localStorage.getItem('dartboat_delay'))) - setOpt('delay', val, false); - - if ((val = localStorage.getItem('dartboat_stdev'))) - setOpt('stdev', val, false); +function storeOpt(opt, val) { + localStorage.setItem(UTF8ToString(opt), UTF8ToString(val)); } function boatAfloat() { @@ -121,7 +114,8 @@ document.addEventListener('DOMContentLoaded', () => { promptHandle(...x.split(':', 2))); $$('[data-command]').forEach(x => x.addEventListener('click', f)); - f = e => setOpt(e.target.dataset.setting, e.target.value); + f = e => _set_opt(toCString(e.target.dataset.setting), + toCString(e.target.value)); $$('[data-setting]').forEach(x => x.addEventListener('change', f)); f = e => $(`#${e.target.dataset.modal}`).style.display = 'block'; |