import { Sprite } from 'pixi.js';
import { TintFlash } from '../anim/flash';

/**
 * Тонкий Pixi-адаптер над anim/flash: хит-флэш спрайта.
 * Логика лерпа — в TintFlash (тестируется), здесь только применение tint.
 */
export class SpriteFlash {
    private flash: TintFlash | null = null;

    constructor(
        private readonly sprite: Sprite,
        private readonly flashColor: number,
        private readonly seconds = 0.15
    ) {}

    /** Запустить вспышку (перезапускается с нуля). */
    start(): void {
        if (!this.flash) {
            this.flash = new TintFlash(this.sprite.tint, this.flashColor, this.seconds);
        }
        this.flash.start();
    }

    /** Обновлять каждый тик владельцем (например, боевой системой). */
    update(dt: number): void {
        if (!this.flash) return;
        const tint = this.flash.update(dt);
        if (tint !== null) {
            this.sprite.tint = tint;
        } else {
            this.flash = null;
        }
    }
}