style(utils): 格式化代码并添加测试功能

- 修复 tool.js 中的代码格式问题,包括括号位置和空格调整
- 将 main.js 中的日志级别从 info 调整为 debug 以减少冗余输出
- 在 main.js 中添加 test2 测试函数用于初始化和退出秘境界面测试
- 在 outDomainUI 函数中添加主界面状态检测逻辑
- 优化退出秘境流程的条件判断,增加 inMainUI 状态变量
- 修复代码中的语法格式问题,统一代码风格
This commit is contained in:
yan
2026-02-27 19:17:18 +08:00
parent fa2e36b1cc
commit c25df7abb1
2 changed files with 22 additions and 12 deletions

View File

@@ -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();
}

View File

@@ -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 目标文本(单个文本或文本列表,列表时需全部匹配)