fix(viewer): outline white planets in matching type highlights
This commit is contained in:
parent
6c139f7c4d
commit
c1acabcf58
6 changed files with 227 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/old-ui",
|
||||
"version": "1.2.35",
|
||||
"version": "1.2.36",
|
||||
"scripts": {
|
||||
"serve": "vite --port 5193",
|
||||
"build": "vite build",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/viewer",
|
||||
"version": "5.22.35",
|
||||
"version": "5.22.36",
|
||||
"description": "Functions to visualize the map and boards for gaia project inside html canvas",
|
||||
"contributors": [
|
||||
"coyotte508",
|
||||
|
|
|
|||
143
viewer/scripts/planet-highlight-smoke.mjs
Normal file
143
viewer/scripts/planet-highlight-smoke.mjs
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { createServer } from "node:http";
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { chromium, webkit } from "playwright";
|
||||
|
||||
// Run after building both UIs: cd viewer && node scripts/planet-highlight-smoke.mjs
|
||||
// Repeat with BROWSER=webkit; BROWSER_EXECUTABLE can select a locally installed browser.
|
||||
// Uses only unmodified local production bundles/fixtures; screenshots go to /tmp.
|
||||
const require = createRequire(import.meta.url);
|
||||
const repo = new URL("../../", import.meta.url);
|
||||
const engine = require(fileURLToPath(new URL("engine/dist/index.js", repo)));
|
||||
const modes = ["normal", "old"];
|
||||
const html =
|
||||
'<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/bundle.css"><div id="app"></div><script src="/vue.js"></script>' +
|
||||
'<script src="/bootstrap.js"></script>' +
|
||||
'<script src="/bundle.js"></script>';
|
||||
let mode = "normal";
|
||||
const server = createServer(async (req, res) => {
|
||||
try {
|
||||
const bundle = mode === "old" ? "old-ui/dist/package/old-ui.umd.js" : "viewer/dist/package/viewer.umd.js";
|
||||
const css = mode === "old" ? "old-ui/dist/package/old-ui.css" : "viewer/dist/package/viewer.css";
|
||||
const files = {
|
||||
"/bundle.js": fileURLToPath(new URL(bundle, repo)),
|
||||
"/bundle.css": fileURLToPath(new URL(css, repo)),
|
||||
"/vue.js": require.resolve("vue/dist/vue.min.js"),
|
||||
"/bootstrap.js": require.resolve("bootstrap-vue/dist/bootstrap-vue.min.js"),
|
||||
};
|
||||
if (req.url === "/") {
|
||||
res.setHeader("Content-Type", "text/html");
|
||||
res.end(html);
|
||||
} else if (/^\/[a-zA-Z0-9-]+\.(json|jpg)$/.test(req.url)) {
|
||||
res.setHeader("Content-Type", req.url.endsWith(".json") ? "application/json" : "image/jpeg");
|
||||
res.end(
|
||||
await readFile(
|
||||
fileURLToPath(new URL((mode === "old" ? "old-ui/dist/package" : "viewer/dist/package") + req.url, repo))
|
||||
)
|
||||
);
|
||||
} else if (files[req.url]) {
|
||||
res.setHeader("Content-Type", req.url.endsWith(".css") ? "text/css" : "text/javascript; charset=utf-8");
|
||||
res.end(await readFile(files[req.url]));
|
||||
} else {
|
||||
res.statusCode = 404;
|
||||
res.end();
|
||||
}
|
||||
} catch (error) {
|
||||
res.statusCode = 500;
|
||||
res.end(String(error));
|
||||
}
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
const browserName = process.env.BROWSER || "chromium";
|
||||
assert.ok(["chromium", "webkit"].includes(browserName));
|
||||
const browser = await { chromium, webkit }[browserName].launch({
|
||||
executablePath:
|
||||
process.env.BROWSER_EXECUTABLE || (browserName === "chromium" ? process.env.CHROMIUM_EXECUTABLE : undefined),
|
||||
});
|
||||
try {
|
||||
for (const ui of modes) {
|
||||
mode = ui;
|
||||
for (const width of [390, 1400]) {
|
||||
const page = await browser.newPage({ viewport: { width, height: 900 } });
|
||||
const errors = [];
|
||||
page.on("pageerror", (error) => errors.push(String(error)));
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/`);
|
||||
const state = new engine.default(["init 2 white-planet-contrast", "p1 faction terrans", "p2 faction nevlas"]);
|
||||
await page.evaluate(
|
||||
(state) => {
|
||||
window.host = window.gaiaViewer.launch("#app");
|
||||
host.emit("preferences", { sound: false });
|
||||
host.emit("state", state);
|
||||
},
|
||||
JSON.parse(JSON.stringify(state))
|
||||
);
|
||||
await page.waitForSelector(".space-hex-cell circle.planet.i");
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await page.evaluate((theme) => document.documentElement.setAttribute("data-theme", theme), theme);
|
||||
const result = await page.evaluate(async () => {
|
||||
const cell = [...document.querySelectorAll(".space-hex-cell")].find(
|
||||
(el) => el.querySelector("circle.planet.i") && !el.querySelector(".building")
|
||||
);
|
||||
const circle = cell.querySelector("circle.planet.i");
|
||||
const store = cell.__vue__.$store;
|
||||
// Isolate the map filter from the game's initial build-selection overlays.
|
||||
store.state.context.highlighted.hexes = null;
|
||||
await Vue.nextTick();
|
||||
const snapshot = () => ({
|
||||
stroke: getComputedStyle(circle).stroke,
|
||||
width: getComputedStyle(circle).strokeWidth,
|
||||
radius: circle.getAttribute("r"),
|
||||
count: cell.querySelectorAll("*").length,
|
||||
markers: cell.querySelectorAll("use").length,
|
||||
});
|
||||
const toggle = async (planet) => {
|
||||
store.commit("toggleMapMode", { type: "planetType", planet });
|
||||
await Vue.nextTick();
|
||||
};
|
||||
const off = snapshot();
|
||||
await toggle("i");
|
||||
const on = snapshot();
|
||||
circle.classList.add("warn");
|
||||
const warn = snapshot();
|
||||
circle.classList.remove("warn");
|
||||
await toggle("i");
|
||||
const again = snapshot();
|
||||
await toggle("r");
|
||||
const mismatch = snapshot();
|
||||
const otherMarked = document.querySelectorAll(".planet-type-highlighted").length;
|
||||
await toggle("r");
|
||||
await toggle("i");
|
||||
return { off, on, warn, again, mismatch, otherMarked };
|
||||
});
|
||||
assert.equal(result.on.stroke, "rgb(0, 0, 0)");
|
||||
assert.equal(result.on.width, "0.1px");
|
||||
assert.equal(result.warn.stroke, result.off.stroke, "warn excludes the black filter outline");
|
||||
assert.deepEqual(result.again, result.off, "toggle off restores original styling");
|
||||
assert.deepEqual(result.mismatch, result.off, "another type leaves Ice alone");
|
||||
assert.equal(result.otherMarked, 0);
|
||||
for (const prop of ["radius", "count", "markers"]) assert.equal(result.on[prop], result.off[prop]);
|
||||
await page
|
||||
.locator("svg")
|
||||
.filter({ has: page.locator(".space-hex-cell") })
|
||||
.first()
|
||||
.screenshot({ path: `/tmp/white-planet-${browserName}-${ui}-${width}-${theme}.png` });
|
||||
await page.evaluate(async () => {
|
||||
document
|
||||
.querySelector(".space-hex-cell")
|
||||
.__vue__.$store.commit("toggleMapMode", { type: "planetType", planet: "i" });
|
||||
await Vue.nextTick();
|
||||
});
|
||||
console.log(
|
||||
`${browserName} ${ui} ${width}px ${theme}: Ice contour, off/mismatch, warning priority, unchanged geometry/markers passed`
|
||||
);
|
||||
}
|
||||
assert.deepEqual(errors, [], "no browser errors");
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
|
|
@ -107,7 +107,8 @@ svg {
|
|||
&.i {
|
||||
stroke: var(--ice);
|
||||
|
||||
&.highlighted:not(.warn) {
|
||||
&.highlighted:not(.warn),
|
||||
&.planet-type-highlighted:not(.warn) {
|
||||
stroke-width: 0.1;
|
||||
stroke: black;
|
||||
}
|
||||
|
|
|
|||
75
viewer/src/components/PlanetTypeHighlight.spec.ts
Normal file
75
viewer/src/components/PlanetTypeHighlight.spec.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import Engine, { Planet } from "@gaia-project/engine";
|
||||
import { render } from "@testing-library/vue";
|
||||
import { expect } from "chai";
|
||||
import Vue from "vue";
|
||||
import OldSpaceHex from "../../../old-ui/src/components/SpaceHex.vue";
|
||||
import { MapModeType } from "../data/actions";
|
||||
import { makeStore } from "../store";
|
||||
import SpaceHex from "./SpaceHex.vue";
|
||||
|
||||
for (const [name, component] of [
|
||||
["current", SpaceHex],
|
||||
["alternate", OldSpaceHex],
|
||||
] as const) {
|
||||
describe(`${name} white planet-type highlight`, () => {
|
||||
it("outlines the existing Ice disc only while its type matches, without adding markers or selection", async () => {
|
||||
const engine = new Engine(["init 2 white-planet-contrast"]);
|
||||
const store = makeStore();
|
||||
store.commit("receiveData", engine);
|
||||
const hex = [...engine.map.grid.values()].find((hex) => hex.data.planet === Planet.Ice);
|
||||
const { container } = render(component, { store, props: { hex } });
|
||||
const outline = container.querySelector("circle.planet.i");
|
||||
expect(outline).not.to.equal(null);
|
||||
const count = container.querySelectorAll("*").length;
|
||||
const radius = outline.getAttribute("r");
|
||||
const toggle = async (planet: Planet) => {
|
||||
store.commit("toggleMapMode", { type: MapModeType.planetType, planet });
|
||||
await Vue.nextTick();
|
||||
};
|
||||
const check = (active: boolean) => {
|
||||
expect(outline.classList.contains("planet-type-highlighted")).to.equal(active);
|
||||
expect(outline.classList.contains("highlighted")).to.equal(false);
|
||||
expect(container.querySelector("use.space-hex").classList.contains("bold")).to.equal(active);
|
||||
expect(container.querySelectorAll("*").length).to.equal(count);
|
||||
expect(outline.getAttribute("r")).to.equal(radius);
|
||||
expect(container.querySelector(".space-hex-federation")).to.equal(null);
|
||||
};
|
||||
check(false);
|
||||
await toggle(Planet.Ice);
|
||||
check(true);
|
||||
await toggle(Planet.Ice);
|
||||
check(false);
|
||||
await toggle(Planet.Terra);
|
||||
check(false);
|
||||
});
|
||||
|
||||
it("preserves build selection independently of the planet-type filter", async () => {
|
||||
const engine = new Engine(["init 2 white-planet-contrast"]);
|
||||
const store = makeStore();
|
||||
store.commit("receiveData", engine);
|
||||
const hex = [...engine.map.grid.values()].find((hex) => hex.data.planet === Planet.Ice);
|
||||
store.commit("highlightHexes", { hexes: new Map([[hex, {}]]) });
|
||||
const { container } = render(component, { store, props: { hex } });
|
||||
const circle = container.querySelector("circle.planet.i");
|
||||
expect(circle.classList.contains("highlighted")).to.equal(true);
|
||||
for (const active of [true, false]) {
|
||||
store.commit("toggleMapMode", { type: MapModeType.planetType, planet: Planet.Ice });
|
||||
await Vue.nextTick();
|
||||
expect(circle.classList.contains("highlighted")).to.equal(true);
|
||||
expect(circle.classList.contains("planet-type-highlighted")).to.equal(active);
|
||||
}
|
||||
});
|
||||
|
||||
it("does not mark other matching planet types", async () => {
|
||||
const engine = new Engine(["init 2 white-planet-contrast"]);
|
||||
const store = makeStore();
|
||||
store.commit("receiveData", engine);
|
||||
const hex = [...engine.map.grid.values()].find((hex) => hex.data.planet === Planet.Terra);
|
||||
const { container } = render(component, { store, props: { hex } });
|
||||
store.commit("toggleMapMode", { type: MapModeType.planetType, planet: Planet.Terra });
|
||||
await Vue.nextTick();
|
||||
expect(container.querySelector("use.space-hex.bold")).not.to.equal(null);
|
||||
expect(container.querySelector(".planet-type-highlighted")).to.equal(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -310,6 +310,11 @@ export default class SpaceHex extends Vue {
|
|||
if (highlightHex) {
|
||||
ret.push("highlighted");
|
||||
}
|
||||
// Keep white planets legible on the white planet-type highlight, without
|
||||
// treating a map filter as a build selection or changing other planet types.
|
||||
if (hex.data.planet === PlanetEnum.Ice && this.planetMapMode) {
|
||||
ret.push("planet-type-highlighted");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue