Merge gear-lines (eureka/aetheria-release-gear-lines, a1e81613)
Code only. The branch's GameData/Aetheria.cc is not taken; the catalog is regenerated by replay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f123cdb735
5 changed files with 160 additions and 56 deletions
BIN
GameData/Aetheria.cc
(Stored with Git LFS)
BIN
GameData/Aetheria.cc
(Stored with Git LFS)
Binary file not shown.
|
|
@ -45,14 +45,42 @@ public sealed class ProductLinesCatalogTests
|
|||
Assert.Empty(shared);
|
||||
}
|
||||
|
||||
// Ruling gear-without-presence: a sold ship gear design with roles has two makers. The six reactor designs named here are
|
||||
// station gear or Faction Play's NiteLife-only quirk, and keep their one maker.
|
||||
private static readonly string[] OneMakerGear =
|
||||
{
|
||||
"Muon Fusion Reactor", "Muon Fusion Station Reactor", "Station Reactor", "Heavy Station Reactor",
|
||||
"High-Yield Station Reactor", "Ring Station Reactor",
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void EveryRoleBearingGearDesignWithAProductHasTwoMakers()
|
||||
{
|
||||
using var cache = RestoredHullsTests.OpenCatalog();
|
||||
var products = cache.GetAll<FactionProductData>().ToArray();
|
||||
var gear = cache.GetAll<GearData>().Where(d => d is not WeaponItemData && (d.Roles?.Count ?? 0) > 0).ToArray();
|
||||
Assert.All(OneMakerGear, name => Assert.Contains(gear, d => d.Name == name));
|
||||
var sold = 0;
|
||||
foreach (var design in gear.Where(d => !OneMakerGear.Contains(d.Name)))
|
||||
{
|
||||
var key = cache.RefOf(design).Key;
|
||||
var makers = products.Where(p => p.Design.Key.Equals(key)).Select(p => p.Manufacturer.Key).Distinct().Count();
|
||||
if (makers == 0) continue;
|
||||
sold++;
|
||||
Assert.True(makers >= 2, $"the gear design \"{design.Name}\" is sold by {makers} maker");
|
||||
}
|
||||
Assert.True(sold >= 20, "the gear designs with products should be many");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("weapons", 20)]
|
||||
[InlineData("gear", 22)]
|
||||
[InlineData("minor-powers", 10)]
|
||||
public void LineRowsAreShipped(string line, int rows)
|
||||
public void LineRowsAreShipped(string line, int count)
|
||||
{
|
||||
using var cache = RestoredHullsTests.OpenCatalog();
|
||||
var table = ProductLinesCommand.Table(line);
|
||||
Assert.Equal(rows, table.Count);
|
||||
Assert.Equal(count, table.Count);
|
||||
foreach (var row in table)
|
||||
{
|
||||
var product = Assert.Single(cache.GetAll<FactionProductData>(), p => p.Name == row.Name);
|
||||
|
|
@ -62,7 +90,7 @@ public sealed class ProductLinesCatalogTests
|
|||
Assert.Equal(row.Description, product.Description);
|
||||
var (mean, dev) = Program.MakerProfiles[row.Maker];
|
||||
Assert.Equal(
|
||||
design.Roles.Select(r => r.Name).OrderBy(n => n, StringComparer.Ordinal),
|
||||
(design.Roles ?? new()).Select(r => r.Name).OrderBy(n => n, StringComparer.Ordinal),
|
||||
product.Roles.Select(r => r.Role).OrderBy(n => n, StringComparer.Ordinal));
|
||||
foreach (var role in product.Roles)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,28 +6,32 @@ using GameCult.Caching;
|
|||
using GameCult.Caching.MessagePack;
|
||||
using Xunit;
|
||||
|
||||
// AetherDb's product-lines command (cut product-lines-weapons), run on a scratch copy of the shipped catalog with the weapon
|
||||
// line's twenty products removed from it. Apply must write what the shipped catalog holds, only its own records, finish a
|
||||
// catalog that holds part of the line, refuse a name that is another product's, and accept a maker that already sells the design.
|
||||
public sealed class ProductLinesCommandTests : IDisposable
|
||||
// AetherDb's product-lines command (cuts product-lines-weapons and gear-lines), run per line on a scratch copy of the shipped
|
||||
// catalog with that line's products removed from it. Apply must write what the shipped catalog holds, only its own records,
|
||||
// land on an older-schema catalog, and accept a maker that already sells the design. The weapon line adds the tests that
|
||||
// need weapon rows by name; the gear line adds the cargo-bay exemption from the no-roles refusal.
|
||||
public abstract class ProductLinesCommandTests : IDisposable
|
||||
{
|
||||
private static readonly string[] Names = ProductLinesCommand.Table("weapons").Select(r => r.Name).ToArray();
|
||||
private static readonly string[] Line = { "weapons" };
|
||||
private static readonly string[] LineApply = { "weapons", "apply" };
|
||||
protected readonly string[] Names;
|
||||
protected readonly string[] Line;
|
||||
protected readonly string[] LineApply;
|
||||
|
||||
private readonly string _root = Path.Combine(Path.GetTempPath(), "product-lines-command-" + Guid.NewGuid().ToString("N"));
|
||||
private string CatalogPath => Path.Combine(_root, "GameData", "Aetheria.cc");
|
||||
protected readonly string _root = Path.Combine(Path.GetTempPath(), "product-lines-command-" + Guid.NewGuid().ToString("N"));
|
||||
protected string CatalogPath => Path.Combine(_root, "GameData", "Aetheria.cc");
|
||||
|
||||
// The rows as the shipped catalog holds them, taken before they are removed from the scratch copy.
|
||||
private readonly string[] _shipped;
|
||||
protected readonly string[] _shipped;
|
||||
private readonly string[] _shippedKeys;
|
||||
|
||||
private static string Describe(CultCache cache, FactionProductData product) =>
|
||||
$"{cache.Get(product.Design).Name} | {product.Name} | {cache.Get(product.Manufacturer).ShortName} | {product.Description} | " +
|
||||
string.Join(",", product.Roles.OrderBy(r => r.Role, StringComparer.Ordinal).Select(r => $"{r.Role}:{r.Mean}:{r.StandardDeviation}"));
|
||||
|
||||
public ProductLinesCommandTests()
|
||||
protected ProductLinesCommandTests(string line)
|
||||
{
|
||||
Names = ProductLinesCommand.Table(line).Select(r => r.Name).ToArray();
|
||||
Line = new[] { line };
|
||||
LineApply = new[] { line, "apply" };
|
||||
Directory.CreateDirectory(Path.Combine(_root, "GameData"));
|
||||
Directory.CreateDirectory(Path.Combine(_root, "Assets", "Resources"));
|
||||
var shipped = AetherDb.FindRoot();
|
||||
|
|
@ -44,14 +48,14 @@ public sealed class ProductLinesCommandTests : IDisposable
|
|||
|
||||
public void Dispose() => Directory.Delete(_root, true);
|
||||
|
||||
private CultCache Open()
|
||||
protected CultCache Open()
|
||||
{
|
||||
var cache = new CultCache(TestCatalog.Registry());
|
||||
cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes);
|
||||
return cache;
|
||||
}
|
||||
|
||||
private string[] Line20()
|
||||
protected string[] Line20()
|
||||
{
|
||||
using var cache = Open();
|
||||
return cache.GetAll<FactionProductData>().Where(p => Names.Contains(p.Name)).Select(p => Describe(cache, p)).OrderBy(x => x, StringComparer.Ordinal).ToArray();
|
||||
|
|
@ -127,38 +131,6 @@ public sealed class ProductLinesCommandTests : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Apply_finishes_a_catalog_that_holds_part_of_the_line()
|
||||
{
|
||||
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
|
||||
using (var cache = Open())
|
||||
{
|
||||
foreach (var product in cache.GetAll<FactionProductData>().Where(p => p.Name == "Merlin" || p.Name == "Tripwire").ToArray())
|
||||
Assert.True(cache.Remove(cache.RefOf(product).Key));
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
Assert.Equal(Names.Length - 2, Line20().Length);
|
||||
|
||||
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
|
||||
Assert.Equal(_shipped, Line20());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Apply_refuses_a_row_name_that_is_another_products_and_writes_nothing()
|
||||
{
|
||||
using (var cache = Open())
|
||||
{
|
||||
var other = cache.GetAll<WeaponItemData>().First(w => w.Name == "Light Machine Gun");
|
||||
var maker = cache.GetAll<Faction>().First(f => f.ShortName == "Zhestokost");
|
||||
cache.Upsert(new FactionProductData { Name = "Sparrow", Design = new CultRecordRef<CraftedItemData>(cache.RefOf(other).Key), Manufacturer = cache.RefOf(maker) });
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
var conflicted = File.ReadAllBytes(CatalogPath);
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => ProductLinesCommand.Run(LineApply, _root));
|
||||
Assert.Equal(conflicted, File.ReadAllBytes(CatalogPath));
|
||||
}
|
||||
|
||||
// Ruling maker-design-tiers-allowed: a maker that already sells a design may sell another product of it.
|
||||
[Fact]
|
||||
public void Apply_accepts_a_maker_that_already_sells_the_design()
|
||||
|
|
@ -215,6 +187,46 @@ public sealed class ProductLinesCommandTests : IDisposable
|
|||
Assert.Equal(landed, File.ReadAllBytes(CatalogPath));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// One collection: the lines open the same catalog records through shared state and must not run side by side.
|
||||
[Collection("ProductLinesCommand")]
|
||||
public sealed class WeaponLineCommandTests : ProductLinesCommandTests
|
||||
{
|
||||
public WeaponLineCommandTests() : base("weapons") { }
|
||||
|
||||
[Fact]
|
||||
public void Apply_finishes_a_catalog_that_holds_part_of_the_line()
|
||||
{
|
||||
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
|
||||
using (var cache = Open())
|
||||
{
|
||||
foreach (var product in cache.GetAll<FactionProductData>().Where(p => p.Name == "Merlin" || p.Name == "Tripwire").ToArray())
|
||||
Assert.True(cache.Remove(cache.RefOf(product).Key));
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
Assert.Equal(Names.Length - 2, Line20().Length);
|
||||
|
||||
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
|
||||
Assert.Equal(_shipped, Line20());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Apply_refuses_a_row_name_that_is_another_products_and_writes_nothing()
|
||||
{
|
||||
using (var cache = Open())
|
||||
{
|
||||
var other = cache.GetAll<WeaponItemData>().First(w => w.Name == "Light Machine Gun");
|
||||
var maker = cache.GetAll<Faction>().First(f => f.ShortName == "Zhestokost");
|
||||
cache.Upsert(new FactionProductData { Name = "Sparrow", Design = new CultRecordRef<CraftedItemData>(cache.RefOf(other).Key), Manufacturer = cache.RefOf(maker) });
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
var conflicted = File.ReadAllBytes(CatalogPath);
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => ProductLinesCommand.Run(LineApply, _root));
|
||||
Assert.Equal(conflicted, File.ReadAllBytes(CatalogPath));
|
||||
}
|
||||
|
||||
private void AddProduct(string name, string design, string maker)
|
||||
{
|
||||
using var cache = Open();
|
||||
|
|
@ -260,3 +272,40 @@ public sealed class ProductLinesCommandTests : IDisposable
|
|||
Assert.Equal(1, Program.Main(new[] { "product-lines", "nonesuch" }));
|
||||
}
|
||||
}
|
||||
|
||||
[Collection("ProductLinesCommand")]
|
||||
public sealed class GearLineCommandTests : ProductLinesCommandTests
|
||||
{
|
||||
public GearLineCommandTests() : base("gear") { }
|
||||
|
||||
// Cargo bays carry no roles (ruling catalog-breadth-roles-and-components): their product lands with none. Any other design
|
||||
// with no roles is still refused, with nothing written.
|
||||
[Fact]
|
||||
public void Apply_accepts_a_roleless_cargo_bay_and_refuses_a_roleless_gear_design()
|
||||
{
|
||||
using (var cache = Open())
|
||||
{
|
||||
var radiator = cache.GetAll<GearData>().Single(g => g.Name == "Radiator");
|
||||
radiator.Behaviors.Clear(); // the store refuses a behavior that names a role the design lacks
|
||||
radiator.Roles.Clear();
|
||||
cache.Upsert(radiator);
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
var conflicted = File.ReadAllBytes(CatalogPath);
|
||||
Assert.Throws<InvalidOperationException>(() => ProductLinesCommand.Run(LineApply, _root));
|
||||
Assert.Equal(conflicted, File.ReadAllBytes(CatalogPath));
|
||||
|
||||
using (var cache = Open())
|
||||
{
|
||||
var radiator = cache.GetAll<GearData>().Single(g => g.Name == "Radiator");
|
||||
radiator.Roles.Add(new ItemRole { Name = "Cooling" });
|
||||
cache.Upsert(radiator);
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
Assert.Equal(0, ProductLinesCommand.Run(LineApply, _root));
|
||||
using var after = Open();
|
||||
var pithos = Assert.Single(after.GetAll<FactionProductData>(), p => p.Name == "Pithos");
|
||||
Assert.IsType<CargoBayData>(after.Get(pithos.Design));
|
||||
Assert.Empty(pithos.Roles);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using System.Security.Cryptography;
|
|||
using System.Text;
|
||||
using GameCult.Caching;
|
||||
|
||||
// product-lines <line> [apply] (aetheria-release, cut product-lines-weapons; rulings catalog-grows-generic-designs-branded-products,
|
||||
// product-lines <line> [apply] (aetheria-release, cuts product-lines-weapons and gear-lines; lines: weapons, gear; rulings catalog-grows-generic-designs-branded-products,
|
||||
// maker-design-tiers-allowed, miss-terris-belongs-to-emily-r3, pirates-record-content): authors the branded products of one
|
||||
// product line into GameData/Aetheria.cc. A line is a table of (design, product, maker, text); each row becomes one
|
||||
// FactionProductData with one ProductRole per role of its design, at the maker's profile in Program.MakerProfiles, so the table
|
||||
|
|
@ -59,8 +59,34 @@ public static class ProductLinesCommand
|
|||
new("Point Defense Gun", "Pattern 2", "Forge", "Close-in defence to an open standard. No license check, ever."),
|
||||
};
|
||||
|
||||
private static readonly Row[] Gear =
|
||||
{
|
||||
new("Adaptive Radiator", "Puffin", "Finch", "Fluffs up in the cold, slicks down in the heat. Mostly on cue."),
|
||||
new("Radiator", "Shade Sail", "Lightsail", "Keeps the hold cool on the long run, wherever the run goes."),
|
||||
new("Long Radiator", "Smokestack", "Zhestokost", "The heat goes up the stack. The column keeps marching."),
|
||||
new("Heat Pump", "ChillOut+-", "NiteLife", "Cool down between sets."),
|
||||
new("Cryogenic Heat Pump", "CryoVoid", "Adrasteia", "One half of the Santulanum Duality Thermal Dispersion System. The other half is sold separately."),
|
||||
new("Compact Reactor", "Hestia", "AU", "A small fire that keeps the whole house warm."),
|
||||
new("Compact Reactor", "Night Shift", "Lightsail", "Steady power for the hauls nobody else wants."),
|
||||
new("Heavy Reactor", "HR-9 Bulwark", "R&D", "Rated for continuous output under all certified conditions.*"),
|
||||
new("High-Yield Reactor", "PowerHour 2.0", "NiteLife", "Maximum output, for as long as it lasts."),
|
||||
new("Ring Reactor", "Milk Run", "Lightsail", "Regular, reliable, and on schedule every time."),
|
||||
new("High-Thrust Drive", "Battering Ram", "Zhestokost", "Straight ahead, through whatever is there. The brakes do, in fact, work."),
|
||||
new("Burn Drive", "Headliner", "Lucent", "Top of the bill and the brightest exhaust in the zone."),
|
||||
new("Rugged Drive", "Rough Road", "Lightsail", "Gets the freight through, whatever the road is made of."),
|
||||
new("Racing Drive", "Prokope", "Finch", "67% fatal and 100% fun."),
|
||||
new("Sensor Array", "Ranger", "AU", "Practically haunted by all the ghosts it picks up."),
|
||||
new("Capacitor", "Powder Keg", "Zhestokost", "A broadside's worth of charge, all of it at once."),
|
||||
new("Cargo Bay", "Pithos", "AU", "Holds everything. Do not open in transit."),
|
||||
new("Cargo Bay", "SafeStuff", "R&D", "Safe for valuables. Excludes pets, children, cupcakes and friendship."),
|
||||
new("Small Cargo Bay", "Amphora", "AU", "A jar for the long road."),
|
||||
new("Medium Drive", "Stagecoach", "AU", "Steady miles, every day of the week."),
|
||||
new("Large Drive", "Juggernaut", "Zhestokost", "Moves the column. Stopping it is someone else's problem."),
|
||||
new("Industrial Thermostatic Heater", "WarmUp+-", "NiteLife", "Room temperature, whatever the room."),
|
||||
};
|
||||
|
||||
// Every line the command knows, by the word that follows "product-lines".
|
||||
private static readonly Dictionary<string, Row[]> Lines = new() { ["weapons"] = Weapons, ["minor-powers"] = MinorPowers };
|
||||
private static readonly Dictionary<string, Row[]> Lines = new() { ["weapons"] = Weapons, ["minor-powers"] = MinorPowers, ["gear"] = Gear };
|
||||
|
||||
// A line's rows, for the catalog tests that check the shipped records against the table the command authors from.
|
||||
internal static IReadOnlyList<Row> Table(string line) => Lines[line];
|
||||
|
|
@ -95,7 +121,8 @@ public static class ProductLinesCommand
|
|||
var maker = factions.Where(f => f.ShortName == row.Maker).ToArray();
|
||||
if (maker.Length != 1) throw new InvalidOperationException($"Expected exactly one faction with short name \"{row.Maker}\", found {maker.Length}.");
|
||||
if (!Program.MakerProfiles.ContainsKey(row.Maker)) throw new InvalidOperationException($"No maker profile for \"{row.Maker}\".");
|
||||
if (design[0].Roles.Count == 0) throw new InvalidOperationException($"The design \"{row.Design}\" has no roles.");
|
||||
// A cargo bay carries no roles (ruling catalog-breadth-roles-and-components); its product carries none either.
|
||||
if (design[0] is not CargoBayData && (design[0].Roles?.Count ?? 0) == 0) throw new InvalidOperationException($"The design \"{row.Design}\" has no roles.");
|
||||
|
||||
var designKey = db.Cache.RefOf(design[0]).Key;
|
||||
var makerKey = db.Cache.RefOf(maker[0]).Key;
|
||||
|
|
@ -118,7 +145,7 @@ public static class ProductLinesCommand
|
|||
foreach (var (row, design, _, present) in resolved)
|
||||
{
|
||||
var (mean, dev) = Program.MakerProfiles[row.Maker];
|
||||
Console.WriteLine($" {(present ? "present" : "new ")} {row.Design} -> \"{row.Name}\" by {row.Maker}, mean {mean:0.##} dev {dev:0.##} on [{string.Join(", ", design.Roles.Select(r => r.Name))}]: {row.Description}");
|
||||
Console.WriteLine($" {(present ? "present" : "new ")} {row.Design} -> \"{row.Name}\" by {row.Maker}, mean {mean:0.##} dev {dev:0.##} on [{string.Join(", ", (design.Roles ?? new()).Select(r => r.Name))}]: {row.Description}");
|
||||
}
|
||||
|
||||
if (!apply)
|
||||
|
|
@ -143,7 +170,7 @@ public static class ProductLinesCommand
|
|||
Description = row.Description,
|
||||
Design = db.Cache.RefOf(design),
|
||||
Manufacturer = db.Cache.RefOf(maker),
|
||||
Roles = design.Roles.Select(r => new ProductRole { Role = r.Name, Mean = mean, StandardDeviation = dev }).ToList(),
|
||||
Roles = (design.Roles ?? new()).Select(r => new ProductRole { Role = r.Name, Mean = mean, StandardDeviation = dev }).ToList(),
|
||||
}, KeyOf(row));
|
||||
}
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public static class Program
|
|||
case "minor-power-factions": return MinorPowerFactionsCommand.Run(args.Skip(1).ToArray());
|
||||
case "doctrine-catalog": return DoctrineCatalog.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out);
|
||||
default:
|
||||
Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], save, settings, settings-dump, dangling [clear <Type.Member>]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], range-falloff [apply] [--effective <fraction>] [--end <multiplier>], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, field-kinds [apply], mine-launcher [apply], smoke-hull [apply], smoke-rounds [apply], roles-backfill [apply], pd-gear [apply], consumables-first-set [apply], launch-suppressor [apply], pirates-faction [apply], verse-grammar [apply], generic-designs [apply], sensor-stat-set [apply], inspection-scanner [apply], minor-power-factions [apply], product-lines weapons|minor-powers [apply], doctrine-catalog [apply]");
|
||||
Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], save, settings, settings-dump, dangling [clear <Type.Member>]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], range-falloff [apply] [--effective <fraction>] [--end <multiplier>], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, field-kinds [apply], mine-launcher [apply], smoke-hull [apply], smoke-rounds [apply], roles-backfill [apply], pd-gear [apply], consumables-first-set [apply], launch-suppressor [apply], pirates-faction [apply], verse-grammar [apply], generic-designs [apply], sensor-stat-set [apply], inspection-scanner [apply], minor-power-factions [apply], product-lines weapons|minor-powers|gear [apply], doctrine-catalog [apply]");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue