import { Assets, Container } from 'pixi.js';
import { ITrackEntry, Spine } from 'pixi-spine';

export default class AnticipationFrame extends Container
{
    protected spine: Spine;
    constructor()
    {
        super();
        this.create();
    }

    protected create()
    {
        this.spine = new Spine(Assets.get('anticipation').spineData);
        this.addChild(this.spine);
        this.spine.autoUpdate = false;
    }

    update(dt: number): void
    {
        this.spine.update(dt * 0.001);
    }

    show(): ITrackEntry
    {
        this.spine.state.setEmptyAnimation(0, 0.1);
        this.spine.state.addAnimation(0, 'in', false, 0);

        return this.spine.state.addAnimation(0, 'idle', true, 0);
    }

    hide(): ITrackEntry
    {
        return this.spine.state.setAnimation(0, 'out', false);
    }
}
