- Changed references from './scratchpad' to '.scratchpad/' in graph.json and plan.md for consistency. - Expanded Phase 6 follow-up section in plan.md to clarify changes made to the pat detection logic: - Updated `find_cafe_sparkle()` to utilize multiple template scales for improved detection. - Modified `_pat_room` to allow polling for maximum clicks instead of breaking on the first miss. - Added mouse movement after each pat to prevent cursor occlusion of sparkles. - Verified that room entry and modal state checks function correctly, but end-to-end pat success remains untested due to lack of available interactions.
58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
"""Local PC/Steam/Proton control backend (xdotool/scrot wrappers)."""
|
|
import os
|
|
import subprocess
|
|
import time
|
|
|
|
import cv2
|
|
|
|
from ba_auto import config
|
|
|
|
PROBE_SHOT_PATH = os.path.join(config.SCRATCHPAD_DIR, "probe.png")
|
|
|
|
|
|
def run_command(args, **kwargs):
|
|
kwargs.setdefault("env", config.ENV)
|
|
kwargs.setdefault("check", True)
|
|
return subprocess.run(args, **kwargs)
|
|
|
|
|
|
def focus_game():
|
|
result = run_command(
|
|
["xdotool", "search", "--name", config.WINDOW_NAME],
|
|
check=False, capture_output=True, text=True,
|
|
)
|
|
window_ids = result.stdout.split()
|
|
if not window_ids:
|
|
raise RuntimeError("Blue Archive window not found. Is the game running?")
|
|
run_command(["xdotool", "windowactivate", window_ids[0]])
|
|
wait(0.5)
|
|
|
|
|
|
def click(x, y):
|
|
run_command(["xdotool", "mousemove", str(x), str(y), "click", "1"])
|
|
wait(0.5)
|
|
|
|
|
|
def move_mouse(x, y):
|
|
run_command(["xdotool", "mousemove", str(x), str(y)])
|
|
|
|
|
|
def keypress(key):
|
|
run_command(["xdotool", "key", key])
|
|
wait(0.5)
|
|
|
|
|
|
def screenshot(path):
|
|
run_command(["scrot", "-a", "0,0,1920,1200", "-o", path])
|
|
|
|
|
|
def color_at(x, y):
|
|
screenshot(PROBE_SHOT_PATH)
|
|
image = cv2.imread(PROBE_SHOT_PATH)
|
|
b, g, r = image[y, x]
|
|
return int(r), int(g), int(b)
|
|
|
|
|
|
def wait(seconds):
|
|
time.sleep(seconds)
|