// Real browser DOM/CSS with engine services isolated; this is not a full-game test. const assert = require('node:assert/strict'); const http = require('node:http'); const fs = require('node:fs'); const path = require('node:path'); const app = path.resolve(__dirname, '../../../..'); const packages = process.env.CODEX_NODE_MODULES; const { chromium } = require(packages ? path.join(packages, 'playwright') : 'playwright'); const prefix = '/extension/' + encodeURIComponent('术樱包') + '/mengsan'; const decadePrefix = '/extension/' + encodeURIComponent('十周年UI'); const reviewOnly = process.env.HUD_REVIEW === '1'; const journeyReview = process.env.UI_ZOOM_REVIEW === '1'; const holdStatus = async (page, locator, pointerType = 'mouse') => { const box = await locator.boundingBox(); const point = {x:box.x + box.width / 2,y:box.y + box.height / 2}; if (pointerType === 'touch') { await locator.dispatchEvent('pointerdown', {button:0,pointerId:44, pointerType,clientX:point.x,clientY:point.y}); await page.waitForTimeout(550); await page.evaluate(() => window.dispatchEvent( new PointerEvent('pointerup', {pointerId:44,pointerType:'touch'}))); } else { await page.mouse.move(point.x,point.y); await page.mouse.down(); await page.waitForTimeout(550); await page.mouse.up(); } }; // Native themes use different button sizes. Drag onto an exposed point on the // original player, rather than assuming its center is clear in the dense fixture. const exposedTarget = (page,index) => page.evaluate(index => { const player=game.players[index],rect=player.getBoundingClientRect(); for(const y of [.5,.15,.85,.05,.95])for(const x of [.5,.15,.85]) { const px=rect.left+rect.width*x,py=rect.top+rect.height*y; if(document.elementFromPoint(px,py)?.closest('.player')===player)return {x:px,y:py,width:0,height:0}; } throw new Error('Native target has no exposed drag point: '+index); },index); async function checkMobileTargetLine(page, artifact) { const touch = await page.context().newCDPSession(page); const handCard = page.locator('.handcards>.card').first(); const target = await exposedTarget(page, 1); const end = {x:target.x, y:target.y}; const aim = page.locator('.mengsan-hand-aim-shuying'); async function drag() { const start = await handCard.boundingBox(); const source = {x:start.x + start.width / 2,y:start.y + start.height / 2}; await touch.send('Input.dispatchTouchEvent', {type:'touchStart',touchPoints:[source]}); await touch.send('Input.dispatchTouchEvent', {type:'touchMove',touchPoints:[end]}); await aim.waitFor({state:'visible',timeout:2500}); } // Exercise a WebView-style mismatch between the SVG matrix and its painted bounds. await page.evaluate(() => { const create = document.createElementNS.bind(document); document.createElementNS = (namespace,tag) => { const node = create(namespace,tag); if (tag === 'svg') { const screenMatrix = node.getScreenCTM.bind(node); node.getScreenCTM = () => screenMatrix()?.translate(-120,45); } return node; }; }); await drag(); const geometry = await aim.evaluate((overlay, pointer) => { const card = window.card.getBoundingClientRect(); const origin = {x:card.left + card.width / 2, y:card.top}; const line = overlay.querySelector('line'); if (line) { const matrix = line.getScreenCTM(); return {origin,pointer,from:new DOMPoint(line.x1.baseVal.value,line.y1.baseVal.value).matrixTransform(matrix).toJSON(), to:new DOMPoint(line.x2.baseVal.value,line.y2.baseVal.value).matrixTransform(matrix).toJSON(),bounds:line.getBoundingClientRect().toJSON()}; } const bounds = overlay.getBoundingClientRect(); const left = origin.x <= pointer.x, up = origin.y <= pointer.y; return {origin,pointer,from:{x:left?bounds.left:bounds.right,y:up?bounds.top:bounds.bottom}, to:{x:left?bounds.right:bounds.left,y:up?bounds.bottom:bounds.top}}; },end); await page.evaluate(() => { delete document.createElementNS; }); if (artifact) await page.screenshot({path:artifact}); await touch.send('Input.dispatchTouchEvent', {type:'touchCancel',touchPoints:[]}); assert.equal(await aim.count(),0,'the target line disappears on touch cancellation'); assert.ok(Math.hypot(geometry.from.x-geometry.origin.x,geometry.from.y-geometry.origin.y)<=2, 'A012 target line starts at the selected card’s top center: '+JSON.stringify(geometry)); assert.ok(Math.hypot(geometry.to.x-end.x,geometry.to.y-end.y)<=2, 'A012 target line ends at the current touch: '+JSON.stringify(geometry)); assert.ok(geometry.bounds && Math.abs(geometry.bounds.bottom-geometry.origin.y)<=2 && Math.abs(geometry.bounds.top-end.y)<=2,'A012 the rendered line reaches both endpoint heights'); await page.waitForTimeout(180); await drag(); const before = await page.evaluate(()=>game.isSubmitted()); await touch.send('Input.dispatchTouchEvent', {type:'touchEnd',touchPoints:[]}); assert.equal(await aim.count(),0,'the target line disappears on touch release'); assert.equal(await page.evaluate(()=>game.isSubmitted()),before+1,'touch release still submits the valid target once'); } async function checkOrdinaryPlayCenter(page, skin, artifact) { const geometry = await page.evaluate(async skin => { const {arena,control,me} = ui; const prompt = document.createElement('div'); prompt.className = skin === 'native' ? 'dialog' : 'hand-tip'; prompt.textContent = '请选择要使用的牌'; arena.append(prompt); ui.dialog = prompt; hudEventState.event.dialog = prompt; hud.refresh(); await new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))); const bounds = node => node.getBoundingClientRect().toJSON(); const result = {arena:bounds(arena),hand:bounds(me),card:bounds(card),prompt:bounds(prompt), buttons:[...control.firstElementChild.children].map(bounds)}; if (!window.card.isConnected) throw new Error('The original hand card must remain connected'); return result; },skin); if (artifact) await page.screenshot({path:artifact}); await page.evaluate(()=>{ui.dialog.remove();delete ui.dialog;delete hudEventState.event.dialog;hud.refresh();}); const {arena,hand,card,prompt,buttons} = geometry; const center = box => (box.left+box.right)/2; const actions = {left:Math.min(...buttons.map(box=>box.left)),right:Math.max(...buttons.map(box=>box.right))}; assert.ok([hand,card,prompt,actions].every(box=>Math.abs(center(box)-center(arena))<=2), 'ordinary play fan, prompt and action buttons share the arena center: '+JSON.stringify(geometry)); } async function setBattleZoom(page, zoom) { await page.evaluate(zoom => { const {style} = document.body; style.zoom = zoom; style.width = style.height = '100%'; },zoom); // Let the native hand transform and the resize observers settle after a zoom change. await page.waitForFunction(() => { const arena = ui.arena.getBoundingClientRect(), hand = card.getBoundingClientRect(); return Math.abs(arena.width-innerWidth)<=2 && Math.abs((arena.left+arena.right-hand.left-hand.right)/2)<=2; },null,{timeout:2500}); } async function checkCommittedLine(page, skin) { const geometry = await page.evaluate(async ({skin,decadePrefix}) => { const engine = await import('/noname.js'); const {Player} = await import('/noname/library/element/player.js'); const {arena,me:hand} = window.ui; const [actor,target] = window.game.players; // Use the shipped line producers and renderer, with only the game lifecycle isolated. engine.lib.config ??= {}; engine.setUI({arena,create:{div:selector => { const node = document.createElement('div'); if (selector) node.className = 'linexy hidden'; node.show = () => node.classList.remove('hidden'); node.listenTransition = () => {}; node.setBackgroundImage = path => {node.style.backgroundImage = `url(${path})`;}; return node; }},refresh:node=>node.getBoundingClientRect()}); const get = engine.get; engine.setGet({itemtype:()=> 'player',objtype:get.objtype.bind(get),xyDistance:get.xyDistance.bind(get)}); engine.setGame({me:actor,broadcast(){},addVideo(){},linexy:engine.Game.prototype.linexy}); actor.getLeft = target.getLeft = function() { return this.offsetLeft; }; actor.getTop = target.getTop = function() { return this.offsetTop; }; let line = Player.prototype.line; if (skin !== 'native') { const {playerLine} = await import(decadePrefix+'/src/overrides/player/animations.js'); const {BoundsCache} = await import(decadePrefix+'/src/utils/bounds.js'); window.decadeUI ??= {boundsCaches:{hand:new BoundsCache(hand)}}; actor.checkBoundsCache = target.checkBoundsCache = function() { this.cacheLeft = this.offsetLeft; this.cacheTop = this.offsetTop; this.cacheWidth = this.offsetWidth; this.cacheHeight = this.offsetHeight; }; line = playerLine; } line.call(actor,target,{duration:120}); const effect = arena.querySelector('.linexy'); if (!effect) return null; await new Promise(resolve=>setTimeout(resolve,150)); const matrix = new DOMMatrix(getComputedStyle(effect).transform); const x1 = parseFloat(effect.style.left), y1 = parseFloat(effect.style.top); const length = parseFloat(effect.style.height); const expectedStart = skin === 'native' ? {x:actor.offsetLeft+actor.offsetWidth/2,y:actor.offsetTop+actor.offsetHeight/2} : {x:arena.offsetWidth/2,y:hand.offsetTop}; const result = {x1,y1,x2:x1+matrix.c*length,y2:y1+matrix.d*length,expectedStart, expectedEnd:{x:target.offsetLeft+target.offsetWidth/2,y:target.offsetTop+target.offsetHeight/2}}; effect.remove(); // Run the configured renderer as well as the default one. Its art may be provided by the Android package. Object.assign(engine.game,{ linexy:engine.Game.prototype.zsJinlongLineXy, zsPlayLineAnimationByName:engine.Game.prototype.zsPlayLineAnimationByName, zsPlayLineAnimation:engine.Game.prototype.zsPlayLineAnimation, jianqiLineAnim:new engine.Game().jianqiLineAnim, }); line.call(actor,target,{duration:120}); const dragon = arena.lastElementChild; const {left,top,width,transform,backgroundImage} = dragon.style; const degrees = Number(transform.match(/rotate\(([-.\d]+)deg\)/)?.[1]); const radians = degrees*Math.PI/180; const distance = parseFloat(width)-2; const start = {x:parseFloat(left),y:parseFloat(top)+10}; result.dragon = {start,end:{x:start.x+distance*Math.cos(radians),y:start.y+distance*Math.sin(radians)},backgroundImage}; return result; },{skin,decadePrefix}); assert.ok(geometry && Math.hypot(geometry.x1-geometry.expectedStart.x,geometry.y1-geometry.expectedStart.y)<=2 && Math.hypot(geometry.x2-geometry.expectedEnd.x,geometry.y2-geometry.expectedEnd.y)<=2, 'A012 the committed card effect retains its native origin and reaches the target: '+JSON.stringify(geometry)); assert.ok(geometry.dragon.backgroundImage.includes('jinlonglinexy') && Math.hypot(geometry.dragon.start.x-geometry.expectedStart.x,geometry.dragon.start.y-geometry.expectedStart.y)<=2 && Math.hypot(geometry.dragon.end.x-geometry.expectedEnd.x,geometry.dragon.end.y-geometry.expectedEnd.y)<=2, 'the configured Jinlong effect retains its origin and reaches the target: '+JSON.stringify(geometry)); } async function checkBattlePotionSlots(page, skin, artifact) { await page.evaluate(async ({prefix,skin}) => { const {mountPotionSlots} = await import(prefix+'/ui/potions.js'); const {ui,battle,hud} = window; const counter = document.createElement('div'); counter.className = 'cardRoundNumber'; counter.innerHTML = '
';
} else (node.firstElementChild || node).textContent = index ? '取消' : '确定';
node.addEventListener('click',()=>reviewResponses.push(node.dataset.response));
});
window.reviewResponse = {card,prompt};
window.card.classList.add('selected');
window.card.style.backgroundImage = `url("${decadePrefix}/image/card-skins/decade/shan.png")`;
window.card.textContent = '';
hud.refresh();
},{skin,decadePrefix});
await page.waitForTimeout(550);
const geometry = await page.evaluate(() => {
const box = node => node.getBoundingClientRect().toJSON();
return {arena:box(ui.arena), card:box(reviewResponse.card), prompt:box(reviewResponse.prompt),
ok:box(document.querySelector('[data-response="ok"]')),cancel:box(document.querySelector('[data-response="cancel"]')),
hand:box(card)};
});
if (artifact) await page.screenshot({path:artifact});
const {arena, card, prompt, ok, cancel, hand} = geometry;
const center = ({left,right}) => (left + right) / 2;
assert.ok([card,prompt,{left:ok.left,right:cancel.right}].every(box=>Math.abs(center(box)-center(arena))<=2),
'A013 played card, response prompt and action group share the arena center: '+JSON.stringify(geometry));
const gap = 4;
assert.ok(card.top >= arena.top+2 && card.bottom+gap <= prompt.top && prompt.bottom+gap <= Math.min(ok.top,cancel.top) &&
Math.max(ok.bottom,cancel.bottom)+gap <= hand.top && ok.right <= cancel.left,
'A013 played card, prompt, actions and selected hand card do not overlap: '+JSON.stringify(geometry));
await page.locator('[data-response="ok"]').tap();
await page.locator('[data-response="cancel"]').tap();
assert.deepEqual(await page.evaluate(()=>reviewResponses),['ok','cancel'],'both original response callbacks are reachable');
const restored = await page.evaluate(() => {
delete hudEventState.event.respondTo;
hud.refresh();
const verticalShift = Number.parseFloat(ui.control.style.translate.split(/\s+/)[1]) || 0;
return verticalShift === 0 && reviewResponse.card.style.translate === '';
});
assert.ok(restored,'response spacing is released when the original event ends');
}
const fixture = `