Constants.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEngine;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. namespace COM3D2.MeidoPhotoStudio.Plugin
  9. {
  10. public class Constants
  11. {
  12. public static readonly string customPosePath;
  13. public static readonly string scenesPath;
  14. public static readonly string kankyoPath;
  15. public static readonly string configPath;
  16. public static readonly int mainWindowID = 765;
  17. public static readonly int messageWindowID = 961;
  18. public static readonly int sceneManagerWindowID = 876;
  19. public static readonly int sceneManagerModalID = 283;
  20. public static readonly int dropdownWindowID = 777;
  21. public enum Window
  22. {
  23. Call, Pose, Face, BG, BG2, Message, Save, SaveModal
  24. }
  25. public enum Scene
  26. {
  27. Daily = 3, Edit = 5
  28. }
  29. public static readonly List<string> PoseGroupList;
  30. public static readonly Dictionary<string, List<string>> PoseDict;
  31. public static readonly Dictionary<string, List<KeyValuePair<string, string>>> CustomPoseDict;
  32. public static int CustomPoseGroupsIndex { get; private set; }
  33. public static readonly List<string> FaceBlendList;
  34. public static readonly List<string> BGList;
  35. static Constants()
  36. {
  37. string modsPath = Path.Combine(Path.GetFullPath(".\\"), @"Mod\MeidoPhotoStudio");
  38. customPosePath = Path.Combine(modsPath, "Custom Poses");
  39. scenesPath = Path.Combine(modsPath, "Scenes");
  40. kankyoPath = Path.Combine(modsPath, "Environments");
  41. configPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"Config\MeidoPhotoStudio");
  42. PoseDict = new Dictionary<string, List<string>>();
  43. PoseGroupList = new List<string>();
  44. CustomPoseDict = new Dictionary<string, List<KeyValuePair<string, string>>>();
  45. FaceBlendList = new List<string>();
  46. BGList = new List<string>();
  47. }
  48. public static void Initialize()
  49. {
  50. foreach (string dir in new[] { customPosePath, scenesPath, kankyoPath, configPath })
  51. {
  52. if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
  53. }
  54. // Load Poses
  55. string poseListJson = File.ReadAllText(Path.Combine(configPath, "mm_pose_list.json"));
  56. List<SerializePoseList> poseLists = JsonConvert.DeserializeObject<List<SerializePoseList>>(poseListJson);
  57. foreach (SerializePoseList poseList in poseLists)
  58. {
  59. PoseDict[poseList.UIName] = poseList.PoseList;
  60. PoseGroupList.Add(poseList.UIName);
  61. CustomPoseGroupsIndex++;
  62. }
  63. Action<string> GetPoses = (directory) =>
  64. {
  65. List<KeyValuePair<string, string>> poseList = new List<KeyValuePair<string, string>>();
  66. foreach (string file in Directory.GetFiles(directory))
  67. {
  68. if (Path.GetExtension(file) == ".anm")
  69. {
  70. string fileName = Path.GetFileNameWithoutExtension(file);
  71. poseList.Add(new KeyValuePair<string, string>(fileName, file));
  72. }
  73. }
  74. if (poseList.Count > 0)
  75. {
  76. string poseGroupName = new DirectoryInfo(directory).Name;
  77. PoseGroupList.Add(poseGroupName);
  78. CustomPoseDict[poseGroupName] = poseList;
  79. }
  80. };
  81. GetPoses(customPosePath);
  82. // TODO: Get rest of poses
  83. foreach (string directory in Directory.GetDirectories(customPosePath))
  84. {
  85. GetPoses(directory);
  86. }
  87. // Load Face Blends Presets
  88. using (CsvParser csvParser = OpenCsvParser("phot_face_list.nei"))
  89. {
  90. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  91. {
  92. if (csvParser.IsCellToExistData(3, cell_y))
  93. {
  94. string blendValue = csvParser.GetCellAsString(3, cell_y);
  95. FaceBlendList.Add(blendValue);
  96. }
  97. }
  98. }
  99. // Load BGs
  100. PhotoBGData.Create();
  101. List<PhotoBGData> photList = PhotoBGData.data;
  102. // COM3D2 BGs
  103. foreach (PhotoBGData bgData in photList)
  104. {
  105. if (!string.IsNullOrEmpty(bgData.create_prefab_name))
  106. {
  107. string bg = bgData.create_prefab_name;
  108. BGList.Add(bg);
  109. }
  110. }
  111. // CM3D2 BGs
  112. if (GameUty.IsEnabledCompatibilityMode)
  113. {
  114. using (CsvParser csvParser = OpenCsvParser("phot_bg_list.nei", GameUty.FileSystemOld))
  115. {
  116. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  117. {
  118. if (csvParser.IsCellToExistData(3, cell_y))
  119. {
  120. string bg = csvParser.GetCellAsString(3, cell_y);
  121. BGList.Add(bg);
  122. }
  123. }
  124. }
  125. }
  126. }
  127. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  128. {
  129. try
  130. {
  131. if (fs.IsExistentFile(nei))
  132. {
  133. AFileBase file = fs.FileOpen(nei);
  134. CsvParser csvParser = new CsvParser();
  135. if (csvParser.Open(file)) return csvParser;
  136. }
  137. }
  138. catch { }
  139. return null;
  140. }
  141. private static CsvParser OpenCsvParser(string nei)
  142. {
  143. return OpenCsvParser(nei, GameUty.FileSystem);
  144. }
  145. public class SerializePoseList
  146. {
  147. public string UIName { get; set; }
  148. public List<string> PoseList { get; set; }
  149. }
  150. }
  151. public static class Translation
  152. {
  153. public static Dictionary<string, Dictionary<string, string>> Translations;
  154. public static string CurrentLanguage { get; set; }
  155. public static void Initialize(string language)
  156. {
  157. CurrentLanguage = language;
  158. string translationFile = $"translations.{language}.json";
  159. string translationPath = Path.Combine(Constants.configPath, translationFile);
  160. string translationJson = File.ReadAllText(translationPath);
  161. JObject translation = JObject.Parse(translationJson);
  162. Translations = new Dictionary<string, Dictionary<string, string>>(StringComparer.InvariantCultureIgnoreCase);
  163. foreach (JProperty translationProp in translation.AsJEnumerable())
  164. {
  165. JToken token = translationProp.Value;
  166. Translations[translationProp.Path] = token.ToObject<Dictionary<string, string>>();
  167. }
  168. }
  169. public static string Get(string category, string text)
  170. {
  171. if (!Translations.ContainsKey(category))
  172. {
  173. Debug.LogWarning($"Could not find category '{category}'");
  174. return null;
  175. }
  176. if (!Translations[category].ContainsKey(text))
  177. {
  178. Debug.LogWarning($"Could not find translation for '{text}'");
  179. return null;
  180. }
  181. return Translations[category][text];
  182. }
  183. public static string[] GetList(string category, IEnumerable<string> list)
  184. {
  185. return list.Select(uiName => Get(category, uiName) ?? uiName).ToArray();
  186. }
  187. public static string[] GetList(string category, IEnumerable<KeyValuePair<string, string>> list)
  188. {
  189. return list.Select(kvp => Get(category, kvp.Key) ?? kvp.Key).ToArray();
  190. }
  191. }
  192. }