mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 06:55:59 +01:00
refactor(settings): the move to the trains' tapes made simple, by the black box line
An ini with no physicslog.trains line and blackbox yes gets physicslog.trains yes and physicslog no. The line of the trains' tapes, written from then on even when turned off again, is the mark that it was done; the starter.physicslog.moved key is gone. A profile goes the same way as the ini.
This commit is contained in:
@@ -1258,20 +1258,20 @@ public class SettingsStoreTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void A_profile_from_before_the_move_is_not_moved_and_keeps_the_players_mark()
|
public void A_profile_from_before_the_tapes_of_the_trains_is_moved_as_the_ini_would_be()
|
||||||
{
|
{
|
||||||
var files = new InMemoryFileSystem()
|
var files = new InMemoryFileSystem()
|
||||||
.WithFile(UserIni, "starter.physicslog.moved yes\nphysicslog yes\n")
|
.WithFile(UserIni, "physicslog no\nphysicslog.trains no\n")
|
||||||
.WithFile(Profile, "physicslog yes\n");
|
.WithFile(Profile, "physicslog yes\nblackbox yes\n");
|
||||||
var store = WithHome(files).SettingsStore;
|
var store = WithHome(files).SettingsStore;
|
||||||
store.Load();
|
store.Load();
|
||||||
|
|
||||||
Assert.True(store.TryLoadProfile(Profile));
|
Assert.True(store.TryLoadProfile(Profile));
|
||||||
store.Save();
|
store.Save();
|
||||||
|
|
||||||
Assert.True(store.Settings.PhysicsLog);
|
Assert.False(store.Settings.PhysicsLog);
|
||||||
Assert.False(store.Settings.PhysicsLogTrains);
|
Assert.True(store.Settings.PhysicsLogTrains);
|
||||||
Assert.Contains("starter.physicslog.moved yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
Assert.Contains("physicslog.trains yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -1321,9 +1321,9 @@ public class SettingsStoreTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("starter.physicslog.moved yes\nphysicslog yes\n", true)]
|
[InlineData("physicslog yes\n", true)]
|
||||||
[InlineData("physicslog no\n", false)]
|
[InlineData("physicslog no\n", false)]
|
||||||
[InlineData("starter.physicslog.moved yes\nphysicslog yes\nblackbox no\n", false)]
|
[InlineData("physicslog yes\nblackbox no\n", false)]
|
||||||
[InlineData("physicslog no\nblackbox yes\n", true)]
|
[InlineData("physicslog no\nblackbox yes\n", true)]
|
||||||
public void The_black_box_goes_with_the_physics_log_unless_the_ini_says_otherwise(string ini, bool recorded)
|
public void The_black_box_goes_with_the_physics_log_unless_the_ini_says_otherwise(string ini, bool recorded)
|
||||||
{
|
{
|
||||||
@@ -1350,7 +1350,7 @@ public class SettingsStoreTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void A_black_box_that_says_no_more_than_the_physics_log_adds_no_line()
|
public void A_black_box_that_says_no_more_than_the_physics_log_adds_no_line()
|
||||||
{
|
{
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "starter.physicslog.moved yes\nphysicslog yes\n"));
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog yes\n"));
|
||||||
installation.SettingsStore.Load();
|
installation.SettingsStore.Load();
|
||||||
installation.SettingsStore.Settings.Width = 1600;
|
installation.SettingsStore.Settings.Width = 1600;
|
||||||
|
|
||||||
@@ -1360,7 +1360,7 @@ public class SettingsStoreTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("starter.physicslog.moved yes\nphysicslog yes\nblackbox yes\n")]
|
[InlineData("physicslog yes\nblackbox yes\n")]
|
||||||
[InlineData("physicslog no\nblackbox yes\n")]
|
[InlineData("physicslog no\nblackbox yes\n")]
|
||||||
public void A_black_box_line_of_the_file_says_no_once_the_box_is_off(string ini)
|
public void A_black_box_line_of_the_file_says_no_once_the_box_is_off(string ini)
|
||||||
{
|
{
|
||||||
@@ -1379,7 +1379,7 @@ public class SettingsStoreTests
|
|||||||
public void The_physics_log_turned_off_keeps_the_tapes_it_brought()
|
public void The_physics_log_turned_off_keeps_the_tapes_it_brought()
|
||||||
{
|
{
|
||||||
// an ini of before the black box had a key: the tapes came with the physics log
|
// an ini of before the black box had a key: the tapes came with the physics log
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "starter.physicslog.moved yes\nphysicslog yes\n"));
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog yes\n"));
|
||||||
installation.SettingsStore.Load();
|
installation.SettingsStore.Load();
|
||||||
installation.SettingsStore.Settings.PhysicsLog = false;
|
installation.SettingsStore.Settings.PhysicsLog = false;
|
||||||
|
|
||||||
@@ -1403,9 +1403,9 @@ public class SettingsStoreTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("physicslog yes\n", true)]
|
[InlineData("physicslog yes\nblackbox yes\n")]
|
||||||
[InlineData("physicslog yes\nblackbox no\n", false)]
|
[InlineData("physicslog no\nblackbox yes\n")]
|
||||||
public void The_physics_log_of_every_vehicle_left_on_is_moved_once_to_the_tapes_of_the_trains(string ini, bool recorded)
|
public void Recording_turned_on_before_the_tapes_of_the_trains_is_moved_to_them(string ini)
|
||||||
{
|
{
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini));
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini));
|
||||||
|
|
||||||
@@ -1413,37 +1413,43 @@ public class SettingsStoreTests
|
|||||||
var s = installation.SettingsStore.Settings;
|
var s = installation.SettingsStore.Settings;
|
||||||
Assert.False(s.PhysicsLog);
|
Assert.False(s.PhysicsLog);
|
||||||
Assert.True(s.PhysicsLogTrains);
|
Assert.True(s.PhysicsLogTrains);
|
||||||
// a black box the ini turned off itself stays off
|
Assert.True(s.BlackBox);
|
||||||
Assert.Equal(recorded, s.BlackBox);
|
|
||||||
|
|
||||||
installation.SettingsStore.Save();
|
installation.SettingsStore.Save();
|
||||||
Assert.Equal("physicslog no", LineFor(installation, "physicslog"));
|
Assert.Equal("physicslog no", LineFor(installation, "physicslog"));
|
||||||
Assert.Equal("physicslog.trains yes", LineFor(installation, "physicslog.trains"));
|
Assert.Equal("physicslog.trains yes", LineFor(installation, "physicslog.trains"));
|
||||||
Assert.Equal("starter.physicslog.moved yes", LineFor(installation, "starter.physicslog.moved"));
|
Assert.Equal("blackbox yes", LineFor(installation, "blackbox"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("physicslog yes\n", true)]
|
||||||
|
[InlineData("physicslog yes\nblackbox no\n", true)]
|
||||||
|
[InlineData("physicslog yes\nblackbox yes\nphysicslog.trains no\n", true)]
|
||||||
|
[InlineData("physicslog no\nblackbox yes\nphysicslog.trains no\n", false)]
|
||||||
|
public void Without_a_black_box_line_saying_yes_or_with_the_trains_tapes_line_nothing_is_moved(string ini, bool physicsLog)
|
||||||
|
{
|
||||||
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini));
|
||||||
|
|
||||||
|
installation.SettingsStore.Load();
|
||||||
|
|
||||||
|
Assert.Equal(physicsLog, installation.SettingsStore.Settings.PhysicsLog);
|
||||||
|
Assert.False(installation.SettingsStore.Settings.PhysicsLogTrains);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void The_physics_log_of_every_vehicle_turned_on_again_stays_on()
|
public void Once_moved_the_physics_log_of_every_vehicle_turned_on_again_stays_on()
|
||||||
{
|
{
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog yes\n"));
|
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog yes\nblackbox yes\n"));
|
||||||
installation.SettingsStore.Load();
|
installation.SettingsStore.Load();
|
||||||
installation.SettingsStore.Settings.PhysicsLog = true;
|
installation.SettingsStore.Settings.PhysicsLog = true;
|
||||||
|
installation.SettingsStore.Settings.PhysicsLogTrains = false;
|
||||||
installation.SettingsStore.Save();
|
installation.SettingsStore.Save();
|
||||||
|
|
||||||
installation.SettingsStore.Load();
|
installation.SettingsStore.Load();
|
||||||
|
|
||||||
Assert.True(installation.SettingsStore.Settings.PhysicsLog);
|
Assert.True(installation.SettingsStore.Settings.PhysicsLog);
|
||||||
Assert.Equal("physicslog yes", LineFor(installation, "physicslog"));
|
Assert.False(installation.SettingsStore.Settings.PhysicsLogTrains);
|
||||||
}
|
Assert.Equal("physicslog.trains no", LineFor(installation, "physicslog.trains"));
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void A_new_ini_is_marked_so_the_physics_log_turned_on_later_is_never_moved()
|
|
||||||
{
|
|
||||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog no\n"));
|
|
||||||
installation.SettingsStore.Load();
|
|
||||||
installation.SettingsStore.Save();
|
|
||||||
|
|
||||||
Assert.Equal("starter.physicslog.moved yes", LineFor(installation, "starter.physicslog.moved"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -83,9 +83,6 @@ public sealed class SettingsStore
|
|||||||
string source = _files.FileExists(_savePath) ? _savePath : _paths.InstallationConfigPath();
|
string source = _files.FileExists(_savePath) ? _savePath : _paths.InstallationConfigPath();
|
||||||
LoadedFrom = source;
|
LoadedFrom = source;
|
||||||
LoadFrom(source);
|
LoadFrom(source);
|
||||||
// the player's own settings only, after the snapshot so the next save writes it; a profile is not moved
|
|
||||||
if (!LoadFailed)
|
|
||||||
SettingsSerializer.MovePhysicsLog(Settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>A player with no settings of their own yet starts at High, in the file at once so the simulator goes by it too.</summary>
|
/// <summary>A player with no settings of their own yet starts at High, in the file at once so the simulator goes by it too.</summary>
|
||||||
@@ -116,6 +113,9 @@ public sealed class SettingsStore
|
|||||||
|
|
||||||
_serializer.Read(Settings, _config);
|
_serializer.Read(Settings, _config);
|
||||||
_synced = Render(Settings);
|
_synced = Render(Settings);
|
||||||
|
// after the snapshot, so the next save writes it; a profile of before goes the same way as the ini would
|
||||||
|
if (!LoadFailed)
|
||||||
|
SettingsSerializer.MoveToTrainTapes(Settings);
|
||||||
TouchConfigAge();
|
TouchConfigAge();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,15 +127,9 @@ public sealed class SettingsStore
|
|||||||
{
|
{
|
||||||
if (_files.FileExists(path))
|
if (_files.FileExists(path))
|
||||||
{
|
{
|
||||||
// a profile saved before the move has no mark of it: the player's mark is kept, so their own
|
|
||||||
// physicslog is not moved again at the next start
|
|
||||||
bool moved = Settings.PhysicsLogMoved;
|
|
||||||
LoadFrom(path);
|
LoadFrom(path);
|
||||||
if (!LoadFailed)
|
if (!LoadFailed)
|
||||||
{
|
|
||||||
Settings.PhysicsLogMoved |= moved;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LoadFailed)
|
if (LoadFailed)
|
||||||
|
|||||||
@@ -147,11 +147,6 @@ public sealed class SimulatorSettings
|
|||||||
public bool PhysicsLogTrains;
|
public bool PhysicsLogTrains;
|
||||||
/// <summary>Whether eu07.ini had a line for the logs of the trains when read: kept, else written only when on.</summary>
|
/// <summary>Whether eu07.ini had a line for the logs of the trains when read: kept, else written only when on.</summary>
|
||||||
public bool PhysicsLogTrainsInIni;
|
public bool PhysicsLogTrainsInIni;
|
||||||
/// <summary>
|
|
||||||
/// Whether the physics log of every vehicle, which a starter before called the speedometer's tapes, was moved once
|
|
||||||
/// to the tapes of the trains and the black box: an ini read with it on and this not yet done is moved so.
|
|
||||||
/// </summary>
|
|
||||||
public bool PhysicsLogMoved;
|
|
||||||
public bool DebugLog = true;
|
public bool DebugLog = true;
|
||||||
public bool MultipleLogs;
|
public bool MultipleLogs;
|
||||||
public bool DisplaySimulation = true;
|
public bool DisplaySimulation = true;
|
||||||
|
|||||||
@@ -9,23 +9,19 @@ namespace StarterNG.Infrastructure.Settings;
|
|||||||
|
|
||||||
public sealed class SettingsSerializer
|
public sealed class SettingsSerializer
|
||||||
{
|
{
|
||||||
// the physics log of every vehicle moved once to the tapes of the trains (SimulatorSettings.PhysicsLogMoved)
|
|
||||||
private const string PhysicsLogMovedKey = "starter.physicslog.moved";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// "physicslog yes", left on from a starter which called it the speedometer's tapes: the log of every vehicle,
|
/// An ini of before the tapes of the trains, its recording turned on ("blackbox yes", with the physics log of every
|
||||||
/// hundreds of files on a big scenery. Moved once to the tapes of the trains, with the black box unless the ini
|
/// vehicle, hundreds of files on a big scenery): moved to the tapes of the trains, the log of every vehicle off.
|
||||||
/// turned it off itself; whoever wants the log of every vehicle turns it on again, and it stays so. A change of
|
/// Once: saved, the line of the trains' tapes is in the file, even turned off again before. A change of the
|
||||||
/// the starter's, after the file is read, so saving writes it.
|
/// starter's, after the file is read, so saving writes it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void MovePhysicsLog(SimulatorSettings s)
|
public static void MoveToTrainTapes(SimulatorSettings s)
|
||||||
{
|
{
|
||||||
if (!s.PhysicsLogMoved && s.PhysicsLog)
|
if (s.PhysicsLogTrainsInIni || !s.BlackBoxInIni || !s.BlackBox)
|
||||||
{
|
return;
|
||||||
s.PhysicsLog = false;
|
s.PhysicsLogTrains = true;
|
||||||
s.PhysicsLogTrains = true;
|
s.PhysicsLogTrainsInIni = true;
|
||||||
}
|
s.PhysicsLog = false;
|
||||||
s.PhysicsLogMoved = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly bool _dlssPlatform;
|
private readonly bool _dlssPlatform;
|
||||||
@@ -181,7 +177,6 @@ public sealed class SettingsSerializer
|
|||||||
// the simulator records the black box along with the physics logs when the ini says nothing of it
|
// the simulator records the black box along with the physics logs when the ini says nothing of it
|
||||||
s.BlackBoxInIni = c.Has("blackbox");
|
s.BlackBoxInIni = c.Has("blackbox");
|
||||||
s.BlackBox = s.BlackBoxInIni ? c.GetBool("blackbox", false) : s.PhysicsLog || s.PhysicsLogTrains;
|
s.BlackBox = s.BlackBoxInIni ? c.GetBool("blackbox", false) : s.PhysicsLog || s.PhysicsLogTrains;
|
||||||
s.PhysicsLogMoved = c.GetBool(PhysicsLogMovedKey, false);
|
|
||||||
int debugLog = c.GetInt("debuglog", 3);
|
int debugLog = c.GetInt("debuglog", 3);
|
||||||
s.DebugLog = (debugLog & 1) != 0;
|
s.DebugLog = (debugLog & 1) != 0;
|
||||||
s.DebugLogVisible = (debugLog & 2) != 0;
|
s.DebugLogVisible = (debugLog & 2) != 0;
|
||||||
@@ -402,8 +397,6 @@ public sealed class SettingsSerializer
|
|||||||
// a simulator before it doesn't know the line: an ini without it stays so while it is off
|
// a simulator before it doesn't know the line: an ini without it stays so while it is off
|
||||||
if (s.PhysicsLogTrainsInIni || s.PhysicsLogTrains)
|
if (s.PhysicsLogTrainsInIni || s.PhysicsLogTrains)
|
||||||
c.SetBool("physicslog.trains", s.PhysicsLogTrains);
|
c.SetBool("physicslog.trains", s.PhysicsLogTrains);
|
||||||
if (s.PhysicsLogMoved)
|
|
||||||
c.SetBool(PhysicsLogMovedKey, true);
|
|
||||||
c.SetInt("debuglog",
|
c.SetInt("debuglog",
|
||||||
(s.DebugLog ? 1 : 0) | (s.DebugLogVisible ? 2 : 0) | s.DebugLogExtraBits);
|
(s.DebugLog ? 1 : 0) | (s.DebugLogVisible ? 2 : 0) | s.DebugLogExtraBits);
|
||||||
c.SetBool("multiplelogs", s.MultipleLogs);
|
c.SetBool("multiplelogs", s.MultipleLogs);
|
||||||
|
|||||||
Reference in New Issue
Block a user