#include "ChunkModelBuilder.h"
#include "Chunk.h"

ChunkModelBuilder::ChunkModelBuilder(
    FactoryCraftModel* target, Chunk* zChunk, int type)
    : ReferenceCounter(),
      zChunk(zChunk),
      type(type),
      target(target)
{}

ChunkModelBuilder::~ChunkModelBuilder()
{
    target->release();
}

Block** ChunkModelBuilder::blocks()
{
    return zChunk->blocks;
}

void ChunkModelBuilder::setBlockPartOfModel(Block* zBlock, bool partOfModel)
{
    int state = zBlock->getPartOfModels();
    if (!state && partOfModel)
    {
        zChunk->visibleBlocks.removeValue(zBlock);
    }
    zBlock->setPartOfModel(type, partOfModel);
    if (state && !zBlock->getPartOfModels())
    {
        zChunk->visibleBlocks.add(zBlock);
    }
}

Framework::Point ChunkModelBuilder::chunkCenter()
{
    return zChunk->location;
}

FactoryCraftModel* ChunkModelBuilder::zModel() const
{
    return target;
}

int ChunkModelBuilder::getType() const
{
    return type;
}