123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- 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<EditCharacterDatabase.Data> GetAllDatas(bool onlyEnabled)
- {
- EditCharacterDatabase.CreateData();
- List<EditCharacterDatabase.Data> list = new List<EditCharacterDatabase.Data>();
- foreach (KeyValuePair<int, KeyValuePair<string, string>> 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<int, EditCharacterDatabase.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 = "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>(afileBase, csvParser);
- }
- foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in EditCharacterDatabase.commonIdManager.idMap)
- {
- EditCharacterDatabase.basicDatas.Add(keyValuePair.Key, new EditCharacterDatabase.Data(keyValuePair.Key, array2[0].Value));
- }
- foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
- {
- keyValuePair2.Value.Dispose();
- keyValuePair2.Key.Dispose();
- }
- HashSet<int> hashSet = new HashSet<int>();
- 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<int, KeyValuePair<string, string>>(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<int, EditCharacterDatabase.Data> 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<CharacterMgr.NpcData> list = new List<CharacterMgr.NpcData>();
- 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;
- }
- }
- }
|