Skip to content

Commit

Permalink
Use new import glob parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticFqx committed Mar 19, 2024
1 parent 8f150f2 commit 5633ba6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/assets/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Audio {
rate?: number;
}

const imageGlob = import.meta.glob('./images/**/*.png', {as: 'url', eager: true});
const imageGlob = import.meta.glob<string>('./images/**/*.png', {query: '?url', import: 'default', eager: true});
export const image = (path: string, key: string): Image => {
return { key, path: imageGlob[`./images/${path}.png`] };
}
Expand All @@ -26,17 +26,17 @@ export const spritesheet = (path: string, key: string, width: number, height: nu
return { key, width, height, path: imageGlob[`./images/${path}.png`] };
}

const musicGlob = import.meta.glob('./music/**/*.mp3', {as: 'url', eager: true});
const musicGlob = import.meta.glob<string>('./music/**/*.mp3', {query: '?url', import: 'default', eager: true});
export const music = (path: string, key: string, volume?: number, rate?: number): Audio => {
return { key, volume, rate, path: musicGlob[`./music/${path}.mp3`] };
}

const audioGlob = import.meta.glob('./sounds/**/*.mp3', {as: 'url', eager: true});
const audioGlob = import.meta.glob<string>('./sounds/**/*.mp3', {query: '?url', import: 'default', eager: true});
export const sound = (path: string, key: string, volume?: number, rate?: number): Audio => {
return { key, volume, rate, path: audioGlob[`./sounds/${path}.mp3`] };
}

const fontGlob = import.meta.glob('./fonts/**/*.ttf', {as: 'url', eager: true});
const fontGlob = import.meta.glob<string>('./fonts/**/*.ttf', {query: '?url', import: 'default', eager: true});
export const loadFont = async (path: string, name: string) => {
const face = new FontFace(name, `url(${fontGlob[`./fonts/${path}.ttf`]})`, {style: 'normal', weight: '400'});
await face.load();
Expand Down

0 comments on commit 5633ba6

Please sign in to comment.