/*
    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 { SPlayers } from "./map/players.ts";
import { SSprites } from "./map/sprites.ts";
import { System } from "./system.ts";
import { lerp_exp_v2_mut } from "./util.ts";

export class SPinnedMessages extends System {
    constructor(
        public ss: SSprites,
        public ps: SPlayers
    ) { super() }

    override tick(dt: number): void {
        let pin_xo = 0
        for (const [_, player] of this.ps.players) {
            if (player.message_pinned && player.message_pinned.tick(dt)) delete player.message_pinned
            if (player.message_pinned) lerp_exp_v2_mut(player.message_pinned.anim_position, { x: pin_xo++, y: 0 }, dt * 5)
        }
    }
    override draw(ctx: CanvasRenderingContext2D): void {
        const scale = Math.max(80, ctx.canvas.width / 20)
        ctx.save()
        ctx.scale(scale, scale)
        ctx.translate(0.8, 0.8)

        for (const [_, player] of this.ps.players)
            if (player.message_pinned) player.message_pinned.draw(ctx, this.ss, false)

        ctx.restore()
    }
}
