#include "TeleportZone.h"
#include "render/Renderer.h"
#include "render/TextureManager.h"

namespace ZL {

void TeleportZone::initSparks(std::shared_ptr<Texture> activeTex, std::shared_ptr<Texture> inactiveTex)
{
    sparks = std::make_unique<SparkEmitter>();
    std::vector<Vector3f> emitPoints;
    emitPoints.push_back(Vector3f{ position.x(), position.y(), position.z() });
    sparks->setEmissionPoints(emitPoints);
    sparks->setTexture(active ? activeTex : inactiveTex);
    sparks->setEmissionRate(50.0f);
    sparks->setMaxParticles(80);
    sparks->setParticleSize(0.05f);
    sparks->setBiasX(0.0f);
    sparks->setEmissionDirection(Vector3f{ 0.0f, 1.0f, 0.0f });
    sparks->setEmissionRadius(radius);
    sparks->setSpeedRange(0.5f, 1.0f);
    sparks->setZSpeedRange(0.5f, 1.5f);
    sparks->setScaleRange(0.5f, 1.0f);
    sparks->setLifeTimeRange(1500.0f, 2500.0f);
    sparks->setUseWorldSpace(true);
    sparks->markConfigured();
}

void TeleportZone::update(float deltaMs)
{
    if (sparks) sparks->update(deltaMs);
}

void TeleportZone::prepareForDraw(const Eigen::Matrix4f& viewMatrix)
{
    if (sparks) sparks->prepareForDraw(viewMatrix);
}

void TeleportZone::draw(Renderer& renderer, float zoom, int width, int height)
{
    if (sparks) sparks->draw(renderer, zoom, width, height);
}

} // namespace ZL
