Implement tooltip-based market item collection
This commit is contained in:
+47
-4
@@ -16,6 +16,15 @@ export function resolveFieldRect(anchorPosition, field) {
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveScreenRect(region, width, height) {
|
||||
return {
|
||||
x: Math.round(region.xRatio * width),
|
||||
y: Math.round(region.yRatio * height),
|
||||
width: Math.round(region.widthRatio * width),
|
||||
height: Math.round(region.heightRatio * height),
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeOcrText(text) {
|
||||
return text.replace(/\s+/g, " ").trim();
|
||||
}
|
||||
@@ -31,12 +40,46 @@ export function parseFieldValue(type, text) {
|
||||
return digits ? Number(digits) : null;
|
||||
}
|
||||
|
||||
export function parseMerchantText(text) {
|
||||
return text
|
||||
.split(/\r?\n/)
|
||||
.map(normalizeOcrText)
|
||||
.find(Boolean) ?? "";
|
||||
}
|
||||
|
||||
export function parseTooltipText(text) {
|
||||
const lines = text
|
||||
.split(/\r?\n/)
|
||||
.map(normalizeOcrText)
|
||||
.filter(Boolean);
|
||||
const priceIndex = lines.findIndex((line) => /pr[i1l]ce\s*[:;]?/i.test(line));
|
||||
|
||||
if (priceIndex < 0) return null;
|
||||
|
||||
const priceLine = lines[priceIndex];
|
||||
const priceMatch = priceLine.match(/pr[i1l]ce\s*[:;]?\s*([\d\s,.'`]+)\s*adena/i);
|
||||
const digits = priceMatch?.[1].replace(/\D/g, "") ?? "";
|
||||
let name = lines[priceIndex - 1] ?? "";
|
||||
|
||||
if (!name) {
|
||||
name = priceLine.slice(0, priceLine.search(/pr[i1l]ce/i)).trim();
|
||||
}
|
||||
|
||||
if (!name || !digits) return null;
|
||||
|
||||
return { name, priceAdena: Number(digits), rawText: lines.join("\n") };
|
||||
}
|
||||
|
||||
export function isCalibrationReady(calibration) {
|
||||
return Boolean(
|
||||
calibration?.anchor?.image &&
|
||||
calibration.anchor.width >= 4 &&
|
||||
calibration.anchor.height >= 4 &&
|
||||
calibration.fields?.length,
|
||||
calibration?.saleAnchor?.image &&
|
||||
calibration.saleAnchor.width >= 4 &&
|
||||
calibration.saleAnchor.height >= 4 &&
|
||||
calibration.merchantRegion &&
|
||||
calibration.tooltipSearchRegion &&
|
||||
calibration.tooltipAnchor?.image &&
|
||||
calibration.itemNameRegion &&
|
||||
calibration.itemPriceRegion,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user