feat: Add TTS related settings

This commit is contained in:
2025-05-06 20:35:52 +08:00
parent 2d5d305528
commit 5daee1a01a
3 changed files with 44 additions and 3 deletions

View File

@@ -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<TTSCultureConfig> TTSCultures,
bool DoIgnoreLanguageVariant,
IReadOnlyCollection<EventSourceConfig> EventSources
) {
@@ -22,12 +31,17 @@ namespace Cryville.EEW.Unity {
1f,
false,
"Default",
"FERegionLong",
null,
true,
true,
"1:00:00",
"",
new List<TTSCultureConfig> { new(SharedCultures.CurrentUICulture) },
true,
new List<EventSourceConfig> {
new JMAAtomEventSourceConfig(Array.Empty<string>()),
@@ -61,6 +75,20 @@ namespace Cryville.EEW.Unity {
record WolfxEventSourceConfig(IReadOnlyCollection<string> 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<CultureInfo> {
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);
}
}
}

View File

@@ -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<TTSCultureConfig> 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<TTSCultureConfig> { new(CultureInfo.InvariantCulture) };
DoIgnoreLanguageVariant = config.DoIgnoreLanguageVariant;
EventSources = config.EventSources;
}

View File

@@ -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;