mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-18 14:35:59 +01:00
fix: follow .fiz includes and check vehicle files whatever their case
An include in a .fiz is looked up in the vehicle's folder through CaseInsensitivePaths, so its physics are read on Linux when the include names the file in other letter case. The missing-asset scan finds skins and models the same way, with extensions in any case, instead of reporting files that are there.
This commit is contained in:
@@ -65,6 +65,19 @@ public class PhysicsAndAssetsTests
|
||||
Assert.Equal(125, physics.VMax);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_include_named_in_other_case_is_followed()
|
||||
{
|
||||
var installation = new TestInstallation(new InMemoryFileSystem(caseSensitive: true)
|
||||
.WithFile(Fiz("pkp", "ep07", "ep07"), "include Common.FIZ 84000 end")
|
||||
.WithFile(TestInstallation.At("dynamic", "pkp", "ep07", "common.fiz"), "Param: M=(1) Vmax=125"));
|
||||
|
||||
var physics = installation.Physics.For("pkp/ep07/", "ep07")!;
|
||||
|
||||
Assert.Equal(84000, physics.Mass);
|
||||
Assert.Equal(125, physics.VMax);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_dot_in_the_model_name_is_part_of_the_name()
|
||||
{
|
||||
@@ -202,4 +215,31 @@ public class PhysicsAndAssetsTests
|
||||
|
||||
Assert.Empty(installation.MissingAssets.Scan(installation.Library.Vehicles));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_livery_with_no_folder_is_looked_for_in_dynamic_itself()
|
||||
{
|
||||
var installation = new TestInstallation(new InMemoryFileSystem(caseSensitive: true)
|
||||
.WithFile(TestInstallation.At("dynamic", "EP09.bmp"), "bitmap")
|
||||
.WithFile(TestInstallation.At("dynamic", "ep09.e3d"), "model"));
|
||||
var catalog = new StarterNG.Domain.Vehicles.VehicleCatalog(installation.MiniTextures);
|
||||
catalog.Textures.Add(new StarterNG.Domain.Vehicles.VehicleTexture { Directory = "", Skinfile = "ep09", Model = "EP09" });
|
||||
|
||||
Assert.Empty(installation.MissingAssets.Scan(catalog));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_skin_and_model_on_disk_in_other_case_are_not_reported()
|
||||
{
|
||||
var files = new InMemoryFileSystem(caseSensitive: true)
|
||||
.WithFile(TestInstallation.At("dynamic", "PKP", "EP09", "textures.txt"),
|
||||
"EP09-014.mat=ep09.e3d,ep09")
|
||||
.WithFile(TestInstallation.At("dynamic", "PKP", "EP09", "ep09-014.BMP"), "bitmap")
|
||||
.WithFile(TestInstallation.At("dynamic", "PKP", "EP09", "EP09.E3D"), "model");
|
||||
var installation = new TestInstallation(files);
|
||||
installation.Vehicles.Load(installation.Library.Vehicles);
|
||||
Assert.NotEmpty(installation.Library.Vehicles.Textures);
|
||||
|
||||
Assert.Empty(installation.MissingAssets.Scan(installation.Library.Vehicles));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
};
|
||||
|
||||
private readonly IFileSystem _files;
|
||||
private readonly CaseInsensitivePaths _names;
|
||||
private readonly IGamePaths _paths;
|
||||
private readonly IDiagnosticsLog _log;
|
||||
|
||||
@@ -38,6 +39,7 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
public FizPhysicsRepository(IFileSystem files, IGamePaths paths, IDiagnosticsLog log)
|
||||
{
|
||||
_files = files;
|
||||
_names = new CaseInsensitivePaths(files);
|
||||
_paths = paths;
|
||||
_log = log;
|
||||
}
|
||||
@@ -165,8 +167,9 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
||||
while (i < tokens.Count && !tokens[i].Equals("end", StringComparison.OrdinalIgnoreCase))
|
||||
includeParameters.Add(Resolve(tokens[i++], parameters));
|
||||
|
||||
Parse(physics, Path.Combine(directory, includeFile), directory, includeParameters.ToArray(),
|
||||
depth + 1);
|
||||
// Named in the letter case of whoever wrote the include, not always that of the file.
|
||||
string included = _names.Find(directory, includeFile) ?? Path.Combine(directory, includeFile);
|
||||
Parse(physics, included, directory, includeParameters.ToArray(), depth + 1);
|
||||
pendingKey = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -10,44 +10,53 @@ public sealed class MissingAssetScanner
|
||||
private static readonly string[] TextureExtensions = { ".mat", ".bmp" };
|
||||
private static readonly string[] ModelExtensions = { ".t3d", ".e3d" };
|
||||
|
||||
private readonly IFileSystem _files;
|
||||
private readonly IGamePaths _paths;
|
||||
private readonly CaseInsensitivePaths _names;
|
||||
|
||||
public MissingAssetScanner(IFileSystem files, IGamePaths paths)
|
||||
{
|
||||
_files = files;
|
||||
_paths = paths;
|
||||
_names = new CaseInsensitivePaths(files, keepListings: true);
|
||||
}
|
||||
|
||||
public List<string> Scan(VehicleCatalog catalog)
|
||||
{
|
||||
var lines = new List<string>();
|
||||
|
||||
foreach (var texture in catalog.Textures)
|
||||
try
|
||||
{
|
||||
string directory = Path.Combine(
|
||||
_paths.Dynamic,
|
||||
texture.Directory.Replace('/', Path.DirectorySeparatorChar).TrimEnd('\\', '/'));
|
||||
foreach (var texture in catalog.Textures)
|
||||
{
|
||||
string directory = texture.Directory.Replace('\\', '/').TrimEnd('/');
|
||||
|
||||
if (!string.IsNullOrEmpty(texture.Skinfile) &&
|
||||
!ExistsWithAnyExtension(Path.Combine(directory, texture.Skinfile), TextureExtensions))
|
||||
lines.Add($"# no file: {texture.Directory}{texture.Skinfile}");
|
||||
if (!string.IsNullOrEmpty(texture.Skinfile) &&
|
||||
!ExistsWithAnyExtension(Under(directory, texture.Skinfile), TextureExtensions))
|
||||
lines.Add($"# no file: {texture.Directory}{texture.Skinfile}");
|
||||
|
||||
if (!string.IsNullOrEmpty(texture.Model) &&
|
||||
!ExistsWithAnyExtension(Path.Combine(directory, texture.Model), ModelExtensions))
|
||||
lines.Add($"# no model: {texture.Directory}{texture.Model}");
|
||||
if (!string.IsNullOrEmpty(texture.Model) &&
|
||||
!ExistsWithAnyExtension(Under(directory, texture.Model), ModelExtensions))
|
||||
lines.Add($"# no model: {texture.Directory}{texture.Model}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// The folders are listed once for the whole catalog, and not kept past it.
|
||||
_names.Forget();
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
private bool ExistsWithAnyExtension(string path, string[] extensions)
|
||||
private static string Under(string directory, string name) =>
|
||||
directory.Length == 0 ? name : directory + "/" + name;
|
||||
|
||||
/// <summary>Whether the file is under dynamic as named, or with one of the extensions, in any letter case.</summary>
|
||||
private bool ExistsWithAnyExtension(string name, string[] extensions)
|
||||
{
|
||||
if (_files.FileExists(path))
|
||||
if (_names.Resolve(_paths.Dynamic, name) is not null)
|
||||
return true;
|
||||
|
||||
foreach (string extension in extensions)
|
||||
if (_files.FileExists(Path.ChangeExtension(path, extension)))
|
||||
if (_names.Resolve(_paths.Dynamic, Path.ChangeExtension(name, extension)) is not null)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user