using System;
using System.Collections.Generic;
using wf;

namespace MyRoomCustom
{
	public static class TextureData
	{
		public static int Count
		{
			get
			{
				TextureData.CreateData();
				return TextureData.enabledIDList.Count;
			}
		}

		public static bool Contains(int id)
		{
			TextureData.CreateData();
			return TextureData.enabledIDList.Contains(id);
		}

		public static TextureData.Data GetData(int id)
		{
			TextureData.CreateData();
			NDebug.Assert(TextureData.basicDatas.ContainsKey(id), "自室カスタム.壁紙系テクスチャ\nID[" + id + "]のデータは存在しません");
			return TextureData.basicDatas[id];
		}

		public static bool IsEnabled(int id)
		{
			TextureData.CreateData();
			return TextureData.enabledIDList.Contains(id);
		}

		public static List<TextureData.Data> GetAllDatas(bool onlyEnabled)
		{
			TextureData.CreateData();
			List<TextureData.Data> list = new List<TextureData.Data>();
			foreach (KeyValuePair<int, TextureData.Data> keyValuePair in TextureData.basicDatas)
			{
				if (!onlyEnabled || TextureData.enabledIDList.Contains(keyValuePair.Key))
				{
					list.Add(keyValuePair.Value);
				}
			}
			return list;
		}

		public static List<TextureData.Data> GetDatas(Func<TextureData.Data, bool> customCheckFunction)
		{
			TextureData.CreateData();
			List<TextureData.Data> list = new List<TextureData.Data>();
			foreach (int key in TextureData.enabledIDList)
			{
				TextureData.Data data = TextureData.basicDatas[key];
				if (customCheckFunction(data))
				{
					list.Add(data);
				}
			}
			return list;
		}

		public static void CreateData()
		{
			if (TextureData.enabledIDList != null)
			{
				return;
			}
			TextureData.basicDatas = new Dictionary<int, TextureData.Data>();
			TextureData.enabledIDList = new HashSet<int>();
			CsvCommonIdManager.ReadEnabledIdList(CsvCommonIdManager.FileSystemType.Normal, true, "my_room_texture_panel_enabled_list", ref TextureData.enabledIDList);
			using (AFileBase afileBase = GameUty.FileSystem.FileOpen("my_room_texture_panel_list.nei"))
			{
				using (CsvParser csvParser = new CsvParser())
				{
					bool condition = csvParser.Open(afileBase);
					NDebug.Assert(condition, "my_room_texture_panel_list\nopen failed.");
					foreach (int num in TextureData.enabledIDList)
					{
						TextureData.Data value = new TextureData.Data(num, csvParser);
						TextureData.basicDatas.Add(num, value);
					}
				}
			}
		}

		public static void Clear()
		{
			if (TextureData.enabledIDList != null)
			{
				TextureData.enabledIDList = null;
			}
		}

		private const string csvTopCommonName = "my_room_texture_panel";

		private const string typeNameForErrorLog = "自室カスタム.壁紙系テクスチャ";

		private static HashSet<int> enabledIDList;

		private static Dictionary<int, TextureData.Data> basicDatas;

		public class Data
		{
			public Data(int uniqueID, CsvParser csv)
			{
				for (int i = 1; i < csv.max_cell_y; i++)
				{
					if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
					{
						int num = 1;
						this.ID = uniqueID;
						this.drawName = csv.GetCellAsString(num++, i);
						this.resourceName = csv.GetCellAsString(num++, i);
					}
				}
			}

			public readonly int ID;

			public readonly string drawName;

			public readonly string resourceName;
		}
	}
}
