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:
Meta Vens 2026-09-30 03:06:43 +02:00
commit 1702e0549f
13 changed files with 622 additions and 319 deletions

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using CultMath;
using GameCult.Caching;
using Xunit;
public sealed class ShipAuthoringTests
@ -16,19 +17,20 @@ public sealed class ShipAuthoringTests
try
{
var ship = Fixture();
ShipAuthoringStore.Validate(ship);
ship.Validate();
using (var cache = ShipAuthoringStore.Open(path, writable: true))
{
cache.Upsert(ship);
ShipAuthoringStore.Write(cache, ship.Hull, ship.Visual);
await cache.FlushAsync();
}
var reopened = ShipAuthoringStore.Read(path);
Assert.Equal("mod.skiff", reopened.Id);
Assert.Equal("Skiff", reopened.Hull.Name);
Assert.True(reopened.Hull.Shape.Cells[1, 0]);
Assert.Equal("thruster.port", reopened.Hull.Hardpoints[0].Transform);
Assert.Equal("skiff.glb", reopened.ModelAsset);
Assert.Equal(2, reopened.SchematicLines[0].Points.Length / 3);
var (hull, visual) = ShipAuthoringStore.Read(path);
Assert.Equal("mod.skiff", visual.Id);
Assert.Equal("Skiff", hull.Name);
Assert.True(hull.Shape.Cells[1, 0]);
Assert.Equal("thruster.port", hull.Hardpoints[0].Transform);
Assert.Equal(ShipModCatalog.AuthoringKey("mod.skiff"), hull.Visual.Key);
Assert.Equal("skiff.glb", visual.ModelAsset);
Assert.Equal(2, visual.SchematicLines[0].Points.Length / 3);
}
finally { Directory.Delete(root, true); }
}
@ -38,24 +40,15 @@ public sealed class ShipAuthoringTests
{
var ship = Fixture();
ship.Hull.Shape.Cells[1, 0] = false;
Assert.Contains("outside the hull schematic", Assert.Throws<InvalidOperationException>(() =>
ShipAuthoringStore.Validate(ship)).Message);
Assert.Contains("outside the hull schematic", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
ship = Fixture();
ship.Anchors.RemoveAt(ship.Anchors.Count - 1);
Assert.Contains("has no model anchor", Assert.Throws<InvalidOperationException>(() =>
ShipAuthoringStore.Validate(ship)).Message);
ship.Visual.Anchors.RemoveAt(ship.Visual.Anchors.Count - 1);
Assert.Contains("has no model anchor", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
ship = Fixture();
ship.SchematicLines[0].Points[0] = float.NaN;
Assert.Contains("finite XYZ", Assert.Throws<InvalidOperationException>(() =>
ShipAuthoringStore.Validate(ship)).Message);
ship = Fixture();
ShipAuthoringStore.Validate(ship);
ship.Hull.Shape.Cells[1, 0] = false;
Assert.Contains("outside the hull schematic", Assert.Throws<InvalidOperationException>(() =>
ShipAuthoringStore.Validate(ship)).Message);
ship.Visual.SchematicLines[0].Points[0] = float.NaN;
Assert.Contains("finite XYZ", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
ship = Fixture();
ship.Hull.Hardpoints.Add(new HardpointData
@ -65,24 +58,98 @@ public sealed class ShipAuthoringTests
Shape = new Shape(),
Transform = "thruster.starboard"
});
ship.Anchors.Add(new ShipAnchor { Id = "thruster.starboard", Role = "thruster-emitter", ModelNodeId = "thruster-starboard" });
Assert.Contains("overlaps another hardpoint", Assert.Throws<InvalidOperationException>(() =>
ShipAuthoringStore.Validate(ship)).Message);
ship.Visual.Anchors.Add(new ShipAnchor { Id = "thruster.starboard", Role = "thruster-emitter", ModelNodeId = "thruster-starboard" });
Assert.Contains("overlaps another hardpoint", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
}
internal static ShipAuthoring Fixture()
// The hull owns hull semantics and the visual owns the model package, so the one joint check refuses a hull mount the
// visual has no anchor for, and a visual anchor parented to a mount the hull does not have.
[Fact]
public void HardpointsMustResolveToTheVisualsAnchors()
{
var ship = Fixture();
ship.Hull.Hardpoints[0].Transform = "thruster.renamed";
Assert.Contains("thruster.renamed has no model anchor", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
ship = Fixture();
ship.Visual.Anchors.Add(new ShipAnchor { Id = "muzzle", Role = "weapon-muzzle", ModelNodeId = "muzzle", ParentId = "thruster.gone" });
Assert.Contains("unknown hardpoint parent thruster.gone", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
Fixture().Validate();
}
[Fact]
public void HullNamesExactlyOneVisual()
{
var ship = Fixture();
ship.Hull.Prefab = "Djinni";
Assert.Contains("cannot name a Unity prefab", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
ship = Fixture();
ship.Hull.Visual = default;
Assert.Contains("the hull must name its visual record mod-ship:mod.skiff", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
ship = Fixture();
ship.Hull.Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey("mod.other"));
Assert.Contains("the hull must name its visual record mod-ship:mod.skiff", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
Fixture().Validate();
}
[Fact]
public async Task LoadRefusesAFileWhoseRecordsAreNotOneHullAndOneVisualAtTheirKeys()
{
using var directory = new TempDirectory();
async Task<string> Write(string name, Action<CultCache> fill)
{
var path = Path.Combine(directory.Path, name);
using var cache = ShipAuthoringStore.Open(path, writable: true);
fill(cache);
await cache.FlushAsync();
return path;
}
void Hull(CultCache cache, string key) =>
cache.UpsertAsync(typeof(HullData), Fixture().Hull, new CultRecordKey(key)).GetAwaiter().GetResult();
void Visual(CultCache cache, string key, string id = "mod.skiff") =>
cache.UpsertAsync(typeof(ShipAuthoring), Fixture().WithId(id).Visual, new CultRecordKey(key)).GetAwaiter().GetResult();
var twoShips = await Write("two.cc", cache =>
{
ShipAuthoringStore.Write(cache, Fixture().Hull, Fixture().Visual);
Visual(cache, "mod-ship:mod.other", "mod.other");
});
Assert.Contains("found 2", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(twoShips)).Message);
var noHull = await Write("nohull.cc", cache => Visual(cache, "mod-ship:mod.skiff"));
Assert.Contains("exactly one hull record, found 0", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(noHull)).Message);
var twoHulls = await Write("twohulls.cc", cache =>
{
ShipAuthoringStore.Write(cache, Fixture().Hull, Fixture().Visual);
Hull(cache, "mod-hull:mod.other");
});
Assert.Contains("exactly one hull record, found 2", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(twoHulls)).Message);
var wrongHullKey = await Write("hullkey.cc", cache => { Hull(cache, "hull:skiff"); Visual(cache, "mod-ship:mod.skiff"); });
Assert.Contains("records must be stored under mod-hull:mod.skiff and mod-ship:mod.skiff",
Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(wrongHullKey)).Message);
var wrongVisualKey = await Write("visualkey.cc", cache => { Hull(cache, "mod-hull:mod.skiff"); Visual(cache, "ship:skiff"); });
Assert.Contains("records must be stored under", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(wrongVisualKey)).Message);
}
internal static ShipParts Fixture()
{
var shape = new Shape(2, 2);
shape.Cells[0, 0] = true;
shape.Cells[1, 0] = true;
return new ShipAuthoring
return new ShipParts
{
Id = "mod.skiff",
ModelAsset = "skiff.glb",
Hull = new HullData
{
Name = "Skiff",
Shape = shape,
Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey("mod.skiff")),
Hardpoints = new List<HardpointData>
{
new HardpointData
@ -94,26 +161,49 @@ public sealed class ShipAuthoringTests
}
}
},
Anchors = new List<ShipAnchor>
Visual = new ShipAuthoring
{
new ShipAnchor { Id = "map", Role = "map-icon", ModelNodeId = "map" },
new ShipAnchor { Id = "collider", Role = "hull-collider", ModelNodeId = "collider" },
new ShipAnchor { Id = "shield", Role = "shield", ModelNodeId = "shield" },
new ShipAnchor { Id = "tractor", Role = "tractor", ModelNodeId = "tractor" },
new ShipAnchor { Id = "thruster.port", Role = "thruster-emitter", ModelNodeId = "thruster-port" }
},
SchematicLines = new List<ShipPolyline>
{
new ShipPolyline
Id = "mod.skiff",
ModelAsset = "skiff.glb",
Anchors = new List<ShipAnchor>
{
Layer = "Hull",
Material = "White",
Points = new[] { 0f, 0f, 0f, 1f, 0f, 0f },
Radii = new[] { .01f, .01f },
Opacities = new[] { 1f, 1f },
Color = new[] { 1f, 1f, 1f, 1f }
new ShipAnchor { Id = "map", Role = "map-icon", ModelNodeId = "map" },
new ShipAnchor { Id = "collider", Role = "hull-collider", ModelNodeId = "collider" },
new ShipAnchor { Id = "shield", Role = "shield", ModelNodeId = "shield" },
new ShipAnchor { Id = "tractor", Role = "tractor", ModelNodeId = "tractor" },
new ShipAnchor { Id = "thruster.port", Role = "thruster-emitter", ModelNodeId = "thruster-port" }
},
SchematicLines = new List<ShipPolyline>
{
new ShipPolyline
{
Layer = "Hull",
Material = "White",
Points = new[] { 0f, 0f, 0f, 1f, 0f, 0f },
Radii = new[] { .01f, .01f },
Opacities = new[] { 1f, 1f },
Color = new[] { 1f, 1f, 1f, 1f }
}
}
}
};
}
}
// One ship's two records: the hull and the visual it names.
internal sealed class ShipParts
{
public HullData Hull;
public ShipAuthoring Visual;
public void Deconstruct(out HullData hull, out ShipAuthoring visual) => (hull, visual) = (Hull, Visual);
public ShipParts WithId(string id)
{
Visual.Id = id;
Hull.Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey(id));
return this;
}
public void Validate() => ShipAuthoringStore.Validate(Hull, Visual);
}

