feat: tankopedia website

This commit is contained in:
TrèsAbhi committed 2023-11-30 12:21:20 -06:00
1 parent 818ee1d447
commit f3144be382
7 files changed
+77 -13

No files matched your search

+64
View File
@@ -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 (
<PageWrapper>
{awaitedTanks.map((tank) => (
<Card
style={{
// backgroundImage: `url(${tankIcon(tank.id)})`,
// backgroundRepeat: 'no-repeat',
// backgroundPosition: '8px 8px',
minHeight: 128,
}}
>
<Flex justify="between" align="center">
<img
src={tankIcon(tank.id)}
style={{
backgroundColor: 'white',
width: 256,
height: 128,
objectFit: 'contain',
objectPosition: 'left center',
}}
/>
<Flex direction="column" justify="center" align="end" gap="2">
<Text>
{tank.name_short ?? tank.name ?? `Unknown tank ${tank.id}`}
</Text>
<Flex justify="end" align="center" gap="1">
{tank.tree_type !== 'tech-tree' && (
<Badge
color={tank.tree_type === 'collector' ? 'blue' : 'amber'}
>
{tank.tree_type === 'collector' ? 'Collector' : 'Premium'}
</Badge>
)}
<Badge color="indigo">
{(() => {
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';
})()}
</Badge>
</Flex>
</Flex>
</Flex>
</Card>
))}
</PageWrapper>
);
}
+2 -2
View File
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder } from 'discord.js';
import { go } from 'fuzzysort'; import { go } from 'fuzzysort';
import markdownEscape from 'markdown-escape'; 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 addTankChoices from '../core/discord/addTankChoices';
import embedInfo from '../core/discord/embedInfo'; import embedInfo from '../core/discord/embedInfo';
import { CommandRegistry } from '../events/interactionCreate'; import { CommandRegistry } from '../events/interactionCreate';
@@ -25,7 +25,7 @@ export const searchTanksCommand: CommandRegistry = {
async handler(interaction) { async handler(interaction) {
const tank = interaction.options.getString('tank')!; const tank = interaction.options.getString('tank')!;
const limit = interaction.options.getInteger('limit') ?? 25; const limit = interaction.options.getInteger('limit') ?? 25;
const results = go(tank, await TANK_NAMES_DIACRITICS, { const results = go(tank, await tankNamesDiacritics, {
limit, limit,
keys: ['combined'], keys: ['combined'],
}).map((result) => result.obj.original); }).map((result) => result.obj.original);
+1
View File
@@ -11,6 +11,7 @@ export enum TreeTypeEnum {
Collector, Collector,
} }
export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
export type TreeTypeString = 'tech-tree' | 'premium' | 'collector'; export type TreeTypeString = 'tech-tree' | 'premium' | 'collector';
export const TREE_TYPE_NAMES: Record<TreeTypeString, string> = { export const TREE_TYPE_NAMES: Record<TreeTypeString, string> = {
-1
View File
@@ -20,7 +20,6 @@ export const TOOLS: Tool[] = [
id: 'tankopedia', id: 'tankopedia',
title: 'Tankopedia', title: 'Tankopedia',
description: 'Full Blitz tank encyclopedia', description: 'Full Blitz tank encyclopedia',
disabled: true,
}, },
{ {
id: 'inactive', id: 'inactive',
+2 -2
View File
@@ -1,12 +1,12 @@
import { go } from 'fuzzysort'; import { go } from 'fuzzysort';
import { TANKS, tankopedia } from '../blitzkrieg/tankopedia'; import { tankopedia, tanks } from '../blitzkrieg/tankopedia';
import { UserError } from '../blitzkrieg/userError'; import { UserError } from '../blitzkrieg/userError';
export default async function resolveTankId(tank: string | number) { export default async function resolveTankId(tank: string | number) {
const number = typeof tank === 'string' ? parseInt(tank) : tank; const number = typeof tank === 'string' ? parseInt(tank) : tank;
if (Number.isNaN(number)) { if (Number.isNaN(number)) {
const searchResult = go(`${tank}`, await TANKS, { const searchResult = go(`${tank}`, await tanks, {
keys: ['name'], keys: ['name'],
limit: 1, limit: 1,
}); });
+6 -6
View File
@@ -1,5 +1,5 @@
import { deburr } from 'lodash'; import { deburr } from 'lodash';
import { TreeTypeString } from '../../components/Tanks'; import { TankType, TreeTypeString } from '../../components/Tanks';
import { asset } from './asset'; import { asset } from './asset';
export interface TankopediaEntry { export interface TankopediaEntry {
@@ -25,7 +25,7 @@ export interface BlitzkriegTankopediaEntry {
name_short?: string; name_short?: string;
tree_type: TreeTypeString; tree_type: TreeTypeString;
tier: Tier; tier: Tier;
type: string; type: TankType;
} }
export type BlitzkriegTankopedia = Record<number, BlitzkriegTankopediaEntry>; export type BlitzkriegTankopedia = Record<number, BlitzkriegTankopediaEntry>;
@@ -36,18 +36,18 @@ export const tankopedia = fetch(asset('tankopedia.json')).then(
const entries = new Promise<BlitzkriegTankopediaEntry[]>(async (resolve) => { const entries = new Promise<BlitzkriegTankopediaEntry[]>(async (resolve) => {
resolve(Object.entries(await tankopedia).map(([, entry]) => entry)); resolve(Object.entries(await tankopedia).map(([, entry]) => entry));
}); });
export const TANKS = new Promise<BlitzkriegTankopediaEntry[]>( export const tanks = new Promise<BlitzkriegTankopediaEntry[]>(
async (resolve) => { async (resolve) => {
resolve((await entries).map((entry) => entry)); resolve((await entries).map((entry) => entry));
}, },
); );
export const TANK_NAMES = new Promise<string[]>(async (resolve) => { export const tankNames = new Promise<string[]>(async (resolve) => {
resolve((await entries).map(({ name }) => name)); resolve((await entries).map(({ name }) => name));
}); });
export const TANK_NAMES_DIACRITICS = TANK_NAMES.then((tankNames) => export const tankNamesDiacritics = tankNames.then((tankNames) =>
Promise.all( Promise.all(
tankNames.map(async (tankName, index) => { tankNames.map(async (tankName, index) => {
const { id } = (await TANKS)[index]; const { id } = (await tanks)[index];
const name = tankName ?? `Unknown Tank ${id}`; const name = tankName ?? `Unknown Tank ${id}`;
const diacriticless = deburr(name); const diacriticless = deburr(name);
+2 -2
View File
@@ -4,7 +4,7 @@ import {
CacheType, CacheType,
} from 'discord.js'; } from 'discord.js';
import { go } from 'fuzzysort'; import { go } from 'fuzzysort';
import { TANK_NAMES_DIACRITICS } from '../blitzkrieg/tankopedia'; import { tankNamesDiacritics } from '../blitzkrieg/tankopedia';
import { import {
DISCORD_CHOICES_MAX_NAME_SIZE, DISCORD_CHOICES_MAX_NAME_SIZE,
OVERFLOW_SUFFIX, OVERFLOW_SUFFIX,
@@ -19,7 +19,7 @@ export default async function autocompleteTanks(
await interaction.respond( await interaction.respond(
focusedOption.value focusedOption.value
? await Promise.all( ? await Promise.all(
go(focusedOption.value, await TANK_NAMES_DIACRITICS, { go(focusedOption.value, await tankNamesDiacritics, {
keys: ['combined'], keys: ['combined'],
limit: 10, limit: 10,
}).map(async (item) => { }).map(async (item) => {