Draw a stand-in for a missing thumbnail, pass the language code to eu07.ini

The file was getting "pl" or "en" whatever the user picked, so a simulator with
its own language file started in English.
This commit is contained in:
maj00r
2026-09-04 21:53:29 +02:00
parent 8e87eb8638
commit 27f0e97b43
11 changed files with 283 additions and 48 deletions

View File

@@ -23,7 +23,13 @@ public sealed class SettingsSerializer
{
s.LanguageWasSet = c.Has("lang");
s.Language = c.GetString("lang", "en").ToLowerInvariant() == "pl" ? "Polski" : "English";
// 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);
s.PauseWhenInactive = c.GetBool("inactivepause", true);
s.PauseOnStart = c.GetBool("pause", false);
@@ -165,7 +171,7 @@ public sealed class SettingsSerializer
foreach (string key in ObsoleteKeys)
c.Remove(key);
c.Set("lang", s.Language == "Polski" ? "pl" : "en");
c.Set("lang", string.IsNullOrWhiteSpace(s.LanguageCode) ? "en" : s.LanguageCode);
c.SetBool("fullscreen", s.Fullscreen);
c.SetBool("inactivepause", s.PauseWhenInactive);
c.SetBool("pause", s.PauseOnStart);

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using StarterNG.Application.Abstractions;
@@ -18,26 +19,45 @@ public sealed class MiniTextureIndex : IMiniTextureIndex
/// <summary>Thumbnail shown when a vehicle names one we do not have.</summary>
private const string FallbackName = "other";
/// <summary>
/// Set to 1-100 to make that percentage of thumbnails behave as if the
/// installation did not have their file - the vehicle then falls back to
/// other.bmp exactly as one naming an unknown thumbnail would. For checking
/// how a consist looks when some of its stock has no picture of its own.
/// Off unless the variable is set.
/// </summary>
public const string MissRateVariable = "STARTER_DEBUG_MISSING_MINI";
private readonly IFileSystem _files;
private readonly IGamePaths _paths;
private readonly int _missRate;
private readonly object _gate = new();
private Dictionary<string, string>? _index;
public MiniTextureIndex(IFileSystem files, IGamePaths paths)
public MiniTextureIndex(IFileSystem files, IGamePaths paths, IEnvironment? environment = null)
{
_files = files;
_paths = paths;
_missRate = ReadMissRate(environment);
}
/// <summary>
/// Percentage of thumbnails currently being hidden on purpose; 0 in a normal
/// run.
/// </summary>
public int SimulatedMissRate => _missRate;
public void Preload() => Index();
public bool Has(string? miniName) =>
!string.IsNullOrEmpty(miniName) && Index().ContainsKey(miniName.ToLowerInvariant());
!string.IsNullOrEmpty(miniName) &&
!IsSimulatedMiss(miniName) &&
Index().ContainsKey(miniName.ToLowerInvariant());
public string? PathFor(string? miniName)
{
if (!string.IsNullOrEmpty(miniName) &&
if (!IsSimulatedMiss(miniName) && !string.IsNullOrEmpty(miniName) &&
Index().TryGetValue(miniName.ToLowerInvariant(), out string? path))
return path;
@@ -47,6 +67,35 @@ public sealed class MiniTextureIndex : IMiniTextureIndex
public string? FallbackPath =>
Index().TryGetValue(FallbackName, out string? path) ? path : null;
/// <summary>
/// Whether this name is one of the thumbnails the debug switch is hiding.
/// Decided from the name itself rather than a random draw, so a vehicle keeps
/// the same answer every time the strip is rebuilt and can actually be looked
/// at.
/// </summary>
private bool IsSimulatedMiss(string? miniName) =>
_missRate > 0 && !string.IsNullOrEmpty(miniName) && Bucket(miniName) < _missRate;
/// <summary>FNV-1a over the lower-cased name, folded into 0-99.</summary>
private static int Bucket(string name)
{
uint hash = 2166136261;
foreach (char c in name.ToLowerInvariant())
{
hash ^= c;
hash *= 16777619;
}
return (int)(hash % 100);
}
private static int ReadMissRate(IEnvironment? environment)
{
string? raw = environment?.GetVariable(MissRateVariable);
return int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out int rate)
? Math.Clamp(rate, 0, 100)
: 0;
}
private Dictionary<string, string> Index()
{
lock (_gate)