finished item finder
This commit is contained in:
parent
1246884be9
commit
930e00c9cc
7 changed files with 450 additions and 37 deletions
|
|
@ -397,6 +397,19 @@
|
|||
<button onclick="debugGridScan('shop')">Scan Shop</button>
|
||||
<button onclick="debugGridScan('vendor')">Scan Vendor</button>
|
||||
</div>
|
||||
<div class="debug-row">
|
||||
<select id="matchLayout" style="padding:6px 10px;background:#0d1117;border:1px solid #30363d;border-radius:6px;color:#e6edf3;font-size:13px">
|
||||
<option value="shop">Shop</option>
|
||||
<option value="seller">Seller</option>
|
||||
<option value="stash12">Stash 12×12</option>
|
||||
<option value="stash12_folder">Stash 12×12 (folder)</option>
|
||||
<option value="inventory">Inventory</option>
|
||||
<option value="vendor">Vendor</option>
|
||||
</select>
|
||||
<input type="number" id="matchRow" placeholder="Row" value="8" style="width:60px" />
|
||||
<input type="number" id="matchCol" placeholder="Col" value="0" style="width:60px" />
|
||||
<button class="primary" onclick="debugTestMatchHover()">Match & Hover</button>
|
||||
</div>
|
||||
<div class="debug-row">
|
||||
<input type="text" id="debugTextInput" placeholder="Text to find (e.g. Stash, Ange)" />
|
||||
<button onclick="debugFindText()">Find</button>
|
||||
|
|
@ -645,33 +658,81 @@
|
|||
}
|
||||
|
||||
// Debug functions
|
||||
async function debugGridScan(layout) {
|
||||
showDebugResult(`Scanning ${layout}...`);
|
||||
let lastGridLayout = null;
|
||||
|
||||
async function debugGridScan(layout, targetRow, targetCol) {
|
||||
lastGridLayout = layout;
|
||||
const hasTarget = targetRow != null && targetCol != null;
|
||||
showDebugResult(hasTarget ? `Matching (${targetRow},${targetCol}) in ${layout}...` : `Scanning ${layout}...`);
|
||||
const body = { layout };
|
||||
if (hasTarget) { body.targetRow = targetRow; body.targetCol = targetCol; }
|
||||
const res = await fetch('/api/debug/grid-scan', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ layout }),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!data.ok) { showDebugResult(`Error: ${data.error}`); return; }
|
||||
const el = document.getElementById('debugResult');
|
||||
const count = data.occupied.length;
|
||||
const items = data.items || [];
|
||||
const matches = data.matches || [];
|
||||
const r = data.region;
|
||||
let html = `<b>${layout}</b> ${data.cols}x${data.rows}`;
|
||||
html += ` — ${count} occupied cell(s)`;
|
||||
html += ` — ${count} occupied, ${items.length} items`;
|
||||
if (matches.length > 0) html += `, <span style="color:#f0883e;font-weight:bold">${matches.length} matches</span>`;
|
||||
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(' ');
|
||||
if (items.length > 0) {
|
||||
const sizes = {};
|
||||
items.forEach(i => { const k = i.w + 'x' + i.h; sizes[k] = (sizes[k]||0) + 1; });
|
||||
html += `<br><span style="color:#58a6ff">` + Object.entries(sizes).map(([k,v]) => `${v}x ${k}`).join(', ') + `</span>`;
|
||||
}
|
||||
if (hasTarget) {
|
||||
html += `<br><span style="color:#f0883e">Target: (${targetRow},${targetCol})`;
|
||||
if (matches.length > 0) html += ` → ${matches.map(m => `(${m.row},${m.col}) ${(m.similarity*100).toFixed(0)}%`).join(', ')}`;
|
||||
html += `</span>`;
|
||||
} else {
|
||||
html += `<br><span style="color:#484f58">Click a cell to find matching items</span>`;
|
||||
}
|
||||
html += '<div class="grid-debug">';
|
||||
if (data.image) {
|
||||
html += `<img src="data:image/png;base64,${data.image}" alt="Grid capture" />`;
|
||||
}
|
||||
// Build match set for highlighting
|
||||
const matchSet = new Set(matches.map(m => m.row + ',' + m.col));
|
||||
const targetKey = hasTarget ? targetRow + ',' + targetCol : null;
|
||||
// Build item map: cell → item info
|
||||
const itemMap = {};
|
||||
const colors = ['#238636','#1f6feb','#8957e5','#da3633','#d29922','#3fb950','#388bfd','#a371f7','#f85149','#e3b341'];
|
||||
items.forEach((item, idx) => {
|
||||
const color = colors[idx % colors.length];
|
||||
for (let dr = 0; dr < item.h; dr++)
|
||||
for (let dc = 0; dc < item.w; dc++)
|
||||
itemMap[(item.row+dr)+','+(item.col+dc)] = { item, color, isOrigin: dr===0 && dc===0 };
|
||||
});
|
||||
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>`;
|
||||
const key = r+','+c;
|
||||
const isTarget = key === targetKey;
|
||||
const isMatch = matchSet.has(key);
|
||||
const info = itemMap[key];
|
||||
let bg;
|
||||
if (isTarget) bg = '#f0883e';
|
||||
else if (isMatch) bg = '#d29922';
|
||||
else if (info) bg = info.color;
|
||||
else if (set.has(key)) bg = '#238636';
|
||||
else bg = '';
|
||||
const outline = (isTarget || isMatch) ? 'outline:2px solid #f0883e;z-index:1;' : '';
|
||||
const cursor = set.has(key) ? 'cursor:pointer;' : '';
|
||||
const bgStyle = bg ? `background:${bg};` : '';
|
||||
const style = (bgStyle || outline || cursor) ? ` style="${bgStyle}${outline}${cursor}"` : '';
|
||||
let title = info ? `(${r},${c}) ${info.item.w}x${info.item.h}` : `(${r},${c})`;
|
||||
if (isTarget) title += ' [TARGET]';
|
||||
if (isMatch) { const m = matches.find(m => m.row===r && m.col===c); title += ` [MATCH ${(m.similarity*100).toFixed(0)}%]`; }
|
||||
const onclick = set.has(key) ? ` onclick="debugGridScan('${layout}',${r},${c})"` : '';
|
||||
html += `<div class="grid-cell${set.has(key) ? ' occupied' : ''}"${style}${onclick} title="${title}"></div>`;
|
||||
}
|
||||
}
|
||||
html += '</div></div>';
|
||||
|
|
@ -764,6 +825,22 @@
|
|||
showDebugResult(data.ok ? `Clicked at (${x}, ${y})` : `Error: ${data.error}`);
|
||||
}
|
||||
|
||||
async function debugTestMatchHover() {
|
||||
const layout = document.getElementById('matchLayout').value;
|
||||
const targetRow = parseInt(document.getElementById('matchRow').value);
|
||||
const targetCol = parseInt(document.getElementById('matchCol').value);
|
||||
if (isNaN(targetRow) || isNaN(targetCol)) { showDebugResult('Invalid row/col'); return; }
|
||||
showDebugResult(`Scanning ${layout} and matching (${targetRow},${targetCol})...`);
|
||||
const res = await fetch('/api/debug/test-match-hover', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ layout, targetRow, targetCol }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!data.ok) { showDebugResult(`Error: ${data.error}`); return; }
|
||||
showDebugResult(`Done: ${data.itemSize} item, ${data.matchCount} matches, hovered ${data.hoveredCount} cells`);
|
||||
}
|
||||
|
||||
function showDebugResult(text) {
|
||||
document.getElementById('debugResult').textContent = text;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue