JS: 食材加工添加回收 (#2287)

This commit is contained in:
起个名字好难的喵
2025-11-01 19:34:01 +08:00
committed by GitHub
parent 2dd36284e5
commit a96c4316d8
2 changed files with 10 additions and 2 deletions

View File

@@ -183,10 +183,14 @@ function recognizeImage(templatePath, xMin, yMin, width, height, timeout = 2000)
try {
let template = file.ReadImageMatSync(templatePath);
let recognitionObject = RecognitionObject.TemplateMatch(template, xMin, yMin, width, height);
let result = captureGameRegion().find(recognitionObject);
let ra = captureGameRegion();
let result = ra.find(recognitionObject);
template.dispose();
ra.dispose();
if (result.isExist()) {
return { success: true, x: result.x, y: result.y, width: result.width, height: result.height };
}
} catch (error) {
log.error(`识别图像时发生异常: ${error.message}`);
return null;
@@ -213,6 +217,7 @@ function performOcr(targetText, xRange, yRange, tolerance, timeout = 2000) {
adjustedXMin, adjustedYMin,
adjustedXMax - adjustedXMin, adjustedYMax - adjustedYMin
));
ra.dispose();
// 遍历识别结果,检查是否找到目标文本
for (let i = 0; i < resList.count; i++) {
@@ -326,6 +331,7 @@ async function clickSelectedIngredients(selectedIngredients, filePath, npcNames)
async function checkNpcAndFAlignment(npcName, fDialogueRo) {
let ra = captureGameRegion();
let fRes = ra.find(fDialogueRo);
ra.dispose();
if (!fRes.isExist()) {
let f_attempts = null; // 初始化尝试次数
while (f_attempts < 5) { // 最多尝试 4 次
@@ -352,6 +358,7 @@ async function checkNpcAndFAlignment(npcName, fDialogueRo) {
// 检查是否找到 F 图标
ra = captureGameRegion();
fRes = ra.find(fDialogueRo); // 重新查找 F 图标
ra.dispose();
if (fRes.isExist()) {
log.info("找到 F 图标");
break; // 找到后退出循环
@@ -410,6 +417,7 @@ async function checkNpcAndFAlignment(npcName, fDialogueRo) {
// 重新检查 F 图标和 NPC 名称是否对齐
let ra = captureGameRegion();
let fRes = ra.find(fDialogueRo);
ra.dispose();
if (!fRes.isExist()) {
log.warn("未找到 F 图标");
continue; // 如果未找到 F 图标,继续下一次循环

View File

@@ -1,7 +1,7 @@
{
"manifest_version": 1,
"name": "选择购买食材OCR",
"version": "1.30516",
"version": "1.4",
"description": "至少需要0.48版本bgi对NPC和材料进行文字、图像识别。\n一般食材杂货在蒙德、璃月、稻妻、枫丹杂货商购买。\n10鱼肉、10螃蟹在卯师傅、珀姆、布特罗斯、阿扎莱和志村勘兵卫购买。\n咖啡豆在须弥、枫丹咖啡馆购买。\n增加对话F图像识别增加个别字识别容错增加香辛料在阿扎莱处购买。\nv1.30513修复循环套叠优化F未识别后的尝试方案。",
"authors": [
{