mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-18 22:45:59 +01:00
Cut the comments from the refactored code
Three survive: why AppServices is hand-wired, the cp1250 registration trap, and the IsDieselEngine note carried over from Physics.cs.
This commit is contained in:
@@ -6,17 +6,6 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Adapters;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IDiagnosticsLog"/> that mirrors every line into starter/bledy.txt.
|
||||
/// Writing is best-effort: a read-only or full installation directory degrades to
|
||||
/// an in-memory log rather than taking the starter down, and a single retry is
|
||||
/// made at <see cref="Flush"/> time.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Instance state replaces the previous static <c>Diagnostics</c> accumulator, so
|
||||
/// tests can assert on what a use case logged without touching disk (pair it with
|
||||
/// an in-memory <see cref="IFileSystem"/>).
|
||||
/// </remarks>
|
||||
public sealed class FileDiagnosticsLog : IDiagnosticsLog
|
||||
{
|
||||
private readonly IFileSystem _files;
|
||||
@@ -75,7 +64,6 @@ public sealed class FileDiagnosticsLog : IDiagnosticsLog
|
||||
}
|
||||
catch
|
||||
{
|
||||
// A log we cannot delete is not worth failing a user action over.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,8 +88,6 @@ public sealed class FileDiagnosticsLog : IDiagnosticsLog
|
||||
if (!_writerFailed && _writer is not null)
|
||||
return;
|
||||
|
||||
// The streaming writer never came up (or died mid-session): fall back
|
||||
// to one bulk write so the session is not lost entirely.
|
||||
try
|
||||
{
|
||||
_files.CreateDirectory(Path.GetDirectoryName(_logPath)!);
|
||||
@@ -109,7 +95,6 @@ public sealed class FileDiagnosticsLog : IDiagnosticsLog
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Nothing left to try; the in-memory log still backs the UI.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,7 +128,6 @@ public sealed class FileDiagnosticsLog : IDiagnosticsLog
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Disposing a broken writer is allowed to fail.
|
||||
}
|
||||
_writer = null;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,6 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Adapters;
|
||||
|
||||
/// <summary>
|
||||
/// The stock MaSzyna layout, rooted at the process working directory (the
|
||||
/// starter ships inside the installation folder, next to eu07.exe).
|
||||
/// </summary>
|
||||
public sealed class GamePaths : IGamePaths
|
||||
{
|
||||
public GamePaths(string root)
|
||||
@@ -14,7 +10,6 @@ public sealed class GamePaths : IGamePaths
|
||||
Root = root;
|
||||
}
|
||||
|
||||
/// <summary>The installation the starter was launched from.</summary>
|
||||
public static GamePaths ForCurrentDirectory() => new(Directory.GetCurrentDirectory());
|
||||
|
||||
public string Root { get; }
|
||||
|
||||
@@ -17,14 +17,8 @@ namespace StarterNG.Infrastructure.Adapters;
|
||||
/// </remarks>
|
||||
public static class LegacyText
|
||||
{
|
||||
/// <summary>The .scn / .fiz / .ini code page, or Latin-1 if it is unavailable.</summary>
|
||||
public static Encoding CodePage1250 { get; } = Resolve();
|
||||
|
||||
/// <summary>
|
||||
/// True when the code page could not be loaded and text is being read as
|
||||
/// Latin-1 instead. Polish characters will be wrong; the startup check
|
||||
/// reports it rather than leaving it to be discovered on screen.
|
||||
/// </summary>
|
||||
public static bool IsFallback { get; private set; }
|
||||
|
||||
private static Encoding Resolve()
|
||||
|
||||
@@ -6,10 +6,6 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Adapters;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IFileSystem"/> backed by the real disk. The only place in the
|
||||
/// application allowed to touch <see cref="File"/> and <see cref="Directory"/>.
|
||||
/// </summary>
|
||||
public sealed class PhysicalFileSystem : IFileSystem
|
||||
{
|
||||
public bool FileExists(string path) => File.Exists(path);
|
||||
|
||||
@@ -3,7 +3,6 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Adapters;
|
||||
|
||||
/// <summary><see cref="IClock"/> backed by the machine clock.</summary>
|
||||
public sealed class SystemClock : IClock
|
||||
{
|
||||
public DateTime Now => DateTime.Now;
|
||||
|
||||
@@ -3,7 +3,6 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Adapters;
|
||||
|
||||
/// <summary><see cref="IEnvironment"/> backed by the running process.</summary>
|
||||
public sealed class SystemEnvironment : IEnvironment
|
||||
{
|
||||
public bool IsWindows => OperatingSystem.IsWindows();
|
||||
|
||||
@@ -8,10 +8,6 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Adapters;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IProcessLauncher"/> backed by <see cref="Process"/>. The only place
|
||||
/// in the application that starts an operating-system process.
|
||||
/// </summary>
|
||||
public sealed class SystemProcessLauncher : IProcessLauncher
|
||||
{
|
||||
private readonly IDiagnosticsLog _log;
|
||||
|
||||
@@ -3,7 +3,6 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Adapters;
|
||||
|
||||
/// <summary><see cref="IRandomSource"/> backed by <see cref="Random.Shared"/>.</summary>
|
||||
public sealed class SystemRandomSource : IRandomSource
|
||||
{
|
||||
public int Next(int minInclusive, int maxExclusive) => Random.Shared.Next(minInclusive, maxExclusive);
|
||||
|
||||
@@ -9,16 +9,6 @@ using StarterNG.Views;
|
||||
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Compatibility facade over <see cref="Application.Abstractions.IDiagnosticsLog"/>
|
||||
/// plus the fault dialog.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The log itself now lives in <c>Infrastructure.Adapters.FileDiagnosticsLog</c>
|
||||
/// and is reached through the composition root. This static shim keeps the
|
||||
/// existing call sites compiling while they are migrated to constructor-injected
|
||||
/// logging; new code should take <c>IDiagnosticsLog</c> instead.
|
||||
/// </remarks>
|
||||
public static class Diagnostics
|
||||
{
|
||||
private static Application.Abstractions.IDiagnosticsLog Log_ => AppServices.Current.Log;
|
||||
@@ -63,9 +53,6 @@ public static class Diagnostics
|
||||
Dispatcher.UIThread.Post(() => _ = ReportAsync(message, title));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sanity check of the installation the starter was launched from.
|
||||
/// </summary>
|
||||
public static List<string> CheckInstallation() =>
|
||||
new InstallationCheck(
|
||||
AppServices.Current.Paths,
|
||||
|
||||
@@ -7,14 +7,6 @@ using StarterNG.Domain.Settings;
|
||||
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the folder the starter runs from actually looks like a MaSzyna
|
||||
/// installation, and reports what is missing in the user's language.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Depends only on ports, so a broken installation can be described in a test by
|
||||
/// handing it an empty in-memory file system.
|
||||
/// </remarks>
|
||||
public sealed class InstallationCheck
|
||||
{
|
||||
private static readonly string[] RequiredFolders = { "dynamic", "sounds", "models", "scenery", "textures" };
|
||||
|
||||
@@ -5,15 +5,6 @@ using StarterNG.Domain.Sceneries;
|
||||
|
||||
namespace StarterNG.Infrastructure.Sceneries;
|
||||
|
||||
/// <summary>
|
||||
/// Finds the preview image a scenery names, which authors place in any of
|
||||
/// several conventional spots relative to the .scn.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Was a lazy property on the aggregate; moved out because it is a lookup on
|
||||
/// disk. Results are cached per scenery path, which is what the lazy field
|
||||
/// bought us before.
|
||||
/// </remarks>
|
||||
public sealed class SceneryImageLocator
|
||||
{
|
||||
private readonly IFileSystem _files;
|
||||
@@ -24,7 +15,6 @@ public sealed class SceneryImageLocator
|
||||
_files = files;
|
||||
}
|
||||
|
||||
/// <summary>The image file for this scenery, or null when there is none.</summary>
|
||||
public string? Resolve(Scenery scenery)
|
||||
{
|
||||
lock (_cache)
|
||||
|
||||
@@ -10,15 +10,6 @@ using StarterNG.Domain.Sceneries;
|
||||
|
||||
namespace StarterNG.Infrastructure.Sceneries;
|
||||
|
||||
/// <summary>
|
||||
/// Turns the text of a .scn file into a <see cref="Scenery"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// All knowledge of the .scn dialect lives here, so the aggregate stays free of
|
||||
/// regular expressions and the parser can be exercised on a string. Anything
|
||||
/// malformed is recorded as a fault rather than thrown: a scenery with one bad
|
||||
/// consist is still worth listing.
|
||||
/// </remarks>
|
||||
public sealed class SceneryParser
|
||||
{
|
||||
private readonly IClock _clock;
|
||||
@@ -32,8 +23,6 @@ public sealed class SceneryParser
|
||||
|
||||
public Scenery Parse(string path, string content)
|
||||
{
|
||||
// Directives, attachments and weather are read from the file as written;
|
||||
// the placeholder rewriting below only shapes the export template.
|
||||
string original = content;
|
||||
|
||||
var faults = new List<string>();
|
||||
@@ -42,8 +31,6 @@ public sealed class SceneryParser
|
||||
var includes = new List<SceneryInclude>();
|
||||
content = StripOptionalIncludes(content, includes);
|
||||
|
||||
// Trainsets are lifted out first so the placeholders survive the loose
|
||||
// vehicle sweep below, which would otherwise match nodes inside them.
|
||||
var trainsetEntries = new List<string>();
|
||||
content = Regex.Replace(content, @"trainset\b[\s\S]*?\bendtrainset\b",
|
||||
match =>
|
||||
@@ -98,7 +85,6 @@ public sealed class SceneryParser
|
||||
|
||||
string[] parts = rest.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// A leading one- or two-character token is a legacy ordering hint.
|
||||
if (parts.Length >= 3 && parts[0].Length <= 2)
|
||||
attachments.Add(new SceneryAttachment
|
||||
{
|
||||
@@ -122,10 +108,6 @@ public sealed class SceneryParser
|
||||
return attachments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the includes the scenery marked <c>$optional</c> from the text and
|
||||
/// records them, so the user can pick which ones the export puts back.
|
||||
/// </summary>
|
||||
private static string StripOptionalIncludes(string content, List<SceneryInclude> includes)
|
||||
{
|
||||
if (content.IndexOf("$optional", StringComparison.OrdinalIgnoreCase) < 0)
|
||||
@@ -160,10 +142,6 @@ public sealed class SceneryParser
|
||||
RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lifts <c>node ... dynamic ... enddynamic</c> entries that sit outside any
|
||||
/// trainset, so the depot can show and reorder them like a consist.
|
||||
/// </summary>
|
||||
private static string ExtractLooseVehicles(string content, List<Dynamic> vehicles, List<string> names,
|
||||
List<string> faults)
|
||||
{
|
||||
@@ -176,7 +154,6 @@ public sealed class SceneryParser
|
||||
{
|
||||
string name = m.Groups[3].Value;
|
||||
|
||||
// A placeholder means the node belongs to a trainset already lifted out.
|
||||
if (name.StartsWith("{{", StringComparison.Ordinal))
|
||||
return m.Value;
|
||||
|
||||
@@ -214,7 +191,6 @@ public sealed class SceneryParser
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Leave the node in the template so the export stays faithful.
|
||||
faults.Add($"# loose dynamic parse fault: {name}");
|
||||
names.Add(name);
|
||||
return m.Value;
|
||||
@@ -239,7 +215,6 @@ public sealed class SceneryParser
|
||||
}
|
||||
else if (!time.Success)
|
||||
{
|
||||
// Nothing authored: start the scenario at the player's wall clock.
|
||||
var now = _clock.Now;
|
||||
weather.ScenarioTimeOverride = $"{now.Hour:D2}:{now.Minute:D2}";
|
||||
}
|
||||
|
||||
@@ -12,17 +12,8 @@ using StarterNG.Infrastructure.Adapters;
|
||||
|
||||
namespace StarterNG.Infrastructure.Sceneries;
|
||||
|
||||
/// <summary>
|
||||
/// Loads scenarios from the installation's scenery folder.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sceneries are code page 1250 text, and a large installation holds hundreds of
|
||||
/// them, so the sweep is parallel; each file that throws is logged and dropped
|
||||
/// rather than taking the whole load down.
|
||||
/// </remarks>
|
||||
public sealed class SceneryRepository : ISceneryRepository
|
||||
{
|
||||
/// <summary>Files starting with '$' are authoring scratch, not scenarios.</summary>
|
||||
private const char ExcludedPrefix = '$';
|
||||
|
||||
private readonly IFileSystem _files;
|
||||
@@ -83,5 +74,4 @@ public sealed class SceneryRepository : ISceneryRepository
|
||||
private IEnumerable<string> SceneryFiles() =>
|
||||
_files.GetFiles(_paths.Scenery, "*.scn")
|
||||
.Where(path => Path.GetFileName(path).FirstOrDefault() != ExcludedPrefix);
|
||||
|
||||
}
|
||||
|
||||
@@ -7,18 +7,8 @@ using StarterNG.Domain.Sceneries;
|
||||
|
||||
namespace StarterNG.Infrastructure.Sceneries;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ISceneryTranslations"/> reading the JSON files a scenery may ship
|
||||
/// in its i18n folder.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// English is loaded first and the user's language layered over it, so a partial
|
||||
/// translation falls back per key rather than per file. Nested objects are
|
||||
/// flattened to dotted keys, which is how the scenery text references them.
|
||||
/// </remarks>
|
||||
public sealed class SceneryTranslations : ISceneryTranslations
|
||||
{
|
||||
/// <summary>Marks a scenery string as a key rather than literal text.</summary>
|
||||
private const char ReferencePrefix = '@';
|
||||
|
||||
private const string BaseLanguage = "en";
|
||||
@@ -99,10 +89,6 @@ public sealed class SceneryTranslations : ISceneryTranslations
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sceneries name their files by two-letter code; the starter's language
|
||||
/// setting may carry a display name instead.
|
||||
/// </summary>
|
||||
private static string NormalizeLanguage(string language)
|
||||
{
|
||||
string lower = language.Trim().ToLowerInvariant();
|
||||
|
||||
@@ -6,15 +6,6 @@ using StarterNG.Domain.Sceneries;
|
||||
|
||||
namespace StarterNG.Infrastructure.Sceneries;
|
||||
|
||||
/// <summary>
|
||||
/// Finds the timetable file a consist names.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Timetables live in the shared timetables/ folder, next to the scenery, or in
|
||||
/// scenario/ depending on the installation's vintage, and the name may or may
|
||||
/// not carry its .txt extension. "none" is the format's way of saying a consist
|
||||
/// runs without one.
|
||||
/// </remarks>
|
||||
public sealed class TimetableLocator
|
||||
{
|
||||
private const string NoTimetable = "none";
|
||||
|
||||
@@ -7,18 +7,8 @@ using StarterNG.Domain.Settings;
|
||||
|
||||
namespace StarterNG.Infrastructure.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Finds and vets the simulator executable the starter will launch.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Installations ship the binary under several names (eu07.exe, eu07,
|
||||
/// eu07-vulkan, ...), and a folder shared between platforms may hold both a PE
|
||||
/// and an ELF build. So a candidate is not just found by name: it is checked for
|
||||
/// the execute bit and for a magic number matching the platform we are on.
|
||||
/// </remarks>
|
||||
public sealed class ExecutableLocator
|
||||
{
|
||||
/// <summary>Extensions that are never the simulator, whatever they are named.</summary>
|
||||
private static readonly string[] NeverExecutable =
|
||||
{
|
||||
".ini", ".log", ".txt", ".cfg", ".config", ".json", ".dll", ".so", ".dat", ".bak", ".csv", ".xml"
|
||||
@@ -37,13 +27,8 @@ public sealed class ExecutableLocator
|
||||
_log = log;
|
||||
}
|
||||
|
||||
/// <summary>The canonical name for the platform, used when nothing is found.</summary>
|
||||
public string CanonicalName => _environment.IsWindows ? "eu07.exe" : "eu07";
|
||||
|
||||
/// <summary>
|
||||
/// The executable to launch for these settings, along with what is wrong with
|
||||
/// it. A path is always returned so the UI can show what it was looking for.
|
||||
/// </summary>
|
||||
public string Resolve(SimulatorSettings settings, out ExeProblem problem)
|
||||
{
|
||||
if (!settings.SelectExeAutomatically && !string.IsNullOrWhiteSpace(settings.ExecutablePath))
|
||||
@@ -55,7 +40,6 @@ public sealed class ExecutableLocator
|
||||
string? fallback = null;
|
||||
try
|
||||
{
|
||||
// Prefer the canonical name, then the shortest: "eu07" over "eu07-dev".
|
||||
var candidates = _files.GetFiles(_paths.Root, "eu07*")
|
||||
.Where(IsCandidate)
|
||||
.OrderBy(path => string.Equals(Path.GetFileName(path), CanonicalName,
|
||||
@@ -87,7 +71,6 @@ public sealed class ExecutableLocator
|
||||
return CanonicalName;
|
||||
}
|
||||
|
||||
/// <summary>Executables the user can pick from, most recently built first.</summary>
|
||||
public List<string> ListCandidates(string? directory = null)
|
||||
{
|
||||
try
|
||||
@@ -122,11 +105,6 @@ public sealed class ExecutableLocator
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the file's magic number: "MZ" for a Windows binary, 0x7F "ELF" for a
|
||||
/// Linux one. A file we cannot read four bytes from is given the benefit of
|
||||
/// the doubt.
|
||||
/// </summary>
|
||||
private bool MatchesPlatform(string path)
|
||||
{
|
||||
byte[] head = new byte[4];
|
||||
|
||||
@@ -3,10 +3,6 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Where the simulator's eu07.ini lives: per user on each platform, with the
|
||||
/// installation's own copy as the template for a first run.
|
||||
/// </summary>
|
||||
public sealed class SettingsPaths
|
||||
{
|
||||
private const string ConfigFileName = "eu07.ini";
|
||||
@@ -21,7 +17,6 @@ public sealed class SettingsPaths
|
||||
_paths = paths;
|
||||
}
|
||||
|
||||
/// <summary>The user's own settings file, which is what the starter writes.</summary>
|
||||
public string UserConfigPath()
|
||||
{
|
||||
if (_environment.IsWindows)
|
||||
@@ -46,7 +41,6 @@ public sealed class SettingsPaths
|
||||
return Path.Combine(_environment.BaseDirectory, ConfigFileName);
|
||||
}
|
||||
|
||||
/// <summary>The ini shipped with the installation, read when the user has none.</summary>
|
||||
public string InstallationConfigPath() => _paths.FromRoot(ConfigFileName);
|
||||
|
||||
public string UserConfigDirectory() =>
|
||||
|
||||
@@ -8,26 +8,11 @@ using StarterNG.Domain.Settings;
|
||||
|
||||
namespace StarterNG.Infrastructure.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Maps <see cref="SimulatorSettings"/> onto the simulator's eu07.ini and back.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every key the starter understands is named exactly once, here. Reads clamp
|
||||
/// and default so a hand-edited ini cannot put the UI into an impossible state,
|
||||
/// and writes preserve the keys the starter does not manage - which is why a
|
||||
/// round trip through this class is worth testing on its own.
|
||||
/// </remarks>
|
||||
public sealed class SettingsSerializer
|
||||
{
|
||||
public void Read(SimulatorSettings s, ConfigFile c)
|
||||
{
|
||||
|
||||
s.LanguageWasSet = c.Has("lang");
|
||||
// Kept as the code the file holds. Startup hands it to the localisation
|
||||
// service, which resolves it to a display name and writes that back; the
|
||||
// starter must not decide here that an unrecognised code means English,
|
||||
// because the same key is what tells the simulator which language to run
|
||||
// in.
|
||||
s.LanguageCode = c.GetString("lang", "");
|
||||
s.Language = s.LanguageCode;
|
||||
s.Fullscreen = c.GetBool("fullscreen", false);
|
||||
@@ -167,11 +152,9 @@ public sealed class SettingsSerializer
|
||||
|
||||
public void Write(SimulatorSettings s, ConfigFile c)
|
||||
{
|
||||
|
||||
foreach (string key in ObsoleteKeys)
|
||||
c.Remove(key);
|
||||
|
||||
// Lower case, as the simulator expects and as the old starter wrote it.
|
||||
c.Set("lang", string.IsNullOrWhiteSpace(s.LanguageCode)
|
||||
? "en"
|
||||
: s.LanguageCode.Trim().ToLowerInvariant());
|
||||
|
||||
@@ -7,21 +7,13 @@ namespace StarterNG.Infrastructure;
|
||||
|
||||
public enum ShortcutScope
|
||||
{
|
||||
/// <summary>Works anywhere in the window.</summary>
|
||||
Global,
|
||||
|
||||
/// <summary>Only while the depot page is on screen.</summary>
|
||||
Depot,
|
||||
|
||||
/// <summary>Handled by the consist strip itself, once a vehicle card has focus.</summary>
|
||||
Consist
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One row of the shortcut table. <see cref="Key"/> is <see cref="Avalonia.Input.Key.None"/>
|
||||
/// for rows that only document a gesture handled elsewhere (the consist strip reads the
|
||||
/// arrow keys itself, they are never dispatched from the window).
|
||||
/// </summary>
|
||||
public sealed record Shortcut(
|
||||
string Id,
|
||||
string Display,
|
||||
@@ -36,12 +28,6 @@ public sealed record Shortcut(
|
||||
IsDispatched && Key == key && Modifiers == modifiers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The single source of truth for the starter's own shortcuts: the window dispatches from
|
||||
/// this table and the cheat sheet is printed from it, so the two cannot drift apart. These
|
||||
/// are deliberately hardcoded - the configurable key list in Settings belongs to the
|
||||
/// simulator's cab controls and mixing the two only confuses people.
|
||||
/// </summary>
|
||||
public static class Shortcuts
|
||||
{
|
||||
public const string Start = "start";
|
||||
|
||||
@@ -4,10 +4,6 @@ using System.Text;
|
||||
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Case- and diacritic-insensitive substring matching, so that typing
|
||||
/// "rozdzielczosc" in a search box still finds "Rozdzielczość".
|
||||
/// </summary>
|
||||
public static class TextMatch
|
||||
{
|
||||
public static bool Contains(string? haystack, string? needle)
|
||||
@@ -20,10 +16,6 @@ public static class TextMatch
|
||||
return Fold(haystack).Contains(Fold(needle), StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lower-cases and strips combining marks, so "Ż" and "z" compare equal.
|
||||
/// Polish "ł" has no decomposed form, so it is mapped by hand.
|
||||
/// </summary>
|
||||
public static string Fold(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
|
||||
@@ -11,24 +11,10 @@ using StarterNG.Infrastructure.Adapters;
|
||||
|
||||
namespace StarterNG.Infrastructure.Vehicles;
|
||||
|
||||
/// <summary>
|
||||
/// Reads vehicle physics from the .fiz files under dynamic/.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The format is a flat token stream of "section" headings and "key value"
|
||||
/// pairs, with an <c>include file p1 p2 end</c> directive whose parameters are
|
||||
/// substituted for <c>(1)</c>-style placeholders in the included file. Only the
|
||||
/// handful of keys the starter shows are decoded; everything else is skipped.
|
||||
///
|
||||
/// Both the name index and the parsed results are cached, because the depot asks
|
||||
/// for the same model repeatedly while the user scrolls.
|
||||
/// </remarks>
|
||||
public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
{
|
||||
/// <summary>Guard against an include cycle in hand written files.</summary>
|
||||
private const int MaxIncludeDepth = 6;
|
||||
|
||||
/// <summary>Sentinel meaning "the rear coupler was never declared".</summary>
|
||||
private const int UndeclaredCoupler = -1;
|
||||
|
||||
private static readonly HashSet<string> KnownKeys = new(StringComparer.OrdinalIgnoreCase)
|
||||
@@ -80,7 +66,6 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
{
|
||||
var index = Index();
|
||||
|
||||
// Unpowered variants are shipped as "<model>dumb.fiz".
|
||||
if (!index.TryGetValue(name, out string? path) &&
|
||||
!index.TryGetValue(name + "dumb", out path))
|
||||
return null;
|
||||
@@ -95,7 +80,6 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
_log.Log($"physics/{Path.GetFileName(path)}", ex);
|
||||
}
|
||||
|
||||
// A vehicle that only declares one coupler has the same at both ends.
|
||||
if (physics.AllowedFlagB == UndeclaredCoupler)
|
||||
{
|
||||
physics.AllowedFlagB = physics.AllowedFlagA;
|
||||
@@ -189,7 +173,6 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
}
|
||||
else
|
||||
{
|
||||
// Anything else at this level opens a section, e.g. "Param:" or "BuffCoupl1:".
|
||||
section = new string(bare.Where(char.IsLetterOrDigit).ToArray()).ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
@@ -228,10 +211,6 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
|
||||
private static bool Is(string key, string name) => key.Equals(name, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// A negative flag means the coupling is present but disabled; the simulator
|
||||
/// encodes that as its absolute value plus 128.
|
||||
/// </summary>
|
||||
private static int ParseFlag(string value, int fallback) =>
|
||||
int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int flag)
|
||||
? flag < 0 ? -flag + 128 : flag
|
||||
@@ -242,7 +221,6 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
? parsed
|
||||
: fallback;
|
||||
|
||||
/// <summary>Substitutes an include's "(n)" placeholder with its n-th parameter.</summary>
|
||||
private static string Resolve(string token, string[]? parameters)
|
||||
{
|
||||
if (parameters is null || token.Length < 3 || token[0] != '(' || token[^1] != ')')
|
||||
@@ -270,5 +248,4 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,14 +9,6 @@ using StarterNG.Infrastructure.Adapters;
|
||||
|
||||
namespace StarterNG.Infrastructure.Vehicles;
|
||||
|
||||
/// <summary>
|
||||
/// Reads data/load_weights.txt into a <see cref="LoadWeightsTable"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The file is a brace-delimited list of "name : weight" pairs with '#', ';' and
|
||||
/// '//' comments. It is read once and kept, since it does not change while the
|
||||
/// starter runs.
|
||||
/// </remarks>
|
||||
public sealed class LoadWeightsRepository
|
||||
{
|
||||
private const string FileName = "load_weights.txt";
|
||||
@@ -79,8 +71,6 @@ public sealed class LoadWeightsRepository
|
||||
body.Append(line).Append(' ');
|
||||
}
|
||||
|
||||
// Colons may be written tight against their neighbours, so space them out
|
||||
// before tokenising.
|
||||
string[] tokens = body.Replace(":", " : ").ToString()
|
||||
.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
@@ -100,5 +90,4 @@ public sealed class LoadWeightsRepository
|
||||
|
||||
return weights;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,17 +5,8 @@ using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Infrastructure.Vehicles;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IMiniTextureIndex"/> over the installation's textures/mini folder.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Replaces the static thumbnail dictionary that used to live on the vehicle
|
||||
/// database: an installation-scoped lookup with its own lifetime, which is what
|
||||
/// lets a test point the depot at thumbnails that only exist in memory.
|
||||
/// </remarks>
|
||||
public sealed class MiniTextureIndex : IMiniTextureIndex
|
||||
{
|
||||
/// <summary>Thumbnail shown when a vehicle names one we do not have.</summary>
|
||||
private const string FallbackName = "other";
|
||||
|
||||
private readonly IFileSystem _files;
|
||||
|
||||
@@ -5,14 +5,6 @@ using StarterNG.Domain.Vehicles;
|
||||
|
||||
namespace StarterNG.Infrastructure.Vehicles;
|
||||
|
||||
/// <summary>
|
||||
/// Reports liveries whose skin or model file is not actually present, for the
|
||||
/// optional "log missing vehicle files" diagnostic.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Both assets are looked up under several extensions because the simulator
|
||||
/// accepts a texture as .mat or .bmp and a model as .t3d or .e3d.
|
||||
/// </remarks>
|
||||
public sealed class MissingAssetScanner
|
||||
{
|
||||
private static readonly string[] TextureExtensions = { ".mat", ".bmp" };
|
||||
|
||||
@@ -4,30 +4,10 @@ using StarterNG.Domain.Vehicles;
|
||||
|
||||
namespace StarterNG.Infrastructure.Vehicles;
|
||||
|
||||
/// <summary>
|
||||
/// Reads one vehicle folder's textures.txt into a <see cref="VehicleEntry"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The format is line oriented and stateful: '$a' marks the rest of the file as
|
||||
/// archived, '!=' sets the category letter, and '^n' opens a fixed set of n
|
||||
/// vehicles. Everything else with an '=' is a livery. Unknown lines are skipped
|
||||
/// rather than rejected, because the files are hand written.
|
||||
///
|
||||
/// Pure text in, model out: the repository does the reading, so the format can
|
||||
/// be tested from a string array.
|
||||
/// </remarks>
|
||||
public sealed class TexturesTxtParser
|
||||
{
|
||||
/// <summary>Category letter meaning "derive it from the thumbnail name".</summary>
|
||||
private const string DeriveCategory = "*";
|
||||
|
||||
/// <summary>
|
||||
/// Parses the file's lines. Returns null when the folder declares no liveries.
|
||||
/// </summary>
|
||||
/// <param name="directory">
|
||||
/// The folder path relative to dynamic/, with a trailing slash; it forms the
|
||||
/// livery ids and is what the scenery format writes as the data folder.
|
||||
/// </param>
|
||||
public VehicleEntry? Parse(string directory, IReadOnlyList<string> lines)
|
||||
{
|
||||
var entry = new VehicleEntry { Uuid = "legacy:" + directory };
|
||||
@@ -120,8 +100,6 @@ public sealed class TexturesTxtParser
|
||||
if (skin.Length == 0)
|
||||
return null;
|
||||
|
||||
// Every "=" segment is "model, thumbnail[, per-texture thumbnail]"; the
|
||||
// first is the livery proper and the rest are alternative models.
|
||||
var specs = new List<(string Model, string Mini, string TextureMini)>();
|
||||
for (int i = 1; i < parts.Length; i++)
|
||||
{
|
||||
@@ -170,10 +148,6 @@ public sealed class TexturesTxtParser
|
||||
return texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The trailing comment is a fixed, comma separated credit line. Underscores
|
||||
/// stand in for spaces, a convention from the era the format comes from.
|
||||
/// </summary>
|
||||
private static VehicleMeta? ParseDescription(string description)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(description))
|
||||
|
||||
@@ -8,10 +8,6 @@ using StarterNG.Infrastructure.Adapters;
|
||||
|
||||
namespace StarterNG.Infrastructure.Vehicles;
|
||||
|
||||
/// <summary>
|
||||
/// Loads the catalogue from the dynamic/<maker>/<vehicle>/textures.txt
|
||||
/// files an installation ships.
|
||||
/// </summary>
|
||||
public sealed class TexturesTxtVehicleRepository : IVehicleRepository
|
||||
{
|
||||
private const string TexturesFileName = "textures.txt";
|
||||
@@ -55,8 +51,6 @@ public sealed class TexturesTxtVehicleRepository : IVehicleRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
// Read as text so the code page survives: the credit lines carry
|
||||
// Polish characters that ReadAllLines' default encoding would mangle.
|
||||
string[] lines = _files.ReadAllText(path, _encoding).Split('\n');
|
||||
return _parser.Parse(RelativeDirectory(path), lines);
|
||||
}
|
||||
@@ -67,10 +61,6 @@ public sealed class TexturesTxtVehicleRepository : IVehicleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rolling stock sits exactly two levels below dynamic/: a maker folder and a
|
||||
/// vehicle folder.
|
||||
/// </summary>
|
||||
private IEnumerable<string> TexturesFiles()
|
||||
{
|
||||
foreach (string maker in _files.GetDirectories(_paths.Dynamic))
|
||||
@@ -82,10 +72,6 @@ public sealed class TexturesTxtVehicleRepository : IVehicleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The folder as the scenery format spells it: relative to dynamic/, forward
|
||||
/// slashes, trailing slash.
|
||||
/// </summary>
|
||||
private string RelativeDirectory(string texturesPath)
|
||||
{
|
||||
string directory = Path.GetDirectoryName(texturesPath) ?? "";
|
||||
@@ -98,5 +84,4 @@ public sealed class TexturesTxtVehicleRepository : IVehicleRepository
|
||||
|
||||
return relative.Replace('\\', '/').TrimEnd('/') + "/";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user