using System; using System.Collections.Generic; using System.IO; using System.Text; using UnityEngine; using wf; namespace SceneNPCEdit { public static class EditCharacterDatabase { public static int Count { get { EditCharacterDatabase.CreateData(); return EditCharacterDatabase.commonIdManager.idMap.Count; } } public static bool Contains(int id) { return EditCharacterDatabase.commonIdManager.idMap.ContainsKey(id); } public static EditCharacterDatabase.Data GetData(int id) { EditCharacterDatabase.CreateData(); NDebug.Assert(EditCharacterDatabase.basicDatas.ContainsKey(id), "NPCエディット\nID[" + id + "]のデータは存在しません"); return EditCharacterDatabase.basicDatas[id]; } public static bool IsEnabled(int id) { EditCharacterDatabase.CreateData(); return EditCharacterDatabase.commonIdManager.enabledIdList.Contains(id); } public static List GetAllDatas(bool onlyEnabled) { EditCharacterDatabase.CreateData(); List list = new List(); foreach (KeyValuePair> keyValuePair in EditCharacterDatabase.commonIdManager.idMap) { if (!onlyEnabled || EditCharacterDatabase.commonIdManager.enabledIdList.Contains(keyValuePair.Key)) { list.Add(EditCharacterDatabase.basicDatas[keyValuePair.Key]); } } return list; } public static void CreateData() { if (EditCharacterDatabase.commonIdManager != null) { return; } EditCharacterDatabase.commonIdManager = new CsvCommonIdManager("npcedit", "NPCエディット", CsvCommonIdManager.Type.IdOnly, null); EditCharacterDatabase.basicDatas = new Dictionary(); string[] array = new string[] { "list" }; KeyValuePair[] array2 = new KeyValuePair[array.Length]; for (int i = 0; i < array2.Length; i++) { string text = "npcedit_" + 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); } foreach (KeyValuePair> keyValuePair in EditCharacterDatabase.commonIdManager.idMap) { EditCharacterDatabase.basicDatas.Add(keyValuePair.Key, new EditCharacterDatabase.Data(keyValuePair.Key, array2[0].Value)); } foreach (KeyValuePair keyValuePair2 in array2) { keyValuePair2.Value.Dispose(); keyValuePair2.Key.Dispose(); } HashSet hashSet = new HashSet(); foreach (int num in EditCharacterDatabase.commonIdManager.enabledIdList) { EditCharacterDatabase.Data data = EditCharacterDatabase.GetData(num); if (string.IsNullOrEmpty(data.checkPluginName) || PluginData.IsEnabled(data.checkPluginName)) { if (data.checkLoadFolders != null && 0 < data.checkLoadFolders.Length) { bool flag = false; foreach (string item in data.checkLoadFolders) { if (GameUty.loadArchiveList.Contains(item)) { flag = true; } } if (!flag) { continue; } } hashSet.Add(num); } } EditCharacterDatabase.commonIdManager = new CsvCommonIdManager(new Dictionary>(EditCharacterDatabase.commonIdManager.idMap), EditCharacterDatabase.commonIdManager.nameMap, hashSet, CsvCommonIdManager.Type.IdOnly); } private const string csvTopCommonName = "npcedit"; private const string typeNameForErrorLog = "NPCエディット"; private static CsvCommonIdManager commonIdManager; private static Dictionary basicDatas; public class Data { public Data(int id, CsvParser basicCsv) { for (int i = 1; i < basicCsv.max_cell_y; i++) { if (basicCsv.IsCellToExistData(0, i) && basicCsv.GetCellAsInteger(0, i) == id) { int num = 1; this.id = id; string cellAsString = basicCsv.GetCellAsString(num++, i); if (CharacterMgr.npcDatas.ContainsKey(cellAsString)) { if (!CharacterMgr.npcDatas.ContainsKey(cellAsString)) { Debug.LogError("NPCエディットエラー ユニーク名[" + cellAsString + "]のキャラプリセットが存在しません"); } this.npcData = CharacterMgr.npcDatas[cellAsString]; } this.isCBLEnabled = (basicCsv.GetCellAsString(num++, i) == "〇"); this.checkPluginName = basicCsv.GetCellAsString(num++, i); string cellAsString2 = basicCsv.GetCellAsString(num++, i); if (!string.IsNullOrEmpty(cellAsString2)) { this.checkLoadFolders = cellAsString2.Split(new char[] { '|' }); } else { this.checkLoadFolders = new string[0]; } string cellAsString3 = basicCsv.GetCellAsString(num++, i); if (!string.IsNullOrEmpty(cellAsString3)) { List list = new List(); list.Add(this.npcData); foreach (string text in cellAsString3.Split(new char[] { '|' })) { if (!CharacterMgr.npcDatas.ContainsKey(text)) { Debug.LogError("NPCエディットエラー ユニーク名[" + text + "]のキャラプリセットが存在しません"); } list.Add(CharacterMgr.npcDatas[text]); } this.overRideTargetNpc = list.ToArray(); } else { this.overRideTargetNpc = new CharacterMgr.NpcData[] { this.npcData }; } this.additionalInformationText = basicCsv.GetCellAsString(num++, i); this.additionalInformationTextForCBL = basicCsv.GetCellAsString(num++, i); } } } public Texture2D GetThumbnail() { if (this.npcData.isResourcesLoad) { return GameMain.Instance.CharacterMgr.PresetLoadFromResources(this.npcData.presetFileName).texThum; } using (AFileBase afileBase = GameUty.FileOpen(this.npcData.presetFileName + ".preset", null)) { if (afileBase != null && afileBase.IsValid()) { byte[] buffer = afileBase.ReadAll(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer), Encoding.UTF8)) { return GameMain.Instance.CharacterMgr.PresetLoad(binaryReader, this.npcData.presetFileName).texThum; } } } return null; } public string firstNameTerm { get { return "SceneNPCEdit/" + this.id.ToString() + "/名前"; } } public string lastNameTerm { get { return "SceneNPCEdit/" + this.id.ToString() + "/苗字"; } } public string informationTerm { get { return "SceneNPCEdit/" + this.id.ToString() + "/説明"; } } public readonly int id; public readonly CharacterMgr.NpcData npcData; public readonly bool isCBLEnabled; public readonly string checkPluginName; public readonly string[] checkLoadFolders; public readonly string additionalInformationText; public readonly string additionalInformationTextForCBL; public readonly CharacterMgr.NpcData[] overRideTargetNpc; } } }