Create simple inventory list #120

Merged
Vylpes merged 10 commits from feature/97-simple-inventory-list into develop 2023-12-22 14:41:14 +00:00
Showing only changes of commit b9f6ea69b7 - Show all commits

View file

@ -1,10 +1,24 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
import Inventory from "../database/entities/app/Inventory";
import { CoreClient } from "../client/client";
import SeriesMetadata, { CardMetadata } from "../contracts/SeriesMetadata";
import SeriesMetadata from "../contracts/SeriesMetadata";
import EmbedColours from "../constants/EmbedColours";
import { CardRarity, CardRarityToString } from "../constants/CardRarity";
interface InventoryPage {
id: number,
name: string,
cards: InventoryPageCards[],
seriesSubpage: number,
}
interface InventoryPageCards {
id: string,
name: string,
type: CardRarity,
quantity: number,
}
export default class InventoryHelper {
public static async GenerateInventoryPage(userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
const cardsPerPage = 10;
@ -33,29 +47,14 @@ export default class InventoryHelper {
seriesToDisplay.push(series);
}
const pages: {
id: number,
name: string,
cards: {
cardNumber: string,
name: string,
quantity: number,
type: CardRarity,
}[],
seriesSubpage: number,
}[] = [];
const pages: InventoryPage[] = [];
for (let series of seriesToDisplay) {
const seriesCards = series.cards.sort((a, b) => b.type - a.type);
for (let i = 0; i < seriesCards.length; i+= cardsPerPage) {
const cards = series.cards.slice(i, i + cardsPerPage);
const pageCards: {
cardNumber: string,
name: string,
quantity: number,
type: CardRarity,
}[] = [];
const pageCards: InventoryPageCards[] = [];
for (let card of cards) {
const item = inventory.find(x => x.CardNumber == card.id);
@ -65,10 +64,10 @@ export default class InventoryHelper {
}
pageCards.push({
cardNumber: card.id,
id: card.id,
name: card.name,
quantity: item.Quantity,
type: card.type,
quantity: item.Quantity,
});
}
@ -91,7 +90,7 @@ export default class InventoryHelper {
const embedDescription: string[] = [];
for (let card of currentPage.cards) {
embedDescription.push(`[${card.cardNumber}] ${card.name} (${CardRarityToString(card.type)}) x${card.quantity}`);
embedDescription.push(`[${card.id}] ${card.name} (${CardRarityToString(card.type)}) x${card.quantity}`);
}
const embed = new EmbedBuilder()