import { Noise } from "noisejs";
import { PRNG } from "../../../GlobalVariables/GlobalVariables";
import { Point2D } from "../../../Utils/Math.utils";
import { DWFBMSimplex2 } from "../../../Utils/Noise.utils";
import { NumberCue } from "../../../Utils/DataTypes.utils";

export class TileValue {
    noiseValue = -1;
    temperatureValue = 0;
    tileId = -1;

    constructor(noiseValue, tileId, temperatureValue) {
        this.noiseValue = noiseValue;
        this.tileId = tileId;
        this.temperatureValue = temperatureValue;
    }
}

export class TerrainGenerator {
    cNoise = new Noise(Math.floor(PRNG() * 999999999999));
    tNoise = new Noise(Math.floor(PRNG() * 999999999999));

    /**
     *
     * @param {Noise} cNoise
     * @param {Noise} tNoise
     */
    constructor(cNoise, tNoise) {
        if (cNoise) this.cNoise = cNoise;
        if (tNoise) this.tNoise = tNoise;
    }

    /**
     * returns tile value at point
     * @param {Point2D} point
     * @returns {TileValue}
     */
    getValueAt(point) {
        let mainValue = DWFBMSimplex2(this.cNoise, point.getX() / 1000.0, point.getY() / 1000.0, 3.0);
        mainValue *= mainValue;
        mainValue *= DWFBMSimplex2(this.cNoise, point.getX() / 100, point.getY() / 100, 3.0);
        let temperatureValue = DWFBMSimplex2(this.tNoise, point.getX() / 10.0, point.getY() / 10.0, 3.0);
        // let tileId = -1;
        // if (mainValue < 0.25) {
        //     tileId = 0;
        // } else if (mainValue < 0.3) {
        //     tileId = 1;
        // } else if (mainValue < 0.8) {
        //     tileId = 2;
        // } else {
        //     tileId = 3;
        // }
        return new TileValue(mainValue, -1, temperatureValue);
    }
}
