const jsonNames = ['all', 'behavior', 'level', 'nest', 'map', 'path'];

export class ConfigMgr {
    private static _inst: ConfigMgr;
    public static get inst(): ConfigMgr {
        if (this._inst == null) {
            this._inst = new ConfigMgr();
        }
        return this._inst;
    }

    config: cc.AssetManager.Cache = new cc.AssetManager.Cache();
    init(): Promise<void> {
        let arr = jsonNames.map(v=>{ return 'json/'+ v});

        return new Promise((resolve)=>{
            cc.resources.load(arr, cc.JsonAsset, (err, res)=>{
                if(res){
                    res.forEach((v, k)=>{
                        this.config.add(jsonNames[k], v.json);
                        cc.assetManager.releaseAsset(v);
                    });
                }
                resolve();
            })
        });
    }

    getCfgById(key, id){
        let cfg = this.config.get(key);
        return cfg[id];
    }
}