Feature.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using wf;
  4. namespace MaidStatus
  5. {
  6. public static class Feature
  7. {
  8. public static int Count
  9. {
  10. get
  11. {
  12. Feature.CreateData();
  13. return Feature.commonIdManager.idMap.Count;
  14. }
  15. }
  16. public static bool Contains(string name)
  17. {
  18. return Feature.commonIdManager.nameMap.ContainsKey(name);
  19. }
  20. public static bool Contains(int id)
  21. {
  22. return Feature.commonIdManager.idMap.ContainsKey(id);
  23. }
  24. public static int uniqueNameToId(string name)
  25. {
  26. Feature.CreateData();
  27. NDebug.Assert(Feature.commonIdManager.nameMap.ContainsKey(name), "特徴\nユニーク名[" + name + "]をIDに変換できませんでした");
  28. return Feature.commonIdManager.nameMap[name];
  29. }
  30. public static string IdToUniqueName(int id)
  31. {
  32. Feature.CreateData();
  33. NDebug.Assert(Feature.commonIdManager.idMap.ContainsKey(id), "特徴\nID[" + id + "]をユニーク名に変換できませんでした");
  34. return Feature.commonIdManager.idMap[id].Key;
  35. }
  36. public static Feature.Data GetData(int id)
  37. {
  38. Feature.CreateData();
  39. NDebug.Assert(Feature.basicDatas.ContainsKey(id), "特徴\nID[" + id + "]のデータは存在しません");
  40. return Feature.basicDatas[id];
  41. }
  42. public static Feature.Data GetData(string uniqueName)
  43. {
  44. return Feature.GetData(Feature.uniqueNameToId(uniqueName));
  45. }
  46. public static bool IsEnabled(string uniqueName)
  47. {
  48. Feature.CreateData();
  49. return Feature.commonIdManager.enabledIdList.Contains(Feature.uniqueNameToId(uniqueName));
  50. }
  51. public static bool IsEnabled(int id)
  52. {
  53. Feature.CreateData();
  54. return Feature.commonIdManager.enabledIdList.Contains(id);
  55. }
  56. public static List<Feature.Data> GetAllDatas(bool onlyEnabled)
  57. {
  58. Feature.CreateData();
  59. List<Feature.Data> list = new List<Feature.Data>();
  60. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in Feature.commonIdManager.idMap)
  61. {
  62. if (!onlyEnabled || Feature.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  63. {
  64. list.Add(Feature.basicDatas[keyValuePair.Key]);
  65. }
  66. }
  67. return list;
  68. }
  69. public static void CreateData()
  70. {
  71. if (Feature.commonIdManager != null)
  72. {
  73. return;
  74. }
  75. Feature.commonIdManager = new CsvCommonIdManager("maid_status_feature", "特徴", CsvCommonIdManager.Type.IdAndUniqueName, null);
  76. Feature.basicDatas = new Dictionary<int, Feature.Data>();
  77. string[] array = new string[]
  78. {
  79. "list",
  80. "correction"
  81. };
  82. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  83. for (int i = 0; i < array2.Length; i++)
  84. {
  85. string text = "maid_status_feature_" + array[i] + ".nei";
  86. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  87. CsvParser csvParser = new CsvParser();
  88. bool condition = csvParser.Open(afileBase);
  89. NDebug.Assert(condition, text + "\nopen failed.");
  90. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  91. }
  92. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in Feature.commonIdManager.idMap)
  93. {
  94. Feature.basicDatas.Add(keyValuePair.Key, new Feature.Data(keyValuePair.Key, array2[0].Value, array2[1].Value));
  95. }
  96. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
  97. {
  98. keyValuePair2.Value.Dispose();
  99. keyValuePair2.Key.Dispose();
  100. }
  101. }
  102. private const string csvTopCommonName = "maid_status_feature";
  103. private const string typeNameForErrorLog = "特徴";
  104. public const string termRootText = "MaidStatus/特徴タイプ/";
  105. private static CsvCommonIdManager commonIdManager;
  106. private static Dictionary<int, Feature.Data> basicDatas;
  107. public class Data
  108. {
  109. public Data(int id, CsvParser basicCsv, CsvParser bonusCorrectionCsv)
  110. {
  111. for (int i = 1; i < basicCsv.max_cell_y; i++)
  112. {
  113. if (basicCsv.IsCellToExistData(0, i) && basicCsv.GetCellAsInteger(0, i) == id)
  114. {
  115. int num = 1;
  116. this.id = id;
  117. this.uniqueName = basicCsv.GetCellAsString(num++, i);
  118. this.drawName = basicCsv.GetCellAsString(num++, i);
  119. break;
  120. }
  121. }
  122. for (int j = 1; j < bonusCorrectionCsv.max_cell_y; j++)
  123. {
  124. if (bonusCorrectionCsv.IsCellToExistData(0, j) && bonusCorrectionCsv.GetCellAsInteger(0, j) == id)
  125. {
  126. int num2 = 1;
  127. this.bonusCorrection = new ParametersPack();
  128. this.bonusCorrection.Parse(bonusCorrectionCsv.GetCellAsString(num2++, j), ',');
  129. break;
  130. }
  131. }
  132. }
  133. public string termName
  134. {
  135. get
  136. {
  137. return "MaidStatus/特徴タイプ/" + this.uniqueName;
  138. }
  139. }
  140. public readonly int id;
  141. public readonly string uniqueName;
  142. public readonly string drawName;
  143. public readonly ParametersPack bonusCorrection;
  144. }
  145. }
  146. }