Recognize imported furniture by normalized classname and local IDs
This commit is contained in:
1 parent
9dc6b8a261
commit
a78d8256e0
7 files changed
+254
-46
No files matched your search
@@ -2,6 +2,7 @@ import { promises as fs } from "node:fs";
|
||||
import { eq, inArray, sql } from "drizzle-orm";
|
||||
import { db, ItemsBase } from "@/lib/db";
|
||||
import { autoDetectInteraction } from "@/lib/furni/auto-interaction";
|
||||
import { normalizeClassname } from "@/lib/furni/classname";
|
||||
import { HABBO_GAMEDATA_HOTEL_SETTING_KEY } from "@/lib/habbo-gamedata-hotel";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { extractFurniIconPng } from "@/lib/services/clone-icon";
|
||||
@@ -510,21 +511,24 @@ export async function getCloneList(params: {
|
||||
.select({ itemName: ItemsBase.itemName })
|
||||
.from(ItemsBase)
|
||||
.where(inArray(ItemsBase.itemName, allNames));
|
||||
for (const r of rows) present.add(r.itemName);
|
||||
for (const r of rows) present.add(normalizeClassname(r.itemName));
|
||||
}
|
||||
|
||||
const filtered =
|
||||
filter === "missing"
|
||||
? searched.filter((e) => !present.has(e.classname))
|
||||
? searched.filter((e) => !present.has(normalizeClassname(e.classname)))
|
||||
: filter === "present"
|
||||
? searched.filter((e) => present.has(e.classname))
|
||||
? searched.filter((e) => present.has(normalizeClassname(e.classname)))
|
||||
: searched;
|
||||
|
||||
const total = filtered.length;
|
||||
const start = (Math.max(page, 1) - 1) * perPage;
|
||||
const slice = filtered.slice(start, start + perPage);
|
||||
return {
|
||||
items: slice.map((e) => ({ ...e, present: present.has(e.classname) })),
|
||||
items: slice.map((e) => ({
|
||||
...e,
|
||||
present: present.has(normalizeClassname(e.classname)),
|
||||
})),
|
||||
meta: { page: Math.max(page, 1), perPage, total },
|
||||
};
|
||||
}
|
||||
@@ -540,9 +544,11 @@ export async function getCloneStats(
|
||||
.select({ itemName: ItemsBase.itemName })
|
||||
.from(ItemsBase)
|
||||
.where(inArray(ItemsBase.itemName, classnames));
|
||||
for (const r of rows) have.add(r.itemName);
|
||||
for (const r of rows) have.add(normalizeClassname(r.itemName));
|
||||
}
|
||||
const present = all.filter((e) => have.has(e.classname)).length;
|
||||
const present = all.filter((e) =>
|
||||
have.has(normalizeClassname(e.classname)),
|
||||
).length;
|
||||
return { total: all.length, present, clonable: all.length - present };
|
||||
}
|
||||
|
||||
@@ -561,7 +567,9 @@ export async function getClonableClassnames(
|
||||
.select({ itemName: ItemsBase.itemName })
|
||||
.from(ItemsBase)
|
||||
.where(inArray(ItemsBase.itemName, classnames));
|
||||
for (const r of rows) have.add(r.itemName);
|
||||
for (const r of rows) have.add(normalizeClassname(r.itemName));
|
||||
}
|
||||
return all.filter((e) => !have.has(e.classname)).map((e) => e.classname);
|
||||
return all
|
||||
.filter((e) => !have.has(normalizeClassname(e.classname)))
|
||||
.map((e) => e.classname);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { normalizeClassname } from "@/lib/furni/classname";
|
||||
/**
|
||||
* Furniture search & listing — powered by official Habbo furnidata.
|
||||
*
|
||||
@@ -37,7 +38,9 @@ export async function listFurniture(
|
||||
const perPage = Math.min(options.perPage || 50, 100);
|
||||
const page = options.page || 1;
|
||||
const search = options.search?.toLowerCase().trim() || "";
|
||||
const importedSet = options.importedSet;
|
||||
const importedSet = options.importedSet
|
||||
? new Set([...options.importedSet].map(normalizeClassname))
|
||||
: undefined;
|
||||
|
||||
try {
|
||||
const map = await getOfficialHabboFurnidata();
|
||||
@@ -58,8 +61,8 @@ export async function listFurniture(
|
||||
if (importedSet) {
|
||||
// Non-imported first (id desc), then imported (id desc).
|
||||
items.sort((a, b) => {
|
||||
const aImp = importedSet.has(a.classname) ? 1 : 0;
|
||||
const bImp = importedSet.has(b.classname) ? 1 : 0;
|
||||
const aImp = importedSet.has(normalizeClassname(a.classname)) ? 1 : 0;
|
||||
const bImp = importedSet.has(normalizeClassname(b.classname)) ? 1 : 0;
|
||||
if (aImp !== bImp) return aImp - bImp;
|
||||
return b.id - a.id;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user