feat(#3): rename resource to level loader
This commit is contained in:
parent
fa89a653ad
commit
b68d7ea99c
2 changed files with 22 additions and 15 deletions
22
src/level-loader.js
Normal file
22
src/level-loader.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
class Level {
|
||||
constructor({ image, layer }) {
|
||||
this.image = image;
|
||||
this.layer = layer;
|
||||
}
|
||||
}
|
||||
|
||||
export default class LevelLoader {
|
||||
/**
|
||||
* Loads a level on memory from the specified source and layer.
|
||||
*
|
||||
* @return {Promise<Level>} A Promise that resolves with the loaded level.
|
||||
*/
|
||||
static load({ source, layer }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.src = source;
|
||||
image.onload = () => resolve(new Level({ image, layer }));
|
||||
image.onerror = reject;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
export default class ResourceLoader {
|
||||
/**
|
||||
* Loads an image from the specified URL.
|
||||
*
|
||||
* @return {Promise<HTMLImageElement>} A Promise that resolves with the loaded image.
|
||||
*/
|
||||
static load(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.src = url;
|
||||
image.onload = () => resolve(image)
|
||||
image.onerror = reject;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue