diff --git a/StarterNG.Tests/MiniTextureIndexTests.cs b/StarterNG.Tests/MiniTextureIndexTests.cs
index 294c292..9133c66 100644
--- a/StarterNG.Tests/MiniTextureIndexTests.cs
+++ b/StarterNG.Tests/MiniTextureIndexTests.cs
@@ -6,83 +6,50 @@ namespace StarterNG.Tests;
public class MiniTextureIndexTests
{
- private static readonly string[] Names =
- {
- "ep07", "et22", "111a", "112a", "203v", "401k", "en57", "sm42", "st44", "412w",
- "406r", "424z", "621z", "z1kd", "gags", "eaos", "falns", "uacs", "sgs", "kbs"
- };
-
- private static MiniTextureIndex Build(int? missRate)
+ private static MiniTextureIndex Build(params string[] thumbnails)
{
var files = new InMemoryFileSystem();
- foreach (string name in Names)
+ foreach (string name in thumbnails)
files.WithFile(TestInstallation.At("textures", "mini", name + ".bmp"), "bitmap");
- files.WithFile(TestInstallation.At("textures", "mini", "other.bmp"), "bitmap");
- var environment = new FakeEnvironment();
- if (missRate is { } rate)
- environment.With(MiniTextureIndex.MissRateVariable, rate.ToString());
-
- return new MiniTextureIndex(files, new GamePaths(TestInstallation.Root), environment);
+ return new MiniTextureIndex(files, new GamePaths(TestInstallation.Root));
}
[Fact]
- public void Setting_the_variable_to_zero_shows_the_installation_as_it_is()
+ public void A_thumbnail_is_found_by_name_whatever_its_case()
{
- var index = Build(missRate: 0);
+ var index = Build("ep07", "other");
- Assert.Equal(0, index.SimulatedMissRate);
- Assert.All(Names, name => Assert.True(index.Has(name)));
+ Assert.True(index.Has("EP07"));
+ Assert.EndsWith("ep07.bmp", index.PathFor("ep07"));
}
[Fact]
- public void The_temporary_default_still_hides_half_the_thumbnails()
+ public void A_vehicle_naming_an_unknown_thumbnail_gets_other_bmp()
{
- // Guards the testing default in MiniTextureIndex.DefaultMissRate. When
- // that goes back to 0 for release, this test is what says so - change it
- // together with the constant, do not delete it quietly.
- var index = Build(missRate: null);
-
- Assert.Equal(50, index.SimulatedMissRate);
- Assert.Contains(Names, name => !index.Has(name));
- }
-
- [Fact]
- public void The_debug_variable_hides_roughly_the_share_it_names()
- {
- var index = Build(missRate: 50);
-
- int hidden = Names.Count(name => !index.Has(name));
-
- // Twenty names is a small sample, so this only asserts that the switch
- // bites and does not take everything with it.
- Assert.InRange(hidden, 3, Names.Length - 3);
- }
-
- [Fact]
- public void A_hidden_thumbnail_stays_hidden_rather_than_flickering()
- {
- var index = Build(missRate: 50);
- string hidden = Names.First(name => !index.Has(name));
-
- for (int i = 0; i < 20; i++)
- Assert.False(index.Has(hidden));
- }
-
- [Fact]
- public void A_hidden_thumbnail_falls_back_to_other_bmp_like_an_unknown_one()
- {
- var index = Build(missRate: 50);
- string hidden = Names.First(name => !index.Has(name));
-
- Assert.EndsWith("other.bmp", index.PathFor(hidden));
- }
-
- [Fact]
- public void An_unknown_name_still_falls_back_to_other_bmp_in_a_normal_run()
- {
- var index = Build(missRate: 0);
+ var index = Build("ep07", "other");
+ Assert.False(index.Has("nie-ma-takiej"));
Assert.EndsWith("other.bmp", index.PathFor("nie-ma-takiej"));
}
+
+ [Fact]
+ public void Without_other_bmp_there_is_nothing_to_fall_back_to()
+ {
+ var index = Build("ep07");
+
+ // The views draw their own stand-in wagon from here on; see
+ // MiniTextures.MissingVisual.
+ Assert.Null(index.PathFor("nie-ma-takiej"));
+ Assert.Null(index.FallbackPath);
+ }
+
+ [Fact]
+ public void An_installation_with_no_thumbnails_at_all_resolves_nothing()
+ {
+ var index = Build();
+
+ Assert.False(index.Has("ep07"));
+ Assert.Null(index.PathFor("ep07"));
+ }
}
diff --git a/StarterNG/Application/AppServices.cs b/StarterNG/Application/AppServices.cs
index dd65ffb..d12d0f9 100644
--- a/StarterNG/Application/AppServices.cs
+++ b/StarterNG/Application/AppServices.cs
@@ -43,19 +43,13 @@ public sealed class AppServices
Localization = new LocalizationService(log);
Sceneries = new SceneryRepository(files, paths, log, new SceneryParser(clock, Random));
SceneryImages = new SceneryImageLocator(files);
- MiniTextures = new MiniTextureIndex(files, paths, environment);
+ MiniTextures = new MiniTextureIndex(files, paths);
Vehicles = new TexturesTxtVehicleRepository(files, paths, log, new TexturesTxtParser());
Physics = new FizPhysicsRepository(files, paths, log);
MissingAssets = new MissingAssetScanner(files, paths);
SceneryTexts = new SceneryTranslations(files, log);
Timetables = new TimetableLocator(files);
LoadWeights = new LoadWeightsRepository(files, paths, log);
- // Leaves a trail when the thumbnail debug switch is on, so a run with
- // missing minis is never mistaken for a broken installation.
- if (MiniTextures is MiniTextureIndex { SimulatedMissRate: > 0 } debugMinis)
- log.Log($"{MiniTextureIndex.MissRateVariable}={debugMinis.SimulatedMissRate}: " +
- "ukrywam ten procent miniatur pojazdow");
-
Library = new GameLibrary(Vehicles, Sceneries, MiniTextures, Physics, log);
State = new AppState();
diff --git a/StarterNG/Infrastructure/Vehicles/MiniTextureIndex.cs b/StarterNG/Infrastructure/Vehicles/MiniTextureIndex.cs
index 0e91337..8871522 100644
--- a/StarterNG/Infrastructure/Vehicles/MiniTextureIndex.cs
+++ b/StarterNG/Infrastructure/Vehicles/MiniTextureIndex.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.IO;
using StarterNG.Application.Abstractions;
@@ -19,55 +18,26 @@ public sealed class MiniTextureIndex : IMiniTextureIndex
/// Thumbnail shown when a vehicle names one we do not have.
private const string FallbackName = "other";
- ///
- /// Set to 0-100 to override : the percentage of
- /// thumbnails that behave as if the installation did not have their file, so
- /// the vehicle falls back to other.bmp exactly as one naming an unknown
- /// thumbnail would. Set it to 0 to see the installation as it really is.
- ///
- public const string MissRateVariable = "STARTER_DEBUG_MISSING_MINI";
-
- ///
- /// TEMPORARY, FOR TESTING THE MISSING-THUMBNAIL DRAWING. Half the vehicles in
- /// every consist will show the other.bmp stand-in instead of their own
- /// picture, whether or not the installation is complete.
- ///
- /// Set this back to 0 before release - it is the whole of the switch, and
- /// MiniTextureIndexTests.The_temporary_default_still_hides_half_the_thumbnails
- /// fails the moment it changes, so nothing ships it by accident.
- ///
- private const int DefaultMissRate = 50;
-
private readonly IFileSystem _files;
private readonly IGamePaths _paths;
- private readonly int _missRate;
private readonly object _gate = new();
private Dictionary? _index;
- public MiniTextureIndex(IFileSystem files, IGamePaths paths, IEnvironment? environment = null)
+ public MiniTextureIndex(IFileSystem files, IGamePaths paths)
{
_files = files;
_paths = paths;
- _missRate = ReadMissRate(environment);
}
- ///
- /// Percentage of thumbnails currently being hidden on purpose; 0 in a normal
- /// run.
- ///
- public int SimulatedMissRate => _missRate;
-
public void Preload() => Index();
public bool Has(string? miniName) =>
- !string.IsNullOrEmpty(miniName) &&
- !IsSimulatedMiss(miniName) &&
- Index().ContainsKey(miniName.ToLowerInvariant());
+ !string.IsNullOrEmpty(miniName) && Index().ContainsKey(miniName.ToLowerInvariant());
public string? PathFor(string? miniName)
{
- if (!IsSimulatedMiss(miniName) && !string.IsNullOrEmpty(miniName) &&
+ if (!string.IsNullOrEmpty(miniName) &&
Index().TryGetValue(miniName.ToLowerInvariant(), out string? path))
return path;
@@ -77,35 +47,6 @@ public sealed class MiniTextureIndex : IMiniTextureIndex
public string? FallbackPath =>
Index().TryGetValue(FallbackName, out string? path) ? path : null;
- ///
- /// 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.
- ///
- private bool IsSimulatedMiss(string? miniName) =>
- _missRate > 0 && !string.IsNullOrEmpty(miniName) && Bucket(miniName) < _missRate;
-
- /// FNV-1a over the lower-cased name, folded into 0-99.
- 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)
- : DefaultMissRate;
- }
-
private Dictionary Index()
{
lock (_gate)