diff --git a/src/BadDay.Cli/Program.cs b/src/BadDay.Cli/Program.cs
index 9a61dac..85261b2 100644
--- a/src/BadDay.Cli/Program.cs
+++ b/src/BadDay.Cli/Program.cs
@@ -12,6 +12,7 @@ public static class Program
private const string Usage = """
baddaysim: the Synaptic Induction Chamber (the pain box)
+ baddaysim plan the seated puppet's body plan as JSON: parts and joints in their creation pose (the mesh build's skeleton)
baddaysim run --seed N [options] one run, full timeline
baddaysim run --seed N --body [options] the same run on the Ymir ragdoll, with the hand-out time
baddaysim sweep --seed N --count M [options] seeds N..N+M-1, break-time summary
@@ -52,6 +53,7 @@ public static class Program
public static int Execute(string[] args, System.IO.TextWriter output)
{
+ if (args.Length == 1 && args[0] == "plan") { output.Write(PlanJson()); return 0; }
if (args.Length == 0 || (args[0] != "run" && args[0] != "sweep" && args[0] != "office" && args[0] != "office-sweep"))
throw new ArgumentException("expected 'run', 'sweep', 'office' or 'office-sweep'");
var opts = ParseOptions(args);
@@ -98,6 +100,17 @@ public static class Program
return 0;
}
+ /// SeatedPuppet.Plan as JSON, floats in round-trip form: per part label, side, creation position and rotation (x, y, z, w); per joint label, side, parent and child part ordinals and anchor.
+ private static string PlanJson()
+ {
+ string F(float v) => v.ToString("R", CultureInfo.InvariantCulture);
+ string V((float X, float Y, float Z) v) => $"[{F(v.X)}, {F(v.Y)}, {F(v.Z)}]";
+ var plan = SeatedPuppet.Plan;
+ var parts = plan.Parts.Select(p => $" {{\"label\": \"{p.Label}\", \"side\": \"{p.Side}\", \"position\": {V(p.Position)}, \"rotation\": [{F(p.Rotation.X)}, {F(p.Rotation.Y)}, {F(p.Rotation.Z)}, {F(p.Rotation.W)}]}}");
+ var joints = plan.Joints.Select(j => $" {{\"label\": \"{j.Label}\", \"side\": \"{j.Side}\", \"parent\": {j.Parent}, \"child\": {j.Child}, \"anchor\": {V(j.Anchor)}}}");
+ return "{\n \"parts\": [\n" + string.Join(",\n", parts) + "\n ],\n \"joints\": [\n" + string.Join(",\n", joints) + "\n ]\n}\n";
+ }
+
private static int ExecuteOffice(bool sweep, ulong seed, Dictionary opts, System.IO.TextWriter output)
{
if (opts.ContainsKey("body") && sweep) throw new ArgumentException("--body applies to run and office");
diff --git a/src/BadDay.Ymir/SeatedPuppet.cs b/src/BadDay.Ymir/SeatedPuppet.cs
index 60bbacc..b2f0665 100644
--- a/src/BadDay.Ymir/SeatedPuppet.cs
+++ b/src/BadDay.Ymir/SeatedPuppet.cs
@@ -17,6 +17,10 @@ public static class SeatedPuppet
/// The stable id of the first of Fella's parts: a part's stable id is this plus its ordinal. The ground is 1 and the stool 2.
public const ulong FirstStableId = 100;
+ /// The part ordinal of Fella's body with this stable id ( plus the ordinal), or null for any other body: the one rule from stable id to part.
+ public static int? PartOf(ulong stableId) =>
+ stableId >= FirstStableId && stableId - FirstStableId < (ulong)Plan.Parts.Count ? (int)(stableId - FirstStableId) : null;
+
/// Bodies, joints and sensors a world needs for : the ragdoll, the ground and the stool, the weld, and the airway sensors (the world must also have a particle system for them).
public static (int Bodies, int Joints, int Sensors) Needs => (Ragdoll.Needs(Plan).Bodies + 2, Ragdoll.Needs(Plan).Joints + 1, Ragdoll.Needs(Plan).Sensors);
diff --git a/tests/BadDay.Tests/Program.cs b/tests/BadDay.Tests/Program.cs
index 3561d55..d106e7d 100644
--- a/tests/BadDay.Tests/Program.cs
+++ b/tests/BadDay.Tests/Program.cs
@@ -590,6 +590,26 @@ public static class Program
Check(Run("run", "--seed", "5", "--pay", "20") != Run("run", "--seed", "5", "--pay", "400"), "--pay changed nothing");
}),
+ ("plan prints the seated puppet's 19 parts and 18 joints as JSON, and PartOf claims exactly the parts' stable ids", () =>
+ {
+ var w = new StringWriter();
+ Check(BadDay.Cli.Program.Execute(new[] { "plan" }, w) == 0, "plan did not succeed");
+ using var json = System.Text.Json.JsonDocument.Parse(w.ToString());
+ var plan = SeatedPuppet.Plan;
+ var parts = json.RootElement.GetProperty("parts");
+ var joints = json.RootElement.GetProperty("joints");
+ Check(parts.GetArrayLength() == 19 && joints.GetArrayLength() == 18, $"plan has {parts.GetArrayLength()} parts and {joints.GetArrayLength()} joints");
+ var neck = joints.EnumerateArray().Single(j => j.GetProperty("label").GetString() == "Neck").GetProperty("anchor");
+ var want = plan.Joints[plan.JointIndex("Neck")].Anchor;
+ Check(neck[1].GetSingle() == want.Y && neck[0].GetSingle() == want.X && neck[2].GetSingle() == want.Z, "the neck anchor is not the plan's");
+ for (ulong id = 0; id < SeatedPuppet.FirstStableId + 25; id++)
+ {
+ bool part = id >= SeatedPuppet.FirstStableId && id < SeatedPuppet.FirstStableId + 19;
+ var owner = SeatedPuppet.PartOf(id);
+ Check(part ? owner == (int)(id - SeatedPuppet.FirstStableId) : owner is null, $"PartOf({id}) is {owner}");
+ }
+ }),
+
("office: a stressor is silent before its onset, on for its duration, and back every period", () =>
{
var printer = Cause.Office.Stressors.Single(s => s.Id == "printer"); // 5 s on, 8 s period, 1 s long, 0.25