From 5daee1a01a4b6d873791f68c2f70e6d00327a383 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Tue, 6 May 2025 20:35:52 +0800 Subject: [PATCH] feat: Add TTS related settings --- Assets/Cryville.EEW.Unity/Config.cs | 30 ++++++++++++++++++++- Assets/Cryville.EEW.Unity/SharedSettings.cs | 15 +++++++++-- Assets/Cryville.EEW.Unity/Worker.cs | 2 ++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Assets/Cryville.EEW.Unity/Config.cs b/Assets/Cryville.EEW.Unity/Config.cs index 9169fa3..27d319c 100644 --- a/Assets/Cryville.EEW.Unity/Config.cs +++ b/Assets/Cryville.EEW.Unity/Config.cs @@ -1,5 +1,9 @@ +using Cryville.EEW.Core; using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Text.Json; using System.Text.Json.Serialization; namespace Cryville.EEW.Unity { @@ -8,12 +12,17 @@ namespace Cryville.EEW.Unity { float SeverityColorMappingLuminanceMultiplier, bool UseContinuousColor, string ColorScheme, + string LocationNamer, string OverrideTimeZone, bool DoDisplayTimeZone, bool DoSwitchBackToHistory, + string NowcastWarningDelayTolerance, + string OverrideDisplayCulture, + IReadOnlyCollection TTSCultures, + bool DoIgnoreLanguageVariant, IReadOnlyCollection EventSources ) { @@ -22,12 +31,17 @@ namespace Cryville.EEW.Unity { 1f, false, "Default", + "FERegionLong", null, true, true, + "1:00:00", + "", + new List { new(SharedCultures.CurrentUICulture) }, + true, new List { new JMAAtomEventSourceConfig(Array.Empty()), @@ -61,6 +75,20 @@ namespace Cryville.EEW.Unity { record WolfxEventSourceConfig(IReadOnlyCollection Filter = null, bool IsFilterWhitelist = false, bool UseRawCENCLocationName = false) : EventSourceConfig; [JsonSerializable(typeof(Config))] - [JsonSourceGenerationOptions(WriteIndented = true)] + [JsonSourceGenerationOptions(Converters = new Type[] { typeof(CultureInfoConverter) }, WriteIndented = true)] sealed partial class ConfigSerializationContext : JsonSerializerContext { } + + sealed class CultureInfoConverter : JsonConverter { + public override CultureInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { + Debug.Assert(typeToConvert == typeof(CultureInfo)); + var value = reader.GetString(); + if (value == null) return CultureInfo.InvariantCulture; + if (value == "") return SharedCultures.CurrentUICulture; + return SharedCultures.Get(value); + } + + public override void Write(Utf8JsonWriter writer, CultureInfo value, JsonSerializerOptions options) { + writer.WriteStringValue(value.Name); + } + } } diff --git a/Assets/Cryville.EEW.Unity/SharedSettings.cs b/Assets/Cryville.EEW.Unity/SharedSettings.cs index 724670f..7b388dc 100644 --- a/Assets/Cryville.EEW.Unity/SharedSettings.cs +++ b/Assets/Cryville.EEW.Unity/SharedSettings.cs @@ -26,12 +26,12 @@ namespace Cryville.EEW.Unity { public IColorScheme ColorScheme { get; private set; } = new SeverityBasedColorScheme(DefaultSeverityScheme.Instance, DefaultSeverityColorMapping.Instance); public ISubColorScheme BorderColorScheme { get; private set; } = new WrappedColorScheme(new SeverityBasedColorScheme(DefaultSeverityScheme.Instance, DefaultSeverityColorMapping.SecondaryInstance)); public ISubColorScheme TextColorScheme { get; private set; } = new DefaultTextColorScheme(Color.White, Color.Black); - public TimeSpan NowcastWarningDelayTolerance => TimeSpan.FromMinutes(60); // TODO TTS + public TimeSpan NowcastWarningDelayTolerance { get; private set; } = TimeSpan.FromMinutes(60); public CultureInfo RVMCulture { get; private set; } = SharedCultures.CurrentUICulture; readonly int _infoLocationSpecificity = 3; readonly int _ttsLocationSpecificity = 3; - readonly LocationNamer _locationNamer = new() { Namer = new FERegionLongNamer() }; // TODO TTS + readonly LocationNamer _locationNamer = new() { Namer = new FERegionLongNamer() }; public bool NameLocation(double lat, double lon, CultureInfo localCulture, ref CultureInfo targetCulture, out string name, out int specificity) { specificity = _ttsLocationSpecificity; return _locationNamer.Name(lat, lon, localCulture, ref targetCulture, out name, ref specificity); @@ -41,6 +41,9 @@ namespace Cryville.EEW.Unity { return _locationNamer.Name(lat, lon, localCulture, ref targetCulture, out name, ref specificity); } + public IReadOnlyCollection TTSCultures { get; private set; } + public bool DoIgnoreLanguageVariant { get; private set; } + public TimeZoneInfo OverrideTimeZone { get; private set; } public bool DoDisplayTimeZone { get; private set; } = true; public bool DoSwitchBackToHistory { get; private set; } = true; @@ -114,12 +117,20 @@ namespace Cryville.EEW.Unity { "SREV" => new DefaultTextColorScheme(Color.White, Color.FromArgb(28, 28, 28), 0.555f), _ => new DefaultTextColorScheme(Color.White, Color.Black), }; + _locationNamer.Namer = config.LocationNamer switch { + "FERegionShort" => new FERegionShortNamer(), + _ => new FERegionLongNamer(), + }; + if (config.NowcastWarningDelayTolerance is string nowcastWarningDelayTolerance) + NowcastWarningDelayTolerance = TimeSpan.Parse(nowcastWarningDelayTolerance, CultureInfo.InvariantCulture); OverrideTimeZone = ParseTimeZone(config.OverrideTimeZone); DoDisplayTimeZone = config.DoDisplayTimeZone; DoSwitchBackToHistory = config.DoSwitchBackToHistory; RVMCulture = config.OverrideDisplayCulture is string rvmCulture ? (string.IsNullOrEmpty(rvmCulture) ? SharedCultures.CurrentUICulture : SharedCultures.Get(rvmCulture)) : CultureInfo.InvariantCulture; + TTSCultures = config.TTSCultures ?? new List { new(CultureInfo.InvariantCulture) }; + DoIgnoreLanguageVariant = config.DoIgnoreLanguageVariant; EventSources = config.EventSources; } diff --git a/Assets/Cryville.EEW.Unity/Worker.cs b/Assets/Cryville.EEW.Unity/Worker.cs index ae77a47..888edd3 100644 --- a/Assets/Cryville.EEW.Unity/Worker.cs +++ b/Assets/Cryville.EEW.Unity/Worker.cs @@ -65,6 +65,8 @@ namespace Cryville.EEW.Unity { _worker.RVMGeneratorContext = SharedSettings.Instance; _worker.TTSMessageGeneratorContext = SharedSettings.Instance; _worker.RVMCulture = SharedSettings.Instance.RVMCulture; + _worker.SetTTSCultures(SharedSettings.Instance.TTSCultures ?? new TTSCultureConfig[0]); + _worker.IgnoreLanguageVariant = SharedSettings.Instance.DoIgnoreLanguageVariant; _ongoingReportManager.Changed += OnOngoingReported; _worker.Reported += OnReported; _grouper.GroupUpdated += OnGroupUpdated;