mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: data driven nations
This commit is contained in:
1 parent
7e5357dfe7
commit
7225fb0231
6 files changed
+40
-35
No files matched your search
@@ -11,7 +11,7 @@ import {
|
|||||||
TREE_TYPE_ICONS,
|
TREE_TYPE_ICONS,
|
||||||
TREE_TYPE_IMAGES,
|
TREE_TYPE_IMAGES,
|
||||||
} from '../../../../../../../components/Tanks/components/Item/constants';
|
} from '../../../../../../../components/Tanks/components/Item/constants';
|
||||||
import { NATIONS } from '../../../../../../../core/blitzkit/tankDefinitions';
|
import { gameDefinitions } from '../../../../../../../core/blitzkit/gameDefinitions';
|
||||||
import {
|
import {
|
||||||
TIERS,
|
TIERS,
|
||||||
TIER_ROMAN_NUMERALS,
|
TIER_ROMAN_NUMERALS,
|
||||||
@@ -23,7 +23,7 @@ import mutateTankopediaPersistent, {
|
|||||||
import * as styles from './index.css';
|
import * as styles from './index.css';
|
||||||
|
|
||||||
export function Options() {
|
export function Options() {
|
||||||
const nations = use(NATIONS);
|
const awaitedGameDefinitions = use(gameDefinitions);
|
||||||
const filters = useTankopediaPersistent((state) => state.filters);
|
const filters = useTankopediaPersistent((state) => state.filters);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -65,7 +65,7 @@ export function Options() {
|
|||||||
))}
|
))}
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex className={styles.oneLineFilters}>
|
<Flex className={styles.oneLineFilters}>
|
||||||
{nations.map((nation, index) => (
|
{awaitedGameDefinitions.nations.map((nation, index) => (
|
||||||
<Button
|
<Button
|
||||||
key={nation}
|
key={nation}
|
||||||
color={filters.nations.includes(nation) ? undefined : 'gray'}
|
color={filters.nations.includes(nation) ? undefined : 'gray'}
|
||||||
@@ -76,9 +76,13 @@ export function Options() {
|
|||||||
borderTopLeftRadius: index === 0 ? undefined : 0,
|
borderTopLeftRadius: index === 0 ? undefined : 0,
|
||||||
borderBottomLeftRadius: index === 0 ? undefined : 0,
|
borderBottomLeftRadius: index === 0 ? undefined : 0,
|
||||||
borderTopRightRadius:
|
borderTopRightRadius:
|
||||||
index === nations.length - 1 ? undefined : 0,
|
index === awaitedGameDefinitions.nations.length - 1
|
||||||
|
? undefined
|
||||||
|
: 0,
|
||||||
borderBottomRightRadius:
|
borderBottomRightRadius:
|
||||||
index === nations.length - 1 ? undefined : 0,
|
index === awaitedGameDefinitions.nations.length - 1
|
||||||
|
? undefined
|
||||||
|
: 0,
|
||||||
}}
|
}}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
mutateTankopediaPersistent((draft) => {
|
mutateTankopediaPersistent((draft) => {
|
||||||
@@ -241,7 +245,7 @@ export function Options() {
|
|||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
>
|
>
|
||||||
<Flex>
|
<Flex>
|
||||||
{nations.slice(0, 5).map((nation, index) => (
|
{awaitedGameDefinitions.nations.slice(0, 5).map((nation, index) => (
|
||||||
<Button
|
<Button
|
||||||
key={nation}
|
key={nation}
|
||||||
color={filters.nations.includes(nation) ? undefined : 'gray'}
|
color={filters.nations.includes(nation) ? undefined : 'gray'}
|
||||||
@@ -252,11 +256,15 @@ export function Options() {
|
|||||||
borderTopLeftRadius: index === 0 ? 16 : 0,
|
borderTopLeftRadius: index === 0 ? 16 : 0,
|
||||||
borderBottomLeftRadius: 0,
|
borderBottomLeftRadius: 0,
|
||||||
borderTopRightRadius:
|
borderTopRightRadius:
|
||||||
index === nations.length - Math.round(nations.length / 2)
|
index ===
|
||||||
|
awaitedGameDefinitions.nations.length -
|
||||||
|
Math.round(awaitedGameDefinitions.nations.length / 2)
|
||||||
? 16
|
? 16
|
||||||
: 0,
|
: 0,
|
||||||
borderBottomRightRadius:
|
borderBottomRightRadius:
|
||||||
index === nations.length - 1 ? undefined : 0,
|
index === awaitedGameDefinitions.nations.length - 1
|
||||||
|
? undefined
|
||||||
|
: 0,
|
||||||
}}
|
}}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
mutateTankopediaPersistent((draft) => {
|
mutateTankopediaPersistent((draft) => {
|
||||||
@@ -276,7 +284,7 @@ export function Options() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<Flex>
|
<Flex>
|
||||||
{nations.slice(5).map((nation, index) => (
|
{awaitedGameDefinitions.nations.slice(5).map((nation, index) => (
|
||||||
<Button
|
<Button
|
||||||
key={nation}
|
key={nation}
|
||||||
color={filters.nations.includes(nation) ? undefined : 'gray'}
|
color={filters.nations.includes(nation) ? undefined : 'gray'}
|
||||||
@@ -287,9 +295,14 @@ export function Options() {
|
|||||||
borderTopLeftRadius: 0,
|
borderTopLeftRadius: 0,
|
||||||
borderBottomLeftRadius: index === 0 ? 16 : 0,
|
borderBottomLeftRadius: index === 0 ? 16 : 0,
|
||||||
borderTopRightRadius:
|
borderTopRightRadius:
|
||||||
index === nations.length - 1 ? undefined : 0,
|
index === awaitedGameDefinitions.nations.length - 1
|
||||||
|
? undefined
|
||||||
|
: 0,
|
||||||
borderBottomRightRadius:
|
borderBottomRightRadius:
|
||||||
index === nations.length - Math.round(nations.length / 2) - 1
|
index ===
|
||||||
|
awaitedGameDefinitions.nations.length -
|
||||||
|
Math.round(awaitedGameDefinitions.nations.length / 2) -
|
||||||
|
1
|
||||||
? 16
|
? 16
|
||||||
: 0,
|
: 0,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ import { use, useEffect, useMemo, useRef, useState } from 'react';
|
|||||||
import { isMobileOnly } from 'react-device-detect';
|
import { isMobileOnly } from 'react-device-detect';
|
||||||
import { TANK_CLASSES } from '../../../../../components/Tanks/components/Item/constants';
|
import { TANK_CLASSES } from '../../../../../components/Tanks/components/Item/constants';
|
||||||
import { resolveNearPenetration } from '../../../../../core/blitz/resolveNearPenetration';
|
import { resolveNearPenetration } from '../../../../../core/blitz/resolveNearPenetration';
|
||||||
|
import { gameDefinitions } from '../../../../../core/blitzkit/gameDefinitions';
|
||||||
import { modelDefinitions } from '../../../../../core/blitzkit/modelDefinitions';
|
import { modelDefinitions } from '../../../../../core/blitzkit/modelDefinitions';
|
||||||
import { normalizeBoundingBox } from '../../../../../core/blitzkit/normalizeBoundingBox';
|
import { normalizeBoundingBox } from '../../../../../core/blitzkit/normalizeBoundingBox';
|
||||||
import { resolveDpm } from '../../../../../core/blitzkit/resolveDpm';
|
import { resolveDpm } from '../../../../../core/blitzkit/resolveDpm';
|
||||||
import { resolveReload } from '../../../../../core/blitzkit/resolveReload';
|
import { resolveReload } from '../../../../../core/blitzkit/resolveReload';
|
||||||
import {
|
import {
|
||||||
NATIONS,
|
|
||||||
TankDefinition,
|
TankDefinition,
|
||||||
tanksDefinitionsArray,
|
tanksDefinitionsArray,
|
||||||
} from '../../../../../core/blitzkit/tankDefinitions';
|
} from '../../../../../core/blitzkit/tankDefinitions';
|
||||||
@@ -48,7 +48,7 @@ export function TankSearch({
|
|||||||
onSelectAll,
|
onSelectAll,
|
||||||
}: TankSearchProps) {
|
}: TankSearchProps) {
|
||||||
const tanksPerPage = (compact ? 16 : 96) * (isMobileOnly ? 0.5 : 1);
|
const tanksPerPage = (compact ? 16 : 96) * (isMobileOnly ? 0.5 : 1);
|
||||||
const nations = use(NATIONS);
|
const awaitedGameDefinitions = use(gameDefinitions);
|
||||||
const filters = useTankopediaPersistent((state) => state.filters);
|
const filters = useTankopediaPersistent((state) => state.filters);
|
||||||
const sort = useTankopediaPersistent((state) => state.sort);
|
const sort = useTankopediaPersistent((state) => state.sort);
|
||||||
const awaitedTanks = use(tanksDefinitionsArray);
|
const awaitedTanks = use(tanksDefinitionsArray);
|
||||||
@@ -70,7 +70,8 @@ export function TankSearch({
|
|||||||
)
|
)
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
(nations.indexOf(a.nation) - nations.indexOf(b.nation)) *
|
(awaitedGameDefinitions.nations.indexOf(a.nation) -
|
||||||
|
awaitedGameDefinitions.nations.indexOf(b.nation)) *
|
||||||
(sort.direction === 'descending' ? -1 : 1),
|
(sort.direction === 'descending' ? -1 : 1),
|
||||||
),
|
),
|
||||||
[],
|
[],
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import markdownEscape from 'markdown-escape';
|
|||||||
import { TANK_CLASSES } from '../components/Tanks/components/Item/constants';
|
import { TANK_CLASSES } from '../components/Tanks/components/Item/constants';
|
||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import getTankStats from '../core/blitz/getTankStats';
|
import getTankStats from '../core/blitz/getTankStats';
|
||||||
|
import { gameDefinitions } from '../core/blitzkit/gameDefinitions';
|
||||||
import {
|
import {
|
||||||
NATIONS,
|
|
||||||
TankDefinition,
|
TankDefinition,
|
||||||
Tier,
|
Tier,
|
||||||
flags,
|
flags,
|
||||||
@@ -62,7 +62,7 @@ export const ownedTanksCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const awaitedTankDefinitions = await tankDefinitions;
|
const awaitedTankDefinitions = await tankDefinitions;
|
||||||
const awaitedNations = await NATIONS;
|
const awaitedGameDefinitions = await gameDefinitions;
|
||||||
const lines = tankStats
|
const lines = tankStats
|
||||||
.map(({ tank_id }) => awaitedTankDefinitions[tank_id])
|
.map(({ tank_id }) => awaitedTankDefinitions[tank_id])
|
||||||
.filter((tank) => tank.tier === tier)
|
.filter((tank) => tank.tier === tier)
|
||||||
@@ -72,7 +72,8 @@ export const ownedTanksCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
)
|
)
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
awaitedNations.indexOf(a.nation) - awaitedNations.indexOf(b.nation),
|
awaitedGameDefinitions.nations.indexOf(a.nation) -
|
||||||
|
awaitedGameDefinitions.nations.indexOf(b.nation),
|
||||||
)
|
)
|
||||||
.map((tank) => `${flags[tank.nation]} ${markdownEscape(tank.name)}`);
|
.map((tank) => `${flags[tank.nation]} ${markdownEscape(tank.name)}`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { NATIONS } from '../core/blitzkit/tankDefinitions';
|
import { gameDefinitions } from '../core/blitzkit/gameDefinitions';
|
||||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
import { addFilterOptions } from '../core/discord/addFilterOptions';
|
import { addFilterOptions } from '../core/discord/addFilterOptions';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
@@ -18,14 +18,15 @@ import { CommandRegistry } from '../events/interactionCreate';
|
|||||||
import { renderBreakdown } from './breakdown/render';
|
import { renderBreakdown } from './breakdown/render';
|
||||||
|
|
||||||
export const todayCommand = new Promise<CommandRegistry>(async (resolve) => {
|
export const todayCommand = new Promise<CommandRegistry>(async (resolve) => {
|
||||||
const nations = await NATIONS;
|
const awaitedGameDefinitions = await gameDefinitions;
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command: addFilterOptions(
|
command: addFilterOptions(
|
||||||
createLocalizedCommand('today'),
|
createLocalizedCommand('today'),
|
||||||
nations,
|
awaitedGameDefinitions.nations,
|
||||||
).addStringOption(addUsernameChoices),
|
).addStringOption(addUsernameChoices),
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
|
|||||||
@@ -197,18 +197,6 @@ export const tankNames = tanksDefinitionsArray.then((tanks) =>
|
|||||||
|
|
||||||
export type Tier = (typeof TIERS)[number];
|
export type Tier = (typeof TIERS)[number];
|
||||||
|
|
||||||
// TODO: DEPRICATE THISuuu
|
|
||||||
export const NATIONS = tanksDefinitionsArray.then((tanks) => {
|
|
||||||
const nations = Array.from(
|
|
||||||
new Set<string>(Object.values(tanks).map((tank) => tank.nation)),
|
|
||||||
);
|
|
||||||
|
|
||||||
nations.splice(nations.indexOf('other'), 1);
|
|
||||||
nations.push('other');
|
|
||||||
|
|
||||||
return nations;
|
|
||||||
});
|
|
||||||
|
|
||||||
export const flags: Record<string, string> = {
|
export const flags: Record<string, string> = {
|
||||||
ussr: '<:ussr:1218421042033197197>',
|
ussr: '<:ussr:1218421042033197197>',
|
||||||
germany: '🇩🇪',
|
germany: '🇩🇪',
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
SlashCommandSubcommandBuilder,
|
SlashCommandSubcommandBuilder,
|
||||||
SlashCommandSubcommandGroupBuilder,
|
SlashCommandSubcommandGroupBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { NATIONS } from '../blitzkit/tankDefinitions';
|
import { gameDefinitions } from '../blitzkit/gameDefinitions';
|
||||||
import { addFilterOptions } from './addFilterOptions';
|
import { addFilterOptions } from './addFilterOptions';
|
||||||
import { addPeriodSubCommands } from './addPeriodSubCommands';
|
import { addPeriodSubCommands } from './addPeriodSubCommands';
|
||||||
|
|
||||||
@@ -15,9 +15,10 @@ export default async function addPeriodicFilterOptions<
|
|||||||
option: SlashCommandSubcommandBuilder,
|
option: SlashCommandSubcommandBuilder,
|
||||||
) => SlashCommandSubcommandBuilder = (option) => option,
|
) => SlashCommandSubcommandBuilder = (option) => option,
|
||||||
): Promise<OptionType> {
|
): Promise<OptionType> {
|
||||||
const nations = await NATIONS;
|
const awaitedGameDefinitions = await gameDefinitions;
|
||||||
|
|
||||||
addPeriodSubCommands(option, (option) =>
|
addPeriodSubCommands(option, (option) =>
|
||||||
addFilterOptions(extra(option), nations),
|
addFilterOptions(extra(option), awaitedGameDefinitions.nations),
|
||||||
);
|
);
|
||||||
|
|
||||||
return option;
|
return option;
|
||||||
|
|||||||
Reference in new issue
Block a user