bea593732d
The bundle was built by rewriting the Korean translation mod's asset bundle, so it still carried everything that mod needed and we did not: three unused font assets, their materials and textures, and a .resS stream holding two 2048x2048 atlases. Deleted those, dropped the stream, and rewrote m_Container and m_PreloadTable to reference only the four surviving objects. 862 KB -> 59 KB, verified by reloading: the embedded font still round-trips as Cabin with full Slovak coverage and the Gill Sans MT metrics. The 2s sweep existed to catch labels whose font the game reassigns without any text change, which happens on a language switch. A postfix on the Text.font setter catches exactly that, at the moment it happens rather than up to two seconds later, and costs nothing when idle. Re-entry is safe: our own assignment fires the hook once, which finds the state already correct and returns. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
3.0 KiB
C#
72 lines
3.0 KiB
C#
using HarmonyLib;
|
|
using OWML.Common;
|
|
using OWML.ModHelper;
|
|
|
|
namespace SlovakTranslation
|
|
{
|
|
/// <summary>
|
|
/// Registers Slovenčina as a selectable language via xen-42's Localization
|
|
/// Utility (xen.LocalizationUtility). All the heavy lifting lives in the
|
|
/// utility; this mod just points it at our translated strings and patches the
|
|
/// few menu/HUD fonts that were never baked with Slovak glyphs (see
|
|
/// <see cref="SlovakFont"/>).
|
|
/// </summary>
|
|
public class SlovakTranslation : ModBehaviour
|
|
{
|
|
public static SlovakTranslation Instance;
|
|
|
|
/// <summary>Name the language is registered (and displayed) under.</summary>
|
|
public const string LanguageName = "Slovenčina";
|
|
|
|
/// <summary>Path (relative to the mod folder) to the translated strings.</summary>
|
|
public static string translationFile = "assets/Translation.xml";
|
|
|
|
/// <summary>The Localization Utility's API, kept for reflection in <see cref="SlovakFont"/>.</summary>
|
|
internal static ILocalizationAPI LocalizationApi;
|
|
|
|
private void Start()
|
|
{
|
|
Instance = this;
|
|
|
|
LocalizationApi = ModHelper.Interaction.TryGetModApi<ILocalizationAPI>("xen.LocalizationUtility");
|
|
if (LocalizationApi == null)
|
|
{
|
|
ModHelper.Console.WriteLine(
|
|
"Could not find xen.LocalizationUtility — is Interplanetary Polyglot installed?",
|
|
MessageType.Error);
|
|
return;
|
|
}
|
|
|
|
LocalizationApi.RegisterLanguage(this, LanguageName, translationFile);
|
|
ModHelper.Console.WriteLine("Registered language: " + LanguageName, MessageType.Success);
|
|
|
|
// Deliberately *not* AddLanguageFont: that would make IsLanguageLatin false
|
|
// and pull dialogue, the translator and the ship log off their correct
|
|
// vanilla fonts. We only patch the fonts that can't draw Slovak.
|
|
SlovakFont.Load(this);
|
|
if (SlovakFont.Loaded)
|
|
{
|
|
new Harmony("Homer.SlovakTranslation").PatchAll();
|
|
UnityEngine.SceneManagement.SceneManager.sceneLoaded += (scene, mode) => SlovakFont.ApplyToAll();
|
|
ModHelper.Console.WriteLine("Slovak menu/HUD font (Cabin) loaded and patched in.", MessageType.Success);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// <c>preferGameTypeface</c> — when on, a menu font that can't draw Slovak is
|
|
/// replaced by the game's own dynamic cut of the same typeface where one exists,
|
|
/// so the menu keeps its vanilla look. Turn it off to use the bundled Cabin
|
|
/// everywhere instead.
|
|
/// </summary>
|
|
public override void Configure(IModConfig config)
|
|
{
|
|
SlovakFont.PreferGameTypeface = config.GetSettingsValue<bool>("preferGameTypeface");
|
|
if (!SlovakFont.Loaded) return;
|
|
|
|
SlovakFont.ForgetChoices();
|
|
SlovakFont.ApplyToAll();
|
|
}
|
|
|
|
}
|
|
}
|