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 c8a4fe25d1 - Show all commits

View file

@ -3,6 +3,7 @@ import Inventory from "../database/entities/app/Inventory";
import { CoreClient } from "../client/client"; import { CoreClient } from "../client/client";
import SeriesMetadata, { CardMetadata } from "../contracts/SeriesMetadata"; import SeriesMetadata, { CardMetadata } from "../contracts/SeriesMetadata";
import EmbedColours from "../constants/EmbedColours"; import EmbedColours from "../constants/EmbedColours";
import { CardRarity, CardRarityToString } from "../constants/CardRarity";
export default class InventoryHelper { export default class InventoryHelper {
public static async GenerateInventoryPage(userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> { public static async GenerateInventoryPage(userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
@ -39,17 +40,21 @@ export default class InventoryHelper {
cardNumber: string, cardNumber: string,
name: string, name: string,
quantity: number, quantity: number,
type: CardRarity,
}[], }[],
seriesSubpage: number, seriesSubpage: number,
}[] = []; }[] = [];
for (let series of seriesToDisplay) { for (let series of seriesToDisplay) {
for (let i = 0; i < series.cards.length; i+= cardsPerPage) { 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 cards = series.cards.slice(i, i + cardsPerPage);
const pageCards: { const pageCards: {
cardNumber: string, cardNumber: string,
name: string, name: string,
quantity: number, quantity: number,
type: CardRarity,
}[] = []; }[] = [];
for (let card of cards) { for (let card of cards) {
@ -63,6 +68,7 @@ export default class InventoryHelper {
cardNumber: card.id, cardNumber: card.id,
name: card.name, name: card.name,
quantity: item.Quantity, quantity: item.Quantity,
type: card.type,
}); });
} }
@ -85,7 +91,7 @@ export default class InventoryHelper {
const embedDescription: string[] = []; const embedDescription: string[] = [];
for (let card of currentPage.cards) { for (let card of currentPage.cards) {
embedDescription.push(`[${card.cardNumber}] ${card.name} (${card.quantity})`); embedDescription.push(`[${card.cardNumber}] ${card.name} (${CardRarityToString(card.type)}) x${card.quantity}`);
} }
const embed = new EmbedBuilder() const embed = new EmbedBuilder()