Adjust audio to traverse hierarchy
This commit is contained in:
parent
2668795d69
commit
5544cc83cf
|
@ -1,6 +1,21 @@
|
||||||
import assets from 'url:../../../Assets/Audio/**/*.ogg'
|
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 let enabled = true
|
||||||
export function enableSound() {
|
export function enableSound() {
|
||||||
|
@ -17,7 +32,7 @@ export function disableSound() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preload 'em
|
// 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()
|
let audio = new Audio()
|
||||||
audio.addEventListener('canplaythrough', () => {
|
audio.addEventListener('canplaythrough', () => {
|
||||||
console.log('preloaded audio', key)
|
console.log('preloaded audio', key)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user