Remap occupied furniture IDs during Catalog Studio imports
This commit is contained in:
1 parent
9f791ba284
commit
9dc6b8a261
6 files changed
+206
-9
No files matched your search
@@ -37,6 +37,7 @@ import {
|
||||
} from "@/lib/services/swf-to-nitro";
|
||||
import { getRuntimePath } from "@/lib/utils/runtime-path";
|
||||
import type { ImportSingleResult } from "@/types/furni";
|
||||
import { reserveFurnitureId } from "./furniture-id-reservation";
|
||||
|
||||
// Re-export the download helpers now owned by the shared import core.
|
||||
// Existing furni callers keep importing them from here.
|
||||
@@ -563,8 +564,8 @@ export async function importSingleFurni(params: {
|
||||
error: `Item "${classname}" already exists with id ${existsByName.id} — cannot reassign to spriteId ${originalId}`,
|
||||
};
|
||||
}
|
||||
const itemId = repairExisting && existsByName ? existsByName.id : originalId;
|
||||
const spriteId =
|
||||
let itemId = repairExisting && existsByName ? existsByName.id : originalId;
|
||||
let spriteId =
|
||||
repairExisting && existsByName ? existsByName.spriteId : originalId;
|
||||
const preservingExisting = !!(repairExisting && existsByName);
|
||||
const [existsById] = await db
|
||||
@@ -572,7 +573,7 @@ export async function importSingleFurni(params: {
|
||||
.from(ItemsBase)
|
||||
.where(eq(ItemsBase.id, itemId))
|
||||
.limit(1);
|
||||
if (existsById && (!existsByName || existsById.itemName !== classname)) {
|
||||
if (existsByName && existsById && existsById.itemName !== classname) {
|
||||
// The spriteId is owned by a different classname. Even with
|
||||
// updateExisting this is a genuine conflict, not an update.
|
||||
return {
|
||||
@@ -586,7 +587,7 @@ export async function importSingleFurni(params: {
|
||||
|
||||
// ── Check if spriteId already used in FurnitureData.json ──
|
||||
const takenBy = await findFurniDataIdConflict(spriteId, classname);
|
||||
if (takenBy) {
|
||||
if (takenBy && isUpdate) {
|
||||
return {
|
||||
ok: false,
|
||||
warnings,
|
||||
@@ -634,10 +635,20 @@ export async function importSingleFurni(params: {
|
||||
WHERE id = ${spriteId}
|
||||
`);
|
||||
} else {
|
||||
await db.execute(sql`
|
||||
INSERT INTO items_base (id, sprite_id, public_name, item_name, type)
|
||||
VALUES (${spriteId}, ${spriteId}, ${bestName}, ${classname}, ${itemType})
|
||||
`);
|
||||
itemId = await reserveFurnitureId(
|
||||
originalId,
|
||||
classname,
|
||||
async (allocatedId) => {
|
||||
await db.execute(
|
||||
sql`INSERT INTO items_base (id, sprite_id, public_name, item_name, type) VALUES (${allocatedId}, ${allocatedId}, ${bestName}, ${classname}, ${itemType})`,
|
||||
);
|
||||
},
|
||||
);
|
||||
spriteId = itemId;
|
||||
if (spriteId !== originalId)
|
||||
warnings.push(
|
||||
`Source ID ${originalId} is occupied; imported with local ID ${spriteId}`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user