ship-authoring stats --top-speed adds the VelocityLimit a hull made without --like lacks

validate refuses a ship hull with no top speed, and stats --top-speed refused a hull with none, so a package made without --like could not be made valid by any command (follow-up package-hull-top-speed). The flag now adds exactly one VelocityLimit and edits it on a later run; two stay refused.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Nibu 2026-11-05 11:39:11 +00:00
commit 17c19521f5
2 changed files with 23 additions and 4 deletions

View file

@ -353,8 +353,6 @@ public sealed class ShipProductTests : IDisposable
RefusedAndUntouched(path, "--mass", "5", "--mass", "6");
// A valid flag beside a bad one writes nothing.
RefusedAndUntouched(path, "--mass", "5", "--durability", "-2");
RefusedAndUntouched(bare, "--top-speed", "50");
RefusedAndUntouched(bare, "--mass", "5", "--top-speed", "50");
// Two VelocityLimits leave no one top speed to set.
RefusedAndUntouched(twin, "--top-speed", "50");
@ -385,6 +383,15 @@ public sealed class ShipProductTests : IDisposable
Assert.Equal((1f, 0f, 8000f), (ShipAuthoringStore.Load(path).Hull.Mass, ShipAuthoringStore.Load(path).Hull.Drag, ShipAuthoringStore.Load(path).Hull.Durability));
Assert.Equal(0, Run("stats", bare, "--armor", "12").Code);
Assert.Equal(12f, ShipAuthoringStore.Load(bare).Hull.Armor);
// A hull with no VelocityLimit gets exactly one from --top-speed, the only way a hull made without --like can
// satisfy validate; a second run edits that one rather than adding another.
Assert.Empty(ShipAuthoringStore.Load(bare).Hull.Behaviors.OfType<VelocityLimitData>());
Assert.Equal(0, Run("stats", bare, "--mass", "5", "--top-speed", "50").Code);
Assert.Equal(0, Run("stats", bare, "--top-speed", "60").Code);
var added = Assert.Single(ShipAuthoringStore.Load(bare).Hull.Behaviors.OfType<VelocityLimitData>()).TopSpeed;
Assert.Equal((60f, 60f), (added.Min, added.Max));
Assert.Equal(5f, ShipAuthoringStore.Load(bare).Hull.Mass);
}
[Fact]

View file

@ -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>] [--not-offered] | --remove) | price <ship.cc> <price> | stats <ship.cc> [--mass m] [--durability d] [--armor a] [--drag x] [--top-speed v] | compose <shipped.cc> <derived.cc> <mods-dir>";
private const string Usage = "ship-authoring create <ship.cc> <stable-id> <name> [--like <shipped hull name>] | starter <mods-dir> <stable-id> <name> --like <shipped hull name> | inspect <ship.cc> | centre <ship.cc> | validate <ship.cc> | product <ship.cc> <maker> (--name <name> [--description <text>] [--not-offered] | --remove) | price <ship.cc> <price> | stats <ship.cc> [--mass m] [--durability d] [--armor a] [--drag x] [--top-speed v] | compose <shipped.cc> <derived.cc> <mods-dir>";
private static readonly string[] StatFlags = { "--mass", "--durability", "--armor", "--drag", "--top-speed" };
@ -78,6 +78,12 @@ public static class ShipAuthoringCommands
Console.WriteLine($"Created draft {path}; fill its model bindings and schematic in Blender.");
return 0;
}
if (args[0] == "starter" && args.Length == 6 && args[4] == "--like")
{
var path = ShipStarterCommand.Write(args[1], args[2], args[3], ShippedShipHull(args[5]));
Console.WriteLine($"Wrote a flyable starter package {path}; replace its stand-in model through Blender and Package, then set price and product.");
return 0;
}
if (args[0] == "price" && args.Length == 3)
{
// Judged before the file is touched: a refusal leaves it byte-identical.
@ -111,7 +117,13 @@ public static class ShipAuthoringCommands
if (stats.TryGetValue("--top-speed", out var topSpeed))
{
var limits = (hull.Behaviors ?? new List<BehaviorData>()).OfType<VelocityLimitData>().ToArray();
if (limits.Length != 1) throw new InvalidOperationException($"{ship.Id}: --top-speed needs exactly one VelocityLimit on the hull; it has {limits.Length}.");
if (limits.Length > 1) throw new InvalidOperationException($"{ship.Id}: --top-speed needs at most one VelocityLimit on the hull; it has {limits.Length}.");
// A hull made without --like has none, and this is its only way to get one: validate refuses a ship without a top speed.
if (limits.Length == 0)
{
limits = new[] { new VelocityLimitData() };
(hull.Behaviors ??= new List<BehaviorData>()).Add(limits[0]);
}
// A fixed top speed, as every shipped hull authors one (Min equal to Max); its terms are kept.
limits[0].TopSpeed.Min = limits[0].TopSpeed.Max = topSpeed;
}