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;
}
}
/** Прекратить вспышку и вернуть исходный tint (контракт fx: cancel = сброс). */
cancel(): void {
const f = this.flash;
this.flash = null;
if (!f || this.sprite.destroyed) return;
this.sprite.tint = f.finish();
}
/** Самозачистка из реестра: спрайт разрушен — запись вычистится сама. */
get destroyed(): boolean {
return this.sprite.destroyed;
}
}