using System.Collections;
using System.Collections.Generic;
using LitJson;

public class ResourceCfg
{
    private static ResourceCfg mInstance;
    public static ResourceCfg instance
    {
        get
        {
            if (null == mInstance)
                mInstance = new ResourceCfg();
            return mInstance;
        }
    }

    private Dictionary<int, ResourceCfgItem> mResCfg = new Dictionary<int, ResourceCfgItem>();

    public void LoadCfg()
    {
        var text = ResourceMgr.instance.LoadCfgFile("resources.bytes");
        var list = JsonMapper.ToObject<List<ResourceCfgItem>>(text);
        for (int i = 0; i < list.Count; i++)
        {
            var item = list[i];
            if (!mResCfg.ContainsKey(item.id))
            {
                mResCfg.Add(item.id, item);
            }
            else
            {
                GameLogger.LogError("resources.bytes 有资源id重复，id：" + item.id);
            }
        }
    }

    public ResourceCfgItem GetResCfg(int resId)
    {
        if (mResCfg.ContainsKey(resId))
            return mResCfg[resId];
        GameLogger.LogError("ResourceCfg.GetResCfg Error, resId = " + resId);
        return null;
    }
}

public class ResourceCfgItem
{
    public int id;
    public string editor_path;
}