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

@ -1,3 +1,4 @@
using GameCult.Caching;
using System;
using System.Collections.Generic;
using System.IO;
@ -23,17 +24,14 @@ public static class ShipAuthoringCommands
}
if (args[0] == "inspect" && args.Length == 2)
{
using var cache = ShipAuthoringStore.Open(args[1]);
var records = cache.GetAll<ShipAuthoring>().ToArray();
if (records.Length != 1) throw new InvalidOperationException($"Expected one ship, found {records.Length}.");
var ship = records[0];
Console.WriteLine($"{ship.Id}: {ship.Hull?.Name}, {ship.Hull?.Hardpoints?.Count ?? 0} hardpoints, {ship.SchematicLines?.Count ?? 0} lines, {ship.SchematicLines?.Sum(line => line.Points?.Length / 3 ?? 0) ?? 0} points");
var (hull, ship) = 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");
return 0;
}
if (args[0] == "validate" && args.Length == 2)
{
var ship = ShipAuthoringStore.Read(args[1]);
Console.WriteLine($"{ship.Id}: {ship.Hull.Name}, {ship.Hull.Hardpoints.Count} hardpoints, {ship.SchematicLines.Count} lines");
var (hull, ship) = ShipAuthoringStore.Read(args[1]);
Console.WriteLine($"{ship.Id}: {hull.Name}, {hull.Hardpoints.Count} hardpoints, {ship.SchematicLines.Count} lines");
return 0;
}
if (args[0] == "create" && args.Length == 4)
@ -41,16 +39,16 @@ public static class ShipAuthoringCommands
var path = Path.GetFullPath(args[1]);
if (File.Exists(path)) throw new InvalidOperationException($"Refusing to replace {path}");
Directory.CreateDirectory(Path.GetDirectoryName(path));
var ship = new ShipAuthoring
var ship = new ShipAuthoring { Id = args[2], ModelAsset = "ship.glb", Anchors = new List<ShipAnchor>() };
var hull = new HullData
{
Id = args[2],
Hull = new HullData { Name = args[3], Shape = new Shape() },
ModelAsset = "ship.glb",
Anchors = new List<ShipAnchor>()
Name = args[3],
Shape = new Shape(),
Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey(ship.Id))
};
using (var cache = ShipAuthoringStore.Open(path, writable: true))
{
cache.Upsert(ship);
ShipAuthoringStore.Write(cache, hull, ship);
cache.FlushAsync().Wait();
}
Console.WriteLine($"Created draft {path}; fill its model bindings and schematic in Blender.");

View file

