Skip to content

Commit 937d05f

Browse files
wip: rename ssbu_character_names to ssbu_characters, progress on character paginator
1 parent 2646152 commit 937d05f

6 files changed

Lines changed: 36 additions & 34 deletions

File tree

apps/backend/src/characters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const ssbu_character_names = [
1+
export const ssbu_characters = [
22
"Mario",
33
"Donkey Kong",
44
"Link",

apps/backend/src/db/seeds/SSBUCharacters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ssbu_character_names } from "@src/characters";
1+
import { ssbu_characters } from "@src/characters";
22
import type { Knex } from "knex";
33

44
export async function seed(knex: Knex) {
55
await knex("SSBUChar").del();
66
await knex("SSBUChar").insert(
7-
ssbu_character_names.map((character_name) => {
7+
ssbu_characters.map((character_name) => {
88
return { character_name };
99
}),
1010
);

apps/backend/src/test/factories.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// General utilities for generating test data
22

33
import { faker } from "@faker-js/faker";
4-
import { ssbu_character_names } from "@src/characters";
4+
import { ssbu_characters } from "@src/characters";
55

66
export const snowflake = () =>
77
faker.string.numeric({
@@ -13,12 +13,12 @@ export const randint = (max: number) => {
1313
};
1414

1515
export const rand_character_array = (): Array<
16-
(typeof ssbu_character_names)[number]
16+
(typeof ssbu_characters)[number]
1717
> => [
1818
...new Set(
1919
Array.from(
2020
{ length: 1 + randint(4) },
21-
() => ssbu_character_names[randint(ssbu_character_names.length)],
21+
() => ssbu_characters[randint(ssbu_characters.length)],
2222
),
2323
),
2424
];

apps/backend/src/v1/match/schemas.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { ssbu_character_names } from "@src/characters";
1+
import { ssbu_characters } from "@src/characters";
22
import { z } from "zod";
33

4-
export const SSBUCharEnum = z.enum(ssbu_character_names);
4+
export const SSBUCharEnum = z.enum(ssbu_characters);
55
export type SSBUCharEnum = z.infer<typeof SSBUCharEnum>;
66

77
export const SSBUCharFighterNumber = z
88
.int()
99
.min(0)
10-
.max(ssbu_character_names.length + 1);
10+
.max(ssbu_characters.length + 1);
1111
export type SSBUCharFighterNumber = z.infer<typeof SSBUCharFighterNumber>;
1212

1313
export const SSBUCharEnumToFighterNumber = z.codec(
1414
SSBUCharEnum,
1515
SSBUCharFighterNumber,
1616
{
1717
encode: (fighter_number: SSBUCharFighterNumber) =>
18-
ssbu_character_names[fighter_number - 1],
18+
ssbu_characters[fighter_number - 1],
1919
decode: (character_name: SSBUCharEnum) =>
20-
ssbu_character_names.indexOf(character_name) + 1,
20+
ssbu_characters.indexOf(character_name) + 1,
2121
},
2222
);
2323

apps/backend/src/v1/match/test/models.factories.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ssbu_character_names } from "@src/characters";
1+
import { ssbu_characters } from "@src/characters";
22
import { randint, snowflake } from "@test/factories";
33
import type {
44
MatchCharacterRecord,
@@ -33,7 +33,7 @@ export const matchCharacterRecordFactory = (
3333
return {
3434
match_id: randint(1000),
3535
user_id: snowflake(),
36-
fighter_number: randint(ssbu_character_names.length),
36+
fighter_number: randint(ssbu_characters.length),
3737
...match_character_record,
3838
};
3939
};

apps/bot/src/interaction/command/report/component.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ssbu_character_names } from "@grindcord/characters";
1+
import { ssbu_characters } from "@grindcord/characters";
22
import type { SSBUCharEnum } from "@grindcord/types";
33
import { getLogger } from "@logtape/logtape";
44
import {
@@ -25,7 +25,7 @@ const log = getLogger(["bot", "component"]);
2525
type ReportMatchPlayer = {
2626
name: string;
2727
win_count?: number;
28-
character?: SSBUCharEnum[];
28+
character: SSBUCharEnum[];
2929
};
3030

3131
export async function initializeReportMatchInterface(interaction: CommandInteraction) {
@@ -74,6 +74,7 @@ async function selectUsersPage(
7474
for (const [user_id, user] of i.users) {
7575
selected_users.set(user_id, {
7676
name: i.members.get(user_id)?.nickname ?? user.displayName,
77+
character: [],
7778
});
7879
}
7980
await i.deferUpdate();
@@ -130,7 +131,7 @@ async function selectWinCountPage(
130131
.setPlaceholder(`How many sets did ${match_player.name} win?`)
131132
.setCustomId(user_id)
132133
.setOptions(
133-
[1, 2, 3, 4, 5, 6, 7].map((x) => {
134+
[0, 1, 2, 3, 4, 5, 6, 7].map((x) => {
134135
const wins_choice = new StringSelectMenuOptionBuilder()
135136
.setLabel(x.toString())
136137
.setValue(x.toString());
@@ -202,6 +203,8 @@ async function selectCharactersPage(
202203
interaction: MessageComponentInteraction,
203204
match_players: Collection<string, ReportMatchPlayer>,
204205
) {
206+
const characterPagination = new Collection<string, number>();
207+
205208
const component = new ContainerBuilder().addTextDisplayComponents((title) =>
206209
title.setContent("# Report a Set"),
207210
);
@@ -216,31 +219,23 @@ async function selectCharactersPage(
216219
.setPlaceholder(`Which characters did ${match_player.name} use?`)
217220
.setCustomId(user_id)
218221
.setOptions(
219-
ssbu_character_names.map((x) => {
222+
ssbu_characters.map((x: SSBUCharEnum) => {
220223
const character_choice = new StringSelectMenuOptionBuilder()
221224
.setLabel(x)
222225
.setValue(x);
223-
if (match_player.character && x in match_player.character) {
226+
if (x in match_player.character) {
224227
character_choice.setDefault(true);
225228
}
226229
return character_choice;
227230
}),
228231
),
232+
new ButtonBuilder()
233+
.setCustomId(`more${user_id}`)
234+
.setLabel("More characters")
235+
.setStyle(ButtonStyle.Secondary),
229236
),
230237
);
231238
}
232-
component.addActionRowComponents((actionRow) =>
233-
actionRow.setComponents(
234-
new ButtonBuilder()
235-
.setCustomId("previous")
236-
.setLabel("Previous")
237-
.setStyle(ButtonStyle.Primary),
238-
new ButtonBuilder()
239-
.setCustomId("next")
240-
.setLabel("Next")
241-
.setStyle(ButtonStyle.Primary),
242-
),
243-
);
244239
async function collect(interactable_message: Message<true>): Promise<void> {
245240
const selectCharactersCollector =
246241
interactable_message.createMessageComponentCollector({
@@ -255,17 +250,24 @@ async function selectCharactersPage(
255250
selectCharactersCollector?.on("collect", async (i) => {
256251
const player = match_players.get(i.customId);
257252
if (player) {
258-
player.character = z
259-
.array(z.enum(ssbu_character_names))
260-
.parse(i.values);
253+
player.character = z.array(z.enum(ssbu_characters)).parse(i.values);
261254
}
262255
await i.deferUpdate();
263256
});
264257
pagingCollector?.on("collect", async (i) => {
265258
selectCharactersCollector.stop();
266259
pagingCollector.stop();
267260

268-
if (i.customId === "next") {
261+
if (i.customId.slice(0, 4) === "more") {
262+
const user_id = i.customId.slice(4);
263+
const pagination_index = characterPagination.get(user_id);
264+
const match_player = match_players.get(user_id);
265+
if (pagination_index && match_player) {
266+
const new_pagination_index =
267+
25 - (match_player.character?.length % ssbu_characters.length);
268+
characterPagination.set(user_id, new_pagination_index);
269+
}
270+
} else if (i.customId === "next") {
269271
selectWinCountPage(i, match_players);
270272
} else if (i.customId === "previous") {
271273
selectUsersPage(i, match_players);

0 commit comments

Comments
 (0)