import { GameObject } from "../../GameObject/GameObject";
import { PointInt2D } from "../../Utils/Math.utils";
import { NavigationGridChunk } from "../../World/NavigationGrid/NavigationGrid";
import { TerrainTile } from "../Tiles/TerrainTile";
import { Tile } from "../Tiles/Tile";

export const CHUNK_LAYER_TERRAIN = 0;

export class Chunk extends GameObject
{
    /**
     * @type {Map<String, TerrainTile>}
     */
    terrainLayer = new Map();

    chunkPivotCoordinates = new PointInt2D();

    /**
     * @type {NavigationGridChunk}
     */
    navigationChunk = null;

    filled = false;

    /**
     * 
     * @param {Boolean} tickable 
     * @param {PointInt2D} pivot 
     */
    constructor(tickable, pivot)
    {
        super(tickable);
        this.chunkPivotCoordinates = pivot;
    }

    /**
     * 
     * @param {Number} layerId 
     * @param {Tile} object 
     */
    addToLayer(layerId, object)
    {
        switch (layerId) {
            case CHUNK_LAYER_TERRAIN:
                this.terrainLayer.set(object.tileKey, object);
                break;
        
            default:
                break;
        }
    }

    /**
     * 
     * @param {Boolean} newVisibility 
     */
    changeVisibility(newVisibility)
    {
        for (const i of this.terrainLayer) {
            i[1].drawObject.visible = newVisibility;
        }
    }
}