TextureData.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.enabledIDList.Count;
  14. }
  15. }
  16. public static bool Contains(int id)
  17. {
  18. TextureData.CreateData();
  19. return TextureData.enabledIDList.Contains(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.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, TextureData.Data> keyValuePair in TextureData.basicDatas)
  37. {
  38. if (!onlyEnabled || TextureData.enabledIDList.Contains(keyValuePair.Key))
  39. {
  40. list.Add(keyValuePair.Value);
  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 (int key in TextureData.enabledIDList)
  50. {
  51. TextureData.Data data = TextureData.basicDatas[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.enabledIDList != null)
  62. {
  63. return;
  64. }
  65. TextureData.basicDatas = new Dictionary<int, TextureData.Data>();
  66. TextureData.enabledIDList = new HashSet<int>();
  67. CsvCommonIdManager.ReadEnabledIdList(CsvCommonIdManager.FileSystemType.Normal, true, "my_room_texture_panel_enabled_list", ref TextureData.enabledIDList);
  68. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("my_room_texture_panel_list.nei"))
  69. {
  70. using (CsvParser csvParser = new CsvParser())
  71. {
  72. bool condition = csvParser.Open(afileBase);
  73. NDebug.Assert(condition, "my_room_texture_panel_list\nopen failed.");
  74. foreach (int num in TextureData.enabledIDList)
  75. {
  76. TextureData.Data value = new TextureData.Data(num, csvParser);
  77. TextureData.basicDatas.Add(num, value);
  78. }
  79. }
  80. }
  81. }
  82. public static void Clear()
  83. {
  84. if (TextureData.enabledIDList != null)
  85. {
  86. TextureData.enabledIDList = null;
  87. }
  88. }
  89. private const string csvTopCommonName = "my_room_texture_panel";
  90. private const string typeNameForErrorLog = "自室カスタム.壁紙系テクスチャ";
  91. private static HashSet<int> enabledIDList;
  92. private static Dictionary<int, TextureData.Data> basicDatas;
  93. public class Data
  94. {
  95. public Data(int uniqueID, CsvParser csv)
  96. {
  97. for (int i = 1; i < csv.max_cell_y; i++)
  98. {
  99. if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
  100. {
  101. int num = 1;
  102. this.ID = uniqueID;
  103. this.drawName = csv.GetCellAsString(num++, i);
  104. this.resourceName = csv.GetCellAsString(num++, i);
  105. }
  106. }
  107. }
  108. public readonly int ID;
  109. public readonly string drawName;
  110. public readonly string resourceName;
  111. }
  112. }
  113. }