summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2024-07-06 22:17:20 -0500
committersanine <sanine.not@pm.me>2024-07-06 22:17:20 -0500
commitfdfa8561fbc884418bffa424876eb0e4e6756ecc (patch)
tree3212137f14a734c83c4bb0b528e465dd0b9e4b3b
parent909a3c49fb48361b65dceb437b4182380d3b8277 (diff)
fix audio loading
-rw-r--r--levelSelect.js4
-rw-r--r--main.js14
2 files changed, 9 insertions, 9 deletions
diff --git a/levelSelect.js b/levelSelect.js
index 30285e7..9837a05 100644
--- a/levelSelect.js
+++ b/levelSelect.js
@@ -44,6 +44,8 @@ export function setupLevelSelectUi(root, sfx) {
const [ dependencies, level ] = levels[name];
const allDependenciesSatisfied = dependencies.map(x => levels[x][1].completed).reduce((acc, x) => acc && x, true);
if (allDependenciesSatisfied) {
+ sfx.listAppearAudio.currentTime = 0;
+ sfx.listAppearAudio.play();
// if (true) {
const button = document.createElement('input');
button.type = 'button';
@@ -70,8 +72,6 @@ export function setupLevelSelectUi(root, sfx) {
let time = 0;
[...Object.keys(levels)].forEach(name => {
setTimeout(() => {
- sfx.listAppearAudio.currentTime = 0;
- sfx.listAppearAudio.play();
levelPicker(name);
}, 100 * time + 100)
time += 1;
diff --git a/main.js b/main.js
index 94d5e77..e41a89a 100644
--- a/main.js
+++ b/main.js
@@ -63,20 +63,20 @@ window.onload = () => setTimeout(() => {
audio.createMediaElementSource(sfx.listAppearAudio).connect(audio.destination);
sfx.resourceAudio = document.getElementById('sfx-resource');
- sfx.resourceSource = audio.createMediaElementSource(sfx.resourceAudio);
- sfx.resourceSource.connect(audio.destination);
+ audio.createMediaElementSource(sfx.resourceAudio).connect(audio.destination);
sfx.doneAudio = document.getElementById('sfx-done');
- sfx.doneSource = audio.createMediaElementSource(sfx.doneAudio);
- sfx.doneSource.connect(audio.destination);
+ audio.createMediaElementSource(sfx.doneAudio).connect(audio.destination);
sfx.wrongAudio = document.getElementById('sfx-wrong');
- sfx.wrongSource = audio.createMediaElementSource(sfx.wrongAudio);
- sfx.wrongSource.connect(audio.destination);
+ audio.createMediaElementSource(sfx.wrongAudio).connect(audio.destination);
// const level = setupLevel([[2, 2], [3,3]], [7, 7]);
// const ui = setupLevelUi(level, root, audio);
- setupLevelSelectUi(root, sfx);
+
+ Promise.all([...Object.values(sfx)].map(x => x.load())).then(
+ () => setupLevelSelectUi(root, sfx)
+ );
};
root.appendChild(start);
}, 200);