feat(webui): add item by ItemType
Some checks failed
Build / build (pull_request) Failing after 1m5s

This commit is contained in:
AMelonInsideLemon 2025-08-27 04:47:59 +02:00
parent 9d034824f7
commit d8a389fa7f
10 changed files with 117 additions and 10 deletions

View File

@ -689,6 +689,7 @@ export const addItem = async (
// Path-based duck typing // Path-based duck typing
switch (typeName.substr(1).split("/")[1]) { switch (typeName.substr(1).split("/")[1]) {
case "Powersuits": case "Powersuits":
if (typeName.endsWith("AugmentCard")) break;
switch (typeName.substr(1).split("/")[2]) { switch (typeName.substr(1).split("/")[2]) {
default: { default: {
return { return {
@ -773,6 +774,10 @@ export const addItem = async (
} }
} }
break; break;
case "Skins": {
return addSkin(inventory, typeName);
}
} }
break; break;
} }
@ -869,6 +874,25 @@ export const addItem = async (
break; break;
} }
break; break;
case "Weapons":
if (typeName.substr(1).split("/")[4] == "MeleeTrees") break;
let productCategory = typeName.substr(1).split("/")[3];
switch (productCategory) {
case "Pistols":
case "LongGuns":
case "Melee": {
const inventoryChanges = addEquipment(inventory, productCategory, typeName);
return {
...inventoryChanges,
...occupySlot(
inventory,
productCategoryToInventoryBin(productCategory) ?? InventorySlot.WEAPONS,
premiumPurchase
)
};
}
}
break;
} }
throw new Error(`unable to add item: ${typeName}`); throw new Error(`unable to add item: ${typeName}`);
}; };

View File

@ -93,11 +93,34 @@
<p class="mb-3" data-loc="general_inventoryUpdateNote"></p> <p class="mb-3" data-loc="general_inventoryUpdateNote"></p>
<div class="card mb-3"> <div class="card mb-3">
<h5 class="card-header" data-loc="inventory_addItems"></h5> <h5 class="card-header" data-loc="inventory_addItems"></h5>
<form class="card-body input-group" onsubmit="doAcquireMiscItems();return false;"> <div class="card-body">
<input class="form-control" id="miscitem-count" type="number" value="1" /> <ul class="nav nav-tabs" id="addItemsTab">
<input class="form-control w-50" id="miscitem-type" list="datalist-miscitems" /> <li class="nav-item" role="presentation">
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button> <button class="nav-link" id="miscItems-tab" data-bs-toggle="tab" data-bs-target="#miscItems" data-loc="addMiscItems_label"></button>
</form> </li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="typeName-tab" data-bs-toggle="tab" data-bs-target="#typeName" data-loc="addItemByItemType_label"></button>
</li>
</ul>
<div class="tab-content" id="addItemsTabContent">
<div class="tab-pane" id="miscItems">
<form class="card-body input-group" onsubmit="doAcquireMiscItems();return false;">
<input class="form-control" id="miscitem-count" type="number" value="1" />
<input class="form-control w-50" id="miscitem-type" list="datalist-miscitems" />
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
</form>
</div>
<div class="tab-pane" id="typeName">
<form class="card-body" onsubmit="addItemByItemType();return false;">
<p data-loc="addItemByItemType_warning"></p>
<div class="input-group">
<input class="form-control" id="itemType-type" />
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
</div>
</form>
</div>
</div>
</div>
</div> </div>
<div class="row g-3 mb-3"> <div class="row g-3 mb-3">
<div class="col-md-3"> <div class="col-md-3">

View File

