From 98116bef7ba92de653eb6052866072f1b63d1771 Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Tue, 24 Nov 2026 12:08:04 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20#=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=A0=B7=E5=BC=8FBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .agents/skills/comet-review/SKILL.md | 6 +- AGENTS.md | 4 + docs/reviews/mengsan-battle-ui.md | 25 ++ .../plans/2026-11-24-mengsan-zip-install.md | 8 +- extension.js | 2 +- mengsan/tools/test-battle-hud.cjs | 358 +++++++++++++++++- mengsan/ui/hand/input.js | 28 +- mengsan/ui/hand/style.css | 18 +- mengsan/ui/hud/index.js | 16 +- mengsan/ui/hud/overlays.js | 107 +++++- mengsan/ui/potions.css | 15 +- mengsan/ui/potions.js | 45 ++- tools/UPDATE.md | 2 +- tools/build_mengsan_archives.py | 4 +- tools/test_mengsan_archives.py | 6 +- tools/test_mengsan_zip_install.mjs | 30 +- update.js | 4 +- 17 files changed, 605 insertions(+), 73 deletions(-) create mode 100644 docs/reviews/mengsan-battle-ui.md diff --git a/.agents/skills/comet-review/SKILL.md b/.agents/skills/comet-review/SKILL.md index 2846790..c72dda2 100644 --- a/.agents/skills/comet-review/SKILL.md +++ b/.agents/skills/comet-review/SKILL.md @@ -20,7 +20,7 @@ The entire Skill invocation must remain read-only: - Do not fix findings, advance phase, or update tasks, state, verification reports, or review records. - Do not call this review a Verify pass or treat “no findings” as proof that tests passed. -Only run commands needed to read files, query state, and inspect Git diffs. Checks that might execute project code, install dependencies, or produce files are outside this entry's scope. +Only run commands needed to read files, query state, and inspect Git diffs, plus the focused browser check in the [battle UI review checklist](../../../docs/reviews/mengsan-battle-ui.md). Run that check without screenshot output unless a temporary directory outside the repository has been designated for review evidence. All other checks that execute project code, install dependencies, or produce files are outside this entry's scope. ## 1. Locate the project and current change @@ -80,6 +80,8 @@ If the available evidence still cannot establish a reliable, verifiable baseline ## 4. Perform the review +Apply the battle UI review checklist and record the results by scenario name in the evidence status. Reuse evidence bound to the current changes when available. + Review the requirements, tasks, and current diff, focusing only on: - Implementation correctness and clear logic errors. @@ -110,7 +112,7 @@ Evidence: The specific relationship to the diff, task, spec, or verification rec Then include: - `Review scope`: workflow, change, phase, baseline, included diffs, and any scope limitations. -- `Evidence status`: the test, build, and verification records inspected and whether they still apply to the current changes. Do not rerun tests. +- `Evidence status`: report each battle UI scenario by its name in the checklist, together with the other test, build, and verification records inspected and whether they still apply to the current changes. - `Open questions`: only questions that actually prevent a judgment. - `Conclusion`: the finding count, or an explicit “No concrete findings.” diff --git a/AGENTS.md b/AGENTS.md index 19a6f6a..06273d0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -63,3 +63,7 @@ gives you structural context (callers, dependents, test coverage) that file sear 3. Use `get_affected_flows_tool` to understand impact. 4. Use `query_graph_tool` pattern="tests_for" to check coverage. + +## 梦三战斗 UI 审查 + +每次 review 都按 [梦三战斗 UI 回归清单](docs/reviews/mengsan-battle-ui.md) 逐项核验,并记录结果和验证环境。涉及战斗 UI 的改动须附本轮渲染截图,并单独记录 Android 实机验证状态。 diff --git a/docs/reviews/mengsan-battle-ui.md b/docs/reviews/mengsan-battle-ui.md new file mode 100644 index 0000000..74c97c6 --- /dev/null +++ b/docs/reviews/mengsan-battle-ui.md @@ -0,0 +1,25 @@ +# 梦三战斗 UI 回归清单 + +每次 review 核验下表各项。在报告中逐项写明通过、失败或未验,并记录证据对应的代码版本、皮肤、尺寸和缩放。涉及战斗 UI 的改动,附受影响场景的渲染截图。 + +| 场景 | 操作与通过标准 | +| --- | --- | +| 触屏拖牌与目标连线 | 从手牌拖出一张【杀】并移动到可选敌人。线起点贴在拖动牌上缘中央,终点跟随触点,两端误差各不超过 2 CSS px。取消手势后线立即消失。对合法目标松手后拖线立即消失,原生提交只触发一次。完整对局中再检查提交后的出牌特效能指向实际目标。 | +| 出牌响应布局与按钮交互 | 敌人出【杀】,选择【闪】,观察场上出牌副本、响应文字与「确定/取消」两键的整体边界。三者从上到下共用战场中线,横向中心误差不超过 2 CSS px,牌面、提示、按钮和选中手牌之间有可见间距。确认和取消分别可点击,响应结束后场上的牌恢复原生位置。 | +| 弃牌时技能栏稳定 | 启用十周年 UI,进入需弃置两张手牌的场景并点选第一张。技能栏在重建的首帧起就不出现重复的药水按钮,普通技能仍可见,弃牌计数正常更新。 | +| 战斗药水槽与计数信息 | 持有药水进入战斗。药水槽位于左上区域,可贴近轮数、时间及牌堆数量控件,各自的可见区域互不重叠。点按药水可打开详情,并能在可用阶段正常使用。 | + +## 浏览器回归 + +从无名游戏目录内的术樱包根目录执行。脚本使用本地引擎、十周年 UI 样式、Playwright 和 Microsoft Edge。Playwright 安装在其他目录时,可将 `CODEX_NODE_MODULES` 指向包含它的 `node_modules`。 + +```powershell +$env:HUD_REVIEW = '1' +node mengsan/tools/test-battle-hud.cjs +``` + +需要截图时,将 `HUD_ARTIFACTS` 指向已建立的临时目录。完整矩阵覆盖原生 UI、十周年 UI 的手杀、十周年和新杀风格,以及 1080×486、812×375、667×375,含 0.64 页面缩放和非整数像素比。各场景检查拖牌、出牌连线、响应和药水槽位置,启用十周年 UI 的场景另测弃牌时的技能栏重建。 + +## Android 实机复核 + +在本轮改动对应的 Android 客户端启用十周年 UI,使用该客户端当前启用的皮肤复核各场景,并记录十周年 UI 版本和皮肤。拖牌时分别观察松手前的拖线和松手后的出牌特效。响应用两次事件分别检查确认和取消。弃牌时观察点牌瞬间,检查原生计数面板与药水槽能同时看清并各自操作。实机结果单独记录,实机不可用时写明未验。 diff --git a/docs/superpowers/plans/2026-11-24-mengsan-zip-install.md b/docs/superpowers/plans/2026-11-24-mengsan-zip-install.md index 1ed2c47..b5ddbec 100644 --- a/docs/superpowers/plans/2026-11-24-mengsan-zip-install.md +++ b/docs/superpowers/plans/2026-11-24-mengsan-zip-install.md @@ -38,9 +38,9 @@ **接口** `build_archives(root: Path, output: Path, tag: str) -> list[Path]` 使用 `root/dist/modules/mengsan.json`,生成 `mengsan--part-001.zip` 等附件。条目名为 `mengsan/…`,与模块清单路径逐字一致。 -- [ ] 在 `tools/test_mengsan_archives.py` 写 `test_parts_cover_packable_files_once` 和 `test_reject_inconsistent_release`。用临时目录验证 `Counter(written_paths) == Counter(packable_paths)`、条目 SHA-256 与清单一致、超出 5 MiB 的单文件不入包。对清单版本不匹配、源文件变化和单个分包成品超过 6 MiB 分别断言生成失败。 +- [ ] 在 `tools/test_mengsan_archives.py` 写 `test_parts_cover_packable_files_once` 和 `test_reject_inconsistent_release`。用临时目录验证 `Counter(written_paths) == Counter(packable_paths)`、条目 SHA-256 与清单一致、超出 10 MiB 的单文件不入包。对清单版本不匹配、源文件变化和单个分包成品超过 11 MiB 分别断言生成失败。 - [ ] 运行 `python -m unittest discover -s tools -p test_mengsan_archives.py`,确认因生成器尚缺而失败。 -- [ ] 实现生成器及 CLI `python tools/build_mengsan_archives.py --root --out-dir --tag `。按清单路径排序,依次填入每包合计最多 5 MiB 的未压缩文件。使用 `ZIP_DEFLATED`、压缩级别 6。关闭 ZIP 后检查成品不超过 6 MiB,逐项校验路径、大小和 SHA-256,并检查各包合计覆盖所有可打包条目。两个上限是实测起点,调整时同步客户端和测试。 +- [ ] 实现生成器及 CLI `python tools/build_mengsan_archives.py --root --out-dir --tag `。按清单路径排序,依次填入每包合计最多 10 MiB 的未压缩文件。使用 `ZIP_DEFLATED`、压缩级别 6。关闭 ZIP 后检查成品不超过 11 MiB,逐项校验路径、大小和 SHA-256,并检查各包合计覆盖所有可打包条目。调整上限时同步客户端和测试。 - [ ] 重跑 Python 测试并确认通过。以当前分支生成的清单和导出快照运行 CLI,检查实际分包数、最大包大小和完整覆盖。使用发布工作流同样的标签快照校验命令 `python tools/verify_manifest.py --root --version `。 ## 任务二 · 接入两个发布工作流 @@ -57,14 +57,14 @@ - [ ] 在 `tools/test_mengsan_zip_install.mjs` 用 `node:test` 从正常菜单入口 `manageMengsanModule` 触发安装。`fresh install stages from selected release` 对两个源分别断言附件查询标签正确、成功分包文件无 raw 请求、所有文件备齐前无正式路径写入。`falls back for missing or unusable release parts` 覆盖 Release 404、草稿、标签不匹配、超限响应、损坏 ZIP、越界条目和错误 SHA-256,断言 `rawRequests` 恰好等于未成功暂存文件。`retries the failed ZIP once` 覆盖单包下载异常后成功。`staging write errors preserve recovery` 断言写入失败后无后续 raw 请求。`installed updates and legacy repairs stay on raw` 从 `checkVersion`、`repairMissingFiles` 和旧修复记录分别验证无 Release 请求。至少一个解析用例使用宿主实际捆绑的 JSZip 2.7 和脚本生成的 ZIP。 - [ ] 运行 `node --experimental-vm-modules --test tools/test_mengsan_zip_install.mjs` 并确认新增 ZIP 场景因当前只请求 raw 文件而失败。可通过 `vm.SourceTextModule` 和测试用 `SyntheticModule` 为 `../../noname.js` 注入宿主 API,无需从产品代码导出测试接口。 -- [ ] 在 `update.js` 实现附件查询和下载。两源均请求所选 `/releases/tags/`,要求 `tag_name` 匹配且 `draft` 为 `false`。仅接收与版本文件名匹配、`size` 为正整数且不超过 6 MiB 的附件。使用该源的 HTTPS `browser_download_url`。GitHub 现有附件链接与 CDN 实测缺少浏览器跨域响应头,因此 Electron 使用支持 HTTPS 重定向的原生请求,Cordova 使用 `FileTransfer` 下载到本次操作目录,校验文件大小后读取并清理。网页 Fetch 用尽该附件的网络重试后回退同源逐文件下载。 +- [ ] 在 `update.js` 实现附件查询和下载。两源均请求所选 `/releases/tags/`,要求 `tag_name` 匹配且 `draft` 为 `false`。仅接收与版本文件名匹配、`size` 为正整数且不超过 11 MiB 的附件。使用该源的 HTTPS `browser_download_url`。GitHub 现有附件链接与 CDN 实测缺少浏览器跨域响应头,因此 Electron 使用支持 HTTPS 重定向的原生请求,Cordova 使用 `FileTransfer` 下载到本次操作目录,校验文件大小后读取并清理。网页 Fetch 用尽该附件的网络重试后回退同源逐文件下载。 - [ ] 使用 `get.zip` 获取 JSZip,逐包调用 `load` 读取目录和压缩字节。解包前检查文件名、清单归属、单条目声明大小和包内合计上限。用 `DecompressionStream("deflate-raw")` 解压到按清单大小分配的缓冲区并限制实际输出,随后调用 `verifyFile` 和 `stageVerified`。缺少流式解压能力的客户端直接逐文件下载。异常 ZIP 至多重新取一次再回退。校验、网络和解包错误记录包名及原因。写盘错误从暂存阶段直接抛出。 - [ ] 在 `manageMengsanModule` 判定首次安装。无既有安装,或已明确清空的卸载记录进入全新安装;旧待修复记录按原路径。操作记录只在已知首次安装进入 `installing` 时标记 `freshInstall: true`,失败后该标记用于重新发起完整下载。通过 `installMengsanFiles` 把这个选择传给 `updateAllFiles` 的暂存阶段;本次已完成的文件更新原进度和清理集合,原文件池仅处理剩余项。将 ZIP 网络进度与已验证文件字节分开,避免回退时重复计数。保留现有正式路径落盘前复核及安装记录提交逻辑。 - [ ] 运行 `node --check update.js` 和 Node 测试,确认通过。分别用清单对比正常 ZIP 和逐文件回退的最终目录及安装记录,确认每个新文件大小和 SHA-256 一致。 ## 任务四 · 实机验收和默认启用 -- [ ] 在同一台受支持手机上,用同一客户端版本、梦三标签、下载源和网络条件,对逐文件和分包的干净安装各测三次。每次从确认安装计时到校验完成。通过网络记录统计资源请求数,从应用及其 WebView 进程记录内存峰值,报告原始样本和中位数。先测 5 MiB 展开、6 MiB 下载上限,再按实测调整。 +- [ ] 在同一台受支持手机上,用同一客户端版本、梦三标签、下载源和网络条件,对逐文件和分包的干净安装各测三次。每次从确认安装计时到校验完成。通过网络记录统计资源请求数,从应用及其 WebView 进程记录内存峰值,报告原始样本和中位数。先测 10 MiB 展开、11 MiB 下载上限,再按实测调整。 - [ ] 在客户端真实窗口验证 GitHub 与 Gitea Release 的匿名下载、重定向和跨域行为,并分别验证 ZIP 不可用时回退到当前源的同标签文件。测试手机端强制退出后再点击安装。通过安装记录、清单校验和重启后进入梦三确认结果。另跑桌面端首次安装及差量更新一次。 - [ ] 对照同环境逐文件基线检验收益。建议启用条件为手机端资源请求数和总耗时中位数下降,内存峰值无可重复的上升,两个源与回退均通过。记录采用的包大小、测试设备和结果,再启用默认 ZIP 路径。 diff --git a/extension.js b/extension.js index 07aefa8..c9e19cd 100644 --- a/extension.js +++ b/extension.js @@ -6,7 +6,7 @@ import { configureDiagnostics } from "./diagnostics/index.js"; export const type = "extension"; export let shuYing = new Object(); -const shuYingLocalVersion = "2.0.2.3-rc.9"; +const shuYingLocalVersion = "2.0.2.3-rc.10"; shuYing.name = "术樱包"; shuYing.editable = false; diff --git a/mengsan/tools/test-battle-hud.cjs b/mengsan/tools/test-battle-hud.cjs index 246c3bf..eb81c9e 100644 --- a/mengsan/tools/test-battle-hud.cjs +++ b/mengsan/tools/test-battle-hud.cjs @@ -4,9 +4,11 @@ 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 || 'C:/Users/Diuse/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules'; -const { chromium } = require(path.join(packages, 'playwright')); +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 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}; @@ -31,10 +33,315 @@ const exposedTarget = (page,index) => page.evaluate(index => { } 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}); + } + 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); + 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 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:() => { + const node = document.createElement('div'); + node.className = 'linexy hidden'; + node.show = () => node.classList.remove('hidden'); + node.listenTransition = () => {}; + 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(); + 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)); +} + +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 = '
23
第3轮
03:00
'; + if (skin === 'native') counter.style.cssText = 'left:18px;top:4px;width:140px;height:40px'; + (skin === 'shousha' ? document.body : ui.arena).append(counter); + ui.cardRoundTime = counter; + window.reviewCounter = counter; + window.potionActionCalls = 0; + battle.potionUI = mountPotionSlots(ui.arena,{potions:['ENERGY_POTION',null,'FIRE_POTION']},{ + canUse:()=>true,use:()=>{ window.potionActionCalls++; }, + }); + hud.refresh(); + },{prefix,skin}); + const geometry = await page.evaluate(() => { + const box = node => node.getBoundingClientRect().toJSON(); + return {arena:box(ui.arena),strip:box(document.querySelector('.mengsan-battle-potions')), + counters:[reviewCounter,...reviewCounter.querySelectorAll('div,span')].map(box)}; + }); + const {arena,strip,counters} = geometry; + assert.ok(strip.left>=arena.left && strip.right<=arena.left+arena.width/2 && strip.top>=arena.top && + strip.bottom<=arena.top+140,'battle potions stay at the upper left: '+JSON.stringify(geometry)); + assert.ok(counters.every(box=>!box.width||!box.height||strip.right<=box.left||strip.left>=box.right|| + strip.bottom<=box.top||strip.top>=box.bottom),'battle potion slots clear the round, time and pile counters'); + if (artifact) await page.screenshot({path:artifact}); + await page.getByRole('button',{name:'能量药水',exact:true}).tap(); + await page.getByRole('button',{name:'使用',exact:true}).tap(); + assert.equal(await page.evaluate(()=>potionActionCalls),1,'the relocated potion button opens details and submits once'); + const fallback = await page.evaluate(() => { + reviewCounter.className = ''; + reviewCounter.replaceChildren(); + reviewCounter.style.cssText = 'position:absolute;left:0;top:0;width:46%;height:46px;transition:none'; + hud.refresh(); + const panel = reviewCounter.getBoundingClientRect(), arena = ui.arena.getBoundingClientRect(); + const slots = ui.arena.querySelector('.mengsan-battle-potions').getBoundingClientRect(); + return slots.top>panel.bottom && slots.left>=arena.left && slots.right<=arena.left+arena.width/2; + }); + assert.ok(fallback,'the potion strip drops below a counter that leaves no room beside it'); + await page.evaluate(()=>{battle.potionUI.dispose();delete battle.potionUI;reviewCounter.remove();delete ui.cardRoundTime;}); +} + +async function checkPotionSkillsDuringDiscard(page, skin, artifact) { + const [factory,filename] = {shousha:['createShoushaSkillPlugin','shousha'], + shizhounian:['createShizhounianSkillPlugin','shizhounian'],xinsha:['createXinshaSkillPlugin','xinsha']}[skin]; + await page.evaluate(async ({prefix,decadePrefix,filename,factory}) => { + const [engine,{Click},{Check},skinModule,{createBaseLbtnPlugin},potions] = await Promise.all([ + import('/noname.js'),import('/noname/ui/click/index.js'),import('/noname/game/check.js'), + import(decadePrefix+`/ui/skill/skins/${filename}.js`),import(decadePrefix+'/ui/lbtn/skins/base.js'),import(prefix+'/potions/battle.js'), + ]); + const {ui,game,card,hud,hudEventState:status} = window; + const me = game.me; + const passive = 'mengsan_taoyuan_bond_shuying'; + const names = {...potions.potionSkillTranslations,[passive]:'桃园羁绊'}; + const skill = {...potions.createPotionSkills(()=>null,game),[passive]:{locked:true,mark:true}}; + const config = {touchscreen:true,phonelayout:true,extension_十周年UI_rightLayout:'on'}; + const lib = {config,skill}; + const get = {info:id=>skill[id],translation:id=>names[id]||id, + is:{locked:id=>id===passive,zhuanhuanji:()=>false,phoneLayout:()=>true}}; + const app = {listen(){},reWriteFunction(){},get:{skillInfo(id) { + return {id,name:id,info:skill[id],translation:names[id],type:skill[id].enable?'enable':'trigger'}; + }}}; + Array.prototype.addArray ??= function(items){for(const item of items)if(!this.includes(item))this.push(item);return this;}; + Array.prototype.add ??= function(item){if(!this.includes(item))this.push(item);return this;}; + Array.prototype.remove ??= function(item){const i=this.indexOf(item);if(i!==-1)this.splice(i,1);return this;}; + ui.controls = [ui.control.firstElementChild]; + ui.updatec = ()=>{}; + ui.create = {div(selector,parent,label) { + const node = document.createElement('div'); + if(selector) node.className = selector.split('.').filter(Boolean).join(' '); + if(label) node.textContent=label; + parent?.appendChild(node); + return node; + },control:()=>ui.control.firstElementChild}; + engine.lib.config = config; + engine.lib.device = 'android'; + engine.setUI(ui);engine.setGame(game);engine.setGet(get);engine.setStatus(status); + Object.assign(status.event,{name:'chooseToDiscard',selectCard:[2,2],position:'h'}); + delete status.event.respondTo; + window.reviewResponse.card.remove(); + ui.thrown = []; + const prompt = window.reviewResponse.prompt; + const count = document.createElement('span'); + count.textContent = '0/2'; + prompt.replaceChildren('请弃置两张手牌',document.createElement('br'),count); + status.event.custom = {add:{card() {count.textContent = `${ui.selected.cards.length}/2`;}}}; + Object.assign(me,{getSkills:type=>type==='e'?[]:Object.keys(skill),invisibleSkills:[],awakenedSkills:[], + getStorage:(key,fallback=[])=>me.storage[key]??fallback,isTempBanned:()=>false}); + Object.assign(game,{expandSkills:skills=>skills,addVideo(){},countChoose(){},check:()=>Check.prototype.confirm(status.event,'')}); + const plugin = skinModule[factory](lib,game,ui,get,{},status,app); + if (filename === 'xinsha') { + plugin.initCreateFunctions(); + plugin.initUpdateFunctions(); + } else { + plugin._extendUICreate(); + plugin._extendUI(); + } + plugin.updateSkillMarks=()=>{}; + createBaseLbtnPlugin(lib,game,ui,get,{},status,app).initConfirmRewrite(); + ui.confirm = null; + ui.create.confirm(''); + card.classList.remove('selected'); + card.updateTransform=()=>{}; + card.addEventListener('touchend',()=>{ + status.clicked=false; + Click.prototype.card.call(card); + }); + hud.refresh(); + const visiblePotionButtons = () => [...ui.skillControl.querySelectorAll('[data-id]')].filter(node=> + node.getClientRects().length && potions.potionSkillIds.includes(node.dataset.id)).map(node=>node.dataset.id); + window.discardSkillCheck = {frames:[],visiblePotionButtons,passive, + initialPotionButton:ui.skillControl.querySelector(`[data-id="${potions.potionSkillIds[0]}"]`)}; + const capture = event => { + if (event.target.closest('.card')!==card) return; + // Listen after the real card handler, before any scheduled HUD refresh. + discardSkillCheck.frames.push(visiblePotionButtons()); + requestAnimationFrame(()=>discardSkillCheck.frames.push(visiblePotionButtons())); + }; + window.addEventListener('touchend',capture,{once:true}); + },{prefix,decadePrefix,factory,filename}); + await page.locator('.handcards>.card').first().tap(); + const result = await page.evaluate(async () => { + await new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))); + const {frames,passive,initialPotionButton,visiblePotionButtons} = discardSkillCheck; + return {frames,visible:visiblePotionButtons(),rebuilt:initialPotionButton && !initialPotionButton.isConnected, + selected:ui.selected.cards.length,count:ui.dialog.textContent,passiveVisible:Boolean(ui.skillControl.querySelector(`[data-id="${passive}"]`)?.getClientRects().length)}; + }); + if (artifact) await page.screenshot({path:artifact}); + assert.equal(result.rebuilt,true,'ten-year UI rebuilt the skill row on tap'); + assert.ok(result.selected===1 && result.count.endsWith('1/2'),'the original touch selects one discard card and updates the count'); + assert.ok(result.passiveVisible,'normal skills remain visible'); + assert.equal(result.frames.length,2,'both touch and first animation frame were sampled'); + assert.deepEqual([...result.frames.flat(),...result.visible],[],'potion skill duplicates are hidden from the first frame'); +} + +async function checkMobileResponseLayout(page, skin, artifact) { + await page.evaluate(({skin,decadePrefix}) => { + const {arena,control} = ui; + const card = document.createElement('div'); + const scale = Math.min(arena.clientHeight * .18 / 156,1); + card.className = 'card thrown'; + card.style.cssText = `left:calc(50% - 56px);top:calc(50% - 78px);width:112px;height:156px;transform:scale(${scale});`; + card.style.background = `center/100% 100% url("${decadePrefix}/image/card-skins/decade/sha.png")`; + arena.appendChild(card); + ui.thrown = [card]; + const prompt = document.createElement('div'); + prompt.className = skin === 'native' ? 'dialog' : 'hand-tip'; + prompt.innerHTML = skin === 'native' + ? '
请使用一张闪响应杀
' + : '请使用一张闪响应杀'; + arena.appendChild(prompt); + ui.dialog = prompt; + const event = hudEventState.event; + event.name = 'chooseToUse'; + event.respondTo = [game.players[1],{name:'sha'}]; + event.dialog = prompt; + window.reviewResponses = []; + const confirm = control.firstElementChild; + confirm.classList.remove('stayleft'); + ui.confirm = confirm; + if (skin !== 'native') confirm.classList.add('combo-control','lbtn-confirm'); + const [ok,cancel] = confirm.children; + confirm.node = {ok,cancel}; + [ok,cancel].forEach((node,index) => { + node.dataset.response = index ? 'cancel' : 'ok'; + if (skin !== 'native') node.classList.add('control'); + if (skin === 'shousha') { + (node.firstElementChild || node).textContent = ''; + if (index) node.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(); + return ui.control.style.translate === '' && reviewResponse.card.style.translate === ''; + }); + assert.ok(restored,'response spacing is released when the original event ends'); +} const fixture = `
测试技能
结束出牌
`; +const importMap = reviewOnly ? fs.readFileSync(path.join(app,'index.html'),'utf8').match(/