if(stored) {
let merge = (source, target) => {
for(let k of Object.keys(source)) {
- if(typeof(source[k]) == 'object' && typeof(target[k]) == 'object') {
+ if(typeof(source[k]) == 'object' && typeof(target[k]) == 'object' && !Array.isArray(target[k])) {
merge(source[k], target[k]);
} else if(k in target) {
target[k] = source[k];
case 'ArrowRight': return '🠖';
case 'ArrowDown': return '🠗';
case 'ArrowLeft': return '🠔';
+ case ' ': return 'Space';
default: return k;
}
});
}
});
});
+game.ui.root.querySelectorAll('.options .keyboard label button').forEach((btn) => {
+ btn.addEventListener('click', () => {
+ if(game.ui.root.querySelector('.ui-page.keyboard-modal')) {
+ return;
+ }
+ const keyboardModal = document.createElement('div');
+ keyboardModal.classList.add('ui-page', 'keyboard-modal');
+ const instruction = document.createElement('span');
+ const direction = btn.classList[0];
+ keyboardModal.classList.add(direction);
+ instruction.innerText = 'Please press the key for “' + direction[0].toUpperCase() + direction.slice(1) + '”';
+ keyboardModal.appendChild(instruction);
+ game.ui.root.appendChild(keyboardModal);
+ });
+});
game.ui.root.querySelector('.options .keyboard button[value="reset"]').addEventListener('click', applySettings(game));
game.ui.root.querySelectorAll('.ui-page .areatabs button').forEach((btn) => {
btn.addEventListener('click', (e) => {
}
});
document.addEventListener('keydown', (e) => {
+ const keyboardModal = game.ui.root.querySelector('.keyboard-modal');
+ if(keyboardModal) {
+ const direction = [...keyboardModal.classList].filter(c => c != 'ui-page' && c != 'keyboard-modal')[0];
+ if(e.key != 'Escape') {
+ game.ui.root.querySelector('.options .keyboard label button.' + direction).value = e.key;
+ applySettings(game);
+ loadSettings(game);
+ }
+ keyboardModal.remove();
+ e.preventDefault();
+ e.stopPropagation();
+ return;
+ }
if(e.key == 'Escape') {
if(game.ui.currentPage == 'gameplay') {
game.ui.moveToPage('pause', true);