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:
1 parent
652d331402
commit
4b7cb519df
14 files changed
+418
-58
No files matched your search
@@ -361,6 +361,16 @@ export async function generateCatalogSql(
|
||||
skipped++;
|
||||
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;
|
||||
if (organizeSql && parentPageId) {
|
||||
const catKey = classifyFurni(entry.classname, entry.itemType);
|
||||
|
||||
@@ -379,6 +379,8 @@ export async function cloneSingleFurni(params: {
|
||||
cansiton: entry.cansiton,
|
||||
canlayon: entry.canlayon,
|
||||
canstandon: entry.canstandon,
|
||||
// Source furnidata flags are curated → authoritative over keywords.
|
||||
hasActionData: true,
|
||||
logicType: (clonedNitroJson?.logicType as string) || undefined,
|
||||
animationStates: nitroAnimationStatesCount(clonedNitroJson),
|
||||
});
|
||||
@@ -440,15 +442,26 @@ export async function cloneSingleFurni(params: {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
const pageId = await getOrCreateCategoryPage(classname, itemType);
|
||||
const price = autoPriceFurni(classname);
|
||||
await allocateCatalogItemId(async (nextCatalogId) => {
|
||||
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) {
|
||||
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)
|
||||
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`);
|
||||
return nextCatalogId;
|
||||
});
|
||||
return nextCatalogId;
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
logger.warn("[clone-import] catalog entry failed for", {
|
||||
classname,
|
||||
|
||||
@@ -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 };
|
||||
});
|
||||
}
|
||||
@@ -848,10 +848,21 @@ export async function importSingleFurni(params: {
|
||||
: { x: 1, y: 1, z: 0 });
|
||||
const meta = conversionResult?.metadata ?? null;
|
||||
|
||||
// Prefer .nitro flags, then the configured official Habbo furnidata.
|
||||
const cansiton = meta?.cansiton ?? officialHabbo?.cansiton ?? false;
|
||||
const canlayon = meta?.canlayon ?? officialHabbo?.canlayon ?? false;
|
||||
const canstandon = meta?.canstandon ?? officialHabbo?.canstandon ?? false;
|
||||
// Real sit/lay/stand flags: prefer .nitro logic flags, then the configured
|
||||
// official Habbo furnidata. Only pass them when a real source exists —
|
||||
// defaulted all-false values must not suppress keyword detection (custom
|
||||
// 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:
|
||||
// 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
|
||||
}
|
||||
const autoInteraction = autoDetectInteraction(classname, bestName, {
|
||||
cansiton,
|
||||
canlayon,
|
||||
canstandon,
|
||||
...realFlags,
|
||||
logicType,
|
||||
animationStates: nitroAnimationStatesCount(nitroJsonForModes),
|
||||
});
|
||||
@@ -929,9 +938,9 @@ export async function importSingleFurni(params: {
|
||||
const update = buildItemsBaseEnrichmentUpdate({
|
||||
id: spriteId,
|
||||
dims,
|
||||
cansiton,
|
||||
canlayon,
|
||||
canstandon,
|
||||
cansiton: autoInteraction.canSit,
|
||||
canlayon: autoInteraction.canLay,
|
||||
canstandon: autoInteraction.canStand,
|
||||
allowStack,
|
||||
interactionType,
|
||||
interactionModesCount,
|
||||
@@ -1123,6 +1132,8 @@ export async function verifyAndFixInteractionModesCount(): Promise<{
|
||||
cansiton: realFlags.cansiton,
|
||||
canlayon: realFlags.canlayon,
|
||||
canstandon: realFlags.canstandon,
|
||||
// Furnidata flags are curated → authoritative over keywords.
|
||||
hasActionData: true,
|
||||
animationStates: animationModes,
|
||||
});
|
||||
|
||||
|
||||
@@ -425,6 +425,7 @@ export function convertSwfToNitro(
|
||||
canstandon: logic.canstandon,
|
||||
cansiton: logic.cansiton,
|
||||
canlayon: logic.canlayon,
|
||||
hasActions: logic.hasActions,
|
||||
specialtype: indexData?.specialtype ?? 0,
|
||||
defaultdir: computeDefaultDir(logic.directions),
|
||||
partcolors: extractPartColors(visualizations),
|
||||
|
||||
@@ -226,6 +226,8 @@ export interface LogicResult {
|
||||
canstandon: boolean;
|
||||
cansiton: boolean;
|
||||
canlayon: boolean;
|
||||
/** True when the logic XML actually declared <action> nodes — flags are then authoritative. */
|
||||
hasActions: boolean;
|
||||
action?: { link?: string; startState?: number };
|
||||
credits?: string;
|
||||
soundSample?: { id: number; noPitch?: boolean };
|
||||
@@ -242,6 +244,7 @@ export function processLogic(xml: string): LogicResult {
|
||||
canstandon: false,
|
||||
cansiton: false,
|
||||
canlayon: false,
|
||||
hasActions: false,
|
||||
};
|
||||
const root = parseXml(xml);
|
||||
if (!root) return defaults;
|
||||
@@ -285,6 +288,7 @@ export function processLogic(xml: string): LogicResult {
|
||||
canstandon,
|
||||
cansiton,
|
||||
canlayon,
|
||||
hasActions: actions.length > 0,
|
||||
};
|
||||
|
||||
// Parse action link/startState
|
||||
|
||||
@@ -337,6 +337,8 @@ export async function uploadSingleFurni(params: {
|
||||
cansiton,
|
||||
canlayon,
|
||||
canstandon,
|
||||
// Flags come from explicit user input → authoritative over keywords.
|
||||
hasActionData: true,
|
||||
logicType: (nitroMeta?.logicType as string) || undefined,
|
||||
animationStates: nitroAnimationStatesCount(nitroMeta),
|
||||
});
|
||||
@@ -387,13 +389,25 @@ export async function uploadSingleFurni(params: {
|
||||
|
||||
let catalogItemId: number | null = null;
|
||||
try {
|
||||
const pageId = await getOrCreateCategoryPage(classname, itemType);
|
||||
catalogItemId = await allocateCatalogItemId(async (nextCatalogId) => {
|
||||
await db.execute(sql`
|
||||
// Skip when the item already has a catalog row — re-uploads must never
|
||||
// create a second row for the same item_ids.
|
||||
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)
|
||||
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`);
|
||||
return nextCatalogId;
|
||||
});
|
||||
return nextCatalogId;
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
warnings.push(`catalog entry failed: ${(err as Error).message}`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user