diff --git a/src/app/tools/tankopedia/page.tsx b/src/app/tools/tankopedia/page.tsx new file mode 100644 index 000000000..f03653954 --- /dev/null +++ b/src/app/tools/tankopedia/page.tsx @@ -0,0 +1,64 @@ +import { Badge, Card, Flex, Text } from '@radix-ui/themes'; +import PageWrapper from '../../../components/PageWrapper'; +import { tankIcon } from '../../../core/blitzkrieg/tankIcon'; +import { tanks } from '../../../core/blitzkrieg/tankopedia'; + +const sortedTanks = tanks.then((tanks) => + tanks.sort((a, b) => b.tier - a.tier), +); + +export default async function Page() { + const awaitedTanks = await sortedTanks; + + return ( + + {awaitedTanks.map((tank) => ( + + + + + + + {tank.name_short ?? tank.name ?? `Unknown tank ${tank.id}`} + + + + {tank.tree_type !== 'tech-tree' && ( + + {tank.tree_type === 'collector' ? 'Collector' : 'Premium'} + + )} + + {(() => { + if (tank.type === 'AT-SPG') return 'Tank Destroyer'; + if (tank.type === 'lightTank') return 'Light Tank'; + if (tank.type === 'mediumTank') return 'Medium Tank'; + if (tank.type === 'heavyTank') return 'Heavy Tank'; + })()} + + + + + + ))} + + ); +} diff --git a/src/commands/searchTanks.ts b/src/commands/searchTanks.ts index 5eff8444f..99bc0e113 100644 --- a/src/commands/searchTanks.ts +++ b/src/commands/searchTanks.ts @@ -1,7 +1,7 @@ import { SlashCommandBuilder } from 'discord.js'; import { go } from 'fuzzysort'; import markdownEscape from 'markdown-escape'; -import { TANK_NAMES_DIACRITICS } from '../core/blitzkrieg/tankopedia'; +import { tankNamesDiacritics } from '../core/blitzkrieg/tankopedia'; import addTankChoices from '../core/discord/addTankChoices'; import embedInfo from '../core/discord/embedInfo'; import { CommandRegistry } from '../events/interactionCreate'; @@ -25,7 +25,7 @@ export const searchTanksCommand: CommandRegistry = { async handler(interaction) { const tank = interaction.options.getString('tank')!; const limit = interaction.options.getInteger('limit') ?? 25; - const results = go(tank, await TANK_NAMES_DIACRITICS, { + const results = go(tank, await tankNamesDiacritics, { limit, keys: ['combined'], }).map((result) => result.obj.original); diff --git a/src/components/Tanks/components/Item.tsx b/src/components/Tanks/components/Item.tsx index 89a60db98..ce3f5ba35 100644 --- a/src/components/Tanks/components/Item.tsx +++ b/src/components/Tanks/components/Item.tsx @@ -11,6 +11,7 @@ export enum TreeTypeEnum { Collector, } +export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank'; export type TreeTypeString = 'tech-tree' | 'premium' | 'collector'; export const TREE_TYPE_NAMES: Record = { diff --git a/src/constants/tools.ts b/src/constants/tools.ts index efcaab6a6..0bc0847fe 100644 --- a/src/constants/tools.ts +++ b/src/constants/tools.ts @@ -20,7 +20,6 @@ export const TOOLS: Tool[] = [ id: 'tankopedia', title: 'Tankopedia', description: 'Full Blitz tank encyclopedia', - disabled: true, }, { id: 'inactive', diff --git a/src/core/blitz/resolveTankId.ts b/src/core/blitz/resolveTankId.ts index 3d9e9a18b..a360e2f83 100644 --- a/src/core/blitz/resolveTankId.ts +++ b/src/core/blitz/resolveTankId.ts @@ -1,12 +1,12 @@ import { go } from 'fuzzysort'; -import { TANKS, tankopedia } from '../blitzkrieg/tankopedia'; +import { tankopedia, tanks } from '../blitzkrieg/tankopedia'; import { UserError } from '../blitzkrieg/userError'; export default async function resolveTankId(tank: string | number) { const number = typeof tank === 'string' ? parseInt(tank) : tank; if (Number.isNaN(number)) { - const searchResult = go(`${tank}`, await TANKS, { + const searchResult = go(`${tank}`, await tanks, { keys: ['name'], limit: 1, }); diff --git a/src/core/blitzkrieg/tankopedia.ts b/src/core/blitzkrieg/tankopedia.ts index d3c5f52ae..26a15a04a 100644 --- a/src/core/blitzkrieg/tankopedia.ts +++ b/src/core/blitzkrieg/tankopedia.ts @@ -1,5 +1,5 @@ import { deburr } from 'lodash'; -import { TreeTypeString } from '../../components/Tanks'; +import { TankType, TreeTypeString } from '../../components/Tanks'; import { asset } from './asset'; export interface TankopediaEntry { @@ -25,7 +25,7 @@ export interface BlitzkriegTankopediaEntry { name_short?: string; tree_type: TreeTypeString; tier: Tier; - type: string; + type: TankType; } export type BlitzkriegTankopedia = Record; @@ -36,18 +36,18 @@ export const tankopedia = fetch(asset('tankopedia.json')).then( const entries = new Promise(async (resolve) => { resolve(Object.entries(await tankopedia).map(([, entry]) => entry)); }); -export const TANKS = new Promise( +export const tanks = new Promise( async (resolve) => { resolve((await entries).map((entry) => entry)); }, ); -export const TANK_NAMES = new Promise(async (resolve) => { +export const tankNames = new Promise(async (resolve) => { resolve((await entries).map(({ name }) => name)); }); -export const TANK_NAMES_DIACRITICS = TANK_NAMES.then((tankNames) => +export const tankNamesDiacritics = tankNames.then((tankNames) => Promise.all( tankNames.map(async (tankName, index) => { - const { id } = (await TANKS)[index]; + const { id } = (await tanks)[index]; const name = tankName ?? `Unknown Tank ${id}`; const diacriticless = deburr(name); diff --git a/src/core/discord/autocompleteTanks.ts b/src/core/discord/autocompleteTanks.ts index 1b1c584e8..1765a3bb9 100644 --- a/src/core/discord/autocompleteTanks.ts +++ b/src/core/discord/autocompleteTanks.ts @@ -4,7 +4,7 @@ import { CacheType, } from 'discord.js'; import { go } from 'fuzzysort'; -import { TANK_NAMES_DIACRITICS } from '../blitzkrieg/tankopedia'; +import { tankNamesDiacritics } from '../blitzkrieg/tankopedia'; import { DISCORD_CHOICES_MAX_NAME_SIZE, OVERFLOW_SUFFIX, @@ -19,7 +19,7 @@ export default async function autocompleteTanks( await interaction.respond( focusedOption.value ? await Promise.all( - go(focusedOption.value, await TANK_NAMES_DIACRITICS, { + go(focusedOption.value, await tankNamesDiacritics, { keys: ['combined'], limit: 10, }).map(async (item) => {