View file

@ -0,0 +1,54 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
// Writes the mod package the tests, the Python round-trip check and the Unity smoke (ShipModPreview.Smoke) share. It is
// generated from ShipAuthoringTests.Fixture() so no opaque bytes are committed.
internal static class ShipFixture
{
public static readonly string[] Nodes = { "map", "collider", "shield", "tractor", "thruster-port" };
// The GLB carries a glTF scene naming every node: glTFast instantiates a scene, and a scene-less file has none.
public static string GlbJson(string[] nodes) =>
@"{""asset"":{""version"":""2.0""},""scene"":0,""scenes"":[{""nodes"":[" + string.Join(",", nodes.Select((_, index) => index)) + @"]}],""nodes"":[" +
string.Join(",", nodes.Select(node => $@"{{""name"":""{node}"",""extras"":{{""aetheria.id"":""{node}""}}}}")) + "]}";
public static byte[] Glb(string json)
{
var body = Encoding.UTF8.GetBytes(json);
var padded = new byte[(body.Length + 3) / 4 * 4];
Array.Fill(padded, (byte)' ');
body.CopyTo(padded, 0);
var bytes = new byte[20 + padded.Length + 8];
BitConverter.GetBytes(0x46546C67u).CopyTo(bytes, 0);
BitConverter.GetBytes(2u).CopyTo(bytes, 4);
BitConverter.GetBytes((uint)bytes.Length).CopyTo(bytes, 8);
BitConverter.GetBytes((uint)padded.Length).CopyTo(bytes, 12);
BitConverter.GetBytes(0x4E4F534Au).CopyTo(bytes, 16);
padded.CopyTo(bytes, 20);
BitConverter.GetBytes(0u).CopyTo(bytes, 20 + padded.Length);
BitConverter.GetBytes(0x004E4942u).CopyTo(bytes, 24 + padded.Length);
return bytes;
}
// <modsRoot>/<id>/ship.cc plus the GLB at the record's ModelAsset path.
public static string WritePackage(string modsRoot, string id, string hullName = "Skiff", string[] nodes = null,
string modelAsset = "skiff.glb", Action<ShipParts> tweak = null)
{
var ship = ShipAuthoringTests.Fixture();
tweak?.Invoke(ship);
ship.WithId(id);
ship.Hull.Name = hullName;
ship.Visual.ModelAsset = modelAsset;
var directory = Path.Combine(modsRoot, id);
Directory.CreateDirectory(directory);
using (var cache = ShipAuthoringStore.Open(Path.Combine(directory, "ship.cc"), writable: true))
{
ShipAuthoringStore.Write(cache, ship.Hull, ship.Visual);
cache.FlushAsync().Wait();
}
File.WriteAllBytes(Path.Combine(directory, modelAsset), Glb(GlbJson(nodes ?? Nodes)));
return directory;
}
}

