2026-09-26 18:14:36 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
|
|
|
using System.Linq;
|
2026-09-26 18:14:36 +02:00
|
|
|
using System.Threading.Tasks;
|
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
|
|
|
using GameCult.Caching.MessagePack;
|
|
|
|
|
using MessagePack;
|
2026-09-26 18:14:36 +02:00
|
|
|
using CultMath;
|
2026-09-30 03:06:43 +02:00
|
|
|
using GameCult.Caching;
|
2026-09-26 18:14:36 +02:00
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
public sealed class ShipAuthoringTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task StandaloneShipRoundTripsWithoutTouchingTheCatalog()
|
|
|
|
|
{
|
|
|
|
|
var root = Path.Combine(Path.GetTempPath(), "aetheria-ship-" + Guid.NewGuid().ToString("N"));
|
|
|
|
|
Directory.CreateDirectory(root);
|
|
|
|
|
var path = Path.Combine(root, "skiff.cc");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var ship = Fixture();
|
2026-09-30 03:06:43 +02:00
|
|
|
ship.Validate();
|
2026-09-26 18:14:36 +02:00
|
|
|
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
|
|
|
|
{
|
2026-09-30 03:06:43 +02:00
|
|
|
ShipAuthoringStore.Write(cache, ship.Hull, ship.Visual);
|
2026-09-26 18:14:36 +02:00
|
|
|
await cache.FlushAsync();
|
|
|
|
|
}
|
2026-10-12 03:54:30 +02:00
|
|
|
var (hull, visual, _) = ShipAuthoringStore.Read(path);
|
2026-09-30 03:06:43 +02:00
|
|
|
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);
|
2026-09-26 18:14:36 +02:00
|
|
|
}
|
|
|
|
|
finally { Directory.Delete(root, true); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void InvalidSchematicOrDanglingMountCannotBePublished()
|
|
|
|
|
{
|
|
|
|
|
var ship = Fixture();
|
|
|
|
|
ship.Hull.Shape.Cells[1, 0] = false;
|
2026-09-30 03:06:43 +02:00
|
|
|
Assert.Contains("outside the hull schematic", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
|
2026-09-26 18:14:36 +02:00
|
|
|
|
|
|
|
|
ship = Fixture();
|
2026-09-30 03:06:43 +02:00
|
|
|
ship.Visual.Anchors.RemoveAt(ship.Visual.Anchors.Count - 1);
|
|
|
|
|
Assert.Contains("has no model anchor", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
|
2026-09-26 18:14:36 +02:00
|
|
|
|
|
|
|
|
ship = Fixture();
|
2026-09-30 03:06:43 +02:00
|
|
|
ship.Visual.SchematicLines[0].Points[0] = float.NaN;
|
|
|
|
|
Assert.Contains("finite XYZ", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
|
2026-09-26 18:14:36 +02:00
|
|
|
|
|
|
|
|
ship = Fixture();
|
|
|
|
|
ship.Hull.Hardpoints.Add(new HardpointData
|
|
|
|
|
{
|
|
|
|
|
Type = HardpointType.Thruster,
|
|
|
|
|
Position = new int2(1, 0),
|
|
|
|
|
Shape = new Shape(),
|
|
|
|
|
Transform = "thruster.starboard"
|
|
|
|
|
});
|
2026-09-30 03:06:43 +02:00
|
|
|
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);
|
2026-09-26 18:14:36 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-30 03:06:43 +02:00
|
|
|
// 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";
|
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
|
|
|
Assert.Contains("names both a Unity prefab and a visual record", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
|
|
|
|
|
|
|
|
|
|
// A whitespace-only prefab is unset.
|
|
|
|
|
ship = Fixture();
|
|
|
|
|
ship.Hull.Prefab = " \t";
|
|
|
|
|
ship.Validate();
|
2026-09-30 03:06:43 +02:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
|
|
|
// The key is compared exactly: a differently-cased key is another record.
|
|
|
|
|
ship = Fixture();
|
|
|
|
|
ship.Hull.Visual = new CultRecordRef<ShipAuthoring>(new CultRecordKey("MOD-SHIP:mod.skiff"));
|
|
|
|
|
Assert.Contains("the hull must name its visual record mod-ship:mod.skiff", Assert.Throws<InvalidOperationException>(ship.Validate).Message);
|
|
|
|
|
|
2026-09-30 03:06:43 +02:00
|
|
|
Fixture().Validate();
|
|
|
|
|
}
|
|
|
|
|
|
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
|
|
|
// A hull with both a prefab and a visual is refused wherever hulls are validated or composed.
|
|
|
|
|
// ShipModCatalogTests.ComposeRefusesAShippedHullThatNamesTwoBodies covers Compose.
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RequireOneBodyRefusesBothAndAcceptsEitherAlone()
|
|
|
|
|
{
|
|
|
|
|
var hull = Fixture().Hull;
|
|
|
|
|
ShipAuthoringStore.RequireOneBody(hull, "skiff");
|
|
|
|
|
hull.Prefab = "Djinni";
|
|
|
|
|
Assert.Contains("skiff: a hull names one body", Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.RequireOneBody(hull, "skiff")).Message);
|
|
|
|
|
hull.Visual = default;
|
|
|
|
|
ShipAuthoringStore.RequireOneBody(hull, "skiff");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The ship authoring record held the whole hull at key 1 before S1.
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task LoadRefusesAShipAuthoringRecordThatStillCarriesTheRetiredEmbeddedHull()
|
|
|
|
|
{
|
|
|
|
|
using var directory = new TempDirectory();
|
|
|
|
|
var path = Path.Combine(directory.Path, "legacy.cc");
|
|
|
|
|
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
|
|
|
|
{
|
|
|
|
|
ShipAuthoringStore.Write(cache, Fixture().Hull, Fixture().Visual);
|
|
|
|
|
await cache.FlushAsync();
|
|
|
|
|
}
|
|
|
|
|
RewritePayload(path, "aetheria.ship_authoring", slots => { slots[1] = new object[] { "Skiff" }; });
|
|
|
|
|
foreach (var load in new Action[] { () => ShipAuthoringStore.Load(path), () => ShipAuthoringStore.Read(path) })
|
|
|
|
|
{
|
|
|
|
|
var message = Assert.Throws<InvalidOperationException>(load).Message;
|
|
|
|
|
Assert.Contains("legacy embedded hull at retired key 1", message);
|
|
|
|
|
Assert.Contains(path, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// An old file has no separate hull record at all; it is named for what it is, not for a missing hull.
|
|
|
|
|
var oldShape = Path.Combine(directory.Path, "old.cc");
|
|
|
|
|
using (var cache = ShipAuthoringStore.Open(oldShape, writable: true))
|
|
|
|
|
{
|
|
|
|
|
cache.UpsertAsync(typeof(ShipAuthoring), Fixture().Visual, ShipModCatalog.AuthoringKey("mod.skiff")).GetAwaiter().GetResult();
|
|
|
|
|
await cache.FlushAsync();
|
|
|
|
|
}
|
|
|
|
|
RewritePayload(oldShape, "aetheria.ship_authoring", slots => { slots[1] = new object[] { "Skiff" }; });
|
|
|
|
|
var oldMessage = Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(oldShape)).Message;
|
|
|
|
|
Assert.Contains("legacy embedded hull", oldMessage);
|
|
|
|
|
Assert.DoesNotContain("exactly one hull record", oldMessage);
|
|
|
|
|
|
|
|
|
|
// A nil in the retired slot is the shape every current file has.
|
|
|
|
|
RewritePayload(path, "aetheria.ship_authoring", slots => { slots[1] = null; });
|
|
|
|
|
ShipAuthoringStore.Load(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The layout editor's Python once accepted any msgpack value in a cell; C# then failed with a bare serializer exception.
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task LoadNamesTheFileWhoseRecordDoesNotDecode()
|
|
|
|
|
{
|
|
|
|
|
using var directory = new TempDirectory();
|
|
|
|
|
var path = Path.Combine(directory.Path, "cells.cc");
|
|
|
|
|
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
|
|
|
|
{
|
|
|
|
|
ShipAuthoringStore.Write(cache, Fixture().Hull, Fixture().Visual);
|
|
|
|
|
await cache.FlushAsync();
|
|
|
|
|
}
|
|
|
|
|
// ItemData.Shape is key 5: [[width, height, cells]].
|
|
|
|
|
RewritePayload(path, "aetheria.hulldata", slots => ((object[])((object[])slots[5])[0])[2] = new object[] { 5, false, true, false });
|
|
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(path));
|
|
|
|
|
Assert.Contains(path, error.Message);
|
2026-10-22 20:23:32 +02:00
|
|
|
// The pull names the record key and schema; the MessagePack failure is its cause.
|
|
|
|
|
var pull = Assert.IsType<InvalidDataException>(error.InnerException);
|
2026-10-22 20:39:29 +02:00
|
|
|
Assert.Contains("Record '" + ShipModCatalog.HullKey("mod.skiff") + "'", pull.Message);
|
|
|
|
|
Assert.Contains("schema", pull.Message);
|
2026-10-22 20:23:32 +02:00
|
|
|
Assert.IsAssignableFrom<MessagePackSerializationException>(pull.InnerException);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-11 09:50:22 +00:00
|
|
|
// A store header with a nil format stamp is refused by the runtime with CultStoreUnreadableException; Load names the file.
|
2026-10-22 20:23:32 +02:00
|
|
|
[Fact]
|
|
|
|
|
public void LoadNamesTheFileWhoseFormatStampIsNil()
|
|
|
|
|
{
|
|
|
|
|
using var directory = new TempDirectory();
|
|
|
|
|
var path = Path.Combine(directory.Path, "nilstamp.cc");
|
2026-11-11 09:50:22 +00:00
|
|
|
// The runtime no longer writes a store without a format stamp, so the header is spelled by hand: [nil, [], []].
|
|
|
|
|
File.WriteAllBytes(path, new byte[] { 0x93, 0xC0, 0x90, 0x90 });
|
2026-10-22 20:23:32 +02:00
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(path));
|
|
|
|
|
Assert.Contains(path, error.Message);
|
2026-11-11 09:50:22 +00:00
|
|
|
Assert.IsType<CultStoreUnreadableException>(error.InnerException);
|
2026-10-22 23:34:08 +02:00
|
|
|
}
|
|
|
|
|
|
2026-11-11 09:50:22 +00:00
|
|
|
// A store format this runtime does not know is refused on read with CultStoreUnreadableException from the attach; Load names the file.
|
2026-10-22 23:34:08 +02:00
|
|
|
[Fact]
|
|
|
|
|
public async Task LoadNamesTheFileWhoseStoreFormatIsNewer()
|
|
|
|
|
{
|
|
|
|
|
using var directory = new TempDirectory();
|
|
|
|
|
var path = Path.Combine(directory.Path, "newer.cc");
|
|
|
|
|
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
|
|
|
|
{
|
|
|
|
|
ShipAuthoringStore.Write(cache, Fixture().Hull, Fixture().Visual);
|
|
|
|
|
await cache.FlushAsync();
|
|
|
|
|
}
|
|
|
|
|
var snapshot = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(path));
|
|
|
|
|
snapshot.FormatVersion = "cultcache.store.v9";
|
|
|
|
|
File.WriteAllBytes(path, CultDocumentMessagePackSerialization.SerializeSnapshot(snapshot));
|
|
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Load(path));
|
|
|
|
|
Assert.Contains(path, error.Message);
|
2026-11-11 09:50:22 +00:00
|
|
|
Assert.IsType<CultStoreUnreadableException>(error.InnerException);
|
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Decodes one record's payload of the named schema to its slot array, lets the edit change it, and stores it again.
|
|
|
|
|
private static void RewritePayload(string path, string schemaName, Action<object[]> edit)
|
|
|
|
|
{
|
|
|
|
|
var snapshot = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(path));
|
|
|
|
|
var schemaId = snapshot.SchemaCatalog.Single(entry => entry.SchemaName == schemaName).SchemaId;
|
|
|
|
|
var record = snapshot.Records.Single(candidate => candidate.SchemaId == schemaId);
|
|
|
|
|
var slots = MessagePackSerializer.Deserialize<object[]>(record.Payload);
|
|
|
|
|
edit(slots);
|
|
|
|
|
record.Payload = MessagePackSerializer.Serialize(slots);
|
|
|
|
|
File.WriteAllBytes(path, CultDocumentMessagePackSerialization.SerializeSnapshot(snapshot));
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 03:06:43 +02:00
|
|
|
[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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-03 14:39:08 +02:00
|
|
|
private static readonly string[] AllRoles =
|
|
|
|
|
{
|
2026-10-10 05:23:02 +02:00
|
|
|
"map-icon", "hull-collider", "shield", "tractor", "thruster-emitter", "weapon-mount", "weapon-muzzle", "radiator-mesh"
|
2026-10-03 14:39:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// The fixture with its thruster swapped for one hardpoint of the given type at mount id "mount", and no anchor for it.
|
|
|
|
|
private static ShipParts WithOnly(HardpointType type)
|
Ship S2 fixes: structural anchors are not mounts, mod presets refused, one bad mod never bricks the boot
- Validate: a hardpoint's anchor role is fixed by its type (thruster-emitter, radiator-mesh, else articulation); ShipModPlan's
duplicate role check is deleted.
- Loadouts.Commit refuses a preset naming a mod design (mod-hull:/mod-ship:), so the shipped catalog never references a mod.
- Compose quarantines each package: a bad package is excluded and named, a collision excludes every package involved; the
game boots on the rest (or the shipped catalog) and the main menu lists the exclusions.
- RequireDesigns refuses a save with a null item or lot instead of throwing NullReferenceException.
- Tests: per structural role, muzzle id ties, every slot/zone/lot in RequireDesigns, listing order, exclusion cases.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 08:30:52 +02:00
|
|
|
{
|
|
|
|
|
var ship = Fixture();
|
2026-10-03 14:39:08 +02:00
|
|
|
ship.Hull.Hardpoints.Clear();
|
|
|
|
|
ship.Visual.Anchors.RemoveAll(anchor => anchor.Id == "thruster.port");
|
|
|
|
|
ship.Hull.Hardpoints.Add(new HardpointData { Type = type, Position = new int2(0, 0), Shape = new Shape(), Transform = "mount" });
|
|
|
|
|
return ship;
|
|
|
|
|
}
|
Ship S2 fixes: structural anchors are not mounts, mod presets refused, one bad mod never bricks the boot
- Validate: a hardpoint's anchor role is fixed by its type (thruster-emitter, radiator-mesh, else articulation); ShipModPlan's
duplicate role check is deleted.
- Loadouts.Commit refuses a preset naming a mod design (mod-hull:/mod-ship:), so the shipped catalog never references a mod.
- Compose quarantines each package: a bad package is excluded and named, a collision excludes every package involved; the
game boots on the rest (or the shipped catalog) and the main menu lists the exclusions.
- RequireDesigns refuses a save with a null item or lot instead of throwing NullReferenceException.
- Tests: per structural role, muzzle id ties, every slot/zone/lot in RequireDesigns, listing order, exclusion cases.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 08:30:52 +02:00
|
|
|
|
2026-10-03 14:39:08 +02:00
|
|
|
private static string Refusal(ShipParts ship) => Assert.Throws<InvalidOperationException>(ship.Validate).Message;
|
|
|
|
|
|
|
|
|
|
// Mount anchors exist only for hardpoints that show on the model: weapons, radiators and thrusters.
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(HardpointType.Hull), InlineData(HardpointType.Tool), InlineData(HardpointType.Thermal), InlineData(HardpointType.WarpDrive),
|
|
|
|
|
InlineData(HardpointType.Reactor), InlineData(HardpointType.Shield), InlineData(HardpointType.Sensors),
|
2026-10-08 13:44:48 +02:00
|
|
|
InlineData(HardpointType.ControlModule)]
|
2026-10-03 14:39:08 +02:00
|
|
|
public void AnInternalHardpointCarriesNoAnchor(HardpointType type)
|
|
|
|
|
{
|
|
|
|
|
WithOnly(type).Validate();
|
|
|
|
|
|
|
|
|
|
// Any anchor taking the mount's id is refused, a mount role or not. (The four structural roles are one-of-a-kind,
|
|
|
|
|
// so they are covered by renaming the existing anchor.)
|
|
|
|
|
foreach (var role in AllRoles)
|
|
|
|
|
{
|
|
|
|
|
var ship = WithOnly(type);
|
|
|
|
|
var existing = ship.Visual.Anchors.FirstOrDefault(anchor => anchor.Role == role);
|
|
|
|
|
if (existing != null) existing.Id = "mount";
|
|
|
|
|
else ship.Visual.Anchors.Add(new ShipAnchor { Id = "mount", Role = role, ModelNodeId = "mount" });
|
|
|
|
|
Assert.Contains($"mod.skiff: {type} hardpoint mount is internal, so no anchor may take its id", Refusal(ship));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(HardpointType.Thruster, "thruster-emitter")]
|
|
|
|
|
[InlineData(HardpointType.Radiator, "radiator-mesh")]
|
|
|
|
|
[InlineData(HardpointType.Energy, "weapon-mount")]
|
|
|
|
|
[InlineData(HardpointType.Ballistic, "weapon-mount")]
|
|
|
|
|
[InlineData(HardpointType.Launcher, "weapon-mount")]
|
|
|
|
|
public void EachVisibleHardpointNeedsItsRoleAnchor(HardpointType type, string wanted)
|
|
|
|
|
{
|
|
|
|
|
ShipParts Rig()
|
|
|
|
|
{
|
|
|
|
|
var ship = WithOnly(type);
|
|
|
|
|
if (ShipAuthoringStore.IsWeapon(type))
|
|
|
|
|
ship.Visual.Anchors.Add(new ShipAnchor { Id = "mount.muzzle", Role = "weapon-muzzle", ModelNodeId = "muzzle", ParentId = "mount" });
|
|
|
|
|
return ship;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.Contains($"mod.skiff: {type} hardpoint mount has no model anchor", Refusal(Rig()));
|
|
|
|
|
|
|
|
|
|
// A structural anchor (the map icon, the collider...) whose id is the mount, or a mount anchor of the wrong role.
|
|
|
|
|
foreach (var role in AllRoles.Where(role => role != wanted))
|
|
|
|
|
{
|
|
|
|
|
var ship = Rig();
|
|
|
|
|
var existing = ship.Visual.Anchors.FirstOrDefault(anchor => anchor.Role == role);
|
|
|
|
|
if (existing != null) existing.Id = "mount";
|
|
|
|
|
else ship.Visual.Anchors.Add(new ShipAnchor { Id = "mount", Role = role, ModelNodeId = "mount" });
|
|
|
|
|
Assert.Contains($"mod.skiff: {type} hardpoint mount needs a {wanted} anchor of that id", Refusal(ship));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var valid = Rig();
|
|
|
|
|
valid.Visual.Anchors.Add(new ShipAnchor { Id = "mount", Role = wanted, ModelNodeId = "mount" });
|
|
|
|
|
valid.Validate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called on Validate itself: a mount-role anchor is the mount of a hardpoint of its own type, never a loose node and
|
|
|
|
|
// never another type's mount.
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("thruster-emitter", HardpointType.Radiator)]
|
|
|
|
|
[InlineData("thruster-emitter", HardpointType.Energy)]
|
|
|
|
|
[InlineData("thruster-emitter", HardpointType.Reactor)]
|
|
|
|
|
[InlineData("radiator-mesh", HardpointType.Thruster)]
|
|
|
|
|
[InlineData("radiator-mesh", HardpointType.Launcher)]
|
|
|
|
|
[InlineData("radiator-mesh", HardpointType.Sensors)]
|
|
|
|
|
[InlineData("weapon-mount", HardpointType.Thruster)]
|
|
|
|
|
[InlineData("weapon-mount", HardpointType.Radiator)]
|
|
|
|
|
[InlineData("weapon-mount", HardpointType.Tool)]
|
|
|
|
|
public void AMountRoleAnchorMustBeAMountOfItsType(string role, HardpointType otherType)
|
|
|
|
|
{
|
|
|
|
|
string Refused(ShipParts ship) =>
|
|
|
|
|
Assert.Throws<InvalidOperationException>(() => ShipAuthoringStore.Validate(ship.Hull, ship.Visual)).Message;
|
|
|
|
|
|
|
|
|
|
var loose = Fixture();
|
|
|
|
|
loose.Visual.Anchors.Add(new ShipAnchor { Id = "loose", Role = role, ModelNodeId = "loose" });
|
|
|
|
|
Assert.Contains($"mod.skiff: {role} anchor loose must be the mount of a hardpoint of its type", Refused(loose));
|
|
|
|
|
|
|
|
|
|
// The anchor takes the id of a hardpoint of another type; whichever side the validator reads first, it refuses.
|
|
|
|
|
var other = WithOnly(otherType);
|
|
|
|
|
other.Visual.Anchors.Add(new ShipAnchor { Id = "mount", Role = role, ModelNodeId = "mount" });
|
|
|
|
|
if (ShipAuthoringStore.IsWeapon(otherType))
|
|
|
|
|
other.Visual.Anchors.Add(new ShipAnchor { Id = "mount.muzzle", Role = "weapon-muzzle", ModelNodeId = "muzzle", ParentId = "mount" });
|
|
|
|
|
Assert.Contains($"mod.skiff: {otherType} hardpoint mount ", Refused(other));
|
Ship S2 fixes: structural anchors are not mounts, mod presets refused, one bad mod never bricks the boot
- Validate: a hardpoint's anchor role is fixed by its type (thruster-emitter, radiator-mesh, else articulation); ShipModPlan's
duplicate role check is deleted.
- Loadouts.Commit refuses a preset naming a mod design (mod-hull:/mod-ship:), so the shipped catalog never references a mod.
- Compose quarantines each package: a bad package is excluded and named, a collision excludes every package involved; the
game boots on the rest (or the shipped catalog) and the main menu lists the exclusions.
- RequireDesigns refuses a save with a null item or lot instead of throwing NullReferenceException.
- Tests: per structural role, muzzle id ties, every slot/zone/lot in RequireDesigns, listing order, exclusion cases.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 08:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-10-03 14:39:08 +02:00
|
|
|
public void MuzzleRulesBelongToTheValidator()
|
Ship S2 fixes: structural anchors are not mounts, mod presets refused, one bad mod never bricks the boot
- Validate: a hardpoint's anchor role is fixed by its type (thruster-emitter, radiator-mesh, else articulation); ShipModPlan's
duplicate role check is deleted.
- Loadouts.Commit refuses a preset naming a mod design (mod-hull:/mod-ship:), so the shipped catalog never references a mod.
- Compose quarantines each package: a bad package is excluded and named, a collision excludes every package involved; the
game boots on the rest (or the shipped catalog) and the main menu lists the exclusions.
- RequireDesigns refuses a save with a null item or lot instead of throwing NullReferenceException.
- Tests: per structural role, muzzle id ties, every slot/zone/lot in RequireDesigns, listing order, exclusion cases.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 08:30:52 +02:00
|
|
|
{
|
2026-10-03 14:39:08 +02:00
|
|
|
ShipParts Armed()
|
Ship S2 fixes: structural anchors are not mounts, mod presets refused, one bad mod never bricks the boot
- Validate: a hardpoint's anchor role is fixed by its type (thruster-emitter, radiator-mesh, else articulation); ShipModPlan's
duplicate role check is deleted.
- Loadouts.Commit refuses a preset naming a mod design (mod-hull:/mod-ship:), so the shipped catalog never references a mod.
- Compose quarantines each package: a bad package is excluded and named, a collision excludes every package involved; the
game boots on the rest (or the shipped catalog) and the main menu lists the exclusions.
- RequireDesigns refuses a save with a null item or lot instead of throwing NullReferenceException.
- Tests: per structural role, muzzle id ties, every slot/zone/lot in RequireDesigns, listing order, exclusion cases.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 08:30:52 +02:00
|
|
|
{
|
2026-10-03 14:39:08 +02:00
|
|
|
var ship = Fixture();
|
|
|
|
|
ship.Hull.Hardpoints.Add(new HardpointData { Type = HardpointType.Energy, Position = new int2(0, 0), Shape = new Shape(), Transform = "gun" });
|
|
|
|
|
ship.Visual.Anchors.Add(new ShipAnchor { Id = "gun", Role = "weapon-mount", ModelNodeId = "gun" });
|
|
|
|
|
ship.Visual.Anchors.Add(new ShipAnchor { Id = "gun.b", Role = "weapon-muzzle", ModelNodeId = "gun-b", ParentId = "gun", Order = 0 });
|
|
|
|
|
ship.Visual.Anchors.Add(new ShipAnchor { Id = "gun.a", Role = "weapon-muzzle", ModelNodeId = "gun-a", ParentId = "gun", Order = 0 });
|
|
|
|
|
ship.Visual.Anchors.Add(new ShipAnchor { Id = "gun.z", Role = "weapon-muzzle", ModelNodeId = "gun-z", ParentId = "gun", Order = -1 });
|
|
|
|
|
return ship;
|
Ship S2 fixes: structural anchors are not mounts, mod presets refused, one bad mod never bricks the boot
- Validate: a hardpoint's anchor role is fixed by its type (thruster-emitter, radiator-mesh, else articulation); ShipModPlan's
duplicate role check is deleted.
- Loadouts.Commit refuses a preset naming a mod design (mod-hull:/mod-ship:), so the shipped catalog never references a mod.
- Compose quarantines each package: a bad package is excluded and named, a collision excludes every package involved; the
game boots on the rest (or the shipped catalog) and the main menu lists the exclusions.
- RequireDesigns refuses a save with a null item or lot instead of throwing NullReferenceException.
- Tests: per structural role, muzzle id ties, every slot/zone/lot in RequireDesigns, listing order, exclusion cases.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 08:30:52 +02:00
|
|
|
}
|
2026-10-03 14:39:08 +02:00
|
|
|
|
|
|
|
|
var orphan = Armed();
|
|
|
|
|
orphan.Visual.Anchors.Single(anchor => anchor.Id == "gun.z").ParentId = null;
|
|
|
|
|
Assert.Contains("mod.skiff: muzzle gun.z must be parented to a weapon hardpoint's mount", Refusal(orphan));
|
|
|
|
|
|
|
|
|
|
var onThruster = Armed();
|
|
|
|
|
onThruster.Visual.Anchors.Single(anchor => anchor.Id == "gun.z").ParentId = "thruster.port";
|
|
|
|
|
Assert.Contains("mod.skiff: muzzle gun.z must be parented to a weapon hardpoint's mount", Refusal(onThruster));
|
|
|
|
|
|
|
|
|
|
var unarmed = Armed();
|
|
|
|
|
unarmed.Visual.Anchors.RemoveAll(anchor => anchor.Role == "weapon-muzzle");
|
|
|
|
|
Assert.Contains("mod.skiff: weapon hardpoint gun needs at least one muzzle anchor", Refusal(unarmed));
|
|
|
|
|
|
2026-10-03 14:54:03 +02:00
|
|
|
// Each weapon needs a muzzle of its own: another weapon's muzzle does not arm it.
|
|
|
|
|
var second = Armed();
|
|
|
|
|
second.Hull.Shape.Cells[0, 1] = true;
|
|
|
|
|
second.Hull.Hardpoints.Add(new HardpointData { Type = HardpointType.Launcher, Position = new int2(0, 1), Shape = new Shape(), Transform = "tube" });
|
|
|
|
|
second.Visual.Anchors.Add(new ShipAnchor { Id = "tube", Role = "weapon-mount", ModelNodeId = "tube" });
|
|
|
|
|
Assert.Contains("mod.skiff: weapon hardpoint tube needs at least one muzzle anchor", Refusal(second));
|
|
|
|
|
|
2026-10-03 14:39:08 +02:00
|
|
|
// A valid pair plans without a refusal of the plan's own; muzzles by Order, then id ordinally.
|
|
|
|
|
var valid = Armed();
|
|
|
|
|
var (mount, muzzles) = Assert.Single(ShipModPlan.Build(valid.Hull, valid.Visual).Weapons);
|
|
|
|
|
Assert.Equal("gun", mount);
|
|
|
|
|
Assert.Equal(new[] { "gun.z", "gun.a", "gun.b" }, muzzles);
|
Ship S2 fixes: structural anchors are not mounts, mod presets refused, one bad mod never bricks the boot
- Validate: a hardpoint's anchor role is fixed by its type (thruster-emitter, radiator-mesh, else articulation); ShipModPlan's
duplicate role check is deleted.
- Loadouts.Commit refuses a preset naming a mod design (mod-hull:/mod-ship:), so the shipped catalog never references a mod.
- Compose quarantines each package: a bad package is excluded and named, a collision excludes every package involved; the
game boots on the rest (or the shipped catalog) and the main menu lists the exclusions.
- RequireDesigns refuses a save with a null item or lot instead of throwing NullReferenceException.
- Tests: per structural role, muzzle id ties, every slot/zone/lot in RequireDesigns, listing order, exclusion cases.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 08:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-30 03:06:43 +02:00
|
|
|
internal static ShipParts Fixture()
|
2026-09-26 18:14:36 +02:00
|
|
|
{
|
|
|
|
|
var shape = new Shape(2, 2);
|
|
|
|
|
shape.Cells[0, 0] = true;
|
|
|
|
|
shape.Cells[1, 0] = true;
|
2026-09-30 03:06:43 +02:00
|
|
|
return new ShipParts
|
2026-09-26 18:14:36 +02:00
|
|
|
{
|
|
|
|
|
Hull = new HullData
|
|
|
|
|
{
|
|
|
|
|
Name = "Skiff",
|
|
|
|
|
Shape = shape,
|
2026-10-12 03:54:30 +02:00
|
|
|
Behaviors = { new VelocityLimitData() },
|
2026-09-30 03:06:43 +02:00
|
|
|
Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey("mod.skiff")),
|
2026-09-26 18:14:36 +02:00
|
|
|
Hardpoints = new List<HardpointData>
|
|
|
|
|
{
|
|
|
|
|
new HardpointData
|
|
|
|
|
{
|
|
|
|
|
Type = HardpointType.Thruster,
|
|
|
|
|
Position = new int2(1, 0),
|
|
|
|
|
Shape = new Shape(),
|
|
|
|
|
Transform = "thruster.port"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-09-30 03:06:43 +02:00
|
|
|
Visual = new ShipAuthoring
|
2026-09-26 18:14:36 +02:00
|
|
|
{
|
2026-09-30 03:06:43 +02:00
|
|
|
Id = "mod.skiff",
|
|
|
|
|
ModelAsset = "skiff.glb",
|
|
|
|
|
Anchors = new List<ShipAnchor>
|
|
|
|
|
{
|
|
|
|
|
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>
|
2026-09-26 18:14:36 +02:00
|
|
|
{
|
2026-09-30 03:06:43 +02:00
|
|
|
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 }
|
|
|
|
|
}
|
2026-09-26 18:14:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-10-03 17:07:09 +02:00
|
|
|
|
|
|
|
|
// create --like: the shipped hull's stats, never its body or layout. Every member a reference carries is copied,
|
|
|
|
|
// including one this test does not name, because the copy goes through the type's own serializer.
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HullLikeCopiesStatsButNotTheBodyOrLayout()
|
|
|
|
|
{
|
|
|
|
|
var reference = new HullData
|
|
|
|
|
{
|
|
|
|
|
Name = "Djinni", Price = 1234, Durability = 56, Mass = 78, Armor = 9, Drag = 0.25f, CanTow = true,
|
|
|
|
|
HullType = HullType.Ship, Shape = new Shape(3, 2), Prefab = "prefab-guid", Schematic = "schematic-guid",
|
|
|
|
|
Hardpoints = new List<HardpointData> { new HardpointData { Type = HardpointType.Thruster, Shape = new Shape(), Transform = "aft" } },
|
|
|
|
|
};
|
|
|
|
|
reference.Shape.Cells[2, 1] = true;
|
|
|
|
|
var hull = ShipAuthoringStore.HullLike(reference, "Gale", "mod.gale");
|
|
|
|
|
|
|
|
|
|
Assert.Equal((1234, 56f, 78f, 9f, 0.25f, true, HullType.Ship),
|
|
|
|
|
(hull.Price, hull.Durability, hull.Mass, hull.Armor, hull.Drag, hull.CanTow, hull.HullType));
|
|
|
|
|
Assert.Equal("Gale", hull.Name);
|
|
|
|
|
Assert.Equal((1, 1, true), (hull.Shape.Width, hull.Shape.Height, hull.Shape.Cells[0, 0]));
|
|
|
|
|
Assert.Empty(hull.Hardpoints);
|
|
|
|
|
Assert.Null(hull.Prefab);
|
|
|
|
|
Assert.Null(hull.Schematic);
|
|
|
|
|
Assert.Equal(ShipModCatalog.AuthoringKey("mod.gale"), hull.Visual.Key);
|
|
|
|
|
// A copy, not the reference: the reference keeps its own body.
|
|
|
|
|
Assert.Equal(("Djinni", "prefab-guid", 1), (reference.Name, reference.Prefab, reference.Hardpoints.Count));
|
|
|
|
|
}
|
2026-09-26 18:14:36 +02:00
|
|
|
}
|
2026-09-30 03:06:43 +02:00
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|