Files
bettergi-scripts-list/repo/js/HolyRelicsUp/utils/holyRelicsUpUtils.js
云端客 5fd58b7be5 [圣遗物批量强化] 添加语言刷新设置功能 并优化命中属性 (#1966)
* feat: 添加语言刷新设置功能

* feat: 添加语言刷新设置功能

* fix: 修复多语言标签格式和调试日志输出

* refactor: 替换硬编码的降序文本为国际化方法调用

* refactor: 移除ocrTestHolyRelic函数,优化属性百分比处理

* fix(HolyRelicsUp): 修复设置更新时的JSON解析问题

* fix: 修复圣遗物强化命中功能的验证逻辑和错误处理

* feat: 添加多语言支持和相关配置项

* feat(HolyRelicsUp): 添加验证开始提示信息
2025-09-21 19:38:06 +08:00

138 lines
3.1 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.
function info(msg, must = false, log_off = false) {
if (log_off || must) {
log.info(msg)
}
}
function warn(msg, must = false, log_off = false) {
if (log_off || must) {
log.warn(msg)
}
}
function debug(msg, must = false, log_off = false) {
if (log_off || must) {
log.debug(msg)
}
}
function error(msg, must = false, log_off = false) {
if (log_off || must) {
log.error(msg)
}
}
function throwError(msg) {
notification.error(`${msg}`);
throw new Error(msg);
}
function openCaptureGameRegion() {
return captureGameRegion()
}
function closeCaptureGameRegion(region) {
region.Dispose()
}
function findByCaptureGameRegion(region, templateMatchObject) {
return region.find(templateMatchObject)
}
function findMultiByCaptureGameRegion(region, templateMatchObject) {
return region.findMulti(templateMatchObject)
}
function mTo(x, y) {
moveMouseTo(x, y);
}
function recognitionObjectOcr(x, y, width, height) {
return RecognitionObject.Ocr(x, y, width, height)
}
function downLeftButton() {
leftButtonDown();
}
function upLeftButton() {
leftButtonUp();
}
function moveByMouse(x, y) {
moveMouseBy(x, y);
}
async function wait(ms = 1000) {
// 等待300毫秒确保按下操作生效
await sleep(ms);
}
function downClick(x, y) {
click(x, y);
}
/**
* 检查资源是否存在
* @param {Object} res - 需要检查的资源对象
* @returns {Boolean} 返回资源是否存在的结果
* true表示资源存在false表示资源不存在
*/
function isExist(res) {
return res.isExist() // 调用资源对象的isExist方法获取存在状态
}
function sendMessage(msg) {
notification.Send(msg);
}
// 更新settings.json文件
async function updateSettingsFile(settingsArray) {
const settingsPath = "./settings.json";
// let settingsArray = JSON.parse(await file.readText(settingsPath));
if (!(settingsArray.length >= 2)) {
try {
// 读取现有设置
const content = file.readTextSync(settingsPath);
settingsArray = JSON.parse(content);
} catch (e) {
// 文件不存在或解析失败时创建默认设置
throw new Error("设置文件不存在");
}
warn("设置文件格式不正确请检查settings.json文件", true)
}
let json = JSON.stringify(settingsArray, null, 2)
.replaceAll(']"', ']')
.replaceAll('"[','[')
.replaceAll('\\"', '"')
.replaceAll('\\\\n', '\\n')
// warn("settings==>"+json, true)
// 写入更新后的设置
const success = file.writeTextSync(settingsPath, json);
if (!success) {
throwError("写入设置文件失败");
}
}
this.holyRelicsUpUtils = {
isExist,
info,
warn,
debug,
error,
throwError,
openCaptureGameRegion,
closeCaptureGameRegion,
findByCaptureGameRegion,
findMultiByCaptureGameRegion,
mTo,
recognitionObjectOcr,
downLeftButton,
upLeftButton,
moveByMouse,
wait,
downClick,
updateSettingsFile,
sendMessage,
};