ui/phase-19: ship-group decoder + map binding + selection store
Wires Phase 19's data and rendering layers without yet adding the
inspector UI:
- game-state.ts grows ReportLocalShipGroup / ReportOtherShipGroup
/ ReportIncomingShipGroup / ReportUnidentifiedShipGroup /
ReportLocalFleet types and walks the matching FlatBuffers
vectors (LocalGroup, OtherGroup, IncomingGroup,
UnidentifiedGroup, LocalFleet) inside decodeReport. The Tech
map is folded into the fixed-shape ShipGroupTech struct;
cargo strings normalise to the closed CargoLoadType | "NONE"
union; UUIDs come back as canonical 36-char strings.
- synthetic-report.ts mirrors the new fields so the DEV-only
lobby loader can feed JSON produced by legacy-report-to-json
straight into the live UI surface.
- selection.svelte.ts widens its discriminated union with a
`kind: "shipGroup"` branch carrying a ShipGroupRef
(local UUID / other / incoming / unidentified by index).
- world.ts adds Style.strokeDashPx and render.ts.drawLine
honours it via manual segmentation (PixiJS v8 has no native
dash API). Ignored on points and circles.
- state-binding.ts now returns { world, hitLookup }: the
hit-lookup map keys every primitive id back to a concrete
HitTarget so the click handler can dispatch to selectPlanet
or selectShipGroup. Ship-group primitives live in a separate
ship-groups.ts that emits one point per local / other /
unidentified group, plus a dashed origin→destination line +
clickable point per incoming group. Position is interpolated
along the trajectory for in-hyperspace groups.
- map.svelte threads the hitLookup into handleMapClick.
Vitest:
- tests/helpers/empty-ship-groups.ts exposes EMPTY_SHIP_GROUPS
so existing fixtures can spread the new five empty arrays
without enumerating every field.
- state-binding-groups.test.ts covers each group variant's
primitive geometry and lookup correctness.
- All previously-existing fixture builders pick up the spread
so GameReport stays a complete object.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -20,10 +20,18 @@
|
||||
|
||||
import type {
|
||||
GameReport,
|
||||
ReportIncomingShipGroup,
|
||||
ReportLocalFleet,
|
||||
ReportLocalShipGroup,
|
||||
ReportOtherShipGroup,
|
||||
ReportPlanet,
|
||||
ReportRoute,
|
||||
ReportUnidentifiedShipGroup,
|
||||
ShipClassSummary,
|
||||
ShipGroupTech,
|
||||
} from "./game-state";
|
||||
import type { CargoLoadType } from "../sync/order-types";
|
||||
import { isCargoLoadType } from "../sync/order-types";
|
||||
|
||||
export const SYNTHETIC_GAME_ID_PREFIX = "synthetic-";
|
||||
|
||||
@@ -96,6 +104,45 @@ interface SyntheticPlayer {
|
||||
cargo: number;
|
||||
}
|
||||
|
||||
interface SyntheticShipGroup {
|
||||
id?: string;
|
||||
number?: number;
|
||||
class?: string;
|
||||
tech?: Record<string, number>;
|
||||
cargo?: string;
|
||||
load?: number;
|
||||
destination?: number;
|
||||
origin?: number;
|
||||
range?: number;
|
||||
speed?: number;
|
||||
mass?: number;
|
||||
state?: string;
|
||||
fleet?: string;
|
||||
}
|
||||
|
||||
interface SyntheticIncomingGroup {
|
||||
origin?: number;
|
||||
destination?: number;
|
||||
distance?: number;
|
||||
speed?: number;
|
||||
mass?: number;
|
||||
}
|
||||
|
||||
interface SyntheticUnidentifiedGroup {
|
||||
x?: number;
|
||||
y?: number;
|
||||
}
|
||||
|
||||
interface SyntheticLocalFleet {
|
||||
name?: string;
|
||||
groups?: number;
|
||||
destination?: number;
|
||||
origin?: number;
|
||||
range?: number;
|
||||
speed?: number;
|
||||
state?: string;
|
||||
}
|
||||
|
||||
interface SyntheticReportRoot {
|
||||
turn?: number;
|
||||
mapWidth?: number;
|
||||
@@ -108,6 +155,11 @@ interface SyntheticReportRoot {
|
||||
uninhabitedPlanet?: SyntheticPlanet[];
|
||||
unidentifiedPlanet?: SyntheticPlanet[];
|
||||
localShipClass?: SyntheticShipClass[];
|
||||
localGroup?: SyntheticShipGroup[];
|
||||
otherGroup?: SyntheticShipGroup[];
|
||||
incomingGroup?: SyntheticIncomingGroup[];
|
||||
unidentifiedGroup?: SyntheticUnidentifiedGroup[];
|
||||
localFleet?: SyntheticLocalFleet[];
|
||||
}
|
||||
|
||||
function decodeSyntheticReport(json: unknown): GameReport {
|
||||
@@ -146,6 +198,59 @@ function decodeSyntheticReport(json: unknown): GameReport {
|
||||
|
||||
const routes: ReportRoute[] = [];
|
||||
|
||||
const localShipGroups: ReportLocalShipGroup[] = (root.localGroup ?? []).map(
|
||||
(g, i) => ({
|
||||
id: typeof g.id === "string" ? g.id : `synthetic-local-group-${i}`,
|
||||
count: numOr0(g.number),
|
||||
class: typeof g.class === "string" ? g.class : "",
|
||||
tech: toShipGroupTech(g.tech),
|
||||
cargo: toCargoType(g.cargo),
|
||||
load: numOr0(g.load),
|
||||
destination: numOr0(g.destination),
|
||||
origin: typeof g.origin === "number" ? g.origin : null,
|
||||
range: typeof g.range === "number" ? g.range : null,
|
||||
speed: numOr0(g.speed),
|
||||
mass: numOr0(g.mass),
|
||||
state: typeof g.state === "string" ? g.state : "",
|
||||
fleet: typeof g.fleet === "string" ? g.fleet : null,
|
||||
}),
|
||||
);
|
||||
const otherShipGroups: ReportOtherShipGroup[] = (root.otherGroup ?? []).map(
|
||||
(g) => ({
|
||||
count: numOr0(g.number),
|
||||
class: typeof g.class === "string" ? g.class : "",
|
||||
tech: toShipGroupTech(g.tech),
|
||||
cargo: toCargoType(g.cargo),
|
||||
load: numOr0(g.load),
|
||||
destination: numOr0(g.destination),
|
||||
origin: typeof g.origin === "number" ? g.origin : null,
|
||||
range: typeof g.range === "number" ? g.range : null,
|
||||
speed: numOr0(g.speed),
|
||||
mass: numOr0(g.mass),
|
||||
}),
|
||||
);
|
||||
const incomingShipGroups: ReportIncomingShipGroup[] = (
|
||||
root.incomingGroup ?? []
|
||||
).map((g) => ({
|
||||
origin: numOr0(g.origin),
|
||||
destination: numOr0(g.destination),
|
||||
distance: numOr0(g.distance),
|
||||
speed: numOr0(g.speed),
|
||||
mass: numOr0(g.mass),
|
||||
}));
|
||||
const unidentifiedShipGroups: ReportUnidentifiedShipGroup[] = (
|
||||
root.unidentifiedGroup ?? []
|
||||
).map((g) => ({ x: numOr0(g.x), y: numOr0(g.y) }));
|
||||
const localFleets: ReportLocalFleet[] = (root.localFleet ?? []).map((f) => ({
|
||||
name: typeof f.name === "string" ? f.name : "",
|
||||
groupCount: numOr0(f.groups),
|
||||
destination: numOr0(f.destination),
|
||||
origin: typeof f.origin === "number" ? f.origin : null,
|
||||
range: typeof f.range === "number" ? f.range : null,
|
||||
speed: numOr0(f.speed),
|
||||
state: typeof f.state === "string" ? f.state : "",
|
||||
}));
|
||||
|
||||
return {
|
||||
turn: numOr0(root.turn),
|
||||
mapWidth: numOr0(root.mapWidth),
|
||||
@@ -159,9 +264,30 @@ function decodeSyntheticReport(json: unknown): GameReport {
|
||||
localPlayerWeapons: tech.weapons,
|
||||
localPlayerShields: tech.shields,
|
||||
localPlayerCargo: tech.cargo,
|
||||
localShipGroups,
|
||||
otherShipGroups,
|
||||
incomingShipGroups,
|
||||
unidentifiedShipGroups,
|
||||
localFleets,
|
||||
};
|
||||
}
|
||||
|
||||
function toShipGroupTech(raw: Record<string, number> | undefined): ShipGroupTech {
|
||||
const out: ShipGroupTech = { drive: 0, weapons: 0, shields: 0, cargo: 0 };
|
||||
if (raw === undefined || raw === null) return out;
|
||||
if (typeof raw.drive === "number") out.drive = raw.drive;
|
||||
if (typeof raw.weapons === "number") out.weapons = raw.weapons;
|
||||
if (typeof raw.shields === "number") out.shields = raw.shields;
|
||||
if (typeof raw.cargo === "number") out.cargo = raw.cargo;
|
||||
return out;
|
||||
}
|
||||
|
||||
function toCargoType(raw: string | undefined): CargoLoadType | "NONE" {
|
||||
if (raw === undefined || raw === "" || raw === "-") return "NONE";
|
||||
if (isCargoLoadType(raw)) return raw;
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
function toPlanet(
|
||||
p: SyntheticPlanet,
|
||||
kind: ReportPlanet["kind"],
|
||||
|
||||
Reference in New Issue
Block a user