Skip draft vision when Dota 2 is not the foreground window.
Prevents Alt-Tab desktop frames from advancing confirm streaks or burning strategy_tail polls. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+25
-4
@@ -30,7 +30,7 @@ from pathlib import Path
|
||||
|
||||
import mss
|
||||
|
||||
from capture import append_gsi_payload, grab_frame, raw_dir_for_match, save_frame
|
||||
from capture import append_gsi_payload, grab_frame, is_dota_foreground, raw_dir_for_match, save_frame
|
||||
from common import ROOT, load_config, load_template_library
|
||||
from draft_session import HERO_SELECTION, DraftSession, describe, gsi_slot, loc
|
||||
from recognize import recognize_image
|
||||
@@ -155,13 +155,32 @@ class Watcher:
|
||||
def _capture_only(self, match_id: str, state: str) -> None:
|
||||
"""No calibration yet: just bank a few frames to calibrate from later."""
|
||||
out = raw_dir_for_match(match_id)
|
||||
require_fg = bool(self.cfg.get("gsi", {}).get("require_foreground", True))
|
||||
print(f"[run] capture-only -> {out} (state={state})", flush=True)
|
||||
saved = 0
|
||||
skipped_fg = False
|
||||
with mss.MSS() as sct:
|
||||
for attempt in range(1, 4):
|
||||
# Retry until 3 usable frames or a short deadline so Alt-Tab does not
|
||||
# bank desktop screenshots for calibration.
|
||||
deadline = time.monotonic() + max(self.interval * 12, 15.0)
|
||||
while saved < 3 and time.monotonic() < deadline:
|
||||
if require_fg and not is_dota_foreground():
|
||||
if not skipped_fg:
|
||||
print("[run] Dota 2 not foreground - waiting to capture", flush=True)
|
||||
skipped_fg = True
|
||||
time.sleep(self.interval)
|
||||
continue
|
||||
if skipped_fg:
|
||||
print("[run] Dota 2 foreground again - capturing", flush=True)
|
||||
skipped_fg = False
|
||||
saved += 1
|
||||
path = save_frame(grab_frame(sct), out, prefix="draft")
|
||||
print(f"[run] capture-only {attempt}/3: {path}", flush=True)
|
||||
print(f"[run] capture-only {saved}/3: {path}", flush=True)
|
||||
time.sleep(self.interval)
|
||||
print("[run] no calibrated slots - run calibrate.py on one of these frames", flush=True)
|
||||
if saved == 0:
|
||||
print("[run] capture-only got no frames (Dota never foreground)", flush=True)
|
||||
else:
|
||||
print("[run] no calibrated slots - run calibrate.py on one of these frames", flush=True)
|
||||
return None
|
||||
|
||||
def report_session(self, summary: dict) -> None:
|
||||
@@ -175,6 +194,8 @@ class Watcher:
|
||||
|
||||
def run_once(self) -> dict | None:
|
||||
"""One snapshot of whatever is on screen right now, for manual checks."""
|
||||
if not is_dota_foreground():
|
||||
print("[run] warning: Dota 2 is not the foreground window", flush=True)
|
||||
frame = grab_frame()
|
||||
out = raw_dir_for_match(self.last_match_id)
|
||||
if not self.calibrated:
|
||||
|
||||
Reference in New Issue
Block a user