24c68e9846
Tests · UI / test (push) Has been cancelled
Tests · Go / test (pull_request) Successful in 2m6s
Tests · Go / test (push) Successful in 2m6s
Tests · Integration / integration (pull_request) Successful in 1m51s
Tests · UI / test (pull_request) Successful in 3m53s
Issue #48 п.32 ("Stationed ship groups") shipped with a fragile race fallback: when a foreign group sat on a non-`other`-kind planet the inspector printed a generic "foreign" label, which collapsed the race dropdown to a single uninformative bucket. The engine FBS contract did not carry per-group race either, so live games hit the same gap. This patch carries race authoritatively from the engine through every layer down to the inspector. Wire format & engine - `pkg/schema/fbs/report.fbs`: add `race:string` to `OtherGroup` and `LocalGroup` (additive — old clients ignore). - `pkg/schema/fbs/report/`: regenerated Go bindings. - `ui/frontend/src/proto/galaxy/fbs/report/`: regenerated TS bindings. - `pkg/model/report.OtherGroup.Race`: new field; carried through `LocalGroup` via the embedded `OtherGroup`. - `pkg/transcoder/report.go`: encode + decode `race` on both `LocalGroup` and `OtherGroup`. - `game/internal/controller/report.go.otherGroup`: set `v.Race` from `c.g.Race[c.RaceIndex(sg.OwnerID)].Name` so every emitted group — own or foreign — carries the resolved race name. Legacy parser - `tools/local-dev/legacy-report/parser.go`: capture the `<Race> Groups` header into `pendingOtherGroup.race`, fill local group `Race` from `p.rep.Race`, propagate both into the `report.OtherGroup` rows. - Tests + smoke counts updated; regenerated `KNNTS{039,041}.json` fixtures so the synthetic loader carries the new field. UI - `ui/frontend/src/api/`: `ReportShipGroupBase.race` field; synthetic loader + FBS decoder populate it. - `ui/frontend/src/lib/inspectors/planet/ship-groups.svelte`: the stationed-groups inspector picks race directly from `group.race` (own falls back to `localRace`, both finally to the `race.unknown` placeholder). The planet-owner / "foreign" heuristic is gone. - Row label changes from "N ships mass M" to a compact `<class>` | `<N ×>` | `<mass>` three-column layout: the count cell is right-aligned tabular, the mass cell is right-aligned monospace + tabular, matching the inspector / calculator number conventions. Stale i18n keys removed (`ship_groups.row.count`, `.row.mass`, `.race.foreign`). - All affected unit tests (8 files) carry the new `race` field. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
234 lines
6.0 KiB
TypeScript
234 lines
6.0 KiB
TypeScript
// Vitest coverage for the pending-Send overlay. The overlay
|
|
// renders a green dashed line from the source group's orbit
|
|
// planet to the chosen destination for every wire-valid
|
|
// `sendShipGroup` command in the order draft.
|
|
|
|
import { describe, expect, test } from "vitest";
|
|
|
|
import type {
|
|
GameReport,
|
|
ReportLocalShipGroup,
|
|
ReportPlanet,
|
|
} from "../src/api/game-state";
|
|
import type { OrderCommand } from "../src/sync/order-types";
|
|
import { buildPendingSendLines } from "../src/map/pending-send-routes";
|
|
import { DARK_THEME, LIGHT_THEME } from "../src/map/world";
|
|
|
|
function planet(overrides: Partial<ReportPlanet> & Pick<ReportPlanet, "number" | "x" | "y">): ReportPlanet {
|
|
return {
|
|
name: `P${overrides.number}`,
|
|
kind: "uninhabited",
|
|
owner: null,
|
|
size: 1,
|
|
resources: 1,
|
|
industryStockpile: 0,
|
|
materialsStockpile: 0,
|
|
industry: 0,
|
|
population: 0,
|
|
colonists: 0,
|
|
production: null,
|
|
freeIndustry: 0,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function localGroup(overrides: Partial<ReportLocalShipGroup> & Pick<ReportLocalShipGroup, "id" | "destination">): ReportLocalShipGroup {
|
|
return {
|
|
count: 1,
|
|
class: "Cruiser",
|
|
tech: { drive: 1, weapons: 0, shields: 0, cargo: 0 },
|
|
cargo: "NONE",
|
|
load: 0,
|
|
origin: null,
|
|
range: null,
|
|
speed: 0,
|
|
mass: 1,
|
|
state: "In_Orbit",
|
|
fleet: null,
|
|
race: "Earthlings",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function makeReport(
|
|
overrides: Partial<GameReport> & Pick<GameReport, "planets" | "localShipGroups">,
|
|
): GameReport {
|
|
return {
|
|
turn: 1,
|
|
mapWidth: 200,
|
|
mapHeight: 200,
|
|
planetCount: overrides.planets.length,
|
|
race: "Earthlings",
|
|
localShipClass: [],
|
|
localScience: [],
|
|
routes: [],
|
|
localPlayerDrive: 0,
|
|
localPlayerWeapons: 0,
|
|
localPlayerShields: 0,
|
|
localPlayerCargo: 0,
|
|
otherShipGroups: [],
|
|
incomingShipGroups: [],
|
|
unidentifiedShipGroups: [],
|
|
localFleets: [],
|
|
otherRaces: [],
|
|
races: [],
|
|
myVotes: 0,
|
|
myVoteFor: "",
|
|
players: [],
|
|
otherScience: [],
|
|
otherShipClass: [],
|
|
battles: [],
|
|
battleIds: [],
|
|
bombings: [],
|
|
shipProductions: [],
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
const SOURCE_PLANET = planet({ number: 1, x: 100, y: 100, kind: "local" });
|
|
const DEST_PLANET = planet({ number: 2, x: 110, y: 100, kind: "uninhabited" });
|
|
const GROUP_ID = "11111111-1111-1111-1111-111111111111";
|
|
|
|
describe("buildPendingSendLines", () => {
|
|
test("emits a dashed line from the orbit planet to the destination", () => {
|
|
const report = makeReport({
|
|
planets: [SOURCE_PLANET, DEST_PLANET],
|
|
localShipGroups: [localGroup({ id: GROUP_ID, destination: 1 })],
|
|
});
|
|
const cmd: OrderCommand = {
|
|
kind: "sendShipGroup",
|
|
id: "cmd-1",
|
|
groupId: GROUP_ID,
|
|
destinationPlanetNumber: 2,
|
|
};
|
|
const lines = buildPendingSendLines(report, [cmd], { "cmd-1": "valid" });
|
|
expect(lines).toHaveLength(1);
|
|
const line = lines[0]!;
|
|
expect(line.kind).toBe("line");
|
|
expect(line.x1).toBe(100);
|
|
expect(line.y1).toBe(100);
|
|
expect(line.x2).toBe(110);
|
|
expect(line.y2).toBe(100);
|
|
expect(line.style.strokeDashPx).toBeGreaterThan(0);
|
|
expect(line.style.strokeColor).toBe(DARK_THEME.pendingSend);
|
|
});
|
|
|
|
test("uses the supplied palette's dashed-line colour", () => {
|
|
const report = makeReport({
|
|
planets: [SOURCE_PLANET, DEST_PLANET],
|
|
localShipGroups: [localGroup({ id: GROUP_ID, destination: 1 })],
|
|
});
|
|
const cmd: OrderCommand = {
|
|
kind: "sendShipGroup",
|
|
id: "cmd-1",
|
|
groupId: GROUP_ID,
|
|
destinationPlanetNumber: 2,
|
|
};
|
|
const lines = buildPendingSendLines(
|
|
report,
|
|
[cmd],
|
|
{ "cmd-1": "valid" },
|
|
undefined,
|
|
LIGHT_THEME,
|
|
);
|
|
expect(lines[0]?.style.strokeColor).toBe(LIGHT_THEME.pendingSend);
|
|
expect(LIGHT_THEME.pendingSend).not.toBe(DARK_THEME.pendingSend);
|
|
});
|
|
|
|
test("uses the torus-shortest path across the seam", () => {
|
|
const report = makeReport({
|
|
mapWidth: 100,
|
|
mapHeight: 100,
|
|
planets: [
|
|
planet({ number: 1, x: 95, y: 50, kind: "local" }),
|
|
planet({ number: 2, x: 5, y: 50 }),
|
|
],
|
|
localShipGroups: [localGroup({ id: GROUP_ID, destination: 1 })],
|
|
});
|
|
const cmd: OrderCommand = {
|
|
kind: "sendShipGroup",
|
|
id: "cmd-1",
|
|
groupId: GROUP_ID,
|
|
destinationPlanetNumber: 2,
|
|
};
|
|
const lines = buildPendingSendLines(report, [cmd], { "cmd-1": "valid" });
|
|
expect(lines).toHaveLength(1);
|
|
expect(lines[0]!.x1).toBe(95);
|
|
expect(lines[0]!.x2).toBe(105); // 95 + (+10) wrap delta
|
|
});
|
|
|
|
test("ignores commands targeting groups missing from the report", () => {
|
|
const report = makeReport({
|
|
planets: [SOURCE_PLANET, DEST_PLANET],
|
|
localShipGroups: [],
|
|
});
|
|
const cmd: OrderCommand = {
|
|
kind: "sendShipGroup",
|
|
id: "cmd-1",
|
|
groupId: GROUP_ID,
|
|
destinationPlanetNumber: 2,
|
|
};
|
|
expect(buildPendingSendLines(report, [cmd], { "cmd-1": "valid" })).toEqual(
|
|
[],
|
|
);
|
|
});
|
|
|
|
test("ignores commands when the source group is in hyperspace", () => {
|
|
const report = makeReport({
|
|
planets: [SOURCE_PLANET, DEST_PLANET],
|
|
localShipGroups: [
|
|
localGroup({
|
|
id: GROUP_ID,
|
|
destination: 1,
|
|
origin: 2,
|
|
range: 5,
|
|
state: "In_Space",
|
|
}),
|
|
],
|
|
});
|
|
const cmd: OrderCommand = {
|
|
kind: "sendShipGroup",
|
|
id: "cmd-1",
|
|
groupId: GROUP_ID,
|
|
destinationPlanetNumber: 2,
|
|
};
|
|
expect(buildPendingSendLines(report, [cmd], { "cmd-1": "valid" })).toEqual(
|
|
[],
|
|
);
|
|
});
|
|
|
|
test("skips rejected and invalid commands", () => {
|
|
const report = makeReport({
|
|
planets: [SOURCE_PLANET, DEST_PLANET],
|
|
localShipGroups: [localGroup({ id: GROUP_ID, destination: 1 })],
|
|
});
|
|
const cmd: OrderCommand = {
|
|
kind: "sendShipGroup",
|
|
id: "cmd-1",
|
|
groupId: GROUP_ID,
|
|
destinationPlanetNumber: 2,
|
|
};
|
|
expect(
|
|
buildPendingSendLines(report, [cmd], { "cmd-1": "rejected" }),
|
|
).toEqual([]);
|
|
expect(
|
|
buildPendingSendLines(report, [cmd], { "cmd-1": "invalid" }),
|
|
).toEqual([]);
|
|
});
|
|
|
|
test("ignores non-sendShipGroup commands", () => {
|
|
const report = makeReport({
|
|
planets: [SOURCE_PLANET, DEST_PLANET],
|
|
localShipGroups: [localGroup({ id: GROUP_ID, destination: 1 })],
|
|
});
|
|
const cmd: OrderCommand = {
|
|
kind: "dismantleShipGroup",
|
|
id: "cmd-1",
|
|
groupId: GROUP_ID,
|
|
};
|
|
expect(buildPendingSendLines(report, [cmd], { "cmd-1": "valid" })).toEqual(
|
|
[],
|
|
);
|
|
});
|
|
});
|