"""Action: find — find a template and return its position (sets ctx['_last_pos']).""" import os class Action: name = "find" def run(self, ctx, params): template = params["template"] confidence = params.get("confidence", 0.8) region = params.get("region") 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) ctx["_last_pos"] = pos if pos is None: ctx["log"].info("find(%s) → not found", template) else: ctx["log"].info("find(%s) → %s", template, pos) return pos