"""Action: find_and_click — locate a template image and tap it.""" import os class Action: name = "find_and_click" def run(self, ctx, params): template = params["template"] confidence = params.get("confidence", 0.8) region = params.get("region") offset_x = params.get("offset_x", 0) offset_y = params.get("offset_y", 0) tmpl_dir = ctx.get("_templates_dir", os.path.join(os.path.dirname(__file__), "..", "templates")) tpl_path = os.path.join(tmpl_dir, template) pos = ctx["vision"].find_template(tpl_path, confidence, region) if pos is None: ctx["log"].info("find_and_click(%s) → not found, skipping", template) return None cx, cy = pos[0] + offset_x, pos[1] + offset_y ctx["adb"].tap(cx, cy) ctx["log"].info("find_and_click(%s) → tap(%d, %d)", template, cx, cy) return (cx, cy)