finished up grid detection.

This commit is contained in:
Boki 2026-02-10 17:29:37 -05:00
parent 41d174195e
commit 1246884be9
11 changed files with 1037 additions and 19 deletions

View file

@ -274,10 +274,48 @@
font-size: 12px;
color: #8b949e;
white-space: pre-wrap;
max-height: 200px;
overflow-y: auto;
}
.debug-result:empty { display: none; }
.grid-debug {
display: flex;
gap: 8px;
margin-top: 8px;
align-items: flex-start;
}
.grid-debug img {
border: 1px solid #30363d;
border-radius: 4px;
max-width: 280px;
max-height: 280px;
object-fit: contain;
}
.grid-view {
display: inline-grid;
gap: 1px;
background: #30363d;
border: 1px solid #30363d;
border-radius: 4px;
overflow: hidden;
flex-shrink: 0;
}
.grid-cell {
width: 12px; height: 12px;
background: #0d1117;
}
.grid-cell.occupied {
background: #238636;
}
.detect-badge {
display: inline-block;
font-size: 10px;
padding: 1px 6px;
border-radius: 4px;
margin-left: 6px;
font-weight: 600;
}
.detect-badge.ok { background: #238636; color: #fff; }
.detect-badge.fallback { background: #9e6a03; color: #fff; }
</style>
</head>
<body>
@ -339,6 +377,25 @@
<div class="debug-row">
<button onclick="debugScreenshot()">Screenshot</button>
<button onclick="debugOcr()">OCR Screen</button>
<button onclick="debugHideout()">Go Hideout</button>
</div>
<div class="debug-row">
<button onclick="debugFindAndClick('ANGE')">ANGE</button>
<button onclick="debugFindAndClick('STASH')">STASH</button>
</div>
<div class="debug-row">
<button onclick="debugAngeOption('Currency')">Currency Exchange</button>
<button onclick="debugAngeOption('Manage')">Manage Shop</button>
<button onclick="debugAngeOption('Buy')">Buy or Sell</button>
<button onclick="debugAngeOption('Purchase')">Purchase Items</button>
</div>
<div class="debug-row">
<button onclick="debugGridScan('inventory')">Scan Inventory</button>
<button onclick="debugGridScan('stash12')">Scan Stash 12×12</button>
<button onclick="debugGridScan('stash24')">Scan Stash 24×24</button>
<button onclick="debugGridScan('seller')">Scan Seller</button>
<button onclick="debugGridScan('shop')">Scan Shop</button>
<button onclick="debugGridScan('vendor')">Scan Vendor</button>
</div>
<div class="debug-row">
<input type="text" id="debugTextInput" placeholder="Text to find (e.g. Stash, Ange)" />
@ -588,6 +645,63 @@
}
// Debug functions
async function debugGridScan(layout) {
showDebugResult(`Scanning ${layout}...`);
const res = await fetch('/api/debug/grid-scan', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ layout }),
});
const data = await res.json();
if (!data.ok) { showDebugResult(`Error: ${data.error}`); return; }
const el = document.getElementById('debugResult');
const count = data.occupied.length;
const r = data.region;
let html = `<b>${layout}</b> ${data.cols}x${data.rows}`;
html += ` — ${count} occupied cell(s)`;
if (r) html += `<br><span style="color:#484f58">Region: (${r.x}, ${r.y}) ${r.width}x${r.height}</span>`;
if (count > 0) {
html += `<br>` + data.occupied.map(c => `(${c.row},${c.col})`).join(' ');
}
html += '<div class="grid-debug">';
if (data.image) {
html += `<img src="data:image/png;base64,${data.image}" alt="Grid capture" />`;
}
html += `<div class="grid-view" style="grid-template-columns:repeat(${data.cols},12px)">`;
const set = new Set(data.occupied.map(c => c.row + ',' + c.col));
for (let r = 0; r < data.rows; r++) {
for (let c = 0; c < data.cols; c++) {
html += `<div class="grid-cell${set.has(r+','+c) ? ' occupied' : ''}" title="(${r},${c})"></div>`;
}
}
html += '</div></div>';
el.innerHTML = html;
}
async function debugAngeOption(option) {
showDebugResult(`Clicking ANGE → ${option}...`);
const res = await fetch('/api/debug/click-then-click', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ first: 'ANGE', second: option }),
});
const data = await res.json();
if (!data.found && data.step === 'first') {
showDebugResult('ANGE not found on screen');
} else if (!data.found) {
showDebugResult(`"${option}" not found in ANGE menu (timed out)`);
} else {
showDebugResult(`Clicked "${option}" at (${data.position.x}, ${data.position.y})`);
}
}
async function debugHideout() {
showDebugResult('Sending /hideout...');
const res = await fetch('/api/debug/hideout', { method: 'POST' });
const data = await res.json();
showDebugResult(data.ok ? 'Sent /hideout command' : `Error: ${data.error}`);
}
async function debugScreenshot() {
const res = await fetch('/api/debug/screenshot', { method: 'POST' });
const data = await res.json();
@ -620,8 +734,8 @@
}
}
async function debugFindAndClick() {
const text = document.getElementById('debugTextInput').value.trim();
async function debugFindAndClick(directText) {
const text = directText || document.getElementById('debugTextInput').value.trim();
if (!text) return;
showDebugResult(`Finding and clicking "${text}"...`);
const res = await fetch('/api/debug/find-and-click', {