let gameConfig = require("GameConfig");
cc.Class({
    extends: cc.Component,

    properties: {
        gameStates: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
        videoplayer: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
        videoController: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
        title: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
    },
    onLoad()
    {
        this.gStatesScp = this.gameStates.getComponent('GameStates');
        this.videoControllerScp = this.videoController.getComponent('SpriteVideoPlayer');
        this.audioControllerScp = this.node.getComponent('AudioController');

        this.audioNames = [
            '1、前绕肩',
            '2、后绕肩',
            '3、屈膝转体热身',
            '4、体前曲出拳',
            '5、拳击站架',
            '6、前直拳',
            '7、后直拳',
            '8、前后滑步',
            '9、前后滑步前直拳',
            '10、上步左右直拳',
            '11、侧闪',
            '12、前摆拳',
            '13、后勾拳',
            '14、前直后勾组合拳',
            '15、前摆后直组合拳',
            '16、直勾摆组合拳',
            '17、摇臂',
            '18、侧闪后直拳',
            '19、交替出拳',
            '20、右侧肩部拉伸',
            '21、左侧肩部拉伸',
            '22、左臂拉伸',
            '23、右臂拉伸',
            '24、最后一个动作，坚持就是胜利'
        ];
    },
    play(callback)
    {
        let self = this;
        this.gStatesScp.curretState = this.gStatesScp.demonstration;
        this.round = gameConfig.round[this.gStatesScp.currentRound];

        this.videoControllerScp.play(this.videoplayer,this.gStatesScp.currentRound,self,this.videoCompleted);
        this.title.getComponent(cc.Label).string = '动作预览: '+this.round.name;

        this.playAudioHint(callback);
    },
    videoCompleted(self)
    {
        if(self.gStatesScp.curretState == self.gStatesScp.demonstration)
        {
            self.videoControllerScp.play(self.videoplayer,self.gStatesScp.currentRound,self,self.videoCompleted);
        }
    },
    playAudioHint(callback)
    {
        let self = this;
        let demonstrationAudios = [
            'Audios/Game/Others/11、休息结束，下一个动作',
            'Audios/Game/Names/'+this.audioNames[this.gStatesScp.currentRound],
            // 'Audios/Game/Others/1、一组',
        ];

        demonstrationAudios.push(this.round.second);

        this.audioControllerScp.playAudioBySequence(demonstrationAudios,function () {
            // console.log('111111')
            self.scheduleOnce(function () {

                self.gStatesScp.curretState = self.gStatesScp.countDown;
                // self.main.active = true;
                cc.tween(this.node)
                    .by(0.5, { position: cc.v2(-this.node.width, 0) })
                    .call(() => {

                        self.node.x = 0;
                        // self.node.active = false;
                        self.node.opacity = 0;
                    })
                    .start();
                self.videoControllerScp.stop();
                callback();

            },1);
        });
    }
});
