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

+94 -1
View File
@@ -1,6 +1,7 @@
import { existsSync, promises as fs } from "node:fs";
import path from "node:path";
import { db, ItemsBase } from "@/lib/db";
import { eq } from "drizzle-orm";
import { CatalogItems, db, ItemsBase } from "@/lib/db";
import {
getGamedataRoot,
getNitroFilesRoot,
@@ -563,3 +564,95 @@ export async function reconcileFurniDataWithItemsBase(): Promise<FurniDataReconc
return { fixedIds, fixedOfferIds, normalizedIds, missing, conflicts };
});
}
export interface CatalogOfferRebuildResult {
/** catalog_items rows examined. */
checked: number;
/** Rows whose offer_id was corrected. */
fixed: number;
/** Fixed rows with no furnidata entry (offer_id fell back to the sprite id). */
fallback: number;
}
/**
* Rebuild EVERY catalog_items.offer_id from the local FurnitureData.json.
*
* The Nitro client resolves offers through the furnidata `offerid`, and the
* emulator maps that offer id back to a catalog item (CatalogManager
* offerDefs). The chain only works when catalog_items.offer_id equals the
* furnidata offerid — which this CMS reconciles to the items_base sprite id.
*
* For every catalog row: resolve item_ids → items_base classname → furnidata
* offerid and write it into offer_id. Rows without a furnidata entry fall
* back to the sprite id itself (same value in practice). Run after every
* import so drift from manual edits or legacy rows is repaired automatically.
*/
export async function rebuildCatalogOfferIds(): Promise<CatalogOfferRebuildResult> {
return withFurniDataLock(async () => {
const furniData = (await readFurniData()) as Record<
string,
{ furnitype?: Array<Record<string, unknown>> }
>;
const offerById = new Map<number, number>();
const offerByClass = new Map<string, number>();
for (const section of ["roomitemtypes", "wallitemtypes"] as const) {
for (const e of furniData[section]?.furnitype ?? []) {
const cn = typeof e?.classname === "string" ? e.classname : "";
const entryId = Number(e?.id);
const offer = Number(e?.offerid);
if (
cn &&
Number.isFinite(offer) &&
offer > 0 &&
!offerByClass.has(cn)
) {
offerByClass.set(cn, offer);
}
if (
Number.isFinite(entryId) &&
entryId > 0 &&
!offerById.has(entryId)
) {
offerById.set(
entryId,
Number.isFinite(offer) && offer > 0 ? offer : entryId,
);
}
}
}
const itemRows = await db
.select({ id: ItemsBase.id, itemName: ItemsBase.itemName })
.from(ItemsBase);
const nameById = new Map<number, string>();
for (const r of itemRows) nameById.set(r.id, r.itemName);
const catalogRows = await db
.select({
id: CatalogItems.id,
itemIds: CatalogItems.itemIds,
offerId: CatalogItems.offerId,
})
.from(CatalogItems);
let fixed = 0;
let fallback = 0;
for (const row of catalogRows) {
const itemId = Number(String(row.itemIds ?? "").split(/[;,]/)[0]);
if (!Number.isFinite(itemId) || itemId <= 0) continue;
const classname = nameById.get(itemId);
const furnidataOffer =
offerById.get(itemId) ??
(classname ? offerByClass.get(classname) : undefined);
const target = furnidataOffer ?? itemId;
if (row.offerId === target) continue;
await db
.update(CatalogItems)
.set({ offerId: target })
.where(eq(CatalogItems.id, row.id));
fixed++;
if (furnidataOffer === undefined) fallback++;
}
return { checked: catalogRows.length, fixed, fallback };
});
}