EditCharacterDatabase.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using UnityEngine;
  6. using wf;
  7. namespace SceneNPCEdit
  8. {
  9. public static class EditCharacterDatabase
  10. {
  11. public static int Count
  12. {
  13. get
  14. {
  15. EditCharacterDatabase.CreateData();
  16. return EditCharacterDatabase.commonIdManager.idMap.Count;
  17. }
  18. }
  19. public static bool Contains(int id)
  20. {
  21. return EditCharacterDatabase.commonIdManager.idMap.ContainsKey(id);
  22. }
  23. public static EditCharacterDatabase.Data GetData(int id)
  24. {
  25. EditCharacterDatabase.CreateData();
  26. NDebug.Assert(EditCharacterDatabase.basicDatas.ContainsKey(id), "NPCエディット\nID[" + id + "]のデータは存在しません");
  27. return EditCharacterDatabase.basicDatas[id];
  28. }
  29. public static bool IsEnabled(int id)
  30. {
  31. EditCharacterDatabase.CreateData();
  32. return EditCharacterDatabase.commonIdManager.enabledIdList.Contains(id);
  33. }
  34. public static List<EditCharacterDatabase.Data> GetAllDatas(bool onlyEnabled)
  35. {
  36. EditCharacterDatabase.CreateData();
  37. List<EditCharacterDatabase.Data> list = new List<EditCharacterDatabase.Data>();
  38. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in EditCharacterDatabase.commonIdManager.idMap)
  39. {
  40. if (!onlyEnabled || EditCharacterDatabase.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  41. {
  42. list.Add(EditCharacterDatabase.basicDatas[keyValuePair.Key]);
  43. }
  44. }
  45. return list;
  46. }
  47. public static void CreateData()
  48. {
  49. if (EditCharacterDatabase.commonIdManager != null)
  50. {
  51. return;
  52. }
  53. EditCharacterDatabase.commonIdManager = new CsvCommonIdManager("npcedit", "NPCエディット", CsvCommonIdManager.Type.IdOnly, null);
  54. EditCharacterDatabase.basicDatas = new Dictionary<int, EditCharacterDatabase.Data>();
  55. string[] array = new string[]
  56. {
  57. "list"
  58. };
  59. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  60. for (int i = 0; i < array2.Length; i++)
  61. {
  62. string text = "npcedit_" + array[i] + ".nei";
  63. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  64. CsvParser csvParser = new CsvParser();
  65. bool condition = csvParser.Open(afileBase);
  66. NDebug.Assert(condition, text + "\nopen failed.");
  67. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  68. }
  69. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in EditCharacterDatabase.commonIdManager.idMap)
  70. {
  71. EditCharacterDatabase.basicDatas.Add(keyValuePair.Key, new EditCharacterDatabase.Data(keyValuePair.Key, array2[0].Value));
  72. }
  73. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
  74. {
  75. keyValuePair2.Value.Dispose();
  76. keyValuePair2.Key.Dispose();
  77. }
  78. HashSet<int> hashSet = new HashSet<int>();
  79. foreach (int num in EditCharacterDatabase.commonIdManager.enabledIdList)
  80. {
  81. EditCharacterDatabase.Data data = EditCharacterDatabase.GetData(num);
  82. if (string.IsNullOrEmpty(data.checkPluginName) || PluginData.IsEnabled(data.checkPluginName))
  83. {
  84. if (data.checkLoadFolders != null && 0 < data.checkLoadFolders.Length)
  85. {
  86. bool flag = false;
  87. foreach (string item in data.checkLoadFolders)
  88. {
  89. if (GameUty.loadArchiveList.Contains(item))
  90. {
  91. flag = true;
  92. }
  93. }
  94. if (!flag)
  95. {
  96. continue;
  97. }
  98. }
  99. hashSet.Add(num);
  100. }
  101. }
  102. EditCharacterDatabase.commonIdManager = new CsvCommonIdManager(new Dictionary<int, KeyValuePair<string, string>>(EditCharacterDatabase.commonIdManager.idMap), EditCharacterDatabase.commonIdManager.nameMap, hashSet, CsvCommonIdManager.Type.IdOnly);
  103. }
  104. private const string csvTopCommonName = "npcedit";
  105. private const string typeNameForErrorLog = "NPCエディット";
  106. private static CsvCommonIdManager commonIdManager;
  107. private static Dictionary<int, EditCharacterDatabase.Data> basicDatas;
  108. public class Data
  109. {
  110. public Data(int id, CsvParser basicCsv)
  111. {
  112. for (int i = 1; i < basicCsv.max_cell_y; i++)
  113. {
  114. if (basicCsv.IsCellToExistData(0, i) && basicCsv.GetCellAsInteger(0, i) == id)
  115. {
  116. int num = 1;
  117. this.id = id;
  118. string cellAsString = basicCsv.GetCellAsString(num++, i);
  119. if (CharacterMgr.npcDatas.ContainsKey(cellAsString))
  120. {
  121. if (!CharacterMgr.npcDatas.ContainsKey(cellAsString))
  122. {
  123. Debug.LogError("NPCエディットエラー ユニーク名[" + cellAsString + "]のキャラプリセットが存在しません");
  124. }
  125. this.npcData = CharacterMgr.npcDatas[cellAsString];
  126. }
  127. this.isCBLEnabled = (basicCsv.GetCellAsString(num++, i) == "〇");
  128. this.checkPluginName = basicCsv.GetCellAsString(num++, i);
  129. string cellAsString2 = basicCsv.GetCellAsString(num++, i);
  130. if (!string.IsNullOrEmpty(cellAsString2))
  131. {
  132. this.checkLoadFolders = cellAsString2.Split(new char[]
  133. {
  134. '|'
  135. });
  136. }
  137. else
  138. {
  139. this.checkLoadFolders = new string[0];
  140. }
  141. string cellAsString3 = basicCsv.GetCellAsString(num++, i);
  142. if (!string.IsNullOrEmpty(cellAsString3))
  143. {
  144. List<CharacterMgr.NpcData> list = new List<CharacterMgr.NpcData>();
  145. list.Add(this.npcData);
  146. foreach (string text in cellAsString3.Split(new char[]
  147. {
  148. '|'
  149. }))
  150. {
  151. if (!CharacterMgr.npcDatas.ContainsKey(text))
  152. {
  153. Debug.LogError("NPCエディットエラー ユニーク名[" + text + "]のキャラプリセットが存在しません");
  154. }
  155. list.Add(CharacterMgr.npcDatas[text]);
  156. }
  157. this.overRideTargetNpc = list.ToArray();
  158. }
  159. else
  160. {
  161. this.overRideTargetNpc = new CharacterMgr.NpcData[]
  162. {
  163. this.npcData
  164. };
  165. }
  166. this.additionalInformationText = basicCsv.GetCellAsString(num++, i);
  167. this.additionalInformationTextForCBL = basicCsv.GetCellAsString(num++, i);
  168. }
  169. }
  170. }
  171. public Texture2D GetThumbnail()
  172. {
  173. if (this.npcData.isResourcesLoad)
  174. {
  175. return GameMain.Instance.CharacterMgr.PresetLoadFromResources(this.npcData.presetFileName).texThum;
  176. }
  177. using (AFileBase afileBase = GameUty.FileOpen(this.npcData.presetFileName + ".preset", null))
  178. {
  179. if (afileBase != null && afileBase.IsValid())
  180. {
  181. byte[] buffer = afileBase.ReadAll();
  182. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer), Encoding.UTF8))
  183. {
  184. return GameMain.Instance.CharacterMgr.PresetLoad(binaryReader, this.npcData.presetFileName).texThum;
  185. }
  186. }
  187. }
  188. return null;
  189. }
  190. public readonly int id;
  191. public readonly CharacterMgr.NpcData npcData;
  192. public readonly bool isCBLEnabled;
  193. public readonly string checkPluginName;
  194. public readonly string[] checkLoadFolders;
  195. public readonly string additionalInformationText;
  196. public readonly string additionalInformationTextForCBL;
  197. public readonly CharacterMgr.NpcData[] overRideTargetNpc;
  198. }
  199. }
  200. }