import { Container } from '@pixi/display'; import { AnticipationAnimationConfig } from '../types'; import { AnticipationAnimation } from './AnticipationAnimation'; import { gsap } from 'gsap'; export class AnticipationAnimationManager { private _anims: AnticipationAnimation[] = []; constructor(parent: Container, animationsConfig: AnticipationAnimationConfig[], columnCount: number) { if (animationsConfig.length !== columnCount - 1) { throw new Error(`Expected ${columnCount} anticipation animations, but got ${animationsConfig.length - 1}`); } // Start from 1, no need to create animation for first reel for (let i = 1; i < columnCount; i++) { const newAnim = AnticipationAnimation.CreateAnticipation(animationsConfig[i - 1]); parent.addChild(newAnim); this._anims[i] = newAnim; } } private transitionTween(index: number, alpha: number, duration: number = 0.2): gsap.core.Tween { const tween = gsap.to(this._anims[index], { duration, alpha }); return tween; } public playAnimation(index: number) { if (index <= 0) { throw new Error(`Invalid index ${index}, no animation for first reel`); } this._anims[index].srcAnimatedSprite.play(); this.transitionTween(index, 1); } public stopAnimation(index: number) { this.transitionTween(index, 0).then(() => { this._anims[index].srcAnimatedSprite.stop(); }) } public stopAllAnimations() { for (let i = 0; i < this._anims.length; i++) { this.stopAnimation(i); } } public playAnimationsFrom(index: number) { for (let i = index; i < this._anims.length; i++) { this.playAnimation(i); } } }