ship-authoring boss on|off sets HullData.Boss on a package hull
Judged before the file is touched, touches no product; inspect prints ", boss" when set. Tests: the command, and the package path through compose. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1b5e989182
commit
6b602dd34a
2 changed files with 67 additions and 2 deletions
|
|
@ -99,6 +99,25 @@ public sealed class ShipProductTests : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
// The package path of the derivation: the flag survives compose on the hull, and the maker is the package's product's.
|
||||
[Fact]
|
||||
public void ABossPackageIsItsMakersBossAfterCompose()
|
||||
{
|
||||
Environment.CurrentDirectory = _root.Path;
|
||||
var path = Package("mod.boss", "Bosshull", 100, Product("Acme Boss", _acme, "mod.boss"));
|
||||
Assert.Equal(0, Run("boss", path, "on").Code);
|
||||
var composition = ShipModCatalog.Compose(Shipped, Derived, Mods);
|
||||
Assert.Equal(new[] { "mod.boss" }, composition.Included);
|
||||
|
||||
using var cache = AetheriaStores.Open(Derived);
|
||||
var hull = Assert.IsType<HullData>(cache.Get(new CultRecordRef<CraftedItemData>(ShipModCatalog.HullKey("mod.boss"))));
|
||||
Assert.True(hull.Boss);
|
||||
var acme = cache.Get<Faction>(_acme);
|
||||
var rival = cache.Get<Faction>(_rival);
|
||||
Assert.Same(hull, Assert.Single(LoadoutGenerator.BossHullsOf(cache, acme)).hull);
|
||||
Assert.Empty(LoadoutGenerator.BossHullsOf(cache, rival));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void APackageWithAnUnknownMakerIsExcluded()
|
||||
{
|
||||
|
|
@ -299,6 +318,37 @@ public sealed class ShipProductTests : IDisposable
|
|||
RefusedAndUntouched("product", path, "ACM", "--remove");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BossCommand()
|
||||
{
|
||||
Environment.CurrentDirectory = _root.Path;
|
||||
var path = Package("mod.skiff", "Skiffhull", 100, Product("Acme Skiff", _acme, "mod.skiff"));
|
||||
void RefusedAndUntouched(params string[] args)
|
||||
{
|
||||
var before = File.ReadAllBytes(path);
|
||||
Assert.Equal(1, Run(args).Code);
|
||||
Assert.Equal(before, File.ReadAllBytes(path));
|
||||
}
|
||||
var options = CultDocumentMessagePackSerialization.OptionsFor(typeof(FactionProductData).Assembly);
|
||||
byte[] ProductBytes() => MessagePack.MessagePackSerializer.Serialize(ShipAuthoringStore.Load(path).Products.Single(), options);
|
||||
|
||||
var productBefore = ProductBytes();
|
||||
Assert.False(ShipAuthoringStore.Read(path).Hull.Boss);
|
||||
RefusedAndUntouched("boss", path, "yes");
|
||||
RefusedAndUntouched("boss", path, "ON");
|
||||
RefusedAndUntouched("boss", path);
|
||||
|
||||
Assert.Equal(0, Run("boss", path, "on").Code);
|
||||
Assert.True(ShipAuthoringStore.Read(path).Hull.Boss);
|
||||
Assert.Equal(productBefore, ProductBytes());
|
||||
Assert.Contains(", boss", Run("inspect", path).Output);
|
||||
|
||||
Assert.Equal(0, Run("boss", path, "off").Code);
|
||||
Assert.False(ShipAuthoringStore.Read(path).Hull.Boss);
|
||||
Assert.Equal(productBefore, ProductBytes());
|
||||
Assert.DoesNotContain(", boss", Run("inspect", path).Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateJudgesProductsOnADraftAndInspectListsThem()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Linq;
|
|||
// Uses the existing database executable; mod authoring does not earn another binary target.
|
||||
public static class ShipAuthoringCommands
|
||||
{
|
||||
private const string Usage = "ship-authoring create <ship.cc> <stable-id> <name> [--like <shipped hull name>] | inspect <ship.cc> | centre <ship.cc> | validate <ship.cc> | product <ship.cc> <maker> (--name <name> [--description <text>] | --remove) | price <ship.cc> <price> | compose <shipped.cc> <derived.cc> <mods-dir>";
|
||||
private const string Usage = "ship-authoring create <ship.cc> <stable-id> <name> [--like <shipped hull name>] | inspect <ship.cc> | centre <ship.cc> | validate <ship.cc> | product <ship.cc> <maker> (--name <name> [--description <text>] | --remove) | price <ship.cc> <price> | boss <ship.cc> on|off | compose <shipped.cc> <derived.cc> <mods-dir>";
|
||||
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
|
|
@ -29,7 +29,7 @@ public static class ShipAuthoringCommands
|
|||
if (args[0] == "inspect" && args.Length == 2)
|
||||
{
|
||||
var (hull, ship, products) = ShipAuthoringStore.Load(args[1]);
|
||||
Console.WriteLine($"{ship.Id}: {hull.Name}, {hull.Hardpoints?.Count ?? 0} hardpoints, {ship.SchematicLines?.Count ?? 0} lines, {ship.SchematicLines?.Sum(line => line.Points?.Length / 3 ?? 0) ?? 0} points");
|
||||
Console.WriteLine($"{ship.Id}: {hull.Name}, {hull.Hardpoints?.Count ?? 0} hardpoints, {ship.SchematicLines?.Count ?? 0} lines, {ship.SchematicLines?.Sum(line => line.Points?.Length / 3 ?? 0) ?? 0} points{(hull.Boss ? ", boss" : "")}");
|
||||
foreach (var product in products) Console.WriteLine($"product {product.Manufacturer.Key.Value}: {product.Name}");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -91,6 +91,21 @@ public static class ShipAuthoringCommands
|
|||
Console.WriteLine($"{ship.Id}: price {price}.");
|
||||
return 0;
|
||||
}
|
||||
if (args[0] == "boss" && args.Length == 3)
|
||||
{
|
||||
// Judged before the file is touched: a refusal leaves it byte-identical. Sets the hull's flag and no product.
|
||||
if (args[2] != "on" && args[2] != "off")
|
||||
throw new InvalidOperationException("boss must be on or off.");
|
||||
var (hull, ship, _) = ShipAuthoringStore.Load(args[1]);
|
||||
hull.Boss = args[2] == "on";
|
||||
using (var cache = ShipAuthoringStore.Open(args[1], writable: true))
|
||||
{
|
||||
ShipAuthoringStore.Write(cache, hull, ship);
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
Console.WriteLine($"{ship.Id}: boss {args[2]}.");
|
||||
return 0;
|
||||
}
|
||||
if (args[0] == "product" && args.Length >= 4)
|
||||
{
|
||||
var remove = args.Length == 4 && args[3] == "--remove";
|
||||
|
|
|
|||
Loading…
Reference in a new issue