From 7c2d259fdc62af09d22f646b5b98464775430e3e Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Sun, 29 Nov 2026 20:16:24 +0100 Subject: [PATCH] feat(settings): the physical models of the simulator, and Arcade and Realistic levels of realism The Physics tab has a section of driving realism with the models the simulator reads (utilities/Globals.cpp): - couplerphysics: the legacy couplings, or the physical ones (play, give, breaking) of the player's train or of every train; - physics.derailment: off, classic (the simulator's own monitor), physical; - physics.collisions: classic or physical (the simulator's own); - physics.trackbuckling: off, from the scenery (its own), also from heat; - deer: animals by the track; with the crash damage, the breaking pantographs, the power from the wires only and the state of a consist at its start, moved here from General. Two levels set them in one go: Arcade forgives - no derailment, the legacy couplings and collisions, no buckling, no damage, power without the wires, every consist ready to drive; Realistic takes the physical models - the couplings of the player's train, the derailment by its criteria (a track's own speed limit still derails nothing), the crush of the ends, buckling in the heat - and the consists as the scenario has them. The simulator's own values stand between the two and show as custom; each setting can still be changed on its own. The developer tab has physics.derailment.trustlimits, controlcoupling.enginecheck, ai.brakesetting.cw1 and physics.trackcheck. A list takes the other words the simulator reads for its own (couplerphysics true, physics.derailment no), and a word of a list is named per key where it means something of its own there. --- StarterNG.Tests/PhysicsPresetTests.cs | 105 +++++++++++++++++++ StarterNG.Tests/SettingsUnknownValueTests.cs | 26 +++++ StarterNG/Domain/Settings/PhysicsPreset.cs | 68 ++++++++++++ StarterNG/Domain/Settings/SimulatorKeys.cs | 31 +++++- StarterNG/Views/Settings.axaml | 39 +++++-- StarterNG/Views/Settings.axaml.cs | 54 ++++++++++ StarterNG/Views/SimulatorKeyRows.cs | 14 +-- StarterNG/startercfg/lang/cz.xml | 23 ++++ StarterNG/startercfg/lang/en.xml | 34 ++++++ StarterNG/startercfg/lang/hu.xml | 23 ++++ StarterNG/startercfg/lang/pl.xml | 34 ++++++ StarterNG/startercfg/lang/ru.xml | 23 ++++ StarterNG/startercfg/lang/zh.xml | 23 ++++ 13 files changed, 478 insertions(+), 19 deletions(-) create mode 100644 StarterNG.Tests/PhysicsPresetTests.cs create mode 100644 StarterNG/Domain/Settings/PhysicsPreset.cs diff --git a/StarterNG.Tests/PhysicsPresetTests.cs b/StarterNG.Tests/PhysicsPresetTests.cs new file mode 100644 index 0000000..9d81787 --- /dev/null +++ b/StarterNG.Tests/PhysicsPresetTests.cs @@ -0,0 +1,105 @@ +using StarterNG.Domain.Settings; +using StarterNG.Tests.Fakes; + +namespace StarterNG.Tests; + +public class PhysicsPresetTests +{ + private static SimulatorSettings Defaults() + { + var installation = new TestInstallation(); + installation.SettingsStore.Load(); + return installation.SettingsStore.Settings.Copy(); + } + + [Fact] + public void The_simulators_own_physics_are_neither_arcade_nor_realistic() + { + Assert.Null(PhysicsPreset.Matching(Defaults())); + } + + [Fact] + public void A_level_of_realism_applied_is_recognised_until_one_setting_moves() + { + foreach (var preset in PhysicsPreset.All) + { + var settings = Defaults(); + preset.ApplyTo(settings); + Assert.Same(preset, PhysicsPreset.Matching(settings)); + + settings.CrashDamage = !settings.CrashDamage; + Assert.Null(PhysicsPreset.Matching(settings)); + } + } + + [Fact] + public void Arcade_forgives_and_realistic_takes_the_physical_models() + { + var arcade = Defaults(); + PhysicsPreset.Arcade.ApplyTo(arcade); + Assert.False(arcade.CrashDamage); + Assert.False(arcade.LiveTraction); + Assert.Equal(ConsistReadyOverride.AlwaysReady, arcade.ReadyOverride); + Assert.Equal("off", arcade.Extra["physics.derailment"]); + + var realistic = Defaults(); + PhysicsPreset.Realistic.ApplyTo(realistic); + Assert.True(realistic.CrashDamage); + Assert.Equal(ConsistReadyOverride.Scenery, realistic.ReadyOverride); + Assert.Equal("yes", realistic.Extra["couplerphysics"]); + Assert.Equal("new", realistic.Extra["physics.derailment"]); + Assert.Equal("new", realistic.Extra["physics.collisions"]); + Assert.Equal("auto", realistic.Extra["physics.trackbuckling"]); + } + + [Fact] + public void Every_value_of_a_level_is_one_its_row_offers() + { + foreach (var preset in PhysicsPreset.All) + foreach (var (name, value) in preset.Keys) + Assert.True(SimulatorKeys.Named(name).ChoiceIndex(value) >= 0, $"{preset.NameKey} {name} {value}"); + Assert.All(PhysicsPreset.All.SelectMany(preset => preset.Keys.Keys), key => Assert.Contains(key, PhysicsPreset.AllKeys)); + } + + [Fact] + public void No_level_of_realism_touches_the_picture_nor_a_level_of_detail_the_realism() + { + var settings = Defaults(); + GraphicsPreset.Low.ApplyTo(settings); + PhysicsPreset.Realistic.ApplyTo(settings); + Assert.Same(GraphicsPreset.Low, GraphicsPreset.Matching(settings)); + + GraphicsPreset.VeryHigh.ApplyTo(settings); + Assert.Same(PhysicsPreset.Realistic, PhysicsPreset.Matching(settings)); + } + + [Theory] + [InlineData("couplerphysics", "true", "yes")] + [InlineData("couplerphysics", "1", "yes")] + [InlineData("physics.derailment", "no", "off")] + [InlineData("physics.trackbuckling", "no", "off")] + [InlineData("couplerphysics", "no", "no")] + public void A_word_the_simulator_takes_for_another_stands_for_it(string name, string raw, string word) + { + var key = SimulatorKeys.Named(name); + Assert.Equal(key.ChoiceIndex(word), key.ChoiceIndex(raw)); + } + + [Fact] + public void A_level_of_realism_survives_a_save() + { + var installation = new TestInstallation(); + var store = installation.SettingsStore; + store.Load(); + PhysicsPreset.Realistic.ApplyTo(store.Settings); + + store.Save(); + + var again = new TestInstallation(installation.Files).SettingsStore; + again.Load(); + Assert.Same(PhysicsPreset.Realistic, PhysicsPreset.Matching(again.Settings)); + string saved = installation.Files.ReadAllText(store.SavePath); + Assert.Contains("physics.derailment new", saved); + Assert.Contains("couplerphysics yes", saved); + } +} diff --git a/StarterNG.Tests/SettingsUnknownValueTests.cs b/StarterNG.Tests/SettingsUnknownValueTests.cs index 12ab51a..74251f0 100644 --- a/StarterNG.Tests/SettingsUnknownValueTests.cs +++ b/StarterNG.Tests/SettingsUnknownValueTests.cs @@ -81,6 +81,32 @@ public class SettingsUnknownValueTests }); } + [Fact] + public void A_level_of_realism_picked_is_saved_and_marked_until_a_setting_moves() + { + WithPage(Standard, (page, services, saved) => + { + var buttons = page.FindControl("PhysicsPresetButtons")!.Children.OfType