返回提交历史
Modified
src/controllers/custom/getItemListsController.ts
+5
-2
Modified
static/webui/script.js
+22
-6
XFEstudio/XFESpaceNinjaServer
feat(webui): disambiguate gear and resource with the same name for add items (#2127)
Closes #2097 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2127 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
65387ccd
代码差异
2 个文件
+27
-8
@@ -25,6 +25,7 @@ import allIncarnons from "@/static/fixed_responses/allIncarnonList.json";
25
25
interface ListedItem {
26
26
uniqueName: string;
27
27
name: string;
28
subtype?: string;
28
29
fusionLimit?: number;
29
30
exalted?: string[];
30
31
badReason?: "starter" | "frivolous" | "notraw";
@@ -175,7 +176,8 @@ const getItemListsController: RequestHandler = (req, response) => {
175
176
) {
176
177
res.miscitems.push({
177
178
uniqueName: uniqueName,
178
name: name
179
name: name,
180
subtype: "Resource"
179
181
});
180
182
}
181
183
}
@@ -193,7 +195,8 @@ const getItemListsController: RequestHandler = (req, response) => {
193
195
for (const [uniqueName, item] of Object.entries(ExportGear)) {
194
196
res.miscitems.push({
195
197
uniqueName: uniqueName,
196
name: getString(item.name, lang)
198
name: getString(item.name, lang),
199
subtype: "Gear"
197
200
});
198
201
}
199
202
const recipeNameTemplate = getString("/Lotus/Language/Items/BlueprintAndItem", lang);
@@ -312,7 +312,7 @@ function fetchItemList() {
312
312
document.getElementById("changeSyndicate").appendChild(option);
313
313
});
314
314
} else {
315
const nameSet = new Set();
315
const nameToItems = {};
316
316
items.forEach(item => {
317
317
item.name = item.name.replace(/<.+>/g, "").trim();
318
318
if ("badReason" in item) {
@@ -322,6 +322,11 @@ function fetchItemList() {
322
322
item.name += " " + loc("code_badItem");
323
323
}
324
324
}
325
nameToItems[item.name] ??= [];
326
nameToItems[item.name].push(item);
327
});
328
329
items.forEach(item => {
325
330
if (type == "ModularParts") {
326
331
const supportedModularParts = [
327
332
"LWPT_HB_DECK",
@@ -360,15 +365,26 @@ function fetchItemList() {
360
365
.appendChild(option);
361
366
}
362
367
} else if (item.badReason != "notraw") {
363
if (nameSet.has(item.name)) {
364
//console.log(`Not adding ${item.uniqueName} to datalist for ${type} due to duplicate display name: ${item.name}`);
365
} else {
366
nameSet.add(item.name);
367
368
const ambiguous = nameToItems[item.name].length > 1;
369
let canDisambiguate = true;
370
if (ambiguous) {
371
for (const i2 of nameToItems[item.name]) {
372
if (!i2.subtype) {
373
canDisambiguate = false;
374
break;
375
}
376
}
377
}
378
if (!ambiguous || canDisambiguate || nameToItems[item.name][0] == item) {
368
379
const option = document.createElement("option");
369
380
option.setAttribute("data-key", item.uniqueName);
370
381
option.value = item.name;
382
if (ambiguous && canDisambiguate) {
383
option.value += " (" + item.subtype + ")";
384
}
371
385
document.getElementById("datalist-" + type).appendChild(option);
386
} else {
387
//console.log(`Not adding ${item.uniqueName} to datalist for ${type} due to duplicate display name: ${item.name}`);
372
388
}
373
389
}
374
390
itemMap[item.uniqueName] = { ...item, type };