chore(webui): split weapons by category #820

Merged
Sainan merged 2 commits from webui-split-weapons into main 2025-01-19 03:29:32 -08:00
3 changed files with 83 additions and 58 deletions

View File

@ -17,25 +17,32 @@ interface ListedItem {
fusionLimit?: number;
}
const getItemListsController: RequestHandler = (req, res) => {
const getItemListsController: RequestHandler = (req, response) => {
const lang = getDict(typeof req.query.lang == "string" ? req.query.lang : "en");
const weapons = [];
const miscitems = [];
const res: Record<string, ListedItem[]> = {};
res.LongGuns = [];
res.Pistols = [];
res.Melee = [];
res.miscitems = [];
for (const [uniqueName, item] of Object.entries(ExportWeapons)) {
if (item.productCategory !== "OperatorAmps") {
if (item.totalDamage !== 0) {
weapons.push({
if (
item.productCategory == "LongGuns" ||
item.productCategory == "Pistols" ||
item.productCategory == "Melee"
) {
res[item.productCategory].push({
uniqueName,
name: getString(item.name, lang)
});
}
} else if (!item.excludeFromCodex) {
miscitems.push({
res.miscitems.push({
uniqueName: "MiscItems:" + uniqueName,
name: getString(item.name, lang)
});
}
}
}
for (const [uniqueName, item] of Object.entries(ExportResources)) {
let name = getString(item.name, lang);
if ("dissectionParts" in item) {
@ -48,13 +55,13 @@ const getItemListsController: RequestHandler = (req, res) => {
name = name.split("|FISH_SIZE|").join(getString("/Lotus/Language/Fish/FishSizeSmallAbbrev", lang));
}
}
miscitems.push({
res.miscitems.push({
uniqueName: item.productCategory + ":" + uniqueName,
name: name
});
}
for (const [uniqueName, item] of Object.entries(ExportGear)) {
miscitems.push({
res.miscitems.push({
uniqueName: "Consumables:" + uniqueName,
name: getString(item.name, lang)
});
@ -64,7 +71,7 @@ const getItemListsController: RequestHandler = (req, res) => {
if (!item.hidden) {
const resultName = getItemName(item.resultType);
if (resultName) {
miscitems.push({
res.miscitems.push({
uniqueName: "Recipes:" + uniqueName,
name: recipeNameTemplate.replace("|ITEM|", getString(resultName, lang))
});
@ -72,10 +79,10 @@ const getItemListsController: RequestHandler = (req, res) => {
}
}
const mods: ListedItem[] = [];
res.mods = [];
const badItems: Record<string, boolean> = {};
for (const [uniqueName, upgrade] of Object.entries(ExportUpgrades)) {
mods.push({
res.mods.push({
uniqueName,
name: getString(upgrade.name, lang),
fusionLimit: upgrade.fusionLimit
@ -85,7 +92,7 @@ const getItemListsController: RequestHandler = (req, res) => {
}
}
for (const [uniqueName, arcane] of Object.entries(ExportArcanes)) {
mods.push({
res.mods.push({
uniqueName,
name: getString(arcane.name, lang)
});
@ -94,7 +101,7 @@ const getItemListsController: RequestHandler = (req, res) => {
}
}
res.json({
response.json({
warframes: Object.entries(ExportWarframes)
.filter(([_uniqueName, warframe]) => warframe.productCategory == "Suits")
.map(([uniqueName, warframe]) => {
@ -104,11 +111,9 @@ const getItemListsController: RequestHandler = (req, res) => {
exalted: warframe.exalted
};
}),
weapons,
miscitems,
mods,
badItems,
archonCrystalUpgrades
archonCrystalUpgrades,
...res
});
};

View File

@ -96,7 +96,7 @@
</div>
<div class="row g-3">
<div class="col-lg-6">
<div class="card mb-3" style="height: 480px;">
<div class="card mb-3" style="height: 400px;">
<h5 class="card-header">Warframes</h5>
<div class="card-body overflow-auto">
<form class="input-group mb-3" onsubmit="doAcquireWarframe();return false;">
@ -110,15 +110,45 @@
</div>
</div>
<div class="col-lg-6">
<div class="card mb-3" style="height: 480px;">
<h5 class="card-header">Weapons</h5>
<div class="card mb-3" style="height: 400px;">
<h5 class="card-header">Primary Weapons</h5>
<div class="card-body overflow-auto">
<form class="input-group mb-3" onsubmit="doAcquireWeapon();return false;">
<input class="form-control" id="weapon-to-acquire" list="datalist-weapons" />
<form class="input-group mb-3" onsubmit="doAcquireWeapon('LongGuns');return false;">
<input class="form-control" id="acquire-type-LongGuns" list="datalist-LongGuns" />
<button class="btn btn-primary" type="submit">Add</button>
</form>
<table class="table table-hover w-100">
<tbody id="weapon-list"></tbody>
<tbody id="LongGuns-list"></tbody>
</table>
</div>
</div>
</div>
</div>
<div class="row g-3">
<div class="col-lg-6">
<div class="card mb-3" style="height: 400px;">
<h5 class="card-header">Secondary Weapons</h5>
<div class="card-body overflow-auto">
<form class="input-group mb-3" onsubmit="doAcquireWeapon('Pistols');return false;">
<input class="form-control" id="acquire-type-Pistols" list="datalist-Pistols" />
<button class="btn btn-primary" type="submit">Add</button>
</form>
<table class="table table-hover w-100">
<tbody id="Pistols-list"></tbody>
</table>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="card mb-3" style="height: 400px;">
<h5 class="card-header">Melee Weapons</h5>
<div class="card-body overflow-auto">
<form class="input-group mb-3" onsubmit="doAcquireWeapon('Melee');return false;">
<input class="form-control" id="acquire-type-Melee" list="datalist-Melee" />
<button class="btn btn-primary" type="submit">Add</button>
</form>
<table class="table table-hover w-100">
<tbody id="Melee-list"></tbody>
</table>
</div>
</div>
@ -355,7 +385,9 @@
</div>
</div>
<datalist id="datalist-warframes"></datalist>
<datalist id="datalist-weapons"></datalist>
<datalist id="datalist-LongGuns"></datalist>
<datalist id="datalist-Pistols"></datalist>
<datalist id="datalist-Melee"></datalist>
<datalist id="datalist-miscitems"></datalist>
<datalist id="datalist-mods">
<option data-key="/Lotus/Upgrades/Mods/Fusers/LegendaryModFuser" value="Legendary Core"></option>

View File

@ -265,8 +265,8 @@ function updateInventory() {
}
document.getElementById("warframe-list").appendChild(tr);
});
document.getElementById("weapon-list").innerHTML = "";
["LongGuns", "Pistols", "Melee"].forEach(category => {
document.getElementById(category + "-list").innerHTML = "";
data[category].forEach(item => {
const tr = document.createElement("tr");
tr.setAttribute("data-item-type", item.ItemType);
@ -319,7 +319,7 @@ function updateInventory() {
}
tr.appendChild(td);
}
document.getElementById("weapon-list").appendChild(tr);
document.getElementById(category + "-list").appendChild(tr);
});
});
@ -546,14 +546,16 @@ function doAcquireWarframe() {
});
}
$("#warframe-to-acquire").on("input", () => {
$("#warframe-to-acquire").removeClass("is-invalid");
$("input[list]").on("input", function () {
$(this).removeClass("is-invalid");
});
function doAcquireWeapon() {
const uniqueName = getKey(document.getElementById("weapon-to-acquire"));
function doAcquireWeapon(category) {
const uniqueName = getKey(document.getElementById("acquire-type-" + category));
if (!uniqueName) {
$("#weapon-to-acquire").addClass("is-invalid").focus();
$("#acquire-type-" + category)
.addClass("is-invalid")
.focus();
return;
}
revalidateAuthz(() => {
@ -568,16 +570,12 @@ function doAcquireWeapon() {
])
});
coderabbitai[bot] commented 2025-01-18 19:05:16 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Declare jQuery dependency.

The '$' variable is undefined. Add a declaration to fix the ESLint error:

+/* global $ */
$("input[list]").on("input", function () {
    $(this).removeClass("is-invalid");
});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

/* global $ */
$("input[list]").on("input", function () {
    $(this).removeClass("is-invalid");
🧰 Tools
🪛 eslint

[error] 549-549: '$' is not defined.

(no-undef)


[error] 550-550: '$' is not defined.

(no-undef)

_:warning: Potential issue_ **Declare jQuery dependency.** The '$' variable is undefined. Add a declaration to fix the ESLint error: ```diff +/* global $ */ $("input[list]").on("input", function () { $(this).removeClass("is-invalid"); }); ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion /* global $ */ $("input[list]").on("input", function () { $(this).removeClass("is-invalid"); ````` </details> <!-- suggestion_end --> <details> <summary>🧰 Tools</summary> <details> <summary>🪛 eslint</summary> [error] 549-549: '$' is not defined. (no-undef) --- [error] 550-550: '$' is not defined. (no-undef) </details> </details> <!-- This is an auto-generated comment by CodeRabbit -->
req.done(() => {
document.getElementById("weapon-to-acquire").value = "";
document.getElementById("acquire-type-" + category).value = "";
updateInventory();
});
});
}
$("#weapon-to-acquire").on("input", () => {
$("#weapon-to-acquire").removeClass("is-invalid");
});
function dispatchAddItemsRequestsBatch(requests) {
revalidateAuthz(() => {
const req = $.post({
@ -648,7 +646,9 @@ function maxRankAllWarframes() {
function addMissingWeapons() {
const requests = [];
document.querySelectorAll("#datalist-weapons option").forEach(elm => {
document
.querySelectorAll("#datalist-LongGuns option, #datalist-Pistols option, #datalist-Melee option")
.forEach(elm => {
if (!document.querySelector("#weapon-list [data-item-type='" + elm.getAttribute("data-key") + "']")) {
requests.push({ type: "Weapon", internalName: elm.getAttribute("data-key") });
}
@ -807,10 +807,6 @@ function doAcquireMiscItems() {
});
}
$("#miscitem-type").on("input", () => {
$("#miscitem-type").removeClass("is-invalid");
});
function doAcquireRiven() {
let fingerprint;
try {
@ -923,10 +919,6 @@ function doAcquireMod() {
});
}
$("#mod-to-acquire").on("input", () => {
$("#mod-to-acquire").removeClass("is-invalid");
});
const uiConfigs = [...$("#server-settings input[id]")].map(x => x.id);
function doChangeSettings() {
@ -1153,10 +1145,6 @@ function doPushArchonCrystalUpgrade() {
});
}
$("[list='datalist-archonCrystalUpgrades']").on("input", () => {
$("[list='datalist-archonCrystalUpgrades']").removeClass("is-invalid");
});
function doPopArchonCrystalUpgrade(type) {
revalidateAuthz(() => {
$.get(