js:锄地一条龙1.4.0 (#1568)
* js:锄地一条龙1.4.0 ### 1.4.0(2025.08.12) 1.增加拾取模式,模板匹配拾取并设为默认项,之前的拾取模式改名为ocr拾取 * js:性能测试 增加自定义配置选择测试项目和识图区域大小 * js:锄地一条龙 适当增加拾取后延时
This commit is contained in:
@@ -1,29 +1,79 @@
|
||||
// 主函数
|
||||
(async function () {
|
||||
operationMode = settings.operationMode || "截图";
|
||||
const xRange = parseInt(+settings.xRange || 1920, 10);
|
||||
const yRange = parseInt(+settings.yRange || 1920, 10);
|
||||
let startTime = Date.now();
|
||||
const interval = +settings.interval || 1000;
|
||||
const timeout = +settings.timeout || 60;
|
||||
let lastCheck = startTime;
|
||||
let ocrcount = 0;
|
||||
let loopCount = 0;
|
||||
let logCount = 0;
|
||||
//let store = [];
|
||||
while (Date.now() - startTime < timeout * 1000) {
|
||||
loopCount++;
|
||||
try {
|
||||
let GameRegion = captureGameRegion();
|
||||
// store[loopCount] = GameRegion;
|
||||
if (settings.dispose) GameRegion.dispose();
|
||||
ocrcount++;
|
||||
} catch (error) {
|
||||
log.error(`运行时发生异常: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
if (Date.now() - lastCheck >= interval) {
|
||||
logCount++;
|
||||
lastCheck = Date.now();
|
||||
log.info(`在第${logCount}个${interval}毫秒内执行了${ocrcount}次截图`);
|
||||
ocrcount = 0;
|
||||
const imagePath = "assets/流放.png";
|
||||
let template = file.ReadImageMatSync(imagePath);
|
||||
if (operationMode === "截图") {
|
||||
while (Date.now() - startTime < timeout * 1000) {
|
||||
try {
|
||||
let GameRegion = captureGameRegion();
|
||||
if (settings.dispose) GameRegion.dispose();
|
||||
ocrcount++;
|
||||
if (Date.now() - lastCheck >= interval) {
|
||||
loopCount++;
|
||||
await sleep(1);
|
||||
lastCheck = Date.now();
|
||||
log.info(`在第${loopCount}个${interval}毫秒内执行了${ocrcount}次截图`);
|
||||
ocrcount = 0;
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(`运行时发生异常: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (operationMode === "模板匹配") {
|
||||
let GameRegion = captureGameRegion();
|
||||
while (Date.now() - startTime < timeout * 1000) {
|
||||
try {
|
||||
|
||||
let recognitionObject = RecognitionObject.TemplateMatch(template, 0, 0, xRange, yRange);
|
||||
let result = GameRegion.find(recognitionObject);
|
||||
ocrcount++;
|
||||
if (Date.now() - lastCheck >= interval) {
|
||||
loopCount++;
|
||||
await sleep(1);
|
||||
lastCheck = Date.now();
|
||||
log.info(`在第${loopCount}个${interval}毫秒内执行了${ocrcount}次模板匹配`);
|
||||
ocrcount = 0;
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(`运行时发生异常: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (settings.dispose) GameRegion.dispose();
|
||||
}
|
||||
if (operationMode === "ocr") {
|
||||
let GameRegion = captureGameRegion();
|
||||
while (Date.now() - startTime < timeout * 1000) {
|
||||
try {
|
||||
let result = GameRegion.findMulti(RecognitionObject.ocr(
|
||||
0, 0,
|
||||
xRange, yRange
|
||||
));
|
||||
ocrcount++;
|
||||
} catch (error) {
|
||||
log.error(`运行时发生异常: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
if (Date.now() - lastCheck >= interval) {
|
||||
loopCount++;
|
||||
lastCheck = Date.now();
|
||||
await sleep(1);
|
||||
log.info(`在第${loopCount}个${interval}毫秒内执行了${ocrcount}次OCR`);
|
||||
ocrcount = 0;
|
||||
}
|
||||
}
|
||||
if (settings.dispose) GameRegion.dispose();
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user