// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import {
    RandomInt
} from '../script/SN11_utils';

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {
        let bg_leaf1 = this.node.getChildByName('bg_leaf1');
        let bg_leaf2 = this.node.getChildByName('bg_leaf2');
        let bg_tree = this.node.getChildByName('bg_tree');
        let bg_tree2 = this.node.getChildByName('bg_tree2');
        let bg_tree3 = this.node.getChildByName('bg_tree3');
        let bg_cloud1 = this.node.getChildByName('bg_cloud1');
        let bg_cloud2 = this.node.getChildByName('bg_cloud2');

        let nodeList = [
            bg_tree,
            bg_tree2,
            bg_tree3,
            bg_leaf1,
            bg_leaf2,
            bg_cloud1,
            bg_cloud2
        ];

        nodeList.forEach((node) => {
            node.active = false;
        });

        let idx = RandomInt(nodeList.length);
        nodeList[idx].active = true;

        this.node.zIndex = idx;

    },

    // update (dt) {},
});
