using System; using System.Collections.Generic; using UnityEngine; namespace wf { public class CsvCommonIdManager { public CsvCommonIdManager(string csvTopCommonName, string typeName, CsvCommonIdManager.Type type, Func customCheckFunction = null) { this.idMap = new SortedDictionary>(); this.nameMap = new Dictionary(); this.type = type; AFileSystemBase fileSystem = GameUty.FileSystem; List pathList = GameUty.PathList; string fileName = csvTopCommonName + "_enabled_list"; string str = csvTopCommonName + "_list"; this.enabledIdList = new HashSet(); CsvCommonIdManager.ReadEnabledIdList(fileSystem, pathList, fileName, ref this.enabledIdList); using (AFileBase afileBase = fileSystem.FileOpen(str + ".nei")) { using (CsvParser csvParser = new CsvParser()) { bool condition = csvParser.Open(afileBase); NDebug.Assert(condition, str + ".nei\nopen failed."); for (int i = 1; i < csvParser.max_cell_y; i++) { if (csvParser.IsCellToExistData(0, i)) { int num = 0; int cellAsInteger = csvParser.GetCellAsInteger(num++, i); if (type == CsvCommonIdManager.Type.IdAndUniqueName) { string cellAsString = csvParser.GetCellAsString(num++, i); string cellAsString2 = csvParser.GetCellAsString(num++, i); if (this.idMap.ContainsKey(cellAsInteger) || this.nameMap.ContainsKey(cellAsString) || string.IsNullOrEmpty(cellAsString)) { if (this.idMap.ContainsKey(cellAsInteger)) { Debug.LogError(string.Concat(new object[] { typeName, "のID[", cellAsInteger, "]が重複しています" })); } else if (this.nameMap.ContainsKey(cellAsString)) { Debug.LogError(typeName + "の名前[" + cellAsString + "]が重複しています"); } else { Debug.LogError(string.Concat(new object[] { typeName, "の名前が空です\n", i + 1, "行目" })); } } else if (customCheckFunction == null || customCheckFunction(cellAsInteger)) { this.idMap.Add(cellAsInteger, new KeyValuePair(cellAsString, cellAsString2)); this.nameMap.Add(cellAsString, cellAsInteger); } } else { string cellAsString3 = csvParser.GetCellAsString(num++, i); if (this.idMap.ContainsKey(cellAsInteger)) { if (this.idMap.ContainsKey(cellAsInteger)) { Debug.LogError(string.Concat(new object[] { typeName, "のID[", cellAsInteger, "]が重複しています" })); } } else if (customCheckFunction == null || customCheckFunction(cellAsInteger)) { this.idMap.Add(cellAsInteger, new KeyValuePair(string.Empty, cellAsString3)); } } } } } } } public CsvCommonIdManager(Dictionary> idMap, Dictionary nameMap, HashSet enabledIdList, CsvCommonIdManager.Type type) { this.idMap = new SortedDictionary>(idMap); this.nameMap = new Dictionary(nameMap); this.enabledIdList = new HashSet(enabledIdList); this.type = type; } public static void ReadEnabledIdList(CsvCommonIdManager.FileSystemType fileSystemType, bool readPathList, string fileName, ref HashSet destList) { AFileSystemBase fileSystem = null; List pathList = null; if (fileSystemType == CsvCommonIdManager.FileSystemType.Normal) { fileSystem = GameUty.FileSystem; if (readPathList) { pathList = GameUty.PathList; } } else if (fileSystemType == CsvCommonIdManager.FileSystemType.Old) { fileSystem = GameUty.FileSystemOld; if (readPathList) { pathList = GameUty.PathListOld; } } CsvCommonIdManager.ReadEnabledIdList(fileSystem, pathList, fileName, ref destList); } public static void ReadEnabledIdList(AFileSystemBase fileSystem, List pathList, string fileName, ref HashSet destList) { if (destList == null) { destList = new HashSet(); } string str = fileName; fileName += ".nei"; if (!fileSystem.IsExistentFile(fileName)) { if (pathList != null) { foreach (string str2 in pathList) { CsvCommonIdManager.ReadEnabledIdList(fileSystem, null, str + "_" + str2, ref destList); } } return; } using (AFileBase afileBase = fileSystem.FileOpen(fileName)) { using (CsvParser csvParser = new CsvParser()) { bool condition = csvParser.Open(afileBase); NDebug.Assert(condition, fileName + "\nopen failed."); for (int i = 1; i < csvParser.max_cell_y; i++) { if (csvParser.IsCellToExistData(0, i)) { int cellAsInteger = csvParser.GetCellAsInteger(0, i); if (!destList.Contains(cellAsInteger)) { destList.Add(cellAsInteger); } } } } } if (pathList != null) { foreach (string str3 in pathList) { CsvCommonIdManager.ReadEnabledIdList(fileSystem, null, str + "_" + str3, ref destList); } } } public static void ReadEnabledIdList(AFileSystemBase fileSystem, List pathList, string fileName, ref HashSet destList) { if (destList == null) { destList = new HashSet(); } string str = fileName; fileName += ".nei"; if (!fileSystem.IsExistentFile(fileName)) { if (pathList != null) { foreach (string str2 in pathList) { CsvCommonIdManager.ReadEnabledIdList(fileSystem, null, str + "_" + str2, ref destList); } } return; } using (AFileBase afileBase = fileSystem.FileOpen(fileName)) { using (CsvParser csvParser = new CsvParser()) { bool condition = csvParser.Open(afileBase); NDebug.Assert(condition, fileName + "\nopen failed."); for (int i = 1; i < csvParser.max_cell_y; i++) { if (csvParser.IsCellToExistData(0, i)) { string cellAsString = csvParser.GetCellAsString(0, i); if (!destList.Contains(cellAsString)) { destList.Add(cellAsString); } } } } } if (pathList != null) { foreach (string str3 in pathList) { CsvCommonIdManager.ReadEnabledIdList(fileSystem, null, str + "_" + str3, ref destList); } } } public readonly SortedDictionary> idMap; public readonly Dictionary nameMap; public readonly HashSet enabledIdList; public readonly CsvCommonIdManager.Type type; public enum Type { IdAndUniqueName, IdOnly } public enum FileSystemType { Normal, Old } } }