TextureData.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Collections.Generic;
  3. using wf;
  4. namespace MyRoomCustom
  5. {
  6. public static class TextureData
  7. {
  8. public static int Count
  9. {
  10. get
  11. {
  12. TextureData.CreateData();
  13. return TextureData.commonIdManager.idMap.Count;
  14. }
  15. }
  16. public static bool Contains(int id)
  17. {
  18. TextureData.CreateData();
  19. return TextureData.commonIdManager.idMap.ContainsKey(id);
  20. }
  21. public static TextureData.Data GetData(int id)
  22. {
  23. TextureData.CreateData();
  24. NDebug.Assert(TextureData.basicDatas.ContainsKey(id), "自室カスタム.壁紙系テクスチャ\nID[" + id + "]のデータは存在しません");
  25. return TextureData.basicDatas[id];
  26. }
  27. public static bool IsEnabled(int id)
  28. {
  29. TextureData.CreateData();
  30. return TextureData.commonIdManager.enabledIdList.Contains(id);
  31. }
  32. public static List<TextureData.Data> GetAllDatas(bool onlyEnabled)
  33. {
  34. TextureData.CreateData();
  35. List<TextureData.Data> list = new List<TextureData.Data>();
  36. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in TextureData.commonIdManager.idMap)
  37. {
  38. if (!onlyEnabled || TextureData.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  39. {
  40. list.Add(TextureData.basicDatas[keyValuePair.Key]);
  41. }
  42. }
  43. return list;
  44. }
  45. public static List<TextureData.Data> GetDatas(Func<TextureData.Data, bool> customCheckFunction)
  46. {
  47. TextureData.CreateData();
  48. List<TextureData.Data> list = new List<TextureData.Data>();
  49. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in TextureData.commonIdManager.idMap)
  50. {
  51. TextureData.Data data = TextureData.basicDatas[keyValuePair.Key];
  52. if (customCheckFunction(data))
  53. {
  54. list.Add(data);
  55. }
  56. }
  57. return list;
  58. }
  59. public static void CreateData()
  60. {
  61. if (TextureData.commonIdManager != null)
  62. {
  63. return;
  64. }
  65. TextureData.commonIdManager = new CsvCommonIdManager("my_room_texture_panel", "自室カスタム.壁紙系テクスチャ", CsvCommonIdManager.Type.IdOnly, null);
  66. TextureData.basicDatas = new Dictionary<int, TextureData.Data>();
  67. string[] array = new string[]
  68. {
  69. "list"
  70. };
  71. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  72. for (int i = 0; i < array2.Length; i++)
  73. {
  74. string text = "my_room_texture_panel_" + array[i] + ".nei";
  75. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  76. CsvParser csvParser = new CsvParser();
  77. bool condition = csvParser.Open(afileBase);
  78. NDebug.Assert(condition, text + "\nopen failed.");
  79. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  80. }
  81. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in TextureData.commonIdManager.idMap)
  82. {
  83. int key = keyValuePair.Key;
  84. TextureData.Data value = new TextureData.Data(key, array2[0].Value);
  85. TextureData.basicDatas.Add(key, value);
  86. }
  87. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
  88. {
  89. keyValuePair2.Value.Dispose();
  90. keyValuePair2.Key.Dispose();
  91. }
  92. }
  93. public static void Clear()
  94. {
  95. if (TextureData.commonIdManager != null)
  96. {
  97. TextureData.commonIdManager = null;
  98. }
  99. }
  100. private const string csvTopCommonName = "my_room_texture_panel";
  101. private const string typeNameForErrorLog = "自室カスタム.壁紙系テクスチャ";
  102. private static CsvCommonIdManager commonIdManager;
  103. private static Dictionary<int, TextureData.Data> basicDatas;
  104. public class Data
  105. {
  106. public Data(int uniqueID, CsvParser csv)
  107. {
  108. for (int i = 1; i < csv.max_cell_y; i++)
  109. {
  110. if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
  111. {
  112. int num = 1;
  113. this.ID = uniqueID;
  114. this.drawName = csv.GetCellAsString(num++, i);
  115. this.resourceName = csv.GetCellAsString(num++, i);
  116. }
  117. }
  118. }
  119. public readonly int ID;
  120. public readonly string drawName;
  121. public readonly string resourceName;
  122. }
  123. }
  124. }