0.2.6-dev: a piece has no screen rect until it is first drawn — pieceScreenRect returned a just-built view's unprojected (0, 0) record, so a browser test grabbed a piece bought that frame at the canvas corner (the intermittent .fwheel__dia timeout in coop.e2e / real.e2e); the tests' piecePoint waits for a drawn piece that holds still; golden: unchanged

This commit is contained in:
sganggs committed 2026-10-13 15:54:40 +08:00
1 parent 2b685011e9
commit 1df530f2b9
4 files changed
+38 -9

No files matched your search

+15 -4
View File
@@ -286,12 +286,23 @@ export class Client {
viewKind() { return this.page.evaluate(() => globalThis.__SP_VIEW__?.kind ?? null); }
viewStats() { return this.page.evaluate(() => { try { return globalThis.__SP_VIEW__?.raw?.stats?.() ?? null; } catch { return null; } }); }
/** Client point to grab a prep piece (`at` = fraction of the piece rect's height, from the top). */
piecePoint(uid, at = 0.72) {
return this.page.evaluate((uid, at) => {
/** Client point to grab a prep piece (`at` = fraction of the piece rect's height, from the top). Waits (up to 2.5 s)
* until the piece is drawn and holds still: a piece bought this frame has no rect yet, and one still sliding to its
* tile (0.22 s) would be grabbed over a neighbouring tile — picking is by the tile under the pointer. */
async piecePoint(uid, at = 0.72) {
const read = () => this.page.evaluate((uid, at) => {
const r = globalThis.__SP_VIEW__?.pieceScreenRect(uid);
return r && r.width > 0 ? { x: r.left + r.width / 2, y: r.top + r.height * at } : null;
if (!r || !(r.width >= 4)) return null;
const x = r.left + r.width / 2, y = r.top + r.height * at;
return x >= 0 && y >= 0 && x <= innerWidth && y <= innerHeight ? { x, y } : null;
}, uid, at);
let last = null;
for (const end = Date.now() + 2500; Date.now() < end; await sleep(80)) {
const p = await read();
if (p && last && Math.abs(p.x - last.x) < 1.5 && Math.abs(p.y - last.y) < 1.5) return p;
last = p;
}
return last;
}
/** Record the view's pieceDrop events (for diagnostics) and return + clear them. */
+14 -4
View File
@@ -145,12 +145,22 @@ class Client {
viewKind() { return this.page.evaluate(() => globalThis.__SP_VIEW__?.kind ?? null); }
viewStats() { return this.page.evaluate(() => { try { return globalThis.__SP_VIEW__?.raw?.stats?.() ?? null; } catch { return null; } }); }
/** Client point to grab a prep piece. */
piecePoint(uid) {
return this.page.evaluate((uid) => {
/** Client point to grab a prep piece. Waits (up to 2.5 s) until the piece is drawn and holds still: a piece bought
* this frame has no rect yet, and one still sliding to its tile would be grabbed over a neighbouring tile. */
async piecePoint(uid) {
const read = () => this.page.evaluate((uid) => {
const r = globalThis.__SP_VIEW__?.pieceScreenRect(uid);
return r && r.width > 0 ? { x: r.left + r.width / 2, y: r.top + r.height * 0.72 } : null;
if (!r || !(r.width >= 4)) return null;
const x = r.left + r.width / 2, y = r.top + r.height * 0.72;
return x >= 0 && y >= 0 && x <= innerWidth && y <= innerHeight ? { x, y } : null;
}, uid);
let last = null;
for (const end = Date.now() + 2500; Date.now() < end; await sleep(80)) {
const p = await read();
if (p && last && Math.abs(p.x - last.x) < 1.5 && Math.abs(p.y - last.y) < 1.5) return p;
last = p;
}
return last;
}
/** Client point of a board tile centre (top face). */