Station packages: ship-authoring kind writes a station hull's Kind; create --like takes a station; a station assembles as EntityInstance
kind <ship.cc> <kind-id> is the one writer of a package station's Kind, judged by StationKinds.HullKindFault over the shipped catalog before the file is opened writable; validate (and push's verdict) judge a station package's kind with the same rule. HullLike clears Kind. ShipModShips.Assemble makes a ShipInstance and tractor only for HullType.Ship; any other hull gets a plain EntityInstance. The packager manifest gains optional kind, written by ship-authoring kind after stats. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7bc6226c02
commit
92b2df7b12
9 changed files with 148 additions and 32 deletions
|
|
@ -15,6 +15,9 @@ using UnityEngine;
|
|||
// accepts it, so it composes, and the importer cannot build it, so Preload faults Loading with ImportFault naming it.
|
||||
// RemovePackage then moves it aside and the next Compose leaves it out.
|
||||
//
|
||||
// A Station package takes the same path to an EntityInstance with no ShipInstance (a station does not fly), checked without
|
||||
// thruster or weapon asserts; its .broken sibling swaps the map-icon anchor with the shield anchor, which has no mesh.
|
||||
//
|
||||
// Unity -batchmode -nographics -projectPath <project> -executeMethod ShipModPlaySmoke.Run
|
||||
// -shipModPath <mods>/<id>/ship.cc [-shippedCatalog GameData/Aetheria.cc] -logFile <log>
|
||||
//
|
||||
|
|
@ -39,11 +42,12 @@ public static class ShipModPlaySmoke
|
|||
if (packagePath == null) throw new InvalidOperationException("-shipModPath <package/ship.cc> is required");
|
||||
var package = ShipModCatalog.ReadPackage(packagePath);
|
||||
Install(package.Visual.Id, package, modsRoot, Path.GetFullPath(packagePath));
|
||||
var station = package.Hull.HullType == HullType.Station;
|
||||
var broken = InstallSibling(package, modsRoot, ".broken", ship =>
|
||||
{
|
||||
var mapIcon = ship.Anchors.Single(anchor => anchor.Role == "map-icon");
|
||||
var muzzle = ship.Anchors.First(anchor => anchor.Role == "weapon-muzzle");
|
||||
(mapIcon.ModelNodeId, muzzle.ModelNodeId) = (muzzle.ModelNodeId, mapIcon.ModelNodeId);
|
||||
var meshless = station ? ship.Anchors.Single(anchor => anchor.Role == "shield") : ship.Anchors.First(anchor => anchor.Role == "weapon-muzzle");
|
||||
(mapIcon.ModelNodeId, meshless.ModelNodeId) = (meshless.ModelNodeId, mapIcon.ModelNodeId);
|
||||
}, null);
|
||||
var shipped = Path.GetFullPath(Option("-shippedCatalog", "GameData/Aetheria.cc"));
|
||||
var composition = ShipModCatalog.Compose(shipped, derived, modsRoot);
|
||||
|
|
@ -60,13 +64,23 @@ public static class ShipModPlaySmoke
|
|||
var hull = Hull(package.Hull.Name);
|
||||
|
||||
zone = new GameObject("Play Smoke Zone");
|
||||
var ship = ShipModShips.Instantiate(hull, zone.transform).GetComponent<ShipInstance>();
|
||||
if (ship == null) throw new InvalidOperationException("The mod ship body has no ShipInstance.");
|
||||
var body = ShipModShips.Instantiate(hull, zone.transform);
|
||||
var ship = body.GetComponent<EntityInstance>();
|
||||
if (ship == null) throw new InvalidOperationException("The mod hull's body has no EntityInstance.");
|
||||
var thrusters = ship.ThrusterHardpoints?.Length ?? 0;
|
||||
var weapons = ship.WeaponHardpoints?.Length ?? 0;
|
||||
if (thrusters == 0) throw new InvalidOperationException("ThrusterHardpoints is empty.");
|
||||
if (weapons == 0 || ship.WeaponHardpoints.Any(node => node.FiringPoint == null || node.FiringPoint.Length == 0))
|
||||
throw new InvalidOperationException("WeaponHardpoints is empty or a weapon has no muzzle.");
|
||||
if (station)
|
||||
{
|
||||
// A station renders as an EntityInstance: a ShipInstance would throw in Update (SetEntity returns before _thrusters).
|
||||
if (body.GetComponent<ShipInstance>() != null) throw new InvalidOperationException("A station body must not carry a ShipInstance.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ship is not ShipInstance) throw new InvalidOperationException("The mod ship body has no ShipInstance.");
|
||||
if (thrusters == 0) throw new InvalidOperationException("ThrusterHardpoints is empty.");
|
||||
if (weapons == 0 || ship.WeaponHardpoints.Any(node => node.FiringPoint == null || node.FiringPoint.Length == 0))
|
||||
throw new InvalidOperationException("WeaponHardpoints is empty or a weapon has no muzzle.");
|
||||
}
|
||||
if (ship.HullColliders == null || ship.HullColliders.Length != 1)
|
||||
throw new InvalidOperationException("The ship needs exactly one hull collider.");
|
||||
var collider = ship.HullColliders[0].GetComponent<MeshCollider>();
|
||||
|
|
|
|||
|
|
@ -47,17 +47,24 @@ public static class ShipModPreview
|
|||
if (template == null) throw new InvalidOperationException($"{TemplatePath} is missing or has no ShipModTemplate.");
|
||||
var plan = ShipModPlan.Build(package.Hull, package.Visual);
|
||||
var ship = ShipModShips.Assemble(visual, package.Hull, package.Visual, template);
|
||||
// A station is a plain EntityInstance: ShipInstance flies, and SetEntity would read thrusters it does not have.
|
||||
if ((package.Hull.HullType == HullType.Ship) != (ship is ShipInstance))
|
||||
throw new InvalidOperationException($"assembled: a {package.Hull.HullType} hull got {ship.GetType().Name}; only a Ship gets a ShipInstance.");
|
||||
CheckShip(ship, plan, "assembled");
|
||||
|
||||
// Instantiate clones the assembled root, and Unity must remap every array reference into the clone.
|
||||
var clone = UnityEngine.Object.Instantiate(ship.gameObject).GetComponent<ShipInstance>();
|
||||
try { CheckShip(clone, plan, "clone"); CheckExhaust(clone); }
|
||||
var clone = UnityEngine.Object.Instantiate(ship.gameObject).GetComponent<EntityInstance>();
|
||||
try
|
||||
{
|
||||
CheckShip(clone, plan, "clone");
|
||||
if (clone is ShipInstance flier) CheckExhaust(flier);
|
||||
}
|
||||
finally { UnityEngine.Object.DestroyImmediate(clone.gameObject); }
|
||||
Debug.Log($"SHIP_MOD_ASSEMBLY_SMOKE thrusters={plan.Thrusters.Length} exhaust=ok collider=hidden " +
|
||||
$"weapons={plan.Weapons.Length} radiators={plan.Radiators.Length}");
|
||||
}
|
||||
|
||||
private static void CheckShip(ShipInstance ship, ShipModPlan plan, string what)
|
||||
private static void CheckShip(EntityInstance ship, ShipModPlan plan, string what)
|
||||
{
|
||||
void Require(bool ok, string claim) { if (!ok) throw new InvalidOperationException($"{what}: {claim}"); }
|
||||
bool Inside(Component part) => part != null && part.transform.IsChildOf(ship.transform);
|
||||
|
|
@ -66,7 +73,8 @@ public static class ShipModPreview
|
|||
Require(ship.HullColliders[0].GetComponentsInChildren<Renderer>(true).All(renderer =>
|
||||
renderer.sharedMaterials.All(material => material == ship.InvisibleMaterial)),
|
||||
"a hull collider that draws nothing");
|
||||
Require(Inside(ship.MapIcon) && Inside(ship.Shield) && Inside(ship.TractorBeam), "map icon, shield and tractor inside the ship");
|
||||
Require(Inside(ship.MapIcon) && Inside(ship.Shield) && (ship is not ShipInstance flier || Inside(flier.TractorBeam)),
|
||||
"map icon, shield and tractor inside the ship");
|
||||
Require(ship.ThrusterHardpoints.Select(node => node.name).SequenceEqual(plan.Thrusters) &&
|
||||
ship.ThrusterHardpoints.All(node => Inside(node) && Inside(node.Emitter) &&
|
||||
node.Emitter.sharedMaterials.All(material => material == ship.InvisibleMaterial)),
|
||||
|
|
|
|||
|
|
@ -85,10 +85,11 @@ public static class ShipModShips
|
|||
return body;
|
||||
}
|
||||
|
||||
// Fills a ShipInstance on the visual's root from its anchors, as ShipModPlan says; the shared effects come from the
|
||||
// Fills an instance on the visual's root from its anchors, as ShipModPlan says; the shared effects come from the
|
||||
// template. Nothing here decides a slot: the plan does. The schematic lines stay in the prototype but are hidden in
|
||||
// world; the in-world ship is the GLB.
|
||||
public static ShipInstance Assemble(ShipModVisual.Instance visual, HullData hull, ShipAuthoring ship, ShipModTemplate template)
|
||||
// world; the in-world ship is the GLB. A Ship hull gets a ShipInstance and a tractor beam; any other hull (a station)
|
||||
// gets a plain EntityInstance, because ShipInstance flies (SetEntity and Update read its thrusters) and a station does not.
|
||||
public static EntityInstance Assemble(ShipModVisual.Instance visual, HullData hull, ShipAuthoring ship, ShipModTemplate template)
|
||||
{
|
||||
var plan = ShipModPlan.Build(hull, ship);
|
||||
var minimap = LayerMask.NameToLayer("Minimap");
|
||||
|
|
@ -135,8 +136,14 @@ public static class ShipModShips
|
|||
var shield = Object.Instantiate(template.Shield.GetComponent<ShieldManager>(), shieldMarker, false);
|
||||
Reset(shield.transform);
|
||||
AddOrGet<ShieldEnvelope>(shield.gameObject);
|
||||
var tractor = Object.Instantiate(template.TractorBeam.GetComponent<TractorBeam>(), Node(plan.Tractor), false);
|
||||
Reset(tractor.transform);
|
||||
var isShip = hull.HullType == HullType.Ship;
|
||||
// The tractor anchor stays required by the plan; a station leaves it unused.
|
||||
TractorBeam tractor = null;
|
||||
if (isShip)
|
||||
{
|
||||
tractor = Object.Instantiate(template.TractorBeam.GetComponent<TractorBeam>(), Node(plan.Tractor), false);
|
||||
Reset(tractor.transform);
|
||||
}
|
||||
|
||||
var thrusters = plan.Thrusters.Select(id =>
|
||||
{
|
||||
|
|
@ -164,7 +171,7 @@ public static class ShipModShips
|
|||
var lines = visual.Root.transform.Find("Schematic Lines");
|
||||
if (lines != null) lines.gameObject.SetActive(false);
|
||||
|
||||
var instance = AddOrGet<ShipInstance>(visual.Root);
|
||||
EntityInstance instance = isShip ? AddOrGet<ShipInstance>(visual.Root) : AddOrGet<EntityInstance>(visual.Root);
|
||||
instance.MapIcon = mapIcon;
|
||||
instance.InfluencePrefab = null;
|
||||
instance.PingPrefab = template.Ping.transform;
|
||||
|
|
@ -176,7 +183,7 @@ public static class ShipModShips
|
|||
instance.RadiatorHardpoints = radiators;
|
||||
instance.ArticulationPoints = Array.Empty<ArticulationPoint>();
|
||||
instance.DestroyEffect = template.DestroyEffect;
|
||||
instance.TractorBeam = tractor;
|
||||
if (instance is ShipInstance flier) flier.TractorBeam = tractor;
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -123,8 +123,8 @@ public static class ShipAuthoringStore
|
|||
cache.Remove(ShipModCatalog.ProductKey(shipId, maker));
|
||||
|
||||
// A new mod hull that flies like a shipped one. Every member of the reference is copied through the type's own
|
||||
// MessagePack round trip, so a member added to HullData later is copied too; then the six that are the shipped ship's
|
||||
// own body and layout are reset: Name, Shape (one occupied cell, so the record loads), Hardpoints, Prefab, Schematic,
|
||||
// MessagePack round trip, so a member added to HullData later is copied too; then the seven that are the shipped ship's
|
||||
// own body and layout are reset: Name, Shape (one occupied cell, so the record loads), Hardpoints, Prefab, Schematic, Kind,
|
||||
// and Visual, which names this mod's visual record.
|
||||
public static HullData HullLike(HullData reference, string name, string shipId)
|
||||
{
|
||||
|
|
@ -135,6 +135,8 @@ public static class ShipAuthoringStore
|
|||
hull.Hardpoints = new List<HardpointData>();
|
||||
hull.Prefab = null;
|
||||
hull.Schematic = null;
|
||||
// A station's kind is its own fact, written by ship-authoring kind; a like hull's is never copied.
|
||||
hull.Kind = default;
|
||||
hull.Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey(shipId));
|
||||
return hull;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -680,6 +680,54 @@ public sealed class ShipModCatalogTests : IDisposable
|
|||
Assert.True(File.Exists(target), error);
|
||||
}
|
||||
|
||||
// A station package: create --like Zenith makes a Station and never copies Zenith's kind; kind is the one writer of it, judged
|
||||
// by the one kind rule against the shipped catalog; a refusal leaves the file byte-identical.
|
||||
[Fact]
|
||||
public void AStationPackageGetsItsKindOnlyFromTheKindCommand()
|
||||
{
|
||||
var target = Path.Combine(_directory.Path, "GameData", "Mods", "probe.depot", "ship.cc");
|
||||
Assert.Equal(0, Run("create", target, "probe.depot", "Probe Depot", "--like", "Zenith").Code);
|
||||
var (hull, _, _) = ShipAuthoringStore.Load(target);
|
||||
Assert.Equal(HullType.Station, hull.HullType);
|
||||
Assert.False(hull.Kind.IsSet());
|
||||
|
||||
var before = File.ReadAllBytes(target);
|
||||
var (code, _, error) = Run("kind", target, "no-such-kind");
|
||||
Assert.Equal(1, code);
|
||||
Assert.Contains("names no station kind", error);
|
||||
Assert.Equal(before, File.ReadAllBytes(target));
|
||||
|
||||
(code, _, error) = Run("kind", target, "depot");
|
||||
Assert.Equal(0, code);
|
||||
Assert.Equal("", error);
|
||||
Assert.Equal("station-kind:depot", ShipAuthoringStore.Load(target).Hull.Kind.Key.Value);
|
||||
}
|
||||
|
||||
// validate judges a finished station package's kind with the rule Compose applies, before compose does.
|
||||
[Fact]
|
||||
public void ValidateRefusesAKindlessStationAndAcceptsOneThatNamesAShippedKind()
|
||||
{
|
||||
WritePackage("mod.station", tweak: parts => parts.Hull.HullType = HullType.Station);
|
||||
var path = Path.Combine(Mods, "mod.station", "ship.cc");
|
||||
var (code, _, error) = Run("validate", path);
|
||||
Assert.Equal(1, code);
|
||||
Assert.Contains("has no Kind", error);
|
||||
Assert.Equal(0, Run("kind", path, "depot").Code);
|
||||
Assert.Equal(0, Run("validate", path).Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheKindCommandRefusesAShipHullAndLeavesTheFileUntouched()
|
||||
{
|
||||
var target = Path.Combine(_directory.Path, "GameData", "Mods", "probe.ship", "ship.cc");
|
||||
Assert.Equal(0, Run("create", target, "probe.ship", "Probe Ship", "--like", "Djinni").Code);
|
||||
var before = File.ReadAllBytes(target);
|
||||
var (code, _, error) = Run("kind", target, "depot");
|
||||
Assert.Equal(1, code);
|
||||
Assert.Contains("only a station hull has one", error);
|
||||
Assert.Equal(before, File.ReadAllBytes(target));
|
||||
}
|
||||
|
||||
// starter: a complete package from nothing but a hull to take stats from. The package must pass the reader the game boots
|
||||
// with (GLB node ids and mesh roles included) and plan a rig, and a second run must not touch the first package.
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using System.Linq;
|
|||
// Uses the existing database executable; mod authoring does not earn another binary target.
|
||||
public static class ShipAuthoringCommands
|
||||
{
|
||||
private const string Usage = "ship-authoring create <ship.cc> <stable-id> <name> [--like <shipped hull name>] | starter <mods-dir> <stable-id> <name> --like <shipped hull name> | regenerate <ship.cc> [apply] | inspect <ship.cc> | open <ship.cc> | push <ship.cc> [apply] (request on stdin) | centre <ship.cc> | validate <ship.cc> | product <ship.cc> <maker> (--name <name> [--description <text>] [--not-offered] | --remove) | price <ship.cc> <price> | stats <ship.cc> [--mass m] [--durability d] [--armor a] [--drag x] [--top-speed v] | compose <shipped.cc> <derived.cc> <mods-dir>";
|
||||
private const string Usage = "ship-authoring create <ship.cc> <stable-id> <name> [--like <shipped ship or station hull name>] | starter <mods-dir> <stable-id> <name> --like <shipped hull name> | regenerate <ship.cc> [apply] | inspect <ship.cc> | open <ship.cc> | push <ship.cc> [apply] (request on stdin) | centre <ship.cc> | validate <ship.cc> | product <ship.cc> <maker> (--name <name> [--description <text>] [--not-offered] | --remove) | price <ship.cc> <price> | stats <ship.cc> [--mass m] [--durability d] [--armor a] [--drag x] [--top-speed v] | kind <ship.cc> <kind-id> | compose <shipped.cc> <derived.cc> <mods-dir>";
|
||||
|
||||
private static readonly string[] StatFlags = { "--mass", "--durability", "--armor", "--drag", "--top-speed" };
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ public static class ShipAuthoringCommands
|
|||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
var ship = new ShipAuthoring { Id = args[2], ModelAsset = "ship.glb", Anchors = new List<ShipAnchor>() };
|
||||
var hull = args.Length == 6
|
||||
? ShipAuthoringStore.HullLike(ShippedShipHull(args[5]), args[3], ship.Id)
|
||||
? ShipAuthoringStore.HullLike(ShippedLikeHull(args[5]), args[3], ship.Id)
|
||||
: new HullData
|
||||
{
|
||||
Name = args[3],
|
||||
|
|
@ -205,6 +205,22 @@ public static class ShipAuthoringCommands
|
|||
Console.WriteLine($"{ship.Id}: {(remove ? "removed" : "wrote")} the product by {makerName}{(notOffered ? ", not offered" : "")}.");
|
||||
return 0;
|
||||
}
|
||||
if (args[0] == "kind" && args.Length == 3)
|
||||
{
|
||||
// The one writer of a station package's Kind, beside push (the scene's writer): same loader, one commit. The one
|
||||
// kind rule judges it against the shipped catalog, read-only, before the file is opened writable.
|
||||
var (hull, ship, _) = ShipAuthoringStore.Load(args[1]);
|
||||
hull.Kind = new CultRecordRef<StationKindData>(StationKindData.KeyOf(args[2]));
|
||||
using (var catalog = AetherDb.Open().Cache)
|
||||
if (StationKinds.HullKindFault(catalog, hull) is { } fault) throw new InvalidOperationException($"{ship.Id}: {fault}");
|
||||
using (var cache = ShipAuthoringStore.Open(args[1], writable: true))
|
||||
{
|
||||
ShipAuthoringStore.Write(cache, hull, ship);
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
Console.WriteLine($"{ship.Id}: kind {hull.Kind.Key.Value}.");
|
||||
return 0;
|
||||
}
|
||||
Console.Error.WriteLine(Usage);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -217,7 +233,8 @@ public static class ShipAuthoringCommands
|
|||
|
||||
// The judgment validate reports and push reports on its derived records: the package's records, and its GLB too once it
|
||||
// exists (node ids, mesh roles); a draft without one is judged on its records alone, and the label says which. A package
|
||||
// with no products has no bin and is never offered, so the shipped catalog is opened for none. Throws the refusal.
|
||||
// with no products and no station kind to judge has no bin and is never offered, so the shipped catalog is opened for none.
|
||||
// Throws the refusal.
|
||||
internal static string Judge(string path, HullData hull, ShipAuthoring ship, FactionProductData[] products)
|
||||
{
|
||||
var full = Path.GetFullPath(path);
|
||||
|
|
@ -226,8 +243,11 @@ public static class ShipAuthoringCommands
|
|||
ShipAuthoringStore.ValidateLoaded(hull, ship, products);
|
||||
if (judged == "records and model") ShipModCatalog.Bind(hull, ship, products, Path.GetDirectoryName(full), full);
|
||||
// Compose's verdict on a package's bins and its offered hull's schematic; the author sees it here, before compose.
|
||||
using var catalog = products.Length > 0 ? AetherDb.Open().Cache : null;
|
||||
using var catalog = products.Length > 0 || hull.HullType == HullType.Station ? AetherDb.Open().Cache : null;
|
||||
if (ShipModCatalog.MarketFault(catalog, ship, products) is { } fault) throw new InvalidOperationException(fault);
|
||||
// A station package names a kind the shipped catalog holds (the rule Compose applies), so Package refuses it before compose does.
|
||||
if (hull.HullType == HullType.Station && StationKinds.HullKindFault(catalog, hull) is { } kindFault)
|
||||
throw new InvalidOperationException($"{ship.Id}: {kindFault}");
|
||||
return judged;
|
||||
}
|
||||
|
||||
|
|
@ -243,14 +263,19 @@ public static class ShipAuthoringCommands
|
|||
return (catalog.TryGetHandle(matches[0]).Value.Key, matches[0].Name);
|
||||
}
|
||||
|
||||
// A shipped ship hull by name, from GameData/Aetheria.cc opened read-only.
|
||||
private static HullData ShippedShipHull(string name)
|
||||
// A shipped hull by name, from GameData/Aetheria.cc opened read-only, of one of the types allowed.
|
||||
private static HullData ShippedHull(string name, params HullType[] allowed)
|
||||
{
|
||||
using var catalog = AetherDb.Open().Cache;
|
||||
var hull = catalog.GetAll<HullData>().FirstOrDefault(candidate => candidate.Name == name) ??
|
||||
throw new InvalidOperationException($"--like: the shipped catalog has no hull named '{name}'.");
|
||||
if (hull.HullType != HullType.Ship)
|
||||
throw new InvalidOperationException($"--like: '{name}' is a {hull.HullType} hull, not a ship.");
|
||||
if (!allowed.Contains(hull.HullType))
|
||||
throw new InvalidOperationException($"--like: '{name}' is a {hull.HullType} hull, not a {string.Join(" or ", allowed)}.");
|
||||
return hull;
|
||||
}
|
||||
|
||||
// starter writes a flyable package, so its like hull is a ship; create --like also takes a station (never a turret).
|
||||
private static HullData ShippedShipHull(string name) => ShippedHull(name, HullType.Ship);
|
||||
|
||||
private static HullData ShippedLikeHull(string name) => ShippedHull(name, HullType.Ship, HullType.Station);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ packager still matches the committed first-party package.
|
|||
| --- | --- |
|
||||
| `id` | the stable ship id and the folder name under `GameData/Mods`; `ship_cc.valid_ship_id` decides what is valid |
|
||||
| `name` | the hull's display name |
|
||||
| `like` | the name of a shipped catalog hull of type Ship whose stats and top speed the new hull starts from (AetherDb `--like`) |
|
||||
| `like` | the name of a shipped catalog hull of type Ship or Station whose stats the new hull starts from (AetherDb `--like`); a Station's kind is not copied |
|
||||
| `length` | whole cells, at least 1: the New Ship length field of the add-on |
|
||||
| `extent` | `[x, y, z]` metres of the stand-in box the model is made from; with the add-on's `CELL_SIZE` of 2 m (`aetheria_ships/hull_grid.py`) this fixes the raster, so rows written for one extent do not carry to another |
|
||||
| `hull` | a file beside the manifest, copied to the package as `hull.scad` (OpenSCAD source with the kit's faction modules) |
|
||||
|
|
@ -32,6 +32,7 @@ packager still matches the committed first-party package.
|
|||
| `price` | at least 0 (AetherDb `price`) |
|
||||
| `stats` | `mass`, `durability`, `armor`, `drag`, each at least 0, and optionally `top_speed` (a hull without it keeps `like`'s) |
|
||||
| `rows` | a non-empty list of hardpoint rows, below |
|
||||
| `kind` | optional: a station kind id (such as `depot`), written by AetherDb `ship-authoring kind` after stats; required when `like` is a Station, because `validate` refuses a station package that names no kind the shipped catalog holds |
|
||||
|
||||
A row has all of `id`, `kind`, `cell`, `footprint`, `rotation`, `armor`, `arc`:
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ product, and a manifest is never read again; --replace re-derives the package an
|
|||
existing package is refused untouched. A run is all or nothing: --replace moves the existing package aside, builds, and deletes the old one
|
||||
only when the new one is complete; any failure removes what the run built and puts the old package back as it was.
|
||||
|
||||
Order, one owner per step: New Ship --like, the first Save Layout creates ship.cc, AetherDb stats/price/product (the one writer of
|
||||
each), hull.scad copied in, Load Layout, Build From Hull Source, Rasterise Hull, the rows through place(), Save Layout, Package Ship.
|
||||
Order, one owner per step: New Ship --like, the first Save Layout creates ship.cc, AetherDb stats/kind/price/product (the one writer of
|
||||
each; kind only for a station manifest), hull.scad copied in, Load Layout, Build From Hull Source, Rasterise Hull, the rows through place(), Save Layout, Package Ship.
|
||||
The last line is PACKAGE_OK (exit 0) or PACKAGE_FAILED (exit 1); a row that does not fit its cell is a failure, never a move.
|
||||
Manifest schema and the reproducers: package_hull.md. Everything outside package() is pure Python (test_package_hull.py).
|
||||
"""
|
||||
|
|
@ -27,6 +27,7 @@ from pathlib import Path
|
|||
HERE = Path(__file__).resolve().parent
|
||||
|
||||
MANIFEST_KEYS = ("id", "name", "like", "length", "extent", "hull", "maker", "description", "offered", "price", "stats", "rows")
|
||||
MANIFEST_OPTIONAL = ("kind",)
|
||||
STATS_KEYS = ("mass", "durability", "armor", "drag")
|
||||
STATS_OPTIONAL = ("top_speed",)
|
||||
ROW_KEYS = ("id", "kind", "cell", "footprint", "rotation", "armor", "arc")
|
||||
|
|
@ -81,12 +82,14 @@ def load_manifest(path):
|
|||
manifest = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError) as error:
|
||||
raise Refused(f"The manifest cannot be read: {error}") from None
|
||||
_keys("The manifest", manifest, MANIFEST_KEYS)
|
||||
_keys("The manifest", manifest, MANIFEST_KEYS, MANIFEST_OPTIONAL)
|
||||
ship_cc = _ship_cc()
|
||||
if not isinstance(manifest["id"], str) or not ship_cc.valid_ship_id(manifest["id"]):
|
||||
raise Refused(f"id {manifest['id']!r} is not a valid ship id")
|
||||
for key in ("name", "like", "maker", "description", "hull"):
|
||||
_text(key, manifest[key])
|
||||
if "kind" in manifest:
|
||||
_text("kind", manifest["kind"])
|
||||
if isinstance(manifest["length"], bool) or not isinstance(manifest["length"], int) or manifest["length"] < 1:
|
||||
raise Refused("length must be a whole number of cells of at least 1")
|
||||
extent = manifest["extent"]
|
||||
|
|
@ -262,6 +265,9 @@ def package(manifest, manifest_dir, game, packages, openscad):
|
|||
require(db(*args) == 0, "stats was refused")
|
||||
if "top_speed" in stats:
|
||||
require(top_speed() == (stats["top_speed"], stats["top_speed"]), "stats did not set the top speed")
|
||||
if "kind" in manifest:
|
||||
# A station's kind is ship.cc's own fact and AetherDb its one writer; the packager holds no kind table.
|
||||
require(db("kind", ship_cc_path, manifest["kind"]) == 0, "kind was refused")
|
||||
require(db("price", ship_cc_path, manifest["price"]) == 0, "price was refused")
|
||||
product = ["product", ship_cc_path, manifest["maker"], "--name", name, "--description", manifest["description"]]
|
||||
require(db(*product, *([] if manifest["offered"] else ["--not-offered"])) == 0, "product was refused")
|
||||
|
|
|
|||
|
|
@ -46,6 +46,11 @@ class ManifestTests(unittest.TestCase):
|
|||
self.assertEqual(len(manifest["rows"]), 6)
|
||||
self.assertEqual(ph.rows_of(manifest)[0], ("Gun.D", "Ballistic", (2, 3), "#", 0, 20, 90))
|
||||
|
||||
def test_a_station_kind_loads_and_must_be_text(self):
|
||||
self.assertEqual(self.load(lambda m: m.update(kind="depot"))["kind"], "depot")
|
||||
for bad in (7, "", None):
|
||||
self.refused(lambda m, bad=bad: m.update(kind=bad), "kind")
|
||||
|
||||
def test_a_missing_key_is_named(self):
|
||||
self.refused(lambda m: m.pop("price"), "missing", "price")
|
||||
self.refused(lambda m: m["stats"].pop("drag"), "stats", "drag")
|
||||
|
|
|
|||
Loading…
Reference in a new issue