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
2 changed files with 6 additions and 4 deletions
Showing only changes of commit 3c3381847b - Show all commits

View file

@ -84,7 +84,7 @@ export class CoreClient extends Client {
console.log(`Registered Events: ${CoreClient._eventItems.flatMap(x => x.EventType).join(", ")}`); console.log(`Registered Events: ${CoreClient._eventItems.flatMap(x => x.EventType).join(", ")}`);
console.log(`Registered Buttons: ${CoreClient._buttonEvents.flatMap(x => x.ButtonId).join(", ")}`); console.log(`Registered Buttons: ${CoreClient._buttonEvents.flatMap(x => x.ButtonId).join(", ")}`);
const page = await InventoryHelper.GenerateInventoryPage('125776189666230272', 11); const page = await InventoryHelper.GenerateInventoryPage('125776189666230272', 0);
console.log(page); console.log(page);

View file

@ -21,14 +21,16 @@ interface InventoryPageCards {
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 = 9;
const inventory = await Inventory.FetchAllByUserId(userid); const inventory = await Inventory.FetchAllByUserId(userid);
const allSeriesClaimed = CoreClient.Cards const allSeriesClaimed = CoreClient.Cards
.sort((a, b) => a.id - b.id) .sort((a, b) => a.id - b.id)
.filter(x => { .filter(x => {
x.cards = x.cards.filter(y => inventory.find(z => z.CardNumber == y.id)); x.cards = x.cards
.sort((a, b) => b.type - a.type)
.filter(y => inventory.find(z => z.CardNumber == y.id));
return x; return x;
}); });
@ -36,7 +38,7 @@ export default class InventoryHelper {
const pages: InventoryPage[] = []; const pages: InventoryPage[] = [];
for (let series of allSeriesClaimed) { for (let series of allSeriesClaimed) {
const seriesCards = series.cards.sort((a, b) => b.type - a.type); const seriesCards = series.cards;
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);