XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

chore(webui): improve item disambiguation (#3373)

Closes #3368 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3373 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

f4916094
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

2 个文件 +39 -25
Modified src/controllers/custom/getItemListsController.ts +6 -4
@@ -156,10 +156,12 @@ const getItemListsController: RequestHandler = (req, response) => {
156 156 maxLevelCap: item.maxLevelCap
157 157 });
158 158 item.abilities.forEach(ability => {
159 res.Abilities.push({
160 uniqueName: ability.uniqueName,
161 name: getString(ability.name || uniqueName, lang)
162 });
159 if (!res.Abilities.some(x => x.uniqueName == ability.uniqueName)) {
160 res.Abilities.push({
161 uniqueName: ability.uniqueName,
162 name: getString(ability.name || uniqueName, lang)
163 });
164 }
163 165 });
164 166 }
165 167 for (const [uniqueName, item] of Object.entries(ExportSentinels)) {
Modified static/webui/script.js +33 -21
@@ -329,6 +329,22 @@ const permanentEvolutionWeapons = new Set([
329 329 "/Lotus/Weapons/Tenno/Zariman/Melee/HeavyScythe/ZarimanHeavyScythe/ZarimanHeavyScytheWeapon"
330 330 ]);
331 331
332 const itemToString = item => item.name;
333 const itemToStringWithSubtype = item => (item.subtype ? item.name + " (" + item.subtype + ")" : item.name);
334 const itemToStringWithUniqueName = item => item.name + " [" + item.uniqueName.split("/").pop() + "]";
335
336 const areItemsUnambiguous = (items, stringifier) => {
337 const set = new Set();
338 for (const item of items) {
339 const str = stringifier(item);
340 if (set.has(str)) {
341 return false;
342 }
343 set.add(str);
344 }
345 return true;
346 };
347
332 348 function fetchItemList() {
333 349 window.itemListPromise = new Promise(resolve => {
334 350 const req = $.get("/custom/getItemLists?lang=" + window.lang);
@@ -717,30 +733,26 @@ function fetchItemList() {
717 733 .appendChild(option);
718 734 }
719 735 } else if (item.badReason != "notraw") {
720 const ambiguous = nameToItems[item.name].length > 1;
721 let canDisambiguate = true;
722 if (ambiguous) {
723 for (const i2 of nameToItems[item.name]) {
724 if (!i2.subtype) {
725 canDisambiguate = false;
726 break;
736 let stringifier = itemToString;
737 if (nameToItems[item.name].length > 1) {
738 stringifier = itemToStringWithSubtype;
739 if (!areItemsUnambiguous(nameToItems[item.name], stringifier)) {
740 stringifier = itemToStringWithUniqueName;
741 if (!areItemsUnambiguous(nameToItems[item.name], stringifier)) {
742 console.log(
743 `Not adding ${item.uniqueName} to datalist for ${type} due to ambiguous display name: ${item.name}`
744 );
745 return;
727 746 }
728 747 }
729 748 }
730 if (!ambiguous || canDisambiguate || nameToItems[item.name][0] == item) {
731 const option = document.createElement("option");
732 option.setAttribute("data-key", item.uniqueName);
733 option.value = item.name;
734 if (ambiguous && canDisambiguate) {
735 option.value += " (" + item.subtype + ")";
736 }
737 document.getElementById("datalist-" + type).appendChild(option);
738 if (item.eligibleForVault) {
739 const vaultOption = option.cloneNode(true);
740 document.getElementById("datalist-VaultMiscItems").appendChild(vaultOption);
741 }
742 } else {
743 //console.log(`Not adding ${item.uniqueName} to datalist for ${type} due to duplicate display name: ${item.name}`);
749 const option = document.createElement("option");
750 option.setAttribute("data-key", item.uniqueName);
751 option.value = stringifier(item);
752 document.getElementById("datalist-" + type).appendChild(option);
753 if (item.eligibleForVault) {
754 const vaultOption = option.cloneNode(true);
755 document.getElementById("datalist-VaultMiscItems").appendChild(vaultOption);
744 756 }
745 757 }
746 758 itemMap[item.uniqueName] = { ...item, type };