feat(audio): audio system

This commit is contained in:
2026-02-24 17:34:01 +01:00
parent 8a67577d36
commit ef00bd06bb
3 changed files with 74 additions and 3 deletions

View File

@@ -7,6 +7,18 @@ type Rect = [number, number, number, number];
let atlasImage: HTMLImageElement | null = null;
const modelCache = new Map<string, THREE.Group>();
const createAudio = (path: string) => {
const audio = import.meta.client ? new Audio(path) : null;
return {
play: () => {
if (!audio) return;
audio.currentTime = 0;
audio.play().catch(() => {});
},
};
};
const loaded = ref(0);
const total = ref({{TOTAL}});
const isReady = computed(() => loaded.value === total.value);
@@ -93,9 +105,16 @@ type ModelTree = {
[key: string]: THREE.Group | ModelTree;
};
export type AudioEntry = ReturnType<typeof createAudio>;
type AudioTree = {
[key: string]: AudioEntry | AudioTree;
};
const assets = {
images: {{IMAGES}} as const satisfies ImageTree,
models: {{MODELS}} as const satisfies ModelTree,
audio: {{AUDIO}} as const satisfies AudioTree,
};
type Assets = typeof assets;