53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
"""Local PC/Steam/Proton control backend (xdotool/scrot wrappers)."""
|
|
import subprocess
|
|
import time
|
|
|
|
import cv2
|
|
|
|
from ba_auto import config
|
|
|
|
PROBE_SHOT_PATH = "/tmp/ba_auto_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 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)
|