feat(webui): force category to add items (raw)
All checks were successful
Build / build (pull_request) Successful in 1m50s
All checks were successful
Build / build (pull_request) Successful in 1m50s
also closes #2786
This commit is contained in:
parent
60e87543aa
commit
b9009b5102
@ -1,14 +1,91 @@
|
||||
import { getAccountIdForRequest } from "../../services/loginService.ts";
|
||||
import { getInventory, addItem } from "../../services/inventoryService.ts";
|
||||
import {
|
||||
getInventory,
|
||||
addItem,
|
||||
addMiscItem,
|
||||
addMods,
|
||||
addShipDecorations,
|
||||
addPowerSuit,
|
||||
addEquipment,
|
||||
addMechSuit,
|
||||
addSentinel,
|
||||
addSentinelWeapon,
|
||||
addCustomization,
|
||||
addSkin,
|
||||
productCategoryToInventoryBin,
|
||||
occupySlot
|
||||
} from "../../services/inventoryService.ts";
|
||||
import type { RequestHandler } from "express";
|
||||
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
|
||||
import { InventorySlot } from "../../types/inventoryTypes/inventoryTypes.ts";
|
||||
|
||||
export const addItemsController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const requests = req.body as IAddItemRequest[];
|
||||
const inventory = await getInventory(accountId);
|
||||
const productCategory = (req.query.productCategory as string) || "";
|
||||
for (const request of requests) {
|
||||
await addItem(inventory, request.ItemType, request.ItemCount, true, undefined, request.Fingerprint, true);
|
||||
switch (productCategory) {
|
||||
case "MiscItems":
|
||||
addMiscItem(inventory, request.ItemType, request.ItemCount);
|
||||
break;
|
||||
|
||||
case "RawUpgrades":
|
||||
addMods(inventory, [request]);
|
||||
break;
|
||||
|
||||
case "ShipDecorations":
|
||||
addShipDecorations(inventory, [request]);
|
||||
break;
|
||||
|
||||
case "Suits":
|
||||
await addPowerSuit(inventory, request.ItemType);
|
||||
occupySlot(inventory, InventorySlot.SUITS, true);
|
||||
break;
|
||||
|
||||
case "MechSuits":
|
||||
await addMechSuit(inventory, request.ItemType);
|
||||
occupySlot(inventory, InventorySlot.MECHSUITS, true);
|
||||
break;
|
||||
|
||||
case "Sentinels":
|
||||
addSentinel(inventory, request.ItemType, true);
|
||||
break;
|
||||
|
||||
case "SentinelWeapons":
|
||||
addSentinelWeapon(inventory, request.ItemType, true);
|
||||
break;
|
||||
|
||||
case "FlavourItems":
|
||||
addCustomization(inventory, request.ItemType);
|
||||
break;
|
||||
|
||||
case "WeaponSkins":
|
||||
addSkin(inventory, request.ItemType);
|
||||
break;
|
||||
|
||||
case "LongGuns":
|
||||
case "Pistols":
|
||||
case "Melee":
|
||||
case "SpaceSuits":
|
||||
case "SpaceGuns":
|
||||
case "SpaceMelee":
|
||||
addEquipment(inventory, productCategory, request.ItemType);
|
||||
occupySlot(inventory, productCategoryToInventoryBin(productCategory) ?? InventorySlot.WEAPONS, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
await addItem(
|
||||
inventory,
|
||||
request.ItemType,
|
||||
request.ItemCount,
|
||||
true,
|
||||
undefined,
|
||||
request.Fingerprint,
|
||||
true
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
await inventory.save();
|
||||
res.end();
|
||||
|
||||
@ -941,7 +941,7 @@ export const applyDefaultUpgrades = (
|
||||
};
|
||||
|
||||
//TODO: maybe genericMethod for all the add methods, they share a lot of logic
|
||||
const addSentinel = (
|
||||
export const addSentinel = (
|
||||
inventory: TInventoryDatabaseDocument,
|
||||
sentinelName: string,
|
||||
premiumPurchase: boolean,
|
||||
@ -972,11 +972,11 @@ const addSentinel = (
|
||||
return inventoryChanges;
|
||||
};
|
||||
|
||||
const addSentinelWeapon = (
|
||||
export const addSentinelWeapon = (
|
||||
inventory: TInventoryDatabaseDocument,
|
||||
typeName: string,
|
||||
premiumPurchase: boolean,
|
||||
inventoryChanges: IInventoryChanges
|
||||
inventoryChanges: IInventoryChanges = {}
|
||||
): void => {
|
||||
// Sentinel weapons also occupy a slot in the sentinels bin
|
||||
combineInventoryChanges(inventoryChanges, occupySlot(inventory, InventorySlot.SENTINELS, premiumPurchase));
|
||||
|
||||
@ -116,9 +116,31 @@
|
||||
</div>
|
||||
<div class="tab-pane" id="typeName-tab-content">
|
||||
<form class="card-body" onsubmit="addItemByItemType();return false;">
|
||||
<p data-loc="inventory_addItemByItemType_warning"></p>
|
||||
<p>
|
||||
<span data-loc="inventory_addItemByItemType_warning"></span>
|
||||
<span data-loc="inventory_addItemByItemType_productCategory"></span>
|
||||
</p>
|
||||
<div class="input-group">
|
||||
<input class="form-control" id="typeName-type" />
|
||||
<input class="form-control" id="typeName-count" type="number" value="1" disabled />
|
||||
<input class="form-control w-50" id="typeName-type" />
|
||||
<select class="form-control" id="typeName-productCategory" data-default="">
|
||||
<option value="" data-loc="notSpecified"></option>
|
||||
<option value="MiscItems">MiscItems</option>
|
||||
<option value="RawUpgrades">RawUpgrades</option>
|
||||
<option value="ShipDecorations">ShipDecorations</option>
|
||||
<option value="Suits">Suits</option>
|
||||
<option value="LongGuns">LongGuns</option>
|
||||
<option value="Pistols">Pistols</option>
|
||||
<option value="Melee">Melee</option>
|
||||
<option value="SpaceSuits">SpaceSuits</option>
|
||||
<option value="SpaceGuns">SpaceGuns</option>
|
||||
<option value="SpaceMelee">SpaceMelee</option>
|
||||
<option value="MechSuits">MechSuits</option>
|
||||
<option value="Sentinels">Sentinels</option>
|
||||
<option value="SentinelWeapons">SentinelWeapons</option>
|
||||
<option value="FlavourItems">FlavourItems</option>
|
||||
<option value="WeaponSkins">WeaponSkins</option>
|
||||
</select>
|
||||
<button class="btn btn-primary" type="submit" data-loc="general_addButton"></button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -773,6 +773,9 @@ function updateInventory() {
|
||||
document.getElementById("typeName-tab").classList.remove("active");
|
||||
document.getElementById("typeName-tab-content").classList.remove("active", "show");
|
||||
document.getElementById("typeName-type").value = "";
|
||||
document.getElementById("typeName-productCategory").value = "";
|
||||
document.getElementById("typeName-count").value = 1;
|
||||
document.getElementById("typeName-count").disabled = true;
|
||||
|
||||
document.getElementById("miscItems-tab").classList.add("active");
|
||||
document.getElementById("miscItems-tab-content").classList.add("active", "show");
|
||||
@ -2965,27 +2968,48 @@ function removeCountItems(uniqueName, count) {
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById("typeName-productCategory").onchange = function () {
|
||||
const productCategory = document.getElementById("typeName-productCategory").value;
|
||||
const ItemCount = document.getElementById("typeName-count");
|
||||
if (["MiscItems", "RawUpgrades", "ShipDecorations"].includes(productCategory)) {
|
||||
ItemCount.disabled = false;
|
||||
} else {
|
||||
ItemCount.disabled = true;
|
||||
ItemCount.value = 1;
|
||||
}
|
||||
};
|
||||
|
||||
function addItemByItemType() {
|
||||
const ItemType = document.getElementById("typeName-type").value;
|
||||
const productCategory = document.getElementById("typeName-productCategory");
|
||||
const ItemCount = document.getElementById("typeName-count");
|
||||
// Must start with "/Lotus/", contain only letters A–Z, digits 0–9, no "//", and not end with "/"
|
||||
if (!ItemType || !/^\/Lotus\/(?:[A-Za-z0-9]+(?:\/[A-Za-z0-9]+)*)$/.test(ItemType)) {
|
||||
$("#typeName-type").addClass("is-invalid").focus();
|
||||
return;
|
||||
}
|
||||
let url = "/custom/addItems?" + window.authz;
|
||||
|
||||
if (productCategory.value) {
|
||||
url += "&productCategory=" + productCategory.value;
|
||||
}
|
||||
revalidateAuthz().then(() => {
|
||||
$.post({
|
||||
url: "/custom/addItems?" + window.authz,
|
||||
url,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify([
|
||||
{
|
||||
ItemType,
|
||||
ItemCount: 1
|
||||
ItemCount: ItemCount.value
|
||||
}
|
||||
])
|
||||
})
|
||||
.done(function (_, _, jqXHR) {
|
||||
.done(function (_, __, jqXHR) {
|
||||
if (jqXHR.status === 200) {
|
||||
updateInventory();
|
||||
productCategory.value = "";
|
||||
ItemCount.disabled = true;
|
||||
ItemCount.value = 1;
|
||||
}
|
||||
})
|
||||
.fail(function () {
|
||||
|
||||
@ -98,6 +98,7 @@ dict = {
|
||||
inventory_addItems: `Gegenstände hinzufügen`,
|
||||
inventory_addItemByItemType: `Roh`,
|
||||
inventory_addItemByItemType_warning: `Verwende diese Funktion auf eigene Gefahr. Sie kann dein Inventar beschädigen und du musst Gegenstände manuell entfernen, falls etwas schiefgeht.`,
|
||||
inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify <code>productCategory</code>, some of which will allow you to change the number of items added.`,
|
||||
inventory_suits: `Warframes`,
|
||||
inventory_longGuns: `Primärwaffen`,
|
||||
inventory_pistols: `Sekundärwaffen`,
|
||||
@ -308,6 +309,7 @@ dict = {
|
||||
worldState_incompatibleWith: `Inkompatibel mit:`,
|
||||
enabled: `Aktiviert`,
|
||||
disabled: `Deaktiviert`,
|
||||
notSpecified: `[UNTRANSLATED] Not specified`,
|
||||
worldState_we1: `Wochenende 1`,
|
||||
worldState_we2: `Wochenende 2`,
|
||||
worldState_we3: `Wochenende 3`,
|
||||
|
||||
@ -97,6 +97,7 @@ dict = {
|
||||
inventory_addItems: `Add Items`,
|
||||
inventory_addItemByItemType: `Raw`,
|
||||
inventory_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.`,
|
||||
inventory_addItemByItemType_productCategory: `You can also specify <code>productCategory</code>, some of which will allow you to change the number of items added.`,
|
||||
inventory_suits: `Warframes`,
|
||||
inventory_longGuns: `Primary Weapons`,
|
||||
inventory_pistols: `Secondary Weapons`,
|
||||
@ -307,6 +308,7 @@ dict = {
|
||||
worldState_incompatibleWith: `Incompatible with:`,
|
||||
enabled: `Enabled`,
|
||||
disabled: `Disabled`,
|
||||
notSpecified: `Not specified`,
|
||||
worldState_we1: `Weekend 1`,
|
||||
worldState_we2: `Weekend 2`,
|
||||
worldState_we3: `Weekend 3`,
|
||||
|
||||
@ -98,6 +98,7 @@ dict = {
|
||||
inventory_addItems: `Agregar objetos`,
|
||||
inventory_addItemByItemType: `Sin refinar`,
|
||||
inventory_addItemByItemType_warning: `Usa esta función bajo tu propio riesgo. Podría dañar tu inventario, y tendrías que eliminar los objetos manualmente si algo sale mal.`,
|
||||
inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify <code>productCategory</code>, some of which will allow you to change the number of items added.`,
|
||||
inventory_suits: `Warframes`,
|
||||
inventory_longGuns: `Armas primarias`,
|
||||
inventory_pistols: `Armas secundarias`,
|
||||
@ -308,6 +309,7 @@ dict = {
|
||||
worldState_incompatibleWith: `No compatible con:`,
|
||||
enabled: `Activado`,
|
||||
disabled: `Desactivado`,
|
||||
notSpecified: `[UNTRANSLATED] Not specified`,
|
||||
worldState_we1: `Semana 1`,
|
||||
worldState_we2: `Semana 2`,
|
||||
worldState_we3: `Semana 3`,
|
||||
|
||||
@ -98,6 +98,7 @@ dict = {
|
||||
inventory_addItems: `Ajouter des items`,
|
||||
inventory_addItemByItemType: `Brut`,
|
||||
inventory_addItemByItemType_warning: `Cette fonctionnalité comporte des risques. Il faudra rajouter les items manuellement si l'inventaire est compris.`,
|
||||
inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify <code>productCategory</code>, some of which will allow you to change the number of items added.`,
|
||||
inventory_suits: `Warframes`,
|
||||
inventory_longGuns: `Armes principales`,
|
||||
inventory_pistols: `Armes secondaires`,
|
||||
@ -308,6 +309,7 @@ dict = {
|
||||
worldState_incompatibleWith: `Incompatible avec :`,
|
||||
enabled: `Activé`,
|
||||
disabled: `Désactivé`,
|
||||
notSpecified: `[UNTRANSLATED] Not specified`,
|
||||
worldState_we1: `Weekend 1`,
|
||||
worldState_we2: `Weekend 2`,
|
||||
worldState_we3: `Weekend 3`,
|
||||
|
||||
@ -98,6 +98,7 @@ dict = {
|
||||
inventory_addItems: `Добавить предметы`,
|
||||
inventory_addItemByItemType: `Необработанные данные`,
|
||||
inventory_addItemByItemType_warning: `Используйте эту функцию на свой страх и риск. Она может повредить ваш инвентарь, и в случае проблем вам придётся удалять предметы вручную.`,
|
||||
inventory_addItemByItemType_productCategory: `Вы также можете указать <code>productCategory</code>, некоторые из них позволят вам изменить количество добавленных преметов.`,
|
||||
inventory_suits: `Варфреймы`,
|
||||
inventory_longGuns: `Основное оружие`,
|
||||
inventory_pistols: `Вторичное оружие`,
|
||||
@ -308,6 +309,7 @@ dict = {
|
||||
worldState_incompatibleWith: `Несовместимо с:`,
|
||||
enabled: `Включено`,
|
||||
disabled: `Отключено`,
|
||||
notSpecified: `Не указано`,
|
||||
worldState_we1: `Выходные 1`,
|
||||
worldState_we2: `Выходные 2`,
|
||||
worldState_we3: `Выходные 3`,
|
||||
|
||||
@ -98,6 +98,7 @@ dict = {
|
||||
inventory_addItems: `Додати предмети`,
|
||||
inventory_addItemByItemType: `Необроблені дані`,
|
||||
inventory_addItemByItemType_warning: `Використовуйте цю функцію на власний ризик. Вона може пошкодити ваше спорядження, і вам доведеться видаляти предмети вручну, якщо щось піде не так.`,
|
||||
inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify <code>productCategory</code>, some of which will allow you to change the number of items added.`,
|
||||
inventory_suits: `Ворфрейми`,
|
||||
inventory_longGuns: `Основна зброя`,
|
||||
inventory_pistols: `Допоміжна зброя`,
|
||||
@ -308,6 +309,7 @@ dict = {
|
||||
worldState_incompatibleWith: `Несумісне з:`,
|
||||
enabled: `Увімкнено`,
|
||||
disabled: `Вимкнено`,
|
||||
notSpecified: `[UNTRANSLATED] Not specified`,
|
||||
worldState_we1: `Вихідні 1`,
|
||||
worldState_we2: `Вихідні 2`,
|
||||
worldState_we3: `Вихідні 3`,
|
||||
|
||||
@ -98,6 +98,7 @@ dict = {
|
||||
inventory_addItems: `添加物品`,
|
||||
inventory_addItemByItemType: `[UNTRANSLATED] Raw`,
|
||||
inventory_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.`,
|
||||
inventory_addItemByItemType_productCategory: `[UNTRANSLATED] You can also specify <code>productCategory</code>, some of which will allow you to change the number of items added.`,
|
||||
inventory_suits: `战甲`,
|
||||
inventory_longGuns: `主要武器`,
|
||||
inventory_pistols: `次要武器`,
|
||||
@ -308,6 +309,7 @@ dict = {
|
||||
worldState_incompatibleWith: `不兼容的活动:`,
|
||||
enabled: `启用`,
|
||||
disabled: `关闭/取消配置`,
|
||||
notSpecified: `[UNTRANSLATED] Not specified`,
|
||||
worldState_we1: `活动阶段:第一周`,
|
||||
worldState_we2: `活动阶段:第二周`,
|
||||
worldState_we3: `活动阶段:第三周`,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user