| | |
| | | //-------------------------------------------------------- |
| | | // [Author]: 第二世界 |
| | | // [ Date ]: Sunday, April 08, 2018 |
| | | // [Author]: Fish |
| | | // [ Date ]: Thursday, February 14, 2019 |
| | | //-------------------------------------------------------- |
| | | |
| | | using UnityEngine; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Threading; |
| | | using System; |
| | | using UnityEngine; |
| | | |
| | | namespace TableConfig { |
| | | [XLua.LuaCallCSharp] |
| | | public partial class MapEventPointConfig |
| | | { |
| | | |
| | | |
| | | public partial class MapEventPointConfig : ConfigBase { |
| | | public readonly int Key; |
| | | public readonly int MapID; |
| | | public readonly int NPCID; |
| | | public readonly int IsShowInfo; |
| | | public readonly int ShowInMipMap; |
| | | public readonly int Colour; |
| | | public readonly int LowLV; |
| | | public readonly int HighestLV; |
| | | public readonly int Defense; |
| | | public readonly string Drop1; |
| | | public readonly string Drop2; |
| | | public readonly string EXP; |
| | | |
| | | public int Key { get ; private set ; } |
| | | public int MapID { get ; private set ; } |
| | | public int NPCID { get ; private set ; } |
| | | public int IsShowInfo { get ; private set ; } |
| | | public int ShowInMipMap { get ; private set ; } |
| | | public int Colour { get ; private set ; } |
| | | public int LowLV { get ; private set ; } |
| | | public int HighestLV { get ; private set ; } |
| | | public int Defense { get ; private set ; } |
| | | public string Drop1 { get ; private set; } |
| | | public string Drop2 { get ; private set; } |
| | | public string EXP { get ; private set; } |
| | | public MapEventPointConfig() |
| | | { |
| | | } |
| | | |
| | | public override string getKey() |
| | | public MapEventPointConfig(string input) |
| | | { |
| | | try |
| | | { |
| | | return Key.ToString(); |
| | | var tables = input.Split('\t'); |
| | | |
| | | int.TryParse(tables[0],out Key); |
| | | |
| | | int.TryParse(tables[1],out MapID); |
| | | |
| | | int.TryParse(tables[2],out NPCID); |
| | | |
| | | int.TryParse(tables[3],out IsShowInfo); |
| | | |
| | | int.TryParse(tables[4],out ShowInMipMap); |
| | | |
| | | int.TryParse(tables[5],out Colour); |
| | | |
| | | int.TryParse(tables[6],out LowLV); |
| | | |
| | | int.TryParse(tables[7],out HighestLV); |
| | | |
| | | int.TryParse(tables[8],out Defense); |
| | | |
| | | Drop1 = tables[9]; |
| | | |
| | | Drop2 = tables[10]; |
| | | |
| | | EXP = tables[11]; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | DebugEx.Log(ex); |
| | | } |
| | | } |
| | | |
| | | static Dictionary<string, MapEventPointConfig> configs = new Dictionary<string, MapEventPointConfig>(); |
| | | public static MapEventPointConfig Get(string id) |
| | | { |
| | | if (!inited) |
| | | { |
| | | Debug.Log("MapEventPointConfig 还未完成初始化。"); |
| | | return null; |
| | | } |
| | | |
| | | if (configs.ContainsKey(id)) |
| | | { |
| | | return configs[id]; |
| | | } |
| | | |
| | | public override void Parse() { |
| | | try |
| | | MapEventPointConfig config = null; |
| | | if (rawDatas.ContainsKey(id)) |
| | | { |
| | | config = configs[id] = new MapEventPointConfig(rawDatas[id]); |
| | | rawDatas.Remove(id); |
| | | } |
| | | |
| | | return config; |
| | | } |
| | | |
| | | public static MapEventPointConfig 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<MapEventPointConfig> GetValues() |
| | | { |
| | | var values = new List<MapEventPointConfig>(); |
| | | values.AddRange(configs.Values); |
| | | |
| | | var keys = new List<string>(rawDatas.Keys); |
| | | foreach (var key in keys) |
| | | { |
| | | values.Add(Get(key)); |
| | | } |
| | | |
| | | 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 +"/MapEventPoint.txt"; |
| | | } |
| | | else |
| | | { |
| | | path = AssetVersionUtility.GetAssetFilePath("config/MapEventPoint.txt"); |
| | | } |
| | | |
| | | var tempConfig = new MapEventPointConfig(); |
| | | var preParse = tempConfig is IConfigPostProcess; |
| | | |
| | | if (sync) |
| | | { |
| | | var lines = File.ReadAllLines(path); |
| | | if (!preParse) |
| | | { |
| | | Key=IsNumeric(rawContents[0]) ? int.Parse(rawContents[0]):0; |
| | | |
| | | MapID=IsNumeric(rawContents[1]) ? int.Parse(rawContents[1]):0; |
| | | |
| | | NPCID=IsNumeric(rawContents[2]) ? int.Parse(rawContents[2]):0; |
| | | |
| | | IsShowInfo=IsNumeric(rawContents[3]) ? int.Parse(rawContents[3]):0; |
| | | |
| | | ShowInMipMap=IsNumeric(rawContents[4]) ? int.Parse(rawContents[4]):0; |
| | | |
| | | Colour=IsNumeric(rawContents[5]) ? int.Parse(rawContents[5]):0; |
| | | |
| | | LowLV=IsNumeric(rawContents[6]) ? int.Parse(rawContents[6]):0; |
| | | |
| | | HighestLV=IsNumeric(rawContents[7]) ? int.Parse(rawContents[7]):0; |
| | | |
| | | Defense=IsNumeric(rawContents[8]) ? int.Parse(rawContents[8]):0; |
| | | |
| | | Drop1 = rawContents[9].Trim(); |
| | | |
| | | Drop2 = rawContents[10].Trim(); |
| | | |
| | | EXP = rawContents[11].Trim(); |
| | | rawDatas = new Dictionary<string, string>(lines.Length - 3); |
| | | } |
| | | catch (Exception ex) |
| | | for (int i = 3; i < lines.Length; i++) |
| | | { |
| | | DesignDebug.Log(ex); |
| | | 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 MapEventPointConfig(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 MapEventPointConfig(line); |
| | | configs[id] = config; |
| | | (config as IConfigPostProcess).OnConfigParseCompleted(); |
| | | } |
| | | else |
| | | { |
| | | rawDatas[id] = line; |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.LogError(ex); |
| | | } |
| | | } |
| | | |
| | | inited = true; |
| | | }); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |