复查修正: 饰品三选一被上游倒序、选队顶栏同名被覆盖
- 饰品(P1-3): 三张及以上时上游把认出体系图标的卡逐张 insert(0), 后看的排到最前,
两张命中关键词的卡都带图标时补丁的顺序会被倒过来, 先拿命中少的。现在交给上游
"没命中的(原顺序) + 命中的(倒着)", 上游查体系图标时对命中的卡答"有", 拼出来是
命中多 -> 命中少 -> 只认出图标 -> 其余。测试的假界面加上体系图标, 先复现再修。
- 选队(P1-5): _team_ocr 经 _run_ocr_for_text 的 {文本: 坐标} 取结果, 选中某队后
顶栏和列表同名, 顶栏那条会被覆盖; 旧测试用成对结果模拟重复, 真实 dict 做不到。
改读 OCR 引擎逐行结果(同一引擎、同一截图), 引擎导入不了才退回 dict。
- 事件(P1-4): 同一张截图只判断一次, 单通模式再找 "???" 时不再整屏 OCR 第二遍。
- 文档: 修正 BACKLOG/README/交接文档对应描述, 去掉两处没核实的推断。
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest import mock
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
@@ -51,8 +52,33 @@ class RegionTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
def ocr_engine(lines):
|
||||
"""假的 module.ocr: 引擎按 [(文本, x, y)] 逐行返回, 同名文本可以出现多次(真实引擎就是这样)。"""
|
||||
result = SimpleNamespace(txts=tuple(t for t, _, _ in lines),
|
||||
boxes=[[[x - 10, y - 5], [x + 10, y - 5], [x + 10, y + 5], [x - 10, y + 5]]
|
||||
for _, x, y in lines])
|
||||
return SimpleNamespace(ocr=SimpleNamespace(run=lambda image: result))
|
||||
|
||||
|
||||
class TeamOcrTest(unittest.TestCase):
|
||||
|
||||
def test_engine_lines_keep_duplicate_names(self):
|
||||
# 选中「流血」后顶栏和列表都是「流血」; 经 {文本: 坐标} 只会剩一条
|
||||
engine = ocr_engine([('流血', 242.0, 125.0), (' 流血 ', 130.0, 493.0), ('', 1.0, 1.0)])
|
||||
auto = mock.Mock()
|
||||
with mock.patch.dict(sys.modules, {'module': types.ModuleType('module'), 'module.ocr': engine}):
|
||||
self.assertEqual(aalc_patches._team_ocr(auto), [('流血', 242.0, 125.0), ('流血', 130.0, 493.0)])
|
||||
auto._run_ocr_for_text.assert_not_called()
|
||||
|
||||
|
||||
class TeamOcrFallbackTest(unittest.TestCase):
|
||||
"""OCR 引擎导入不了时退回 AALC 的 _run_ocr_for_text。"""
|
||||
|
||||
def setUp(self):
|
||||
patcher = mock.patch.dict(sys.modules, {'module.ocr': None})
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def test_returns_list_and_strips_spaces(self):
|
||||
auto = mock.Mock()
|
||||
auto._run_ocr_for_text.return_value = {
|
||||
@@ -140,16 +166,6 @@ class PickTeamItemTest(unittest.TestCase):
|
||||
self.assertEqual(aalc_patches.pick_team_item([('斩击', 130, 330)], ('流血',)), (None, ''))
|
||||
|
||||
|
||||
class _OcrPairs:
|
||||
"""OCR 结果里同名文本可以出现两次(列表和顶栏), 用 items() 返回成对列表来模拟。"""
|
||||
|
||||
def __init__(self, pairs):
|
||||
self.pairs = pairs
|
||||
|
||||
def items(self):
|
||||
return list(self.pairs)
|
||||
|
||||
|
||||
class _FakeTeamScreen:
|
||||
"""编队界面: 列表按 3 次下拖翻一屏, 点哪条顶栏就变成哪条。"""
|
||||
|
||||
@@ -167,6 +183,10 @@ class _FakeTeamScreen:
|
||||
def take_screenshot(self):
|
||||
return object()
|
||||
|
||||
@property
|
||||
def screenshot(self):
|
||||
return self # 交给假 OCR 引擎的"截图"就是这块界面
|
||||
|
||||
def find_element(self, *args, **kwargs):
|
||||
return True
|
||||
|
||||
@@ -176,11 +196,13 @@ class _FakeTeamScreen:
|
||||
def mouse_swipe_for_team_scroll(self, x, y, dy, duration):
|
||||
self.swipes_down = 0 if dy > 0 else self.swipes_down + 1
|
||||
|
||||
def _run_ocr_for_text(self, my_crop=None):
|
||||
pairs = [(text, [130.0, 320.0 + 50 * row]) for row, text in enumerate(self.screens[self.page])]
|
||||
if self.header:
|
||||
pairs.append((self.header, [242.0, 125.0]))
|
||||
return _OcrPairs(pairs)
|
||||
def read(self):
|
||||
"""OCR 引擎逐行结果: 顶栏在上、列表在下; 同名条目各出现一次。"""
|
||||
lines = [(self.header, 242.0, 125.0)] if self.header else []
|
||||
lines += [(text, 130.0, 320.0 + 50 * row) for row, text in enumerate(self.screens[self.page])]
|
||||
return SimpleNamespace(txts=tuple(t for t, _, _ in lines),
|
||||
boxes=[[[x - 10, y - 5], [x + 10, y - 5], [x + 10, y + 5], [x - 10, y + 5]]
|
||||
for _, x, y in lines])
|
||||
|
||||
def mouse_action_with_pos(self, pos, offset=False):
|
||||
self.clicks.append(tuple(pos))
|
||||
@@ -197,6 +219,10 @@ class SelectTeamByNameTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.lines = []
|
||||
engine = SimpleNamespace(ocr=SimpleNamespace(run=lambda screen: screen.read()))
|
||||
modules = mock.patch.dict(sys.modules, {'module': types.ModuleType('module'), 'module.ocr': engine})
|
||||
modules.start()
|
||||
self.addCleanup(modules.stop)
|
||||
for patcher in (mock.patch.object(aalc_patches.time, 'sleep'),
|
||||
mock.patch.object(aalc_patches.decisions, 'record')):
|
||||
self.records = patcher.start()
|
||||
@@ -228,6 +254,13 @@ class SelectTeamByNameTest(unittest.TestCase):
|
||||
self.assertEqual(auto.clicks, [])
|
||||
self.assertIn('当前已经是编队 沉沦', self.log)
|
||||
|
||||
def test_current_team_that_is_also_in_the_list(self):
|
||||
# 列表这一屏里也有「流血」: 顶栏那条不能被列表那条盖掉
|
||||
auto = _FakeTeamScreen([self.MIDDLE], header='流血')
|
||||
self.assertTrue(self.select(auto, ('流血',)))
|
||||
self.assertEqual(auto.clicks, [])
|
||||
self.assertIn('当前已经是编队 流血', self.log)
|
||||
|
||||
def test_current_team_with_suffix_is_confirmed_in_the_list(self):
|
||||
# 顶栏 "流血队" 只是前缀命中, 不能直接当成目标; 列表里唯一后再点一次
|
||||
auto = _FakeTeamScreen([self.TOP, ['流血队', '震颤']], header='流血队')
|
||||
|
||||
Reference in New Issue
Block a user