ManData.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System;
  2. using System.Collections.Generic;
  3. using wf;
  4. namespace Kasizuki
  5. {
  6. public static class ManData
  7. {
  8. public static int Count
  9. {
  10. get
  11. {
  12. ManData.CreateData();
  13. return ManData.commonIdManager.idMap.Count;
  14. }
  15. }
  16. public static bool Contains(string name)
  17. {
  18. return ManData.commonIdManager.nameMap.ContainsKey(name);
  19. }
  20. public static bool Contains(int id)
  21. {
  22. return ManData.commonIdManager.idMap.ContainsKey(id);
  23. }
  24. public static int uniqueNameToId(string uniqueName)
  25. {
  26. ManData.CreateData();
  27. NDebug.Assert(ManData.commonIdManager.nameMap.ContainsKey(uniqueName), "傅き.男データ\nユニーク名[" + uniqueName + "]をIDに変換できませんでした");
  28. return ManData.commonIdManager.nameMap[uniqueName];
  29. }
  30. public static string IdToUniqueName(int id)
  31. {
  32. ManData.CreateData();
  33. NDebug.Assert(ManData.commonIdManager.idMap.ContainsKey(id), "傅き.男データ\nID[" + id + "]をユニーク名に変換できませんでした");
  34. return ManData.commonIdManager.idMap[id].Key;
  35. }
  36. public static ManData.Data GetData(int id)
  37. {
  38. ManData.CreateData();
  39. NDebug.Assert(ManData.basicDatas.ContainsKey(id), "傅き.男データ\nID[" + id + "]のデータは存在しません");
  40. return ManData.basicDatas[id];
  41. }
  42. public static ManData.Data GetData(string uniqueName)
  43. {
  44. return ManData.GetData(ManData.uniqueNameToId(uniqueName));
  45. }
  46. public static bool IsEnabled(string uniqueName)
  47. {
  48. ManData.CreateData();
  49. return ManData.commonIdManager.enabledIdList.Contains(ManData.uniqueNameToId(uniqueName));
  50. }
  51. public static bool IsEnabled(int id)
  52. {
  53. ManData.CreateData();
  54. return ManData.commonIdManager.enabledIdList.Contains(id);
  55. }
  56. public static List<ManData.Data> GetAllDatas(bool onlyEnabled, bool checkLockNTR = true)
  57. {
  58. ManData.CreateData();
  59. List<ManData.Data> list = new List<ManData.Data>();
  60. if (checkLockNTR && GameMain.Instance.CharacterMgr.status.lockNTRPlay)
  61. {
  62. list.Add(ManData.GetData(10));
  63. }
  64. else
  65. {
  66. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in ManData.commonIdManager.idMap)
  67. {
  68. if (!onlyEnabled || ManData.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  69. {
  70. list.Add(ManData.basicDatas[keyValuePair.Key]);
  71. }
  72. }
  73. }
  74. return list;
  75. }
  76. public static List<ManData.Data> GetDatas(Func<ManData.Data, bool> customCheckFunction)
  77. {
  78. ManData.CreateData();
  79. List<ManData.Data> list = new List<ManData.Data>();
  80. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in ManData.commonIdManager.idMap)
  81. {
  82. ManData.Data data = ManData.basicDatas[keyValuePair.Key];
  83. if (customCheckFunction(data))
  84. {
  85. list.Add(data);
  86. }
  87. }
  88. return list;
  89. }
  90. public static void CreateData()
  91. {
  92. if (ManData.commonIdManager != null)
  93. {
  94. return;
  95. }
  96. ManData.commonIdManager = new CsvCommonIdManager("kasizuki_man", "傅き.男データ", CsvCommonIdManager.Type.IdAndUniqueName, null);
  97. ManData.basicDatas = new Dictionary<int, ManData.Data>();
  98. string[] array = new string[]
  99. {
  100. "list"
  101. };
  102. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  103. for (int i = 0; i < array2.Length; i++)
  104. {
  105. string text = "kasizuki_man_" + array[i] + ".nei";
  106. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  107. CsvParser csvParser = new CsvParser();
  108. bool condition = csvParser.Open(afileBase);
  109. NDebug.Assert(condition, text + "\nopen failed.");
  110. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  111. }
  112. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in ManData.commonIdManager.idMap)
  113. {
  114. int key = keyValuePair.Key;
  115. ManData.Data value = new ManData.Data(key, array2[0].Value);
  116. ManData.basicDatas.Add(key, value);
  117. }
  118. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
  119. {
  120. keyValuePair2.Value.Dispose();
  121. keyValuePair2.Key.Dispose();
  122. }
  123. }
  124. private const string csvTopCommonName = "kasizuki_man";
  125. private const string typeNameForErrorLog = "傅き.男データ";
  126. private static CsvCommonIdManager commonIdManager;
  127. private static Dictionary<int, ManData.Data> basicDatas;
  128. public class Data
  129. {
  130. public Data(int uniqueID, CsvParser csv)
  131. {
  132. for (int i = 1; i < csv.max_cell_y; i++)
  133. {
  134. if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
  135. {
  136. int num = 1;
  137. this.ID = uniqueID;
  138. this.uniqueName = csv.GetCellAsString(num++, i);
  139. this.drawName = csv.GetCellAsString(num++, i);
  140. this.modelResourceName = csv.GetCellAsString(num++, i);
  141. this.profileText = csv.GetCellAsString(num++, i);
  142. this.favoritePlayText = csv.GetCellAsString(num++, i);
  143. try
  144. {
  145. this.manType = (ManDataType)Enum.ToObject(typeof(ManDataType), this.ID);
  146. }
  147. catch (Exception e)
  148. {
  149. NDebug.AssertParseError("ManDataType", e);
  150. }
  151. }
  152. }
  153. }
  154. public readonly int ID;
  155. public readonly string uniqueName;
  156. public readonly string drawName;
  157. public readonly string modelResourceName;
  158. public readonly string profileText;
  159. public readonly string favoritePlayText;
  160. public readonly ManDataType manType;
  161. }
  162. }
  163. }