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

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

		public static bool Contains(int id)
		{
			TextureData.CreateData();
			return TextureData.commonIdManager.idMap.ContainsKey(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.commonIdManager.enabledIdList.Contains(id);
		}

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

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

		public static void CreateData()
		{
			if (TextureData.commonIdManager != null)
			{
				return;
			}
			TextureData.commonIdManager = new CsvCommonIdManager("my_room_texture_panel", "自室カスタム.壁紙系テクスチャ", CsvCommonIdManager.Type.IdOnly, null);
			TextureData.basicDatas = new Dictionary<int, TextureData.Data>();
			string[] array = new string[]
			{
				"list"
			};
			KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				string text = "my_room_texture_panel_" + array[i] + ".nei";
				AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
				CsvParser csvParser = new CsvParser();
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, text + "\nopen failed.");
				array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
			}
			foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in TextureData.commonIdManager.idMap)
			{
				int key = keyValuePair.Key;
				TextureData.Data value = new TextureData.Data(key, array2[0].Value);
				TextureData.basicDatas.Add(key, value);
			}
			foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
			{
				keyValuePair2.Value.Dispose();
				keyValuePair2.Key.Dispose();
			}
		}

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

		private const string csvTopCommonName = "my_room_texture_panel";

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

		private static CsvCommonIdManager commonIdManager;

		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;
		}
	}
}
