Files
bettergi-scripts-list/repo/js/AutoPlanDomain/utils/tool.js
yan 43137cd1c9 feat(AutoPlanDomain): 添加秘境配置按日期执行功能
- 新增 parseDay 辅助函数用于安全解析 day 字段
- 在配置加载过程中对 day 字段进行解析和验证
- 解析输入数据时新增 day 字段支持并调整索引位置
- 在秘境顺序对象中添加 day 执行日期字段
- 更新配置字符串格式说明文档
- 新增 getDayOfWeek 工具函数获取当前星期信息
- 添加星期几执行的逻辑判断功能
2026-02-08 22:46:40 +08:00

56 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 对指定区域进行OCR文字识别
* @param {number} x - 区域左上角x坐标默认为0
* @param {number} y - 区域左上角y坐标默认为0
* @param {number} w - 区域宽度默认为1920
* @param {number} h - 区域高度默认为1080
* @returns {Promise<string|null>} 返回识别到的文本内容如果识别失败则返回null
*/
async function ocrRegion(x = 0,
y = 0,
w = 1920,
h = 1080) {
// 创建OCR识别对象使用指定的坐标和尺寸
let recognitionObjectOcr = RecognitionObject.Ocr(x, y, w,h);
// 捕获游戏区域图像
let region3 = captureGameRegion()
try {
// 在捕获的区域中查找OCR识别对象
let res = region3.find(recognitionObjectOcr);
// 返回识别到的文本内容如果不存在则返回undefined
return res?.text
} catch (e) {
// 捕获并记录错误信息
log.error("识别异常:{1}", e.message)
return null
} finally {
// 确保释放区域资源
region3.Dispose()
}
}
/**
* 获取当前日期的星期信息
* @returns {Object} 返回包含星期数字和星期名称的对象
*/
async function getDayOfWeek() {
// 获取当前日期对象
const today = new Date();
// 获取当前日期是星期几0代表星期日1代表星期一以此类推
const day = today.getDay();
// 创建包含星期名称的数组
const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
let weekDay = `${weekDays[day]}`;
log.debug(`今天是[{day}]`, day)
log.debug(`今天是[{weekDays}]`, weekDay)
// 返回包含星期数字和对应星期名称的对象
return {
day: day,
dayOfWeek: weekDay
}
}
export {
ocrRegion,
getDayOfWeek
}