/*
    Hurry Curry! - a game about cooking
    Copyright (C) 2026 Hurry Curry! Contributors

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, version 3 of the License only.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

*/

import { camera } from "../main.ts";
import { ceil_v2, floor_v2 } from "../util.ts";

export interface MapLayer {
    draw_map_layer(ctx: CanvasRenderingContext2D): void
}

export class GridLayer implements MapLayer {
    draw_map_layer(ctx: CanvasRenderingContext2D): void {
        ctx.strokeStyle = "#333"
        ctx.lineWidth = 0.01
        ctx.beginPath()
        const min = floor_v2(camera.screen_to_world({ x: 0, y: 0 }))
        const max = ceil_v2(camera.screen_to_world({ x: ctx.canvas.width, y: ctx.canvas.height }))
        for (let x = min.x; x < max.x; x++) {
            ctx.moveTo(x, min.y)
            ctx.lineTo(x, max.y)
        }
        for (let y = min.y; y < max.y; y++) {
            ctx.moveTo(min.x, y)
            ctx.lineTo(max.x, y)
        }
        ctx.stroke()
    }
}
