#include "ModelInfo.h"

#include <Textur.h>

#include "Globals.h"

using namespace Framework;

ModelInfo::ModelInfo(const char* model, const char *texture, bool transparent, int numTextures)
    : modelPath(model),
      transparent(transparent)
{
    for (int i = 0; i < numTextures; i++)
        texturPaths.add(new Text(texture));
}

ModelInfo::ModelInfo(Framework::StreamReader* reader)
{
    char len;
    reader->lese(&len, 1);
    char* path = new char[len + 1];
    reader->lese(path, len);
    path[len] = 0;
    modelPath = path;
    delete[] path;
    short count;
    reader->lese((char*)&count, 2);
    for (int i = 0; i < count; i++)
    {
        reader->lese(&len, 1);
        path = new char[len + 1];
        reader->lese(path, len);
        path[len] = 0;
        texturPaths.add(new Text(path));
        delete[] path;
    }
    reader->lese((char*)&transparent, 1);
}

Framework::Model3DData* ModelInfo::getModel() const
{
    return uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(modelPath);
}

Framework::Model3DTextur* ModelInfo::getTexture() const
{
    Model3DTextur* textur = new Model3DTextur();
    int index = 0;
    for (Text* texturPath : texturPaths)
    {
        Textur* tex
            = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur(
                texturPath->getText(), 0);
        textur->setPolygonTextur(index++, tex);
    }
    return textur;
}

Framework::Text ModelInfo::getModelName() const
{
    return modelPath;
}

const Framework::RCArray<Framework::Text>* ModelInfo::getTexturNames() const
{
    return &texturPaths;
}

bool ModelInfo::isTransparent() const
{
    return transparent;
}