summaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2024-07-07 18:31:39 -0500
committersanine <sanine.not@pm.me>2024-07-07 18:31:39 -0500
commit2c31a91ba27ea48c5db4a06be82476d26d642c7d (patch)
tree51442315c9d36e175a70fe1437ecc00cf82f0089 /main.js
parent95ee8172ae99c00efbfb1c8c105112f82711ae01 (diff)
parentc6c473e03c7b9a993ccaf28bcff2d87fbdf9c931 (diff)
add level intro messages & mergemain
Diffstat (limited to 'main.js')
-rw-r--r--main.js91
1 files changed, 82 insertions, 9 deletions
diff --git a/main.js b/main.js
index 44a0fe3..6b5edc1 100644
--- a/main.js
+++ b/main.js
@@ -27,6 +27,16 @@ window.onload = () => setTimeout(() => {
start.type = 'button';
start.value = 'connect to AMH';
start.onclick = () => {
+ // set up fullscreen
+ document.documentElement.requestFullscreen({ navigationUI: 'hide' });
+ document.getElementById('fullscreen-toggle').onclick = () => {
+ if (document.fullscreenElement === null) {
+ document.documentElement.requestFullscreen({ navigationUI: 'hide' });
+ } else {
+ document.exitFullscreen();
+ }
+ }
+
root.classList.remove('center');
root.innerText = '';
const audio = new AudioContext();
@@ -55,21 +65,22 @@ window.onload = () => setTimeout(() => {
musicList[0].element.play();
const sfx = {};
+ const sfxGain = audio.createGain();
sfx.buttonEnterAudio = document.getElementById('sfx-buttonenter');
sfx.buttonClickAudio = document.getElementById('sfx-buttonclick');
sfx.listAppearAudio = document.getElementById('sfx-listappear');
- audio.createMediaElementSource(sfx.buttonEnterAudio).connect(audio.destination);
- audio.createMediaElementSource(sfx.buttonClickAudio).connect(audio.destination);
- audio.createMediaElementSource(sfx.listAppearAudio).connect(audio.destination);
+ audio.createMediaElementSource(sfx.buttonEnterAudio).connect(sfxGain).connect(audio.destination);
+ audio.createMediaElementSource(sfx.buttonClickAudio).connect(sfxGain).connect(audio.destination);
+ audio.createMediaElementSource(sfx.listAppearAudio).connect(sfxGain).connect(audio.destination);
sfx.resourceAudio = document.getElementById('sfx-resource');
- audio.createMediaElementSource(sfx.resourceAudio).connect(audio.destination);
+ audio.createMediaElementSource(sfx.resourceAudio).connect(sfxGain).connect(audio.destination);
sfx.doneAudio = document.getElementById('sfx-done');
- audio.createMediaElementSource(sfx.doneAudio).connect(audio.destination);
+ audio.createMediaElementSource(sfx.doneAudio).connect(sfxGain).connect(audio.destination);
sfx.wrongAudio = document.getElementById('sfx-wrong');
- audio.createMediaElementSource(sfx.wrongAudio).connect(audio.destination);
+ audio.createMediaElementSource(sfx.wrongAudio).connect(sfxGain).connect(audio.destination);
// const level = setupLevel([[2, 2], [3,3]], [7, 7]);
// const ui = setupLevelUi(level, root, audio);
@@ -77,9 +88,71 @@ window.onload = () => setTimeout(() => {
Promise.all([...Object.values(sfx)].map(x => new Promise(resolve => {
x.load();
x.addEventListener('canplaythrough', resolve, false);
- }))).then(
- () => setupLevelSelectUi(root, sfx)
- );
+ }))).then(() => {
+ sfx.gain = sfxGain;
+ document.getElementById('sound-controls').onclick = () => showSoundControls(root, sfx, musicGain);
+ setupLevelSelectUi(root, sfx)
+ });
};
root.appendChild(start);
}, 200);
+
+
+function showSoundControls(root, sfx, musicGain) {
+ const div = document.createElement('div');
+ div.classList.add('center-screen-container');
+ const div2 = document.createElement('div');
+ div2.classList.add('center-screen');
+ div.appendChild(div2);
+ const p = document.createElement('p');
+ p.classList.add('alert-box');
+ p.innerText = 'sound settings';
+ div2.appendChild(p);
+ root.appendChild(div);
+
+ const musicLabel = document.createElement('label');
+ musicLabel.innerText = 'music:';
+ const musicRange = document.createElement('input');
+ musicRange.type = 'range';
+ musicRange.min = 0;
+ musicRange.max = 1;
+ musicRange.step = 0.1;
+ musicRange.value = 2*musicGain.gain.value;
+ musicRange.onchange = e => {
+ musicGain.gain.value = 0.5*e.target.value;
+ }
+ p.appendChild(document.createElement('br'));
+ p.appendChild(musicLabel);
+ p.appendChild(musicRange);
+
+ const sfxLabel = document.createElement('label');
+ sfxLabel.innerText = 'sfx:';
+ const sfxRange = document.createElement('input');
+ sfxRange.type = 'range';
+ sfxRange.min = 0;
+ sfxRange.max = 1;
+ sfxRange.step = 0.1;
+ sfxRange.value = sfx.gain.gain.value;
+ sfxRange.onchange = e => {
+ sfx.gain.gain.value = e.target.value;
+ }
+ p.appendChild(document.createElement('br'));
+ p.appendChild(sfxLabel);
+ p.appendChild(sfxRange);
+
+
+ const button = document.createElement('input');
+ button.type = 'button';
+ button.value = 'OK';
+ button.onmouseenter = () => {
+ sfx.buttonEnterAudio.currentTime = 0;
+ sfx.buttonEnterAudio.play();
+ }
+ button.onclick = () => {
+ sfx.buttonClickAudio.currentTime = 0;
+ sfx.buttonClickAudio.play();
+ root.removeChild(div);
+ }
+ p.appendChild(document.createElement('br'));
+ p.appendChild(button);
+}