Up-in-the-Air – commitdiff

You can use Git to clone the repository via the web URL. Download snapshot (zip)
More stuff respects the settings now
authorJulian Fietkau <git@fietkau.software>
Tue, 24 Sep 2024 12:32:03 +0000 (14:32 +0200)
committerJulian Fietkau <git@fietkau.software>
Tue, 24 Sep 2024 12:32:03 +0000 (14:32 +0200)
main.js

diff --git a/main.js b/main.js
index 7d7314c20a0117a5507b8d44f05c100e54da289b..b2ce2a3451382f4ab81807bb7ca0bcca1a6f5df5 100644 (file)
--- a/main.js
+++ b/main.js
@@ -710,6 +710,7 @@ function applySettings(game) {
   }
   game.settings['keyboard']['tapmode'] = ui.querySelector('input[value="tapmode"]').checked;
   window['localStorage'].setItem('upInTheAirGameSettings', JSON.stringify(game.settings));
+
   for(let audioCategory of ['music', 'sounds']) {
     game.settings['audio'][audioCategory] = parseInt(ui.querySelector('.audio input[type=range].' + audioCategory).value, 10) / 100;
     let value = Math.round(100 * game.settings['audio'][audioCategory]);
@@ -717,10 +718,14 @@ function applySettings(game) {
       elem.value = value;
       elem.parentNode.nextElementSibling.innerText = value;
     });
-    if(audioCategory == 'music') {
+    if(audioCategory == 'music' && game.view) {
       game.view.music.setVolume(game.settings['audio'][audioCategory]);
     }
   }
+  game.ui.root.classList.remove('font-atkinson', 'font-opendyslexic');
+  if(game.settings['font'] != 'standard') {
+    game.ui.root.classList.add('font-' + game.settings['font']);
+  }
 }
 
 window['game'] = {
@@ -740,12 +745,15 @@ game.ui.root.querySelectorAll('button.goto').forEach((btn) => {
       game.view.camera.add(audioListener);
       game.view.music = new THREE.Audio(audioListener);
       game.view.music.setBuffer(game.assets.audio.music);
-      game.view.music.setVolume(0.5);
+      game.view.music.setVolume(game.settings['audio']['music']);
     }
     let target = e.target.closest('button');
     game.ui.moveToPage(Array.from(target.classList).filter(c => c != 'goto')[0]);
   });
 });
+game.ui.root.querySelectorAll('.options .controls input, .options .graphics input, .options .feather input, .options .accessibility input').forEach((radioOrCb) => {
+  radioOrCb.addEventListener('change', () => applySettings(game));
+});
 game.ui.root.querySelectorAll('.ui-page .audio input[type=range]').forEach((elem) => {
   elem.addEventListener('input', (e) => {
     let audioCategory = Array.from(e.target.classList).filter(v => ['music', 'sounds'].includes(v))[0];
@@ -772,26 +780,11 @@ game.ui.root.querySelectorAll('.options .audio button').forEach((btn) => {
     }
   });
 });
-function checkFontSelection() {
-  const checked = document.querySelector('input[name=upInTheAirGame-font]:checked');
-  if(!checked) {
-    return;
-  }
-  const newFont = checked.value;
-  game.ui.root.classList.remove('font-atkinson', 'font-opendyslexic');
-  if(newFont != 'standard') {
-    game.ui.root.classList.add('font-' + newFont);
-  }
-}
-checkFontSelection();
-game.ui.root.querySelectorAll('.options input[name=upInTheAirGame-font]').forEach((radio) => {
-  radio.addEventListener('change', e => checkFontSelection());
-});
 game.ui.root.querySelectorAll('.options .controls input').forEach((radio) => {
-  radio.addEventListener('change', (e) => {
-    e.target.closest('.controls').querySelectorAll('span:not(.' + e.target.value + ')').forEach(span => span.style.display = 'none');
-    e.target.closest('.controls').querySelector('span.' + e.target.value).style.display = 'block';
-  });
+  radio.addEventListener('change', () => applySettings(game));
+});
+game.ui.root.querySelectorAll('.options input[name=upInTheAirGame-font]').forEach((radio) => {
+  radio.addEventListener('change', () => applySettings(game));
 });
 game.ui.root.querySelectorAll('.ui-page .areatabs button').forEach((btn) => {
   btn.addEventListener('click', (e) => {