From b68d7ea99c86bbec2e485e98f49c38a0c2dee7ac Mon Sep 17 00:00:00 2001 From: Juan Sebastian Montoya Date: Thu, 11 Jul 2024 20:56:05 -0500 Subject: [PATCH] feat(#3): rename resource to level loader --- src/level-loader.js | 22 ++++++++++++++++++++++ src/resource-loader.js | 15 --------------- 2 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 src/level-loader.js delete mode 100644 src/resource-loader.js diff --git a/src/level-loader.js b/src/level-loader.js new file mode 100644 index 0000000..edf510a --- /dev/null +++ b/src/level-loader.js @@ -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} 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; + }); + } +} diff --git a/src/resource-loader.js b/src/resource-loader.js deleted file mode 100644 index 4b86564..0000000 --- a/src/resource-loader.js +++ /dev/null @@ -1,15 +0,0 @@ -export default class ResourceLoader { -/** - * Loads an image from the specified URL. - * - * @return {Promise} 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; - }); - } -}