#include "EntityType.h"

#include "Entity.h"
#include "Globals.h"
#include "Registries.h"

EntityType::EntityType(int id, ModelInfo model)
    : id(id),
      model(model)
{}

Entity* EntityType::loadEntity(Framework::StreamReader* zReader) const
{
    int id;
    zReader->lese((char*)&id, 4);
    Framework::Vec3<float> position;
    zReader->lese((char*)&position.x, 4);
    zReader->lese((char*)&position.y, 4);
    zReader->lese((char*)&position.z, 4);
    float maxSpeed;
    zReader->lese((char*)&maxSpeed, 4);
    bool specialModel = 0;
    zReader->lese((char*)&specialModel, 1);
    Entity* e;
    if (specialModel)
    {
        ModelInfo model(zReader);
        e = new Entity(
            this, model.getModel(), model.getTexture(), id, position, maxSpeed);
    }
    else
    {
        e = new Entity(
            this, model.getModel(), model.getTexture(), id, position, maxSpeed);
    }
    if (World::INSTANCE->zKamera()->getEntityId() == id)
    {
        e->setPlayerControlled();
    }
    return e;
}

int EntityType::getId() const
{
    return id;
}