CsvCommonIdManager.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace wf
  5. {
  6. public class CsvCommonIdManager
  7. {
  8. public CsvCommonIdManager(string csvTopCommonName, string typeName, CsvCommonIdManager.Type type, Func<int, bool> customCheckFunction = null)
  9. {
  10. this.idMap = new SortedDictionary<int, KeyValuePair<string, string>>();
  11. this.nameMap = new Dictionary<string, int>();
  12. this.type = type;
  13. AFileSystemBase fileSystem = GameUty.FileSystem;
  14. List<string> pathList = GameUty.PathList;
  15. string fileName = csvTopCommonName + "_enabled_list";
  16. string str = csvTopCommonName + "_list";
  17. this.enabledIdList = new HashSet<int>();
  18. CsvCommonIdManager.ReadEnabledIdList(fileSystem, pathList, fileName, ref this.enabledIdList);
  19. using (AFileBase afileBase = fileSystem.FileOpen(str + ".nei"))
  20. {
  21. using (CsvParser csvParser = new CsvParser())
  22. {
  23. bool condition = csvParser.Open(afileBase);
  24. NDebug.Assert(condition, str + ".nei\nopen failed.");
  25. for (int i = 1; i < csvParser.max_cell_y; i++)
  26. {
  27. if (csvParser.IsCellToExistData(0, i))
  28. {
  29. int num = 0;
  30. int cellAsInteger = csvParser.GetCellAsInteger(num++, i);
  31. if (type == CsvCommonIdManager.Type.IdAndUniqueName)
  32. {
  33. string cellAsString = csvParser.GetCellAsString(num++, i);
  34. string cellAsString2 = csvParser.GetCellAsString(num++, i);
  35. if (this.idMap.ContainsKey(cellAsInteger) || this.nameMap.ContainsKey(cellAsString) || string.IsNullOrEmpty(cellAsString))
  36. {
  37. if (this.idMap.ContainsKey(cellAsInteger))
  38. {
  39. Debug.LogError(string.Concat(new object[]
  40. {
  41. typeName,
  42. "のID[",
  43. cellAsInteger,
  44. "]が重複しています"
  45. }));
  46. }
  47. else if (this.nameMap.ContainsKey(cellAsString))
  48. {
  49. Debug.LogError(typeName + "の名前[" + cellAsString + "]が重複しています");
  50. }
  51. else
  52. {
  53. Debug.LogError(string.Concat(new object[]
  54. {
  55. typeName,
  56. "の名前が空です\n",
  57. i + 1,
  58. "行目"
  59. }));
  60. }
  61. }
  62. else if (customCheckFunction == null || customCheckFunction(cellAsInteger))
  63. {
  64. this.idMap.Add(cellAsInteger, new KeyValuePair<string, string>(cellAsString, cellAsString2));
  65. this.nameMap.Add(cellAsString, cellAsInteger);
  66. }
  67. }
  68. else
  69. {
  70. string cellAsString3 = csvParser.GetCellAsString(num++, i);
  71. if (this.idMap.ContainsKey(cellAsInteger))
  72. {
  73. if (this.idMap.ContainsKey(cellAsInteger))
  74. {
  75. Debug.LogError(string.Concat(new object[]
  76. {
  77. typeName,
  78. "のID[",
  79. cellAsInteger,
  80. "]が重複しています"
  81. }));
  82. }
  83. }
  84. else if (customCheckFunction == null || customCheckFunction(cellAsInteger))
  85. {
  86. this.idMap.Add(cellAsInteger, new KeyValuePair<string, string>(string.Empty, cellAsString3));
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. public CsvCommonIdManager(Dictionary<int, KeyValuePair<string, string>> idMap, Dictionary<string, int> nameMap, HashSet<int> enabledIdList, CsvCommonIdManager.Type type)
  95. {
  96. this.idMap = new SortedDictionary<int, KeyValuePair<string, string>>(idMap);
  97. this.nameMap = new Dictionary<string, int>(nameMap);
  98. this.enabledIdList = new HashSet<int>(enabledIdList);
  99. this.type = type;
  100. }
  101. public static void ReadEnabledIdList(CsvCommonIdManager.FileSystemType fileSystemType, bool readPathList, string fileName, ref HashSet<int> destList)
  102. {
  103. AFileSystemBase fileSystem = null;
  104. List<string> pathList = null;
  105. if (fileSystemType == CsvCommonIdManager.FileSystemType.Normal)
  106. {
  107. fileSystem = GameUty.FileSystem;
  108. if (readPathList)
  109. {
  110. pathList = GameUty.PathList;
  111. }
  112. }
  113. else if (fileSystemType == CsvCommonIdManager.FileSystemType.Old)
  114. {
  115. fileSystem = GameUty.FileSystemOld;
  116. if (readPathList)
  117. {
  118. pathList = GameUty.PathListOld;
  119. }
  120. }
  121. CsvCommonIdManager.ReadEnabledIdList(fileSystem, pathList, fileName, ref destList);
  122. }
  123. public static void ReadEnabledIdList(AFileSystemBase fileSystem, List<string> pathList, string fileName, ref HashSet<int> destList)
  124. {
  125. if (destList == null)
  126. {
  127. destList = new HashSet<int>();
  128. }
  129. string str = fileName;
  130. fileName += ".nei";
  131. if (!fileSystem.IsExistentFile(fileName))
  132. {
  133. if (pathList != null)
  134. {
  135. foreach (string str2 in pathList)
  136. {
  137. CsvCommonIdManager.ReadEnabledIdList(fileSystem, null, str + "_" + str2, ref destList);
  138. }
  139. }
  140. return;
  141. }
  142. using (AFileBase afileBase = fileSystem.FileOpen(fileName))
  143. {
  144. using (CsvParser csvParser = new CsvParser())
  145. {
  146. bool condition = csvParser.Open(afileBase);
  147. NDebug.Assert(condition, fileName + "\nopen failed.");
  148. for (int i = 1; i < csvParser.max_cell_y; i++)
  149. {
  150. if (csvParser.IsCellToExistData(0, i))
  151. {
  152. int cellAsInteger = csvParser.GetCellAsInteger(0, i);
  153. if (!destList.Contains(cellAsInteger))
  154. {
  155. destList.Add(cellAsInteger);
  156. }
  157. }
  158. }
  159. }
  160. }
  161. if (pathList != null)
  162. {
  163. foreach (string str3 in pathList)
  164. {
  165. CsvCommonIdManager.ReadEnabledIdList(fileSystem, null, str + "_" + str3, ref destList);
  166. }
  167. }
  168. }
  169. public static void ReadEnabledIdList(AFileSystemBase fileSystem, List<string> pathList, string fileName, ref HashSet<string> destList)
  170. {
  171. if (destList == null)
  172. {
  173. destList = new HashSet<string>();
  174. }
  175. string str = fileName;
  176. fileName += ".nei";
  177. if (!fileSystem.IsExistentFile(fileName))
  178. {
  179. if (pathList != null)
  180. {
  181. foreach (string str2 in pathList)
  182. {
  183. CsvCommonIdManager.ReadEnabledIdList(fileSystem, null, str + "_" + str2, ref destList);
  184. }
  185. }
  186. return;
  187. }
  188. using (AFileBase afileBase = fileSystem.FileOpen(fileName))
  189. {
  190. using (CsvParser csvParser = new CsvParser())
  191. {
  192. bool condition = csvParser.Open(afileBase);
  193. NDebug.Assert(condition, fileName + "\nopen failed.");
  194. for (int i = 1; i < csvParser.max_cell_y; i++)
  195. {
  196. if (csvParser.IsCellToExistData(0, i))
  197. {
  198. string cellAsString = csvParser.GetCellAsString(0, i);
  199. if (!destList.Contains(cellAsString))
  200. {
  201. destList.Add(cellAsString);
  202. }
  203. }
  204. }
  205. }
  206. }
  207. if (pathList != null)
  208. {
  209. foreach (string str3 in pathList)
  210. {
  211. CsvCommonIdManager.ReadEnabledIdList(fileSystem, null, str + "_" + str3, ref destList);
  212. }
  213. }
  214. }
  215. public readonly SortedDictionary<int, KeyValuePair<string, string>> idMap;
  216. public readonly Dictionary<string, int> nameMap;
  217. public readonly HashSet<int> enabledIdList;
  218. public readonly CsvCommonIdManager.Type type;
  219. public enum Type
  220. {
  221. IdAndUniqueName,
  222. IdOnly
  223. }
  224. public enum FileSystemType
  225. {
  226. Normal,
  227. Old
  228. }
  229. }
  230. }