diff --git a/BepisLocaleLoader.csproj b/BepisLocaleLoader.csproj index e512839..ea88cf7 100644 --- a/BepisLocaleLoader.csproj +++ b/BepisLocaleLoader.csproj @@ -1,7 +1,7 @@ - 1.0.0 + 1.0.1 ResoniteModding net9.0 https://github.com/ResoniteModding/BepisLocaleLoader @@ -33,6 +33,7 @@ + diff --git a/ConfigLocale.cs b/ConfigLocale.cs new file mode 100644 index 0000000..52230f8 --- /dev/null +++ b/ConfigLocale.cs @@ -0,0 +1,22 @@ +using Elements.Core; + +namespace BepisLocaleLoader; + +// We could maybe add more things to this later if needed +public struct ConfigLocale +{ + public ConfigLocale(string name, string description) + { + Name = name.AsLocaleKey(); + Description = description.AsLocaleKey(); + } + + public ConfigLocale(LocaleString name, LocaleString description) + { + Name = name; + Description = description; + } + + public LocaleString Name; + public LocaleString Description; +} \ No newline at end of file diff --git a/LocaleLoader.cs b/LocaleLoader.cs index 6e9526e..525ae18 100644 --- a/LocaleLoader.cs +++ b/LocaleLoader.cs @@ -81,7 +81,7 @@ public static void AddLocaleFromFile(string path) return; } - Plugin.Log.LogDebug($"- {localeData.LocaleCode} - c-{localeData.Messages.Count}"); + Plugin.Log.LogDebug($"- LocaleCode: {localeData.LocaleCode}, Message Count: {localeData.Messages.Count}"); Update(localeData, true); } @@ -164,6 +164,35 @@ private static void ProcessDirectory(string directory, Action fileAction } } + private static string GetFormattedLocaleString(this string key, string format, Dictionary dict, (string, object)[] arguments) + { + Dictionary merged = dict != null ? new Dictionary(dict) : new Dictionary(); + + if (arguments != null) + { + foreach ((string name, object value) in arguments) + { + merged[name] = value; + } + } + + string formatted = _localeProvider?.Asset?.Format(key, merged); + + if (!string.IsNullOrWhiteSpace(format)) + { + formatted = string.Format(format, formatted); + } + + return formatted; + } + + public static string GetFormattedLocaleString(this string key) => key.GetFormattedLocaleString(null, null, null); + public static string GetFormattedLocaleString(this string key, string format) => key.GetFormattedLocaleString(format, null, null); + public static string GetFormattedLocaleString(this string key, string argName, object argField) => key.GetFormattedLocaleString(null, null, new (string, object)[] { (argName, argField) }); + public static string GetFormattedLocaleString(this string key, string format, string argName, object argField) => key.GetFormattedLocaleString(format, null, new (string, object)[] { (argName, argField) }); + public static string GetFormattedLocaleString(this string key, params (string, object)[] arguments) => key.GetFormattedLocaleString(null, null, arguments); + public static string GetFormattedLocaleString(this string key, string format, params (string, object)[] arguments) => key.GetFormattedLocaleString(format, null, arguments); + public static LocaleString T(this string str, string argName, object argField) => str.AsLocaleKey(null, (argName, argField)); public static LocaleString T(this string str, string format, string argName, object argField) => str.AsLocaleKey(format, (argName, argField)); public static LocaleString T(this string str, params (string, object)[] arguments) => str.AsLocaleKey(null, arguments); diff --git a/Plugin.cs b/Plugin.cs index 1f99c1d..9e40211 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -2,6 +2,7 @@ using BepInEx.Logging; using BepInEx.NET.Common; using BepInExResoniteShim; +using BepisResoniteWrapper; using FrooxEngine; using HarmonyLib; @@ -18,20 +19,14 @@ public override void Load() // Plugin startup logic Log = base.Log; - // TODO: Switch this to a event subscription when BepInExResoniteShim is updated - Task.Run(async () => + ResoniteHooks.OnEngineReady += async () => { - while (Engine.Current == null || Userspace.UserspaceWorld == null) - { - await Task.Delay(10); - } - await Task.Delay(5000); if (NetChainloader.Instance.Plugins.Count <= 0) return; NetChainloader.Instance.Plugins.Values.Do(LocaleLoader.AddLocaleFromPlugin); - }); + }; Log.LogInfo($"Plugin {PluginMetadata.GUID} is loaded!"); }