const emptyFn = _ => {}

class ImageLoader {
    constructor () {
        this.images = {}
    }

    load (name, path, cb = emptyFn) {
        const image = new Image()
        image.onload = () => {
            const item = {
                src: image,
                width: image.width,
                height: image.height
            }

            this.images[name] = item
            cb(item)
        }
        image.src = path
    }

    draw (name, ctx) {
        const img = this.images[name]
        if (img) {
            ctx.drawImage(img.src, 0, 0, img.width, img.height);
        }
    }
}

export default new ImageLoader
