From 662ee9f86555b7442e6299137a3a97ffd66f019f Mon Sep 17 00:00:00 2001 From: katboi01 <59540382+katboi01@users.noreply.github.com> Date: Wed, 28 Dec 2022 14:29:18 +0100 Subject: [PATCH] Config file Configurable file path, language. --- .gitignore | 1 + .../Audio/CRIMW/CriScript/LoadSound.cs | 4 +- Assets/Scripts/Config.cs | 48 +++++++++++++++++++ Assets/Scripts/Config.cs.meta | 11 +++++ Assets/Scripts/Manifest/ManifestDB.cs | 2 +- Assets/Scripts/UmaDatabase/UmaDataTypes.cs | 1 + .../UmaDatabase/UmaDatabaseController.cs | 25 ++-------- Assets/Scripts/UmaViewerBuilder.cs | 12 ++--- Assets/Scripts/UmaViewerMain.cs | 23 +++++---- Assets/Scripts/UmaViewerUI.cs | 2 +- 10 files changed, 88 insertions(+), 41 deletions(-) create mode 100644 Assets/Scripts/Config.cs create mode 100644 Assets/Scripts/Config.cs.meta diff --git a/.gitignore b/.gitignore index cf16bff..a497701 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ crashlytics-build.properties /Assets/Plugins/RootMotion/PuppetMaster/_Integration /VMDRecords /umamusume +Config.json diff --git a/Assets/Scripts/Audio/CRIMW/CriScript/LoadSound.cs b/Assets/Scripts/Audio/CRIMW/CriScript/LoadSound.cs index 3c38585..30477f9 100644 --- a/Assets/Scripts/Audio/CRIMW/CriScript/LoadSound.cs +++ b/Assets/Scripts/Audio/CRIMW/CriScript/LoadSound.cs @@ -15,8 +15,8 @@ public class LoadSound : ScriptableObject public UmaSoundInfo getSoundPath(string name) { UmaSoundInfo info; - info.acbPath = UmaDatabaseController.GetABPath(Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("acb"))); - info.awbPath = UmaDatabaseController.GetABPath(Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("awb"))); + info.acbPath = Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("acb")).FilePath; + info.awbPath = Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("awb")).FilePath; return info; } diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs new file mode 100644 index 0000000..d0e1cd1 --- /dev/null +++ b/Assets/Scripts/Config.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +public class Config +{ + public static Config Instance; + public string Version = ""; + public string LanguageTip = "Affects Uma names on the list. Language options: 0 - En, 1 - Jp"; + public Language Language = Language.En; + public string MainPathTip = "Path to game folder, eg. D:\\Backup\\Cygames\\umamusume or D:/Backup/Cygames/umamusume"; + public string MainPath = ""; + + public Config() + { + //TODO: Updating config file + Version = Application.version; + string configPath = Application.dataPath + "/../Config.json"; + + MainPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume"; + if (!File.Exists(configPath)) + { + File.WriteAllText(configPath, JsonUtility.ToJson(this, true)); + } + else + { + try + { + JsonUtility.FromJsonOverwrite(File.ReadAllText(configPath), this); + } + catch (Exception ex) + { + UmaViewerUI.Instance.LyricsText.text = "Config load error. Using default path. " + ex.Message; + MainPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume"; + } + } + + Instance = this; + } +} + +public enum Language +{ + En, + Jp +} \ No newline at end of file diff --git a/Assets/Scripts/Config.cs.meta b/Assets/Scripts/Config.cs.meta new file mode 100644 index 0000000..baaf0d2 --- /dev/null +++ b/Assets/Scripts/Config.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: be06b6cd776f04146a28ef529c501dc7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Manifest/ManifestDB.cs b/Assets/Scripts/Manifest/ManifestDB.cs index 4c6f9a2..ba8e3d4 100644 --- a/Assets/Scripts/Manifest/ManifestDB.cs +++ b/Assets/Scripts/Manifest/ManifestDB.cs @@ -17,7 +17,7 @@ public class ManifestDB public ManifestDB() { - string DBPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\\Cygames\\umamusume\\meta"; + string DBPath = $"{Config.Instance.MainPath}\\meta"; ManifestDB.DBPath = DBPath; if (File.Exists(DBPath)) { diff --git a/Assets/Scripts/UmaDatabase/UmaDataTypes.cs b/Assets/Scripts/UmaDatabase/UmaDataTypes.cs index 3ba085f..290bf50 100644 --- a/Assets/Scripts/UmaDatabase/UmaDataTypes.cs +++ b/Assets/Scripts/UmaDatabase/UmaDataTypes.cs @@ -11,6 +11,7 @@ public class UmaDatabaseEntry public string Url; public string Checksum; public string Prerequisites; + public string FilePath => $"{Config.Instance.MainPath}\\dat\\{Url.Substring(0, 2)}\\{Url}"; } public class UmaCharaData diff --git a/Assets/Scripts/UmaDatabase/UmaDatabaseController.cs b/Assets/Scripts/UmaDatabase/UmaDatabaseController.cs index e508507..a8d2e9b 100644 --- a/Assets/Scripts/UmaDatabase/UmaDatabaseController.cs +++ b/Assets/Scripts/UmaDatabase/UmaDatabaseController.cs @@ -53,8 +53,8 @@ public class UmaDatabaseController { try { - metaDb = new SqliteConnection($@"Data Source={Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume\meta;"); - masterDb = new SqliteConnection($@"Data Source={Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\Cygames\umamusume\master\master.mdb;"); + metaDb = new SqliteConnection($@"Data Source={Config.Instance.MainPath}\meta;"); + masterDb = new SqliteConnection($@"Data Source={Config.Instance.MainPath}\master\master.mdb;"); metaDb.Open(); MetaEntries = ReadMeta(metaDb); @@ -66,7 +66,7 @@ public class UmaDatabaseController } catch { - UmaViewerUI.Instance.LyricsText.text = $"Database not found: \n{GetGameRootPath()}/meta\n{GetGameRootPath()}/master/master.mdb"; + UmaViewerUI.Instance.LyricsText.text = $"Database not found: \n{Config.Instance.MainPath}/meta\n{Config.Instance.MainPath}/master/master.mdb"; UmaViewerUI.Instance.LyricsText.color = Color.red; } } @@ -158,23 +158,4 @@ public class UmaDatabaseController DataRow row = result.Rows[0]; return row; } - - public static string GetABPath(UmaDatabaseEntry entry) - { - if (Application.platform == RuntimePlatform.Android) - { - return $"{GetGameRootPath()}/dat/{entry.Url.Substring(0, 2)}/{entry.Url}"; - } - - return $"{GetGameRootPath()}\\dat\\{entry.Url.Substring(0, 2)}\\{entry.Url}"; - } - - public static string GetGameRootPath() - { - if (Application.platform == RuntimePlatform.Android) - { - return Application.persistentDataPath; - } - return $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\\Cygames\\umamusume"; - } } diff --git a/Assets/Scripts/UmaViewerBuilder.cs b/Assets/Scripts/UmaViewerBuilder.cs index e7ea0c1..7f42329 100644 --- a/Assets/Scripts/UmaViewerBuilder.cs +++ b/Assets/Scripts/UmaViewerBuilder.cs @@ -275,7 +275,7 @@ public class UmaViewerBuilder : MonoBehaviour if (CurrentUMAContainer.Head) { var locatorEntry = Main.AbList.FirstOrDefault(a => a.Name.EndsWith("3d/animator/drivenkeylocator")); - var bundle = AssetBundle.LoadFromFile(UmaDatabaseController.GetABPath(locatorEntry)); + var bundle = AssetBundle.LoadFromFile(locatorEntry.FilePath); Main.LoadedBundles.Add(locatorEntry.Name, bundle); var locator = Instantiate(bundle.LoadAsset("DrivenKeyLocator"), CurrentUMAContainer.transform) as GameObject; locator.name = "DrivenKeyLocator"; @@ -288,7 +288,7 @@ public class UmaViewerBuilder : MonoBehaviour var mangaObjects = new List(); mangaEntry.ForEach(entry => { - AssetBundle ab = AssetBundle.LoadFromFile(UmaDatabaseController.GetABPath(entry)); + AssetBundle ab = AssetBundle.LoadFromFile(entry.FilePath); Main.LoadedBundles.Add(entry.Name, ab); var obj = ab.LoadAsset(Path.GetFileNameWithoutExtension(entry.Name)) as GameObject; obj.SetActive(false); @@ -561,7 +561,7 @@ public class UmaViewerBuilder : MonoBehaviour { List clips = new List(); UmaViewerUI.Instance.LoadedAssetsAdd(awb); - string awbPath = UmaDatabaseController.GetABPath(awb); ; + string awbPath = awb.FilePath; if (!File.Exists(awbPath)) return clips; FileStream awbFile = File.OpenRead(awbPath); @@ -599,7 +599,7 @@ public class UmaViewerBuilder : MonoBehaviour UmaDatabaseEntry lyricsAsset = Main.AbList.FirstOrDefault(a => a.Name.Contains(lyricsVar)); if (lyricsAsset != null) { - string filePath = UmaDatabaseController.GetABPath(lyricsAsset); + string filePath = lyricsAsset.FilePath; if (File.Exists(filePath)) { AssetBundle bundle; @@ -664,7 +664,7 @@ public class UmaViewerBuilder : MonoBehaviour Debug.Log("Loading " + entry.Name); if (Main.LoadedBundles.ContainsKey(entry.Name)) return; - string filePath = UmaDatabaseController.GetABPath(entry); + string filePath = entry.FilePath; if (File.Exists(filePath)) { AssetBundle bundle = AssetBundle.LoadFromFile(filePath); @@ -1250,7 +1250,7 @@ public class UmaViewerBuilder : MonoBehaviour { string value = $"chara/chr{id}/chr_icon_{id}"; var entry = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Equals(value)); - string path = UmaDatabaseController.GetABPath(entry); + string path = entry.FilePath; if (File.Exists(path)) { AssetBundle assetBundle = AssetBundle.LoadFromFile(path); diff --git a/Assets/Scripts/UmaViewerMain.cs b/Assets/Scripts/UmaViewerMain.cs index 918ec53..fe03da9 100644 --- a/Assets/Scripts/UmaViewerMain.cs +++ b/Assets/Scripts/UmaViewerMain.cs @@ -30,6 +30,7 @@ public class UmaViewerMain : MonoBehaviour private void Awake() { Instance = this; + new Config(); Application.targetFrameRate = -1; AbList = UmaDatabaseController.Instance.MetaEntries.ToList(); AbChara = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.CharaPath)).ToList(); @@ -41,18 +42,22 @@ public class UmaViewerMain : MonoBehaviour private IEnumerator Start() { Dictionary enNames = new Dictionary(); - yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/BasicCharaDataInfo", txt => + + if(Config.Instance.Language == Language.En) { - if (string.IsNullOrEmpty(txt)) return; - var umaData = JArray.Parse(txt); - foreach (var item in umaData) + yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/BasicCharaDataInfo", txt => { - if (!enNames.ContainsKey((int)item["charaId"])) + if (string.IsNullOrEmpty(txt)) return; + var umaData = JArray.Parse(txt); + foreach (var item in umaData) { - enNames.Add((int)item["charaId"], item["charaNameEnglish"].ToString()); + if (!enNames.ContainsKey((int)item["charaId"])) + { + enNames.Add((int)item["charaId"], item["charaNameEnglish"].ToString()); + } } - } - }); + }); + } var UmaCharaData = UmaDatabaseController.Instance.CharaData; foreach (var item in UmaCharaData) @@ -79,7 +84,7 @@ public class UmaViewerMain : MonoBehaviour var asset = AbList.FirstOrDefault(a => a.Name.Equals("livesettings")); if (asset != null) { - string filePath = UmaDatabaseController.GetABPath(asset); + string filePath = asset.FilePath; if (File.Exists(filePath)) { AssetBundle bundle = AssetBundle.LoadFromFile(filePath); diff --git a/Assets/Scripts/UmaViewerUI.cs b/Assets/Scripts/UmaViewerUI.cs index fe89c0d..5b7a9d5 100644 --- a/Assets/Scripts/UmaViewerUI.cs +++ b/Assets/Scripts/UmaViewerUI.cs @@ -148,7 +148,7 @@ public class UmaViewerUI : MonoBehaviour public void LoadedAssetsAdd(UmaDatabaseEntry entry) { LoadedAssetCount++; - string filePath = UmaDatabaseController.GetABPath(entry); + string filePath = entry.FilePath; var container = Instantiate(UmaContainerAssetsPrefab, LoadedAssetsPanel).GetComponent(); container.Name = Path.GetFileName(entry.Name) + "\n" + entry.Url; container.Button.onClick.AddListener(() => {Process.Start("explorer.exe", "/select," + filePath);});