hardpoint-fit counts what the game boots: AetherDb.Open(withMods), one UnfillableHardpoints census
The census read only Aetheria.cc and missed package hulls (the Nakovalnya's shield mount). It now opens the catalog ResolveCatalog composes at boot, read-only and refusing excluded packages, and the count comes from Program.UnfillableHardpoints, the function the test will call. The stale 'exactly as many cells' comment is gone: fit is loose. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
795d3d9356
commit
178db6be32
3 changed files with 85 additions and 20 deletions
18
tests/Aetheria.Shared.Tests/HardpointFitTests.cs
Normal file
18
tests/Aetheria.Shared.Tests/HardpointFitTests.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
// The hardpoint census (campaign aetheria-release, cut hardpoint-fit-1): every hardpoint on every hull the game boots takes a
|
||||
// design some product sells. Program.UnfillableHardpoints is the one census, over HardpointData.Takes, the one fit rule.
|
||||
public sealed class HardpointFitTests
|
||||
{
|
||||
// The census is over the catalog the game boots, packages included: a package hull's mount is as fillable as a shipped one.
|
||||
[Fact]
|
||||
public void TheCensusReadsThePackagesTheGameBoots()
|
||||
{
|
||||
var root = RunStartTests.FindRepoRoot();
|
||||
using (var db = AetherDb.Open(root: root, withMods: true))
|
||||
Assert.Contains(db.Cache.GetAll<HullData>(), hull => hull.Name == "Nakovalnya");
|
||||
Assert.Throws<ArgumentException>(() => AetherDb.Open(catalogWritable: true, root: root, withMods: true));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
|
||||
// Opens GameData/Aetheria.cc through AetheriaStores, the game's own store composition. The catalog attaches read-only
|
||||
|
|
@ -10,22 +11,52 @@ public sealed class AetherDb : IDisposable
|
|||
public string Root { get; }
|
||||
public CultCache Cache { get; }
|
||||
|
||||
public void Dispose() => Cache.Dispose();
|
||||
// The compose directory withMods made, owned by this instance: the derived catalog is read from it until Dispose.
|
||||
private readonly string _composed;
|
||||
|
||||
private AetherDb(string root, bool catalogWritable, bool withRun, Action<string> warn)
|
||||
public void Dispose()
|
||||
{
|
||||
Cache.Dispose();
|
||||
if (_composed != null) try { Directory.Delete(_composed, true); } catch (IOException) { }
|
||||
}
|
||||
|
||||
private AetherDb(string root, bool catalogWritable, bool withRun, bool withMods, Action<string> warn)
|
||||
{
|
||||
Root = root;
|
||||
var gameData = Path.Combine(root, "GameData");
|
||||
Cache = AetheriaStores.Open(
|
||||
Path.Combine(gameData, "Aetheria.cc"),
|
||||
runPath: withRun ? Path.Combine(gameData, "run.cc") : null,
|
||||
catalogWritable: catalogWritable,
|
||||
kindlessStation: warn ?? Console.Error.WriteLine);
|
||||
var catalog = Path.Combine(gameData, "Aetheria.cc");
|
||||
if (withMods)
|
||||
{
|
||||
// The catalog the game boots: ShipModCatalog.ResolveCatalog over GameData/Mods. It is derived and read-only, so a write
|
||||
// through it would land in a temp file, never in Aetheria.cc; the one writable open stays the shipped file alone.
|
||||
if (catalogWritable) throw new ArgumentException("A catalog composed with packages is read-only; a write opens the shipped file alone.", nameof(withMods));
|
||||
_composed = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "aetherdb-mods-" + Guid.NewGuid().ToString("N"))).FullName;
|
||||
try
|
||||
{
|
||||
var (resolved, excluded) = ShipModCatalog.ResolveCatalog(catalog, Path.Combine(_composed, "derived.cc"), Path.Combine(gameData, "Mods"));
|
||||
// The game skips a broken package so a player still boots; a census of the shipped game does not.
|
||||
if (excluded.Length > 0)
|
||||
throw new InvalidOperationException("First-party packages were excluded from the catalog: " +
|
||||
string.Join("; ", excluded.Select(entry => entry.Package + ": " + entry.Reason)));
|
||||
catalog = resolved;
|
||||
}
|
||||
catch { try { Directory.Delete(_composed, true); } catch (IOException) { } throw; }
|
||||
}
|
||||
try
|
||||
{
|
||||
Cache = AetheriaStores.Open(
|
||||
catalog,
|
||||
runPath: withRun ? Path.Combine(gameData, "run.cc") : null,
|
||||
catalogWritable: catalogWritable,
|
||||
kindlessStation: warn ?? Console.Error.WriteLine);
|
||||
}
|
||||
catch { if (_composed != null) try { Directory.Delete(_composed, true); } catch (IOException) { } throw; }
|
||||
}
|
||||
|
||||
// With no root given, walks up from the working directory to the game folder: the first folder whose GameData holds Aetheria.cc
|
||||
public static AetherDb Open(bool catalogWritable = false, bool withRun = false, string root = null, Action<string> warn = null) =>
|
||||
new AetherDb(root ?? FindRoot(), catalogWritable, withRun, warn);
|
||||
// withMods composes the packages in GameData/Mods as the game boots them, read-only (see the constructor).
|
||||
public static AetherDb Open(bool catalogWritable = false, bool withRun = false, string root = null, Action<string> warn = null, bool withMods = false) =>
|
||||
new AetherDb(root ?? FindRoot(), catalogWritable, withRun, withMods, warn);
|
||||
|
||||
public static string FindRoot()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -526,24 +526,23 @@ public static class Program
|
|||
return failures;
|
||||
}
|
||||
|
||||
// Every hardpoint on every hull, and which designs can fill it: LoadoutGenerator requires a matching
|
||||
// HardpointType, a shape that fits the hardpoint, and exactly as many cells as the hardpoint has. A
|
||||
// hardpoint no product can fill is gear the game cannot place.
|
||||
// Every hardpoint on every hull the game boots (the shipped catalog with GameData/Mods composed in), and which designs
|
||||
// can fill it. Fit is loose (HardpointData.Takes: a design of the mount's type whose shape lies within the mount's cells,
|
||||
// at its rotation), so a smaller design serves a larger mount. A hardpoint no product sells a design for is gear the game
|
||||
// cannot place; the count is UnfillableHardpoints', and so is the exit code.
|
||||
private static int HardpointFit()
|
||||
{
|
||||
var db = AetherDb.Open();
|
||||
var gear = db.Cache.GetAll<GearData>().ToArray();
|
||||
using var db = AetherDb.Open(withMods: true);
|
||||
var designs = db.Cache.GetAll<EquippableItemData>().ToArray();
|
||||
var sold = SoldDesigns(db.Cache.GetAll<FactionProductData>());
|
||||
var unfillable = 0;
|
||||
foreach (var hull in db.Cache.GetAll<HullData>().OrderBy(h => h.HullType).ThenBy(h => h.Name))
|
||||
foreach (var hull in db.Cache.GetAll<HullData>().OrderBy(h => h.HullType).ThenBy(h => h.Name, StringComparer.Ordinal))
|
||||
{
|
||||
Console.WriteLine($"\n{hull.Name} ({hull.HullType}):");
|
||||
foreach (var hardpoint in hull.Hardpoints.OrderByDescending(h => h.Shape.Coordinates.Length))
|
||||
{
|
||||
var cells = hardpoint.Shape.Coordinates.Length;
|
||||
var matches = gear.Where(hardpoint.Takes).ToArray();
|
||||
var matches = designs.Where(hardpoint.Takes).ToArray();
|
||||
var soldMatches = matches.Where(m => sold.Contains(db.Cache.RefOf(m).Key)).ToArray();
|
||||
if (soldMatches.Length == 0) unfillable++;
|
||||
Console.WriteLine($" {hardpoint.Type,-14} {cells,2} cells: {matches.Length} designs match, {soldMatches.Length} sold" +
|
||||
(matches.Length == 0 ? " <- no design of that size" : soldMatches.Length == 0 ? " <- designs exist but no product sells them" : ""));
|
||||
foreach (var match in matches)
|
||||
|
|
@ -551,8 +550,25 @@ public static class Program
|
|||
(sold.Contains(db.Cache.RefOf(match).Key) ? "" : " (unsold)"));
|
||||
}
|
||||
}
|
||||
Console.WriteLine($"\n{unfillable} hardpoints no product can fill");
|
||||
return unfillable;
|
||||
var unfillable = UnfillableHardpoints(db.Cache);
|
||||
foreach (var line in unfillable) Console.WriteLine($"unfillable: {line}");
|
||||
Console.WriteLine($"\n{unfillable.Count} hardpoints no product can fill");
|
||||
return unfillable.Count;
|
||||
}
|
||||
|
||||
// One line per hull hardpoint no design a product sells Takes, by hull type, then name, then position: the census the
|
||||
// hardpoint-fit command prints and HardpointFitTests pins, over whatever catalog it is given.
|
||||
public static IReadOnlyList<string> UnfillableHardpoints(CultCache cache)
|
||||
{
|
||||
var sold = SoldDesigns(cache.GetAll<FactionProductData>());
|
||||
var offered = cache.GetAll<EquippableItemData>().Where(design => sold.Contains(cache.RefOf(design).Key)).ToArray();
|
||||
return cache.GetAll<HullData>()
|
||||
.OrderBy(h => h.HullType).ThenBy(h => h.Name, StringComparer.Ordinal)
|
||||
.SelectMany(hull => hull.Hardpoints
|
||||
.Where(hardpoint => !offered.Any(hardpoint.Takes))
|
||||
.OrderBy(hardpoint => hardpoint.Position.x).ThenBy(hardpoint => hardpoint.Position.y)
|
||||
.Select(hardpoint => $"{hull.Name} ({hull.HullType}) {hardpoint.Type} {hardpoint.Shape.Width}x{hardpoint.Shape.Height} at ({hardpoint.Position.x},{hardpoint.Position.y})"))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
// The parsed shape of the settings asset, for checking where sequence items actually landed.
|
||||
|
|
|
|||
Loading…
Reference in a new issue