Implement tooltip-based market item collection

This commit is contained in:
2026-08-11 17:11:44 +03:00
parent f9271d4ab9
commit d6e0ba466b
9 changed files with 458 additions and 172 deletions
+38 -4
View File
@@ -3,9 +3,12 @@ import assert from "node:assert/strict";
import {
isCalibrationReady,
isRectInside,
parseMerchantText,
parseFieldValue,
parseTooltipText,
rectFromPoints,
resolveFieldRect,
resolveScreenRect,
} from "../src/parser.js";
test("normalizes a reverse drag into a positive rectangle", () => {
@@ -33,12 +36,16 @@ test("parses formatted prices and rejects empty numeric OCR", () => {
assert.equal(parseFieldValue("item", " Soulshot: S-grade\n"), "Soulshot: S-grade");
});
test("requires an anchor image and at least one field", () => {
assert.equal(isCalibrationReady({ anchor: null, fields: [] }), false);
test("requires both anchors and exact OCR regions", () => {
assert.equal(isCalibrationReady({ saleAnchor: null }), false);
assert.equal(
isCalibrationReady({
anchor: { image: "data:image/png;base64,x", width: 20, height: 10 },
fields: [{ id: "price" }],
saleAnchor: { image: "data:image/png;base64,x", width: 20, height: 10 },
merchantRegion: { xRatio: 0.1, yRatio: 0.1, widthRatio: 0.2, heightRatio: 0.1 },
tooltipSearchRegion: { offsetX: -100, offsetY: -300, width: 300, height: 100 },
tooltipAnchor: { image: "data:image/png;base64,y", width: 30, height: 12 },
itemNameRegion: { offsetX: 0, offsetY: -18, width: 220, height: 18 },
itemPriceRegion: { offsetX: 0, offsetY: 0, width: 160, height: 18 },
}),
true,
);
@@ -48,3 +55,30 @@ test("detects OCR rectangles outside the captured frame", () => {
assert.equal(isRectInside({ x: 10, y: 10, width: 20, height: 20 }, 100, 100), true);
assert.equal(isRectInside({ x: 90, y: 10, width: 20, height: 20 }, 100, 100), false);
});
test("resolves the merchant region against the current window size", () => {
assert.deepEqual(
resolveScreenRect(
{ xRatio: 0.25, yRatio: 0.1, widthRatio: 0.5, heightRatio: 0.08 },
1200,
800,
),
{ x: 300, y: 80, width: 600, height: 64 },
);
});
test("parses a hovered item tooltip", () => {
assert.deepEqual(
parseTooltipText("Tears of Eva\nPrice : 3,000,000 Adena\n(3 Million Adena)"),
{
name: "Tears of Eva",
priceAdena: 3000000,
rawText: "Tears of Eva\nPrice : 3,000,000 Adena\n(3 Million Adena)",
},
);
assert.equal(parseTooltipText("Purchase List\nAdena 5,403,160"), null);
});
test("takes the first OCR line as merchant name", () => {
assert.equal(parseMerchantText(" Dwa \nVagabond\n"), "Dwa");
});