ui/phase-15: planet inspector production controls + order-draft collapse

Adds the second end-to-end command (`setProductionType`) with a
collapse-by-`planetNumber` rule on the order draft, the segmented
production-controls component on the planet inspector, the FBS
encoder/decoder pair for `CommandPlanetProduce`, and the
`localShipClass` projection on `GameReport`. Forecast number is
deferred and tracked in the new `ui/docs/calc-bridge.md`.
This commit is contained in:
Ilia Denisov
2026-05-09 15:54:30 +02:00
parent c4f1409329
commit 915b4372dd
31 changed files with 2200 additions and 76 deletions
+92 -1
View File
@@ -11,13 +11,18 @@ import { uuidToHiLo } from "../src/api/game-state";
import { UUID } from "../src/proto/galaxy/fbs/common";
import {
CommandItem,
CommandPlanetProduce,
CommandPlanetRename,
CommandPayload,
PlanetProduction,
UserGamesOrder,
UserGamesOrderResponse,
} from "../src/proto/galaxy/fbs/order";
import { submitOrder } from "../src/sync/submit";
import type { OrderCommand } from "../src/sync/order-types";
import type {
OrderCommand,
ProductionType,
} from "../src/sync/order-types";
const GAME_ID = "11111111-2222-3333-4444-555555555555";
@@ -178,4 +183,90 @@ describe("submitOrder", () => {
expect(Number(inner.number())).toBe(7);
expect(inner.name()).toBe("Earth");
});
test("encodes setProductionType as CommandPlanetProduce on the wire", async () => {
let captured: Uint8Array | null = null;
const exec = vi.fn(async (_messageType, payload: Uint8Array) => {
captured = payload;
return { resultCode: "ok", payloadBytes: new Uint8Array() };
});
const cmd: OrderCommand = {
kind: "setProductionType",
id: "00000000-0000-0000-0000-00000000cccc",
planetNumber: 17,
productionType: "SHIP",
subject: "Scout",
};
await submitOrder(mockClient(exec), GAME_ID, [cmd]);
expect(captured).not.toBeNull();
const decoded = UserGamesOrder.getRootAsUserGamesOrder(
new (await import("flatbuffers")).ByteBuffer(captured!),
);
expect(decoded.commandsLength()).toBe(1);
const item = decoded.commands(0);
expect(item).not.toBeNull();
expect(item!.cmdId()).toBe(cmd.id);
expect(item!.payloadType()).toBe(CommandPayload.CommandPlanetProduce);
const inner = new CommandPlanetProduce();
item!.payload(inner);
expect(Number(inner.number())).toBe(17);
expect(inner.production()).toBe(PlanetProduction.SHIP);
expect(inner.subject()).toBe("Scout");
});
test("maps every productionType literal to its FBS enum value", async () => {
const cases: Array<{
productionType: ProductionType;
fbs: PlanetProduction;
subject: string;
}> = [
{ productionType: "MAT", fbs: PlanetProduction.MAT, subject: "" },
{ productionType: "CAP", fbs: PlanetProduction.CAP, subject: "" },
{ productionType: "DRIVE", fbs: PlanetProduction.DRIVE, subject: "" },
{
productionType: "WEAPONS",
fbs: PlanetProduction.WEAPONS,
subject: "",
},
{
productionType: "SHIELDS",
fbs: PlanetProduction.SHIELDS,
subject: "",
},
{ productionType: "CARGO", fbs: PlanetProduction.CARGO, subject: "" },
{
productionType: "SCIENCE",
fbs: PlanetProduction.SCIENCE,
subject: "AlphaSci",
},
{
productionType: "SHIP",
fbs: PlanetProduction.SHIP,
subject: "Scout",
},
];
for (const tc of cases) {
let captured: Uint8Array | null = null;
const exec = vi.fn(async (_messageType, payload: Uint8Array) => {
captured = payload;
return { resultCode: "ok", payloadBytes: new Uint8Array() };
});
const cmd: OrderCommand = {
kind: "setProductionType",
id: `id-${tc.productionType}`,
planetNumber: 5,
productionType: tc.productionType,
subject: tc.subject,
};
await submitOrder(mockClient(exec), GAME_ID, [cmd]);
expect(captured).not.toBeNull();
const decoded = UserGamesOrder.getRootAsUserGamesOrder(
new (await import("flatbuffers")).ByteBuffer(captured!),
);
const inner = new CommandPlanetProduce();
decoded.commands(0)!.payload(inner);
expect(inner.production()).toBe(tc.fbs);
expect(inner.subject()).toBe(tc.subject);
}
});
});