import { _decorator, Component, Node, sp } from 'cc';
import { BattleManager } from '../../../manager/BattleManager';
import { BattleData } from '../../../data/BattleData';
import { Framework } from '../../../../framework/Framework';
import { GameEvent } from '../../../data/GameEvent';
const { ccclass, property } = _decorator;

@ccclass('ChangeChapter')
export class ChangeChapter extends Component {


    @property({type:sp.Skeleton,tooltip:'胜利动画'})
    winSpine:sp.Skeleton = null;

    
    private _endcallback:Function
    
    protected onLoad(): void {
        Framework.event.addEvent(GameEvent.BattleDuplicateReset, this.duplicateReset.bind(this),this);
    }

    show(callback:Function) {
        this.node.active = true

        this.winSpine.setAnimation(0,'animation1',false)

        this._endcallback = callback
    }

    actionComplete(trackEntry:sp.spine.TrackEntry) {
        // this.bAnimOver = true
        // if(this.bWait) return
        // this.node.active = false
        // this._endcallback&&this._endcallback()
        // this._endcallback = null
    }
    onTouchButton() {
        BattleManager.sendBattleDuplicateResetMsg(BattleData.duplicate.chapter+1)
        
    }

    duplicateReset() {
        this.node.active = false
        this._endcallback&&this._endcallback()
        this._endcallback = null
    }
}


