ItemData.cs 4.5 KB

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