# -*- coding: utf-8 -*- """测试用引擎: 屏幕内容由测试脚本预设, 记录所有输入动作。""" from .engine import Engine class FakeEngine(Engine): def __init__(self, frames=None, images=None): # frames: 每次 ocr() 依次返回的 items 列表; 用完后停在最后一帧 self.frames = list(frames or [[]]) self.images = dict(images or {}) # name -> (x, y) self.actions = [] self.shots = 0 def screenshot(self): self.shots += 1 return {'path': 'fake/shot_%d.png' % self.shots, 'w': 1920, 'h': 1080} def show_game_background(self): self.actions.append(('show_game_background',)) return {'visible': True, 'foreground_changed': False} def ocr(self): shot = self.screenshot() items = self.frames.pop(0) if len(self.frames) > 1 else self.frames[0] return shot, [dict(it, score=it.get('score', 0.99)) for it in items] def find_image(self, name, threshold=0.8, model='normal'): return self.images.get(name) def list_images(self, prefix=''): return sorted(n for n in self.images if n.startswith(prefix)) def click(self, x, y, times=1): self.actions.append(('click', int(x), int(y), int(times))) def keypress(self, key): self.actions.append(('key', key)) def drag(self, from_x, from_y, to_x, to_y, duration=1.0): self.actions.append(('drag', from_x, from_y, to_x, to_y, duration)) def type_text(self, text): self.actions.append(('type', text))