@ -219,15 +219,15 @@ class AETHERIA_OT_bind_ship_collection(bpy.types.Operator):
else:
raise ValueError("Select an object in exactly one ship collection")
path = bpy.path.abspath(context.scene.aetheria_ship_cc_path)
_, _, body, _ = read(path, _brokkr_cultlib(context))
ship_id = read(path, _brokkr_cultlib(context)).ship.body[0]
if collection.get("aetheria.asset_kind") not in (None, "ship"):
raise ValueError(f"{collection.name} has another aetheria.asset_kind")
if collection.get("aetheria.id") not in (None, body[0]):
if collection.get("aetheria.id") not in (None, ship_id):
raise ValueError(f"{collection.name} is bound to another ship ID")
collection["aetheria.asset_kind"] = "ship"
collection["aetheria.id"] = body[0]
collection["aetheria.id"] = ship_id
collection["aetheria.ship_cc"] = bpy.path.relpath(path)
self.report({"INFO"}, f"Bound {collection.name} to {body[0]}")
self.report({"INFO"}, f"Bound {collection.name} to {ship_id}")
return {"FINISHED"}
except (OSError, ValueError, RuntimeError, ImportError) as exc:
self.report({"ERROR"}, str(exc))
@ -248,8 +248,7 @@ class AETHERIA_OT_capture_ship_lines(bpy.types.Operator):
raise ValueError(f"{collection.name} has no bound ship .cc path")
path = bpy.path.abspath(collection["aetheria.ship_cc"])
cultlib = _brokkr_cultlib(context)
_, _, body, _ = read(path, cultlib)
if body[0] != collection["aetheria.id"]:
if read(path, cultlib).ship.body[0] != collection["aetheria.id"]:
raise ValueError("The bound collection ID does not match its .cc ship ID")
lines = capture_grease_pencil(
obj, context.evaluated_depsgraph_get(), context.scene.frame_current,

View file

@ -1,8 +1,8 @@
"""Aetheria's Blender-side view of one typed ShipAuthoring CultCache record.
"""Aetheria's Blender-side view of one ship file: a typed HullData record and the ShipAuthoring visual it names.
The schema and authority live in Aetheria's C# ShipAuthoring type. This module
preserves the C# schema catalog and all slots it does not edit. Brokkr supplies
the Blender host and CultLib Python dependency path.
The schemas and authority live in Aetheria's C# HullData and ShipAuthoring types. This module edits the hull's grid
and hardpoints and the visual's lines, and preserves the C# schema catalog and every slot it does not edit. Brokkr
supplies the Blender host and CultLib Python dependency path.
"""
from __future__ import annotations
@ -12,15 +12,15 @@ import hashlib
from dataclasses import replace
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
from typing import Any, NamedTuple
SCHEMA = "aetheria.ship_authoring"
HULL_SCHEMA = "aetheria.hulldata"
# MessagePack slots of the C# types, which own them (ShipAuthoring, ItemData.Shape, HullData.Hardpoints,
# HardpointData). ShipSchemaPinTests in tests/Aetheria.Shared.Tests fails when any number or name below
# disagrees with those types' [Key] attributes, so a renumbered or added member cannot drift silently.
SCHEMATIC_LINES_SLOT = 4 # ShipAuthoring.SchematicLines
HULL_SLOT = 1 # ShipAuthoring.Hull
HULL_SHAPE_SLOT = 5 # ItemData.Shape
HULL_HARDPOINTS_SLOT = 23 # HullData.Hardpoints
# HardpointData member names in slot order; a hardpoint row is one value per name, and any slot past the last
@ -51,40 +51,65 @@ def _libraries(cultlib_packages: str):
return cultcache_py, msgpack
def read(path: str, cultlib_packages: str):
class Record(NamedTuple):
envelope: Any
body: list
class ShipFile(NamedTuple):
store: Any
ship: Record # the ShipAuthoring visual
hull: Record # the HullData it belongs to
msgpack: Any
def read(path: str, cultlib_packages: str) -> ShipFile:
cultcache, msgpack = _libraries(cultlib_packages)
store = cultcache.SingleFileMessagePackBackingStore(path)
envelopes = store.pull_all()
ships = [envelope for envelope in envelopes if envelope.type == SCHEMA]
if len(envelopes) != 1 or len(ships) != 1:
raise ValueError(f"{path} must hold exactly one {SCHEMA} record")
envelope = ships[0]
body = msgpack.unpackb(envelope.payload, raw=False)
if not isinstance(body, list) or len(body) < SCHEMATIC_LINES_SLOT + 1:
hulls = [envelope for envelope in envelopes if envelope.type == HULL_SCHEMA]
if len(envelopes) != 2 or len(ships) != 1 or len(hulls) != 1:
raise ValueError(f"{path} must hold exactly one {SCHEMA} record and one {HULL_SCHEMA} record")
bodies = []
for envelope in (ships[0], hulls[0]):
body = msgpack.unpackb(envelope.payload, raw=False)
if not isinstance(body, list):
raise ValueError(f"{path} has an incompatible {envelope.type} payload")
bodies.append(Record(envelope, body))
ship, hull = bodies
if len(ship.body) < SCHEMATIC_LINES_SLOT + 1:
raise ValueError(f"{path} has an incompatible {SCHEMA} payload")
return store, envelope, body, msgpack
return ShipFile(store, ship, hull, msgpack)
def _stamped(record: Record, msgpack: Any):
return replace(
record.envelope,
payload=msgpack.packb(record.body, use_bin_type=True),
stored_at=datetime.now(timezone.utc).isoformat(),
)
def replace_lines(path: str, cultlib_packages: str, lines: list[list[Any]]) -> int:
store, envelope, body, msgpack = read(path, cultlib_packages)
file = read(path, cultlib_packages)
if not lines:
raise ValueError("No Grease Pencil strokes were captured; the ship record was not changed")
body[SCHEMATIC_LINES_SLOT] = lines
updated = replace(
envelope,
payload=msgpack.packb(body, use_bin_type=True),
stored_at=datetime.now(timezone.utc).isoformat(),
)
store.push(updated)
file.ship.body[SCHEMATIC_LINES_SLOT] = lines
file.store.push(_stamped(file.ship, file.msgpack))
return len(lines)
def read_layout(path: str, cultlib_packages: str):
_, _, body, msgpack = read(path, cultlib_packages)
hull = body[HULL_SLOT]
if not isinstance(hull, list) or len(hull) <= HULL_HARDPOINTS_SLOT:
def _hull_body(file: ShipFile) -> list:
if len(file.hull.body) <= HULL_HARDPOINTS_SLOT:
raise ValueError("Ship hull has an incompatible typed payload")
return hull[HULL_SHAPE_SLOT][0], hull[HULL_HARDPOINTS_SLOT], _layout_revision(hull, msgpack)
return file.hull.body
def read_layout(path: str, cultlib_packages: str):
file = read(path, cultlib_packages)
hull = _hull_body(file)
return hull[HULL_SHAPE_SLOT][0], hull[HULL_HARDPOINTS_SLOT], _layout_revision(hull, file.msgpack)
def _layout_revision(hull, msgpack):
@ -95,11 +120,11 @@ def _layout_revision(hull, msgpack):
def replace_layout(path: str, cultlib_packages: str, expected_id: str, expected_revision: str,
shape: list[Any], hardpoints: list[list[Any]]) -> str:
store, envelope, body, msgpack = read(path, cultlib_packages)
if body[0] != expected_id:
file = read(path, cultlib_packages)
if file.ship.body[0] != expected_id:
raise ValueError("The bound ship ID changed; reload its layout")
hull = body[HULL_SLOT]
if _layout_revision(hull, msgpack) != expected_revision:
hull = _hull_body(file)
if _layout_revision(hull, file.msgpack) != expected_revision:
raise ValueError("The .cc layout changed since Load; reload before saving")
width, height, cells = shape
if not (1 <= width <= 32 and 1 <= height <= 32 and len(cells) == width * height):
@ -122,12 +147,8 @@ def replace_layout(path: str, cultlib_packages: str, expected_id: str, expected_
updated_hardpoints.append(hardpoint + previous.get(mount, []))
hull[HULL_SHAPE_SLOT] = [shape]
hull[HULL_HARDPOINTS_SLOT] = updated_hardpoints
store.push(replace(
envelope,
payload=msgpack.packb(body, use_bin_type=True),
stored_at=datetime.now(timezone.utc).isoformat(),
))
return _layout_revision(hull, msgpack)
file.store.push(_stamped(file.hull, file.msgpack))
return _layout_revision(hull, file.msgpack)
def capture_grease_pencil(obj: Any, depsgraph: Any, frame_number: int, *, evaluated: bool = True) -> list[list[Any]]:

View file

@ -1,4 +1,4 @@
"""Blender-free tests for aetheria_ships/ship_cc.py, the Python view of a typed ShipAuthoring record.
"""Blender-free tests for aetheria_ships/ship_cc.py, the Python view of a ship file's HullData and ShipAuthoring records.
Run with CultLib's cultcache-py and msgpack importable:
@ -10,6 +10,7 @@ ship_cc's own slot constants; ShipSchemaPinTests (C#) pins those constants to th
import importlib.util
import os
import shutil
import sys
import tempfile
import unittest
@ -40,7 +41,7 @@ def hardpoint_row(mount="thruster.port", tail=("future-hardpoint-slot",)):
return row + list(tail)
def hull_slots():
def hull_body():
hull = [None] * (ship_cc.HULL_HARDPOINTS_SLOT + 1)
hull[1] = "Skiff"
hull[ship_cc.HULL_SHAPE_SLOT] = [shape(2, 2, [True, False, True, False])]
@ -55,18 +56,28 @@ LINES = [["Hull", "White", [0.0, 0.0, 0.0, 1.0, 0.0, 0.0], [0.01, 0.01], [1.0, 1
def ship_body():
body = [None] * (ship_cc.SCHEMATIC_LINES_SLOT + 1)
body[0] = "mod.skiff"
body[ship_cc.HULL_SLOT] = hull_slots()
body[2] = "skiff.glb"
body[3] = [["map", "map-icon", "map", None, 0]]
body[ship_cc.SCHEMATIC_LINES_SLOT] = LINES
return body
CATALOG = cultcache_py.CultCacheSchemaCatalogEntry(
schema_id="ship-authoring-schema-1", schema_name=ship_cc.SCHEMA, schema_version="1",
content_hash="hash", canonical_schema_json='{"members":[{"slot":9,"name":"FutureMember"}]}',
compatible_schema_ids=("ship-authoring-schema-1",),
members=(cultcache_py.CultCacheSchemaCatalogMember(slot=9, member_name="FutureMember", type_name="string"),))
def catalog(schema_id, schema_name):
return cultcache_py.CultCacheSchemaCatalogEntry(
schema_id=schema_id, schema_name=schema_name, schema_version="1",
content_hash="hash", canonical_schema_json='{"members":[{"slot":9,"name":"FutureMember"}]}',
compatible_schema_ids=(schema_id,),
members=(cultcache_py.CultCacheSchemaCatalogMember(slot=9, member_name="FutureMember", type_name="string"),))
CATALOG = catalog("ship-authoring-schema-1", ship_cc.SCHEMA)
HULL_CATALOG = catalog("hull-schema-1", ship_cc.HULL_SCHEMA)
def envelope(key, schema, entry, body):
return cultcache_py.CultCacheEnvelope.create(
key=key, type=schema, payload=msgpack.packb(body, use_bin_type=True),
schema_id=entry.schema_id, catalog_entry=entry)
class ShipFileCase(unittest.TestCase):
@ -74,38 +85,54 @@ class ShipFileCase(unittest.TestCase):
directory = tempfile.TemporaryDirectory()
self.addCleanup(directory.cleanup)
self.path = str(Path(directory.name) / "ship.cc")
self.write(ship_body())
self.write(ship_body(), hull_body())
def write(self, body, path=None):
cultcache_py.SingleFileMessagePackBackingStore(path or self.path).push(cultcache_py.CultCacheEnvelope.create(
key="mod.skiff", type=ship_cc.SCHEMA, payload=msgpack.packb(body, use_bin_type=True),
schema_id=CATALOG.schema_id, catalog_entry=CATALOG))
def write(self, ship, hull, path=None):
cultcache_py.SingleFileMessagePackBackingStore(path or self.path).push_all([
envelope("mod-ship:mod.skiff", ship_cc.SCHEMA, CATALOG, ship),
envelope("mod-hull:mod.skiff", ship_cc.HULL_SCHEMA, HULL_CATALOG, hull)])
def body(self):
return ship_cc.read(self.path, PACKAGES)[2]
def ship(self):
return ship_cc.read(self.path, PACKAGES).ship.body
def hull(self):
return ship_cc.read(self.path, PACKAGES).hull.body
def envelopes(self):
return {(e.type, e.key): e for e in cultcache_py.SingleFileMessagePackBackingStore(self.path).pull_all()}
def bytes(self):
return Path(self.path).read_bytes()
class ReadTests(ShipFileCase):
def test_reads_the_one_ship_record(self):
store, envelope, body, _ = ship_cc.read(self.path, PACKAGES)
self.assertEqual("mod.skiff", body[0])
self.assertEqual(ship_cc.SCHEMA, envelope.type)
def test_reads_the_ship_and_its_hull(self):
file = ship_cc.read(self.path, PACKAGES)
self.assertEqual("mod.skiff", file.ship.body[0])
self.assertEqual(ship_cc.SCHEMA, file.ship.envelope.type)
self.assertEqual("Skiff", file.hull.body[1])
self.assertEqual(ship_cc.HULL_SCHEMA, file.hull.envelope.type)
def test_refuses_a_file_with_another_record_beside_the_ship(self):
def test_refuses_a_file_with_another_record_beside_the_pair(self):
cultcache_py.SingleFileMessagePackBackingStore(self.path).push(cultcache_py.CultCacheEnvelope.create(
key="other", type="aetheria.something", payload=msgpack.packb([1], use_bin_type=True)))
with self.assertRaisesRegex(ValueError, "must hold exactly one"):
ship_cc.read(self.path, PACKAGES)
def test_refuses_a_file_whose_only_record_is_not_a_ship(self):
other = str(Path(self.path).with_name("other.cc"))
cultcache_py.SingleFileMessagePackBackingStore(other).push(cultcache_py.CultCacheEnvelope.create(
key="other", type="aetheria.something", payload=msgpack.packb([1], use_bin_type=True)))
def test_refuses_a_file_missing_either_half_of_the_pair(self):
for name, schema, entry, body in (("hull only", ship_cc.HULL_SCHEMA, HULL_CATALOG, hull_body()),
("ship only", ship_cc.SCHEMA, CATALOG, ship_body())):
other = str(Path(self.path).with_name(name.replace(" ", "-") + ".cc"))
cultcache_py.SingleFileMessagePackBackingStore(other).push(envelope("key", schema, entry, body))
with self.subTest(name):
with self.assertRaisesRegex(ValueError, "must hold exactly one"):
ship_cc.read(other, PACKAGES)
def test_refuses_a_file_with_two_hulls(self):
cultcache_py.SingleFileMessagePackBackingStore(self.path).push(
envelope("mod-hull:mod.other", ship_cc.HULL_SCHEMA, HULL_CATALOG, hull_body()))
with self.assertRaisesRegex(ValueError, "must hold exactly one"):
ship_cc.read(other, PACKAGES)
ship_cc.read(self.path, PACKAGES)
def test_refuses_a_file_with_no_record(self):
empty = str(Path(self.path).with_name("empty.cc"))
@ -113,15 +140,19 @@ class ReadTests(ShipFileCase):
with self.assertRaisesRegex(ValueError, "must hold exactly one"):
ship_cc.read(empty, PACKAGES)
def test_refuses_a_payload_too_short_for_the_line_slot(self):
self.write(["mod.skiff", None])
def test_refuses_a_ship_payload_too_short_for_the_line_slot(self):
self.write(["mod.skiff", None], hull_body())
with self.assertRaisesRegex(ValueError, "incompatible"):
ship_cc.read(self.path, PACKAGES)
def test_refuses_a_payload_that_is_not_an_array(self):
for payload in ({"Id": "mod.skiff"}, {str(index): index for index in range(9)}, "a string long enough to fill every slot"):
with self.subTest(payload=payload):
self.write(payload)
with self.subTest(ship=payload):
self.write(payload, hull_body())
with self.assertRaisesRegex(ValueError, "incompatible"):
ship_cc.read(self.path, PACKAGES)
with self.subTest(hull=payload):
self.write(ship_body(), payload)
with self.assertRaisesRegex(ValueError, "incompatible"):
ship_cc.read(self.path, PACKAGES)
@ -129,17 +160,22 @@ class ReadTests(ShipFileCase):
class ReplaceLinesTests(ShipFileCase):
def test_replaces_only_the_line_slot(self):
new_lines = [["Detail", "Red", [0.0] * 6, [0.1, 0.1], [1.0, 1.0], True, [1.0, 0.0, 0.0, 1.0]]]
before = self.body()
before = self.ship()
self.assertEqual(1, ship_cc.replace_lines(self.path, PACKAGES, new_lines))
after = self.body()
after = self.ship()
self.assertEqual(new_lines, after[ship_cc.SCHEMATIC_LINES_SLOT])
for slot in range(len(before)):
if slot != ship_cc.SCHEMATIC_LINES_SLOT:
self.assertEqual(before[slot], after[slot], f"slot {slot} changed")
def test_leaves_the_hull_record_byte_identical(self):
before = self.envelopes()[(ship_cc.HULL_SCHEMA, "mod-hull:mod.skiff")]
ship_cc.replace_lines(self.path, PACKAGES, LINES)
self.assertEqual(before, self.envelopes()[(ship_cc.HULL_SCHEMA, "mod-hull:mod.skiff")])
def test_keeps_the_schema_catalog(self):
ship_cc.replace_lines(self.path, PACKAGES, LINES)
envelope = cultcache_py.SingleFileMessagePackBackingStore(self.path).pull_all()[0]
envelope = self.envelopes()[(ship_cc.SCHEMA, "mod-ship:mod.skiff")]
self.assertEqual(CATALOG.members, envelope.catalog_entry.members)
self.assertEqual(CATALOG.canonical_schema_json, envelope.catalog_entry.canonical_schema_json)
@ -168,13 +204,14 @@ class LayoutTests(ShipFileCase):
def test_the_revision_follows_the_layout_and_only_the_layout(self):
_, _, revision = self.layout()
body = self.body()
body[ship_cc.SCHEMATIC_LINES_SLOT] = []
body[ship_cc.HULL_SLOT][1] = "Renamed"
self.write(body)
ship = self.ship()
ship[ship_cc.SCHEMATIC_LINES_SLOT] = []
hull = self.hull()
hull[1] = "Renamed"
self.write(ship, hull)
self.assertEqual(revision, self.layout()[2])
body[ship_cc.HULL_SLOT][ship_cc.HULL_SHAPE_SLOT] = [shape(2, 2, [True, True, True, True])]
self.write(body)
hull[ship_cc.HULL_SHAPE_SLOT] = [shape(2, 2, [True, True, True, True])]
self.write(ship, hull)
self.assertNotEqual(revision, self.layout()[2])
def test_the_revision_follows_the_hardpoints_too(self):
@ -198,15 +235,16 @@ class LayoutTests(ShipFileCase):
def test_preserves_every_slot_it_does_not_edit(self):
_, _, revision = self.layout()
before = self.body()
ship_before, hull_before = self.ship(), self.hull()
ship_envelope = self.envelopes()[(ship_cc.SCHEMA, "mod-ship:mod.skiff")]
self.edit(revision)
after = self.body()
for slot in range(len(before)):
if slot != ship_cc.HULL_SLOT:
self.assertEqual(before[slot], after[slot], f"ship slot {slot} changed")
for slot in range(len(before[ship_cc.HULL_SLOT])):
self.assertEqual(ship_before, self.ship())
self.assertEqual(ship_envelope, self.envelopes()[(ship_cc.SCHEMA, "mod-ship:mod.skiff")])
hull_after = self.hull()
self.assertEqual(len(hull_before), len(hull_after))
for slot in range(len(hull_before)):
if slot not in (ship_cc.HULL_SHAPE_SLOT, ship_cc.HULL_HARDPOINTS_SLOT):
self.assertEqual(before[ship_cc.HULL_SLOT][slot], after[ship_cc.HULL_SLOT][slot], f"hull slot {slot} changed")
self.assertEqual(hull_before[slot], hull_after[slot], f"hull slot {slot} changed")
def test_carries_a_later_schemas_hardpoint_slots_by_mount_id(self):
_, _, revision = self.layout()
@ -225,8 +263,8 @@ class LayoutTests(ShipFileCase):
def test_keeps_the_schema_catalog(self):
_, _, revision = self.layout()
self.edit(revision)
envelope = cultcache_py.SingleFileMessagePackBackingStore(self.path).pull_all()[0]
self.assertEqual(CATALOG.members, envelope.catalog_entry.members)
envelope = self.envelopes()[(ship_cc.HULL_SCHEMA, "mod-hull:mod.skiff")]
self.assertEqual(HULL_CATALOG.members, envelope.catalog_entry.members)
def test_refuses_a_ship_id_that_changed_and_writes_nothing(self):
_, _, revision = self.layout()
@ -293,14 +331,55 @@ class LayoutTests(ShipFileCase):
self.edit(revision, hardpoints=[row])
self.assertEqual(before, self.bytes())
def test_refuses_a_payload_without_the_hull_hardpoint_slot(self):
body = self.body()
body[ship_cc.HULL_SLOT] = body[ship_cc.HULL_SLOT][:ship_cc.HULL_HARDPOINTS_SLOT]
self.write(body)
def test_refuses_a_hull_payload_without_the_hardpoint_slot(self):
hull = self.hull()[:ship_cc.HULL_HARDPOINTS_SLOT]
self.write(self.ship(), hull)
with self.assertRaisesRegex(ValueError, "incompatible typed payload"):
self.layout()
@unittest.skipUnless(os.environ.get("SHIP_FIXTURE_DIR"), "SHIP_FIXTURE_DIR names the C#-written fixture (see below)")
class CSharpWrittenFixtureTests(unittest.TestCase):
"""Gate 1's Python half: a package C# wrote survives a Python edit with every untouched slot intact.
The fixture comes from the C# suite (`AETHERIA_SHIP_FIXTURE_DIR=<dir> dotnet test ... --filter
TheFixturePackageIsCompleteAndItsGlbCarriesAScene`). Point SHIP_FIXTURE_DIR at that <dir> and, optionally,
SHIP_EDITED_DIR at an empty directory to keep the edited package; C# then reopens and validates it with
`dotnet run --project tools/AetherDb -- ship-authoring validate <SHIP_EDITED_DIR>/mod.skiff/ship.cc`.
"""
def test_a_layout_and_line_edit_preserves_every_slot_it_does_not_own(self):
with tempfile.TemporaryDirectory() as scratch:
path = str(Path(scratch) / "ship.cc")
shutil.copy(Path(os.environ["SHIP_FIXTURE_DIR"]) / "mod.skiff" / "ship.cc", path)
before = ship_cc.read(path, PACKAGES)
shape_triple, hardpoints, revision = ship_cc.read_layout(path, PACKAGES)
width, height, cells = shape_triple
self.assertEqual(64, len(revision))
cells = list(cells)
cells[-1] = True
ship_cc.replace_layout(path, PACKAGES, before.ship.body[0], revision, [width, height, cells], hardpoints)
ship_cc.replace_lines(path, PACKAGES, before.ship.body[ship_cc.SCHEMATIC_LINES_SLOT])
after = ship_cc.read(path, PACKAGES)
self.assertEqual(before.ship.body, after.ship.body)
self.assertEqual(before.ship.envelope.key, after.ship.envelope.key)
self.assertEqual(before.ship.envelope.catalog_entry, after.ship.envelope.catalog_entry)
self.assertEqual(before.hull.envelope.key, after.hull.envelope.key)
self.assertEqual(before.hull.envelope.catalog_entry, after.hull.envelope.catalog_entry)
for slot in range(len(before.hull.body)):
if slot != ship_cc.HULL_SHAPE_SLOT:
self.assertEqual(before.hull.body[slot], after.hull.body[slot], f"hull slot {slot} changed")
self.assertTrue(after.hull.body[ship_cc.HULL_SHAPE_SLOT][0][2][-1])
kept = os.environ.get("SHIP_EDITED_DIR")
if kept:
target = Path(kept) / "mod.skiff"
target.mkdir(parents=True, exist_ok=True)
shutil.copy(path, target / "ship.cc")
shutil.copy(Path(os.environ["SHIP_FIXTURE_DIR"]) / "mod.skiff" / "skiff.glb", target / "skiff.glb")
class HardpointRowTests(unittest.TestCase):
def test_a_row_is_one_value_per_member_in_slot_order(self):
fields = dict(Type=1, Position=[2, 3], Shape="shape", Transform="mount", Rotation=2, Armor=4.0, FiringArc=90.0)