mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-12 09:04:09 +01:00
The simulator writes a black box of each run to physicslog/*.blackbox (blackbox_doc.md in the maszyna repository). Three new projects read and show it: - Eu07.BlackBox: the reader of the records, the recording as a whole (the user's vehicle and consist at a time, the timetable shown, the progress along it with arrival and departure delays, whether the train stood at the platform), the light patterns Pc 1, Pc 2, Pc 5 and Tb 1 with the ones the run asks for, and a summary of the driving. - Eu07.BlackBox.Views: the player window, with the scenery map (tracks, signals, W4 stop points with their heading and W32, the train, the cameras), the cab, the timeline of speed against the AI's reference, the events, the timetable and the summary. - Eu07.BlackBox.Viewer: the window on its own, with options for the time, following the train and screenshots. The tapes window of the starter lists the black boxes of each session beside the Hasler tapes and opens them in the player.
29 lines
939 B
C#
29 lines
939 B
C#
using System.Threading.Tasks;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Media.Imaging;
|
|
using Eu07.BlackBox.Views;
|
|
|
|
namespace Eu07.BlackBox.Viewer;
|
|
|
|
/// <summary>The window as it shows a moment, saved to a PNG; then the viewer closes.</summary>
|
|
internal static class Screenshot
|
|
{
|
|
public static async Task SaveAsync(BlackBoxWindow window, string path, double? time, bool follow)
|
|
{
|
|
if (time is { } t)
|
|
window.SeekTo(t);
|
|
window.FollowTrain = follow;
|
|
// A few frames for the layout and the first render.
|
|
await Task.Delay(1000);
|
|
if (window.Content is Control content)
|
|
{
|
|
var size = new PixelSize((int)content.Bounds.Width, (int)content.Bounds.Height);
|
|
using var bitmap = new RenderTargetBitmap(size);
|
|
bitmap.Render(content);
|
|
bitmap.Save(path, new PngBitmapEncoderOptions());
|
|
}
|
|
window.Close();
|
|
}
|
|
}
|