mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-19 01:24:26 +00:00
* Add the initial support for settings * Rearrange init order for the settings and log modules * Add import settings function * Add initial settings display panel * Add settings controls * Add settings controls handlers * Add garbage gui auto-builder for settings * Add some custom binding handlers for settings * Add super ineffective ¯\_(ツ)_/¯ keyboard bindings remap function * Migrate keyboard to codes instead deprecated keyCodes * Abort key remap on Esc Co-authored-by: Sergey Stepanov <sergystepanov@gmail.com>
63 lines
1.4 KiB
JavaScript
Vendored
63 lines
1.4 KiB
JavaScript
Vendored
/**
|
|
* App UI elements module.
|
|
*
|
|
* @version 1
|
|
*/
|
|
const gui = (() => {
|
|
|
|
const _create = (name = 'div') => document.createElement(name);
|
|
|
|
const _option = (text = '', selected = false) => {
|
|
const el = _create('option');
|
|
el.textContent = text;
|
|
if (selected) el.selected = true;
|
|
|
|
return el;
|
|
}
|
|
|
|
const select = (key = '', callback = function () {
|
|
}, values = [], current = '') => {
|
|
const el = _create();
|
|
const select = _create('select');
|
|
select.onchange = event => {
|
|
callback(key, event.target.value);
|
|
};
|
|
el.append(select);
|
|
|
|
select.append(_option('none', current === ''));
|
|
for (let value of values) select.append(_option(value, current === value));
|
|
|
|
return el;
|
|
}
|
|
|
|
const _bind = (callback = function () {
|
|
}, name = '', oldValue) => {
|
|
const el = _create('button');
|
|
el.onclick = () => callback(name, oldValue);
|
|
|
|
el.textContent = name;
|
|
|
|
return el;
|
|
}
|
|
|
|
const binding = (key = '', value = '', callback = function () {
|
|
}) => {
|
|
const el = _create();
|
|
el.setAttribute('class', 'binding-element');
|
|
|
|
const k = _bind(callback, key, value);
|
|
|
|
el.append(k);
|
|
|
|
const v = _create();
|
|
v.textContent = value;
|
|
el.append(v);
|
|
|
|
return el;
|
|
}
|
|
|
|
return {
|
|
select,
|
|
binding,
|
|
}
|
|
})(document);
|