mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-16 21:14:10 +01:00
Compare commits
21 Commits
v1.6.280
...
feat/tapes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0fa2d1768 | ||
|
|
fa8ae760e1 | ||
|
|
195f358e55 | ||
|
|
be7b9c5679 | ||
|
|
faa06fb9d8 | ||
|
|
829a3e7a3d | ||
|
|
5b43e29f9e | ||
|
|
b63ba8fe2e | ||
|
|
76693c1494 | ||
|
|
13990a7036 | ||
|
|
5ab9bce321 | ||
|
|
f1d77addae | ||
|
|
192f9fa499 | ||
|
|
92c0283479 | ||
|
|
b2fd53f7bc | ||
|
|
06513537f0 | ||
|
|
7823bb8d09 | ||
|
|
1398545ff2 | ||
|
|
45105e7b9c | ||
|
|
4429eff4ef | ||
|
|
1ef630b1b6 |
@@ -30,7 +30,7 @@ public sealed class DefaultBlackBoxStrings : IBlackBoxStrings
|
||||
["MapHelp"] = "The map of the run. What it shows is also in the events and the timetable, and on the run below it.",
|
||||
["Follow"] = "Follow the train",
|
||||
["Fit"] = "Whole map",
|
||||
["NoFile"] = "Open a black box: physicslog/*.blackbox, written with the physics logs on.",
|
||||
["NoFile"] = "Open a black box: physicslog/*.blackbox, written with the black box or the physics logs on.",
|
||||
["Unreadable"] = "Can't read {0}: {1}",
|
||||
["Reading"] = "Reading {0}…",
|
||||
["Summary"] = "{0} · {1:0.0} km · max {2:0} km/h · driven {3} · autopilot {4} · over the AI {5} ({6} by more than {7:0} km/h, at most +{8:0} km/h) · signals {9} · at danger {10} · commands {11}",
|
||||
@@ -190,6 +190,7 @@ public sealed class DefaultBlackBoxStrings : IBlackBoxStrings
|
||||
["EventSecurityAlarmMissed"] = "{0} buzzer, not acknowledged",
|
||||
["EventTimetable"] = "Timetable {0}, {1}",
|
||||
["CabSpeed"] = "Speed",
|
||||
["CabWheels"] = "wheels {0:0}",
|
||||
["CabAiTarget"] = "AI {0:0} km/h",
|
||||
["CabAcceleration"] = "Along",
|
||||
["CabLateral"] = "Lateral",
|
||||
@@ -308,7 +309,7 @@ public sealed class DefaultBlackBoxStrings : IBlackBoxStrings
|
||||
["MapHelp"] = "Mapa przejazdu. To, co pokazuje, jest też w zdarzeniach, w rozkładzie i na przebiegu jazdy pod nią.",
|
||||
["Follow"] = "Śledź pociąg",
|
||||
["Fit"] = "Cała mapa",
|
||||
["NoFile"] = "Otwórz czarną skrzynkę: physicslog/*.blackbox, zapisywaną razem z logami fizyki.",
|
||||
["NoFile"] = "Otwórz czarną skrzynkę: physicslog/*.blackbox, zapisywaną przy włączonej czarnej skrzynce albo logach fizyki.",
|
||||
["Unreadable"] = "Nie można odczytać {0}: {1}",
|
||||
["Reading"] = "Czytanie {0}…",
|
||||
["Summary"] = "{0} · {1:0.0} km · maks. {2:0} km/h · jazda {3} · autopilot {4} · ponad AI {5} (w tym {6} o więcej niż {7:0} km/h, najwyżej +{8:0} km/h) · sygnalizatory {9} · minięte na „Stój” {10} · komendy {11}",
|
||||
@@ -468,6 +469,7 @@ public sealed class DefaultBlackBoxStrings : IBlackBoxStrings
|
||||
["EventSecurityAlarmMissed"] = "Brzęczyk {0}, bez potwierdzenia",
|
||||
["EventTimetable"] = "Rozkład {0}, {1}",
|
||||
["CabSpeed"] = "Prędkość",
|
||||
["CabWheels"] = "koła {0:0}",
|
||||
["CabAiTarget"] = "AI {0:0} km/h",
|
||||
["CabAcceleration"] = "Wzdłużne",
|
||||
["CabLateral"] = "Boczne",
|
||||
|
||||
@@ -24,6 +24,7 @@ public sealed class CabPanel : Control
|
||||
private const double LampRow = 14;
|
||||
private const int DoorColumns = 2;
|
||||
private const double DriveRow = 34;
|
||||
private const double WheelsApartKmh = 1.0; // the wheels shown when they turn this much faster or slower
|
||||
|
||||
private Recording? _recording;
|
||||
private double _time;
|
||||
@@ -174,8 +175,19 @@ public sealed class CabPanel : Control
|
||||
var speed = MapView.Text(kmh, SpeedBrush(DrivingSummary.Judge(s)), 36, FontWeight.SemiBold);
|
||||
context.DrawText(speed, new Point(Pad, 24));
|
||||
Say($"{kmh} km/h");
|
||||
context.DrawText(MapView.Text("km/h", Palette.DimText, 12), new Point(Pad + speed.Width + 4, 24 + speed.Height - 21));
|
||||
var unit = MapView.Text("km/h", Palette.DimText, 12);
|
||||
context.DrawText(unit, new Point(Pad + speed.Width + 4, 24 + speed.Height - 21));
|
||||
double gaugeX = Pad + Math.Max(150, width * 0.42);
|
||||
// the wheels, when they turn otherwise: slipping, or locked in a skid. Signed both, so wheels slipping ahead
|
||||
// of a train rolling back show too. Kept off the gauges at the right, as the AI's line is.
|
||||
if (s.WheelSpeedKmh is { } wheels && Math.Abs(wheels - s.SpeedKmh) >= WheelsApartKmh)
|
||||
{
|
||||
double wheelsX = Pad + speed.Width + 4 + unit.Width + 8;
|
||||
string wheelsText = string.Format(culture, Strings["CabWheels"], Math.Abs(wheels));
|
||||
using (context.PushClip(new Rect(wheelsX, 24, Math.Max(0, gaugeX - 8 - wheelsX), 40)))
|
||||
context.DrawText(MapView.Text(wheelsText, Palette.Warn, 12), new Point(wheelsX, 24 + speed.Height - 21));
|
||||
Say(wheelsText);
|
||||
}
|
||||
if (s.AiValid)
|
||||
{
|
||||
using (context.PushClip(new Rect(Pad, 76, gaugeX - Pad - 8, 40)))
|
||||
@@ -337,7 +349,7 @@ public sealed class CabPanel : Control
|
||||
{
|
||||
context.DrawText(MapView.Text(Strings["CabGroupDoors"], Palette.DimText, 10, FontWeight.SemiBold), new Point(Pad, top));
|
||||
Say(Strings["CabGroupDoors"]);
|
||||
var doors = Doors(s);
|
||||
var doors = Doors(s.AsTheCabSees);
|
||||
double doorColumn = width / DoorColumns;
|
||||
for (int i = 0; i < doors.Length; i++)
|
||||
{
|
||||
|
||||
@@ -316,6 +316,8 @@ public sealed class EventList : ListBox
|
||||
(CabDevices.DoorStep, "DevDoorStep"), (CabDevices.DoorLock, "DevDoorLock"), (CabDevices.SpeedControl, "DevSpeedControl")
|
||||
];
|
||||
|
||||
private const CabDevices DoorSides = CabDevices.DoorsLeft | CabDevices.DoorsRight | CabDevices.DoorPermitLeft | CabDevices.DoorPermitRight;
|
||||
|
||||
/// <summary>
|
||||
/// What the driver did in the cab, from one look to the next in the same vehicle: the switches on and off, the
|
||||
/// doors opened and closed, the departure signal, the hand brake, the brakes' setting, the radio's channel, the
|
||||
@@ -325,7 +327,8 @@ public sealed class EventList : ListBox
|
||||
{
|
||||
CabSample? last = null;
|
||||
bool movingOpen = false;
|
||||
foreach (var s in recording.Cab)
|
||||
// the doors' sides as the driver has them, from the cab the driver is in (CabSample.AsTheCabSees)
|
||||
foreach (var s in recording.Cab.Select(sample => sample.AsTheCabSees))
|
||||
{
|
||||
if (last is not { } b || b.Vehicle != s.Vehicle)
|
||||
{
|
||||
@@ -333,8 +336,10 @@ public sealed class EventList : ListBox
|
||||
movingOpen = false;
|
||||
continue;
|
||||
}
|
||||
bool Came(CabDevices device) => !b.Has(device) && s.Has(device);
|
||||
bool Went(CabDevices device) => b.Has(device) && !s.Has(device);
|
||||
// the other end swaps the sides, and tells nothing of the doors; no cab (0) sees them as the front one does
|
||||
bool sameCab = (b.CabEnd < 0) == (s.CabEnd < 0);
|
||||
bool Came(CabDevices device) => !b.Has(device) && s.Has(device) && (sameCab || (device & DoorSides) == 0);
|
||||
bool Went(CabDevices device) => b.Has(device) && !s.Has(device) && (sameCab || (device & DoorSides) == 0);
|
||||
foreach (var (device, key) in Switched)
|
||||
{
|
||||
if (Came(device))
|
||||
|
||||
@@ -172,6 +172,9 @@ public sealed class BlackBoxReader
|
||||
Extra = new CabExtra((EngineKind)r.U8(), r.U8(), r.U8(), r.F32(), r.F32(), r.F32(), r.F32(), r.F32(),
|
||||
r.F32(), r.F32(), r.F32(), r.I8(), r.U8(), r.U8(), r.F32(), r.F32(), r.F32(), r.F32())
|
||||
};
|
||||
// The speed of the wheels, later again.
|
||||
if (sample.Extra is not null && r.Remaining >= 4)
|
||||
sample = sample with { WheelSpeedKmh = r.F32() };
|
||||
rec.AddCab(sample);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -366,8 +366,12 @@ public readonly record struct CabSample(double Time, int Vehicle, Position Posit
|
||||
Lights LightsHead, Lights LightsTail, sbyte CabEnd = 0,
|
||||
SecurityFlags Security = SecurityFlags.None, float LateralAcceleration = 0,
|
||||
Movement Movement = Movement.Unknown, short LightHintHead = -1, short LightHintTail = -1,
|
||||
Lights? EquippedHead = null, Lights? EquippedTail = null, CabExtra? Extra = null)
|
||||
Lights? EquippedHead = null, Lights? EquippedTail = null, CabExtra? Extra = null,
|
||||
float? WheelSpeedKmh = null)
|
||||
{
|
||||
// WheelSpeedKmh: the speed of the wheels as they turn, which the speedometer shows, signed as SpeedKmh; apart
|
||||
// from it while they slip, 0 while they are locked in a skid. None in a recording made before it.
|
||||
|
||||
public bool Has(CabDevices device) => (Devices & device) == device;
|
||||
public bool Has(SecurityFlags flag) => (Security & flag) == flag;
|
||||
|
||||
@@ -386,6 +390,26 @@ public readonly record struct CabSample(double Time, int Vehicle, Position Posit
|
||||
/// </summary>
|
||||
public bool ProtectionBraking => Has(SecurityFlags.Braking) && (Has(SecurityFlags.Vigilance) || Has(SecurityFlags.CabSignal));
|
||||
|
||||
private const CabDevices LeftDoors = CabDevices.DoorsLeft | CabDevices.DoorPermitLeft;
|
||||
private const CabDevices RightDoors = CabDevices.DoorsRight | CabDevices.DoorPermitRight;
|
||||
|
||||
/// <summary>
|
||||
/// The doors as the driver has them: the recording holds the left and right of the vehicle, and from its rear
|
||||
/// cab the driver's left is the vehicle's right, as the simulator works the doors from it. Out of a cab, the
|
||||
/// vehicle's.
|
||||
/// </summary>
|
||||
public CabSample AsTheCabSees =>
|
||||
CabEnd >= 0
|
||||
? this
|
||||
: this with
|
||||
{
|
||||
Devices = (Devices & ~(LeftDoors | RightDoors))
|
||||
| ((Devices & CabDevices.DoorsLeft) != 0 ? CabDevices.DoorsRight : 0)
|
||||
| ((Devices & CabDevices.DoorsRight) != 0 ? CabDevices.DoorsLeft : 0)
|
||||
| ((Devices & CabDevices.DoorPermitLeft) != 0 ? CabDevices.DoorPermitRight : 0)
|
||||
| ((Devices & CabDevices.DoorPermitRight) != 0 ? CabDevices.DoorPermitLeft : 0)
|
||||
};
|
||||
|
||||
public bool AiValid => (Flags & CabFlags.AiValid) != 0;
|
||||
public bool InCab => (Flags & CabFlags.InCab) != 0;
|
||||
public float AbsSpeedKmh => Math.Abs(SpeedKmh);
|
||||
|
||||
@@ -109,7 +109,7 @@ internal sealed class BlackBoxFile
|
||||
uint devices = 0x0007, bool extended = true, sbyte cabEnd = 1, byte security = 0,
|
||||
float lateral = 0.2f, ushort lightsHead = 0x15, ushort lightsTail = 0x22, byte? movement = null,
|
||||
short hintHead = -1, short hintTail = -1, ushort? equippedHead = null, ushort? equippedTail = null,
|
||||
byte? engine = null, float oilTemperature = 70) =>
|
||||
byte? engine = null, float oilTemperature = 70, float? wheelSpeed = null) =>
|
||||
Record(0x20, w =>
|
||||
{
|
||||
w.Write(time);
|
||||
@@ -181,6 +181,9 @@ internal sealed class BlackBoxFile
|
||||
w.Write(1.0f); // clutch
|
||||
w.Write(0.0f); // torque converter
|
||||
w.Write(2.5f); // the highest brake cylinder of the train
|
||||
// the speed of the wheels: a recording made before it ends above
|
||||
if (wheelSpeed is { } wheels)
|
||||
w.Write(wheels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,13 +60,15 @@ public class BlackBoxListingTests
|
||||
public void Black_boxes_with_no_launch_noted_go_with_the_tapes_written_about_the_same_time()
|
||||
{
|
||||
var early = new DateTime(2026, 3, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
// named in the local time they started at, whatever the zone the tests run in
|
||||
string first = Box("td", early.AddHours(-1)), second = Box("td", early.AddMinutes(30));
|
||||
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||
.WithFile(Log("a.dat"), "t")
|
||||
.WithFile(Log("td_2026-03-01_11-00-00.blackbox"), "b")
|
||||
.WithFile(Log("td_2026-03-01_12-30-00.blackbox"), "b")
|
||||
.WithFile(Log(first), "b")
|
||||
.WithFile(Log(second), "b")
|
||||
.WrittenAt(Log("a.dat"), early)
|
||||
.WrittenAt(Log("td_2026-03-01_11-00-00.blackbox"), early.AddSeconds(2))
|
||||
.WrittenAt(Log("td_2026-03-01_12-30-00.blackbox"), early.AddHours(1)));
|
||||
.WrittenAt(Log(first), early.AddSeconds(2))
|
||||
.WrittenAt(Log(second), early.AddHours(1)));
|
||||
|
||||
var sessions = installation.Tapes.Sessions();
|
||||
|
||||
@@ -74,12 +76,59 @@ public class BlackBoxListingTests
|
||||
Assert.All(sessions, session => Assert.Null(session.Launch));
|
||||
// Newest first: the black box on its own, then the run with the tape.
|
||||
Assert.Empty(sessions[0].Tapes);
|
||||
Assert.EndsWith("12-30-00.blackbox", Assert.Single(sessions[0].BlackBoxes).Path);
|
||||
Assert.EndsWith(second, Assert.Single(sessions[0].BlackBoxes).Path);
|
||||
Assert.Single(sessions[1].Tapes);
|
||||
Assert.EndsWith("11-00-00.blackbox", Assert.Single(sessions[1].BlackBoxes).Path);
|
||||
Assert.EndsWith(first, Assert.Single(sessions[1].BlackBoxes).Path);
|
||||
Assert.Equal(early, sessions[1].StartedUtc);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_tape_of_a_vehicle_left_early_in_a_run_with_no_launch_goes_with_its_black_box()
|
||||
{
|
||||
// The black box writes the tapes as it goes: that of the vehicle the player left after ten minutes ends
|
||||
// twenty minutes before the run, that of the next one with it.
|
||||
var started = new DateTime(2026, 3, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
string box = Box("td", started);
|
||||
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||
.WithFile(Log("first.dat"), "t")
|
||||
.WithFile(Log("second.dat"), "t")
|
||||
.WithFile(Log(box), "b")
|
||||
.WrittenAt(Log("first.dat"), started.AddMinutes(10))
|
||||
.WrittenAt(Log(box), started.AddMinutes(30))
|
||||
.WrittenAt(Log("second.dat"), started.AddMinutes(30).AddSeconds(1)));
|
||||
|
||||
var session = Assert.Single(installation.Tapes.Sessions());
|
||||
|
||||
Assert.Null(session.Launch);
|
||||
Assert.Equal(new[] { "first", "second" }, session.Tapes.Select(tape => tape.Vehicle).Order());
|
||||
Assert.EndsWith(box, Assert.Single(session.BlackBoxes).Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_black_box_downloaded_later_takes_in_no_tapes_of_the_runs_after_it()
|
||||
{
|
||||
// Shared and downloaded two weeks later, so last written then; a run of its own with no launch noted since.
|
||||
var shared = new DateTime(2026, 3, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
var later = shared.AddDays(7);
|
||||
string old = Box("td", shared), own = Box("td", later);
|
||||
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||
.WithFile(Log(old), "b").WrittenAt(Log(old), shared.AddDays(14))
|
||||
.WithFile(Log(own), "b").WrittenAt(Log(own), later.AddMinutes(30))
|
||||
.WithFile(Log("ra.dat"), "t").WrittenAt(Log("ra.dat"), later.AddMinutes(30).AddSeconds(1))
|
||||
.WithFile(Log("left.dat"), "t").WrittenAt(Log("left.dat"), later.AddMinutes(10)));
|
||||
|
||||
var recordings = StarterNG.Application.HaslerTapes.Recordings(new[]
|
||||
{
|
||||
new StarterNG.Application.BlackBoxRecording(Log(old), shared.AddDays(14), 1),
|
||||
new StarterNG.Application.BlackBoxRecording(Log(own), later.AddMinutes(30), 1),
|
||||
});
|
||||
Assert.EndsWith(own, StarterNG.Application.HaslerTapes.RecordingAt(later.AddMinutes(10), recordings)!.Path);
|
||||
|
||||
var mine = Assert.Single(installation.Tapes.Sessions(), session => session.Tapes.Count > 0);
|
||||
Assert.Equal(new[] { "left", "ra" }, mine.Tapes.Select(tape => tape.Vehicle).Order());
|
||||
Assert.EndsWith(own, Assert.Single(mine.BlackBoxes).Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_black_box_of_a_running_session_is_listed_while_it_is_written()
|
||||
{
|
||||
|
||||
@@ -125,6 +125,20 @@ public class HeadCodeTests
|
||||
Assert.Null(cab[1].Extra);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_speed_of_the_wheels_is_read_when_written()
|
||||
{
|
||||
var f = new BlackBoxFile().Info();
|
||||
// the wheels slipping at 40 km/h
|
||||
f.Cab(0, 1, 1000, 40, movement: 1, equippedHead: 0x15, equippedTail: 0x22, engine: 1, wheelSpeed: 55.5f);
|
||||
f.Cab(0.5, 1, 1000, 40, movement: 1, equippedHead: 0x15, equippedTail: 0x22, engine: 1);
|
||||
var cab = BlackBoxReader.Read(f.End(1).Stream()).Cab;
|
||||
Assert.Equal(55.5f, cab[0].WheelSpeedKmh);
|
||||
Assert.Equal(40f, cab[0].SpeedKmh);
|
||||
// an older sample has none
|
||||
Assert.Null(cab[1].WheelSpeedKmh);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_vehicle_with_no_lamps_is_not_judged()
|
||||
{
|
||||
|
||||
@@ -222,6 +222,34 @@ public class BlackBoxViewsTests
|
||||
Assert.Equal(cab.Said, Controls.Peer(cab).GetHelpText());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Wheels_turning_apart_from_the_train_are_said_beside_its_speed()
|
||||
{
|
||||
var f = new BlackBoxFile().Info()
|
||||
.Vehicle(Head, "EU07-005", "ROJ1")
|
||||
.User(0, Head, true, 1);
|
||||
// slipping for the first ten seconds, then the wheels as fast as the train, give or take the rounding
|
||||
for (double t = 0; t <= 20; t += 0.5)
|
||||
f.Cab(t, Head, 1150 + t * 10, 40, movement: 1, equippedHead: 0x15, equippedTail: 0x22, engine: 1,
|
||||
wheelSpeed: t < 10 ? 55.4f : 40.3f);
|
||||
var cab = new CabPanel
|
||||
{
|
||||
Recording = BlackBoxReader.Read(f.End(20).Stream()),
|
||||
Strings = new DefaultBlackBoxStrings("en"),
|
||||
Time = 5
|
||||
};
|
||||
Controls.Lay(cab, 600, 900);
|
||||
|
||||
Controls.Draw(cab);
|
||||
Assert.Contains("40 km/h", cab.Said);
|
||||
Assert.Contains("wheels 55", cab.Said);
|
||||
|
||||
cab.Time = 15;
|
||||
Controls.Draw(cab);
|
||||
Assert.Contains("40 km/h", cab.Said);
|
||||
Assert.DoesNotContain("wheels", cab.Said);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_cab_stopped_under_the_brakes_and_out_of_the_recording()
|
||||
{
|
||||
|
||||
49
StarterNG.Tests/BlackBox/CabDoorsTests.cs
Normal file
49
StarterNG.Tests/BlackBox/CabDoorsTests.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Eu07.BlackBox;
|
||||
using Eu07.BlackBox.Views;
|
||||
|
||||
namespace StarterNG.Tests.BlackBox;
|
||||
|
||||
// The events are coloured with the views' brushes.
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class CabDoorsTests
|
||||
{
|
||||
private static CabSample Sample(sbyte cab, CabDevices devices) =>
|
||||
default(CabSample) with { CabEnd = cab, Devices = devices | CabDevices.Radio };
|
||||
|
||||
[Fact]
|
||||
public void From_the_rear_cab_the_vehicles_right_doors_are_the_drivers_left()
|
||||
{
|
||||
var seen = Sample(-1, CabDevices.DoorsRight | CabDevices.DoorPermitRight).AsTheCabSees;
|
||||
|
||||
Assert.True(seen.Has(CabDevices.DoorsLeft));
|
||||
Assert.True(seen.Has(CabDevices.DoorPermitLeft));
|
||||
Assert.False(seen.Has(CabDevices.DoorsRight));
|
||||
Assert.False(seen.Has(CabDevices.DoorPermitRight));
|
||||
Assert.True(seen.Has(CabDevices.Radio));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(0)]
|
||||
public void From_the_front_cab_or_out_of_one_the_sides_are_the_vehicles(sbyte cab)
|
||||
{
|
||||
var sample = Sample(cab, CabDevices.DoorsLeft | CabDevices.DoorPermitRight);
|
||||
|
||||
Assert.Equal(sample, sample.AsTheCabSees);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Going_to_the_other_cab_tells_nothing_of_the_doors_and_still_tells_the_switches()
|
||||
{
|
||||
var f = new BlackBoxFile().Info().Vehicle(1, "EN57-1001").User(0, 1, true);
|
||||
// the left doors permitted from the front cab; in the rear one the permit is still on, and the radio turned off
|
||||
f.Cab(0, 1, 1000, 0, cabEnd: 1, devices: 0x0007 | (uint)(CabDevices.DoorPermitLeft | CabDevices.Radio));
|
||||
f.Cab(1, 1, 1000, 0, cabEnd: -1, devices: 0x0007 | (uint)CabDevices.DoorPermitLeft);
|
||||
|
||||
var events = EventList.Collect(BlackBoxReader.Read(f.End(1).Stream()), new DefaultBlackBoxStrings("en"))
|
||||
.Select(e => e.Text).ToList();
|
||||
|
||||
Assert.Contains("Radio: off", events);
|
||||
Assert.DoesNotContain(events, e => e.Contains("doors permitted"));
|
||||
}
|
||||
}
|
||||
55
StarterNG.Tests/ColumnLineTests.cs
Normal file
55
StarterNG.Tests/ColumnLineTests.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Avalonia;
|
||||
using StarterNG.Views.Tapes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>The line of a tape, drawn a column of pixels at a time and broken off at a gap.</summary>
|
||||
public class ColumnLineTests
|
||||
{
|
||||
private readonly List<string> _drawn = [];
|
||||
|
||||
private ColumnLine Line() =>
|
||||
new(p => _drawn.Add($"begin {p.X} {p.Y}"), p => _drawn.Add($"line {p.X} {p.Y}"), () => _drawn.Add("end"));
|
||||
|
||||
[Fact]
|
||||
public void A_column_is_entered_where_it_started_and_left_where_it_ended_through_its_lowest_and_highest()
|
||||
{
|
||||
var line = Line();
|
||||
|
||||
// Falling within the column: from its first through its highest and its lowest to its last.
|
||||
foreach (double v in new[] { 3.0, 1.0, 4.0, 2.0 })
|
||||
line.Add(5, v);
|
||||
// Rising: through its lowest first.
|
||||
foreach (double v in new[] { 2.0, 4.0, 1.0, 3.0 })
|
||||
line.Add(6, v);
|
||||
line.Break();
|
||||
|
||||
Assert.Equal(["begin 5 3", "line 5 4", "line 5 1", "line 5 2",
|
||||
"line 6 2", "line 6 1", "line 6 4", "line 6 3", "end"], _drawn);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_break_ends_the_figure_and_the_next_point_begins_another()
|
||||
{
|
||||
var line = Line();
|
||||
|
||||
line.Add(0, 10);
|
||||
line.Break();
|
||||
line.Add(9, 20);
|
||||
line.Break();
|
||||
|
||||
Assert.Equal(["begin 0 10", "line 0 10", "line 0 10", "line 0 10", "end",
|
||||
"begin 9 20", "line 9 20", "line 9 20", "line 9 20", "end"], _drawn);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_break_with_nothing_drawn_ends_nothing()
|
||||
{
|
||||
var line = Line();
|
||||
|
||||
line.Break();
|
||||
line.Break();
|
||||
|
||||
Assert.Empty(_drawn);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
// Puts in services of its own: not while the controls read theirs.
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class ConsistOrientationTests
|
||||
{
|
||||
private readonly VehicleCatalog _catalog;
|
||||
|
||||
29
StarterNG.Tests/Fakes/ForwardOnlyStream.cs
Normal file
29
StarterNG.Tests/Fakes/ForwardOnlyStream.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace StarterNG.Tests.Fakes;
|
||||
|
||||
/// <summary>A stream read from its start to its end and no other way: no length, no seeking.</summary>
|
||||
internal sealed class ForwardOnlyStream(Stream inner) : Stream
|
||||
{
|
||||
public override bool CanRead => true;
|
||||
public override bool CanSeek => false;
|
||||
public override bool CanWrite => false;
|
||||
public override long Length => throw new NotSupportedException();
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
set => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) => inner.Read(buffer, offset, count);
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
public override void SetLength(long value) => throw new NotSupportedException();
|
||||
public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException();
|
||||
public override void Flush() { }
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
inner.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public sealed class InMemoryFileSystem : IFileSystem
|
||||
private readonly HashSet<string> _executable;
|
||||
private readonly Dictionary<string, string> _links;
|
||||
private readonly HashSet<string> _unreadable;
|
||||
private readonly HashSet<string> _unseekable;
|
||||
private readonly HashSet<string> _unlistable;
|
||||
private readonly Dictionary<string, DateTime> _written;
|
||||
|
||||
@@ -32,6 +33,7 @@ public sealed class InMemoryFileSystem : IFileSystem
|
||||
_executable = new HashSet<string>(comparer);
|
||||
_links = new Dictionary<string, string>(comparer);
|
||||
_unreadable = new HashSet<string>(comparer);
|
||||
_unseekable = new HashSet<string>(comparer);
|
||||
_unlistable = new HashSet<string>(comparer);
|
||||
_written = new Dictionary<string, DateTime>(comparer);
|
||||
}
|
||||
@@ -51,6 +53,13 @@ public sealed class InMemoryFileSystem : IFileSystem
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>The file opens as a stream read only forward, as a pipe or some network shares give it.</summary>
|
||||
public InMemoryFileSystem OpenedForwardOnly(string path)
|
||||
{
|
||||
_unseekable.Add(Normalize(path));
|
||||
return this;
|
||||
}
|
||||
|
||||
public InMemoryFileSystem AllowReading(string path)
|
||||
{
|
||||
_unreadable.Remove(Normalize(path));
|
||||
@@ -115,7 +124,11 @@ public sealed class InMemoryFileSystem : IFileSystem
|
||||
|
||||
public byte[] ReadAllBytes(string path) => Bytes(path);
|
||||
|
||||
public Stream OpenRead(string path) => new MemoryStream(Bytes(path), writable: false);
|
||||
public Stream OpenRead(string path)
|
||||
{
|
||||
var stream = new MemoryStream(Bytes(path), writable: false);
|
||||
return _unseekable.Contains(Normalize(path)) ? new ForwardOnlyStream(stream) : stream;
|
||||
}
|
||||
|
||||
public void WriteAllText(string path, string contents) => WithFile(path, contents);
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
using StarterNG.Infrastructure.Adapters;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public sealed class FolderChangesTests : IDisposable
|
||||
{
|
||||
private static readonly TimeSpan Patience = TimeSpan.FromSeconds(10);
|
||||
private readonly string _root = Path.Combine(Path.GetTempPath(), "folder-changes-" + Guid.NewGuid().ToString("N"));
|
||||
|
||||
public FolderChangesTests() => Directory.CreateDirectory(Path.Combine(_root, "sub"));
|
||||
|
||||
public void Dispose() => Directory.Delete(_root, recursive: true);
|
||||
|
||||
private static async Task<bool> Reported(FolderChanges changes, Action change)
|
||||
{
|
||||
var told = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
changes.Changed += () => told.TrySetResult();
|
||||
change();
|
||||
return await Task.WhenAny(told.Task, Task.Delay(Patience)) == told.Task;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_file_written_below_the_folder_is_reported()
|
||||
{
|
||||
string file = Path.Combine(_root, "sub", "a.scm");
|
||||
File.WriteAllText(file, "old");
|
||||
using var changes = new FolderChanges(_root);
|
||||
|
||||
Assert.True(changes.Watching);
|
||||
Assert.True(await Reported(changes, () => File.WriteAllText(file, "new text")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_save_through_a_renamed_temp_file_is_reported()
|
||||
{
|
||||
string file = Path.Combine(_root, "test.scn");
|
||||
File.WriteAllText(file, "old");
|
||||
using var changes = new FolderChanges(_root);
|
||||
|
||||
Assert.True(await Reported(changes, () =>
|
||||
{
|
||||
string temp = file + ".tmp";
|
||||
File.WriteAllText(temp, "new");
|
||||
File.Move(temp, file, overwrite: true);
|
||||
}));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_file_removed_is_reported()
|
||||
{
|
||||
string file = Path.Combine(_root, "gone.scn");
|
||||
File.WriteAllText(file, "x");
|
||||
using var changes = new FolderChanges(_root);
|
||||
|
||||
Assert.True(await Reported(changes, () => File.Delete(file)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_missing_folder_is_not_watched_and_does_not_throw()
|
||||
{
|
||||
using var changes = new FolderChanges(Path.Combine(_root, "nowhere"));
|
||||
|
||||
Assert.False(changes.Watching);
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
using Avalonia.Controls;
|
||||
using StarterNG.Infrastructure;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public sealed class FolderLooksTests : IDisposable
|
||||
{
|
||||
private static readonly TimeSpan Patience = TimeSpan.FromSeconds(10);
|
||||
private readonly string _root = Path.Combine(Path.GetTempPath(), "folder-looks-" + Guid.NewGuid().ToString("N"));
|
||||
private readonly ManualTime _time = new();
|
||||
private readonly Window _window;
|
||||
private int _looks;
|
||||
|
||||
public FolderLooksTests()
|
||||
{
|
||||
Directory.CreateDirectory(_root);
|
||||
HeadlessDrawing.Ensure();
|
||||
_window = new Window();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_window.Close();
|
||||
Directory.Delete(_root, recursive: true);
|
||||
}
|
||||
|
||||
private FolderLooks Opened(string folder)
|
||||
{
|
||||
var looks = new FolderLooks(_window, () => folder, () =>
|
||||
{
|
||||
_looks++;
|
||||
return Task.CompletedTask;
|
||||
}, _time);
|
||||
_window.Show();
|
||||
Controls.Settle();
|
||||
_looks = 0;
|
||||
return looks;
|
||||
}
|
||||
|
||||
private ManualTimer Quiet => _time.Timers.Single(t => t.Period == Timeout.InfiniteTimeSpan);
|
||||
private ManualTimer Often => _time.Timers.Single(t => t.Period != Timeout.InfiniteTimeSpan);
|
||||
|
||||
// Waited for without leaving the thread: the window belongs to it.
|
||||
private static void Until(Func<bool> condition) => Assert.True(SpinWait.SpinUntil(condition, Patience), "waited too long");
|
||||
|
||||
[Fact]
|
||||
public void Nothing_is_watched_before_the_window_opens()
|
||||
{
|
||||
_ = new FolderLooks(_window, () => _root, () => Task.CompletedTask, _time);
|
||||
|
||||
Assert.Empty(_time.Timers);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_watched_folder_is_looked_at_anyway_seldom()
|
||||
{
|
||||
var looks = Opened(_root);
|
||||
|
||||
Assert.True(looks.Watching);
|
||||
Assert.Equal(FolderLooks.Watched, Often.Due);
|
||||
Assert.Equal(FolderLooks.Watched, Often.Period);
|
||||
Assert.Equal(Timeout.InfiniteTimeSpan, Quiet.Due);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_folder_the_system_reports_nothing_of_is_looked_at_often()
|
||||
{
|
||||
var looks = Opened(Path.Combine(_root, "nowhere"));
|
||||
|
||||
Assert.False(looks.Watching);
|
||||
Assert.Equal(FolderLooks.Unwatched, Often.Period);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_tick_looks_on_the_ui_thread_once_it_gets_there()
|
||||
{
|
||||
Opened(_root);
|
||||
|
||||
Often.Fire();
|
||||
Assert.Equal(0, _looks);
|
||||
Controls.Settle();
|
||||
|
||||
Assert.Equal(1, _looks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_change_is_looked_at_once_the_reports_stop()
|
||||
{
|
||||
Opened(_root);
|
||||
|
||||
File.WriteAllText(Path.Combine(_root, "test.scn"), "new");
|
||||
Until(() => Quiet.Due == FolderLooks.Quiet);
|
||||
Controls.Settle();
|
||||
Assert.Equal(0, _looks);
|
||||
|
||||
Quiet.Fire();
|
||||
Controls.Settle();
|
||||
|
||||
Assert.Equal(1, _looks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Coming_back_to_the_window_looks()
|
||||
{
|
||||
Opened(_root);
|
||||
|
||||
_window.Activate();
|
||||
Controls.Settle();
|
||||
|
||||
Assert.Equal(1, _looks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Asked_it_looks()
|
||||
{
|
||||
var looks = Opened(_root);
|
||||
|
||||
Assert.True(looks.LookAsync().IsCompletedSuccessfully);
|
||||
|
||||
Assert.Equal(1, _looks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Closed_it_stops_the_timers()
|
||||
{
|
||||
Opened(_root);
|
||||
|
||||
_window.Close();
|
||||
|
||||
Assert.Equal(2, _time.Timers.Count);
|
||||
Assert.All(_time.Timers, t => Assert.True(t.Disposed));
|
||||
}
|
||||
|
||||
private sealed class ManualTime : TimeProvider
|
||||
{
|
||||
private readonly List<ManualTimer> _timers = new();
|
||||
|
||||
public IReadOnlyList<ManualTimer> Timers
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_timers)
|
||||
return _timers.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
|
||||
{
|
||||
var timer = new ManualTimer(() => callback(state), dueTime, period);
|
||||
lock (_timers)
|
||||
_timers.Add(timer);
|
||||
return timer;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ManualTimer : ITimer
|
||||
{
|
||||
private readonly Action _tick;
|
||||
private long _dueTicks;
|
||||
|
||||
public ManualTimer(Action tick, TimeSpan due, TimeSpan period)
|
||||
{
|
||||
_tick = tick;
|
||||
_dueTicks = due.Ticks;
|
||||
Period = period;
|
||||
}
|
||||
|
||||
public TimeSpan Due => TimeSpan.FromTicks(Interlocked.Read(ref _dueTicks));
|
||||
public TimeSpan Period { get; private set; }
|
||||
public bool Disposed { get; private set; }
|
||||
|
||||
public void Fire() => _tick();
|
||||
|
||||
public bool Change(TimeSpan dueTime, TimeSpan period)
|
||||
{
|
||||
if (Disposed)
|
||||
throw new ObjectDisposedException(nameof(ManualTimer));
|
||||
Interlocked.Exchange(ref _dueTicks, dueTime.Ticks);
|
||||
Period = period;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose() => Disposed = true;
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
Dispose();
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,12 @@ namespace StarterNG.Tests;
|
||||
|
||||
public class HaslerTapeTests
|
||||
{
|
||||
private const string Header =
|
||||
internal const string Header =
|
||||
"Time[s] Velocity[m/s] Acceleration[m/ss] Coupler.Dist[m] Coupler.Force[N] TractionForce[kN] FrictionForce[kN] " +
|
||||
"BrakeForce[kN] BrakePress[MPa] PipePress[MPa] MotorCurrent[A] MCP SCP BCP LBP Direction Command CVal1 CVal2 " +
|
||||
"Security Wheelslip EngineTemp[Deg] OilTemp[Deg] WaterTemp[Deg] WaterAuxTemp[Deg]\r\n";
|
||||
|
||||
private static string Line(double t, double v, double brake, double current, string command = "none",
|
||||
internal static string Line(double t, double v, double brake, double current, string command = "none",
|
||||
int security = 0) =>
|
||||
string.Create(CultureInfo.InvariantCulture,
|
||||
$"{t:0.0000} {v:0.0000} 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 {brake:0.0000} 0.5000 {current:0.0000} ") +
|
||||
@@ -68,6 +68,197 @@ public class HaslerTapeTests
|
||||
Assert.Equal(5, tape.DistanceM, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_security_flag_is_found_where_the_header_puts_it_with_the_vehicle_speed_at_the_end()
|
||||
{
|
||||
// the simulator's log since 2026-10: a column of the vehicle's speed after the temperatures
|
||||
string header = Header.Replace("WaterAuxTemp[Deg]\r\n", "WaterAuxTemp[Deg] VehicleVelocity[km/h]\r\n");
|
||||
static string WithSpeed(string line, double kmh) =>
|
||||
line.Replace("\r\n", string.Create(CultureInfo.InvariantCulture, $" {kmh:0.0000}\r\n"));
|
||||
// the wheels slipping, the alerter quiet: the column before the speed used to be read as the alerter
|
||||
string slipping = Line(0, 36, 0, 0, security: 0).Replace(" 0 0 0.0000 0.0000 0.0000 0.0000\r\n",
|
||||
" 0 1 0.0000 0.0000 0.0000 0.0000\r\n");
|
||||
|
||||
var tape = HaslerTape.Parse(header + WithSpeed(slipping, 36) + WithSpeed(Line(1, 36, 0, 0, security: 1), 36));
|
||||
|
||||
Assert.Equal(2, tape.Samples.Count);
|
||||
Assert.False(tape.Samples[0].SecurityAlarm);
|
||||
Assert.True(tape.Samples[1].SecurityAlarm);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_command_named_like_a_heading_is_read_as_a_line_not_as_the_header()
|
||||
{
|
||||
var tape = HaslerTape.Parse(Header + Line(0, 36, 0, 0, command: "Security") + Line(1, 36, 0, 0, security: 1));
|
||||
|
||||
Assert.Equal(2, tape.Samples.Count);
|
||||
Assert.False(tape.Samples[0].SecurityAlarm);
|
||||
Assert.True(tape.Samples[1].SecurityAlarm);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_gap_in_the_time_is_neither_driving_nor_standing_and_covers_no_distance()
|
||||
{
|
||||
// the player in another vehicle for ten minutes, then back in this one
|
||||
var tape = HaslerTape.Parse(Header + Line(0, 36, 0, 0) + Line(1, 36, 0, 0) + Line(601, 36, 0, 0)
|
||||
+ Line(602, 36, 0, 0) + Line(603, 0, 0, 0));
|
||||
|
||||
Assert.Equal(603, tape.Duration, 6);
|
||||
Assert.Equal(600, tape.GapTime, 6);
|
||||
Assert.Equal(2, tape.RunningTime, 6);
|
||||
Assert.Equal(1, tape.StandingTime, 6); // the last second, stopping
|
||||
Assert.Equal(10 + 10 + 5, tape.DistanceM, 6);
|
||||
Assert.Equal(25 / 3.0 * 3.6, tape.AverageWithStopsKmh, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_stall_of_the_simulator_a_little_over_a_second_is_driven_not_a_gap()
|
||||
{
|
||||
// a line every 0.05 s, as at 60 FPS, and one step of 1.017 s: the frame held to a second, and the frame after
|
||||
var text = new System.Text.StringBuilder(Header);
|
||||
double t = 0;
|
||||
for (int i = 0; i < 40; i++, t += 0.05)
|
||||
text.Append(Line(t, 100, 0, 0));
|
||||
t += 1.017 - 0.05;
|
||||
for (int i = 0; i < 40; i++, t += 0.05)
|
||||
text.Append(Line(t, 100, 0, 0));
|
||||
|
||||
var tape = HaslerTape.Parse(text.ToString());
|
||||
|
||||
Assert.Equal(0, tape.GapTime, 6);
|
||||
Assert.Equal(tape.Duration, tape.RunningTime, 6);
|
||||
Assert.Equal(tape.Duration * 100 / 3.6, tape.DistanceM, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_tape_read_in_pieces_cut_anywhere_is_the_tape_read_whole()
|
||||
{
|
||||
string text = Header + Line(0, 18, 0, 0, command: "Set Velocity") + Line(1, 36, 0.45, 0) + Line(2, 36, 0, 400)
|
||||
+ Line(602, 36, 0, 0, security: 1) + Line(603, 0, 0, 0);
|
||||
var whole = HaslerTape.Parse(text);
|
||||
|
||||
for (int cut = 1; cut < text.Length; cut += 7)
|
||||
{
|
||||
var reader = new HaslerTape.Reader();
|
||||
reader.Feed(text[..cut]);
|
||||
reader.Feed(text[cut..]);
|
||||
Assert.Equal(whole.Samples, reader.Tape(final: true).Samples);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_line_not_ended_waits_for_its_end_while_the_tape_is_followed()
|
||||
{
|
||||
var reader = new HaslerTape.Reader();
|
||||
string line = Line(1, 36, 0, 0);
|
||||
reader.Feed(Header + Line(0, 36, 0, 0) + line[..20]);
|
||||
|
||||
Assert.Single(reader.Tape(final: false).Samples);
|
||||
Assert.Single(reader.Tape(final: false).Samples);
|
||||
reader.Feed(line[20..]);
|
||||
Assert.Equal(2, reader.Tape(final: false).Samples.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_followed_tape_reads_what_was_added_and_one_begun_anew_whole()
|
||||
{
|
||||
string path = TestInstallation.At("physicslog", "EU07-424.dat");
|
||||
var files = new InMemoryFileSystem().WithFile(path, Header + Line(0, 36, 0, 0));
|
||||
var tapes = new TestInstallation(files).Tapes;
|
||||
var file = Assert.Single(tapes.List());
|
||||
|
||||
Assert.Single(tapes.Load(file, follow: false)!.Samples);
|
||||
files.WithFile(path, Header + Line(0, 36, 0, 0) + Line(1, 36, 0, 0) + Line(2, 36, 0, 0));
|
||||
Assert.Equal(3, tapes.Load(file, follow: true)!.Samples.Count);
|
||||
|
||||
// begun anew, and already longer than was read: its time goes back
|
||||
files.WithFile(path, Header + Line(0, 72, 0, 0) + Line(1, 72, 0, 0) + Line(2, 72, 0, 0) + Line(3, 72, 0, 0));
|
||||
var tape = tapes.Load(file, follow: true)!;
|
||||
Assert.Equal(4, tape.Samples.Count);
|
||||
Assert.All(tape.Samples, s => Assert.Equal(72, s.SpeedKmh, 6));
|
||||
|
||||
// begun anew, and shorter
|
||||
files.WithFile(path, Header + Line(0, 18, 0, 0));
|
||||
Assert.Equal(18, Assert.Single(tapes.Load(file, follow: true)!.Samples).SpeedKmh, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_log_begun_anew_over_the_end_that_was_read_is_read_whole_once_its_time_goes_back()
|
||||
{
|
||||
// the command is free text, here long enough that the end kept of the read part holds no time
|
||||
string command = new('x', 400);
|
||||
string path = TestInstallation.At("physicslog", "EU07-424.dat");
|
||||
var files = new InMemoryFileSystem().WithFile(path, Header + Line(3, 36, 0, 0, command));
|
||||
var tapes = new TestInstallation(files).Tapes;
|
||||
var file = Assert.Single(tapes.List());
|
||||
Assert.Equal(3, Assert.Single(tapes.Load(file, follow: false)!.Samples).Time, 6);
|
||||
|
||||
// begun anew: where the read part ended it reads as it did, but the lines added go back to the start
|
||||
files.WithFile(path, Header + Line(0, 36, 0, 0, command) + Line(1, 36, 0, 0, command) + Line(2, 36, 0, 0, command));
|
||||
var tape = tapes.Load(file, follow: true)!;
|
||||
|
||||
Assert.Equal([0.0, 1.0, 2.0], tape.Samples.Select(s => s.Time));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_tape_that_cannot_be_read_is_none_and_told_and_is_read_whole_once_it_can()
|
||||
{
|
||||
string path = TestInstallation.At("physicslog", "EU07-424.dat");
|
||||
var files = new InMemoryFileSystem().WithFile(path, Header + Line(0, 36, 0, 0));
|
||||
var installation = new TestInstallation(files);
|
||||
var tapes = installation.Tapes;
|
||||
var file = Assert.Single(tapes.List());
|
||||
tapes.Load(file, follow: false);
|
||||
|
||||
files.FailReading(path);
|
||||
Assert.Null(tapes.Load(file, follow: true));
|
||||
Assert.Contains("EU07-424.dat", installation.Log.Text);
|
||||
|
||||
files.AllowReading(path).WithFile(path, Header + Line(0, 72, 0, 0) + Line(1, 72, 0, 0));
|
||||
Assert.All(tapes.Load(file, follow: true)!.Samples, s => Assert.Equal(72, s.SpeedKmh, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_file_read_only_forward_is_read_whole_each_time()
|
||||
{
|
||||
string path = TestInstallation.At("physicslog", "EU07-424.dat");
|
||||
var files = new InMemoryFileSystem().WithFile(path, Header + Line(0, 36, 0, 0)).OpenedForwardOnly(path);
|
||||
var tapes = new TestInstallation(files).Tapes;
|
||||
var file = Assert.Single(tapes.List());
|
||||
|
||||
Assert.Single(tapes.Load(file, follow: true)!.Samples);
|
||||
files.WithFile(path, Header + Line(0, 36, 0, 0) + Line(1, 36, 0, 0));
|
||||
Assert.Equal(2, tapes.Load(file, follow: true)!.Samples.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Empty_lines_in_a_log_are_passed_over()
|
||||
{
|
||||
var tape = HaslerTape.Parse(Header + "\r\n" + Line(0, 36, 0, 0) + " \r\n" + Line(1, 36, 0, 0));
|
||||
|
||||
Assert.Equal(2, tape.Samples.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Forgetting_another_file_keeps_the_followed_tape_and_its_own_lets_it_go()
|
||||
{
|
||||
string Lines(int firstSpeed, int count) =>
|
||||
Header + Line(0, firstSpeed, 0, 0) + string.Concat(Enumerable.Range(1, count).Select(t => Line(t, 36, 0, 0)));
|
||||
string path = TestInstallation.At("physicslog", "EU07-424.dat");
|
||||
var files = new InMemoryFileSystem().WithFile(path, Lines(36, 20));
|
||||
var tapes = new TestInstallation(files).Tapes;
|
||||
var file = Assert.Single(tapes.List());
|
||||
tapes.Load(file, follow: false);
|
||||
|
||||
// the first line changed, as long as it was and far from the end: a tape still followed doesn't read it again
|
||||
files.WithFile(path, Lines(72, 21));
|
||||
tapes.Forget(TestInstallation.At("physicslog", "EU07-111.dat"));
|
||||
Assert.Equal(36, tapes.Load(file, follow: true)!.Samples[0].SpeedKmh, 6);
|
||||
|
||||
tapes.Forget(file.Path);
|
||||
Assert.Equal(72, tapes.Load(file, follow: true)!.Samples[0].SpeedKmh, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_sample_under_a_point_of_the_tape_is_found_by_time_and_by_distance()
|
||||
{
|
||||
|
||||
96
StarterNG.Tests/HaslerTapeWindowTests.cs
Normal file
96
StarterNG.Tests/HaslerTapeWindowTests.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.LogicalTree;
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Domain.Tapes;
|
||||
using StarterNG.Tests.Fakes;
|
||||
using StarterNG.Views.Tapes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>The tapes' window over the tapes of an installation of its own, read as it is opened.</summary>
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class HaslerTapeWindowTests
|
||||
{
|
||||
private static readonly DateTime Launched = new(2025, 12, 31, 23, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
static HaslerTapeWindowTests() => HeadlessDrawing.Ensure();
|
||||
|
||||
private static AppServices Services(InMemoryFileSystem files)
|
||||
{
|
||||
var installation = new TestInstallation(files);
|
||||
installation.Clock.Now = Launched;
|
||||
return AppServices.Initialize(installation.Paths, installation.Files, installation.Clock, installation.Environment);
|
||||
}
|
||||
|
||||
// The window reads the tapes off the UI thread and shows them on it: what it shows is waited for.
|
||||
private static void Until(Func<bool> shown) =>
|
||||
Assert.True(SpinWait.SpinUntil(() =>
|
||||
{
|
||||
Controls.Settle();
|
||||
return shown();
|
||||
}, TimeSpan.FromSeconds(5)));
|
||||
|
||||
private static Button Button(Window window, string key) =>
|
||||
window.GetLogicalDescendants().OfType<Button>().Single(b => b.Content as string == App.Loc[key]);
|
||||
|
||||
[Fact]
|
||||
public void With_nothing_recorded_it_offers_to_record_and_turns_on_the_black_box_and_the_trains_tapes()
|
||||
{
|
||||
var services = Services(new InMemoryFileSystem());
|
||||
var window = new HaslerTapeWindow();
|
||||
bool told = false;
|
||||
window.LogEnabled += () => told = true;
|
||||
window.Show();
|
||||
try
|
||||
{
|
||||
var strip = (Control)Button(window, "HaslerRecordingEnable").Parent!;
|
||||
Until(() => strip.IsVisible);
|
||||
|
||||
Button(window, "HaslerRecordingEnable").RaiseEvent(Controls.Click());
|
||||
|
||||
Assert.True(services.Settings.BlackBox);
|
||||
Assert.True(services.Settings.PhysicsLogTrains);
|
||||
Assert.False(services.Settings.PhysicsLog);
|
||||
Assert.True(told);
|
||||
Assert.False(strip.IsVisible);
|
||||
// the simulator's own log is on as it comes: nothing more to offer
|
||||
Assert.False(((Control)Button(window, "HaslerLogEnable").Parent!).IsVisible);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_tape_of_the_last_launch_is_summed_up_with_its_scenario_and_train()
|
||||
{
|
||||
string path = TestInstallation.At("physicslog", "EP07-424.dat");
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithFile(path, HaslerTapeTests.Header + HaslerTapeTests.Line(0, 36, 0, 0) + HaslerTapeTests.Line(60, 36, 0, 0));
|
||||
var services = Services(files);
|
||||
services.Tapes.RecordLaunch("td.scn", TimeSpan.Zero, Array.Empty<TapeVehicle>(), "EP07-424", new[] { "EP07-424" },
|
||||
"Tor doświadczalny", "EIE1531");
|
||||
var window = new HaslerTapeWindow();
|
||||
window.Show();
|
||||
try
|
||||
{
|
||||
string scenario = string.Format(App.Loc["HaslerScenario"], "Tor doświadczalny");
|
||||
var texts = window.GetLogicalDescendants().OfType<TextBlock>();
|
||||
Until(() => texts.Any(t => t.Text?.Contains(scenario) == true));
|
||||
string summary = texts.First(t => t.Text?.Contains(scenario) == true).Text!;
|
||||
|
||||
Assert.StartsWith("EP07-424", summary);
|
||||
Assert.Contains(string.Format(App.Loc["HaslerTrain"], "EIE1531"), summary);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
// closed, the tape it read is no longer followed: begun anew and longer, it is read whole
|
||||
files.WithFile(path, HaslerTapeTests.Header + HaslerTapeTests.Line(0, 72, 0, 0) + HaslerTapeTests.Line(1, 72, 0, 0)
|
||||
+ HaslerTapeTests.Line(2, 72, 0, 0));
|
||||
var tape = services.Tapes.Load(services.Tapes.List().Single(), follow: true)!;
|
||||
Assert.All(tape.Samples, s => Assert.Equal(72, s.SpeedKmh, 6));
|
||||
}
|
||||
}
|
||||
87
StarterNG.Tests/MessageBoxTests.cs
Normal file
87
StarterNG.Tests/MessageBoxTests.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.LogicalTree;
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Tests.Fakes;
|
||||
using StarterNG.Views;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>The starter's questions over its window, answered with the mouse or not at all.</summary>
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class MessageBoxTests
|
||||
{
|
||||
// The buttons are labelled in the starter's language.
|
||||
static MessageBoxTests()
|
||||
{
|
||||
HeadlessDrawing.Ensure();
|
||||
if (AppServices.CurrentOrNull is null)
|
||||
{
|
||||
var installation = new TestInstallation(new InMemoryFileSystem());
|
||||
AppServices.Initialize(installation.Paths, installation.Files, installation.Clock, installation.Environment);
|
||||
}
|
||||
}
|
||||
|
||||
private static (Window Owner, Window Dialog, Task<bool?> Answer) Choose()
|
||||
{
|
||||
var owner = new Window();
|
||||
owner.Show();
|
||||
var answer = MessageBox.Choose(owner, "Zapisać zmiany przed startem?", "Niezapisane zmiany", "Zapisz", "Nie zapisuj");
|
||||
Controls.Settle();
|
||||
return (owner, Assert.Single(owner.OwnedWindows), answer);
|
||||
}
|
||||
|
||||
// The answer is given once the dialog's closing has gone through the dispatcher.
|
||||
private static bool? Answered(Task<bool?> answer)
|
||||
{
|
||||
Assert.True(SpinWait.SpinUntil(() =>
|
||||
{
|
||||
Controls.Settle();
|
||||
return answer.IsCompleted;
|
||||
}, TimeSpan.FromSeconds(5)));
|
||||
return answer.Result;
|
||||
}
|
||||
|
||||
private static Button[] Buttons(Window dialog) => dialog.GetLogicalDescendants().OfType<Button>().ToArray();
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, true)]
|
||||
[InlineData(1, false)]
|
||||
[InlineData(2, null)]
|
||||
public void A_choice_gives_the_answer_clicked_and_the_way_back_gives_none(int clicked, bool? expected)
|
||||
{
|
||||
var (owner, dialog, answer) = Choose();
|
||||
try
|
||||
{
|
||||
Assert.Equal("Niezapisane zmiany", dialog.Title);
|
||||
Assert.Contains(dialog.GetLogicalDescendants().OfType<TextBlock>(), t => t.Text == "Zapisać zmiany przed startem?");
|
||||
var buttons = Buttons(dialog);
|
||||
Assert.Equal(["Zapisz", "Nie zapisuj", App.Loc["Cancel"]], buttons.Select(b => b.Content as string));
|
||||
Assert.False(answer.IsCompleted);
|
||||
|
||||
buttons[clicked].RaiseEvent(Controls.Click());
|
||||
|
||||
Assert.Equal(expected, Answered(answer));
|
||||
Assert.Empty(owner.OwnedWindows);
|
||||
}
|
||||
finally
|
||||
{
|
||||
owner.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Closing_the_window_of_a_choice_picks_neither_answer()
|
||||
{
|
||||
var (owner, dialog, answer) = Choose();
|
||||
try
|
||||
{
|
||||
dialog.Close();
|
||||
|
||||
Assert.Null(Answered(answer));
|
||||
}
|
||||
finally
|
||||
{
|
||||
owner.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using StarterNG.Application;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class OneAtATimeTests
|
||||
{
|
||||
private static async Task Until(Func<bool> condition)
|
||||
{
|
||||
var giveUp = DateTime.UtcNow.AddSeconds(5);
|
||||
while (!condition())
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < giveUp, "waited too long");
|
||||
await Task.Delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Asked_once_it_runs_once()
|
||||
{
|
||||
int runs = 0;
|
||||
var once = new OneAtATime(() => { runs++; return Task.CompletedTask; });
|
||||
|
||||
await once.RunAsync();
|
||||
|
||||
Assert.Equal(1, runs);
|
||||
Assert.False(once.IsRunning);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Asked_while_running_it_runs_once_more_after_not_alongside()
|
||||
{
|
||||
int runs = 0, together = 0, most = 0;
|
||||
var gates = new Queue<TaskCompletionSource>();
|
||||
var once = new OneAtATime(async () =>
|
||||
{
|
||||
runs++;
|
||||
most = Math.Max(most, ++together);
|
||||
var gate = new TaskCompletionSource();
|
||||
gates.Enqueue(gate);
|
||||
await gate.Task;
|
||||
together--;
|
||||
});
|
||||
|
||||
var first = once.RunAsync();
|
||||
// Three requests during the first run make one more run, not three.
|
||||
await once.RunAsync();
|
||||
await once.RunAsync();
|
||||
await once.RunAsync();
|
||||
Assert.Equal(1, runs);
|
||||
|
||||
gates.Dequeue().SetResult();
|
||||
await Until(() => Volatile.Read(ref runs) == 2);
|
||||
await Until(() => gates.Count == 1);
|
||||
gates.Dequeue().SetResult();
|
||||
await first;
|
||||
|
||||
Assert.Equal(2, runs);
|
||||
Assert.Equal(1, most);
|
||||
Assert.False(once.IsRunning);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_failed_run_does_not_keep_it_busy()
|
||||
{
|
||||
bool fail = true;
|
||||
int runs = 0;
|
||||
var once = new OneAtATime(() =>
|
||||
{
|
||||
runs++;
|
||||
return fail ? Task.FromException(new IOException("locked")) : Task.CompletedTask;
|
||||
});
|
||||
|
||||
await Assert.ThrowsAsync<IOException>(once.RunAsync);
|
||||
fail = false;
|
||||
await once.RunAsync();
|
||||
|
||||
Assert.Equal(2, runs);
|
||||
Assert.False(once.IsRunning);
|
||||
}
|
||||
}
|
||||
@@ -1257,6 +1257,39 @@ public class SettingsStoreTests
|
||||
Assert.False(store.LoadFailed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_profile_from_before_the_tapes_of_the_trains_is_moved_as_the_ini_would_be()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithFile(UserIni, "physicslog no\nphysicslog.trains no\n")
|
||||
.WithFile(Profile, "physicslog yes\nblackbox yes\n");
|
||||
var store = WithHome(files).SettingsStore;
|
||||
store.Load();
|
||||
|
||||
Assert.True(store.TryLoadProfile(Profile));
|
||||
store.Save();
|
||||
|
||||
Assert.False(store.Settings.PhysicsLog);
|
||||
Assert.True(store.Settings.PhysicsLogTrains);
|
||||
Assert.Contains("physicslog.trains yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_profile_exported_from_a_pages_edits_leaves_the_settings_held_and_the_ini_alone()
|
||||
{
|
||||
var files = new InMemoryFileSystem().WithFile(UserIni, "fieldofview 45\n");
|
||||
var store = WithHome(files).SettingsStore;
|
||||
store.Load();
|
||||
var edited = store.Settings.Copy();
|
||||
edited.FieldOfView = 60;
|
||||
|
||||
Assert.True(store.ExportTo(Profile, edited));
|
||||
|
||||
Assert.Contains("fieldofview 60", files.ReadAllText(Profile, System.Text.Encoding.UTF8));
|
||||
Assert.Equal(45, store.Settings.FieldOfView);
|
||||
Assert.Contains("fieldofview 45", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_missing_profile_leaves_the_settings_as_they_are()
|
||||
{
|
||||
@@ -1302,4 +1335,189 @@ public class SettingsStoreTests
|
||||
Assert.False(store.LoadFailed);
|
||||
Assert.Equal(60, store.Settings.FieldOfView);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("physicslog yes\n", true)]
|
||||
[InlineData("physicslog no\n", false)]
|
||||
[InlineData("physicslog yes\nblackbox no\n", false)]
|
||||
[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)
|
||||
{
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini));
|
||||
|
||||
installation.SettingsStore.Load();
|
||||
|
||||
Assert.Equal(recorded, installation.SettingsStore.Settings.BlackBox);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Tapes_turned_on_write_the_black_box_and_leave_the_physics_log_off()
|
||||
{
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog no\n"));
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Settings.BlackBox = true;
|
||||
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
Assert.Equal("blackbox yes", LineFor(installation, "blackbox"));
|
||||
Assert.Equal("physicslog no", LineFor(installation, "physicslog"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_black_box_that_says_no_more_than_the_physics_log_adds_no_line()
|
||||
{
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog yes\n"));
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Settings.Width = 1600;
|
||||
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
Assert.Null(LineFor(installation, "blackbox"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("physicslog yes\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)
|
||||
{
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini));
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Settings.BlackBox = false;
|
||||
installation.SettingsStore.Settings.PhysicsLog = false;
|
||||
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
Assert.Equal("blackbox no", LineFor(installation, "blackbox"));
|
||||
Assert.Equal("physicslog no", LineFor(installation, "physicslog"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog yes\n"));
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Settings.PhysicsLog = false;
|
||||
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
Assert.Equal("blackbox yes", LineFor(installation, "blackbox"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("physicslog no\n", false, false)]
|
||||
[InlineData("physicslog no\nphysicslog.trains yes\n", true, true)]
|
||||
[InlineData("physicslog no\nphysicslog.trains yes\nblackbox no\n", true, false)]
|
||||
public void The_logs_of_the_trains_are_read_and_bring_the_black_box_as_the_simulator_has_it(string ini, bool trains, bool recorded)
|
||||
{
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, ini));
|
||||
|
||||
installation.SettingsStore.Load();
|
||||
|
||||
Assert.Equal(trains, installation.SettingsStore.Settings.PhysicsLogTrains);
|
||||
Assert.Equal(recorded, installation.SettingsStore.Settings.BlackBox);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("physicslog yes\nblackbox yes\n")]
|
||||
[InlineData("physicslog no\nblackbox yes\n")]
|
||||
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));
|
||||
|
||||
installation.SettingsStore.Load();
|
||||
var s = installation.SettingsStore.Settings;
|
||||
Assert.False(s.PhysicsLog);
|
||||
Assert.True(s.PhysicsLogTrains);
|
||||
Assert.True(s.BlackBox);
|
||||
|
||||
installation.SettingsStore.Save();
|
||||
Assert.Equal("physicslog no", LineFor(installation, "physicslog"));
|
||||
Assert.Equal("physicslog.trains yes", LineFor(installation, "physicslog.trains"));
|
||||
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]
|
||||
public void An_imported_ini_from_before_the_tapes_of_the_trains_is_moved_as_a_profile_is()
|
||||
{
|
||||
string backup = Path.Combine("/home/kolejarz", "backup", "eu07.ini");
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithFile(UserIni, "physicslog yes\nphysicslog.trains no\n")
|
||||
.WithFile(backup, "physicslog yes\nblackbox yes\n");
|
||||
var store = WithHome(files).SettingsStore;
|
||||
store.Load();
|
||||
|
||||
Assert.True(store.ImportFrom(backup));
|
||||
store.Save();
|
||||
|
||||
Assert.False(store.Settings.PhysicsLog);
|
||||
Assert.True(store.Settings.PhysicsLogTrains);
|
||||
Assert.Contains("physicslog.trains yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Once_moved_the_physics_log_of_every_vehicle_turned_on_again_stays_on()
|
||||
{
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog yes\nblackbox yes\n"));
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Settings.PhysicsLog = true;
|
||||
installation.SettingsStore.Settings.PhysicsLogTrains = false;
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
installation.SettingsStore.Load();
|
||||
|
||||
Assert.True(installation.SettingsStore.Settings.PhysicsLog);
|
||||
Assert.False(installation.SettingsStore.Settings.PhysicsLogTrains);
|
||||
Assert.Equal("physicslog.trains no", LineFor(installation, "physicslog.trains"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_logs_of_the_trains_are_written_only_once_on_or_where_the_file_has_them()
|
||||
{
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog no\n"));
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Save();
|
||||
Assert.Null(LineFor(installation, "physicslog.trains"));
|
||||
|
||||
installation.SettingsStore.Settings.PhysicsLogTrains = true;
|
||||
installation.SettingsStore.Settings.BlackBox = true;
|
||||
installation.SettingsStore.Save();
|
||||
Assert.Equal("physicslog.trains yes", LineFor(installation, "physicslog.trains"));
|
||||
// it says no more than the logs of the trains bring
|
||||
Assert.Null(LineFor(installation, "blackbox"));
|
||||
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Settings.PhysicsLogTrains = false;
|
||||
installation.SettingsStore.Save();
|
||||
Assert.Equal("physicslog.trains no", LineFor(installation, "physicslog.trains"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_black_box_line_written_once_goes_away_when_it_says_no_more()
|
||||
{
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "physicslog no\n"));
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Settings.BlackBox = true;
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
installation.SettingsStore.Settings.BlackBox = false;
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
Assert.Null(LineFor(installation, "blackbox"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,18 @@ public class StartSimulationTests
|
||||
Assert.Contains($"vehicle\t{driven}\tPKP/EP07\tep07.mmd", noted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void With_the_black_box_alone_the_launch_is_noted_for_the_tapes_it_writes()
|
||||
{
|
||||
var (start, _, installation) = Rig(files => files.WithExecutable(Build), sceneryClock: "07:52");
|
||||
installation.SettingsStore.Settings.BlackBox = true;
|
||||
|
||||
start.Execute(freeFly: false, saveSettings: false);
|
||||
|
||||
string noted = installation.Files.ReadAllText(TestInstallation.At("physicslog", "starter-launch.txt"));
|
||||
Assert.Contains("clock\t07:52", noted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_the_physics_log_nothing_is_noted()
|
||||
{
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace StarterNG.Tests;
|
||||
|
||||
// PresetStore keeps the disk of the first test that reaches it, a fake one as every
|
||||
// composition root in the tests is built on fakes. So each test has a name to itself.
|
||||
// Puts in services of its own: not while the controls read theirs.
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class WarehouseEditTests
|
||||
{
|
||||
private const string Text =
|
||||
|
||||
@@ -35,6 +35,7 @@ public sealed class HaslerTapes
|
||||
{
|
||||
private const int RememberedLaunches = 30;
|
||||
private static readonly TimeSpan QuietBetweenRuns = TimeSpan.FromMinutes(2);
|
||||
private static readonly TimeSpan TapesAfterBlackBox = TimeSpan.FromSeconds(10);
|
||||
|
||||
private readonly IFileSystem _files;
|
||||
private readonly IGamePaths _paths;
|
||||
@@ -244,8 +245,9 @@ public sealed class HaslerTapes
|
||||
/// <summary>
|
||||
/// The runs the tapes came from, the running or latest one first. A tape belongs
|
||||
/// to the last launch before it was written, unless a run the starter didn't launch
|
||||
/// began between them; one with no launch goes with those written about the same
|
||||
/// time, as a run writes them all at its end.
|
||||
/// began between them; one with no launch goes with the black box recording when it
|
||||
/// was written, or else with those written about the same time, as a run writes its
|
||||
/// logs until it ends.
|
||||
/// </summary>
|
||||
public IReadOnlyList<TapeSession> Sessions()
|
||||
{
|
||||
@@ -278,11 +280,15 @@ public sealed class HaslerTapes
|
||||
boxesBehind.GetValueOrDefault(launch, new List<BlackBoxRecording>())));
|
||||
}
|
||||
|
||||
// What no launch covers goes together by when it was written: a run writes it all at its end.
|
||||
// What no launch covers goes together by when it was written: a run writes its logs until it ends. A tape
|
||||
// written while a black box recorded is of its run, though: the black box writes the tapes of the player's
|
||||
// vehicles as it goes, and that of a vehicle the player left ends before the run does.
|
||||
var looseBoxes = boxes.Where(b => LaunchOf(b, launches) is null).ToList();
|
||||
var recordings = Recordings(looseBoxes);
|
||||
var loose = tapes.Where(t => tapeLaunch[t] is null)
|
||||
.Select(t => (Written: t.LastWriteUtc, Tape: (TapeFile?)t, Box: (BlackBoxRecording?)null))
|
||||
.Concat(boxes.Where(b => LaunchOf(b, launches) is null)
|
||||
.Select(b => (Written: b.LastWriteUtc, Tape: (TapeFile?)null, Box: (BlackBoxRecording?)b)))
|
||||
.Select(t => (Written: RecordingAt(t.LastWriteUtc, recordings)?.LastWriteUtc ?? t.LastWriteUtc,
|
||||
Tape: (TapeFile?)t, Box: (BlackBoxRecording?)null))
|
||||
.Concat(looseBoxes.Select(b => (Written: b.LastWriteUtc, Tape: (TapeFile?)null, Box: (BlackBoxRecording?)b)))
|
||||
.OrderBy(file => file.Written);
|
||||
var run = new List<TapeFile>();
|
||||
var runBoxes = new List<BlackBoxRecording>();
|
||||
@@ -315,6 +321,39 @@ public sealed class HaslerTapes
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When each black box recorded, its name read once: from the start its name has, to when it was last written,
|
||||
/// and the tapes a moment after. No longer than until the next one started, though: a box downloaded or copied
|
||||
/// later was last written then, not when it stopped, and would take in the tapes of the runs since.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<(BlackBoxRecording Box, DateTime FromUtc, DateTime ToUtc)> Recordings(IEnumerable<BlackBoxRecording> boxes)
|
||||
{
|
||||
var named = boxes.Select(box => (Box: box, Named: NamedBy(box.Path)))
|
||||
.Where(each => each.Named is not null)
|
||||
.Select(each => (each.Box, FromUtc: each.Named!.Value.StartedUtc))
|
||||
.OrderBy(each => each.FromUtc)
|
||||
.ToList();
|
||||
var recordings = new List<(BlackBoxRecording, DateTime, DateTime)>(named.Count);
|
||||
for (int i = 0; i < named.Count; i++)
|
||||
{
|
||||
var to = named[i].Box.LastWriteUtc + TapesAfterBlackBox;
|
||||
if (i + 1 < named.Count && named[i + 1].FromUtc < to)
|
||||
to = named[i + 1].FromUtc;
|
||||
recordings.Add((named[i].Box, named[i].FromUtc, to));
|
||||
}
|
||||
return recordings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The black box that was recording at the moment, the tapes being written last, a moment after it is closed.
|
||||
/// Of more, the one that stopped nearest to it.
|
||||
/// </summary>
|
||||
public static BlackBoxRecording? RecordingAt(DateTime momentUtc, IEnumerable<(BlackBoxRecording Box, DateTime FromUtc, DateTime ToUtc)> recordings) =>
|
||||
recordings.Where(each => each.FromUtc <= momentUtc && momentUtc <= each.ToUtc)
|
||||
.OrderBy(each => (each.Box.LastWriteUtc - momentUtc).Duration())
|
||||
.Select(each => each.Box)
|
||||
.FirstOrDefault();
|
||||
|
||||
private TapeFile ReadTape(string path) =>
|
||||
new(path, Path.GetFileNameWithoutExtension(path), _files.GetLastWriteTimeUtc(path), _files.GetFileSize(path));
|
||||
|
||||
@@ -411,19 +450,88 @@ public sealed class HaslerTapes
|
||||
return new TapeSession(launch, started, written.Count > 0 ? written.Max() : started, running, listed, recorded);
|
||||
}
|
||||
|
||||
public HaslerTape? Load(TapeFile file)
|
||||
// the tape followed as the simulator writes it: what of its file was read, and where it ended
|
||||
private readonly object _followedLock = new();
|
||||
private (string Path, long Read, byte[] Tail, HaslerTape.Reader Reader)? _followed;
|
||||
// what of the end of the read part is kept, to tell the file still has it: one begun anew doesn't
|
||||
private const int FollowedTail = 256;
|
||||
|
||||
public HaslerTape? Load(TapeFile file) => Load(file, follow: false);
|
||||
|
||||
/// <summary>
|
||||
/// The tape of this file no longer followed: what was kept of it is let go. Another file's, followed for another
|
||||
/// window, stays.
|
||||
/// </summary>
|
||||
public void Forget(string path)
|
||||
{
|
||||
try
|
||||
lock (_followedLock)
|
||||
if (_followed?.Path == path)
|
||||
_followed = null;
|
||||
}
|
||||
|
||||
// what the file has between the two: less, up to its end, when it was cut shorter since its length was taken
|
||||
private static byte[] Bytes(Stream stream, long from, long to)
|
||||
{
|
||||
stream.Seek(from, SeekOrigin.Begin);
|
||||
var bytes = new byte[to - from];
|
||||
int read = stream.ReadAtLeast(bytes, bytes.Length, throwOnEndOfStream: false);
|
||||
return read == bytes.Length ? bytes : bytes[..read];
|
||||
}
|
||||
|
||||
// the end of what was read, after the part added to it
|
||||
private static byte[] Tail(byte[] before, byte[] added)
|
||||
{
|
||||
if (added.Length >= FollowedTail)
|
||||
return added[^FollowedTail..];
|
||||
var keptBefore = Math.Min(before.Length, FollowedTail - added.Length);
|
||||
return [.. before[^keptBefore..], .. added];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tape of the file. Followed, the one read last and grown since: only what was added is read, so a log
|
||||
/// written fast, at a higher time speed, is kept up with; a line not ended yet waits for the next time. Not
|
||||
/// followed, or another file, or one shorter than was read - begun anew - it is read whole, and kept to be
|
||||
/// followed from there.
|
||||
/// </summary>
|
||||
public HaslerTape? Load(TapeFile file, bool follow)
|
||||
{
|
||||
lock (_followedLock)
|
||||
{
|
||||
// Through OpenRead, which does not mind the simulator still writing the file.
|
||||
using var stream = _files.OpenRead(file.Path);
|
||||
using var reader = new StreamReader(stream, Encoding.ASCII);
|
||||
return HaslerTape.Parse(reader.ReadToEnd());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Log($"reading {file.Path}", ex);
|
||||
return null;
|
||||
try
|
||||
{
|
||||
// Through OpenRead, which does not mind the simulator still writing the file.
|
||||
using var stream = _files.OpenRead(file.Path);
|
||||
if (!stream.CanSeek)
|
||||
{
|
||||
_followed = null;
|
||||
using var whole = new StreamReader(stream, Encoding.ASCII);
|
||||
return HaslerTape.Parse(whole.ReadToEnd());
|
||||
}
|
||||
|
||||
long length = stream.Length;
|
||||
// the same file grown, its end as it was read: else another, or begun anew, read whole
|
||||
if (!follow || _followed is not { } followed || followed.Path != file.Path || length < followed.Read
|
||||
|| !Bytes(stream, followed.Read - followed.Tail.Length, followed.Read).AsSpan().SequenceEqual(followed.Tail))
|
||||
followed = (file.Path, 0, Array.Empty<byte>(), new HaslerTape.Reader());
|
||||
// what was read, not the length taken before: the file may be cut shorter meanwhile
|
||||
var added = Bytes(stream, followed.Read, length);
|
||||
followed.Reader.Feed(Encoding.ASCII.GetString(added));
|
||||
// the time went back in what was added: the log begun anew and already longer than was read
|
||||
if (followed.Read > 0 && followed.Reader.WentBack)
|
||||
{
|
||||
followed = (file.Path, 0, Array.Empty<byte>(), new HaslerTape.Reader());
|
||||
added = Bytes(stream, 0, length);
|
||||
followed.Reader.Feed(Encoding.ASCII.GetString(added));
|
||||
}
|
||||
_followed = (file.Path, followed.Read + added.Length, Tail(followed.Tail, added), followed.Reader);
|
||||
return followed.Reader.Tape(final: !follow);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_followed = null;
|
||||
_log.Log($"reading {file.Path}", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StarterNG.Application;
|
||||
|
||||
/// <summary>
|
||||
/// Runs a piece of work one at a time. Asked again while it runs, it does not start a
|
||||
/// second one alongside, nor forget the request: it runs once more when the first ends,
|
||||
/// however many times it was asked meanwhile. For the UI thread, which calls it alone.
|
||||
/// </summary>
|
||||
public sealed class OneAtATime
|
||||
{
|
||||
private readonly Func<Task> _work;
|
||||
private bool _running;
|
||||
private bool _again;
|
||||
|
||||
public OneAtATime(Func<Task> work) => _work = work;
|
||||
|
||||
public bool IsRunning => _running;
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
if (_running)
|
||||
{
|
||||
_again = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_running = true;
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
_again = false;
|
||||
await _work();
|
||||
}
|
||||
while (_again);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_running = false;
|
||||
_again = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,9 @@ public sealed class SettingsStore
|
||||
|
||||
_serializer.Read(Settings, _config);
|
||||
_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();
|
||||
}
|
||||
|
||||
@@ -233,6 +236,8 @@ public sealed class SettingsStore
|
||||
s.WindowMaximized = maximized;
|
||||
s.CabLampLight = cabLampLight;
|
||||
s.DepthPrepassScene = depthPrepassScene;
|
||||
// an ini of before the tapes of the trains goes the same way as a profile
|
||||
SettingsSerializer.MoveToTrainTapes(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -240,7 +245,8 @@ public sealed class SettingsStore
|
||||
/// Writes the settings as a complete eu07.ini somewhere else - this user's file
|
||||
/// with the settings applied - leaving the file itself and its state alone.
|
||||
/// </summary>
|
||||
public bool ExportTo(string path)
|
||||
/// <param name="settings">What to write, when not the settings held: a page's edits, still not taken in.</param>
|
||||
public bool ExportTo(string path, SimulatorSettings? settings = null)
|
||||
{
|
||||
if (LoadFailed)
|
||||
{
|
||||
@@ -249,7 +255,7 @@ public sealed class SettingsStore
|
||||
}
|
||||
|
||||
var copy = ConfigFile.Parse(_config.ToText());
|
||||
ApplyChanges(copy, Changes(Settings));
|
||||
ApplyChanges(copy, Changes(settings ?? Settings));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -144,7 +144,7 @@ public sealed class StartSimulation
|
||||
if (saveSettings)
|
||||
_settings.CaptureAndSave();
|
||||
|
||||
if (_settings.Settings.PhysicsLog)
|
||||
if (_settings.Settings.PhysicsLog || _settings.Settings.BlackBox || _settings.Settings.PhysicsLogTrains)
|
||||
_tapes.RecordLaunch(scenery, trainset, freeFly ? null : vehicle);
|
||||
|
||||
string[] arguments = freeFly || string.IsNullOrEmpty(vehicle)
|
||||
|
||||
@@ -133,6 +133,20 @@ public sealed class SimulatorSettings
|
||||
public bool EnableTraction = true;
|
||||
public bool LiveTraction = true;
|
||||
public bool PhysicsLog;
|
||||
/// <summary>
|
||||
/// The black box of the session, and with it the tapes (.dat) of the vehicles the player was in, written when the
|
||||
/// simulator closes: the tapes without the log of every vehicle. With no entry of its own it goes with the physics log.
|
||||
/// </summary>
|
||||
public bool BlackBox;
|
||||
/// <summary>Whether eu07.ini had a line of its own for the black box when read: it is kept saying what is wanted.</summary>
|
||||
public bool BlackBoxInIni;
|
||||
/// <summary>
|
||||
/// The physics logs (.dat) of the trains only, "physicslog.trains": of each driver of rail vehicles, not of the
|
||||
/// passengers nor of the vehicles of the roads. The tapes of every train, far fewer files than the log of every vehicle.
|
||||
/// </summary>
|
||||
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>
|
||||
public bool PhysicsLogTrainsInIni;
|
||||
public bool DebugLog = true;
|
||||
public bool MultipleLogs;
|
||||
public bool DisplaySimulation = true;
|
||||
|
||||
@@ -29,23 +29,42 @@ public readonly record struct TapeSample(
|
||||
public sealed class HaslerTape
|
||||
{
|
||||
// Columns counted from the start; the security flag is counted from the end, past
|
||||
// the command, which is free text. The header says m/s and MPa, the values are km/h and bar.
|
||||
// the command, which is free text, as far from the end as the header has it: the
|
||||
// simulator adds a new column at the end (the vehicle's speed, 2026-10). The header
|
||||
// says m/s and MPa, the values are km/h and bar.
|
||||
private const int TimeColumn = 0;
|
||||
private const int VelocityColumn = 1;
|
||||
private const int BrakePressColumn = 8;
|
||||
private const int PipePressColumn = 9;
|
||||
private const int MotorCurrentColumn = 10;
|
||||
private const int SecurityFromEnd = 6;
|
||||
private const string SecurityHeading = "Security";
|
||||
private const int SecurityFromEndOf25 = 6; // a log with no header to tell: the columns up to the water's temperature
|
||||
private const int MinimumColumns = 17;
|
||||
|
||||
public HaslerTape(IReadOnlyList<TapeSample> samples)
|
||||
// above the longest step the simulator makes at once (its frame is held to a second) and a line's interval: a
|
||||
// stall of the simulator, a dragged window say, is time driven or stood, not a gap
|
||||
private const double MinimumGapSeconds = 2.0;
|
||||
private const int GapSteps = 20;
|
||||
|
||||
public HaslerTape(IReadOnlyList<TapeSample> samples) : this(samples, GapAbove(samples))
|
||||
{
|
||||
}
|
||||
|
||||
// the gap already found, by the reader: the steps are sorted once, not again here
|
||||
private HaslerTape(IReadOnlyList<TapeSample> samples, double gap)
|
||||
{
|
||||
Samples = samples;
|
||||
foreach (var s in samples)
|
||||
MaxSpeedKmh = Math.Max(MaxSpeedKmh, s.SpeedKmh);
|
||||
GapSeconds = gap;
|
||||
for (int i = 1; i < samples.Count; i++)
|
||||
if (samples[i].SpeedKmh > 0.5)
|
||||
RunningTime += samples[i].Time - samples[i - 1].Time;
|
||||
{
|
||||
double step = samples[i].Time - samples[i - 1].Time;
|
||||
if (step > gap)
|
||||
GapTime += step;
|
||||
else if (samples[i].SpeedKmh > 0.5)
|
||||
RunningTime += step;
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<TapeSample> Samples { get; }
|
||||
@@ -60,50 +79,137 @@ public sealed class HaslerTape
|
||||
|
||||
public double MaxSpeedKmh { get; }
|
||||
|
||||
/// <summary>Seconds on the move; the rest of <see cref="Duration"/> was spent standing.</summary>
|
||||
/// <summary>Seconds on the move; the rest of <see cref="Duration"/> was spent standing, or not recorded.</summary>
|
||||
public double RunningTime { get; }
|
||||
|
||||
public double StandingTime => Duration - RunningTime;
|
||||
/// <summary>Seconds of <see cref="Duration"/> not recorded: the gaps, see <see cref="GapAbove"/>.</summary>
|
||||
public double GapTime { get; }
|
||||
|
||||
/// <summary>A step between two lines longer than this is a gap: <see cref="GapAbove"/> of this tape.</summary>
|
||||
public double GapSeconds { get; }
|
||||
|
||||
public double StandingTime => Duration - RunningTime - GapTime;
|
||||
|
||||
/// <summary>Mean speed while moving.</summary>
|
||||
public double AverageSpeedKmh => RunningTime > 0 ? DistanceM / RunningTime * 3.6 : 0;
|
||||
|
||||
/// <summary>Mean speed over the whole recording, stops included - the commercial speed.</summary>
|
||||
public double AverageWithStopsKmh => Duration > 0 ? DistanceM / Duration * 3.6 : 0;
|
||||
public double AverageWithStopsKmh => Duration - GapTime > 0 ? DistanceM / (Duration - GapTime) * 3.6 : 0;
|
||||
|
||||
/// <summary>
|
||||
/// A step between two lines longer than this is time not recorded, the player in another vehicle before
|
||||
/// coming back to this one: neither driving nor standing, and no distance. The lines come every 0.05 s of
|
||||
/// simulated time or so; it is twenty of their usual steps, two seconds at least.
|
||||
/// </summary>
|
||||
public static double GapAbove(IReadOnlyList<TapeSample> samples)
|
||||
{
|
||||
if (samples.Count < 2)
|
||||
return MinimumGapSeconds;
|
||||
var steps = new double[samples.Count - 1];
|
||||
for (int i = 1; i < samples.Count; i++)
|
||||
steps[i - 1] = samples[i].Time - samples[i - 1].Time;
|
||||
Array.Sort(steps);
|
||||
return Math.Max(MinimumGapSeconds, GapSteps * steps[steps.Length / 2]);
|
||||
}
|
||||
|
||||
public static HaslerTape Parse(string text)
|
||||
{
|
||||
var samples = new List<TapeSample>();
|
||||
double distance = 0;
|
||||
TapeSample? previous = null;
|
||||
var reader = new Reader();
|
||||
reader.Feed(text);
|
||||
return reader.Tape(final: true);
|
||||
}
|
||||
|
||||
foreach (var raw in text.Split('\n'))
|
||||
/// <summary>
|
||||
/// A tape read as it is written: each piece of the file given once, in order, so a log the simulator keeps
|
||||
/// adding to - fast, at a higher time speed - is not read and split from its start every time it grows. A line
|
||||
/// not ended yet waits for the rest.
|
||||
/// </summary>
|
||||
public sealed class Reader
|
||||
{
|
||||
private readonly List<TapeSample> _samples = new();
|
||||
private readonly System.Text.StringBuilder _unended = new();
|
||||
private int _securityFromEnd = SecurityFromEndOf25;
|
||||
|
||||
public void Feed(string text)
|
||||
{
|
||||
WentBack = false;
|
||||
int start = 0;
|
||||
for (int end = text.IndexOf('\n'); end >= 0; end = text.IndexOf('\n', start))
|
||||
{
|
||||
if (_unended.Length > 0)
|
||||
{
|
||||
_unended.Append(text, start, end - start);
|
||||
Keep(_unended.ToString(), _samples);
|
||||
_unended.Clear();
|
||||
}
|
||||
else
|
||||
Keep(text.Substring(start, end - start), _samples);
|
||||
start = end + 1;
|
||||
}
|
||||
_unended.Append(text, start, text.Length - start);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tape of what was read. Final, the end of the file: a last line with no end is read too, though
|
||||
/// only for this tape; otherwise it may be cut short by a simulator still writing, and waits.
|
||||
/// </summary>
|
||||
public HaslerTape Tape(bool final)
|
||||
{
|
||||
var read = _samples;
|
||||
if (final && _unended.Length > 0)
|
||||
{
|
||||
read = new List<TapeSample>(_samples);
|
||||
Keep(_unended.ToString(), read);
|
||||
}
|
||||
// the distance, trapezoid by trapezoid, none over the gaps
|
||||
var samples = new List<TapeSample>(read.Count);
|
||||
double gap = GapAbove(read), distance = 0;
|
||||
for (int i = 0; i < read.Count; i++)
|
||||
{
|
||||
var sample = read[i];
|
||||
if (i > 0)
|
||||
{
|
||||
var before = read[i - 1];
|
||||
double step = sample.Time - before.Time;
|
||||
if (step <= gap)
|
||||
distance += (before.SpeedKmh + sample.SpeedKmh) / 2 / 3.6 * step;
|
||||
}
|
||||
samples.Add(sample with { DistanceM = distance });
|
||||
}
|
||||
return new HaslerTape(samples, gap);
|
||||
}
|
||||
|
||||
private void Keep(string raw, List<TapeSample> samples)
|
||||
{
|
||||
var columns = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (columns.Length < MinimumColumns
|
||||
|| !Number(columns[TimeColumn], out double time)
|
||||
|| !Number(columns[VelocityColumn], out double velocity))
|
||||
continue; // the header, or a line cut short by a simulator still writing
|
||||
if (columns.Length == 0)
|
||||
return;
|
||||
if (!Number(columns[TimeColumn], out double time))
|
||||
{
|
||||
// the header; a line of figures may have the word too, in the free text of its command
|
||||
int heading = Array.IndexOf(columns, SecurityHeading);
|
||||
if (heading >= 0)
|
||||
_securityFromEnd = columns.Length - heading;
|
||||
return;
|
||||
}
|
||||
if (columns.Length < MinimumColumns || !Number(columns[VelocityColumn], out double velocity))
|
||||
return; // a line cut short by a simulator still writing
|
||||
|
||||
Number(columns[BrakePressColumn], out double brake);
|
||||
Number(columns[PipePressColumn], out double pipe);
|
||||
Number(columns[MotorCurrentColumn], out double current);
|
||||
bool security = columns[^SecurityFromEnd] == "1";
|
||||
bool security = _securityFromEnd <= columns.Length && columns[^_securityFromEnd] == "1";
|
||||
|
||||
double speed = Math.Abs(velocity);
|
||||
if (previous is { } p)
|
||||
if (samples.Count > 0 && time < samples[^1].Time)
|
||||
{
|
||||
if (time < p.Time)
|
||||
continue;
|
||||
distance += (p.SpeedKmh + speed) / 2 / 3.6 * (time - p.Time);
|
||||
WentBack = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var sample = new TapeSample(time, speed, distance, brake, pipe, current, security);
|
||||
samples.Add(sample);
|
||||
previous = sample;
|
||||
samples.Add(new TapeSample(time, Math.Abs(velocity), 0, brake, pipe, current, security));
|
||||
}
|
||||
|
||||
return new HaslerTape(samples);
|
||||
/// <summary>In the last piece fed, a line whose time was before the last one's, left out: maybe the log begun anew.</summary>
|
||||
public bool WentBack { get; private set; }
|
||||
}
|
||||
|
||||
/// <summary>Index of the last sample at or before the given time or distance.</summary>
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace StarterNG.Infrastructure.Adapters;
|
||||
|
||||
/// <summary>
|
||||
/// Tells when anything in a folder or below it is written, made, removed or renamed, as
|
||||
/// the system reports it. Only a hint that it is time to look: a save comes as several
|
||||
/// reports, and on a network drive, under Wine or past the system's limit of watches it
|
||||
/// may come as none, so whoever listens still looks now and then on its own.
|
||||
/// </summary>
|
||||
public sealed class FolderChanges : IDisposable
|
||||
{
|
||||
private readonly FileSystemWatcher? _watcher;
|
||||
|
||||
/// <summary>Something changed, or the reports were lost and anything may have: on a thread of the pool.</summary>
|
||||
public event Action? Changed;
|
||||
|
||||
/// <param name="folder">Watched with everything below it; a missing one is not watched.</param>
|
||||
public FolderChanges(string folder)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(folder))
|
||||
return;
|
||||
|
||||
var watcher = new FileSystemWatcher(folder)
|
||||
{
|
||||
IncludeSubdirectories = true,
|
||||
NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName
|
||||
| NotifyFilters.LastWrite | NotifyFilters.Size,
|
||||
// Unpacking an update changes hundreds of files at once.
|
||||
InternalBufferSize = 64 * 1024
|
||||
};
|
||||
watcher.Changed += (_, _) => Changed?.Invoke();
|
||||
watcher.Created += (_, _) => Changed?.Invoke();
|
||||
watcher.Deleted += (_, _) => Changed?.Invoke();
|
||||
watcher.Renamed += (_, _) => Changed?.Invoke();
|
||||
// Too many at once for the buffer: which ones is lost, so all are looked at.
|
||||
watcher.Error += (_, _) => Changed?.Invoke();
|
||||
watcher.EnableRaisingEvents = true;
|
||||
_watcher = watcher;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException
|
||||
or PlatformNotSupportedException)
|
||||
{
|
||||
// Out of watches on Linux, or a drive that gives none: the slow look alone stays.
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Whether the system reports changes here at all.</summary>
|
||||
public bool Watching => _watcher is not null;
|
||||
|
||||
public void Dispose() => _watcher?.Dispose();
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Threading;
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Infrastructure.Adapters;
|
||||
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Looks at a folder's files for a window, one look at a time on the UI thread: when the system
|
||||
/// reports a change, once the burst a save makes has passed; when the window comes back to the
|
||||
/// front; when asked; and now and then anyway, for the drives and systems where the reports do
|
||||
/// not come - often where none come at all. From the window's opening to its closing.
|
||||
/// </summary>
|
||||
public sealed class FolderLooks
|
||||
{
|
||||
/// <summary>How long the reports have to stop for: a save comes as several of them.</summary>
|
||||
public static readonly TimeSpan Quiet = TimeSpan.FromMilliseconds(400);
|
||||
|
||||
/// <summary>How often it looks anyway where the system reports the changes.</summary>
|
||||
public static readonly TimeSpan Watched = TimeSpan.FromSeconds(30);
|
||||
|
||||
/// <summary>How often it looks where the system reports nothing.</summary>
|
||||
public static readonly TimeSpan Unwatched = TimeSpan.FromSeconds(2);
|
||||
|
||||
private readonly Func<string> _folder;
|
||||
private readonly OneAtATime _look;
|
||||
private readonly TimeProvider _time;
|
||||
private readonly object _gate = new();
|
||||
private bool _closed;
|
||||
private ITimer? _quiet;
|
||||
private ITimer? _often;
|
||||
private FolderChanges? _changes;
|
||||
|
||||
/// <param name="window">Looked for from its opening to its closing.</param>
|
||||
/// <param name="folder">The folder, as it is when the window opens.</param>
|
||||
/// <param name="look">The look itself; it knows when it is no time to look.</param>
|
||||
/// <param name="time">The clock of the timers, the system's when not given.</param>
|
||||
public FolderLooks(Window window, Func<string> folder, Func<Task> look, TimeProvider? time = null)
|
||||
{
|
||||
_folder = folder;
|
||||
_look = new OneAtATime(look);
|
||||
_time = time ?? TimeProvider.System;
|
||||
window.Opened += (_, _) => Watch();
|
||||
window.Activated += async (_, _) => await LookAsync();
|
||||
window.Closed += (_, _) => Close();
|
||||
}
|
||||
|
||||
/// <summary>Whether the system reports the folder's changes; not before the window opens.</summary>
|
||||
public bool Watching => _changes?.Watching == true;
|
||||
|
||||
/// <summary>Looks now, or once more after the look that runs.</summary>
|
||||
public Task LookAsync() => _look.RunAsync();
|
||||
|
||||
private void Watch()
|
||||
{
|
||||
var changes = new FolderChanges(_folder());
|
||||
var often = changes.Watching ? Watched : Unwatched;
|
||||
lock (_gate)
|
||||
{
|
||||
_changes = changes;
|
||||
_quiet = _time.CreateTimer(_ => LookLater(), null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
|
||||
_often = _time.CreateTimer(_ => LookLater(), null, often, often);
|
||||
}
|
||||
changes.Changed += PutOff;
|
||||
}
|
||||
|
||||
// Each report puts the look off again, so a save of many files is one look after it. The
|
||||
// reports come on threads of the pool, and may come still as the window closes.
|
||||
private void PutOff()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (!_closed)
|
||||
_quiet?.Change(Quiet, Timeout.InfiniteTimeSpan);
|
||||
}
|
||||
}
|
||||
|
||||
// The timers tick on threads of the pool; the look belongs on the UI thread.
|
||||
private void LookLater() => Dispatcher.UIThread.Post(() => _ = LookAsync());
|
||||
|
||||
private void Close()
|
||||
{
|
||||
FolderChanges? changes;
|
||||
lock (_gate)
|
||||
{
|
||||
_closed = true;
|
||||
_quiet?.Dispose();
|
||||
_often?.Dispose();
|
||||
changes = _changes;
|
||||
}
|
||||
changes?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,21 @@ namespace StarterNG.Infrastructure.Settings;
|
||||
|
||||
public sealed class SettingsSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// An ini of before the tapes of the trains, its recording turned on ("blackbox yes", with the physics log of every
|
||||
/// vehicle, hundreds of files on a big scenery): moved to the tapes of the trains, the log of every vehicle off.
|
||||
/// Once: saved, the line of the trains' tapes is in the file, even turned off again before. A change of the
|
||||
/// starter's, after the file is read, so saving writes it.
|
||||
/// </summary>
|
||||
public static void MoveToTrainTapes(SimulatorSettings s)
|
||||
{
|
||||
if (s.PhysicsLogTrainsInIni || !s.BlackBoxInIni || !s.BlackBox)
|
||||
return;
|
||||
s.PhysicsLogTrains = true;
|
||||
s.PhysicsLogTrainsInIni = true;
|
||||
s.PhysicsLog = false;
|
||||
}
|
||||
|
||||
private readonly bool _dlssPlatform;
|
||||
|
||||
/// <param name="dlssPlatform">Whether the simulator can have DLSS here at all (not on macOS).</param>
|
||||
@@ -157,6 +172,11 @@ public sealed class SettingsSerializer
|
||||
s.EnableTraction = c.GetBool("enabletraction", true);
|
||||
s.LiveTraction = c.GetBool("livetraction", true);
|
||||
s.PhysicsLog = c.GetBool("physicslog", false);
|
||||
s.PhysicsLogTrainsInIni = c.Has("physicslog.trains");
|
||||
s.PhysicsLogTrains = c.GetBool("physicslog.trains", false);
|
||||
// the simulator records the black box along with the physics logs when the ini says nothing of it
|
||||
s.BlackBoxInIni = c.Has("blackbox");
|
||||
s.BlackBox = s.BlackBoxInIni ? c.GetBool("blackbox", false) : s.PhysicsLog || s.PhysicsLogTrains;
|
||||
int debugLog = c.GetInt("debuglog", 3);
|
||||
s.DebugLog = (debugLog & 1) != 0;
|
||||
s.DebugLogVisible = (debugLog & 2) != 0;
|
||||
@@ -370,6 +390,13 @@ public sealed class SettingsSerializer
|
||||
c.SetBool("enabletraction", s.EnableTraction);
|
||||
c.SetBool("livetraction", s.LiveTraction);
|
||||
c.SetBool("physicslog", s.PhysicsLog);
|
||||
// written where it says more than the physics logs, or where the file has it already: an ini without it
|
||||
// stays so, and a line written once and no longer saying more goes away on the next save
|
||||
if (s.BlackBoxInIni || s.BlackBox != (s.PhysicsLog || s.PhysicsLogTrains))
|
||||
c.SetBool("blackbox", s.BlackBox);
|
||||
// a simulator before it doesn't know the line: an ini without it stays so while it is off
|
||||
if (s.PhysicsLogTrainsInIni || s.PhysicsLogTrains)
|
||||
c.SetBool("physicslog.trains", s.PhysicsLogTrains);
|
||||
c.SetInt("debuglog",
|
||||
(s.DebugLog ? 1 : 0) | (s.DebugLogVisible ? 2 : 0) | s.DebugLogExtraBits);
|
||||
c.SetBool("multiplelogs", s.MultipleLogs);
|
||||
|
||||
@@ -40,9 +40,8 @@ public partial class MainWindow : Window
|
||||
private DateTime _openedUtc = DateTime.UtcNow;
|
||||
private DateTime _startedUtc = DateTime.MinValue;
|
||||
private bool _starting;
|
||||
// Scenery files: looked at when they change, on coming back to the window or from the
|
||||
// simulator, and now and then anyway.
|
||||
private readonly FolderLooks _sceneryLooks;
|
||||
private bool _lookingAtSceneryFiles;
|
||||
private readonly DispatcherTimer _sceneryFilesTimer = new() { Interval = TimeSpan.FromSeconds(2) };
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@@ -108,6 +107,7 @@ public partial class MainWindow : Window
|
||||
|
||||
_openedUtc = DateTime.UtcNow;
|
||||
UpdateStartButton();
|
||||
_sceneryFilesTimer.Start();
|
||||
FollowLastRun();
|
||||
};
|
||||
Activated += (_, _) =>
|
||||
@@ -117,20 +117,20 @@ public partial class MainWindow : Window
|
||||
if (SettingsView.IsVisible)
|
||||
SettingsView.RefreshExecutables();
|
||||
};
|
||||
// After the handlers above: back at the window, the settings are checked first.
|
||||
_sceneryLooks = new FolderLooks(this, () => AppServices.Current.Paths.Scenery, LookAtSceneryFilesAsync);
|
||||
_sceneryFilesTimer.Tick += async (_, _) => await LookAtSceneryFilesAsync();
|
||||
Closed += (_, _) => _sceneryFilesTimer.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scenery files changed outside the starter are picked up without a reload. Not
|
||||
/// with the simulator running: it is left in peace, and what it changes comes in after it.
|
||||
/// Run through <see cref="_sceneryLooks"/>, one look at a time.
|
||||
/// </summary>
|
||||
private async Task LookAtSceneryFilesAsync()
|
||||
{
|
||||
if (AppServices.Current.State.SimulatorRunning || !IsVisible || WindowState == WindowState.Minimized)
|
||||
if (_lookingAtSceneryFiles || AppServices.Current.State.SimulatorRunning || !IsVisible || WindowState == WindowState.Minimized)
|
||||
return;
|
||||
|
||||
_lookingAtSceneryFiles = true;
|
||||
try
|
||||
{
|
||||
var services = AppServices.Current;
|
||||
@@ -146,6 +146,10 @@ public partial class MainWindow : Window
|
||||
{
|
||||
Diagnostics.Log("Following the scenery files", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lookingAtSceneryFiles = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -648,6 +652,29 @@ public partial class MainWindow : Window
|
||||
App.Loc["StartNoStaffTitle"], MessageBoxButtons.YesNo))
|
||||
return;
|
||||
|
||||
// edits on the settings page not saved: saved, or let go - kept, the starter would write them when it
|
||||
// closes, perhaps while the simulator reads the file
|
||||
if (saveSettings && SettingsView.HasUnsavedChanges)
|
||||
{
|
||||
var save = await MessageBox.Choose(this, App.Loc["StartUnsavedMessage"], App.Loc["UnsavedChanges"],
|
||||
App.Loc["StartUnsavedSave"], App.Loc["StartUnsavedWithout"]);
|
||||
if (save is null)
|
||||
return;
|
||||
if (save == false)
|
||||
SettingsView.DiscardEdits();
|
||||
else
|
||||
{
|
||||
SettingsView.Save();
|
||||
// eu07.ini or the keys' file not written: still there to be saved
|
||||
if (SettingsView.HasUnsavedChanges)
|
||||
{
|
||||
await MessageBox.Show(this, App.Loc["SettingsNotSaved"], App.Loc["UnsavedChanges"],
|
||||
MessageBoxButtons.Ok);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LoadingScreen.Prepare(trainset?.Logo, Path.GetFileNameWithoutExtension(scenery.Path));
|
||||
|
||||
await FollowStartAsync(() => AppServices.Current.StartSimulation.Execute(freeFly, saveSettings));
|
||||
@@ -738,8 +765,6 @@ public partial class MainWindow : Window
|
||||
FollowLastRun();
|
||||
RestoreFromSimulator();
|
||||
ReportIfCrashed(simulator, executable, started);
|
||||
// What the simulator or its editor wrote while it ran comes in now.
|
||||
_ = _sceneryLooks.LookAsync();
|
||||
}), TaskScheduler.Default);
|
||||
}
|
||||
|
||||
@@ -749,7 +774,8 @@ public partial class MainWindow : Window
|
||||
/// </summary>
|
||||
private static void FollowLastRun()
|
||||
{
|
||||
if (AppServices.Current.Settings.PhysicsLog)
|
||||
var settings = AppServices.Current.Settings;
|
||||
if (settings.PhysicsLog || settings.BlackBox || settings.PhysicsLogTrains)
|
||||
_ = Task.Run(AppServices.Current.Tapes.FollowLastRun);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,35 @@ public static class MessageBox
|
||||
return yes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A question with two answers and a way back: true for the first, false for the second, null when cancelled
|
||||
/// or the window is closed - closing it never picks one of the answers.
|
||||
/// </summary>
|
||||
public static async Task<bool?> Choose(Window owner, string message, string title, string firstText,
|
||||
string secondText)
|
||||
{
|
||||
var win = FixedDialog(title, 460);
|
||||
|
||||
bool? answer = null;
|
||||
var first = DialogButton(firstText, "Accent", 80, () => { answer = true; win.Close(); });
|
||||
var second = DialogButton(secondText, "Flat", 80, () => { answer = false; win.Close(); });
|
||||
var cancel = DialogButton(App.Loc["Cancel"], "Flat", 80, () => win.Close());
|
||||
|
||||
win.Content = new StackPanel
|
||||
{
|
||||
Margin = new Avalonia.Thickness(16),
|
||||
Spacing = 16,
|
||||
Children =
|
||||
{
|
||||
new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap },
|
||||
ButtonRow(first, second, cancel)
|
||||
}
|
||||
};
|
||||
|
||||
await win.ShowDialog(owner);
|
||||
return answer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A notice with one action besides closing it, and a box to stop it coming
|
||||
/// back, which counts however the window is closed.
|
||||
|
||||
@@ -328,9 +328,8 @@ public partial class Settings
|
||||
return;
|
||||
|
||||
// The edits on screen go into the export as they would into a save, but the
|
||||
// user's own eu07.ini is not written.
|
||||
CaptureInto(AppServices.Current.Settings);
|
||||
if (!AppServices.Current.SettingsStore.ExportTo(path))
|
||||
// user's own eu07.ini is not written, nor the settings held: the edits stay the page's, not saved.
|
||||
if (!AppServices.Current.SettingsStore.ExportTo(path, Trial()))
|
||||
{
|
||||
await MessageBox.Show(owner, string.Format(App.Loc["ExportIniFailed"], path), App.Loc["ExportIni"],
|
||||
MessageBoxButtons.Ok);
|
||||
|
||||
@@ -554,6 +554,12 @@
|
||||
<ctl:SettingRow ConfigKey="livetraction" Description="{Binding [PowerOverheadLineOnlyDesc], Source={x:Static starterNg:App.Loc}}">
|
||||
<CheckBox x:Name="OverheadOnlyCb" Content="{Binding [PowerOverheadLineOnly], Source={x:Static starterNg:App.Loc}}" />
|
||||
</ctl:SettingRow>
|
||||
<ctl:SettingRow Description="{Binding [SaveBlackBoxDesc], Source={x:Static starterNg:App.Loc}}" ConfigKey="blackbox">
|
||||
<CheckBox x:Name="BlackBoxCb" Content="{Binding [SaveBlackBox], Source={x:Static starterNg:App.Loc}}" />
|
||||
</ctl:SettingRow>
|
||||
<ctl:SettingRow Description="{Binding [SaveTrainTapesDesc], Source={x:Static starterNg:App.Loc}}" ConfigKey="physicslog.trains">
|
||||
<CheckBox x:Name="TrainTapesCb" Content="{Binding [SaveTrainTapes], Source={x:Static starterNg:App.Loc}}" />
|
||||
</ctl:SettingRow>
|
||||
<ctl:SettingRow Description="{Binding [SaveSpeedometerTapesDesc], Source={x:Static starterNg:App.Loc}}" ConfigKey="physicslog">
|
||||
<CheckBox x:Name="SpeedometerTapesCb" Content="{Binding [SaveSpeedometerTapes], Source={x:Static starterNg:App.Loc}}" />
|
||||
</ctl:SettingRow>
|
||||
|
||||
@@ -242,9 +242,8 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
App.Loc["ProfileSaveAs"], MessageBoxButtons.YesNo))
|
||||
return;
|
||||
|
||||
// Written beside the user's own eu07.ini, which stays as it is.
|
||||
CaptureInto(AppServices.Current.Settings);
|
||||
bool saved = AppServices.Current.SettingsStore.ExportTo(path);
|
||||
// Written beside the user's own eu07.ini, which stays as it is; the edits stay the page's, not saved
|
||||
bool saved = AppServices.Current.SettingsStore.ExportTo(path, Trial());
|
||||
PopulateProfileCombo();
|
||||
int idx = FindComboIndexByContent(ProfileCb, Path.GetFileNameWithoutExtension(path));
|
||||
if (idx >= 0) ProfileCb.SelectedIndex = idx;
|
||||
@@ -340,7 +339,13 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
SelectExeCb.SelectedIndex = index;
|
||||
}
|
||||
|
||||
public void ReloadFromSettings() => ApplyToUi();
|
||||
/// <summary>The settings read again from the file: the page shows them, no edit of its own left.</summary>
|
||||
public void ReloadFromSettings()
|
||||
{
|
||||
ApplyToUi();
|
||||
_dirty = false;
|
||||
UpdateSaveState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True while a cab-control binding is waiting for a keypress. The window's own
|
||||
@@ -353,6 +358,8 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
WhileLoading(() =>
|
||||
{
|
||||
SpeedometerTapesCb.IsChecked = AppServices.Current.Settings.PhysicsLog;
|
||||
BlackBoxCb.IsChecked = AppServices.Current.Settings.BlackBox;
|
||||
TrainTapesCb.IsChecked = AppServices.Current.Settings.PhysicsLogTrains;
|
||||
SimLogsCb.IsChecked = AppServices.Current.Settings.DebugLog;
|
||||
});
|
||||
|
||||
@@ -465,6 +472,8 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
PantographBreakCb.IsChecked = s.EnableTraction;
|
||||
OverheadOnlyCb.IsChecked = s.LiveTraction;
|
||||
SpeedometerTapesCb.IsChecked = s.PhysicsLog;
|
||||
BlackBoxCb.IsChecked = s.BlackBox;
|
||||
TrainTapesCb.IsChecked = s.PhysicsLogTrains;
|
||||
SimLogsCb.IsChecked = s.DebugLog;
|
||||
KeepLogsCb.IsChecked = s.MultipleLogs;
|
||||
DisplaySimulationCb.IsChecked = s.DisplaySimulation;
|
||||
@@ -900,6 +909,8 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
s.EnableTraction = IsChecked(PantographBreakCb);
|
||||
s.LiveTraction = IsChecked(OverheadOnlyCb);
|
||||
s.PhysicsLog = IsChecked(SpeedometerTapesCb);
|
||||
s.BlackBox = IsChecked(BlackBoxCb);
|
||||
s.PhysicsLogTrains = IsChecked(TrainTapesCb);
|
||||
s.DebugLog = IsChecked(SimLogsCb);
|
||||
s.MultipleLogs = IsChecked(KeepLogsCb);
|
||||
s.DisplaySimulation = IsChecked(DisplaySimulationCb);
|
||||
@@ -1176,6 +1187,18 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
Announcer.Say(this, App.Loc["SettingsRestored"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The page's own edits let go, and the keys': the page shows the settings as held. Not read again from the file
|
||||
/// as "Restore" does - what other pages set and not yet saved (a filter of the depot, the window maximized) stays.
|
||||
/// </summary>
|
||||
public void DiscardEdits()
|
||||
{
|
||||
ApplyToUi();
|
||||
_keyBindings.Reload();
|
||||
_dirty = false;
|
||||
UpdateSaveState();
|
||||
}
|
||||
|
||||
/// <summary>The list as <see cref="ResolutionChoices"/> has it for the monitors there are now, with the size selected.</summary>
|
||||
private void SelectResolution(int width, int height)
|
||||
{
|
||||
@@ -1514,9 +1537,12 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
UpdateSaveState();
|
||||
}
|
||||
|
||||
/// <summary>Edits on the page, or of the keys, not saved yet: what "Niezapisane zmiany" tells.</summary>
|
||||
public bool HasUnsavedChanges => _dirty || KeyboardConfig.Instance.Dirty;
|
||||
|
||||
private void UpdateSaveState()
|
||||
{
|
||||
bool dirty = _dirty || KeyboardConfig.Instance.Dirty;
|
||||
bool dirty = HasUnsavedChanges;
|
||||
SaveButton.Classes.Set("Accent", dirty);
|
||||
SaveStatus.Text = dirty ? App.Loc["UnsavedChanges"] : string.Empty;
|
||||
}
|
||||
|
||||
65
StarterNG/Views/Tapes/ColumnLine.cs
Normal file
65
StarterNG/Views/Tapes/ColumnLine.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
|
||||
namespace StarterNG.Views.Tapes;
|
||||
|
||||
/// <summary>
|
||||
/// The line of a tape, one column of pixels at a time: of each column, the first, the lowest, the highest and the
|
||||
/// last point in it, entered where the column started and left where it ended, so a long trip draws as fast as a
|
||||
/// short one. The figures go out through the three calls given: one begun at its first point, a line to each next,
|
||||
/// and its end.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Its state is kept in fields, not in the locals of a local function, which Sonar's analysis doesn't see changed
|
||||
/// by it (S2583 took the end of a figure after a gap for code never run).
|
||||
/// </remarks>
|
||||
internal sealed class ColumnLine(Action<Point> begin, Action<Point> lineTo, Action end)
|
||||
{
|
||||
private bool _begun;
|
||||
private int _column = int.MinValue;
|
||||
private double _top, _bottom, _first, _last;
|
||||
|
||||
/// <summary>The point of a sample, at its column of pixels.</summary>
|
||||
public void Add(int column, double value)
|
||||
{
|
||||
if (column != _column)
|
||||
{
|
||||
Flush();
|
||||
_column = column;
|
||||
_top = _bottom = _first = value;
|
||||
}
|
||||
_top = Math.Min(_top, value);
|
||||
_bottom = Math.Max(_bottom, value);
|
||||
_last = value;
|
||||
}
|
||||
|
||||
/// <summary>The line ends here, at a gap or at the end of the tape; a point added after begins a figure of its own.</summary>
|
||||
public void Break()
|
||||
{
|
||||
Flush();
|
||||
_column = int.MinValue;
|
||||
if (!_begun)
|
||||
return;
|
||||
end();
|
||||
_begun = false;
|
||||
}
|
||||
|
||||
private void Flush()
|
||||
{
|
||||
if (_column == int.MinValue)
|
||||
return;
|
||||
// Enter where the column started, leave where it ended.
|
||||
var (a, b) = _first <= _last ? (_top, _bottom) : (_bottom, _top);
|
||||
foreach (double v in new[] { _first, a, b, _last })
|
||||
{
|
||||
var p = new Point(_column, v);
|
||||
if (_begun)
|
||||
lineTo(p);
|
||||
else
|
||||
{
|
||||
begin(p);
|
||||
_begun = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,10 @@ public sealed class HaslerTapeWindow : Window
|
||||
private bool _running;
|
||||
private bool _loading;
|
||||
private bool _looking;
|
||||
// closed: a read already under way when it closed is let go, not kept followed
|
||||
private bool _closed;
|
||||
// the file read last, kept by the tapes to be followed even once another is picked or none is shown
|
||||
private string? _read;
|
||||
|
||||
/// <summary>A setting went on from here; the settings page's boxes have to follow it.</summary>
|
||||
public event Action? LogEnabled;
|
||||
@@ -166,7 +170,12 @@ public sealed class HaslerTapeWindow : Window
|
||||
Content = _view
|
||||
};
|
||||
|
||||
_recordingOff = Strip("HaslerRecordingOff", "HaslerRecordingEnable", settings => settings.PhysicsLog = true);
|
||||
// the black box, with the tapes of the player's vehicles, and the tapes of every train
|
||||
_recordingOff = Strip("HaslerRecordingOff", "HaslerRecordingEnable", settings =>
|
||||
{
|
||||
settings.BlackBox = true;
|
||||
settings.PhysicsLogTrains = true;
|
||||
});
|
||||
_logOff = Strip("HaslerLogOff", "HaslerLogEnable", settings => settings.DebugLog = true);
|
||||
|
||||
var folder = ToolButton(App.Loc["HaslerOpenFolder"]);
|
||||
@@ -222,7 +231,13 @@ public sealed class HaslerTapeWindow : Window
|
||||
await RefreshListAsync();
|
||||
};
|
||||
Activated += (_, _) => ShowWhatIsKnown();
|
||||
Closed += (_, _) => _timer.Stop();
|
||||
Closed += (_, _) =>
|
||||
{
|
||||
_closed = true;
|
||||
_timer.Stop();
|
||||
if (_read is { } read)
|
||||
_tapes.Forget(read);
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -232,10 +247,12 @@ public sealed class HaslerTapeWindow : Window
|
||||
private void ShowWhatIsKnown()
|
||||
{
|
||||
var settings = AppServices.Current.Settings;
|
||||
_recordingOff.IsVisible = !settings.PhysicsLog;
|
||||
_logOff.IsVisible = settings.PhysicsLog && !settings.DebugLog;
|
||||
bool recording = settings.PhysicsLog || settings.BlackBox || settings.PhysicsLogTrains;
|
||||
_recordingOff.IsVisible = !recording;
|
||||
_logOff.IsVisible = recording && !settings.DebugLog;
|
||||
|
||||
bool canFollow = _running && _tapes.DrivenVehicle is not null;
|
||||
// the physics logs and the black box's tapes both grow while the simulator runs, every two seconds
|
||||
bool canFollow = _running && recording && _tapes.DrivenVehicle is not null;
|
||||
_live.IsEnabled = canFollow;
|
||||
if (!canFollow)
|
||||
_live.IsChecked = false;
|
||||
@@ -641,7 +658,15 @@ public sealed class HaslerTapeWindow : Window
|
||||
_loading = true;
|
||||
try
|
||||
{
|
||||
var tape = await Task.Run(() => _tapes.Load(file));
|
||||
// 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;
|
||||
_read = file.Path;
|
||||
var tape = await Task.Run(() => _tapes.Load(file, follow));
|
||||
if (_closed)
|
||||
{
|
||||
_tapes.Forget(file.Path);
|
||||
return;
|
||||
}
|
||||
bool another = file.Path != _shown?.Path;
|
||||
_shown = file;
|
||||
_tapeless = null;
|
||||
@@ -656,10 +681,13 @@ public sealed class HaslerTapeWindow : Window
|
||||
|
||||
_view.Tape = tape;
|
||||
ShowMark(scrollTo: another && !scrollToEnd);
|
||||
_summary.Text = string.Format(App.Loc["HaslerSummary"], file.Vehicle, TapeFigures.Clock(tape.Duration),
|
||||
// what was recorded is running and standing; a gap, the player in another vehicle, is neither
|
||||
_summary.Text = string.Format(App.Loc["HaslerSummary"], file.Vehicle, TapeFigures.Clock(tape.Duration - tape.GapTime),
|
||||
TapeFigures.Clock(tape.RunningTime), TapeFigures.Clock(tape.StandingTime),
|
||||
tape.DistanceM / 1000.0, tape.MaxSpeedKmh, tape.AverageSpeedKmh,
|
||||
tape.AverageWithStopsKmh);
|
||||
if (tape.GapTime > 0)
|
||||
_summary.Text += " · " + string.Format(App.Loc["HaslerGap"], TapeFigures.Clock(tape.GapTime));
|
||||
if (_context?.Scenery is { } scenery)
|
||||
_summary.Text += " · " + string.Format(App.Loc["HaslerScenario"], scenery);
|
||||
if (_context?.Train is { } train)
|
||||
@@ -693,6 +721,8 @@ public sealed class HaslerTapeWindow : Window
|
||||
try
|
||||
{
|
||||
var sessions = await Task.Run(_tapes.Sessions);
|
||||
if (_closed)
|
||||
return;
|
||||
bool live = _live.IsChecked == true;
|
||||
bool newDriven = live && DrivenTape(sessions) is { } driven && driven.Path != _followed;
|
||||
if (newDriven || Fingerprint(sessions) != _listed)
|
||||
|
||||
@@ -341,46 +341,18 @@ public abstract class TapeView : Control
|
||||
{
|
||||
var geometry = new StreamGeometry();
|
||||
using var g = geometry.Open();
|
||||
bool begun = false;
|
||||
int column = int.MinValue;
|
||||
double top = 0, bottom = 0, first = 0, last = 0;
|
||||
|
||||
void Flush()
|
||||
{
|
||||
if (column == int.MinValue)
|
||||
return;
|
||||
// Enter where the column started, leave where it ended.
|
||||
var (a, b) = first <= last ? (top, bottom) : (bottom, top);
|
||||
foreach (double v in new[] { first, a, b, last })
|
||||
{
|
||||
var p = new Point(column, v);
|
||||
if (!begun)
|
||||
{
|
||||
g.BeginFigure(p, false);
|
||||
begun = true;
|
||||
}
|
||||
else
|
||||
g.LineTo(p);
|
||||
}
|
||||
}
|
||||
|
||||
var line = new ColumnLine(p => g.BeginFigure(p, false), p => g.LineTo(p), () => g.EndFigure(false));
|
||||
double? before = null;
|
||||
foreach (var s in tape.Samples)
|
||||
{
|
||||
int c = (int)Math.Round(XOf(s));
|
||||
double value = y(s);
|
||||
if (c != column)
|
||||
{
|
||||
Flush();
|
||||
column = c;
|
||||
top = bottom = first = value;
|
||||
}
|
||||
top = Math.Min(top, value);
|
||||
bottom = Math.Max(bottom, value);
|
||||
last = value;
|
||||
// A gap, the player in another vehicle, is not drawn as if the train drove or stood through it: the
|
||||
// line breaks off there.
|
||||
if (before is { } previous && s.Time - previous > tape.GapSeconds)
|
||||
line.Break();
|
||||
before = s.Time;
|
||||
line.Add((int)Math.Round(XOf(s)), y(s));
|
||||
}
|
||||
Flush();
|
||||
if (begun)
|
||||
g.EndFigure(false);
|
||||
line.Break();
|
||||
return geometry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
<String key="HaslerClockUnknown">hodina neznámá, čas se počítá od startu simulace</String>
|
||||
<String key="HaslerUnreadable">Pásku {0} se nepodařilo přečíst.</String>
|
||||
<String key="HaslerSummary">{0} · zaznamenáno {1} (jízda {2}, stání {3}) · dráha {4:0.00} km · Vmax {5:0} km/h · průměr za jízdy {6:0} km/h · průměr se zastávkami {7:0} km/h</String>
|
||||
<String key="HaslerGap">nezaznamenáno {0}</String>
|
||||
<String key="HaslerCursor">{0} · {1:0.0} km · {2:0} km/h · válce {3:0.0} bar · proud {4}</String>
|
||||
<String key="HaslerTrackCylinders">Válce</String>
|
||||
<String key="HaslerTrackPipe">HP</String>
|
||||
@@ -497,7 +498,11 @@
|
||||
<String key="PhysicsAccuracyIncreased">Zvýšená přesnost fyziky</String>
|
||||
<String key="BreakingPantographPossibility">Možnost zlomení pantografu</String>
|
||||
<String key="PowerOverheadLineOnly">Napájení jen pod trolejí</String>
|
||||
<String key="SaveSpeedometerTapes">Ukládat pásky rychloměru</String>
|
||||
<String key="SaveBlackBox">Nahrávat černou skříňku a pásky rychloměru</String>
|
||||
<String key="SaveBlackBoxDesc">Nahrává jízdu do jednoho souboru ve složce physicslog/ a průběžně, každé 2 s, zapisuje pásky (.dat) vozidel, ve kterých jste.</String>
|
||||
<String key="SaveTrainTapes">Nahrávat pásky rychloměru všech vlaků</String>
|
||||
<String key="SaveTrainTapesDesc">Průběžně, každé 2 s, zapisuje pásky (.dat) každého vlaku scenérie do složky physicslog/: jednu na strojvedoucího kolejových vozidel, bez silničních vozidel a cestujících. Mnohem méně souborů než fyzikální log každého vozidla.</String>
|
||||
<String key="SaveSpeedometerTapes">Ukládat fyzikální log všech vozidel</String>
|
||||
<String key="SaveSimLogs">Ukládat log simulace</String>
|
||||
<String key="KeepPrevLogs">Zachovat předchozí logy</String>
|
||||
<String key="DisplaySimulation">Zobrazit simulaci</String>
|
||||
@@ -670,6 +675,9 @@
|
||||
<String key="WarehouseAppend">Připojit soupravu ze skladu</String>
|
||||
<String key="WarehouseImportFile">Přidat soupravy ze souboru...</String>
|
||||
<String key="StartWithoutSaving">Spustit bez uložení nastavení</String>
|
||||
<String key="StartUnsavedMessage">Nastavení obsahuje neuložené změny. Uložit je před spuštěním simulátoru?</String>
|
||||
<String key="StartUnsavedSave">Uložit a spustit</String>
|
||||
<String key="StartUnsavedWithout">Zahodit změny a spustit</String>
|
||||
<String key="StartMore">Další způsoby spuštění</String>
|
||||
<String key="StartFreeFly">Spustit bez vozidla</String>
|
||||
<String key="StartEditorShort">Editor scenérie</String>
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
<String key="HaslerClockUnknown">hour unknown, time counted from the start of the simulation</String>
|
||||
<String key="HaslerUnreadable">Could not read the tape {0}.</String>
|
||||
<String key="HaslerSummary">{0} · recorded {1} (running {2}, standing {3}) · distance {4:0.00} km · Vmax {5:0} km/h · running average {6:0} km/h · average with stops {7:0} km/h</String>
|
||||
<String key="HaslerGap">not recorded {0}</String>
|
||||
<String key="HaslerCursor">{0} · {1:0.0} km · {2:0} km/h · cylinders {3:0.0} bar · current {4}</String>
|
||||
<String key="HaslerTrackCylinders">Cylinders</String>
|
||||
<String key="HaslerTrackPipe">BP</String>
|
||||
@@ -516,8 +517,12 @@
|
||||
<String key="BreakingPantographPossibilityDesc">Disabling protects the pantograph from breaking on faulty overhead line geometry.</String>
|
||||
<String key="PowerOverheadLineOnly">Powered only under overhead line</String>
|
||||
<String key="PowerOverheadLineOnlyDesc">When disabled, a raised pantograph can power the vehicle even without touching the wire.</String>
|
||||
<String key="SaveSpeedometerTapes">Save physics parameters log</String>
|
||||
<String key="SaveSpeedometerTapesDesc">Writes a detailed trip log to the physicslog/ folder.</String>
|
||||
<String key="SaveBlackBox">Record the black box and the speedometer tapes</String>
|
||||
<String key="SaveBlackBoxDesc">Records the session to one file in the physicslog/ folder and writes the tapes (.dat) of the vehicles you are in as it goes, every 2 s.</String>
|
||||
<String key="SaveTrainTapes">Record the speedometer tapes of every train</String>
|
||||
<String key="SaveTrainTapesDesc">Writes the tapes (.dat) of every train of the scenery to the physicslog/ folder as it goes, every 2 s: one per driver of rail vehicles, not of road vehicles nor passengers. Far fewer files than the physics log of every vehicle.</String>
|
||||
<String key="SaveSpeedometerTapes">Save the physics log of every vehicle</String>
|
||||
<String key="SaveSpeedometerTapesDesc">Writes the log of every vehicle of the scenery to the physicslog/ folder: a line every 0.05 s, added every 2 s. For diagnostics: on a large scenery that is hundreds of files.</String>
|
||||
<String key="SaveSimLogs">Save simulation log</String>
|
||||
<String key="KeepPrevLogs">Keep previous logs</String>
|
||||
<String key="KeepPrevLogsDesc">Creates a separate log file for each scenery instead of overwriting errors.txt.</String>
|
||||
@@ -696,6 +701,9 @@
|
||||
<String key="WarehouseAppend">Append warehouse consist</String>
|
||||
<String key="WarehouseImportFile">Add consists from file...</String>
|
||||
<String key="StartWithoutSaving">Start without saving settings</String>
|
||||
<String key="StartUnsavedMessage">The settings have unsaved changes. Save them before starting the simulator?</String>
|
||||
<String key="StartUnsavedSave">Save and start</String>
|
||||
<String key="StartUnsavedWithout">Discard changes and start</String>
|
||||
<String key="StartMore">More ways to start</String>
|
||||
<String key="StartFreeFly">Start with no vehicle</String>
|
||||
<String key="StartEditorShort">Scenery editor</String>
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
<String key="HaslerClockUnknown">az óra ismeretlen, az idő a szimuláció kezdetétől számít</String>
|
||||
<String key="HaslerUnreadable">A(z) {0} szalag nem olvasható.</String>
|
||||
<String key="HaslerSummary">{0} · rögzítve {1} (menet {2}, állás {3}) · út {4:0.00} km · Vmax {5:0} km/h · menetátlag {6:0} km/h · átlag megállásokkal {7:0} km/h</String>
|
||||
<String key="HaslerGap">nem rögzítve {0}</String>
|
||||
<String key="HaslerCursor">{0} · {1:0.0} km · {2:0} km/h · hengerek {3:0.0} bar · áram {4}</String>
|
||||
<String key="HaslerTrackCylinders">Hengerek</String>
|
||||
<String key="HaslerTrackPipe">Fővez.</String>
|
||||
@@ -497,7 +498,11 @@
|
||||
<String key="PhysicsAccuracyIncreased">Növelt fizikai pontosság</String>
|
||||
<String key="BreakingPantographPossibility">Áramszedő törésének lehetősége</String>
|
||||
<String key="PowerOverheadLineOnly">Táplálás csak felsővezeték alatt</String>
|
||||
<String key="SaveSpeedometerTapes">Sebességmérő-szalagok mentése</String>
|
||||
<String key="SaveBlackBox">Fekete doboz és sebességmérő-szalagok rögzítése</String>
|
||||
<String key="SaveBlackBoxDesc">A menetet egy fájlba rögzíti a physicslog/ mappában, és menet közben, 2 másodpercenként kiírja azoknak a járműveknek a szalagjait (.dat), amelyekben ülsz.</String>
|
||||
<String key="SaveTrainTapes">Minden vonat sebességmérő-szalagjának rögzítése</String>
|
||||
<String key="SaveTrainTapesDesc">Menet közben, 2 másodpercenként kiírja a pálya minden vonatának szalagját (.dat) a physicslog/ mappába: egyet a sínjárművek minden vezetőjének, közúti járművek és utasok nélkül. Jóval kevesebb fájl, mint minden jármű fizikai naplója.</String>
|
||||
<String key="SaveSpeedometerTapes">Minden jármű fizikai naplójának mentése</String>
|
||||
<String key="SaveSimLogs">Szimulációs napló mentése</String>
|
||||
<String key="KeepPrevLogs">Korábbi naplók megtartása</String>
|
||||
<String key="DisplaySimulation">Szimuláció megjelenítése</String>
|
||||
@@ -670,6 +675,9 @@
|
||||
<String key="WarehouseAppend">Raktári szerelvény hozzáfűzése</String>
|
||||
<String key="WarehouseImportFile">Szerelvények hozzáadása fájlból...</String>
|
||||
<String key="StartWithoutSaving">Indítás a beállítások mentése nélkül</String>
|
||||
<String key="StartUnsavedMessage">A beállításokban nem mentett módosítások vannak. Menti őket a szimulátor indítása előtt?</String>
|
||||
<String key="StartUnsavedSave">Mentés és indítás</String>
|
||||
<String key="StartUnsavedWithout">Módosítások elvetése és indítás</String>
|
||||
<String key="StartMore">További indítási módok</String>
|
||||
<String key="StartFreeFly">Indítás jármű nélkül</String>
|
||||
<String key="StartEditorShort">Pályaszerkesztő</String>
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
<String key="HaslerClockUnknown">godzina nieznana, czas liczony od startu symulacji</String>
|
||||
<String key="HaslerUnreadable">Nie udało się odczytać taśmy {0}.</String>
|
||||
<String key="HaslerSummary">{0} · zarejestrowano {1} (jazda {2}, postój {3}) · droga {4:0.00} km · Vmax {5:0} km/h · Vśr jazdy {6:0} km/h · Vśr z postojami {7:0} km/h</String>
|
||||
<String key="HaslerGap">nie zarejestrowano {0}</String>
|
||||
<String key="HaslerCursor">{0} · {1:0.0} km · {2:0} km/h · cylindry {3:0.0} bar · prąd {4}</String>
|
||||
<String key="HaslerTrackCylinders">Cylindry</String>
|
||||
<String key="HaslerTrackPipe">PG</String>
|
||||
@@ -516,8 +517,12 @@
|
||||
<String key="BreakingPantographPossibilityDesc">Wyłączenie chroni pantograf przed uszkodzeniem przy błędnej geometrii sieci.</String>
|
||||
<String key="PowerOverheadLineOnly">Zasilanie tylko pod siecią trakcyjna</String>
|
||||
<String key="PowerOverheadLineOnlyDesc">Gdy wyłączone, podniesiony pantograf zasila pojazd nawet bez kontaktu z drutem.</String>
|
||||
<String key="SaveSpeedometerTapes">Zapisuj log parametrów fizycznych</String>
|
||||
<String key="SaveSpeedometerTapesDesc">Zapisuje szczegółowy log jazdy do folderu physicslog/.</String>
|
||||
<String key="SaveBlackBox">Zapisuj czarną skrzynkę i taśmy prędkościomierza</String>
|
||||
<String key="SaveBlackBoxDesc">Nagrywa przejazd do jednego pliku w folderze physicslog/ i na bieżąco, co 2 s, zapisuje taśmy (.dat) pojazdów, w których jesteś.</String>
|
||||
<String key="SaveTrainTapes">Zapisuj taśmy prędkościomierza wszystkich pociągów</String>
|
||||
<String key="SaveTrainTapesDesc">Na bieżąco, co 2 s, zapisuje taśmy (.dat) każdego pociągu scenerii do folderu physicslog/: jedną na maszynistę pojazdów szynowych, bez pojazdów drogowych i pasażerów. Znacznie mniej plików niż log fizyki każdego pojazdu.</String>
|
||||
<String key="SaveSpeedometerTapes">Zapisuj log parametrów fizycznych wszystkich pojazdów</String>
|
||||
<String key="SaveSpeedometerTapesDesc">Zapisuje log każdego pojazdu scenerii do folderu physicslog/: wiersz co 0,05 s, dopisywany co 2 s. Do diagnostyki: na dużej scenerii to setki plików.</String>
|
||||
<String key="SaveSimLogs">Zapisuj log z symulacji</String>
|
||||
<String key="KeepPrevLogs">Zachowuj poprzednie logi</String>
|
||||
<String key="KeepPrevLogsDesc">Tworzy osobny plik logu dla każdej scenerii zamiast nadpisywać errors.txt.</String>
|
||||
@@ -696,6 +701,9 @@
|
||||
<String key="WarehouseAppend">Dołącz skład z magazynu</String>
|
||||
<String key="WarehouseImportFile">Dodaj składy z pliku...</String>
|
||||
<String key="StartWithoutSaving">Uruchom bez zapisu ustawień</String>
|
||||
<String key="StartUnsavedMessage">Ustawienia mają niezapisane zmiany. Zapisać je przed uruchomieniem symulatora?</String>
|
||||
<String key="StartUnsavedSave">Zapisz i uruchom</String>
|
||||
<String key="StartUnsavedWithout">Odrzuć zmiany i uruchom</String>
|
||||
<String key="StartMore">Inne sposoby uruchomienia</String>
|
||||
<String key="StartFreeFly">Uruchom bez pojazdu</String>
|
||||
<String key="StartEditorShort">Edytor scenerii</String>
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
<String key="HaslerClockUnknown">час неизвестен, время считается от начала симуляции</String>
|
||||
<String key="HaslerUnreadable">Не удалось прочитать ленту {0}.</String>
|
||||
<String key="HaslerSummary">{0} · записано {1} (движение {2}, стоянка {3}) · путь {4:0.00} км · Vmax {5:0} км/ч · средняя в движении {6:0} км/ч · средняя со стоянками {7:0} км/ч</String>
|
||||
<String key="HaslerGap">не записано {0}</String>
|
||||
<String key="HaslerCursor">{0} · {1:0.0} км · {2:0} км/ч · цилиндры {3:0.0} бар · ток {4}</String>
|
||||
<String key="HaslerTrackCylinders">Цилиндры</String>
|
||||
<String key="HaslerTrackPipe">ТМ</String>
|
||||
@@ -497,7 +498,11 @@
|
||||
<String key="PhysicsAccuracyIncreased">Повышенная точность физики</String>
|
||||
<String key="BreakingPantographPossibility">Возможность излома пантографа</String>
|
||||
<String key="PowerOverheadLineOnly">Питание только под контактной сетью</String>
|
||||
<String key="SaveSpeedometerTapes">Сохранять ленты скоростемера</String>
|
||||
<String key="SaveBlackBox">Записывать чёрный ящик и ленты скоростемера</String>
|
||||
<String key="SaveBlackBoxDesc">Записывает поездку в один файл в папке physicslog/ и по ходу, каждые 2 с, сохраняет ленты (.dat) тех единиц, в которых вы находитесь.</String>
|
||||
<String key="SaveTrainTapes">Записывать ленты скоростемера всех поездов</String>
|
||||
<String key="SaveTrainTapesDesc">По ходу, каждые 2 с, сохраняет ленты (.dat) каждого поезда сценария в папку physicslog/: по одной на машиниста рельсового состава, без автомобилей и пассажиров. Гораздо меньше файлов, чем физический журнал каждой единицы.</String>
|
||||
<String key="SaveSpeedometerTapes">Сохранять физический лог всех единиц</String>
|
||||
<String key="SaveSimLogs">Сохранять журнал симуляции</String>
|
||||
<String key="KeepPrevLogs">Сохранять предыдущие журналы</String>
|
||||
<String key="DisplaySimulation">Показывать симуляцию</String>
|
||||
@@ -670,6 +675,9 @@
|
||||
<String key="WarehouseAppend">Присоединить состав со склада</String>
|
||||
<String key="WarehouseImportFile">Добавить составы из файла...</String>
|
||||
<String key="StartWithoutSaving">Запустить без сохранения настроек</String>
|
||||
<String key="StartUnsavedMessage">В настройках есть несохранённые изменения. Сохранить их перед запуском симулятора?</String>
|
||||
<String key="StartUnsavedSave">Сохранить и запустить</String>
|
||||
<String key="StartUnsavedWithout">Отменить изменения и запустить</String>
|
||||
<String key="StartMore">Другие способы запуска</String>
|
||||
<String key="StartFreeFly">Запустить без транспорта</String>
|
||||
<String key="StartEditorShort">Редактор сценария</String>
|
||||
|
||||
Reference in New Issue
Block a user