diff options
Diffstat (limited to 'src/engine/config/assets.ts')
-rw-r--r-- | src/engine/config/assets.ts | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/engine/config/assets.ts b/src/engine/config/assets.ts index fbfab2f..8cf7685 100644 --- a/src/engine/config/assets.ts +++ b/src/engine/config/assets.ts @@ -1,7 +1,12 @@ import { type SpriteSpec, SPRITE_SPECS } from "."; import { SOUND_SPECS, SoundSpec } from "./sounds"; -export const FONT = new FontFace("scientifica", "url(/fonts/scientifica.ttf)"); +const BASE_URL = document.location; + +export const FONT = new FontFace( + "scientifica", + `url(${BASE_URL}/fonts/scientifica.ttf)` +); FONT.load().then((font) => { document.fonts.add(font); }); @@ -10,26 +15,26 @@ export const IMAGES = new Map<string, HTMLImageElement>(); export const SOUNDS = new Map<string, HTMLAudioElement>(); export const loadSpritesIntoImageElements = ( - spriteSpecs: Partial<SpriteSpec>[], + spriteSpecs: Partial<SpriteSpec>[] ): Promise<void>[] => { const spritePromises: Promise<void>[] = []; for (const spriteSpec of spriteSpecs) { if (spriteSpec.sheet) { const img = new Image(); - img.src = spriteSpec.sheet; + img.src = BASE_URL + spriteSpec.sheet; IMAGES.set(spriteSpec.sheet, img); spritePromises.push( new Promise((resolve) => { img.onload = () => resolve(); - }), + }) ); } if (spriteSpec.states) { spritePromises.push( - ...loadSpritesIntoImageElements(Array.from(spriteSpec.states.values())), + ...loadSpritesIntoImageElements(Array.from(spriteSpec.states.values())) ); } } @@ -38,13 +43,13 @@ export const loadSpritesIntoImageElements = ( }; export const loadSoundsIntoAudioElements = ( - soundSpecs: SoundSpec[], + soundSpecs: SoundSpec[] ): Promise<void>[] => { const soundPromises: Promise<void>[] = []; for (const soundSpec of soundSpecs) { if (soundSpec.url) { - const promise = fetch(soundSpec.url) + const promise = fetch(BASE_URL + soundSpec.url) .then((response) => response.blob()) .then((blob) => { const audio = new Audio(); @@ -68,7 +73,7 @@ export const loadSoundsIntoAudioElements = ( if (soundSpec.states) { soundPromises.push( - ...loadSoundsIntoAudioElements(Array.from(soundSpec.states.values())), + ...loadSoundsIntoAudioElements(Array.from(soundSpec.states.values())) ); } } @@ -80,8 +85,8 @@ export const loadAssets = () => Promise.all([ ...loadSpritesIntoImageElements( Array.from(SPRITE_SPECS.keys()).map( - (key) => SPRITE_SPECS.get(key) as SpriteSpec, - ), + (key) => SPRITE_SPECS.get(key) as SpriteSpec + ) ), FONT.load(), ...loadSoundsIntoAudioElements(Array.from(SOUND_SPECS.values())), |