diff --git a/src/Murder.Editor/CustomFields/LocalizedStringField.cs b/src/Murder.Editor/CustomFields/LocalizedStringField.cs index 1d7ff280..adf6f95e 100644 --- a/src/Murder.Editor/CustomFields/LocalizedStringField.cs +++ b/src/Murder.Editor/CustomFields/LocalizedStringField.cs @@ -16,7 +16,7 @@ public override (bool modified, object? result) ProcessInput(EditorMember member bool modified = false; LocalizedString? localizedString = (LocalizedString?)fieldValue; - LocalizationAsset localization = LocalizationServices.GetCurrentLocalization(); + LocalizationAsset localization = Game.Data.GetDefaultLocalization(); if (localizedString is null || localizedString.Value.Id == Guid.Empty) { diff --git a/src/Murder.Editor/Data/Graphics/FontImporter.cs b/src/Murder.Editor/Data/Graphics/FontImporter.cs index ee1feb20..9dc4ad47 100644 --- a/src/Murder.Editor/Data/Graphics/FontImporter.cs +++ b/src/Murder.Editor/Data/Graphics/FontImporter.cs @@ -173,6 +173,7 @@ public static bool GenerateFontJsonAndPng(int fontIndex, string fontPath, int fo bitmap.Encode(stream, SKEncodedImageFormat.Png, 100); } + // EditorTextureServices.SaveAsPng(stream, Path.Join(sourcePackedPath, $"{name}.png")); EditorTextureServices.ConvertPngStreamToQuoiGz(stream, imageSourcePackedPath); // ProcessFinished: diff --git a/src/Murder.Editor/Services/EditorLocalizationServices.cs b/src/Murder.Editor/Services/EditorLocalizationServices.cs index 13cbf570..8b3c3e07 100644 --- a/src/Murder.Editor/Services/EditorLocalizationServices.cs +++ b/src/Murder.Editor/Services/EditorLocalizationServices.cs @@ -10,7 +10,7 @@ internal static class EditorLocalizationServices { public static LocalizedString? SearchLocalizedString() { - LocalizationAsset localization = LocalizationServices.GetCurrentLocalization(); + LocalizationAsset localization = Game.Data.GetDefaultLocalization(); SearchBoxSettings settings = new(initialText: "Create localized string") { @@ -68,7 +68,7 @@ internal static class EditorLocalizationServices { LocalizedString result = new(Guid.NewGuid()); - LocalizationAsset asset = Game.Data.Localization; + LocalizationAsset asset = Game.Data.GetDefaultLocalization(); asset.AddResource(result.Id); EditorServices.SaveAssetWhenSelectedAssetIsSaved(asset.Guid); @@ -79,7 +79,7 @@ internal static class EditorLocalizationServices private static void AddExistingResource(Guid g) { - LocalizationAsset asset = Game.Data.Localization; + LocalizationAsset asset = Game.Data.GetDefaultLocalization(); asset.AddResource(g); EditorServices.SaveAssetWhenSelectedAssetIsSaved(asset.Guid); diff --git a/src/Murder.Editor/Services/EditorTextureServices.cs b/src/Murder.Editor/Services/EditorTextureServices.cs index c3b16de0..7d72fc52 100644 --- a/src/Murder.Editor/Services/EditorTextureServices.cs +++ b/src/Murder.Editor/Services/EditorTextureServices.cs @@ -29,7 +29,7 @@ public static void SaveAsQoiGz(this Texture2D texture, string path) } /// - /// Save a as a QOI image. + /// Save a as a QOI image. /// public static void ConvertPngStreamToQuoiGz(MemoryStream stream, string path) { @@ -37,4 +37,15 @@ public static void ConvertPngStreamToQuoiGz(MemoryStream stream, string path) SaveAsQoiGz(texture, path); } + + public static void SaveAsPng(MemoryStream stream, string path) + { + using Texture2D texture = Texture2D.FromStream(Architect.GraphicsDevice, stream); + + { + using FileStream fileStream = File.Open(path, FileMode.OpenOrCreate); + texture.SaveAsPng(fileStream, texture.Width, texture.Height); + fileStream.Close(); + } + } } diff --git a/src/Murder/Assets/Localization/Languages.cs b/src/Murder/Assets/Localization/Languages.cs index 9a01f01d..5a34fb50 100644 --- a/src/Murder/Assets/Localization/Languages.cs +++ b/src/Murder/Assets/Localization/Languages.cs @@ -12,7 +12,7 @@ public static class Languages { private static LanguageIdData[]? _all = null; - public static LanguageIdData[] All => _all ??= [ English, Portuguese ]; + public static LanguageIdData[] All => _all ??= [ English, Portuguese, Japanese]; public static LanguageIdData Get(LanguageId id) => All[(int)id]; @@ -22,11 +22,13 @@ public static LanguageIdData Next(LanguageId id) => public static readonly LanguageIdData English = new(LanguageId.English, "en-US"); public static readonly LanguageIdData Portuguese = new(LanguageId.Portuguese, "pt-BR"); + public static readonly LanguageIdData Japanese = new(LanguageId.Japanese, "ja"); } public enum LanguageId { English = 0, - Portuguese = 1 + Portuguese = 1, + Japanese = 2 } } diff --git a/src/Murder/Assets/Localization/LocalizedString.cs b/src/Murder/Assets/Localization/LocalizedString.cs index 394951be..9a03df1a 100644 --- a/src/Murder/Assets/Localization/LocalizedString.cs +++ b/src/Murder/Assets/Localization/LocalizedString.cs @@ -1,4 +1,6 @@ -namespace Murder.Assets; +using Murder.Services; + +namespace Murder.Assets; public readonly struct LocalizedString { @@ -15,4 +17,7 @@ public LocalizedString() { } public LocalizedString(Guid id) => Id = id; public LocalizedString(string overrideText) => OverrideText = overrideText; + + public static implicit operator string(LocalizedString localizedString) => + LocalizationServices.GetLocalizedString(localizedString); } diff --git a/src/Murder/Data/GameDataManager.cs b/src/Murder/Data/GameDataManager.cs index 4f5a3a0e..c9402580 100644 --- a/src/Murder/Data/GameDataManager.cs +++ b/src/Murder/Data/GameDataManager.cs @@ -868,6 +868,11 @@ public ImmutableDictionary FilterOutAssets(params Type[] types) public PixelFont GetFont(int index) { + if (_game is not null) + { + index = _game.GetLocalizedFont(index); + } + if (_fonts.TryGetValue(index, out PixelFont? font)) { return font; diff --git a/src/Murder/IMurderGame.cs b/src/Murder/IMurderGame.cs index 70bb430e..d3861933 100644 --- a/src/Murder/IMurderGame.cs +++ b/src/Murder/IMurderGame.cs @@ -75,6 +75,11 @@ public void OnExit() { } /// public GamePreferences CreateGamePreferences() => new(); + /// + /// Allow the game to override a font based on localization settings. + /// + public int GetLocalizedFont(int index) => index; + /// /// Creates a custom render context for the game. /// diff --git a/src/Murder/Services/RenderServices.cs b/src/Murder/Services/RenderServices.cs index 5005ea2a..ae682996 100644 --- a/src/Murder/Services/RenderServices.cs +++ b/src/Murder/Services/RenderServices.cs @@ -12,8 +12,6 @@ using Murder.Utilities; using System.Collections.Immutable; using System.Numerics; -using static System.Formats.Asn1.AsnWriter; -using static System.Net.Mime.MediaTypeNames; using Matrix = Microsoft.Xna.Framework.Matrix; using Vector3 = Microsoft.Xna.Framework.Vector3;