fix: furniture interaction detection and automatic catalog offer_id rebuild

Interaction detection:
- Trust SWF-derived sit/lay/stand flags only when the logic XML actually
  contains action data (new hasActions metadata); otherwise fall back to
  keyword detection so custom furni without <action> nodes are still
  classified correctly
- Add French/Dutch/German/Spanish/Italian keywords (chaise, banquette,
  stoel, silla, sedia, stuhl, tafel, mesa, ...) to sit/lay/stand detection
  with token-boundary matching to avoid false positives like bedside_table
- Unify interaction_modes_count priority: mechanic fixed modes, then raw
  animation state count, then sit/lay fallback, then keyword default
- Detect mechanic type even when real flags are not used

Catalog integrity:
- Skip duplicate catalog_items inserts in clone and upload imports
- Re-check live catalog rows before applying generated repair SQL
- Add rebuildCatalogOfferIds() which rebuilds every catalog_items.offer_id
  from the local FurnitureData.json (matched by entry id, then classname)
  and run it after every import path (single, batch, batch-regen, clone)
This commit is contained in:
openhands committed 2026-08-21 13:39:21 +02:00
1 parent 652d331402
commit 4b7cb519df
14 files changed
+418 -58

No files matched your search

+39 -3
View File
@@ -30,16 +30,52 @@ describe("autoDetectInteraction with real data", () => {
expect(result.interactionType).toBe("bed");
});
it("respects all-false real flags (no keyword false positive)", () => {
it("respects curated all-false real flags (no keyword false positive)", () => {
const result = autoDetectInteraction("table_plasto_4leg", "Table", {
cansiton: false,
canlayon: false,
canstandon: false,
hasActionData: true,
});
expect(result.canSit).toBe(false);
expect(result.canLay).toBe(false);
expect(result.canStand).toBe(false);
expect(result.interactionModesCount).toBe(0);
});
it("falls back to keywords when flags carry no action data", () => {
const result = autoDetectInteraction("chaise_metal_lamarr", "Chaise", {
cansiton: false,
canlayon: false,
canstandon: false,
animationStates: 4,
});
expect(result.canSit).toBe(true);
expect(result.canStand).toBe(false);
expect(result.interactionModesCount).toBe(4);
});
it("detects French bench (banquette) with raw state count", () => {
const result = autoDetectInteraction("banquette_lamarr", "Banquette", {
cansiton: false,
canlayon: false,
canstandon: false,
animationStates: 6,
});
expect(result.canSit).toBe(true);
expect(result.interactionType).toBe("bench");
expect(result.interactionModesCount).toBe(6);
});
it("does not match short keywords without token boundaries", () => {
const result = autoDetectInteraction("bedside_table", "Bedside Table", {
cansiton: false,
canlayon: false,
canstandon: false,
});
expect(result.canSit).toBe(false);
expect(result.canLay).toBe(false);
expect(result.canStand).toBe(false);
expect(result.interactionModesCount).toBe(0);
expect(result.interactionType).toBe("table");
});
it("detects dice mechanics from classname with fixed modes=6", () => {
+180 -32
View File
@@ -25,6 +25,13 @@ export interface RealInteractionData {
specialtype?: number;
/** Real animation-state count from the .nitro asset. */
animationStates?: number;
/**
* True when the sit/lay/stand flags come from a curated source (official
* furnidata) or from SWF logic that actually contains <action> nodes.
* When false the flags were defaulted (asset had no action data at all),
* so keyword detection may still contribute.
*/
hasActionData?: boolean;
}
function realSitLayStand(
@@ -37,13 +44,16 @@ function realSitLayStand(
canStand: boolean;
usedReal: boolean;
} {
// When real flags are present (even all-false), trust them completely —
// keyword detection would only introduce false positives.
// When real flags are present AND trustworthy (curated furnidata, or SWF
// logic that actually declared <action> nodes), trust them completely —
// keyword detection would only introduce false positives. All-false flags
// without any action data mean "unknown", not "confirmed false".
if (
real &&
(real.cansiton !== undefined ||
real.canlayon !== undefined ||
real.canstandon !== undefined)
(real.hasActionData === true ||
real.cansiton === true ||
real.canlayon === true ||
real.canstandon === true)
) {
return {
canSit: real.cansiton === true,
@@ -100,11 +110,14 @@ export function autoDetectInteraction(
let clickLimit = 0;
let interactionModesCount = 0;
// Classname mechanics (dice/gate/teleport/…) are deterministic — detect
// them regardless of whether real flags were trusted.
const mechanicType = realMechanicType(classname);
if (usedReal) {
// interactionType: the classname mechanic wins when detectable (dice/gate/
// teleport ship as generic furniture_multistate in .nitro, so logicType
// alone cannot distinguish them), then the real logicType mapping.
const mechanicType = realMechanicType(classname);
const keywordType =
INTERACTION_TYPE_MAP[
((layMatch ??
@@ -116,40 +129,45 @@ export function autoDetectInteraction(
(real?.logicType && real.logicType !== "furniture_basic"
? (mapLogicType(real.logicType) ?? "default")
: (keywordType ?? "default"));
// Real modes count. Emulator convention for state-based mechanics is
// fixed (dice = 6, gate/teleport = 2, roller = 1). Generic multistate
// items get the real animation-state count; chairs/beds = 1; plain = 0.
const fixedModes = MECHANIC_MODES[interactionType];
if (fixedModes !== undefined) {
interactionModesCount = fixedModes;
} else if (
real?.animationStates !== undefined &&
real.animationStates > 1
) {
interactionModesCount = real.animationStates;
} else if (canLay || canSit) {
interactionModesCount = 1;
} else {
interactionModesCount = 0;
}
clickLimit = canLay || canSit || canStand ? 1 : 0;
} else if (layMatch) {
matchedKeyword = layMatch;
interactionType = INTERACTION_TYPE_MAP[layMatch] || "bed";
clickLimit = CLICK_LIMITS[layMatch] ?? 1;
interactionModesCount = INTERACTION_MODES[layMatch] ?? 1;
} else if (sitMatch) {
matchedKeyword = sitMatch;
interactionType = INTERACTION_TYPE_MAP[sitMatch] || "chair";
clickLimit = CLICK_LIMITS[sitMatch] ?? 1;
interactionModesCount = INTERACTION_MODES[sitMatch] ?? 1;
} else if (standMatch) {
matchedKeyword = standMatch;
interactionType = INTERACTION_TYPE_MAP[standMatch] || "default";
clickLimit = CLICK_LIMITS[standMatch] ?? 0;
interactionModesCount = INTERACTION_MODES[standMatch] ?? 0;
}
if (!usedReal && mechanicType) {
interactionType = mechanicType;
}
// Modes count = how many states clicking cycles through. Priority:
// 1. Emulator-fixed value per mechanic (dice = 6, gate/teleport = 2, …)
// 2. Real animation-state count from the .nitro asset (renderable states)
// 3. Sit/lay furniture without state info → 1
// 4. Keyword default (chairs 1, tables 0) / plain items → 0
const fixedModes = MECHANIC_MODES[interactionType];
if (fixedModes !== undefined) {
interactionModesCount = fixedModes;
} else if (real?.animationStates !== undefined && real.animationStates > 1) {
interactionModesCount = real.animationStates;
} else if (canLay || canSit) {
interactionModesCount = 1;
} else if (matchedKeyword) {
interactionModesCount = INTERACTION_MODES[matchedKeyword] ?? 0;
} else {
interactionModesCount = 0;
}
clickLimit =
fixedModes !== undefined
? 1
: canLay || canSit || canStand
? 1
: matchedKeyword
? (CLICK_LIMITS[matchedKeyword] ?? 0)
: 0;
const reasonParts: string[] = [];
if (usedReal) {
@@ -278,6 +296,26 @@ const SIT_KEYWORDS = [
"wheelchair",
"toilet",
"potty",
// French
"chaise",
"banquette",
"tabouret",
"fauteuil",
"canap",
"banc",
// Dutch
"stoel",
"kruk",
// Spanish
"silla",
"taburete",
// Italian
"sedia",
"poltrona",
// German
"stuhl",
"sessel",
"hocker",
];
const LAY_KEYWORDS = [
@@ -297,6 +335,17 @@ const LAY_KEYWORDS = [
"daybed",
"divan",
"waterbed",
// French
"matelas",
"couette",
// Dutch
"bedden",
// Spanish
"cama",
// Italian
"letto",
// German
"bett",
];
const STAND_KEYWORDS = [
@@ -328,6 +377,16 @@ const STAND_KEYWORDS = [
"water",
"pool",
"fountain",
// French
"tafel",
"bureau",
"etagere",
// Spanish / Italian
"mesa",
"tavolo",
// German
"schrank",
"kommode",
];
const INTERACTION_TYPE_MAP: Record<string, string> = {
@@ -366,6 +425,27 @@ const INTERACTION_TYPE_MAP: Record<string, string> = {
daybed: "daybed",
divan: "divan",
waterbed: "waterbed",
matelas: "bed",
couette: "bed",
bedden: "bed",
cama: "bed",
letto: "bed",
bett: "bed",
chaise: "chair",
banquette: "bench",
tabouret: "stool",
fauteuil: "armchair",
canap: "sofa",
banc: "bench",
stoel: "chair",
kruk: "stool",
silla: "chair",
taburete: "stool",
sedia: "chair",
poltrona: "armchair",
stuhl: "chair",
sessel: "armchair",
hocker: "stool",
table: "table",
desk: "desk",
counter: "counter",
@@ -380,6 +460,13 @@ const INTERACTION_TYPE_MAP: Record<string, string> = {
pedestal: "pedestal",
platform: "platform",
stage: "stage",
tafel: "table",
bureau: "desk",
etagere: "shelf",
mesa: "table",
tavolo: "table",
schrank: "wardrobe",
kommode: "dresser",
};
const INTERACTION_MODES: Record<string, number> = {
@@ -418,6 +505,27 @@ const INTERACTION_MODES: Record<string, number> = {
daybed: 1,
divan: 1,
waterbed: 1,
matelas: 1,
couette: 1,
bedden: 1,
cama: 1,
letto: 1,
bett: 1,
chaise: 1,
banquette: 1,
tabouret: 1,
fauteuil: 1,
canap: 1,
banc: 1,
stoel: 1,
kruk: 1,
silla: 1,
taburete: 1,
sedia: 1,
poltrona: 1,
stuhl: 1,
sessel: 1,
hocker: 1,
table: 0,
desk: 0,
counter: 0,
@@ -446,6 +554,13 @@ const INTERACTION_MODES: Record<string, number> = {
water: 0,
pool: 0,
fountain: 0,
tafel: 0,
bureau: 0,
etagere: 0,
mesa: 0,
tavolo: 0,
schrank: 0,
kommode: 0,
};
const CLICK_LIMITS: Record<string, number> = {
@@ -484,6 +599,27 @@ const CLICK_LIMITS: Record<string, number> = {
daybed: 1,
divan: 1,
waterbed: 1,
matelas: 1,
couette: 1,
bedden: 1,
cama: 1,
letto: 1,
bett: 1,
chaise: 1,
banquette: 1,
tabouret: 1,
fauteuil: 1,
canap: 1,
banc: 1,
stoel: 1,
kruk: 1,
silla: 1,
taburete: 1,
sedia: 1,
poltrona: 1,
stuhl: 1,
sessel: 1,
hocker: 1,
table: 0,
desk: 0,
counter: 0,
@@ -512,6 +648,13 @@ const CLICK_LIMITS: Record<string, number> = {
water: 0,
pool: 0,
fountain: 0,
tafel: 0,
bureau: 0,
etagere: 0,
mesa: 0,
tavolo: 0,
schrank: 0,
kommode: 0,
};
function normalizeString(str: string): string {
@@ -520,9 +663,14 @@ function normalizeString(str: string): string {
function findMatch(normalized: string, keywords: string[]): string | null {
for (const kw of keywords) {
if (normalized.includes(kw)) {
return kw;
if (!normalized.includes(kw)) continue;
// Short keywords (e.g. "bed", "lit", "bar") must match on token
// boundaries so "bedside_table" or "split" don't false-positive.
if (kw.length < 5) {
const boundary = new RegExp(`(^|_)${kw}(_|$)`);
if (!boundary.test(normalized)) continue;
}
return kw;
}
return null;
}