#include "EntityType.h"

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

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

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

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