AssetStore
The AssetStore class is a singleton class that manages the storage and loading of various assets, such as sounds, images, and fonts.
Getters
instance
- Type: 
AssetStore 
Returns the instance of the AssetStore class.
sounds
- Type: 
Map<string, HTMLAudioElement> 
Returns the map of all the sounds.
images
- Type: 
Map<string, HTMLImageElement> 
Returns the map of all the images.
Methods
addFont
addFont(name: string, url: string): AssetStore;
Adds a font to the AssetStore.
Parameters
name- Type: 
string - The name of the font
 
- Type: 
 url- Type: 
string - The URL of the font
 
- Type: 
 
Return
AssetStore The instance of the AssetStore class.
Example
import myFontUrl from './fonts/myFont.ttf'
ServiceContainer.AssetStore.addSound('myFont', myFontUrl);
addImage
addImage(name: string, url: string): AssetStore;
Adds an image to the AssetStore.
Parameters
name- Type: 
string - The name of the image
 
- Type: 
 url- Type: 
string - The URL of the image
 
- Type: 
 
Return
AssetStore The instance of the AssetStore class.
Example
import myImageUrl from './images/mySImage.png'
ServiceContainer.AssetStore.addImage('myImage', myImageUrl);
addSound
addSound(name: string, url: string): AssetStore;
Adds a sound to the AssetStore.
Parameters
name- Type: 
string - The name of the sound
 
- Type: 
 url- Type: 
string - The URL of the sound
 
- Type: 
 
Return
AssetStore The instance of the AssetStore class.
Example
import mySoundUrl from './sounds/mySound.mp3'
ServiceContainer.AssetStore.addSound('mySound', mySoundUrl);
getSound
getSound(name: string): HTMLAudioElement;
Returns a sound from the AssetStore.
Parameters
name- Type: 
string - The name of the sound
 
- Type: 
 
Return
HTMLAudioElement The sound.
Example
ServiceContainer.AssetStore.getSound('mySound');
getImage
getImage(name: string): HTMLImageElement;
Returns an image from the AssetStore.
Parameters
name- Type: 
string - The name of the image
 
- Type: 
 
Return
HTMLImageElement The image.
Example
ServiceContainer.AssetStore.getImage('myImage');
loadAllAssets
loadAllAssets(): Promise<void[]>;
Loads all the assets and returns a promise that resolves when all the assets are loaded.
Return
Promise<void[]> The promise that resolves when all the assets are loaded.
Example
ServiceContainer.AssetStore.loadAllAssets();
Complete usage example
import { ServiceContainer } from 'r-row';
// Fonts
import myFont from '../fonts/myFont.ttf';
// Images
import myImage from '../images/myImage.png';
// Sounds
import myImage from '../sounds/mySOund.wav';
ServiceContainer.AssetStore
  .addFont('myFont', myFont)
  .addImage('myImage', myImage)
  .addSound('mySound', mySound)
  .loadAllAssets()
  .then(() => {
    //...
  });