Adjust audio to traverse hierarchy

This commit is contained in:
Ketchetwahmeegwun T. Southall 2022-01-30 01:01:18 -08:00
parent 2668795d69
commit 5544cc83cf

View File

@ -1,6 +1,21 @@
import assets from 'url:../../../Assets/Audio/**/*.ogg'
console.log('audio assets:', assets)
export const audio: Record<string, string> = assets
type Entry = { [key: string]: string | Entry }
export const audio: Record<string, string> = {}
function traverse(path: string, entry: Entry|string) {
if (typeof entry === 'string') {
audio[path] = entry
} else if (typeof entry === 'object') {
for (let [key, value] of Object.entries(entry)) {
traverse((path?path+'/':'')+key, value)
}
}
}
traverse('', assets)
export let enabled = true
export function enableSound() {
@ -17,7 +32,7 @@ export function disableSound() {
}
// Preload 'em
for (let [key, value] of (Object.entries(assets) as [string,string][])) {
for (let [key, value] of (Object.entries(audio))) {
let audio = new Audio()
audio.addEventListener('canplaythrough', () => {
console.log('preloaded audio', key)