ui/phase-19: torus-aware incoming track + on-planet groups in inspector
Two follow-up fixes after the initial Phase 19 landing:
1. The IncomingGroup dashed trajectory was drawn between raw
(x1, y1) and (x2, y2) world coordinates. On torus wrap mode
this took the long way around when origin and destination
sat near opposite seams. The line now picks endpoints via
`torusShortestDelta` so the segment crosses the seam when
that's the shorter visual path. The interpolated clickable
point follows the same unwrapped vector. The same helper
fixes the in-hyperspace position for local / foreign groups.
2. On-planet local and foreign groups previously rendered as
small offset points next to every populated planet, which
turned the canvas into noise as soon as a player held more
than a handful of planets. The map no longer renders any
in-orbit group; the planet inspector grows a compact
"stationed ship groups" subsection
(`lib/inspectors/planet/ship-groups.svelte`) that lists
each in-orbit group as a row of `<race> · <class> · <count>
ships · <mass>`. Race attribution: LocalGroup → the player's
race, OtherGroup on a foreign-owned planet → the planet's
owner, OtherGroup elsewhere → "foreign" placeholder. Rows
are non-interactive in Phase 19; Phase 21+ will deep-link
into the ship-groups table view with a (planet, race) filter.
Tests:
- `state-binding-groups.test.ts` swaps the on-planet rendering
expectation for the new "no map primitive" rule, and adds a
regression that asserts the incoming line crosses the torus
seam via `torusShortestDelta`.
- new `inspector-planet-ship-groups.test.ts` covers row
composition, the destination-mismatch filter, the
in-hyperspace exclusion, the foreign-planet owner fallback,
and the empty-state collapse.
- `inspector-planet.test.ts` and `inspector-ship-group.spec.ts`
pick up the new prop chain (`localShipGroups`,
`otherShipGroups`, `localRace`).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -58,7 +58,7 @@ function makeReport(overrides: Partial<GameReport> = {}): GameReport {
|
||||
}
|
||||
|
||||
describe("reportToWorld — ship groups", () => {
|
||||
test("on-planet local group renders a clickable point near the planet", () => {
|
||||
test("on-planet local group is NOT rendered on the map (planet inspector hosts it)", () => {
|
||||
const home = planet({ number: 17, x: 100, y: 100, kind: "local" });
|
||||
const { world, hitLookup } = reportToWorld(
|
||||
makeReport({
|
||||
@@ -82,18 +82,13 @@ describe("reportToWorld — ship groups", () => {
|
||||
],
|
||||
}),
|
||||
);
|
||||
// 1 planet point + 1 ship-group point.
|
||||
expect(world.primitives.length).toBe(2);
|
||||
const groupPrimId = SHIP_GROUP_ID_OFFSETS.local + 0;
|
||||
const group = world.primitives.find((p) => p.id === groupPrimId);
|
||||
expect(group).toBeDefined();
|
||||
if (group?.kind !== "point") throw new Error("expected point");
|
||||
// Off-planet rendering: not exactly on (100, 100).
|
||||
expect(group.x === home.x && group.y === home.y).toBe(false);
|
||||
expect(hitLookup.get(groupPrimId)).toEqual({
|
||||
kind: "shipGroup",
|
||||
ref: { variant: "local", id: "uuid-local-1" },
|
||||
});
|
||||
// Only the planet itself contributes a primitive; the on-planet
|
||||
// group is intentionally invisible on the map. Phase 19's
|
||||
// `lib/inspectors/planet/ship-groups.svelte` lists it inside the
|
||||
// planet inspector instead.
|
||||
expect(world.primitives.length).toBe(1);
|
||||
expect(hitLookup.has(SHIP_GROUP_ID_OFFSETS.local + 0)).toBe(false);
|
||||
expect(hitLookup.get(17)).toEqual({ kind: "planet", number: 17 });
|
||||
});
|
||||
|
||||
test("in-hyperspace local group renders at the interpolated position", () => {
|
||||
@@ -130,6 +125,36 @@ describe("reportToWorld — ship groups", () => {
|
||||
expect(group.y).toBe(0);
|
||||
});
|
||||
|
||||
test("incoming-group line crosses the torus seam via the shortest path", () => {
|
||||
const dest = planet({ number: 1, x: 5, y: 50 });
|
||||
const orig = planet({ number: 9, x: 95, y: 50 });
|
||||
const { world } = reportToWorld(
|
||||
makeReport({
|
||||
mapWidth: 100,
|
||||
mapHeight: 100,
|
||||
planets: [dest, orig],
|
||||
incomingShipGroups: [
|
||||
{
|
||||
origin: 9,
|
||||
destination: 1,
|
||||
distance: 5,
|
||||
speed: 5,
|
||||
mass: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
const line = world.primitives.find(
|
||||
(p) => p.id === SHIP_GROUP_ID_OFFSETS.incomingLine + 0,
|
||||
);
|
||||
if (line?.kind !== "line") throw new Error("expected line");
|
||||
// Origin (95) → unwrapped destination at 105 (origin.x + (-10) is
|
||||
// the no-wrap path). The shortest delta from 95 to 5 on width 100
|
||||
// is +10, so we expect line.x2 = 95 + 10 = 105.
|
||||
expect(line.x1).toBe(95);
|
||||
expect(line.x2).toBe(105);
|
||||
});
|
||||
|
||||
test("incoming group emits one dashed line + one clickable point", () => {
|
||||
const dest = planet({ number: 1, x: 0, y: 0 });
|
||||
const orig = planet({ number: 9, x: 100, y: 0 });
|
||||
|
||||
Reference in New Issue
Block a user