feat: verify and fix interaction_modes_count on every import
- Added verifyAndFixInteractionModesCount() to scan all items_base entries - Auto-detects correct interaction_modes_count from classname/name - Fixes mismatched values during furniture import - Reports fixed/checked count in warnings
This commit is contained in:
1 parent
dee843106f
commit
7911a25ced
1 file changed
+67
@@ -974,6 +974,23 @@ export async function importSingleFurni(params: {
|
|||||||
warnings.push("Catalog entry creation failed");
|
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 {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
itemId: spriteId,
|
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 helpers ───────────────────────────────────────────────────
|
||||||
|
|
||||||
/** Delete a single imported item: DB records, FurnitureData.json entry, and asset files. */
|
/** Delete a single imported item: DB records, FurnitureData.json entry, and asset files. */
|
||||||
|
|||||||
Reference in new issue
Block a user