//--------------------------------------------------------
|
// [Author]: Fish
|
// [ Date ]: 2024年12月31日
|
//--------------------------------------------------------
|
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Threading;
|
using System;
|
using UnityEngine;
|
using LitJson;
|
|
public partial class RealmConfig
|
{
|
|
public readonly int Lv;
|
public readonly int LvLarge;
|
public readonly string Name;
|
public readonly string NameEx;
|
public readonly int LVMax;
|
public readonly int[] AddAttrType;
|
public readonly int[] AddAttrNum;
|
public readonly long expRate;
|
public readonly long expLimit;
|
public readonly string Img;
|
public readonly int Quality;
|
public readonly Dictionary<int, int[]> LearnSkillIDInfo;
|
public readonly int AddFreePoint;
|
public readonly int EquipLV;
|
|
public RealmConfig()
|
{
|
}
|
|
public RealmConfig(string input)
|
{
|
try
|
{
|
var tables = input.Split('\t');
|
|
int.TryParse(tables[0],out Lv);
|
|
int.TryParse(tables[1],out LvLarge);
|
|
Name = tables[2];
|
|
NameEx = tables[3];
|
|
int.TryParse(tables[4],out LVMax);
|
|
if (tables[5].Contains("["))
|
{
|
AddAttrType = JsonMapper.ToObject<int[]>(tables[5]);
|
}
|
else
|
{
|
string[] AddAttrTypeStringArray = tables[5].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
AddAttrType = new int[AddAttrTypeStringArray.Length];
|
for (int i=0;i<AddAttrTypeStringArray.Length;i++)
|
{
|
int.TryParse(AddAttrTypeStringArray[i],out AddAttrType[i]);
|
}
|
}
|
|
if (tables[6].Contains("["))
|
{
|
AddAttrNum = JsonMapper.ToObject<int[]>(tables[6]);
|
}
|
else
|
{
|
string[] AddAttrNumStringArray = tables[6].Trim().Split(StringUtility.splitSeparator,StringSplitOptions.RemoveEmptyEntries);
|
AddAttrNum = new int[AddAttrNumStringArray.Length];
|
for (int i=0;i<AddAttrNumStringArray.Length;i++)
|
{
|
int.TryParse(AddAttrNumStringArray[i],out AddAttrNum[i]);
|
}
|
}
|
|
long.TryParse(tables[7],out expRate);
|
|
long.TryParse(tables[8],out expLimit);
|
|
Img = tables[9];
|
|
int.TryParse(tables[10],out Quality);
|
|
LearnSkillIDInfo = ConfigParse.ParseIntArrayDict(tables[11]);
|
|
int.TryParse(tables[12],out AddFreePoint);
|
|
int.TryParse(tables[13],out EquipLV);
|
}
|
catch (Exception ex)
|
{
|
DebugEx.Log(ex);
|
}
|
}
|
|
static Dictionary<string, RealmConfig> configs = new Dictionary<string, RealmConfig>();
|
public static RealmConfig Get(string id)
|
{
|
if (!inited)
|
{
|
Debug.LogError("RealmConfig 还未完成初始化。");
|
return null;
|
}
|
|
if (configs.ContainsKey(id))
|
{
|
return configs[id];
|
}
|
|
RealmConfig config = null;
|
if (rawDatas.ContainsKey(id))
|
{
|
config = configs[id] = new RealmConfig(rawDatas[id]);
|
rawDatas.Remove(id);
|
}
|
|
return config;
|
}
|
|
public static RealmConfig Get(int id)
|
{
|
return Get(id.ToString());
|
}
|
|
public static List<string> GetKeys()
|
{
|
var keys = new List<string>();
|
keys.AddRange(configs.Keys);
|
keys.AddRange(rawDatas.Keys);
|
return keys;
|
}
|
|
public static List<RealmConfig> GetValues()
|
{
|
var values = new List<RealmConfig>();
|
values.AddRange(configs.Values);
|
|
var keys = new List<string>(rawDatas.Keys);
|
for (int i = 0; i < keys.Count; i++)
|
{
|
values.Add(Get(keys[i]));
|
}
|
|
return values;
|
}
|
|
public static bool Has(string id)
|
{
|
return configs.ContainsKey(id) || rawDatas.ContainsKey(id);
|
}
|
|
public static bool Has(int id)
|
{
|
return Has(id.ToString());
|
}
|
|
public static bool inited { get; private set; }
|
protected static Dictionary<string, string> rawDatas = new Dictionary<string, string>();
|
public static void Init(bool sync=false)
|
{
|
inited = false;
|
var path = string.Empty;
|
if (AssetSource.refdataFromEditor)
|
{
|
path = ResourcesPath.CONFIG_FODLER +"/Realm.txt";
|
}
|
else
|
{
|
path = AssetVersionUtility.GetAssetFilePath("config/Realm.txt");
|
}
|
|
configs.Clear();
|
var tempConfig = new RealmConfig();
|
var preParse = tempConfig is IConfigPostProcess;
|
|
if (sync)
|
{
|
var lines = File.ReadAllLines(path);
|
if (!preParse)
|
{
|
rawDatas = new Dictionary<string, string>(lines.Length - 3);
|
}
|
for (int i = 3; i < lines.Length; i++)
|
{
|
try
|
{
|
var line = lines[i];
|
var index = line.IndexOf("\t");
|
if (index == -1)
|
{
|
continue;
|
}
|
var id = line.Substring(0, index);
|
|
if (preParse)
|
{
|
var config = new RealmConfig(line);
|
configs[id] = config;
|
(config as IConfigPostProcess).OnConfigParseCompleted();
|
}
|
else
|
{
|
rawDatas[id] = line;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
inited = true;
|
}
|
else
|
{
|
ThreadPool.QueueUserWorkItem((object _object) =>
|
{
|
var lines = File.ReadAllLines(path);
|
if (!preParse)
|
{
|
rawDatas = new Dictionary<string, string>(lines.Length - 3);
|
}
|
for (int i = 3; i < lines.Length; i++)
|
{
|
try
|
{
|
var line = lines[i];
|
var index = line.IndexOf("\t");
|
if (index == -1)
|
{
|
continue;
|
}
|
var id = line.Substring(0, index);
|
|
if (preParse)
|
{
|
var config = new RealmConfig(line);
|
configs[id] = config;
|
(config as IConfigPostProcess).OnConfigParseCompleted();
|
}
|
else
|
{
|
rawDatas[id] = line;
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
}
|
|
inited = true;
|
});
|
}
|
}
|
|
}
|
|
|
|
|