From 65387ccdea36c6c235fa5f7fd01a860fd58853d3 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sat, 7 Jun 2025 02:17:27 -0700 Subject: [PATCH] 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> --- .../custom/getItemListsController.ts | 7 +++-- static/webui/script.js | 28 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/controllers/custom/getItemListsController.ts b/src/controllers/custom/getItemListsController.ts index 716104a5..4f03ee94 100644 --- a/src/controllers/custom/getItemListsController.ts +++ b/src/controllers/custom/getItemListsController.ts @@ -25,6 +25,7 @@ import allIncarnons from "@/static/fixed_responses/allIncarnonList.json"; interface ListedItem { uniqueName: string; name: string; + subtype?: string; fusionLimit?: number; exalted?: string[]; badReason?: "starter" | "frivolous" | "notraw"; @@ -175,7 +176,8 @@ const getItemListsController: RequestHandler = (req, response) => { ) { res.miscitems.push({ uniqueName: uniqueName, - name: name + name: name, + subtype: "Resource" }); } } @@ -193,7 +195,8 @@ const getItemListsController: RequestHandler = (req, response) => { for (const [uniqueName, item] of Object.entries(ExportGear)) { res.miscitems.push({ uniqueName: uniqueName, - name: getString(item.name, lang) + name: getString(item.name, lang), + subtype: "Gear" }); } const recipeNameTemplate = getString("/Lotus/Language/Items/BlueprintAndItem", lang); diff --git a/static/webui/script.js b/static/webui/script.js index 718dc840..f4abcb9f 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -312,7 +312,7 @@ function fetchItemList() { document.getElementById("changeSyndicate").appendChild(option); }); } else { - const nameSet = new Set(); + const nameToItems = {}; items.forEach(item => { item.name = item.name.replace(/<.+>/g, "").trim(); if ("badReason" in item) { @@ -322,6 +322,11 @@ function fetchItemList() { item.name += " " + loc("code_badItem"); } } + nameToItems[item.name] ??= []; + nameToItems[item.name].push(item); + }); + + items.forEach(item => { if (type == "ModularParts") { const supportedModularParts = [ "LWPT_HB_DECK", @@ -360,15 +365,26 @@ function fetchItemList() { .appendChild(option); } } else if (item.badReason != "notraw") { - if (nameSet.has(item.name)) { - //console.log(`Not adding ${item.uniqueName} to datalist for ${type} due to duplicate display name: ${item.name}`); - } else { - nameSet.add(item.name); - + const ambiguous = nameToItems[item.name].length > 1; + let canDisambiguate = true; + if (ambiguous) { + for (const i2 of nameToItems[item.name]) { + if (!i2.subtype) { + canDisambiguate = false; + break; + } + } + } + if (!ambiguous || canDisambiguate || nameToItems[item.name][0] == item) { const option = document.createElement("option"); option.setAttribute("data-key", item.uniqueName); option.value = item.name; + if (ambiguous && canDisambiguate) { + option.value += " (" + item.subtype + ")"; + } document.getElementById("datalist-" + type).appendChild(option); + } else { + //console.log(`Not adding ${item.uniqueName} to datalist for ${type} due to duplicate display name: ${item.name}`); } } itemMap[item.uniqueName] = { ...item, type };