#include "states/LoadingManager.h"
#include "app/AssetLoader.h"

LoadingManager::LoadingManager(AssetLoader* loader)
    : m_loader(loader)
{
}

void LoadingManager::queueTexture(const std::string& path) {
    if (!m_loader) return;
    m_loader->queueTexture(path);
}

void LoadingManager::start() {
    m_started = true;
}

bool LoadingManager::update() {
    if (!m_loader) return true;
    // perform a single step on the loader; AssetLoader::performStep returns true when
    // there are no more queued tasks.
    bool done = m_loader->performStep();
    return done;
}

float LoadingManager::getProgress() const {
    if (!m_loader) return 1.0f;
    return m_loader->getProgress();
}

std::vector<std::string> LoadingManager::getAndClearErrors() {
    if (!m_loader) return {};
    return m_loader->getAndClearErrors();
}

std::string LoadingManager::getCurrentLoading() const {
    if (!m_loader) return {};
    return m_loader->getCurrentLoading();
}