View file

@ -5,6 +5,7 @@ using System.Linq;
using System.Security.Cryptography;
using System.Text;
using GameCult.Caching;
using Newtonsoft.Json.Linq;
using Xunit;
// Compose, ReadPackage and ReadNodeIds: the derived catalog a game would open, and the GLB node ids its anchors bind to.
@ -14,7 +15,7 @@ public sealed class ShipModCatalogTests : IDisposable
private string Shipped => Path.Combine(_directory.Path, "Aetheria.cc");
private string Derived => Path.Combine(_directory.Path, "Derived", "Aetheria.modded.cc");
private string Mods => Path.Combine(_directory.Path, "Mods");
private static readonly string[] FixtureNodes = { "map", "collider", "shield", "tractor", "thruster-port" };
private static readonly string[] FixtureNodes = ShipFixture.Nodes;
public ShipModCatalogTests()
{
@ -48,6 +49,60 @@ public sealed class ShipModCatalogTests : IDisposable
AssertOnlyTheDerivedFile();
}
// Correction 2 of the S0 map: the derived catalog held each mod hull twice, once as a HullData and once inside the
// ship's authoring record. The hull is now one record, and the visual holds no hull.
[Fact]
public void ComposedCatalogHoldsOneHullPerModShip()
{
WritePackage("mod.skiff", hullName: "Skiffhull");
ShipModCatalog.Compose(Shipped, Derived, Mods);
using var cache = AetheriaStores.Open(Derived);
Assert.Equal(1, cache.GetAll<HullData>().Count(hull => hull.Name == "Skiffhull"));
// The hull's name is stored exactly once in the derived file, so no second copy of the hull hides in another record.
Assert.Equal(1, Occurrences(File.ReadAllBytes(Derived), Encoding.UTF8.GetBytes("Skiffhull")));
var visual = cache.GetAll<ShipAuthoring>().Single();
Assert.Equal("mod.skiff", visual.Id);
}
[Fact]
public void ComposeCopiesTheModStoresRecordsUnchangedAndTheHullNamesItsVisualByRef()
{
WritePackage("mod.skiff");
var (modHull, modVisual) = ShipAuthoringStore.Read(Path.Combine(Mods, "mod.skiff", "ship.cc"));
ShipModCatalog.Compose(Shipped, Derived, Mods);
using var cache = AetheriaStores.Open(Derived);
var hull = cache.Get<HullData>(ShipModCatalog.HullKey("mod.skiff"));
var visual = cache.Get<ShipAuthoring>(ShipModCatalog.AuthoringKey("mod.skiff"));
Assert.Same(visual, cache.Get(hull.Visual));
var options = GameCult.Caching.MessagePack.CultDocumentMessagePackSerialization.OptionsFor(typeof(ShipAuthoring).Assembly);
Assert.Equal(MessagePack.MessagePackSerializer.Serialize(modHull, options), MessagePack.MessagePackSerializer.Serialize(hull, options));
Assert.Equal(MessagePack.MessagePackSerializer.Serialize(modVisual, options), MessagePack.MessagePackSerializer.Serialize(visual, options));
}
// The package the Unity smoke (ShipModPreview.Smoke) loads. Set AETHERIA_SHIP_FIXTURE_DIR to have this run leave it
// there: `-shipModPath $AETHERIA_SHIP_FIXTURE_DIR/mod.skiff/ship.cc`.
[Fact]
public void TheFixturePackageIsCompleteAndItsGlbCarriesAScene()
{
var directory = ShipFixture.WritePackage(Mods, "mod.skiff");
var package = ShipModCatalog.ReadPackage(Path.Combine(directory, "ship.cc"));
Assert.Equal(ShipFixture.Nodes.Length, package.NodeIndices.Count);
var glb = File.ReadAllBytes(package.ModelPath);
var json = JObject.Parse(Encoding.UTF8.GetString(glb, 20, (int)BitConverter.ToUInt32(glb, 12)));
Assert.Equal(0, (int)json["scene"]);
Assert.Equal(Enumerable.Range(0, ShipFixture.Nodes.Length), json["scenes"][0]["nodes"].Select(node => (int)node));
Assert.Equal(1, ShipModCatalog.Compose(Shipped, Derived, Mods));
var export = Environment.GetEnvironmentVariable("AETHERIA_SHIP_FIXTURE_DIR");
if (string.IsNullOrEmpty(export)) return;
var target = Path.Combine(export, "mod.skiff");
Directory.CreateDirectory(target);
foreach (var name in new[] { "ship.cc", "skiff.glb" }) File.Copy(Path.Combine(directory, name), Path.Combine(target, name), true);
}
[Fact]
public void ComposeCountsEveryPackageAndReplacesAnExistingDerivedCatalog()
{
@ -92,8 +147,7 @@ public sealed class ShipModCatalogTests : IDisposable
{
if (authoring)
{
var stranger = ShipAuthoringTests.Fixture();
stranger.Id = "stranger";
var stranger = ShipAuthoringTests.Fixture().WithId("stranger").Visual;
cache.UpsertAsync(typeof(ShipAuthoring), stranger, new CultRecordKey(key)).GetAwaiter().GetResult();
}
else
@ -143,7 +197,7 @@ public sealed class ShipModCatalogTests : IDisposable
{
using (var cache = AetheriaStores.Open(Shipped, catalogWritable: true))
{
cache.UpsertAsync(typeof(ShipAuthoring), ShipAuthoringTests.Fixture(), new CultRecordKey("shipped:skiff")).GetAwaiter().GetResult();
cache.UpsertAsync(typeof(ShipAuthoring), ShipAuthoringTests.Fixture().Visual, new CultRecordKey("shipped:skiff")).GetAwaiter().GetResult();
cache.FlushAsync().Wait();
}
WritePackage("mod.skiff", hullName: "Different");
@ -177,7 +231,7 @@ public sealed class ShipModCatalogTests : IDisposable
{
WritePackage("mod.skiff");
var package = ShipModCatalog.ReadPackage(Path.Combine(Mods, "mod.skiff", "ship.cc"));
Assert.Equal("mod.skiff", package.Ship.Id);
Assert.Equal("mod.skiff", package.Visual.Id);
Assert.Equal(Path.GetFullPath(Path.Combine(Mods, "mod.skiff", "skiff.glb")), package.ModelPath);
Assert.Equal(new Dictionary<string, uint> { ["map"] = 0, ["collider"] = 1, ["shield"] = 2, ["tractor"] = 3, ["thruster-port"] = 4 }, package.NodeIndices);
}
@ -224,24 +278,24 @@ public sealed class ShipModCatalogTests : IDisposable
[Fact]
public void NodeIdsMapToTheirGlbNodeIndexSkippingNodesWithoutOne()
{
var path = Write("nodes.glb", Glb(@"{""asset"":{""version"":""2.0""},""nodes"":[
var path = Write("nodes.glb", ShipFixture.Glb(@"{""asset"":{""version"":""2.0""},""nodes"":[
{""name"":""plain""},{""extras"":{""aetheria.id"":""a""}},{""extras"":{}},{""extras"":{""aetheria.id"":""""}},{""extras"":{""aetheria.id"":""b""}}]}"));
Assert.Equal(new Dictionary<string, uint> { ["a"] = 1, ["b"] = 4 }, ShipModCatalog.ReadNodeIds(path));
}
[Fact]
public void AGlbWithoutNodesHasNoIds() =>
Assert.Empty(ShipModCatalog.ReadNodeIds(Write("empty.glb", Glb(@"{""asset"":{""version"":""2.0""}}"))));
Assert.Empty(ShipModCatalog.ReadNodeIds(Write("empty.glb", ShipFixture.Glb(@"{""asset"":{""version"":""2.0""}}"))));
[Fact]
public void ADuplicateNodeIdIsRefused() =>
Assert.Contains("duplicate GLB node aetheria.id=a", Assert.Throws<InvalidOperationException>(() =>
ShipModCatalog.ReadNodeIds(Write("dup.glb", Glb(@"{""nodes"":[{""extras"":{""aetheria.id"":""a""}},{""extras"":{""aetheria.id"":""a""}}]}")))).Message);
ShipModCatalog.ReadNodeIds(Write("dup.glb", ShipFixture.Glb(@"{""nodes"":[{""extras"":{""aetheria.id"":""a""}},{""extras"":{""aetheria.id"":""a""}}]}")))).Message);
[Fact]
public void AMalformedGlbHeaderIsRefused()
{
var good = Glb(@"{""nodes"":[]}");
var good = ShipFixture.Glb(@"{""nodes"":[]}");
void Refuse(string name, byte[] bytes, string message) =>
Assert.Contains(message, Assert.Throws<InvalidOperationException>(() => ShipModCatalog.ReadNodeIds(Write(name, bytes))).Message);
@ -281,24 +335,6 @@ public sealed class ShipModCatalogTests : IDisposable
return copy;
}
private static byte[] Glb(string json)
{
var body = Encoding.UTF8.GetBytes(json);
var padded = new byte[(body.Length + 3) / 4 * 4];
Array.Fill(padded, (byte)' ');
body.CopyTo(padded, 0);
var bytes = new byte[20 + padded.Length + 8];
BitConverter.GetBytes(0x46546C67u).CopyTo(bytes, 0);
BitConverter.GetBytes(2u).CopyTo(bytes, 4);
BitConverter.GetBytes((uint)bytes.Length).CopyTo(bytes, 8);
BitConverter.GetBytes((uint)padded.Length).CopyTo(bytes, 12);
BitConverter.GetBytes(0x4E4F534Au).CopyTo(bytes, 16);
padded.CopyTo(bytes, 20);
BitConverter.GetBytes(0u).CopyTo(bytes, 20 + padded.Length);
BitConverter.GetBytes(0x004E4942u).CopyTo(bytes, 24 + padded.Length);
return bytes;
}
private string Write(string name, byte[] bytes)
{
var path = Path.Combine(_directory.Path, name);
@ -307,23 +343,14 @@ public sealed class ShipModCatalogTests : IDisposable
}
private void WritePackage(string id, string hullName = "Skiff", string[] nodes = null, string modelAsset = "skiff.glb",
Action<ShipAuthoring> tweak = null)
Action<ShipParts> tweak = null) => ShipFixture.WritePackage(Mods, id, hullName, nodes, modelAsset, tweak);
private static int Occurrences(byte[] haystack, byte[] needle)
{
var ship = ShipAuthoringTests.Fixture();
tweak?.Invoke(ship);
ship.Id = id;
ship.Hull.Name = hullName;
ship.ModelAsset = modelAsset;
var directory = Path.Combine(Mods, id);
Directory.CreateDirectory(directory);
using (var cache = ShipAuthoringStore.Open(Path.Combine(directory, "ship.cc"), writable: true))
{
cache.Upsert(ship);
cache.FlushAsync().Wait();
}
var json = @"{""asset"":{""version"":""2.0""},""nodes"":[" +
string.Join(",", (nodes ?? FixtureNodes).Select(node => $@"{{""extras"":{{""aetheria.id"":""{node}""}}}}")) + "]}";
File.WriteAllBytes(Path.Combine(directory, modelAsset), Glb(json));
var count = 0;
for (var start = 0; start <= haystack.Length - needle.Length; start++)
if (haystack.AsSpan(start, needle.Length).SequenceEqual(needle)) count++;
return count;
}
private static string Hash(string path) => Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(path)));

View file

@ -4,12 +4,13 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using GameCult.Caching;
using GameCult.Caching.MessagePack;
using MessagePack;
using Xunit;
// tools/blender/aetheria_ships/ship_cc.py edits a ShipAuthoring record by MessagePack slot number and by hardpoint
// member position. These tests bind that file to the C# types that own the numbers: any renumbered, renamed or
// tools/blender/aetheria_ships/ship_cc.py edits a ship file's HullData and ShipAuthoring records by MessagePack slot
// number and by hardpoint member position. These tests bind that file to the C# types that own the numbers: any renumbered, renamed or
// reordered member, enum value, or nested array shape fails here instead of corrupting a ship the next time Blender saves.
public sealed class ShipSchemaPinTests
{
@ -17,7 +18,6 @@ public sealed class ShipSchemaPinTests
[Theory]
[InlineData("SCHEMATIC_LINES_SLOT", typeof(ShipAuthoring), nameof(ShipAuthoring.SchematicLines))]
[InlineData("HULL_SLOT", typeof(ShipAuthoring), nameof(ShipAuthoring.Hull))]
[InlineData("HULL_SHAPE_SLOT", typeof(HullData), nameof(HullData.Shape))]
[InlineData("HULL_HARDPOINTS_SLOT", typeof(HullData), nameof(HullData.Hardpoints))]
public void PythonSlotConstantsAreTheKeysOfTheMembersTheyNameInTheirComments(string constant, Type owner, string member)
@ -26,6 +26,16 @@ public sealed class ShipSchemaPinTests
Assert.Matches(new Regex($@"^{constant} = \d+ # \w+\.{member}\r?$", RegexOptions.Multiline), Source);
}
[Fact]
public void PythonSchemaNamesAreTheDocumentsTheyNameAndTheRetiredSlotIsNotReused()
{
Assert.Equal(typeof(ShipAuthoring).GetCustomAttribute<CultDocumentAttribute>().SchemaName, Text("SCHEMA"));
Assert.Equal(typeof(HullData).GetCustomAttribute<CultDocumentAttribute>().SchemaName, Text("HULL_SCHEMA"));
// Key 1 held the embedded hull until S1. A later member must not take it, or an old file would decode as it.
Assert.DoesNotContain(typeof(ShipAuthoring).GetMembers(BindingFlags.Public | BindingFlags.Instance),
member => member.GetCustomAttribute<KeyAttribute>()?.IntKey == 1);
}
[Fact]
public void PythonHardpointMembersAreHardpointDataMembersAtTheirOwnPositions()
{
@ -45,18 +55,23 @@ public sealed class ShipSchemaPinTests
[Fact]
public void SerializedShipHasTheNestedArrayShapesPythonIndexes()
{
var ship = ShipAuthoringTests.Fixture();
var bytes = MessagePackSerializer.Serialize(ship, CultDocumentMessagePackSerialization.OptionsFor(typeof(ShipAuthoring).Assembly));
var body = Assert.IsType<object[]>(MessagePackSerializer.Deserialize<object>(bytes, MessagePackSerializerOptions.Standard));
var (hull, visual) = ShipAuthoringTests.Fixture();
var options = CultDocumentMessagePackSerialization.OptionsFor(typeof(ShipAuthoring).Assembly);
object[] Body(object document) => Assert.IsType<object[]>(MessagePackSerializer.Deserialize<object>(
MessagePackSerializer.Serialize(document.GetType(), document, options), MessagePackSerializerOptions.Standard));
var body = Body(visual);
Assert.Equal("mod.skiff", body[0]);
var hull = Assert.IsType<object[]>(body[Integer("HULL_SLOT")]);
var lines = Assert.IsType<object[]>(body[Integer("SCHEMATIC_LINES_SLOT")]);
Assert.Equal("Hull", Assert.IsType<object[]>(Assert.Single(lines))[0]);
var hullBody = Body(hull);
// A schematic is [[width, height, cells]] with cells flattened x-major (index x * height + y).
var hullShape = Assert.IsType<object[]>(Assert.IsType<object[]>(hull[Integer("HULL_SHAPE_SLOT")])[0]);
var hullShape = Assert.IsType<object[]>(Assert.IsType<object[]>(hullBody[Integer("HULL_SHAPE_SLOT")])[0]);
Assert.Equal(new object[] { 2, 2 }, hullShape.Take(2).Select(value => (object)Convert.ToInt32(value)));
Assert.Equal(new[] { true, false, true, false }, Assert.IsType<object[]>(hullShape[2]).Cast<bool>());
var hardpoints = Assert.IsType<object[]>(hull[Integer("HULL_HARDPOINTS_SLOT")]);
var hardpoints = Assert.IsType<object[]>(hullBody[Integer("HULL_HARDPOINTS_SLOT")]);
var row = Assert.IsType<object[]>(Assert.Single(hardpoints));
var members = Strings("HARDPOINT_MEMBERS");
Assert.True(row.Length >= members.Length);
@ -65,9 +80,6 @@ public sealed class ShipSchemaPinTests
Assert.Equal(3, footprint.Length);
Assert.Equal(new[] { true }, Assert.IsType<object[]>(footprint[2]).Cast<bool>());
Assert.Equal(new[] { 1, 0 }, Assert.IsType<object[]>(row[Array.IndexOf(members, "Position")]).Select(value => Convert.ToInt32(value)));
var lines = Assert.IsType<object[]>(body[Integer("SCHEMATIC_LINES_SLOT")]);
Assert.Equal("Hull", Assert.IsType<object[]>(Assert.Single(lines))[0]);
}
private static int KeyOf(Type owner, string member)
@ -79,6 +91,13 @@ public sealed class ShipSchemaPinTests
private static int Integer(string constant) =>
int.Parse(Regex.Match(Source, $@"^{constant} = (\d+)", RegexOptions.Multiline).Groups[1].Value);
private static string Text(string constant)
{
var match = Regex.Match(Source, $@"^{constant} = ""([^""]*)""", RegexOptions.Multiline);
Assert.True(match.Success, $"{constant} is not a string in ship_cc.py");
return match.Groups[1].Value;
}
private static string[] Strings(string constant)
{
var block = Regex.Match(Source, $@"^{constant} = \((.*?)\)\r?$", RegexOptions.Multiline | RegexOptions.Singleline);

View file

@ -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;
}
}