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

@@ -10,6 +10,7 @@ import { getSource } from "@/lib/services/clone-sources";
import { import {
appendFurniEntriesBatch, appendFurniEntriesBatch,
appendFurniEntry, appendFurniEntry,
rebuildCatalogOfferIds,
reconcileFurniDataWithItemsBase, reconcileFurniDataWithItemsBase,
} from "@/lib/services/furni-data"; } from "@/lib/services/furni-data";
import { import {
@@ -142,6 +143,7 @@ export const POST = withAdmin(
try { try {
await reconcileImportedOfferIds(); await reconcileImportedOfferIds();
await reconcileFurniDataWithItemsBase(); await reconcileFurniDataWithItemsBase();
await rebuildCatalogOfferIds();
await verifyAndFixInteractionModesCount(); await verifyAndFixInteractionModesCount();
await ensureFurniOwnership(); await ensureFurniOwnership();
await syncAssetsToGamedataBundle(); await syncAssetsToGamedataBundle();
@@ -10,6 +10,7 @@ import {
appendFurniEntriesBatch, appendFurniEntriesBatch,
buildFurniEntry, buildFurniEntry,
readFurniData, readFurniData,
rebuildCatalogOfferIds,
reconcileFurniDataWithItemsBase, reconcileFurniDataWithItemsBase,
} from "@/lib/services/furni-data"; } from "@/lib/services/furni-data";
import { import {
@@ -269,6 +270,9 @@ export const POST = withAdmin(
// Verify the furnidata matches the DB ids // Verify the furnidata matches the DB ids
const furniReconcile = await reconcileFurniDataWithItemsBase(); const furniReconcile = await reconcileFurniDataWithItemsBase();
// Rebuild every catalog offer_id from the furnidata
const offerRebuild = await rebuildCatalogOfferIds();
send({ send({
type: "regen_complete", type: "regen_complete",
succeeded, succeeded,
@@ -281,6 +285,8 @@ export const POST = withAdmin(
furniDataFixedIds: furniReconcile.fixedIds, furniDataFixedIds: furniReconcile.fixedIds,
furniDataMissing: furniReconcile.missing, furniDataMissing: furniReconcile.missing,
furniDataConflicts: furniReconcile.conflicts, furniDataConflicts: furniReconcile.conflicts,
offerRebuildChecked: offerRebuild.checked,
offerRebuildFixed: offerRebuild.fixed,
duration: Date.now() - startTime, duration: Date.now() - startTime,
}); });
@@ -5,6 +5,7 @@ import { logAudit } from "@/lib/services/audit";
import { getSource } from "@/lib/services/clone-sources"; import { getSource } from "@/lib/services/clone-sources";
import { import {
appendFurniEntriesBatch, appendFurniEntriesBatch,
rebuildCatalogOfferIds,
reconcileFurniDataWithItemsBase, reconcileFurniDataWithItemsBase,
} from "@/lib/services/furni-data"; } from "@/lib/services/furni-data";
import { import {
@@ -227,6 +228,7 @@ export const POST = withAdmin(
let furniDataFixedOfferIds = 0; let furniDataFixedOfferIds = 0;
let furniDataMissing = 0; let furniDataMissing = 0;
let furniDataConflicts = 0; let furniDataConflicts = 0;
let offerRebuildFixed = 0;
let interactionFixed = 0; let interactionFixed = 0;
try { try {
offerIdsFixed = (await reconcileImportedOfferIds()).fixed; offerIdsFixed = (await reconcileImportedOfferIds()).fixed;
@@ -239,6 +241,7 @@ export const POST = withAdmin(
furniDataFixedOfferIds = furniReconcile.fixedOfferIds; furniDataFixedOfferIds = furniReconcile.fixedOfferIds;
furniDataMissing = furniReconcile.missing; furniDataMissing = furniReconcile.missing;
furniDataConflicts = furniReconcile.conflicts; furniDataConflicts = furniReconcile.conflicts;
offerRebuildFixed = (await rebuildCatalogOfferIds()).fixed;
interactionFixed = (await verifyAndFixInteractionModesCount()).fixed; interactionFixed = (await verifyAndFixInteractionModesCount()).fixed;
} catch (err) { } catch (err) {
console.warn( console.warn(
@@ -260,6 +263,7 @@ export const POST = withAdmin(
furniDataFixedOfferIds, furniDataFixedOfferIds,
furniDataMissing, furniDataMissing,
furniDataConflicts, furniDataConflicts,
offerRebuildFixed,
interactionFixed, interactionFixed,
duration: Date.now() - startTime, duration: Date.now() - startTime,
}); });
+17 -1
View File
@@ -9,7 +9,10 @@ import { logAudit } from "@/lib/services/audit";
import { getCloneList } from "@/lib/services/clone-import"; import { getCloneList } from "@/lib/services/clone-import";
import { getSource } from "@/lib/services/clone-sources"; import { getSource } from "@/lib/services/clone-sources";
import { getFurniAssetDirs } from "@/lib/services/furni-asset-dirs"; import { getFurniAssetDirs } from "@/lib/services/furni-asset-dirs";
import { reconcileFurniDataWithItemsBase } from "@/lib/services/furni-data"; import {
rebuildCatalogOfferIds,
reconcileFurniDataWithItemsBase,
} from "@/lib/services/furni-data";
import { import {
autoPriceFurni, autoPriceFurni,
CATEGORY_PAGE, CATEGORY_PAGE,
@@ -171,11 +174,14 @@ export const GET = withAdmin(
// Live furnidata reconcile (without hotel RCON reload) // Live furnidata reconcile (without hotel RCON reload)
if (action === "live-reconcile") { if (action === "live-reconcile") {
const furniReconcile = await reconcileFurniDataWithItemsBase(); const furniReconcile = await reconcileFurniDataWithItemsBase();
const offerRebuild = await rebuildCatalogOfferIds();
return apiOk({ return apiOk({
furniDataFixedIds: furniReconcile.fixedIds, furniDataFixedIds: furniReconcile.fixedIds,
furniDataFixedOfferIds: furniReconcile.fixedOfferIds, furniDataFixedOfferIds: furniReconcile.fixedOfferIds,
furniDataMissing: furniReconcile.missing, furniDataMissing: furniReconcile.missing,
furniDataConflicts: furniReconcile.conflicts, furniDataConflicts: furniReconcile.conflicts,
offerRebuildChecked: offerRebuild.checked,
offerRebuildFixed: offerRebuild.fixed,
}); });
} }
@@ -452,6 +458,9 @@ export const POST = withAdmin(
// Verify the furnidata matches the DB ids // Verify the furnidata matches the DB ids
const furniReconcile = await reconcileFurniDataWithItemsBase(); const furniReconcile = await reconcileFurniDataWithItemsBase();
// Rebuild every catalog offer_id from the furnidata
const offerRebuild = await rebuildCatalogOfferIds();
// Verify + fix interaction_modes_count once for the whole batch // Verify + fix interaction_modes_count once for the whole batch
const verification = await verifyAndFixInteractionModesCount(); const verification = await verifyAndFixInteractionModesCount();
@@ -471,6 +480,8 @@ export const POST = withAdmin(
furniDataFixedOfferIds: furniReconcile.fixedOfferIds, furniDataFixedOfferIds: furniReconcile.fixedOfferIds,
furniDataMissing: furniReconcile.missing, furniDataMissing: furniReconcile.missing,
furniDataConflicts: furniReconcile.conflicts, furniDataConflicts: furniReconcile.conflicts,
offerRebuildChecked: offerRebuild.checked,
offerRebuildFixed: offerRebuild.fixed,
interactionFixed: verification.fixed, interactionFixed: verification.fixed,
}); });
} }
@@ -533,6 +544,9 @@ export const POST = withAdmin(
// Verify the furnidata matches the DB ids // Verify the furnidata matches the DB ids
const furniReconcile = await reconcileFurniDataWithItemsBase(); const furniReconcile = await reconcileFurniDataWithItemsBase();
// Rebuild every catalog offer_id from the furnidata
const offerRebuild = await rebuildCatalogOfferIds();
// Verify + fix interaction_modes_count (single consolidated pass) // Verify + fix interaction_modes_count (single consolidated pass)
const verification = await verifyAndFixInteractionModesCount(); const verification = await verifyAndFixInteractionModesCount();
@@ -564,6 +578,8 @@ export const POST = withAdmin(
furniDataFixedOfferIds: furniReconcile.fixedOfferIds, furniDataFixedOfferIds: furniReconcile.fixedOfferIds,
furniDataMissing: furniReconcile.missing, furniDataMissing: furniReconcile.missing,
furniDataConflicts: furniReconcile.conflicts, furniDataConflicts: furniReconcile.conflicts,
offerRebuildChecked: offerRebuild.checked,
offerRebuildFixed: offerRebuild.fixed,
interactionFixed: verification.fixed, interactionFixed: verification.fixed,
spriteCount: result.spriteCount, spriteCount: result.spriteCount,
warnings: result.warnings, warnings: result.warnings,
+39 -3
View File
@@ -30,16 +30,52 @@ describe("autoDetectInteraction with real data", () => {
expect(result.interactionType).toBe("bed"); 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", { const result = autoDetectInteraction("table_plasto_4leg", "Table", {
cansiton: false, cansiton: false,
canlayon: false, canlayon: false,
canstandon: 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.canSit).toBe(false);
expect(result.canLay).toBe(false); expect(result.canLay).toBe(false);
expect(result.canStand).toBe(false); expect(result.interactionType).toBe("table");
expect(result.interactionModesCount).toBe(0);
}); });
it("detects dice mechanics from classname with fixed modes=6", () => { it("detects dice mechanics from classname with fixed modes=6", () => {
File diff suppressed because it is too large. Load diff
+10
View File
@@ -361,6 +361,16 @@ export async function generateCatalogSql(
skipped++; skipped++;
continue; continue;
} }
// Re-check against the live table: the audit snapshot may be stale and
// an import may have created the entry in the meantime. Inserting would
// create a duplicate catalog_items row for the same item_ids.
const [existing] = (await db.execute(sql`
SELECT id FROM catalog_items WHERE item_ids = ${String(entry.itemId)} LIMIT 1
`)) as unknown as [Array<{ id: number }>, unknown];
if (existing.length > 0) {
skipped++;
continue;
}
let pageId: number; let pageId: number;
if (organizeSql && parentPageId) { if (organizeSql && parentPageId) {
const catKey = classifyFurni(entry.classname, entry.itemType); const catKey = classifyFurni(entry.classname, entry.itemType);
+19 -6
View File
@@ -379,6 +379,8 @@ export async function cloneSingleFurni(params: {
cansiton: entry.cansiton, cansiton: entry.cansiton,
canlayon: entry.canlayon, canlayon: entry.canlayon,
canstandon: entry.canstandon, canstandon: entry.canstandon,
// Source furnidata flags are curated → authoritative over keywords.
hasActionData: true,
logicType: (clonedNitroJson?.logicType as string) || undefined, logicType: (clonedNitroJson?.logicType as string) || undefined,
animationStates: nitroAnimationStatesCount(clonedNitroJson), animationStates: nitroAnimationStatesCount(clonedNitroJson),
}); });
@@ -440,15 +442,26 @@ export async function cloneSingleFurni(params: {
} }
// Catalog entry (category sub-page + auto price), serialized id allocation. // Catalog entry (category sub-page + auto price), serialized id allocation.
// Skip when the item already has a catalog row — re-imports must never
// create a second row for the same item_ids.
try { try {
const pageId = await getOrCreateCategoryPage(classname, itemType); const [existingCatalog] = (await db.execute(sql`
const price = autoPriceFurni(classname); SELECT id FROM catalog_items WHERE item_ids = ${String(newId)} LIMIT 1
await allocateCatalogItemId(async (nextCatalogId) => { `)) as unknown as [Array<{ id: number }>, unknown];
await db.execute(sql` if (existingCatalog.length > 0) {
warnings.push(
`catalog entry already exists (#${existingCatalog[0].id}) — skipped duplicate`,
);
} else {
const pageId = await getOrCreateCategoryPage(classname, itemType);
const price = autoPriceFurni(classname);
await allocateCatalogItemId(async (nextCatalogId) => {
await db.execute(sql`
INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata) INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`); VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`);
return nextCatalogId; return nextCatalogId;
}); });
}
} catch (err) { } catch (err) {
logger.warn("[clone-import] catalog entry failed for", { logger.warn("[clone-import] catalog entry failed for", {
classname, classname,
File diff suppressed because it is too large. Load diff
+21 -10
View File
@@ -848,10 +848,21 @@ export async function importSingleFurni(params: {
: { x: 1, y: 1, z: 0 }); : { x: 1, y: 1, z: 0 });
const meta = conversionResult?.metadata ?? null; const meta = conversionResult?.metadata ?? null;
// Prefer .nitro flags, then the configured official Habbo furnidata. // Real sit/lay/stand flags: prefer .nitro logic flags, then the configured
const cansiton = meta?.cansiton ?? officialHabbo?.cansiton ?? false; // official Habbo furnidata. Only pass them when a real source exists —
const canlayon = meta?.canlayon ?? officialHabbo?.canlayon ?? false; // defaulted all-false values must not suppress keyword detection (custom
const canstandon = meta?.canstandon ?? officialHabbo?.canstandon ?? false; // SWFs often ship without <action> nodes even for sittable furniture).
const realSource = meta ?? officialHabbo;
const realFlags = realSource
? {
cansiton: realSource.cansiton ?? false,
canlayon: realSource.canlayon ?? false,
canstandon: realSource.canstandon ?? false,
// Official furnidata is curated → authoritative. SWF-derived flags
// are only authoritative when the logic actually had <action> nodes.
hasActionData: meta ? (meta.hasActions ?? true) : true,
}
: undefined;
// Derive interaction_type. Priority: // Derive interaction_type. Priority:
// 1. Wired LOGIC items (wf_act_/wf_trg_/wf_cnd_/wf_slc_/wf_xtra_/wf_var_) // 1. Wired LOGIC items (wf_act_/wf_trg_/wf_cnd_/wf_slc_/wf_xtra_/wf_var_)
@@ -903,9 +914,7 @@ export async function importSingleFurni(params: {
// no .nitro JSON available — keyword fallback only // no .nitro JSON available — keyword fallback only
} }
const autoInteraction = autoDetectInteraction(classname, bestName, { const autoInteraction = autoDetectInteraction(classname, bestName, {
cansiton, ...realFlags,
canlayon,
canstandon,
logicType, logicType,
animationStates: nitroAnimationStatesCount(nitroJsonForModes), animationStates: nitroAnimationStatesCount(nitroJsonForModes),
}); });
@@ -929,9 +938,9 @@ export async function importSingleFurni(params: {
const update = buildItemsBaseEnrichmentUpdate({ const update = buildItemsBaseEnrichmentUpdate({
id: spriteId, id: spriteId,
dims, dims,
cansiton, cansiton: autoInteraction.canSit,
canlayon, canlayon: autoInteraction.canLay,
canstandon, canstandon: autoInteraction.canStand,
allowStack, allowStack,
interactionType, interactionType,
interactionModesCount, interactionModesCount,
@@ -1123,6 +1132,8 @@ export async function verifyAndFixInteractionModesCount(): Promise<{
cansiton: realFlags.cansiton, cansiton: realFlags.cansiton,
canlayon: realFlags.canlayon, canlayon: realFlags.canlayon,
canstandon: realFlags.canstandon, canstandon: realFlags.canstandon,
// Furnidata flags are curated → authoritative over keywords.
hasActionData: true,
animationStates: animationModes, animationStates: animationModes,
}); });
+1
View File
@@ -425,6 +425,7 @@ export function convertSwfToNitro(
canstandon: logic.canstandon, canstandon: logic.canstandon,
cansiton: logic.cansiton, cansiton: logic.cansiton,
canlayon: logic.canlayon, canlayon: logic.canlayon,
hasActions: logic.hasActions,
specialtype: indexData?.specialtype ?? 0, specialtype: indexData?.specialtype ?? 0,
defaultdir: computeDefaultDir(logic.directions), defaultdir: computeDefaultDir(logic.directions),
partcolors: extractPartColors(visualizations), partcolors: extractPartColors(visualizations),
+4
View File
@@ -226,6 +226,8 @@ export interface LogicResult {
canstandon: boolean; canstandon: boolean;
cansiton: boolean; cansiton: boolean;
canlayon: boolean; canlayon: boolean;
/** True when the logic XML actually declared <action> nodes — flags are then authoritative. */
hasActions: boolean;
action?: { link?: string; startState?: number }; action?: { link?: string; startState?: number };
credits?: string; credits?: string;
soundSample?: { id: number; noPitch?: boolean }; soundSample?: { id: number; noPitch?: boolean };
@@ -242,6 +244,7 @@ export function processLogic(xml: string): LogicResult {
canstandon: false, canstandon: false,
cansiton: false, cansiton: false,
canlayon: false, canlayon: false,
hasActions: false,
}; };
const root = parseXml(xml); const root = parseXml(xml);
if (!root) return defaults; if (!root) return defaults;
@@ -285,6 +288,7 @@ export function processLogic(xml: string): LogicResult {
canstandon, canstandon,
cansiton, cansiton,
canlayon, canlayon,
hasActions: actions.length > 0,
}; };
// Parse action link/startState // Parse action link/startState
+19 -5
View File
@@ -337,6 +337,8 @@ export async function uploadSingleFurni(params: {
cansiton, cansiton,
canlayon, canlayon,
canstandon, canstandon,
// Flags come from explicit user input → authoritative over keywords.
hasActionData: true,
logicType: (nitroMeta?.logicType as string) || undefined, logicType: (nitroMeta?.logicType as string) || undefined,
animationStates: nitroAnimationStatesCount(nitroMeta), animationStates: nitroAnimationStatesCount(nitroMeta),
}); });
@@ -387,13 +389,25 @@ export async function uploadSingleFurni(params: {
let catalogItemId: number | null = null; let catalogItemId: number | null = null;
try { try {
const pageId = await getOrCreateCategoryPage(classname, itemType); // Skip when the item already has a catalog row — re-uploads must never
catalogItemId = await allocateCatalogItemId(async (nextCatalogId) => { // create a second row for the same item_ids.
await db.execute(sql` const [existingCatalog] = (await db.execute(sql`
SELECT id FROM catalog_items WHERE item_ids = ${String(newId)} LIMIT 1
`)) as unknown as [Array<{ id: number }>, unknown];
if (existingCatalog.length > 0) {
catalogItemId = existingCatalog[0].id;
warnings.push(
`catalog entry already exists (#${catalogItemId}) — skipped duplicate`,
);
} else {
const pageId = await getOrCreateCategoryPage(classname, itemType);
catalogItemId = await allocateCatalogItemId(async (nextCatalogId) => {
await db.execute(sql`
INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata) INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`); VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`);
return nextCatalogId; return nextCatalogId;
}); });
}
} catch (err) { } catch (err) {
warnings.push(`catalog entry failed: ${(err as Error).message}`); warnings.push(`catalog entry failed: ${(err as Error).message}`);
} }
+2
View File
@@ -24,6 +24,8 @@ export interface FurniMetadata {
canstandon: boolean; canstandon: boolean;
cansiton: boolean; cansiton: boolean;
canlayon: boolean; canlayon: boolean;
/** True when the SWF logic XML declared <action> nodes (flags authoritative). */
hasActions?: boolean;
specialtype: number; specialtype: number;
defaultdir: number; defaultdir: number;
partcolors: { color: string[] }; partcolors: { color: string[] };