#include "Chunk.h"

Chunk::Chunk(int x, int y) : chunkX(x), chunkY(y)
{
    tiles.resize(CHUNK_SIZE * CHUNK_SIZE);
}

Tile& Chunk::GetTile(int localX, int localY)
{
    if (localX < 0 || localX >= CHUNK_SIZE || localY < 0 || localY >= CHUNK_SIZE)
    {
        throw std::out_of_range("Local tile coordinates out of chunk bonds");
    }
    return tiles[localY * CHUNK_SIZE + localX];
}

const Tile& Chunk::GetTile(int localX, int localY) const
{
    return const_cast<Chunk*>(this)->GetTile(localX, localY);
}

void Chunk::SetTile(int localX, int localY, const Tile& tile)
{
    GetTile(localX, localY) = tile;
}