import loadAtlas from './atlas'
import loadImage from './image'

let resources = {}

const loadAll = arr => {
    const promises = arr.map(item => {
        if (item.type === 'image') return loadImage(item.name, item.path, resources)
        if (item.type === 'atlas') return loadAtlas(item.path, item.items, resources)
    })
    return Promise.all(promises)
}

const load = {
    image: (name, path) => loadImage(name, path, resources),
    atlas: (path, items) => loadAtlas(path, items, resources),
    all: loadAll
}

const get = name => {
    return resources[name] ? resources[name].data : null
}

export default {
    loadAll,
    load,
    get
}
