diff --git a/src/lib/services/furni-import.ts b/src/lib/services/furni-import.ts index 154f3054..86d4fb9b 100644 --- a/src/lib/services/furni-import.ts +++ b/src/lib/services/furni-import.ts @@ -974,6 +974,23 @@ export async function importSingleFurni(params: { warnings.push("Catalog entry creation failed"); } + // Verify and fix interaction_modes_count for all furniture + try { + const verification = await verifyAndFixInteractionModesCount(); + if (verification.fixed > 0) { + warnings.push( + `Fixed interaction_modes_count for ${verification.fixed} of ${verification.checked} items`, + ); + } + for (const err of verification.errors) { + warnings.push(`Interaction modes verification: ${err}`); + } + } catch (err) { + warnings.push( + `Interaction modes verification failed: ${(err as Error).message}`, + ); + } + return { ok: true, itemId: spriteId, @@ -988,6 +1005,56 @@ export async function importSingleFurni(params: { }; } +// ── Interaction modes count verification ────────────────────────────── + +/** Verify and fix interaction_modes_count for ALL furniture in items_base. + * Run after import to ensure all items have correct values based on classname/name. */ +export async function verifyAndFixInteractionModesCount(): Promise<{ + fixed: number; + checked: number; + errors: string[]; +}> { + const errors: string[] = []; + let fixed = 0; + let checked = 0; + + try { + const allItems = await db + .select({ + id: ItemsBase.id, + itemName: ItemsBase.itemName, + publicName: ItemsBase.publicName, + interactionModesCount: ItemsBase.interactionModesCount, + }) + .from(ItemsBase); + + for (const item of allItems) { + checked++; + const auto = autoDetectInteraction(item.itemName, item.publicName); + const expectedModes = auto.interactionModesCount; + const currentModes = item.interactionModesCount ?? 0; + + if (currentModes !== expectedModes) { + try { + await db + .update(ItemsBase) + .set({ interactionModesCount: expectedModes }) + .where(eq(ItemsBase.id, item.id)); + fixed++; + } catch (err) { + errors.push( + `Failed to fix ${item.itemName}: ${(err as Error).message}`, + ); + } + } + } + } catch (err) { + errors.push(`Verification failed: ${(err as Error).message}`); + } + + return { fixed, checked, errors }; +} + // ── Delete helpers ─────────────────────────────────────────────────── /** Delete a single imported item: DB records, FurnitureData.json entry, and asset files. */