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)),
|
||||
|
|
|
|||
Loading…
Reference in a new issue