Ship S1: one hull record, and a hull names its visual
A mod ship file now holds a HullData at mod-hull:<id> and the ShipAuthoring visual package at mod-ship:<id>. HullData.Visual (key 32) is the typed ref between them; ShipAuthoring.Hull (key 1) is retired. - One joint validator over (hull, visual) is the only semantic check; Load owns the file structure (one hull, one visual, deterministic keys). - Compose copies the mod store's records verbatim, so the derived catalog holds one hull per mod ship. - ship_cc.py edits the hull record's slots directly; the body[HULL_SLOT] indirection is gone. - The package fixture is generated from ShipAuthoringTests.Fixture() (glTF scene included) and exported when AETHERIA_SHIP_FIXTURE_DIR is set. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
de1b5b8fa2
commit
1702e0549f
13 changed files with 622 additions and 319 deletions
|
|
@ -11,25 +11,25 @@ using Xunit;
|
|||
// reason) fails its own case and no other.
|
||||
public sealed class ShipValidationTests
|
||||
{
|
||||
private static readonly Dictionary<string, (Action<ShipAuthoring> Break, string Message)> Cases = Build();
|
||||
private static readonly Dictionary<string, (Action<ShipParts> Break, string Message)> Cases = Build();
|
||||
|
||||
public static IEnumerable<object[]> CaseNames => Cases.Keys.Select(name => new object[] { name });
|
||||
|
||||
[Fact]
|
||||
public void TheFixtureIsValid() => ShipAuthoringStore.Validate(ShipAuthoringTests.Fixture());
|
||||
public void TheFixtureIsValid() => ShipAuthoringTests.Fixture().Validate();
|
||||
|
||||
[Theory, MemberData(nameof(CaseNames))]
|
||||
public void ValidatorRefusesEachBreakageByItsOwnGuard(string name)
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
Cases[name].Break(ship);
|
||||
var error = Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Validate(ship));
|
||||
var error = Assert.Throws<InvalidOperationException>(ship.Validate);
|
||||
Assert.Contains(Cases[name].Message, error.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidatorRefusesANullRecord() =>
|
||||
Assert.Contains("is null", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Validate(null)).Message);
|
||||
Assert.Contains("is null", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Validate(ShipAuthoringTests.Fixture().Hull, null)).Message);
|
||||
|
||||
[Theory]
|
||||
[InlineData("a"), InlineData("z"), InlineData("0"), InlineData("9"), InlineData("a0z9"), InlineData("0a"), InlineData("9z"),
|
||||
|
|
@ -37,8 +37,7 @@ public sealed class ShipValidationTests
|
|||
public void IdsMayUseLowerCaseAsciiDigitsDotsUnderscoresAndHyphens(string id)
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
ship.Id = id;
|
||||
ShipAuthoringStore.Validate(ship);
|
||||
ship.WithId(id).Validate();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -47,8 +46,8 @@ public sealed class ShipValidationTests
|
|||
public void IdsOutsideThatAlphabetAreRefused(string id)
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
ship.Id = id;
|
||||
Assert.Contains("ship ID must use", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Validate(ship)).Message);
|
||||
ship.WithId(id);
|
||||
Assert.Contains("ship ID must use", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -56,8 +55,8 @@ public sealed class ShipValidationTests
|
|||
public void ModelAssetsMayLiveInsideTheirPackage(string asset)
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
ship.ModelAsset = asset;
|
||||
ShipAuthoringStore.Validate(ship);
|
||||
ship.Visual.ModelAsset = asset;
|
||||
ship.Validate();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -65,35 +64,35 @@ public sealed class ShipValidationTests
|
|||
public void ModelAssetsCannotEscapeTheirPackage(string asset)
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
ship.ModelAsset = asset;
|
||||
Assert.Contains("relative package path", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Validate(ship)).Message);
|
||||
ship.Visual.ModelAsset = asset;
|
||||
Assert.Contains("relative package path", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RootedModelAssetsAreRefused()
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
ship.ModelAsset = Path.GetFullPath("skiff.glb");
|
||||
Assert.Contains("relative package path", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Validate(ship)).Message);
|
||||
ship.Visual.ModelAsset = Path.GetFullPath("skiff.glb");
|
||||
Assert.Contains("relative package path", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OptionalPartsAndRangeEdgesAreAccepted()
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
var line = ship.SchematicLines[0];
|
||||
var line = ship.Visual.SchematicLines[0];
|
||||
line.Points = new[] { 0f, 0f, 0f, 1f, 0f, 0f, 2f, 0f, 0f };
|
||||
line.Radii = new[] { 0f, 5f, 0f };
|
||||
line.Opacities = new[] { 0f, 1f, .5f };
|
||||
ShipAuthoringStore.Validate(ship);
|
||||
ship.Validate();
|
||||
line.Radii = null;
|
||||
line.Opacities = null;
|
||||
line.Color = null;
|
||||
ShipAuthoringStore.Validate(ship);
|
||||
ship.SchematicLines = null;
|
||||
ship.Validate();
|
||||
ship.Visual.SchematicLines = null;
|
||||
ship.Hull.Hardpoints = null;
|
||||
ship.Anchors.RemoveAt(ship.Anchors.Count - 1);
|
||||
ShipAuthoringStore.Validate(ship);
|
||||
ship.Visual.Anchors.RemoveAt(ship.Visual.Anchors.Count - 1);
|
||||
ship.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -102,39 +101,23 @@ public sealed class ShipValidationTests
|
|||
var ship = ShipAuthoringTests.Fixture();
|
||||
ship.Hull.Hardpoints[0].Shape = new Shape(2, 1);
|
||||
ship.Hull.Hardpoints[0].Shape.Cells[0, 0] = true;
|
||||
ShipAuthoringStore.Validate(ship);
|
||||
ship.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnEmptyParentIdMeansNoParent()
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
ship.Anchors[0].ParentId = "";
|
||||
ShipAuthoringStore.Validate(ship);
|
||||
ship.Visual.Anchors[0].ParentId = "";
|
||||
ship.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnAnchorMayNameItsHardpointAsParent()
|
||||
{
|
||||
var ship = ShipAuthoringTests.Fixture();
|
||||
ship.Anchors.Add(new ShipAnchor { Id = "muzzle", Role = "weapon-muzzle", ModelNodeId = "muzzle", ParentId = "thruster.port" });
|
||||
ShipAuthoringStore.Validate(ship);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadRefusesAFileThatHoldsTwoShips()
|
||||
{
|
||||
using var directory = new TempDirectory();
|
||||
var path = Path.Combine(directory.Path, "two.cc");
|
||||
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
||||
{
|
||||
cache.Upsert(ShipAuthoringTests.Fixture());
|
||||
var other = ShipAuthoringTests.Fixture();
|
||||
other.Id = "mod.other";
|
||||
cache.Upsert(other);
|
||||
await cache.FlushAsync();
|
||||
}
|
||||
Assert.Contains("found 2", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Read(path)).Message);
|
||||
ship.Visual.Anchors.Add(new ShipAnchor { Id = "muzzle", Role = "weapon-muzzle", ModelNodeId = "muzzle", ParentId = "thruster.port" });
|
||||
ship.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -146,20 +129,20 @@ public sealed class ShipValidationTests
|
|||
ship.Hull.Name = "";
|
||||
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
||||
{
|
||||
cache.Upsert(ship);
|
||||
ShipAuthoringStore.Write(cache, ship.Hull, ship.Visual);
|
||||
await cache.FlushAsync();
|
||||
}
|
||||
Assert.Contains("hull name is required", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Read(path)).Message);
|
||||
}
|
||||
|
||||
private static Dictionary<string, (Action<ShipAuthoring>, string)> Build()
|
||||
private static Dictionary<string, (Action<ShipParts>, string)> Build()
|
||||
{
|
||||
var cases = new Dictionary<string, (Action<ShipAuthoring>, string)>();
|
||||
void Add(string name, Action<ShipAuthoring> breakIt, string message) => cases.Add(name, (breakIt, message));
|
||||
HardpointData Mount(ShipAuthoring ship) => ship.Hull.Hardpoints[0];
|
||||
var cases = new Dictionary<string, (Action<ShipParts>, string)>();
|
||||
void Add(string name, Action<ShipParts> breakIt, string message) => cases.Add(name, (breakIt, message));
|
||||
HardpointData Mount(ShipParts ship) => ship.Hull.Hardpoints[0];
|
||||
|
||||
Add("id-null", s => s.Id = null, "Ship ID is required");
|
||||
Add("id-blank", s => s.Id = " ", "Ship ID is required");
|
||||
Add("id-null", s => s.Visual.Id = null, "Ship ID is required");
|
||||
Add("id-blank", s => s.Visual.Id = " ", "Ship ID is required");
|
||||
Add("hull-null", s => s.Hull = null, "hull data is required");
|
||||
Add("hull-name-null", s => s.Hull.Name = null, "hull name is required");
|
||||
Add("hull-name-blank", s => s.Hull.Name = " ", "hull name is required");
|
||||
|
|
@ -169,21 +152,21 @@ public sealed class ShipValidationTests
|
|||
Add("hull-height-zero", s => s.Hull.Shape.Cells = new bool[2, 0], "at least one cell");
|
||||
Add("hull-no-occupied-cell", s => s.Hull.Shape.Cells = new bool[2, 2], "at least one cell");
|
||||
Add("hull-names-a-prefab", s => s.Hull.Prefab = "Djinni", "cannot name a Unity prefab");
|
||||
Add("model-null", s => s.ModelAsset = null, "relative package path");
|
||||
Add("model-blank", s => s.ModelAsset = " ", "relative package path");
|
||||
Add("model-null", s => s.Visual.ModelAsset = null, "relative package path");
|
||||
Add("model-blank", s => s.Visual.ModelAsset = " ", "relative package path");
|
||||
|
||||
Add("anchors-null", s => s.Anchors = null, "anchors are required");
|
||||
Add("anchor-null", s => s.Anchors.Add(null), "anchor IDs must be present and unique");
|
||||
Add("anchor-id-null", s => s.Anchors[4].Id = null, "anchor IDs must be present and unique");
|
||||
Add("anchor-id-blank", s => s.Anchors.Add(new ShipAnchor { Id = " ", Role = "articulation", ModelNodeId = "x" }), "anchor IDs must be present and unique");
|
||||
Add("anchor-id-duplicate", s => s.Anchors.Add(new ShipAnchor { Id = "map", Role = "articulation", ModelNodeId = "x" }), "anchor IDs must be present and unique");
|
||||
Add("anchor-node-null", s => s.Anchors[4].ModelNodeId = null, "needs a model node ID");
|
||||
Add("anchor-node-blank", s => s.Anchors[4].ModelNodeId = " ", "needs a model node ID");
|
||||
Add("anchor-node-shared", s => s.Anchors.Add(new ShipAnchor { Id = "other", Role = "articulation", ModelNodeId = "map" }), "claimed by more than one anchor");
|
||||
Add("anchors-null", s => s.Visual.Anchors = null, "anchors are required");
|
||||
Add("anchor-null", s => s.Visual.Anchors.Add(null), "anchor IDs must be present and unique");
|
||||
Add("anchor-id-null", s => s.Visual.Anchors[4].Id = null, "anchor IDs must be present and unique");
|
||||
Add("anchor-id-blank", s => s.Visual.Anchors.Add(new ShipAnchor { Id = " ", Role = "articulation", ModelNodeId = "x" }), "anchor IDs must be present and unique");
|
||||
Add("anchor-id-duplicate", s => s.Visual.Anchors.Add(new ShipAnchor { Id = "map", Role = "articulation", ModelNodeId = "x" }), "anchor IDs must be present and unique");
|
||||
Add("anchor-node-null", s => s.Visual.Anchors[4].ModelNodeId = null, "needs a model node ID");
|
||||
Add("anchor-node-blank", s => s.Visual.Anchors[4].ModelNodeId = " ", "needs a model node ID");
|
||||
Add("anchor-node-shared", s => s.Visual.Anchors.Add(new ShipAnchor { Id = "other", Role = "articulation", ModelNodeId = "map" }), "claimed by more than one anchor");
|
||||
foreach (var role in new[] { "map-icon", "hull-collider", "shield", "tractor" })
|
||||
{
|
||||
Add("role-missing-" + role, s => s.Anchors.RemoveAll(a => a.Role == role), $"exactly one {role} anchor is required");
|
||||
Add("role-doubled-" + role, s => s.Anchors.Add(new ShipAnchor { Id = "extra", Role = role, ModelNodeId = "extra" }), $"exactly one {role} anchor is required");
|
||||
Add("role-missing-" + role, s => s.Visual.Anchors.RemoveAll(a => a.Role == role), $"exactly one {role} anchor is required");
|
||||
Add("role-doubled-" + role, s => s.Visual.Anchors.Add(new ShipAnchor { Id = "extra", Role = role, ModelNodeId = "extra" }), $"exactly one {role} anchor is required");
|
||||
}
|
||||
|
||||
Add("hardpoint-null", s => s.Hull.Hardpoints.Add(null), "hardpoint IDs must be present and unique");
|
||||
|
|
@ -206,32 +189,32 @@ public sealed class ShipValidationTests
|
|||
Add("hardpoints-overlap", s =>
|
||||
{
|
||||
s.Hull.Hardpoints.Add(new HardpointData { Position = new int2(1, 0), Transform = "thruster.starboard" });
|
||||
s.Anchors.Add(new ShipAnchor { Id = "thruster.starboard", Role = "thruster-emitter", ModelNodeId = "thruster-starboard" });
|
||||
s.Visual.Anchors.Add(new ShipAnchor { Id = "thruster.starboard", Role = "thruster-emitter", ModelNodeId = "thruster-starboard" });
|
||||
}, "overlaps another hardpoint");
|
||||
Add("hardpoint-without-anchor", s => s.Anchors.RemoveAll(a => a.Id == "thruster.port"), "has no model anchor");
|
||||
Add("anchor-parent-unknown", s => s.Anchors.Add(new ShipAnchor { Id = "muzzle", Role = "weapon-muzzle", ModelNodeId = "muzzle", ParentId = "nowhere" }), "unknown hardpoint parent");
|
||||
Add("hardpoint-without-anchor", s => s.Visual.Anchors.RemoveAll(a => a.Id == "thruster.port"), "has no model anchor");
|
||||
Add("anchor-parent-unknown", s => s.Visual.Anchors.Add(new ShipAnchor { Id = "muzzle", Role = "weapon-muzzle", ModelNodeId = "muzzle", ParentId = "nowhere" }), "unknown hardpoint parent");
|
||||
|
||||
Add("line-null", s => s.SchematicLines.Add(null), "finite XYZ points");
|
||||
Add("line-points-null", s => s.SchematicLines[0].Points = null, "finite XYZ points");
|
||||
Add("line-one-point", s => s.SchematicLines[0].Points = new[] { 0f, 0f, 0f }, "finite XYZ points");
|
||||
Add("line-points-not-triples", s => s.SchematicLines[0].Points = new float[7], "finite XYZ points");
|
||||
Add("line-point-nan", s => s.SchematicLines[0].Points[3] = float.NaN, "finite XYZ points");
|
||||
Add("line-point-infinite", s => s.SchematicLines[0].Points[5] = float.PositiveInfinity, "finite XYZ points");
|
||||
Add("line-radii-too-short", s => s.SchematicLines[0].Radii = new[] { .1f }, "attributes have the wrong length");
|
||||
Add("line-radii-too-long", s => s.SchematicLines[0].Radii = new[] { .1f, .1f, .1f }, "attributes have the wrong length");
|
||||
Add("line-opacities-too-short", s => s.SchematicLines[0].Opacities = new[] { 1f }, "attributes have the wrong length");
|
||||
Add("line-opacities-too-long", s => s.SchematicLines[0].Opacities = new[] { 1f, 1f, 1f }, "attributes have the wrong length");
|
||||
Add("line-radius-nan", s => s.SchematicLines[0].Radii[1] = float.NaN, "radius and opacity must be finite");
|
||||
Add("line-radius-infinite", s => s.SchematicLines[0].Radii[1] = float.PositiveInfinity, "radius and opacity must be finite");
|
||||
Add("line-radius-negative", s => s.SchematicLines[0].Radii[0] = -.01f, "radius and opacity must be finite");
|
||||
Add("line-opacity-nan", s => s.SchematicLines[0].Opacities[1] = float.NaN, "radius and opacity must be finite");
|
||||
Add("line-opacity-infinite", s => s.SchematicLines[0].Opacities[1] = float.PositiveInfinity, "radius and opacity must be finite");
|
||||
Add("line-opacity-negative", s => s.SchematicLines[0].Opacities[0] = -.01f, "radius and opacity must be finite");
|
||||
Add("line-opacity-above-one", s => s.SchematicLines[0].Opacities[0] = 1.01f, "radius and opacity must be finite");
|
||||
Add("line-color-short", s => s.SchematicLines[0].Color = new[] { 1f, 1f, 1f }, "must be finite RGBA");
|
||||
Add("line-color-long", s => s.SchematicLines[0].Color = new[] { 1f, 1f, 1f, 1f, 1f }, "must be finite RGBA");
|
||||
Add("line-color-nan", s => s.SchematicLines[0].Color[2] = float.NaN, "must be finite RGBA");
|
||||
Add("line-color-infinite", s => s.SchematicLines[0].Color[3] = float.NegativeInfinity, "must be finite RGBA");
|
||||
Add("line-null", s => s.Visual.SchematicLines.Add(null), "finite XYZ points");
|
||||
Add("line-points-null", s => s.Visual.SchematicLines[0].Points = null, "finite XYZ points");
|
||||
Add("line-one-point", s => s.Visual.SchematicLines[0].Points = new[] { 0f, 0f, 0f }, "finite XYZ points");
|
||||
Add("line-points-not-triples", s => s.Visual.SchematicLines[0].Points = new float[7], "finite XYZ points");
|
||||
Add("line-point-nan", s => s.Visual.SchematicLines[0].Points[3] = float.NaN, "finite XYZ points");
|
||||
Add("line-point-infinite", s => s.Visual.SchematicLines[0].Points[5] = float.PositiveInfinity, "finite XYZ points");
|
||||
Add("line-radii-too-short", s => s.Visual.SchematicLines[0].Radii = new[] { .1f }, "attributes have the wrong length");
|
||||
Add("line-radii-too-long", s => s.Visual.SchematicLines[0].Radii = new[] { .1f, .1f, .1f }, "attributes have the wrong length");
|
||||
Add("line-opacities-too-short", s => s.Visual.SchematicLines[0].Opacities = new[] { 1f }, "attributes have the wrong length");
|
||||
Add("line-opacities-too-long", s => s.Visual.SchematicLines[0].Opacities = new[] { 1f, 1f, 1f }, "attributes have the wrong length");
|
||||
Add("line-radius-nan", s => s.Visual.SchematicLines[0].Radii[1] = float.NaN, "radius and opacity must be finite");
|
||||
Add("line-radius-infinite", s => s.Visual.SchematicLines[0].Radii[1] = float.PositiveInfinity, "radius and opacity must be finite");
|
||||
Add("line-radius-negative", s => s.Visual.SchematicLines[0].Radii[0] = -.01f, "radius and opacity must be finite");
|
||||
Add("line-opacity-nan", s => s.Visual.SchematicLines[0].Opacities[1] = float.NaN, "radius and opacity must be finite");
|
||||
Add("line-opacity-infinite", s => s.Visual.SchematicLines[0].Opacities[1] = float.PositiveInfinity, "radius and opacity must be finite");
|
||||
Add("line-opacity-negative", s => s.Visual.SchematicLines[0].Opacities[0] = -.01f, "radius and opacity must be finite");
|
||||
Add("line-opacity-above-one", s => s.Visual.SchematicLines[0].Opacities[0] = 1.01f, "radius and opacity must be finite");
|
||||
Add("line-color-short", s => s.Visual.SchematicLines[0].Color = new[] { 1f, 1f, 1f }, "must be finite RGBA");
|
||||
Add("line-color-long", s => s.Visual.SchematicLines[0].Color = new[] { 1f, 1f, 1f, 1f, 1f }, "must be finite RGBA");
|
||||
Add("line-color-nan", s => s.Visual.SchematicLines[0].Color[2] = float.NaN, "must be finite RGBA");
|
||||
Add("line-color-infinite", s => s.Visual.SchematicLines[0].Color[3] = float.NegativeInfinity, "must be finite RGBA");
|
||||
return cases;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue