复查修正: 饰品三选一被上游倒序、选队顶栏同名被覆盖
- 饰品(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:
@@ -146,12 +146,14 @@ class EventScreen:
|
||||
self.chosen = []
|
||||
self.model = None
|
||||
self.screenshot = object()
|
||||
self.ocr_runs = 0
|
||||
|
||||
@property
|
||||
def options(self):
|
||||
return self.screens[self.stage] if self.stage < len(self.screens) else None
|
||||
|
||||
def take_screenshot(self, *args, **kwargs):
|
||||
self.screenshot = object() # 每次截图都是新对象, 与 AALC 一致
|
||||
return self.screenshot
|
||||
|
||||
def mouse_to_blank(self, *args, **kwargs):
|
||||
@@ -194,6 +196,7 @@ class EventScreen:
|
||||
return False
|
||||
|
||||
def run(self, image):
|
||||
self.ocr_runs += 1
|
||||
lines = [('事件叙述文字', 200, 60)]
|
||||
for (x, y), text in zip(markers(len(self.options or ())), self.options or ()):
|
||||
lines.append((text, x + 200, y))
|
||||
@@ -243,6 +246,7 @@ class UpstreamEventHandlingTest(unittest.TestCase):
|
||||
self.assertEqual(mirror.event_times, 1)
|
||||
self.assertNotIn('find_element', vars(screen), 'find_element 必须还原')
|
||||
self.assertNotIn('mouse_click', vars(screen), 'mouse_click 必须还原')
|
||||
self.screen = screen
|
||||
return screen.chosen
|
||||
|
||||
@property
|
||||
@@ -276,6 +280,11 @@ class UpstreamEventHandlingTest(unittest.TestCase):
|
||||
self.assertEqual(self.play(options, **kwargs), self.play(options, patched=False, **kwargs))
|
||||
self.assertIn('事件选项: 1=战斗 | 2=离开; 表里没有这个事件, 交给 AALC', self.log)
|
||||
|
||||
def test_one_ocr_per_screenshot_in_solo_mode(self):
|
||||
# 单通模式下上游会再找一次 "???"; 同一张截图不再整屏 OCR 第二遍
|
||||
self.assertEqual(self.play([['战斗', '离开']], unknown=1, solo=True), [0])
|
||||
self.assertEqual(self.screen.ocr_runs, 1)
|
||||
|
||||
def test_misread_target_falls_back_to_upstream(self):
|
||||
options = [['鸡肉就是鸡', CHICKEN[1], CHICKEN[2]]]
|
||||
self.assertEqual(self.play(options), [0])
|
||||
|
||||
@@ -57,6 +57,12 @@ class GiftCardHitsTest(unittest.TestCase):
|
||||
lines = [('流血', 440, 300), ('流血', 500, 300)]
|
||||
self.assertEqual(ap.gift_card_hits(cards, lines, ('流血',), SCALE), [['流血'], ['流血']])
|
||||
|
||||
def test_upstream_order_undoes_the_icon_insertion(self):
|
||||
# 两张卡上游按给的顺序挑; 三张时命中的卡被上游逐张 insert(0), 所以倒着给、放在最后
|
||||
self.assertEqual(ap.gift_upstream_order([[], ['x']]), [1, 0])
|
||||
self.assertEqual(ap.gift_upstream_order([['x'], [], ['x', 'y']]), [1, 0, 2])
|
||||
self.assertEqual(ap.gift_upstream_order([[], [], []]), [0, 1, 2])
|
||||
|
||||
def test_rank_is_stable(self):
|
||||
cards = ['a', 'b', 'c']
|
||||
self.assertEqual(ap.rank_gift_cards(cards, [[], ['x'], []]), ['b', 'a', 'c'])
|
||||
@@ -96,7 +102,8 @@ class KeywordTableTest(unittest.TestCase):
|
||||
|
||||
|
||||
class GiftScreen:
|
||||
"""饰品选择界面: 每张卡 {'pos', 'lines'}; 系统图标模板永远匹配不上(本机现状)。"""
|
||||
"""饰品选择界面: 每张卡 {'pos', 'lines', 'icon'}; icon 为 True 的卡体系图标模板能匹配上
|
||||
(本机日志里没见它匹配上过, 默认 False)。"""
|
||||
|
||||
def __init__(self, cards, pick='0/1'):
|
||||
self.cards = cards
|
||||
@@ -122,6 +129,11 @@ class GiftScreen:
|
||||
def find_element(self, target, find_type='image', threshold=0.8, my_crop=None, **kwargs):
|
||||
if target == ap.GIFT_CARD and find_type == 'image_with_multiple_targets':
|
||||
return [card['pos'] for card in self.cards]
|
||||
if target.startswith('mirror/road_in_mir/acquire_ego_gift/') and my_crop:
|
||||
x1, y1, x2, y2 = my_crop
|
||||
for card in self.cards:
|
||||
if card.get('icon') and x1 <= card['pos'][0] <= x2 and y1 <= card['pos'][1] <= y2:
|
||||
return card['pos']
|
||||
return False
|
||||
|
||||
def find_language_text(self, zh_text, en_text, my_crop=None, **kwargs):
|
||||
@@ -146,8 +158,8 @@ class GiftScreen:
|
||||
for _, x, y in lines])
|
||||
|
||||
|
||||
def card(x, *lines):
|
||||
return {'pos': (x, 300), 'lines': list(lines)}
|
||||
def card(x, *lines, icon=False):
|
||||
return {'pos': (x, 300), 'lines': list(lines), 'icon': icon}
|
||||
|
||||
|
||||
@unittest.skipUnless(MIRROR.is_file(), 'vendor/aalc 子模块未检出')
|
||||
@@ -222,6 +234,25 @@ class UpstreamAcquireEgoGiftTest(unittest.TestCase):
|
||||
cards = [card(300, '烧伤'), card(600, '流血'), card(900, '流血', '施加流血')]
|
||||
self.assertEqual(self.choose(cards, pick='0/2')[0], [2, 1])
|
||||
|
||||
def test_icon_cards_keep_the_keyword_order(self):
|
||||
# 上游把认出体系图标的卡逐张 insert(0), 后认出的反而排前面; 补丁要抵消这一步
|
||||
cards = [card(300, '施加流血', icon=True), card(600, '流血', '施加流血', '流血层数', icon=True), card(900, '烧伤')]
|
||||
self.assertEqual(self.choose(cards)[0], [1])
|
||||
self.assertEqual(self.choose(cards, pick='0/2')[0], [1, 0])
|
||||
|
||||
def test_keyword_card_without_icon_still_beats_an_icon_card(self):
|
||||
cards = [card(300, '流血', '施加流血', '流血层数'), card(600, '施加流血', icon=True), card(900, '烧伤')]
|
||||
self.assertEqual(self.choose(cards)[0], [0])
|
||||
|
||||
def test_icon_only_card_comes_after_keyword_cards_but_before_the_rest(self):
|
||||
cards = [card(300, '烧伤'), card(600, '没读出关键词', icon=True), card(900, '施加流血')]
|
||||
self.assertEqual(self.choose(cards, patched=False)[0], [1])
|
||||
self.assertEqual(self.choose(cards, pick='0/2')[0], [2, 1])
|
||||
|
||||
def test_without_keywords_icons_behave_like_upstream(self):
|
||||
cards = [card(300, '烧伤', icon=True), card(600, '震颤', icon=True), card(900, '充能')]
|
||||
self.assertEqual(self.choose(cards, pick='0/2')[0], self.choose(cards, pick='0/2', patched=False)[0])
|
||||
|
||||
def test_misread_keyword_for_tremor(self):
|
||||
cards = [card(300, '流血'), card(600, '施加震颐')]
|
||||
self.assertEqual(self.choose(cards, system='tremor')[0], [1])
|
||||
|
||||
@@ -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