From e1af8609b35d360c3f851fefbda75e47b74de00d Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Mon, 14 Feb 2022 17:20:28 +0800 Subject: [PATCH] feat: inspect helper --- GodSeekerPlus/Modules/Misc/InspectHelper.cs | 43 +++++++++++++++++++++ GodSeekerPlus/Util/L11nUtil.cs | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 GodSeekerPlus/Modules/Misc/InspectHelper.cs diff --git a/GodSeekerPlus/Modules/Misc/InspectHelper.cs b/GodSeekerPlus/Modules/Misc/InspectHelper.cs new file mode 100644 index 0000000..bbf899b --- /dev/null +++ b/GodSeekerPlus/Modules/Misc/InspectHelper.cs @@ -0,0 +1,43 @@ +namespace GodSeekerPlus.Modules.Misc; + +[Hidden] +internal sealed class InspectHelper : Module { + private static readonly string GO_NAME = $"{nameof(GodSeekerPlus)} Inspect Helper"; + + private protected override void Load() => + ModHooks.FinishedLoadingModsHook += CreateGameObject; + + private static void CreateGameObject() { + if (ModHooks.GetMod("Unity Explorer", true) == null) { + return; + } + + if (GameObject.Find(GO_NAME) is not null and { + scene.name: "DontDestroyOnLoad" + }) { + Logger.LogError("Inspect Helper GameObject already existed!"); + + return; + } + + Logger.Log("Creating Inspect Helper GameObject"); + var go = new GameObject(GO_NAME, typeof(Inspector)); + UObject.DontDestroyOnLoad(go); + } + + private sealed class Inspector : MonoBehaviour { + public GodSeekerPlus Instance => GodSeekerPlus.UnsafeInstance; + + public Dictionary Modules => ModuleManager.Modules; + + public GlobalSettings GlobalSettings => GodSeekerPlus.GlobalSettings; + public LocalSettings LocalSettings => GodSeekerPlus.LocalSettings; + + public Dictionary> Dict => L11nUtil.Dict.Value; + + public Dictionary? GetL11n(string lang) => + L11nUtil.Dict.Value.TryGetValue(lang, out Dictionary? dict) ? dict : null; + + public string Localize(string key) => L11nUtil.Localize(key); + } +} diff --git a/GodSeekerPlus/Util/L11nUtil.cs b/GodSeekerPlus/Util/L11nUtil.cs index 6c67785..1ca8fd5 100644 --- a/GodSeekerPlus/Util/L11nUtil.cs +++ b/GodSeekerPlus/Util/L11nUtil.cs @@ -22,7 +22,7 @@ private static string ToIdentifier(this LanguageCode code) => Lang.CurrentLanguage().ToIdentifier(); - private static readonly Lazy>> Dict = new(() => Assembly + internal static readonly Lazy>> Dict = new(() => Assembly .GetExecutingAssembly() .GetManifestResourceNames() .Filter(name => name.EnclosedWith(resPrefix, resPostfix))