From c25df7abb1196ce1af91b7feef0970d296256f46 Mon Sep 17 00:00:00 2001 From: yan Date: Fri, 27 Feb 2026 19:17:18 +0800 Subject: [PATCH] =?UTF-8?q?style(utils):=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=B9=B6=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 tool.js 中的代码格式问题,包括括号位置和空格调整 - 将 main.js 中的日志级别从 info 调整为 debug 以减少冗余输出 - 在 main.js 中添加 test2 测试函数用于初始化和退出秘境界面测试 - 在 outDomainUI 函数中添加主界面状态检测逻辑 - 优化退出秘境流程的条件判断,增加 inMainUI 状态变量 - 修复代码中的语法格式问题,统一代码风格 --- repo/js/AutoPlan/main.js | 5 +++++ repo/js/AutoPlan/utils/tool.js | 29 +++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/repo/js/AutoPlan/main.js b/repo/js/AutoPlan/main.js index 9c2ef124f..301234cfa 100644 --- a/repo/js/AutoPlan/main.js +++ b/repo/js/AutoPlan/main.js @@ -489,6 +489,7 @@ async function main() { (async function () { // await test() // await test1() + // await test2() await main() })() @@ -514,3 +515,7 @@ async function test1() { const list = await pullJsonConfig(config.user.uid, config.bgi_tools.api.httpPullJsonConfig) log.info("list:{1}", JSON.stringify(list)) } +async function test2() { + await init(); + await outDomainUI(); +} \ No newline at end of file diff --git a/repo/js/AutoPlan/utils/tool.js b/repo/js/AutoPlan/utils/tool.js index 01125a9a8..48aeb6bc8 100644 --- a/repo/js/AutoPlan/utils/tool.js +++ b/repo/js/AutoPlan/utils/tool.js @@ -37,7 +37,7 @@ async function ocrRegion(x = 0, async function getDayOfWeek(calibrationGameRefreshTime = true) { // 获取当前日期对象 let today = new Date();//4点刷新 所以要减去4小时 - if (calibrationGameRefreshTime){ + if (calibrationGameRefreshTime) { today.setHours(today.getHours() - 4); // 减去 4 小 } // 获取当前日期是星期几(0代表星期日,1代表星期一,以此类推) @@ -113,7 +113,7 @@ const isInMainUI = () => { try { let res = captureRegion.find(paimonMenuRo); return !res.isEmpty(); - }finally { + } finally { captureRegion.Dispose() } @@ -162,12 +162,13 @@ const isInOutDomainUI = async () => { h: 563 } const find = await findText(text, ocrRegion.x, ocrRegion.y, ocrRegion.w, ocrRegion.h) - log.info("识别结果:{1}", find) + log.debug("识别结果:{1}", find) return find && find.includes(text) }; async function outDomainUI() { - const ocrRegion={ + log.info(`{0}`,"退出秘境"); + const ocrRegion = { x: 509, y: 259, w: 901, @@ -175,7 +176,8 @@ async function outDomainUI() { } let ms = 300 let index = 1 - let tryMax=false + let tryMax = false + let inMainUI = false await sleep(ms); //点击确认按钮 await findTextAndClick('地脉异常') @@ -183,28 +185,30 @@ async function outDomainUI() { while (!await isInOutDomainUI()) { await sleep(ms); await keyPress("ESCAPE"); - await sleep(ms*2); - if (isInMainUI()){ - break + await sleep(ms * 2); + if (isInMainUI()) { + inMainUI = true + break } if (index > 3) { log.error(`多次尝试匹配退出秘境界面失败 假定已经退出处理`); - tryMax=true + tryMax = true break } index += 1 } - if ((!tryMax)&&await isInOutDomainUI()) { + if ((!tryMax) && (!inMainUI) && await isInOutDomainUI()) { try { //点击确认按钮 - await findTextAndClick('确认',ocrRegion.x, ocrRegion.y, ocrRegion.w, ocrRegion.h) - }catch (e) { + await findTextAndClick('确认', ocrRegion.x, ocrRegion.y, ocrRegion.w, ocrRegion.h) + } catch (e) { // log.error(`多次尝试点击确认失败 假定已经退出处理`); } } } + /** * 在指定区域内查找文本内容 * @param {string} text - 要查找的文本内容 @@ -254,6 +258,7 @@ async function findText( return ""; // 未找到匹配文本,返回空字符串 } + /** * 通用找文本并点击(OCR) * @param {string|string[]} text 目标文本(单个文本或文本列表,列表时需全部匹配)