const { showFireworks } = require("./utils");

cc.Class({
    extends: cc.Component,

    properties: {
        audOver: cc.AudioClip,
        audOver2: cc.AudioClip,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.node.getChildByName('bg_verygood').zIndex = 99;
    },

    start() {
        this.scheduleOnce(() => {
            showFireworks(
                this.node,
                this.node.getChildByName('RibbonNodeBase').children,
                cc.v2(0, -400), cc.v2(0, 1000), 200, 200
            );
            showFireworks(
                this.node,
                this.node.getChildByName('RibbonNodeBase').children,
                cc.v2(-600, -400), cc.v2(200, 1000), 200, 200
            );
            showFireworks(
                this.node,
                this.node.getChildByName('RibbonNodeBase').children,
                cc.v2(600, -400), cc.v2(-200, 1000), 200, 200
            );
            this.playAudioOver2();
        }, 0.6)
        this.playAudioOver();
    },

    playAudioOver() {
        GameData.audioCount++;
        let id = cc.audioEngine.play(this.audOver, false, 1);
        cc.audioEngine.setFinishCallback(id, () => {
            GameData.audioCount--;
        })
    },
    playAudioOver2() {
        GameData.audioCount++;
        let id = cc.audioEngine.play(this.audOver2, false, 1);
        cc.audioEngine.setFinishCallback(id, () => {
            GameData.audioCount--;
        })
    },
    // update (dt) {},
});
