// Valley map QA: for idle and every dragon/route, find text or labels that overlap, fall outside the map, or are too faint. const { chromium } = require("playwright"); const OUT = process.argv[2]; (async () => { const b = await chromium.launch(); const p = await b.newPage({ viewport: { width: 1440, height: 1000 } }); const states = [["idle", "#valley"]]; for (const c of ["red", "orange", "brown", "green", "blue", "black"]) states.push([c, "#valley/" + c]); const extra = { blue: ["shadow-Blue"], red: ["tree-Red"], orange: ["tree-Greens"], brown: ["tree-Greens"] }; for (const [c, encs] of Object.entries(extra)) encs.forEach((e) => states.push([c + "/" + e, `#valley/${c}/${e}`])); for (const [name, hash] of states) { await p.goto("http://localhost:8765/" + hash); await p.waitForTimeout(1800); const res = await p.evaluate(() => { const svg = document.querySelector("#ex-map"), S = svg.getBoundingClientRect(); const items = []; svg.querySelectorAll("text").forEach((t) => { const r = t.getBoundingClientRect(); if (!r.width) return; // walk up for opacity let op = 1; for (let e = t; e && e !== svg; e = e.parentElement) op *= parseFloat(getComputedStyle(e).opacity || 1) * parseFloat(e.getAttribute("fill-opacity") || 1); items.push({ kind: "text", txt: t.textContent.trim(), r: { l: r.left, t: r.top, rr: r.right, b: r.bottom }, op }); }); const out = [], over = []; items.forEach((a) => { if (a.r.l < S.left - 1 || a.r.rr > S.right + 1 || a.r.t < S.top - 1 || a.r.b > S.bottom + 1) out.push(a.txt); }); for (let i = 0; i < items.length; i++) for (let j = i + 1; j < items.length; j++) { const A = items[i].r, B = items[j].r; const ix = Math.min(A.rr, B.rr) - Math.max(A.l, B.l), iy = Math.min(A.b, B.b) - Math.max(A.t, B.t); if (ix > 3 && iy > 3 && items[i].txt !== items[j].txt) over.push(`"${items[i].txt}" × "${items[j].txt}"`); } const dragons = [...svg.querySelectorAll(".ex-dragon")].map((d) => ({ l: d.getAttribute("aria-label") || "twin", op: +d.getAttribute("opacity") })).filter((d) => d.op < 0.3); const card = document.querySelector(".ex-route-card.on"); return { out, over, faint: dragons.map((d) => `${d.l.split(".")[0]} ${d.op}`), focus: card ? card.innerText.split("\n")[0] : "" }; }); console.log(`\n[${name}] ${res.focus}`); if (res.out.length) console.log(" outside:", res.out.join(" | ")); if (res.over.length) console.log(" overlaps:", [...new Set(res.over)].join(" | ")); if (res.faint.length) console.log(" faint (<0.3):", res.faint.join(" | ")); await p.locator("#ex-map").screenshot({ path: `${OUT}/map-${name.replace("/", "_")}.png` }); } await b.close(); })();