feat(audio): audio system
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user