AetherDb ship-authoring: create --like a shipped hull, and validate reads the GLB when present
ShipAuthoringStore.HullLike copies a reference hull through its MessagePack round trip and resets Name, Shape, Hardpoints, Prefab, Schematic and Visual. 'create ... --like <name>' opens the shipped catalog read-only and refuses an unknown or non-ship hull. 'validate' runs ReadPackage when ModelAsset names an existing file and says which it judged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f5743cbad2
commit
f98be434f0
3 changed files with 76 additions and 11 deletions
|
|
@ -88,6 +88,23 @@ public static class ShipAuthoringStore
|
|||
cache.UpsertAsync(typeof(ShipAuthoring), visual, ShipModCatalog.AuthoringKey(visual.Id)).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
// 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,
|
||||
// and Visual, which names this mod's visual record.
|
||||
public static HullData HullLike(HullData reference, string name, string shipId)
|
||||
{
|
||||
var options = CultDocumentMessagePackSerialization.OptionsFor(typeof(HullData).Assembly);
|
||||
var hull = MessagePackSerializer.Deserialize<HullData>(MessagePackSerializer.Serialize(reference, options), options);
|
||||
hull.Name = name;
|
||||
hull.Shape = new Shape();
|
||||
hull.Hardpoints = new List<HardpointData>();
|
||||
hull.Prefab = null;
|
||||
hull.Schematic = null;
|
||||
hull.Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey(shipId));
|
||||
return hull;
|
||||
}
|
||||
|
||||
// The structure of a ship file, without judging its content (drafts load): exactly one hull and one visual, each at
|
||||
// its deterministic key, the hull naming that visual by its typed ref.
|
||||
public static (HullData Hull, ShipAuthoring Visual) Load(string path)
|
||||
|
|
|
|||
|
|
@ -420,6 +420,32 @@ public sealed class ShipAuthoringTests
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
// One ship's two records: the hull and the visual it names.
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ 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>] | inspect <ship.cc> | validate <ship.cc> | compose <shipped.cc> <derived.cc> <mods-dir>";
|
||||
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.Error.WriteLine("ship-authoring create <ship.cc> <stable-id> <name> | inspect <ship.cc> | validate <ship.cc> | compose <shipped.cc> <derived.cc> <mods-dir>");
|
||||
Console.Error.WriteLine(Usage);
|
||||
return 1;
|
||||
}
|
||||
try
|
||||
|
|
@ -31,22 +33,31 @@ public static class ShipAuthoringCommands
|
|||
}
|
||||
if (args[0] == "validate" && args.Length == 2)
|
||||
{
|
||||
var (hull, ship) = ShipAuthoringStore.Read(args[1]);
|
||||
Console.WriteLine($"{ship.Id}: {hull.Name}, {hull.Hardpoints.Count} hardpoints, {ship.SchematicLines.Count} lines");
|
||||
// The package's GLB is judged too once it exists (node ids, mesh roles); a draft without one is judged on
|
||||
// its records alone, and the output says which.
|
||||
var (hull, ship) = ShipAuthoringStore.Load(args[1]);
|
||||
var model = string.IsNullOrWhiteSpace(ship.ModelAsset) ? null
|
||||
: Path.Combine(Path.GetDirectoryName(Path.GetFullPath(args[1])), ship.ModelAsset);
|
||||
var judged = model != null && File.Exists(model) ? "records and model" : "records only, no model yet";
|
||||
if (judged == "records and model") ShipModCatalog.ReadPackage(args[1]);
|
||||
else ShipAuthoringStore.Validate(hull, ship);
|
||||
Console.WriteLine($"{ship.Id}: {hull.Name}, {hull.Hardpoints.Count} hardpoints, {ship.Anchors.Count} anchors, {ship.SchematicLines.Count} lines ({judged})");
|
||||
return 0;
|
||||
}
|
||||
if (args[0] == "create" && args.Length == 4)
|
||||
if (args[0] == "create" && (args.Length == 4 || args.Length == 6 && args[4] == "--like"))
|
||||
{
|
||||
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 { Id = args[2], ModelAsset = "ship.glb", Anchors = new List<ShipAnchor>() };
|
||||
var hull = new HullData
|
||||
{
|
||||
Name = args[3],
|
||||
Shape = new Shape(),
|
||||
Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey(ship.Id))
|
||||
};
|
||||
var hull = args.Length == 6
|
||||
? ShipAuthoringStore.HullLike(ShippedShipHull(args[5]), args[3], ship.Id)
|
||||
: new HullData
|
||||
{
|
||||
Name = args[3],
|
||||
Shape = new Shape(),
|
||||
Visual = new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey(ship.Id))
|
||||
};
|
||||
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
||||
{
|
||||
ShipAuthoringStore.Write(cache, hull, ship);
|
||||
|
|
@ -55,7 +66,7 @@ public static class ShipAuthoringCommands
|
|||
Console.WriteLine($"Created draft {path}; fill its model bindings and schematic in Blender.");
|
||||
return 0;
|
||||
}
|
||||
Console.Error.WriteLine("ship-authoring create <ship.cc> <stable-id> <name> | inspect <ship.cc> | validate <ship.cc> | compose <shipped.cc> <derived.cc> <mods-dir>");
|
||||
Console.Error.WriteLine(Usage);
|
||||
return 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -64,4 +75,15 @@ public static class ShipAuthoringCommands
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// A shipped ship hull by name, from GameData/Aetheria.cc opened read-only.
|
||||
private static HullData ShippedShipHull(string name)
|
||||
{
|
||||
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.");
|
||||
return hull;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue