Add types as interfaces
This commit is contained in:
parent
c8a4fe25d1
commit
b9f6ea69b7
1 changed files with 20 additions and 21 deletions
|
@ -1,10 +1,24 @@
|
||||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||||
import Inventory from "../database/entities/app/Inventory";
|
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 from "../contracts/SeriesMetadata";
|
||||||
import EmbedColours from "../constants/EmbedColours";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import { CardRarity, CardRarityToString } from "../constants/CardRarity";
|
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 {
|
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> }> {
|
||||||
const cardsPerPage = 10;
|
const cardsPerPage = 10;
|
||||||
|
@ -33,29 +47,14 @@ export default class InventoryHelper {
|
||||||
seriesToDisplay.push(series);
|
seriesToDisplay.push(series);
|
||||||
}
|
}
|
||||||
|
|
||||||
const pages: {
|
const pages: InventoryPage[] = [];
|
||||||
id: number,
|
|
||||||
name: string,
|
|
||||||
cards: {
|
|
||||||
cardNumber: string,
|
|
||||||
name: string,
|
|
||||||
quantity: number,
|
|
||||||
type: CardRarity,
|
|
||||||
}[],
|
|
||||||
seriesSubpage: number,
|
|
||||||
}[] = [];
|
|
||||||
|
|
||||||
for (let series of seriesToDisplay) {
|
for (let series of seriesToDisplay) {
|
||||||
const seriesCards = series.cards.sort((a, b) => b.type - a.type);
|
const seriesCards = series.cards.sort((a, b) => b.type - a.type);
|
||||||
|
|
||||||
for (let i = 0; i < seriesCards.length; i+= cardsPerPage) {
|
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: InventoryPageCards[] = [];
|
||||||
cardNumber: string,
|
|
||||||
name: string,
|
|
||||||
quantity: number,
|
|
||||||
type: CardRarity,
|
|
||||||
}[] = [];
|
|
||||||
|
|
||||||
for (let card of cards) {
|
for (let card of cards) {
|
||||||
const item = inventory.find(x => x.CardNumber == card.id);
|
const item = inventory.find(x => x.CardNumber == card.id);
|
||||||
|
@ -65,10 +64,10 @@ export default class InventoryHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
pageCards.push({
|
pageCards.push({
|
||||||
cardNumber: card.id,
|
id: card.id,
|
||||||
name: card.name,
|
name: card.name,
|
||||||
quantity: item.Quantity,
|
|
||||||
type: card.type,
|
type: card.type,
|
||||||
|
quantity: item.Quantity,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +90,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} (${CardRarityToString(card.type)}) x${card.quantity}`);
|
embedDescription.push(`[${card.id}] ${card.name} (${CardRarityToString(card.type)}) x${card.quantity}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
|
|
Loading…
Reference in a new issue