From 1aac7faae1a6ad57ad46568bac54b15da0d38951 Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 30 Nov 2026 19:14:15 +0100 Subject: [PATCH 1/3] fix(weather): the overcast list says what the simulator makes of it, rain and snow among it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The simulator reads the overcast as clear up to 0.1, clouds up to 1 and precipitation above it: rain above 1 °C, snow at or below, denser from 1.35 on. A negative value it draws anew from 0 up to its size. The list named -1.5 "Clear", though it rained one run in three, 1.1 "Cloudy" and 1.5 "Storm", which the simulator has none of, so rain was nowhere to be picked by name. The list is now clear, light, moderate clouds, cloudy, light rain and rain, the last two named snow when the temperature set makes it snow. Random draws only from these, and a negative overcast in a scenery is shown as random rather than clear. --- StarterNG.Tests/SceneryWeatherTests.cs | 28 ++++++++++++++++++- StarterNG/Domain/Sceneries/SceneryWeather.cs | 9 +++++- .../Infrastructure/Sceneries/SceneryParser.cs | 6 +++- StarterNG/Views/Scenarios.axaml | 9 +++--- StarterNG/Views/Scenarios.axaml.cs | 15 ++++++++++ StarterNG/startercfg/lang/cz.xml | 7 +++-- StarterNG/startercfg/lang/en.xml | 7 +++-- StarterNG/startercfg/lang/hu.xml | 7 +++-- StarterNG/startercfg/lang/pl.xml | 7 +++-- StarterNG/startercfg/lang/ru.xml | 7 +++-- StarterNG/startercfg/lang/zh.xml | 7 +++-- 11 files changed, 83 insertions(+), 26 deletions(-) diff --git a/StarterNG.Tests/SceneryWeatherTests.cs b/StarterNG.Tests/SceneryWeatherTests.cs index 35a313e..3581248 100644 --- a/StarterNG.Tests/SceneryWeatherTests.cs +++ b/StarterNG.Tests/SceneryWeatherTests.cs @@ -78,10 +78,36 @@ public class SceneryWeatherTests { var weather = new SceneryWeather { Overcast = 0.42, OvercastRandom = true }; - Assert.Equal(-1.5, weather.EffectiveOvercast(new StubRandom())); + Assert.Equal(0, weather.EffectiveOvercast(new StubRandom())); Assert.Equal(0.42, new SceneryWeather { Overcast = 0.42 }.EffectiveOvercast(new StubRandom())); } + [Fact] + public void No_random_overcast_preset_is_one_the_simulator_would_draw_again() + { + var weather = new SceneryWeather { OvercastRandom = true }; + + for (int i = 0; i < 10; i++) + Assert.InRange(weather.EffectiveOvercast(new StubRandom(i)), 0, 2); + } + + [Fact] + public void A_negative_overcast_in_the_scenery_is_read_as_random() + { + var weather = TestScenery.Parser(new DateTime(2026, 1, 1)) + .Parse("scenery/x.scn", "atmo 0 0 0 50 900 0 0 0 -1.5 endatmo").Weather; + + Assert.True(weather.OvercastRandom); + Assert.False(weather.Changed); + } + + [Theory] + [InlineData(2, false)] + [InlineData(1, true)] + [InlineData(-10, true)] + public void Precipitation_is_snow_at_or_below_one_degree(double temperature, bool snow) => + Assert.Equal(snow, SceneryWeather.Snows(temperature)); + private static string Rewritten(string scn) => SceneryWeatherWriter.Rewrite(scn, new SceneryWeather(), new StubRandom()); diff --git a/StarterNG/Domain/Sceneries/SceneryWeather.cs b/StarterNG/Domain/Sceneries/SceneryWeather.cs index 03c7438..28908cd 100644 --- a/StarterNG/Domain/Sceneries/SceneryWeather.cs +++ b/StarterNG/Domain/Sceneries/SceneryWeather.cs @@ -8,7 +8,14 @@ public sealed class SceneryWeather public const int FogMin = 10; public const int FogMax = 10000; - private static readonly double[] OvercastPresets = { -1.5, 0, 0.3, 0.7, 1, 1.1, 1.5 }; + /// + /// What the simulator makes of each: up to 0.1 clear, 0.5 scattered, 0.9 broken, + /// 1 overcast; above 1 it rains or snows, the denser from 1.35 on. + /// + private static readonly double[] OvercastPresets = { 0, 0.3, 0.7, 1, 1.1, 1.5 }; + + /// The simulator rains above 1 °C and snows at that or below. + public static bool Snows(double temperature) => temperature <= 1; private string _authoredTime = "10:30"; private string _authoredTimeOverride = "10:30"; diff --git a/StarterNG/Infrastructure/Sceneries/SceneryParser.cs b/StarterNG/Infrastructure/Sceneries/SceneryParser.cs index 031a05f..d9827bf 100644 --- a/StarterNG/Infrastructure/Sceneries/SceneryParser.cs +++ b/StarterNG/Infrastructure/Sceneries/SceneryParser.cs @@ -286,7 +286,11 @@ public sealed class SceneryParser if (numbers.Count >= 6 && double.TryParse(numbers[^1], NumberStyles.Float, CultureInfo.InvariantCulture, out double overcast)) - weather.Overcast = overcast; + { + // The simulator draws a negative overcast anew each run, from 0 up to its size. + weather.OvercastRandom = overcast < 0; + weather.Overcast = Math.Max(overcast, 0); + } } private static string? MatchAllDirectives(string content, string letter) diff --git a/StarterNG/Views/Scenarios.axaml b/StarterNG/Views/Scenarios.axaml index 5c541b0..0d090dd 100644 --- a/StarterNG/Views/Scenarios.axaml +++ b/StarterNG/Views/Scenarios.axaml @@ -189,13 +189,12 @@ HorizontalAlignment="Stretch" SelectionChanged="Weather_OnSelectionChanged"> - - + - - - + + + Fog read-out in the language the user is reading the rest in. private static string FogScale2(int metres) => FogScale.Format(metres, LanguageCulture); + private bool? _precipitationIsSnow; + + /// Above 1 the overcast rains or snows, as the temperature decides in the simulator. + private void ShowPrecipitationAs(bool snow) + { + if (_precipitationIsSnow == snow) + return; + _precipitationIsSnow = snow; + weatherPrecipitationLight[!ContentProperty] = + new Avalonia.Data.Binding(snow ? "[OvercastSnowLight]" : "[OvercastRainLight]") { Source = App.Loc }; + weatherPrecipitation[!ContentProperty] = + new Avalonia.Data.Binding(snow ? "[OvercastSnow]" : "[OvercastRain]") { Source = App.Loc }; + } + private const string RandomTag = "random"; private static void SelectByTag(ComboBox combo, string tag, string? excludeFromNearest = null) diff --git a/StarterNG/startercfg/lang/cz.xml b/StarterNG/startercfg/lang/cz.xml index 6e0527e..77241b5 100644 --- a/StarterNG/startercfg/lang/cz.xml +++ b/StarterNG/startercfg/lang/cz.xml @@ -48,12 +48,13 @@ Zima Náhodné Jasno - Skoro jasno Slabá oblačnost Mírná oblačnost - Silná oblačnost Zataženo - Bouřka + Slabý déšť + Déšť + Slabé sněžení + Sněžení Datum a čas Povětrnostní podmínky Souprava diff --git a/StarterNG/startercfg/lang/en.xml b/StarterNG/startercfg/lang/en.xml index afe1ba2..3a459db 100644 --- a/StarterNG/startercfg/lang/en.xml +++ b/StarterNG/startercfg/lang/en.xml @@ -48,12 +48,13 @@ Winter Random Clear - Fair Light clouds Moderate clouds - Heavy clouds Cloudy - Storm + Light rain + Rain + Light snow + Snow Date and time Conditions Consist diff --git a/StarterNG/startercfg/lang/hu.xml b/StarterNG/startercfg/lang/hu.xml index 5b4791b..102ba6b 100644 --- a/StarterNG/startercfg/lang/hu.xml +++ b/StarterNG/startercfg/lang/hu.xml @@ -48,12 +48,13 @@ Tél Véletlenszerű Derült - Gyengén felhős Kevés felhő Közepes felhőzet - Erős felhőzet Borult - Vihar + Gyenge eső + Eső + Gyenge havazás + Havazás Dátum és idő Időjárási viszonyok Szerelvény diff --git a/StarterNG/startercfg/lang/pl.xml b/StarterNG/startercfg/lang/pl.xml index f9d2e04..97a6747 100644 --- a/StarterNG/startercfg/lang/pl.xml +++ b/StarterNG/startercfg/lang/pl.xml @@ -48,12 +48,13 @@ Zima Losowe Bezchmurnie - Pogodnie Lekkie zachmurzenie Umiarkowane zachmurzenie - Duże zachmurzenie Pochmurno - Burza + Lekki deszcz + Deszcz + Lekki śnieg + Śnieg Data i godzina Warunki atmosferyczne Zestawienie diff --git a/StarterNG/startercfg/lang/ru.xml b/StarterNG/startercfg/lang/ru.xml index a4426b3..1375d9f 100644 --- a/StarterNG/startercfg/lang/ru.xml +++ b/StarterNG/startercfg/lang/ru.xml @@ -48,12 +48,13 @@ Зима Случайно Ясно - Малооблачно Лёгкая облачность Умеренная облачность - Сильная облачность Пасмурно - Гроза + Небольшой дождь + Дождь + Небольшой снег + Снег Дата и время Погодные условия Состав diff --git a/StarterNG/startercfg/lang/zh.xml b/StarterNG/startercfg/lang/zh.xml index 419530b..d70171a 100644 --- a/StarterNG/startercfg/lang/zh.xml +++ b/StarterNG/startercfg/lang/zh.xml @@ -48,12 +48,13 @@ 冬 随机 晴 - 晴好 少云 多云 - 阴 阴天 - 雷暴 + 小雨 + 雨 + 小雪 + 雪 日期和时间 天气状况 编组 From a87c1ebc4cabe8f4d222eb62bb1c9587de83ecf1 Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 30 Nov 2026 19:22:26 +0100 Subject: [PATCH 2/3] fix(weather): rain or snow is named by a control of its own, with no reflection binding The two precipitation options were renamed by a Binding made in code, which reads its path by reflection: unsafe for the NativeAOT starter and flagged as such by the analysis. A PrecipitationItem now names itself from the starter's texts and follows a change of language, and the weather tab only tells it whether it snows. --- StarterNG.Tests/PrecipitationItemTests.cs | 53 ++++++++++++++++++++ StarterNG/Controls/PrecipitationItem.cs | 61 +++++++++++++++++++++++ StarterNG/Views/Scenarios.axaml | 4 +- StarterNG/Views/Scenarios.axaml.cs | 16 +----- 4 files changed, 117 insertions(+), 17 deletions(-) create mode 100644 StarterNG.Tests/PrecipitationItemTests.cs create mode 100644 StarterNG/Controls/PrecipitationItem.cs diff --git a/StarterNG.Tests/PrecipitationItemTests.cs b/StarterNG.Tests/PrecipitationItemTests.cs new file mode 100644 index 0000000..0b06eda --- /dev/null +++ b/StarterNG.Tests/PrecipitationItemTests.cs @@ -0,0 +1,53 @@ +using Avalonia.Controls; +using StarterNG.Controls; + +namespace StarterNG.Tests; + +[Collection(AvaloniaControls.Name)] +public class PrecipitationItemTests +{ + // Shown in whatever language the tests run in: the key alone, or English once a test built the application. + private static void ShowsText(string key, PrecipitationItem item) + { + Assert.Equal(key, item.Key); + Assert.Equal(AppLanguage.Text(key), item.Content); + } + + [Fact] + public void Light_precipitation_is_light_rain_until_told_it_snows() + { + var item = new PrecipitationItem(); + + ShowsText("OvercastRainLight", item); + + item.Snow = true; + + ShowsText("OvercastSnowLight", item); + } + + [Fact] + public void Heavy_precipitation_is_rain_or_snow() + { + var item = new PrecipitationItem { Heavy = true }; + + ShowsText("OvercastRain", item); + + item.Snow = true; + + ShowsText("OvercastSnow", item); + } + + [Fact] + public void The_option_keeps_its_name_in_a_dropdown_and_out_of_it() + { + var item = new PrecipitationItem { Heavy = true, Snow = true }; + var combo = new ComboBox { Items = { item } }; + + ShowsText("OvercastSnow", item); + + combo.Items.Remove(item); + item.Snow = false; + + ShowsText("OvercastRain", item); + } +} diff --git a/StarterNG/Controls/PrecipitationItem.cs b/StarterNG/Controls/PrecipitationItem.cs new file mode 100644 index 0000000..9a6ebf6 --- /dev/null +++ b/StarterNG/Controls/PrecipitationItem.cs @@ -0,0 +1,61 @@ +using System; +using Avalonia; +using Avalonia.Controls; +using Avalonia.LogicalTree; + +namespace StarterNG.Controls; + +/// +/// An overcast option above 1, where the simulator rains or, at 1 °C and below, snows: +/// named for what falls, light or not, in the starter's language. +/// +public class PrecipitationItem : ComboBoxItem +{ + public static readonly StyledProperty HeavyProperty = + AvaloniaProperty.Register(nameof(Heavy)); + + public static readonly StyledProperty SnowProperty = + AvaloniaProperty.Register(nameof(Snow)); + + public PrecipitationItem() => UpdateText(); + + /// Rain or snow rather than light rain or light snow. + public bool Heavy + { + get => GetValue(HeavyProperty); + set => SetValue(HeavyProperty, value); + } + + public bool Snow + { + get => GetValue(SnowProperty); + set => SetValue(SnowProperty, value); + } + + protected override Type StyleKeyOverride => typeof(ComboBoxItem); + + /// The key of the text the option is named by. + public string Key => (Snow ? "OvercastSnow" : "OvercastRain") + (Heavy ? "" : "Light"); + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + if (change.Property == HeavyProperty || change.Property == SnowProperty) + UpdateText(); + } + + protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) + { + base.OnAttachedToLogicalTree(e); + AppLanguage.Changed += UpdateText; + UpdateText(); + } + + protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) + { + AppLanguage.Changed -= UpdateText; + base.OnDetachedFromLogicalTree(e); + } + + private void UpdateText() => Content = AppLanguage.Text(Key); +} diff --git a/StarterNG/Views/Scenarios.axaml b/StarterNG/Views/Scenarios.axaml index 0d090dd..2370ef5 100644 --- a/StarterNG/Views/Scenarios.axaml +++ b/StarterNG/Views/Scenarios.axaml @@ -193,8 +193,8 @@ - - + + Fog read-out in the language the user is reading the rest in. private static string FogScale2(int metres) => FogScale.Format(metres, LanguageCulture); - private bool? _precipitationIsSnow; - - /// Above 1 the overcast rains or snows, as the temperature decides in the simulator. - private void ShowPrecipitationAs(bool snow) - { - if (_precipitationIsSnow == snow) - return; - _precipitationIsSnow = snow; - weatherPrecipitationLight[!ContentProperty] = - new Avalonia.Data.Binding(snow ? "[OvercastSnowLight]" : "[OvercastRainLight]") { Source = App.Loc }; - weatherPrecipitation[!ContentProperty] = - new Avalonia.Data.Binding(snow ? "[OvercastSnow]" : "[OvercastRain]") { Source = App.Loc }; - } - private const string RandomTag = "random"; private static void SelectByTag(ComboBox combo, string tag, string? excludeFromNearest = null) From cb9c8cbb08306380a7bdbb03f3b1f967ed42f366 Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 30 Nov 2026 19:29:18 +0100 Subject: [PATCH 3/3] test(weather): a rain or snow option is themed in a window and names itself there too --- StarterNG.Tests/PrecipitationItemTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/StarterNG.Tests/PrecipitationItemTests.cs b/StarterNG.Tests/PrecipitationItemTests.cs index 0b06eda..7574c51 100644 --- a/StarterNG.Tests/PrecipitationItemTests.cs +++ b/StarterNG.Tests/PrecipitationItemTests.cs @@ -50,4 +50,23 @@ public class PrecipitationItemTests ShowsText("OvercastRain", item); } + + [Fact] + public void In_a_window_the_option_looks_like_any_other_and_still_follows_the_temperature() + { + var item = new PrecipitationItem { Heavy = true }; + var combo = new ComboBox { Items = { new ComboBoxItem { Content = "Bezchmurnie" }, item } }; + var window = Controls.Show(combo, themed: true); + + combo.IsDropDownOpen = true; + window.UpdateLayout(); + + Assert.NotNull(item.Template); + item.Snow = true; + ShowsText("OvercastSnow", item); + + window.Close(); + item.Snow = false; + ShowsText("OvercastRain", item); + } }