feat(webui): disambiguate gear and resource with the same name for add items
This commit is contained in:
		
							parent
							
								
									0997f9567f
								
							
						
					
					
						commit
						a57b27e4c9
					
				@ -25,6 +25,7 @@ import allIncarnons from "@/static/fixed_responses/allIncarnonList.json";
 | 
				
			|||||||
interface ListedItem {
 | 
					interface ListedItem {
 | 
				
			||||||
    uniqueName: string;
 | 
					    uniqueName: string;
 | 
				
			||||||
    name: string;
 | 
					    name: string;
 | 
				
			||||||
 | 
					    subtype?: string;
 | 
				
			||||||
    fusionLimit?: number;
 | 
					    fusionLimit?: number;
 | 
				
			||||||
    exalted?: string[];
 | 
					    exalted?: string[];
 | 
				
			||||||
    badReason?: "starter" | "frivolous" | "notraw";
 | 
					    badReason?: "starter" | "frivolous" | "notraw";
 | 
				
			||||||
@ -175,7 +176,8 @@ const getItemListsController: RequestHandler = (req, response) => {
 | 
				
			|||||||
        ) {
 | 
					        ) {
 | 
				
			||||||
            res.miscitems.push({
 | 
					            res.miscitems.push({
 | 
				
			||||||
                uniqueName: uniqueName,
 | 
					                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)) {
 | 
					    for (const [uniqueName, item] of Object.entries(ExportGear)) {
 | 
				
			||||||
        res.miscitems.push({
 | 
					        res.miscitems.push({
 | 
				
			||||||
            uniqueName: uniqueName,
 | 
					            uniqueName: uniqueName,
 | 
				
			||||||
            name: getString(item.name, lang)
 | 
					            name: getString(item.name, lang),
 | 
				
			||||||
 | 
					            subtype: "Gear"
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const recipeNameTemplate = getString("/Lotus/Language/Items/BlueprintAndItem", lang);
 | 
					    const recipeNameTemplate = getString("/Lotus/Language/Items/BlueprintAndItem", lang);
 | 
				
			||||||
 | 
				
			|||||||
@ -312,7 +312,7 @@ function fetchItemList() {
 | 
				
			|||||||
                        document.getElementById("changeSyndicate").appendChild(option);
 | 
					                        document.getElementById("changeSyndicate").appendChild(option);
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    const nameSet = new Set();
 | 
					                    const nameToItems = {};
 | 
				
			||||||
                    items.forEach(item => {
 | 
					                    items.forEach(item => {
 | 
				
			||||||
                        item.name = item.name.replace(/<.+>/g, "").trim();
 | 
					                        item.name = item.name.replace(/<.+>/g, "").trim();
 | 
				
			||||||
                        if ("badReason" in item) {
 | 
					                        if ("badReason" in item) {
 | 
				
			||||||
@ -322,6 +322,11 @@ function fetchItemList() {
 | 
				
			|||||||
                                item.name += " " + loc("code_badItem");
 | 
					                                item.name += " " + loc("code_badItem");
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					                        nameToItems[item.name] ??= [];
 | 
				
			||||||
 | 
					                        nameToItems[item.name].push(item);
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    items.forEach(item => {
 | 
				
			||||||
                        if (type == "ModularParts") {
 | 
					                        if (type == "ModularParts") {
 | 
				
			||||||
                            const supportedModularParts = [
 | 
					                            const supportedModularParts = [
 | 
				
			||||||
                                "LWPT_HB_DECK",
 | 
					                                "LWPT_HB_DECK",
 | 
				
			||||||
@ -360,15 +365,26 @@ function fetchItemList() {
 | 
				
			|||||||
                                    .appendChild(option);
 | 
					                                    .appendChild(option);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        } else if (item.badReason != "notraw") {
 | 
					                        } else if (item.badReason != "notraw") {
 | 
				
			||||||
                            if (nameSet.has(item.name)) {
 | 
					                            let ambiguous = (nameToItems[item.name].length > 1);
 | 
				
			||||||
                                //console.log(`Not adding ${item.uniqueName} to datalist for ${type} due to duplicate display name: ${item.name}`);
 | 
					                            let canDisambiguate = true;
 | 
				
			||||||
                            } else {
 | 
					                            if (ambiguous) {
 | 
				
			||||||
                                nameSet.add(item.name);
 | 
					                                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");
 | 
					                                const option = document.createElement("option");
 | 
				
			||||||
                                option.setAttribute("data-key", item.uniqueName);
 | 
					                                option.setAttribute("data-key", item.uniqueName);
 | 
				
			||||||
                                option.value = item.name;
 | 
					                                option.value = item.name;
 | 
				
			||||||
 | 
					                                if (ambiguous && canDisambiguate) {
 | 
				
			||||||
 | 
					                                    option.value += " (" + item.subtype + ")";
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
                                document.getElementById("datalist-" + type).appendChild(option);
 | 
					                                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 };
 | 
					                        itemMap[item.uniqueName] = { ...item, type };
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user