Update inventory dropdown logic to use a range around the current page so that we can remain within the 25 pages discord allows (#450)
All checks were successful
Test / build (push) Successful in 44s
All checks were successful
Test / build (push) Successful in 44s
#443 Reviewed-on: #450 Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
ead53ba062
commit
8e63f26747
1 changed files with 37 additions and 6 deletions
|
@ -115,17 +115,48 @@ export default class InventoryHelper {
|
|||
|
||||
let pageNum = 0;
|
||||
|
||||
const maxLength = 25; // Discord API limit
|
||||
|
||||
const allPageOptions = pages.map(x =>
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel(`${x.name} (${x.seriesSubpage + 1})`.substring(0, 100))
|
||||
.setDescription(`Page ${pageNum + 1}`)
|
||||
.setDefault(currentPage.id == x.id)
|
||||
.setValue(`${userid} ${pageNum++}`));
|
||||
|
||||
const currentPageIndex = allPageOptions.indexOf(allPageOptions.find(x => x.data.default)!);
|
||||
|
||||
let pageOptions: StringSelectMenuOptionBuilder[] = [];
|
||||
|
||||
if (allPageOptions.length <= maxLength) {
|
||||
pageOptions = allPageOptions;
|
||||
} else {
|
||||
let startIndex = currentPageIndex - Math.floor((maxLength - 1) / 2);
|
||||
let endIndexOffset = 0;
|
||||
|
||||
if (startIndex < 0) {
|
||||
endIndexOffset = 0 - startIndex;
|
||||
|
||||
startIndex = 0;
|
||||
}
|
||||
|
||||
let endIndex = currentPageIndex + Math.floor((maxLength - 1) / 2) + endIndexOffset;
|
||||
|
||||
if (endIndex + 1 > allPageOptions.length) {
|
||||
endIndex = allPageOptions.length;
|
||||
}
|
||||
|
||||
for (let i = startIndex; i < endIndex; i++) {
|
||||
pageOptions.push(allPageOptions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
const row2 = new ActionRowBuilder<StringSelectMenuBuilder>()
|
||||
.addComponents(
|
||||
new StringSelectMenuBuilder()
|
||||
.setCustomId("inventory")
|
||||
.setPlaceholder(`${currentPage.name} (${currentPage.seriesSubpage + 1})`)
|
||||
.addOptions(...pages.map(x =>
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel(`${x.name} (${x.seriesSubpage + 1})`.substring(0, 100))
|
||||
.setDescription(`Page ${pageNum + 1}`)
|
||||
.setDefault(currentPage.id == x.id)
|
||||
.setValue(`${userid} ${pageNum++}`))));
|
||||
.addOptions(pageOptions));
|
||||
|
||||
const buffer = await ImageHelper.GenerateCardImageGrid(currentPage.cards.map(x => ({ id: x.id, path: x.path })));
|
||||
const image = new AttachmentBuilder(buffer, { name: "page.png" });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue