import { eventTarget, SHOW_ACTION_SCREEN, STOP_ANIM_CHUM } from "../Events";


const { ccclass, property } = cc._decorator;

@ccclass
export default class ChumController extends cc.Component {
    private spine: sp.Skeleton = null;

    private _count = 0;
    private _actions: Function[] = [];

    protected onLoad(): void {
        this.spine = this.node.getComponent(sp.Skeleton);

        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this._actions = [this.playAnimationNut1, this.playAnimationNut2, this.playAnimationNut3, this.playAnimationNut4];
        eventTarget.on(STOP_ANIM_CHUM, this.stopAnimation, this);
    }

    private onTouchStart(): void {
        // this._actions[this._count].bind(this)();
        // this._count = (this._count + 1) % this._actions.length;
    }

    private stopAnimation(): void {
        this.spine.setAnimation(0, "default", true);
    }

    public playAnimationNut1(): void {
        this.spine.setAnimation(0, "nut1", true);
        this.spine.timeScale = 1;
    }

    public playAnimationNut2(): void {
        this.spine.setAnimation(0, "nut2", true);
        this.spine.timeScale = 1;
    }

    public playAnimationNut3(): void {
        this.spine.setAnimation(0, "nut3", true);
        this.spine.timeScale = 0.5;
    }

    public playAnimationNut4(): void {
        this.spine.setAnimation(0, "nut4", false);
        this.spine.timeScale = 0.5;
    }

}
