diff --git a/scripts/convert_modules.py b/scripts/convert_modules.py index 9ab43d1..763505c 100644 --- a/scripts/convert_modules.py +++ b/scripts/convert_modules.py @@ -410,12 +410,28 @@ def open_panel(tries=4): return panel_open(screen()) -def on_modules_tab(): - """兑换区显示体力条(x/126)说明停在 Modules 页签。 +# 免费合成页签独有的问句 —— 这句话在别的页签上不会出现 +MODULES_QUESTION = 'assemble Enkephalin Modules' - Use Lunacy 页签那边显示的是狂气, 文案与数字都不同。这里宁可判不出来不合成。 + +def on_modules_tab(): + """确认停在 Modules(免费合成)页签。 + + ⛔ 实测坑(2026-10-16 18:03): 原来只看"兑换区显示体力条 x/126", 但 OCR 会把相邻 + 几行合并成一个元素(那次 "Enkephalin Module Owned 31" 的框高 38、宽 351, 把下面 + 的 x/126 一起吞了), 于是判定失败 —— 整轮拒绝合成, 一个模块没换到。 + + 现在认面板自己的问句 "Would you like to assemble Enkephalin Modules?": + 它只在免费页签出现, 而且实测单独成行、不会被合并吃掉。 + 体力条那条留着当备用信号(两条任一成立即可)。 + + 判不出来时返回 False, 调用方拒绝合成 —— 宁可漏一轮, 也不在不知道哪个页签上点确认。 """ - for it in items(): + its = items() + flat = ' '.join(it.get('text', '') for it in its).replace(' ', '') + if MODULES_QUESTION.replace(' ', '') in flat: + return True + for it in its: if 470 < it.get('y', 0) < 560 and '/126' in it.get('text', '').replace(' ', ''): return True return False diff --git a/tests/test_convert_modules.py b/tests/test_convert_modules.py index 2f49209..44f65ac 100644 --- a/tests/test_convert_modules.py +++ b/tests/test_convert_modules.py @@ -584,6 +584,94 @@ class CliRoutingTest(QuietLogMixin, unittest.TestCase): self.assertEqual(code, 0) +class OnModulesTabTest(QuietLogMixin, unittest.TestCase): + """确认停在免费合成页签 —— 判错的代价是整轮拒绝合成。 + + ⛔ 2026-10-16 18:03 真出过事: 原来只看"兑换区显示体力条 x/126", 而 OCR 会把相邻 + 几行合并成一个元素(那次 "Enkephalin Module Owned 31" 的框高 38、宽 351, 把下面 + 的 x/126 一起吞了), 判定失败 -> 拒绝合成 -> 那轮一个模块没换到。 + + 下面的元素是那次面板上**真实的 OCR 输出**, 不是我编的。 + """ + + # 18:03 那轮真实 dump(体力条被合并吞掉, 但问句完整成行) + REAL_FAILED_DUMP = [ + {'text': 'Modules', 'x': 589, 'y': 269, 'w': 85, 'h': 27}, + {'text': 'Use Lunacy', 'x': 749, 'y': 269, 'w': 101, 'h': 25}, + {'text': 'Use Boxes', 'x': 921, 'y': 271, 'w': 100, 'h': 24}, + {'text': 'Enkephalin Module Owned 31', 'x': 681, 'y': 331, 'w': 351, 'h': 38}, + {'text': '1 Enkephalin recovered inD2:50', 'x': 658, 'y': 462, 'w': 278, 'h': 26}, + {'text': 'Would you like to assemble Enkephalin Modules?', + 'x': 564, 'y': 598, 'w': 472, 'h': 27}, + {'text': 'X Cancel', 'x': 593, 'y': 652, 'w': 118, 'h': 31}, + {'text': 'Confirm', 'x': 926, 'y': 653, 'w': 92, 'h': 30}, + ] + + def _items(self, items): + return mock.patch.object(cm, 'items', lambda: items) + + def test_recognises_the_frame_that_used_to_fail(self): + with self._items(self.REAL_FAILED_DUMP): + self.assertTrue(cm.on_modules_tab(), + '这批元素曾让判定失败, 现在必须认得出来') + + def test_question_phrase_alone_is_enough(self): + with self._items([{'text': 'Would you like to assemble Enkephalin Modules?', + 'x': 564, 'y': 598, 'w': 472, 'h': 27}]): + self.assertTrue(cm.on_modules_tab()) + + def test_question_phrase_survives_ocr_space_noise(self): + # OCR 常在词间丢空格/加空格 + with self._items([{'text': 'WouldyouliketoassembleEnkephalinModules?', + 'x': 564, 'y': 598, 'w': 472, 'h': 27}]): + self.assertTrue(cm.on_modules_tab()) + + def test_gauge_is_still_a_valid_fallback(self): + with self._items([{'text': '132/26112/126', 'x': 709, 'y': 508, + 'w': 200, 'h': 30}]): + self.assertTrue(cm.on_modules_tab()) + + def test_unknown_screen_is_refused(self): + """两条信号都没有时必须拒绝 —— 宁可漏一轮, 也不在不知道哪个页签上点确认。""" + with self._items([{'text': 'Window', 'x': 994, 'y': 809}, + {'text': 'Inventory', 'x': 759, 'y': 834}]): + self.assertFalse(cm.on_modules_tab()) + + def test_tab_labels_alone_are_not_enough(self): + """只有三个页签名(面板刚开、还没点页签)时不能算数。 + + 页签名一直显示, 分不出当前选中哪个, 所以不能当依据。 + """ + with self._items([{'text': 'Modules', 'x': 589, 'y': 269}, + {'text': 'Use Lunacy', 'x': 749, 'y': 269}, + {'text': 'Use Boxes', 'x': 921, 'y': 271}]): + self.assertFalse(cm.on_modules_tab()) + + def test_refusal_prevents_clicking_confirm(self): + """面板开着但认不出页签时, 绝不点确认。 + + 夹具要含面板标记(Charge Enkephalin), 否则走的是"打不开面板"那条更早的路径, + 测不到这里真正想守的东西。 + """ + clicked = [] + panel_but_no_tab_info = [ + {'text': 'Charge Enkephalin', 'x': 700, 'y': 180, 'w': 200, 'h': 30}, + {'text': 'Modules', 'x': 589, 'y': 269, 'w': 85, 'h': 27}, + {'text': 'Use Lunacy', 'x': 749, 'y': 269, 'w': 101, 'h': 25}, + {'text': 'Confirm', 'x': 926, 'y': 653, 'w': 92, 'h': 30}, + ] + with self._items(panel_but_no_tab_info), \ + mock.patch.object(cm, 'click', lambda *a: clicked.append(a)), \ + mock.patch.object(cm, 'read_owned', lambda: 31), \ + mock.patch.object(cm.time, 'sleep', lambda s: None): + ok, info, got = cm._convert_attempt() + self.assertFalse(ok) + self.assertEqual(got, 0) + self.assertIn('页签', info, '应该报"认不出页签", 实际: %s' % info) + self.assertFalse(any(cm.BTN_CONFIRM == tuple(a) for a in clicked), + '判不出页签还点了确认: %s' % clicked) + + class SafeClickTargetsTest(QuietLogMixin, unittest.TestCase): """脚本能点到的地方必须逐个安全 —— 用户的两条硬约束就靠这几个坐标。