Update to fix mp3 from dean's code

This commit is contained in:
Logan Hunt 2022-04-15 13:09:06 -06:00
parent 9307b67a59
commit 1cffeb5520
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 52B3774857EB24B1

13
src/bootstrap.js vendored
View File

@ -1,4 +1,6 @@
game.bootstrap = (() => {
const image_extensions = ["png", "jpeg", "jpg"];
const audio_extensions = ["mp3"];
const scripts = [
{
src: [
@ -68,13 +70,18 @@ game.bootstrap = (() => {
.then((r) => r.blob())
.then((r) => {
let asset;
if (["png", "jpg", "jpeg"].includes(fileExtension)) {
if (image_extensions.includes(fileExtension)) {
asset = new Image();
} else if (["mp3"].includes(fileExtension)) {
} else if (audio_extensions.includes(fileExtension)) {
asset = new Audio();
}
asset.src = URL.createObjectURL(r);
asset.onload = () => URL.revokeObjectURL(asset.src);
const ready = () => URL.revokeObjectURL(asset.src);
if (asset instanceof Image) {
asset.onload = ready;
} else if (asset instanceof Audio) {
asset.oncanplaythrough = ready;
}
return asset;
})
}