@ -649,6 +649,14 @@ function updateInventory() {
]; ];
// Populate inventory route // Populate inventory route
document.getElementById("typeName-tab").classList.remove("active");
document.getElementById("typeName").classList.remove("active", "show");
document.getElementById("itemType-type").value = "";
document.getElementById("miscItems-tab").classList.add("active");
document.getElementById("miscItems").classList.add("active", "show");
["RegularCredits", "PremiumCredits", "FusionPoints", "PrimeTokens"].forEach(currency => { ["RegularCredits", "PremiumCredits", "FusionPoints", "PrimeTokens"].forEach(currency => {
document.getElementById(currency + "-owned").textContent = loc("currency_owned") document.getElementById(currency + "-owned").textContent = loc("currency_owned")
.split("|COUNT|") .split("|COUNT|")
@ -1685,7 +1693,7 @@ function doAcquireEvolution() {
setEvolutionProgress([{ ItemType: uniqueName, Rank: permanentEvolutionWeapons.has(uniqueName) ? 0 : 1 }]); setEvolutionProgress([{ ItemType: uniqueName, Rank: permanentEvolutionWeapons.has(uniqueName) ? 0 : 1 }]);
} }
$(document).on("input", "input[list]", function () { $(document).on("input", "input", function () {
$(this).removeClass("is-invalid"); $(this).removeClass("is-invalid");
}); });
@ -2008,6 +2016,34 @@ function doAcquireMiscItems() {
} }
} }
function addItemByItemType() {
const ItemType = document.getElementById("itemType-type").value;
if (!ItemType || !/^[A-Za-z/]+$/.test(ItemType) || !ItemType.startsWith("/Lotus/")) {
$("#itemType-type").addClass("is-invalid").focus();
return;
}
revalidateAuthz().then(() => {
$.post({
url: "/custom/addItems?" + window.authz,
contentType: "application/json",
data: JSON.stringify([
{
ItemType,
ItemCount: 1
}
])
})
.done(function (_, _, jqXHR) {
if (jqXHR.status === 200) {
updateInventory();
}
})
.fail(function () {
$("#itemType-type").addClass("is-invalid").focus();
});
});
}
function doAcquireRiven() { function doAcquireRiven() {
let fingerprint; let fingerprint;
try { try {
@ -2070,10 +2106,6 @@ function doAcquireRiven() {
}); });
} }
$("#addriven-fingerprint").on("input", () => {
$("#addriven-fingerprint").removeClass("is-invalid");
});
function setFingerprint(ItemType, ItemId, fingerprint) { function setFingerprint(ItemType, ItemId, fingerprint) {
revalidateAuthz().then(() => { revalidateAuthz().then(() => {
$.post({ $.post({

View File

@ -382,5 +382,9 @@ dict = {
theme_dark: `Dunkles Design`, theme_dark: `Dunkles Design`,
theme_light: `Helles Design`, theme_light: `Helles Design`,
addMiscItems_label: `[UNTRANSLATED] Add by Name`,
addItemByItemType_label: `[UNTRANSLATED] Add By ItemType`,
addItemByItemType_warning: `[UNTRANSLATED] Use this feature at your own risk. It may break your inventory, and you will need to remove items manually if something goes wrong.`,
prettier_sucks_ass: `` prettier_sucks_ass: ``
}; };

View File

@ -381,5 +381,9 @@ dict = {
theme_dark: `Dark Theme`, theme_dark: `Dark Theme`,
theme_light: `Light Theme`, theme_light: `Light Theme`,
addMiscItems_label: `Add by Name`,
addItemByItemType_label: `Add By ItemType`,
addItemByItemType_warning: `Use this feature at your own risk. It may break your inventory, and you will need to remove items manually if something goes wrong.`,
prettier_sucks_ass: `` prettier_sucks_ass: ``
}; };

View File

@ -382,5 +382,9 @@ dict = {
theme_dark: `Tema Oscuro`, theme_dark: `Tema Oscuro`,
theme_light: `Tema Claro`, theme_light: `Tema Claro`,
addMiscItems_label: `[UNTRANSLATED] Add by Name`,
addItemByItemType_label: `[UNTRANSLATED] Add By ItemType`,
addItemByItemType_warning: `[UNTRANSLATED] Use this feature at your own risk. It may break your inventory, and you will need to remove items manually if something goes wrong.`,
prettier_sucks_ass: `` prettier_sucks_ass: ``
}; };

View File

@ -382,5 +382,9 @@ dict = {
theme_dark: `Thème sombre`, theme_dark: `Thème sombre`,
theme_light: `Thème clair`, theme_light: `Thème clair`,
addMiscItems_label: `[UNTRANSLATED] Add by Name`,
addItemByItemType_label: `[UNTRANSLATED] Add By ItemType`,
addItemByItemType_warning: `[UNTRANSLATED] Use this feature at your own risk. It may break your inventory, and you will need to remove items manually if something goes wrong.`,
prettier_sucks_ass: `` prettier_sucks_ass: ``
}; };

View File

@ -382,5 +382,9 @@ dict = {
theme_dark: `Темная тема`, theme_dark: `Темная тема`,
theme_light: `Светлая тема`, theme_light: `Светлая тема`,
addMiscItems_label: `По имени`,
addItemByItemType_label: `По ItemType`,
addItemByItemType_warning: `Используйте эту функцию на свой страх и риск. Она может повредить ваш инвентарь, и в случае проблем вам придётся удалять предметы вручную.`,
prettier_sucks_ass: `` prettier_sucks_ass: ``
}; };

View File

@ -382,5 +382,9 @@ dict = {
theme_dark: `Темна тема`, theme_dark: `Темна тема`,
theme_light: `Світла тема`, theme_light: `Світла тема`,
addMiscItems_label: `[UNTRANSLATED] Add by Name`,
addItemByItemType_label: `[UNTRANSLATED] Add By ItemType`,
addItemByItemType_warning: `[UNTRANSLATED] Use this feature at your own risk. It may break your inventory, and you will need to remove items manually if something goes wrong.`,
prettier_sucks_ass: `` prettier_sucks_ass: ``
}; };

View File

@ -382,5 +382,9 @@ dict = {
theme_dark: `暗色主题`, theme_dark: `暗色主题`,
theme_light: `亮色主题`, theme_light: `亮色主题`,
addMiscItems_label: `[UNTRANSLATED] Add by Name`,
addItemByItemType_label: `[UNTRANSLATED] Add By ItemType`,
addItemByItemType_warning: `[UNTRANSLATED] Use this feature at your own risk. It may break your inventory, and you will need to remove items manually if something goes wrong.`,
prettier_sucks_ass: `` prettier_sucks_ass: ``
}; };