forked from OpenWF/SpaceNinjaServer
feat(webui): disambiguate gear and resource with the same name for add items (#2127)
Closes #2097 Reviewed-on: OpenWF/SpaceNinjaServer#2127 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
4118528603
commit
65387ccdea
@ -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);
|
||||
|
@ -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 };
|
||||
|
Loading…
x
Reference in New Issue
Block a user