/*
* 对象池类
*/
import Animation = Laya.Animation;
	import Stage = Laya.Stage;
	import Rectangle = Laya.Rectangle;
	import Loader = Laya.Loader;
	import Browser = Laya.Browser;
    import WebGL = Laya.WebGL;
    

export class GamePool extends Laya.EventDispatcher
{
    private static sprite3DArray:any = {};
    private static contain:any={};
    constructor(){
        super();
    }

    private AniConfPath: string = "res/fighter/fighter.json";

    

    public static RemoveItem( key:string, obj:any ):void
    {
        if( GamePool.contain[key] )
        {
            var index:number = GamePool.contain[key].indexOf( obj );
            if(index == -1)
            {
                GamePool.contain[key].push( obj );
            }
        }
    }

    public static GetItem( key:string,...args:any[] ):any
    {
        if( GamePool.contain[key] )
        {
            var arr:Array<any> = GamePool.contain[key];
            if( arr.length ==0 )
            {
                var calssobj:any = GamePool.sprite3DArray[key];
                var vo:any = new calssobj();
                return vo;
            }
            return GamePool.contain[key].shift();
        }
        else
        {
            console.log( "此key值对应的类未被注册" );
            return null;
        }
    }

    /******************************************* */
    private createAnimation(): void {
        var ani: Animation = new Animation();
        ani.loadAtlas(this.AniConfPath); // 加载图集动画
        ani.interval = 30; // 设置播放间隔（单位：毫秒）
        ani.index = 1; // 当前播放索引
        ani.play(); // 播放图集动画

        // 获取动画的边界信息
        var bounds: Rectangle = ani.getGraphicBounds();
        ani.pivot(bounds.width / 2, bounds.height / 2);

        ani.pos(Laya.stage.width / 2, Laya.stage.height / 2);

        Laya.stage.addChild(ani);
    }

    /******************************************* */

    public static GetItemFairyGUI( url:string ):any
    {
        if( !GamePool.contain[url] )
        {
            GamePool.contain[url] = [];
        }
        var arr:Array<any> = GamePool.contain[url];
        if( arr.length ==0 )
        {
            var vo:any = fairygui.UIPackage.createObjectFromURL( url );
            return vo;
        }
        return GamePool.contain[url].shift();
    }

    public static Mark( key:string, classarg:any ):void
    {
        GamePool.sprite3DArray[key] = classarg;
        GamePool.contain[key] = [];
    }

    
}