mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 06:55:59 +01:00
fix(settings): a profile is not moved to physicslog.trains, and a closed tape window keeps nothing
- the one-time move runs on the player's own settings only; a profile from before it keeps physicslog as it was, and the player's mark of the move stays when it is applied - a read of the tapes under way when the window closes is let go
This commit is contained in:
@@ -1257,6 +1257,23 @@ public class SettingsStoreTests
|
|||||||
Assert.False(store.LoadFailed);
|
Assert.False(store.LoadFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void A_profile_from_before_the_move_is_not_moved_and_keeps_the_players_mark()
|
||||||
|
{
|
||||||
|
var files = new InMemoryFileSystem()
|
||||||
|
.WithFile(UserIni, "starter.physicslog.moved yes\nphysicslog yes\n")
|
||||||
|
.WithFile(Profile, "physicslog yes\n");
|
||||||
|
var store = WithHome(files).SettingsStore;
|
||||||
|
store.Load();
|
||||||
|
|
||||||
|
Assert.True(store.TryLoadProfile(Profile));
|
||||||
|
store.Save();
|
||||||
|
|
||||||
|
Assert.True(store.Settings.PhysicsLog);
|
||||||
|
Assert.False(store.Settings.PhysicsLogTrains);
|
||||||
|
Assert.Contains("starter.physicslog.moved yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void A_missing_profile_leaves_the_settings_as_they_are()
|
public void A_missing_profile_leaves_the_settings_as_they_are()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ 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>
|
||||||
@@ -113,8 +116,6 @@ public sealed class SettingsStore
|
|||||||
|
|
||||||
_serializer.Read(Settings, _config);
|
_serializer.Read(Settings, _config);
|
||||||
_synced = Render(Settings);
|
_synced = Render(Settings);
|
||||||
if (!LoadFailed)
|
|
||||||
SettingsSerializer.MovePhysicsLog(Settings);
|
|
||||||
TouchConfigAge();
|
TouchConfigAge();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +127,15 @@ 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)
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ public sealed class HaslerTapeWindow : Window
|
|||||||
private bool _running;
|
private bool _running;
|
||||||
private bool _loading;
|
private bool _loading;
|
||||||
private bool _looking;
|
private bool _looking;
|
||||||
|
// closed: a read already under way when it closed is let go, not kept followed
|
||||||
|
private bool _closed;
|
||||||
|
|
||||||
/// <summary>A setting went on from here; the settings page's boxes have to follow it.</summary>
|
/// <summary>A setting went on from here; the settings page's boxes have to follow it.</summary>
|
||||||
public event Action? LogEnabled;
|
public event Action? LogEnabled;
|
||||||
@@ -226,6 +228,7 @@ public sealed class HaslerTapeWindow : Window
|
|||||||
Activated += (_, _) => ShowWhatIsKnown();
|
Activated += (_, _) => ShowWhatIsKnown();
|
||||||
Closed += (_, _) =>
|
Closed += (_, _) =>
|
||||||
{
|
{
|
||||||
|
_closed = true;
|
||||||
_timer.Stop();
|
_timer.Stop();
|
||||||
_tapes.Forget();
|
_tapes.Forget();
|
||||||
};
|
};
|
||||||
@@ -643,6 +646,11 @@ public sealed class HaslerTapeWindow : Window
|
|||||||
// the same tape grown, as the simulator writes it: only what was added is read
|
// the same tape grown, as the simulator writes it: only what was added is read
|
||||||
bool follow = file.Path == _shown?.Path && file.Size >= _shown.Size;
|
bool follow = file.Path == _shown?.Path && file.Size >= _shown.Size;
|
||||||
var tape = await Task.Run(() => _tapes.Load(file, follow));
|
var tape = await Task.Run(() => _tapes.Load(file, follow));
|
||||||
|
if (_closed)
|
||||||
|
{
|
||||||
|
_tapes.Forget();
|
||||||
|
return;
|
||||||
|
}
|
||||||
bool another = file.Path != _shown?.Path;
|
bool another = file.Path != _shown?.Path;
|
||||||
_shown = file;
|
_shown = file;
|
||||||
_tapeless = null;
|
_tapeless = null;
|
||||||
@@ -697,6 +705,8 @@ public sealed class HaslerTapeWindow : Window
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sessions = await Task.Run(_tapes.Sessions);
|
var sessions = await Task.Run(_tapes.Sessions);
|
||||||
|
if (_closed)
|
||||||
|
return;
|
||||||
bool live = _live.IsChecked == true;
|
bool live = _live.IsChecked == true;
|
||||||
bool newDriven = live && DrivenTape(sessions) is { } driven && driven.Path != _followed;
|
bool newDriven = live && DrivenTape(sessions) is { } driven && driven.Path != _followed;
|
||||||
if (newDriven || Fingerprint(sessions) != _listed)
|
if (newDriven || Fingerprint(sessions) != _listed)
|
||||||
|
|||||||
Reference in New Issue
Block a user