feat(ui): F8-12 — map polish (zoom invariance, labels, selection, soft radius) (#55)
* Honest pixel-space sizing for `pointRadiusPx` / `strokeWidthPx`: the renderer divides by the current camera scale on every `viewport.zoomed` so thin lines / small markers stay the same on-screen size at any zoom. * Known-size planets switch to `pointRadiusWorld`, softened against the reference scale by `PLANET_SIZE_ZOOM_ALPHA = 0.33`; unidentified planets pin to a 3-px disc. * New planet label layer renders a two-line `name / #N` legend under each planet (`#N` only for unidentified or when the new `planetNames` toggle is off). Selection now paints an inverse-fill frame around the selected planet's label plus an outline on the disc; the old selection-ring primitive is retired. * Bombing markers swap the separate CirclePrim for a planet-outline overlay (damaged / wiped colour); the report deep-link moves to a "view bombing report" link in the planet inspector. * Docs + tests follow: `renderer.md` reflects the new sizing contract + label / outline layers, vitest covers the sizing math, label formatting, and the new toggle, and the map-toggles e2e adds a persistence case for `planetNames`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
// Coverage for the F8-12 / #29 planet-label formatting. The
|
||||
// renderer's per-Pixi.Text drawing lives behind Pixi APIs (and is
|
||||
// exercised by Playwright); this file pins the pure data step.
|
||||
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import type { GameReport } from "../src/api/game-state";
|
||||
import { buildPlanetLabels } from "../src/map/labels";
|
||||
import { EMPTY_SHIP_GROUPS } from "./helpers/empty-ship-groups";
|
||||
|
||||
function makeReport(overrides: Partial<GameReport> = {}): GameReport {
|
||||
return {
|
||||
turn: 1,
|
||||
mapWidth: 100,
|
||||
mapHeight: 100,
|
||||
planetCount: 0,
|
||||
planets: [],
|
||||
race: "",
|
||||
localShipClass: [],
|
||||
routes: [],
|
||||
localPlayerDrive: 0,
|
||||
localPlayerWeapons: 0,
|
||||
localPlayerShields: 0,
|
||||
localPlayerCargo: 0,
|
||||
...EMPTY_SHIP_GROUPS,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("buildPlanetLabels", () => {
|
||||
test("named planet with showNames=true emits both lines", () => {
|
||||
const report = makeReport({
|
||||
planets: [
|
||||
{
|
||||
number: 5,
|
||||
name: "Tancordia",
|
||||
kind: "local",
|
||||
x: 10,
|
||||
y: 20,
|
||||
owner: null,
|
||||
size: null,
|
||||
resources: null,
|
||||
industryStockpile: null,
|
||||
materialsStockpile: null,
|
||||
industry: null,
|
||||
population: null,
|
||||
colonists: null,
|
||||
production: null,
|
||||
freeIndustry: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
const out = buildPlanetLabels(report, { showNames: true });
|
||||
expect(out).toEqual([
|
||||
{
|
||||
planetNumber: 5,
|
||||
x: 10,
|
||||
y: 20,
|
||||
name: "Tancordia",
|
||||
numberLabel: "#5",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("named planet with showNames=false drops the name line", () => {
|
||||
const report = makeReport({
|
||||
planets: [
|
||||
{
|
||||
number: 5,
|
||||
name: "Tancordia",
|
||||
kind: "local",
|
||||
x: 10,
|
||||
y: 20,
|
||||
owner: null,
|
||||
size: null,
|
||||
resources: null,
|
||||
industryStockpile: null,
|
||||
materialsStockpile: null,
|
||||
industry: null,
|
||||
population: null,
|
||||
colonists: null,
|
||||
production: null,
|
||||
freeIndustry: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
const out = buildPlanetLabels(report, { showNames: false });
|
||||
expect(out[0].name).toBeNull();
|
||||
expect(out[0].numberLabel).toBe("#5");
|
||||
});
|
||||
|
||||
test("unidentified planet always renders #N only, ignoring the toggle", () => {
|
||||
const report = makeReport({
|
||||
planets: [
|
||||
{
|
||||
number: 42,
|
||||
name: "Tancordia",
|
||||
kind: "unidentified",
|
||||
x: 5,
|
||||
y: 5,
|
||||
owner: null,
|
||||
size: null,
|
||||
resources: null,
|
||||
industryStockpile: null,
|
||||
materialsStockpile: null,
|
||||
industry: null,
|
||||
population: null,
|
||||
colonists: null,
|
||||
production: null,
|
||||
freeIndustry: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
const on = buildPlanetLabels(report, { showNames: true });
|
||||
const off = buildPlanetLabels(report, { showNames: false });
|
||||
expect(on[0].name).toBeNull();
|
||||
expect(off[0].name).toBeNull();
|
||||
expect(on[0].numberLabel).toBe("#42");
|
||||
});
|
||||
|
||||
test("empty-name planet falls back to #N", () => {
|
||||
const report = makeReport({
|
||||
planets: [
|
||||
{
|
||||
number: 9,
|
||||
name: "",
|
||||
kind: "uninhabited",
|
||||
x: 1,
|
||||
y: 1,
|
||||
owner: null,
|
||||
size: null,
|
||||
resources: null,
|
||||
industryStockpile: null,
|
||||
materialsStockpile: null,
|
||||
industry: null,
|
||||
population: null,
|
||||
colonists: null,
|
||||
production: null,
|
||||
freeIndustry: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
const out = buildPlanetLabels(report, { showNames: true });
|
||||
expect(out[0].name).toBeNull();
|
||||
expect(out[0].numberLabel).toBe("#9");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user