finished item finder
This commit is contained in:
parent
1246884be9
commit
930e00c9cc
7 changed files with 450 additions and 37 deletions
|
|
@ -4,6 +4,7 @@ import { WebSocketServer, WebSocket } from 'ws';
|
|||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { logger } from '../util/logger.js';
|
||||
import { sleep } from '../util/sleep.js';
|
||||
import type { BotController } from './BotController.js';
|
||||
import type { ScreenReader } from '../game/ScreenReader.js';
|
||||
import { GRID_LAYOUTS } from '../game/GridReader.js';
|
||||
|
|
@ -203,18 +204,21 @@ export class DashboardServer {
|
|||
// Grid scan with calibrated positions
|
||||
this.app.post('/api/debug/grid-scan', async (req, res) => {
|
||||
if (!this.debug) { res.status(503).json({ error: 'Debug not available' }); return; }
|
||||
const { layout: layoutName } = req.body as { layout: string };
|
||||
const { layout: layoutName, targetRow, targetCol } = req.body as { layout: string; targetRow?: number; targetCol?: number };
|
||||
if (!GRID_LAYOUTS[layoutName]) { res.status(400).json({ error: `Unknown grid layout: ${layoutName}` }); return; }
|
||||
try {
|
||||
const result = await this.debug.screenReader.grid.scan(layoutName);
|
||||
const result = await this.debug.screenReader.grid.scan(layoutName, undefined, targetRow, targetCol);
|
||||
const imageBuffer = await this.debug.screenReader.captureRegion(result.layout.region);
|
||||
const imageBase64 = imageBuffer.toString('base64');
|
||||
const r = result.layout.region;
|
||||
const matchInfo = result.matches ? `, ${result.matches.length} matches` : '';
|
||||
this.broadcastLog('info',
|
||||
`Grid scan (${layoutName}): ${result.layout.cols}x${result.layout.rows} at (${r.x},${r.y}) ${r.width}x${r.height} — ${result.occupied.length} occupied cells`);
|
||||
`Grid scan (${layoutName}): ${result.layout.cols}x${result.layout.rows} at (${r.x},${r.y}) ${r.width}x${r.height} — ${result.occupied.length} occupied cells${matchInfo}`);
|
||||
res.json({
|
||||
ok: true,
|
||||
occupied: result.occupied,
|
||||
items: result.items,
|
||||
matches: result.matches,
|
||||
cols: result.layout.cols,
|
||||
rows: result.layout.rows,
|
||||
image: imageBase64,
|
||||
|
|
@ -247,6 +251,51 @@ export class DashboardServer {
|
|||
}
|
||||
});
|
||||
|
||||
// Test: scan grid, find matches for target cell, hover over each for 1s
|
||||
this.app.post('/api/debug/test-match-hover', async (req, res) => {
|
||||
if (!this.debug) { res.status(503).json({ error: 'Debug not available' }); return; }
|
||||
const { layout: layoutName, targetRow, targetCol } = req.body as { layout: string; targetRow: number; targetCol: number };
|
||||
if (!GRID_LAYOUTS[layoutName]) { res.status(400).json({ error: `Unknown layout: ${layoutName}` }); return; }
|
||||
if (targetRow == null || targetCol == null) { res.status(400).json({ error: 'Missing targetRow/targetCol' }); return; }
|
||||
try {
|
||||
// Scan with match target
|
||||
this.broadcastLog('info', `Scanning ${layoutName} with target (${targetRow},${targetCol})...`);
|
||||
const result = await this.debug.screenReader.grid.scan(layoutName, undefined, targetRow, targetCol);
|
||||
const matches = result.matches ?? [];
|
||||
const items = result.items ?? [];
|
||||
|
||||
// Find the item dimensions at target cell
|
||||
const targetItem = items.find(i => targetRow >= i.row && targetRow < i.row + i.h && targetCol >= i.col && targetCol < i.col + i.w);
|
||||
const itemSize = targetItem ? `${targetItem.w}x${targetItem.h}` : '1x1';
|
||||
this.broadcastLog('info', `Target (${targetRow},${targetCol}) is ${itemSize}, found ${matches.length} matches`);
|
||||
|
||||
// Build list of cells to hover: target first, then matches
|
||||
const hoverCells = [
|
||||
{ row: targetRow, col: targetCol, label: 'TARGET' },
|
||||
...matches.map(m => ({ row: m.row, col: m.col, label: `MATCH ${(m.similarity * 100).toFixed(0)}%` })),
|
||||
];
|
||||
|
||||
// Focus game and hover each cell
|
||||
await this.debug.gameController.focusGame();
|
||||
for (const cell of hoverCells) {
|
||||
const center = result.layout.region;
|
||||
const cellW = center.width / result.layout.cols;
|
||||
const cellH = center.height / result.layout.rows;
|
||||
const x = Math.round(center.x + cell.col * cellW + cellW / 2);
|
||||
const y = Math.round(center.y + cell.row * cellH + cellH / 2);
|
||||
this.broadcastLog('info', `Hovering ${cell.label} (${cell.row},${cell.col}) at (${x},${y})...`);
|
||||
await this.debug.gameController.moveMouseTo(x, y);
|
||||
await sleep(1000);
|
||||
}
|
||||
|
||||
this.broadcastLog('info', `Done — hovered ${hoverCells.length} cells`);
|
||||
res.json({ ok: true, itemSize, matchCount: matches.length, hoveredCount: hoverCells.length });
|
||||
} catch (err) {
|
||||
logger.error({ err }, 'Debug test-match-hover failed');
|
||||
res.status(500).json({ error: 'Test match hover failed' });
|
||||
}
|
||||
});
|
||||
|
||||
this.server = http.createServer(this.app);
|
||||
this.wss = new WebSocketServer({ server: this.server });
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue