mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 06:55:59 +01:00
Split Settings into model, serializer, paths and store
698 lines did all of it at once. The mutable CaptureFromUi callback becomes an ISettingsCapture the settings view implements.
This commit is contained in:
@@ -52,4 +52,14 @@ public sealed class PhysicalFileSystem : IFileSystem
|
||||
Directory.Exists(path) ? Directory.GetDirectories(path) : Array.Empty<string>();
|
||||
|
||||
public DateTime GetLastWriteTimeUtc(string path) => File.GetLastWriteTimeUtc(path);
|
||||
|
||||
public bool IsExecutable(string path)
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
return true;
|
||||
|
||||
const UnixFileMode anyExecute =
|
||||
UnixFileMode.UserExecute | UnixFileMode.GroupExecute | UnixFileMode.OtherExecute;
|
||||
return (File.GetUnixFileMode(path) & anyExecute) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
18
StarterNG/Infrastructure/Adapters/SystemEnvironment.cs
Normal file
18
StarterNG/Infrastructure/Adapters/SystemEnvironment.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
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();
|
||||
|
||||
public bool IsLinux => OperatingSystem.IsLinux();
|
||||
|
||||
public bool IsMacOS => OperatingSystem.IsMacOS();
|
||||
|
||||
public string? GetVariable(string name) => Environment.GetEnvironmentVariable(name);
|
||||
|
||||
public string BaseDirectory => AppContext.BaseDirectory;
|
||||
}
|
||||
@@ -72,6 +72,7 @@ public static class Diagnostics
|
||||
AppServices.Current.Files,
|
||||
AppServices.Current.Localization,
|
||||
AppServices.Current.Physics,
|
||||
AppServices.Current.Library)
|
||||
AppServices.Current.Library,
|
||||
AppServices.Current.SettingsStore)
|
||||
.Run();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using StarterNG.Application.Abstractions;
|
||||
using StarterNG.Classes;
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Domain.Settings;
|
||||
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
@@ -23,15 +24,17 @@ public sealed class InstallationCheck
|
||||
private readonly ILocalizedStrings _strings;
|
||||
private readonly IPhysicsRepository _physics;
|
||||
private readonly GameLibrary _library;
|
||||
private readonly SettingsStore _settings;
|
||||
|
||||
public InstallationCheck(IGamePaths paths, IFileSystem files, ILocalizedStrings strings,
|
||||
IPhysicsRepository physics, GameLibrary library)
|
||||
IPhysicsRepository physics, GameLibrary library, SettingsStore settings)
|
||||
{
|
||||
_paths = paths;
|
||||
_files = files;
|
||||
_strings = strings;
|
||||
_physics = physics;
|
||||
_library = library;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public List<string> Run()
|
||||
@@ -54,7 +57,8 @@ public sealed class InstallationCheck
|
||||
if (_physics.IndexedCount == 0)
|
||||
faults.Add(_strings["FaultNoPhysics"]);
|
||||
|
||||
if (Settings.Instance.ResolveExecutable(out var problem) is var _ && problem == ExeProblem.NotFound)
|
||||
_settings.ResolveExecutable(out var problem);
|
||||
if (problem == ExeProblem.NotFound)
|
||||
faults.Add(_strings["FaultNoExe"]);
|
||||
|
||||
return faults;
|
||||
|
||||
166
StarterNG/Infrastructure/Settings/ExecutableLocator.cs
Normal file
166
StarterNG/Infrastructure/Settings/ExecutableLocator.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using StarterNG.Application.Abstractions;
|
||||
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"
|
||||
};
|
||||
|
||||
private readonly IFileSystem _files;
|
||||
private readonly IGamePaths _paths;
|
||||
private readonly IEnvironment _environment;
|
||||
private readonly IDiagnosticsLog _log;
|
||||
|
||||
public ExecutableLocator(IFileSystem files, IGamePaths paths, IEnvironment environment, IDiagnosticsLog log)
|
||||
{
|
||||
_files = files;
|
||||
_paths = paths;
|
||||
_environment = environment;
|
||||
_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))
|
||||
{
|
||||
problem = Validate(FullPath(settings.ExecutablePath));
|
||||
return settings.ExecutablePath;
|
||||
}
|
||||
|
||||
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,
|
||||
StringComparison.OrdinalIgnoreCase) ? 0 : 1)
|
||||
.ThenBy(path => Path.GetFileName(path).Length);
|
||||
|
||||
foreach (string path in candidates)
|
||||
{
|
||||
if (Validate(path) == ExeProblem.None)
|
||||
{
|
||||
problem = ExeProblem.None;
|
||||
return path;
|
||||
}
|
||||
fallback ??= path;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Log("looking for the simulator executable", ex);
|
||||
}
|
||||
|
||||
if (fallback is not null)
|
||||
{
|
||||
problem = Validate(fallback);
|
||||
return fallback;
|
||||
}
|
||||
|
||||
problem = ExeProblem.NotFound;
|
||||
return CanonicalName;
|
||||
}
|
||||
|
||||
/// <summary>Executables the user can pick from, most recently built first.</summary>
|
||||
public List<string> ListCandidates(string? directory = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _files.GetFiles(directory ?? _paths.Root, "eu07*")
|
||||
.Where(IsCandidate)
|
||||
.OrderByDescending(_files.GetLastWriteTimeUtc)
|
||||
.Select(Path.GetFileName)
|
||||
.ToList()!;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
public ExeProblem Validate(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_files.FileExists(path))
|
||||
return ExeProblem.NotFound;
|
||||
|
||||
if (!_environment.IsWindows && !_files.IsExecutable(path))
|
||||
return ExeProblem.NotExecutable;
|
||||
|
||||
return MatchesPlatform(path) ? ExeProblem.None : ExeProblem.WrongPlatform;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return ExeProblem.NotFound;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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];
|
||||
using var stream = _files.OpenRead(path);
|
||||
if (stream.Read(head, 0, 4) != 4)
|
||||
return true;
|
||||
|
||||
bool portableExecutable = head[0] == 0x4D && head[1] == 0x5A;
|
||||
bool elf = head[0] == 0x7F && head[1] == 0x45 && head[2] == 0x4C && head[3] == 0x46;
|
||||
|
||||
if (_environment.IsWindows && elf)
|
||||
return false;
|
||||
if (_environment.IsLinux && portableExecutable)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsCandidate(string path)
|
||||
{
|
||||
string extension = Path.GetExtension(path).ToLowerInvariant();
|
||||
|
||||
if (NeverExecutable.Contains(extension))
|
||||
return false;
|
||||
|
||||
if (_environment.IsWindows)
|
||||
return extension == ".exe";
|
||||
|
||||
if (_environment.IsLinux)
|
||||
return extension.Length == 0 || extension is ".x86_64" or ".run" or ".appimage";
|
||||
|
||||
return extension.Length == 0 || extension is ".exe" or ".x86_64" or ".run" or ".appimage";
|
||||
}
|
||||
|
||||
private string FullPath(string path) =>
|
||||
Path.IsPathRooted(path) ? path : Path.Combine(_paths.Root, path);
|
||||
}
|
||||
54
StarterNG/Infrastructure/Settings/SettingsPaths.cs
Normal file
54
StarterNG/Infrastructure/Settings/SettingsPaths.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.IO;
|
||||
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";
|
||||
private const string VendorFolder = "MaSzyna";
|
||||
|
||||
private readonly IEnvironment _environment;
|
||||
private readonly IGamePaths _paths;
|
||||
|
||||
public SettingsPaths(IEnvironment environment, IGamePaths paths)
|
||||
{
|
||||
_environment = environment;
|
||||
_paths = paths;
|
||||
}
|
||||
|
||||
/// <summary>The user's own settings file, which is what the starter writes.</summary>
|
||||
public string UserConfigPath()
|
||||
{
|
||||
if (_environment.IsWindows)
|
||||
{
|
||||
string? appData = _environment.GetVariable("APPDATA");
|
||||
if (!string.IsNullOrEmpty(appData))
|
||||
return Path.Combine(appData, VendorFolder, ConfigFileName);
|
||||
}
|
||||
else if (_environment.IsMacOS)
|
||||
{
|
||||
string? home = _environment.GetVariable("HOME");
|
||||
if (!string.IsNullOrEmpty(home))
|
||||
return Path.Combine(home, "Library", "Application Support", VendorFolder, ConfigFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? home = _environment.GetVariable("HOME");
|
||||
if (!string.IsNullOrEmpty(home))
|
||||
return Path.Combine(home, ".config", VendorFolder, ConfigFileName);
|
||||
}
|
||||
|
||||
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() =>
|
||||
Path.GetDirectoryName(UserConfigPath()) ?? _environment.BaseDirectory;
|
||||
}
|
||||
310
StarterNG/Infrastructure/Settings/SettingsSerializer.cs
Normal file
310
StarterNG/Infrastructure/Settings/SettingsSerializer.cs
Normal file
@@ -0,0 +1,310 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using StarterNG.Classes;
|
||||
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");
|
||||
s.Language = c.GetString("lang", "en").ToLowerInvariant() == "pl" ? "Polski" : "English";
|
||||
s.Fullscreen = c.GetBool("fullscreen", false);
|
||||
s.PauseWhenInactive = c.GetBool("inactivepause", true);
|
||||
s.PauseOnStart = c.GetBool("pause", false);
|
||||
|
||||
var mouse = c.GetTokens("mousescale");
|
||||
if (mouse.Length >= 1 && double.TryParse(mouse[0], NumberStyles.Float, CultureInfo.InvariantCulture, out double mx))
|
||||
{
|
||||
s.InvertMouseHorizontal = mx < 0;
|
||||
s.CursorSensitivity = Clamp((int)Math.Round(Math.Abs(mx)), 1, 5);
|
||||
}
|
||||
if (mouse.Length >= 2 && double.TryParse(mouse[1], NumberStyles.Float, CultureInfo.InvariantCulture, out double my))
|
||||
{
|
||||
s.InvertMouseVertical = my < 0;
|
||||
s.MouseScaleYMagnitude = Math.Abs(my);
|
||||
}
|
||||
|
||||
s.IgnoreGamepad = !c.GetBool("input.gamepad", true);
|
||||
s.FeedbackMode = Clamp(c.GetInt("feedbackmode", 1), 0, 5);
|
||||
s.FeedbackPort = c.GetInt("feedbackport", 888);
|
||||
s.UartEnabled = c.Has("uart");
|
||||
s.UartPort = c.GetString("uart", "");
|
||||
s.UartTune = c.GetString("uarttune", "");
|
||||
s.UartDebug = c.GetBool("uartdebug", false);
|
||||
if (c.Has("uartfeature"))
|
||||
{
|
||||
var uartTokens = (c.GetRaw("uartfeature") ?? "").Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
var uf = new HashSet<string>(uartTokens, StringComparer.OrdinalIgnoreCase);
|
||||
s.UartMain = uf.Contains("main"); s.UartScnd = uf.Contains("scnd"); s.UartTrain = uf.Contains("train");
|
||||
s.UartLocal = uf.Contains("local"); s.UartRadioVolume = uf.Contains("radiovolume"); s.UartRadioChannel = uf.Contains("radiochannel");
|
||||
}
|
||||
else
|
||||
{
|
||||
s.UartMain = s.UartScnd = s.UartTrain = s.UartLocal = true;
|
||||
s.UartRadioVolume = s.UartRadioChannel = false;
|
||||
}
|
||||
|
||||
s.SelectExeAutomatically = c.GetBool("starter.exe.auto", true);
|
||||
s.ExecutablePath = c.GetString("starter.exe.path", "eu07.exe");
|
||||
s.DebugMode = c.GetBool("debugmode", false);
|
||||
s.VirtualShunting = c.GetBool("ai.trainman", true);
|
||||
s.LogMissingVehicleFiles = c.GetBool("starter.logmissingvehicles", false);
|
||||
|
||||
s.RenderEngine = IndexOf(SimulatorSettings.RenderEngines, c.GetString("gfxrenderer", "full"), 0);
|
||||
s.Width = c.GetInt("width", 1280);
|
||||
s.Height = c.GetInt("height", 720);
|
||||
s.BufferScalePercent = Clamp(c.GetInt("starter.bufferscale", 100), 50, 200);
|
||||
s.MaxTextureSize = c.GetInt("maxtexturesize", 4096);
|
||||
s.MaxCabTextureSize = c.GetInt("maxcabtexturesize", 4096);
|
||||
s.TextureFiltering = c.GetInt("anisotropicfiltering", 8);
|
||||
s.Multisampling = Clamp(c.GetInt("multisampling", 2), 0, 3);
|
||||
s.DynamicLights = Clamp(c.GetInt("dynamiclights", 7), 0, 7);
|
||||
s.DrawRangeFactor = c.GetDouble("gfx.drawrange.factor.max", 3.0);
|
||||
s.VSync = c.GetBool("vsync", false);
|
||||
s.Smoke = c.GetBool("gfx.smoke", true);
|
||||
s.SmokeFidelity = Clamp(c.GetInt("gfx.smoke.fidelity", 1), 1, 4);
|
||||
s.ChromaticAberration = c.GetBool("gfx.postfx.chromaticaberration.enabled", true);
|
||||
s.MotionBlur = c.GetBool("gfx.postfx.motionblur.enabled", true);
|
||||
s.ExtraEffects = c.GetBool("gfx.extraeffects", true);
|
||||
s.EnvMap = c.GetBool("gfx.envmap.enabled", true);
|
||||
s.UseVbo = c.GetBool("usevbo", true);
|
||||
s.RenderShadows = c.GetBool("shadows", true);
|
||||
s.ReflectionsFramerate = c.GetInt("gfx.reflections.framerate", 60);
|
||||
|
||||
var shadowTune = c.GetTokens("shadowtune");
|
||||
if (shadowTune.Length >= 1) s.ShadowMapResolution = ParseInt(shadowTune[0], 2048);
|
||||
if (shadowTune.Length >= 2) s.ShadowProjectionRange = ParseInt(shadowTune[1], 250);
|
||||
if (shadowTune.Length >= 4) s.ShadowTuneExtra = new[] { shadowTune[2], shadowTune[3] };
|
||||
|
||||
s.CabShadowsRange = (int)Math.Round(c.GetDouble("gfx.shadows.cab.range", 0));
|
||||
s.ShadowRankCutoff = c.GetInt("gfx.shadow.rank.cutoff", 3);
|
||||
s.ReflectionsFidelity = Clamp(c.GetInt("gfx.reflections.fidelity", 0), 0, 2);
|
||||
s.FieldOfView = Clamp((int)Math.Round(c.GetDouble("fieldofview", 45)), 15, 75);
|
||||
s.PythonScreens = c.GetBool("python.enabled", true);
|
||||
s.PythonThreadedUpload = c.GetBool("python.threadedupload", true);
|
||||
s.FpsLimitEnabled = c.Has("fpslimit");
|
||||
s.FpsLimit = Clamp(c.GetInt("fpslimit", 30), 1, 100);
|
||||
s.ShadowAngleLimit = c.GetDouble("gfx.shadow.angle.min", 0.2);
|
||||
s.FullscreenWindowed = c.GetBool("fullscreenwindowed", false);
|
||||
s.RenderAngleVulkan = string.Equals(c.GetString("gfx.angleplatform", ""), "vulkan", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
s.SplineFidelity = Clamp(c.GetInt("splinefidelity", 1), 1, 4);
|
||||
s.FullPhysics = c.GetBool("fullphysics", true);
|
||||
s.EnableTraction = c.GetBool("enabletraction", true);
|
||||
s.LiveTraction = c.GetBool("livetraction", true);
|
||||
s.PhysicsLog = c.GetBool("physicslog", false);
|
||||
int debugLog = c.GetInt("debuglog", 3);
|
||||
s.DebugLog = (debugLog & 1) != 0;
|
||||
s.DebugLogVisible = (debugLog & 2) != 0;
|
||||
s.DebugLogExtraBits = debugLog & ~3;
|
||||
s.MultipleLogs = c.GetBool("multiplelogs", false);
|
||||
s.DisplaySimulation = !c.GetBool("gfx.skiprendering", false);
|
||||
s.CrashDamage = c.GetBool("crashdamage", true);
|
||||
s.Friction = c.GetDouble("friction", 1.0);
|
||||
s.BrakeStep = c.GetDouble("brakestep", 1.0);
|
||||
s.BrakeSpeed = c.GetDouble("brakespeed", 3.0);
|
||||
|
||||
s.SoundEnabled = c.GetBool("soundenabled", true);
|
||||
s.Volume = Clamp((int)Math.Round(c.GetDouble("sound.volume", 1.0) * 50), 1, 100);
|
||||
s.RadioVolume = Clamp((int)Math.Round(c.GetDouble("sound.volume.radio", 0.75) * 100), 1, 100);
|
||||
s.VehiclesVolume = Clamp((int)Math.Round(c.GetDouble("sound.volume.vehicle", 1.0) * 100), 1, 100);
|
||||
s.PositionalVolume = Clamp((int)Math.Round(c.GetDouble("sound.volume.positional", 1.0) * 100), 1, 100);
|
||||
s.AmbientVolume = Clamp((int)Math.Round(c.GetDouble("sound.volume.ambient", 1.0) * 100), 1, 100);
|
||||
s.SkipPipeline = c.GetBool("gfx.skippipeline", false);
|
||||
s.PythonScreenUpdateRate = c.Has("python.updatetime")
|
||||
? Clamp(c.GetInt("python.updatetime", 200), 0, 10000)
|
||||
: MapOldPyScreenPriority(c.GetString("pyscreenrendererpriority", "normal"));
|
||||
|
||||
s.CompressTextures = c.GetBool("compresstex", true);
|
||||
s.ScaleSpeculars = c.GetBool("scalespeculars", true);
|
||||
s.UseGLES = c.GetBool("gfx.usegles", false);
|
||||
s.ShaderGamma = c.GetBool("gfx.shadergamma", false);
|
||||
s.ScreenMipmaps = c.GetBool("python.mipmaps", true);
|
||||
s.ExtendedModelConversion = c.GetInt("convertmodels", 0) != 0;
|
||||
s.GfxResourceMove = c.GetBool("gfx.resource.move", false);
|
||||
s.GfxResourceSweep = c.GetBool("gfx.resource.sweep", true);
|
||||
s.TrainPhysicsThreads = Clamp(c.GetInt("async.trainThreads", 0), 0, Environment.ProcessorCount);
|
||||
s.IgnoreIrrelevantTrains = c.GetBool("starter.ignoreirrelevant", false);
|
||||
|
||||
s.AutoCloseStarter = c.GetBool("starter.autoclose", false);
|
||||
s.LargeThumbnails = c.GetBool("starter.largethumbnails", false);
|
||||
s.AutoExpandSceneryTree = c.GetBool("starter.expandtree", false);
|
||||
s.BatteryDefault = (BatteryDefault)Clamp(c.GetInt("starter.batterydefault", 0), 0, 2);
|
||||
s.ShowAiVehicles = c.GetBool("starter.show.ai", true);
|
||||
s.DrivableOnly = c.GetBool("starter.drivableonly", true);
|
||||
s.ShowArchivalSceneries = c.GetBool("starter.show.archival", true);
|
||||
s.HideArchivalVehicles = c.GetBool("starter.hide.archivalvehicles", true);
|
||||
s.LastScenery = c.GetString("starter.last.scenery", "");
|
||||
s.WindowMaximized = c.GetBool("starter.window.maximized", false);
|
||||
}
|
||||
|
||||
private static readonly string[] ObsoleteKeys =
|
||||
{
|
||||
"gfx.postfx.tonemapping",
|
||||
};
|
||||
|
||||
public void Write(SimulatorSettings s, ConfigFile c)
|
||||
{
|
||||
|
||||
foreach (string key in ObsoleteKeys)
|
||||
c.Remove(key);
|
||||
|
||||
c.Set("lang", s.Language == "Polski" ? "pl" : "en");
|
||||
c.SetBool("fullscreen", s.Fullscreen);
|
||||
c.SetBool("inactivepause", s.PauseWhenInactive);
|
||||
c.SetBool("pause", s.PauseOnStart);
|
||||
|
||||
double mx = s.CursorSensitivity * (s.InvertMouseHorizontal ? -1 : 1);
|
||||
double my = s.MouseScaleYMagnitude * (s.InvertMouseVertical ? -1 : 1);
|
||||
c.Set("mousescale",
|
||||
$"{mx.ToString("0.###", CultureInfo.InvariantCulture)} " +
|
||||
$"{my.ToString("0.###", CultureInfo.InvariantCulture)}");
|
||||
|
||||
c.SetBool("input.gamepad", !s.IgnoreGamepad);
|
||||
c.SetInt("feedbackmode", s.FeedbackMode);
|
||||
c.SetInt("feedbackport", s.FeedbackPort);
|
||||
if (s.UartEnabled && !string.IsNullOrWhiteSpace(s.UartPort)) c.Set("uart", s.UartPort); else c.Remove("uart");
|
||||
c.Set("uarttune", s.UartTune);
|
||||
c.SetBool("uartdebug", s.UartDebug);
|
||||
var sb = new StringBuilder();
|
||||
if (s.UartMain) sb.Append("main|");
|
||||
if (s.UartScnd) sb.Append("scnd|");
|
||||
if (s.UartTrain) sb.Append("train|");
|
||||
if (s.UartLocal) sb.Append("local|");
|
||||
if (s.UartRadioVolume) sb.Append("radiovolume|");
|
||||
if (s.UartRadioChannel) sb.Append("radiochannel|");
|
||||
c.Set("uartfeature", sb.ToString());
|
||||
|
||||
c.SetBool("starter.exe.auto", s.SelectExeAutomatically);
|
||||
c.Set("starter.exe.path", s.ExecutablePath);
|
||||
c.SetBool("debugmode", s.DebugMode);
|
||||
c.SetBool("ai.trainman", s.VirtualShunting);
|
||||
c.SetBool("starter.logmissingvehicles", s.LogMissingVehicleFiles);
|
||||
|
||||
c.Set("gfxrenderer", SimulatorSettings.RenderEngines[Clamp(s.RenderEngine, 0, SimulatorSettings.RenderEngines.Length - 1)]);
|
||||
c.SetInt("width", s.Width);
|
||||
c.SetInt("height", s.Height);
|
||||
c.SetInt("starter.bufferscale", s.BufferScalePercent);
|
||||
int fbw = (int)Math.Round(s.Width * s.BufferScalePercent / 100.0);
|
||||
int fbh = (int)Math.Round(s.Height * s.BufferScalePercent / 100.0);
|
||||
c.SetInt("gfx.framebuffer.width", fbw);
|
||||
c.SetInt("gfx.framebuffer.height", fbh);
|
||||
c.SetInt("maxtexturesize", s.MaxTextureSize);
|
||||
c.SetInt("maxcabtexturesize", s.MaxCabTextureSize);
|
||||
c.SetInt("anisotropicfiltering", s.TextureFiltering);
|
||||
c.SetInt("multisampling", s.Multisampling);
|
||||
c.SetInt("dynamiclights", s.DynamicLights);
|
||||
c.SetDouble("gfx.drawrange.factor.max", s.DrawRangeFactor);
|
||||
c.SetBool("vsync", s.VSync);
|
||||
c.SetBool("gfx.smoke", s.Smoke);
|
||||
c.SetInt("gfx.smoke.fidelity", s.SmokeFidelity);
|
||||
c.SetBool("gfx.postfx.chromaticaberration.enabled", s.ChromaticAberration);
|
||||
c.SetBool("gfx.postfx.motionblur.enabled", s.MotionBlur);
|
||||
c.SetBool("gfx.extraeffects", s.ExtraEffects);
|
||||
c.SetBool("gfx.envmap.enabled", s.EnvMap);
|
||||
c.SetBool("usevbo", s.UseVbo);
|
||||
c.SetBool("shadows", s.RenderShadows);
|
||||
c.SetBool("gfx.shadowmap.enabled", s.RenderShadows);
|
||||
c.SetInt("gfx.reflections.framerate", s.ReflectionsFramerate);
|
||||
c.Set("shadowtune",
|
||||
$"{s.ShadowMapResolution} {s.ShadowProjectionRange} " +
|
||||
$"{s.ShadowTuneExtra[0]} {s.ShadowTuneExtra[1]}");
|
||||
c.SetInt("gfx.shadows.cab.range", s.CabShadowsRange);
|
||||
c.SetInt("gfx.shadow.rank.cutoff", s.ShadowRankCutoff);
|
||||
c.SetInt("gfx.reflections.fidelity", s.ReflectionsFidelity);
|
||||
c.SetInt("fieldofview", s.FieldOfView);
|
||||
c.SetBool("python.enabled", s.PythonScreens);
|
||||
c.SetBool("python.threadedupload", s.PythonThreadedUpload);
|
||||
if (s.FpsLimitEnabled) c.SetInt("fpslimit", s.FpsLimit); else c.Remove("fpslimit");
|
||||
c.SetDouble("gfx.shadow.angle.min", s.ShadowAngleLimit);
|
||||
c.SetBool("fullscreenwindowed", s.FullscreenWindowed);
|
||||
if (s.RenderAngleVulkan) c.Set("gfx.angleplatform", "vulkan"); else c.Remove("gfx.angleplatform");
|
||||
|
||||
c.SetInt("splinefidelity", s.SplineFidelity);
|
||||
c.SetBool("fullphysics", s.FullPhysics);
|
||||
c.SetBool("enabletraction", s.EnableTraction);
|
||||
c.SetBool("livetraction", s.LiveTraction);
|
||||
c.SetBool("physicslog", s.PhysicsLog);
|
||||
c.SetInt("debuglog",
|
||||
(s.DebugLog ? 1 : 0) | (s.DebugLogVisible ? 2 : 0) | s.DebugLogExtraBits);
|
||||
c.SetBool("multiplelogs", s.MultipleLogs);
|
||||
c.SetBool("gfx.skiprendering", !s.DisplaySimulation);
|
||||
c.SetBool("crashdamage", s.CrashDamage);
|
||||
c.SetDouble("friction", s.Friction);
|
||||
c.SetDouble("brakestep", s.BrakeStep);
|
||||
c.SetDouble("brakespeed", s.BrakeSpeed);
|
||||
|
||||
c.SetBool("soundenabled", s.SoundEnabled);
|
||||
c.SetDouble("sound.volume", s.Volume / 50.0);
|
||||
c.SetDouble("sound.volume.radio", s.RadioVolume / 100.0);
|
||||
c.SetDouble("sound.volume.vehicle", s.VehiclesVolume / 100.0);
|
||||
c.SetDouble("sound.volume.positional", s.PositionalVolume / 100.0);
|
||||
c.SetDouble("sound.volume.ambient", s.AmbientVolume / 100.0);
|
||||
c.SetBool("gfx.skippipeline", s.SkipPipeline);
|
||||
c.SetInt("python.updatetime", s.PythonScreenUpdateRate);
|
||||
|
||||
c.SetBool("compresstex", s.CompressTextures);
|
||||
c.SetBool("scalespeculars", s.ScaleSpeculars);
|
||||
c.SetBool("gfx.usegles", s.UseGLES);
|
||||
c.SetBool("gfx.shadergamma", s.ShaderGamma);
|
||||
c.SetBool("python.mipmaps", s.ScreenMipmaps);
|
||||
c.Set("convertmodels", s.ExtendedModelConversion ? "143" : "0");
|
||||
c.SetBool("gfx.resource.move", s.GfxResourceMove);
|
||||
c.SetBool("gfx.resource.sweep", s.GfxResourceSweep);
|
||||
c.SetInt("async.trainThreads", s.TrainPhysicsThreads);
|
||||
c.SetBool("starter.ignoreirrelevant", s.IgnoreIrrelevantTrains);
|
||||
|
||||
c.SetBool("starter.autoclose", s.AutoCloseStarter);
|
||||
c.SetBool("starter.largethumbnails", s.LargeThumbnails);
|
||||
c.SetBool("starter.expandtree", s.AutoExpandSceneryTree);
|
||||
c.SetInt("starter.batterydefault", (int)s.BatteryDefault);
|
||||
c.SetBool("starter.show.ai", s.ShowAiVehicles);
|
||||
c.SetBool("starter.drivableonly", s.DrivableOnly);
|
||||
c.SetBool("starter.show.archival", s.ShowArchivalSceneries);
|
||||
c.SetBool("starter.hide.archivalvehicles", s.HideArchivalVehicles);
|
||||
if (!string.IsNullOrWhiteSpace(s.LastScenery))
|
||||
c.Set("starter.last.scenery", s.LastScenery);
|
||||
else
|
||||
c.Remove("starter.last.scenery");
|
||||
c.SetBool("starter.window.maximized", s.WindowMaximized);
|
||||
}
|
||||
|
||||
private static int Clamp(int v, int lo, int hi) => v < lo ? lo : (v > hi ? hi : v);
|
||||
|
||||
private static int ParseInt(string s, int fallback) =>
|
||||
int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out int n) ? n : fallback;
|
||||
|
||||
private static int IndexOf(string[] values, string token, int fallback)
|
||||
{
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
if (string.Equals(values[i], token, StringComparison.OrdinalIgnoreCase))
|
||||
return i;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
private static int MapOldPyScreenPriority(string priority) =>
|
||||
priority.ToLowerInvariant() switch
|
||||
{
|
||||
"lower" => 400,
|
||||
"lowest" => 800,
|
||||
"idle" => 1600,
|
||||
"off" => 0,
|
||||
_ => 200
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user