const NodePool = require('NodePool');
const BottleType = require('Types').BottleType;

/**
 * 对象池[Bottle]
 */
cc.Class({
    extends: cc.Component,

    properties: {
        bottlePools: {
            default: [],
            type: NodePool
        }
    },

    init () {
        for (let i = 0; i < this.bottlePools.length; ++i) {
            this.bottlePools[i].init()
        }
    },

    requestBottle (bottleType) {
        let thePool = this.bottlePools[bottleType]
        if(thePool.idx >= 0) {
            return thePool.request()
        } else {
            return null
        }
    },

    returnBottle (bottleType, obj) {
        let thePool = this.bottlePools[bottleType]
        if(thePool.idx < thePool.size) {
            thePool.return(obj)
        } else {
            // console.log('=========== NodePool: 对象池已满 ===========')
            return
        }
    },

    start () {

    },

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