mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
fix: no cross-bot imports
This commit is contained in:
1 parent
6c0b46725d
commit
7c6f381bbe
58 files changed
+233
-252
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { blitzStarsTankAverages } from '@blitzkit/core/src/blitzstars/tankAverages';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { tankAverages } from '../../../core/blitzstars/tankAverages';
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await tankAverages);
|
||||
return NextResponse.json(await blitzStarsTankAverages);
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import { TankCharacteristics } from '@blitzkit/core';
|
||||
import { TankCharacteristics, Var } from '@blitzkit/core';
|
||||
import {
|
||||
CaretLeftIcon,
|
||||
CaretRightIcon,
|
||||
CaretSortIcon,
|
||||
} from '@radix-ui/react-icons';
|
||||
import { Flex, IconButton, Table, Text } from '@radix-ui/themes';
|
||||
import { theme } from '../../../../../../bot/src/stitches.config';
|
||||
import { StickyRowHeaderCell } from '../../../../components/StickyRowHeaderCell';
|
||||
import * as CompareEphemeral from '../../../../stores/compareEphemeral';
|
||||
import * as ComparePersistent from '../../../../stores/comparePersistent';
|
||||
@@ -103,8 +102,8 @@ export function CompareRow({
|
||||
const resolvedDisplayValue = display
|
||||
? display(stats[index])
|
||||
: decimals === undefined
|
||||
? value
|
||||
: value?.toFixed(decimals);
|
||||
? value
|
||||
: value?.toFixed(decimals);
|
||||
|
||||
return (
|
||||
<Table.Cell
|
||||
@@ -117,12 +116,12 @@ export function CompareRow({
|
||||
value === values[0]
|
||||
? undefined
|
||||
: (
|
||||
deltaType === 'higherIsBetter'
|
||||
? value > values[0]
|
||||
: value < values[0]
|
||||
)
|
||||
? `color-mix(in srgb, ${theme.colors.componentCallToActionInteractive_green} ${normalizedDeltaPercentage}%, ${theme.colors.componentCallToActionInteractive_green}00)`
|
||||
: `color-mix(in srgb, ${theme.colors.componentCallToActionInteractive_red} ${normalizedDeltaPercentage}%, ${theme.colors.componentCallToActionInteractive_red}00)`,
|
||||
deltaType === 'higherIsBetter'
|
||||
? value > values[0]
|
||||
: value < values[0]
|
||||
)
|
||||
? `color-mix(in srgb, ${Var('green-7')} ${normalizedDeltaPercentage}%, ${Var('green-3')})`
|
||||
: `color-mix(in srgb, ${Var('red-7')} ${normalizedDeltaPercentage}%, ${Var('red-3')})`,
|
||||
}}
|
||||
>
|
||||
<Flex
|
||||
@@ -149,8 +148,8 @@ export function CompareRow({
|
||||
deltaNominalDisplay
|
||||
? deltaNominalDisplay(delta)
|
||||
: decimals === undefined
|
||||
? delta
|
||||
: delta.toFixed(decimals)
|
||||
? delta
|
||||
: delta.toFixed(decimals)
|
||||
}`}
|
||||
)
|
||||
</Text>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
TankCharacteristics,
|
||||
Var,
|
||||
asset,
|
||||
availableProvisions,
|
||||
checkConsumableProvisionInclusivity,
|
||||
@@ -13,7 +14,6 @@ import { ComponentPlaceholderIcon } from '@radix-ui/react-icons';
|
||||
import { Button, Flex, Popover, Slider, Table, Text } from '@radix-ui/themes';
|
||||
import { debounce, times } from 'lodash';
|
||||
import { use } from 'react';
|
||||
import { theme } from '../../../../../../bot/src/stitches.config';
|
||||
import { BlitzkitButtonGrayIcon } from '../../../../components/BlitzkitButtonGrayIcon';
|
||||
import { ConsumablesManager } from '../../../../components/ConsumablesManager';
|
||||
import { CrewSkillManager } from '../../../../components/CrewSkillManager';
|
||||
@@ -83,12 +83,7 @@ export function CompareTable({ stats }: CompareTableProps) {
|
||||
<Popover.Root>
|
||||
<Popover.Trigger>
|
||||
<Button variant="ghost" radius="large">
|
||||
<Flex
|
||||
direction="column"
|
||||
style={{
|
||||
gap: 2,
|
||||
}}
|
||||
>
|
||||
<Flex direction="column" style={{ gap: 2 }}>
|
||||
{Object.entries(awaitedSkillDefinitions.classes).map(
|
||||
([tankClass, skills]) => (
|
||||
<Flex key={tankClass} style={{ gap: 2 }}>
|
||||
@@ -101,10 +96,10 @@ export function CompareTable({ stats }: CompareTableProps) {
|
||||
borderRadius: 2,
|
||||
backgroundColor:
|
||||
crewSkills[skill] === 0
|
||||
? theme.colors.textLowContrast
|
||||
? Var('gray-11')
|
||||
: permanentSkills.includes(skill)
|
||||
? theme.colors.textLowContrast_crimson
|
||||
: theme.colors.textLowContrast_amber,
|
||||
? Var('crimson-11')
|
||||
: Var('amber-11'),
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
@@ -381,9 +376,8 @@ export function CompareTable({ stats }: CompareTableProps) {
|
||||
height: 8,
|
||||
backgroundColor:
|
||||
equipment === -1
|
||||
? theme.colors
|
||||
.textLowContrast_crimson
|
||||
: theme.colors.textLowContrast,
|
||||
? Var('crimson-11')
|
||||
: Var('gray-11'),
|
||||
borderRadius: 2,
|
||||
}}
|
||||
/>
|
||||
@@ -393,9 +387,8 @@ export function CompareTable({ stats }: CompareTableProps) {
|
||||
height: 8,
|
||||
backgroundColor:
|
||||
equipment === 1
|
||||
? theme.colors
|
||||
.textLowContrast_crimson
|
||||
: theme.colors.textLowContrast,
|
||||
? Var('crimson-11')
|
||||
: Var('gray-11'),
|
||||
borderRadius: 2,
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Var } from '@blitzkit/core';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { theme } from '../../../../../../../bot/src/stitches.config';
|
||||
import { insertionMarkers } from './constants';
|
||||
|
||||
export function InsertionMarker({ index }: { index: number }) {
|
||||
@@ -28,7 +28,7 @@ export function InsertionMarker({ index }: { index: number }) {
|
||||
height: '75%',
|
||||
width: 2,
|
||||
borderRadius: 1,
|
||||
backgroundColor: theme.colors.textLowContrast_crimson,
|
||||
backgroundColor: Var('crimson-11'),
|
||||
position: 'absolute',
|
||||
right: 0,
|
||||
top: '50%',
|
||||
|
||||
@@ -6,7 +6,10 @@ import {
|
||||
Region,
|
||||
REGIONS,
|
||||
UNLOCALIZED_REGION_NAMES,
|
||||
Var,
|
||||
} from '@blitzkit/core';
|
||||
import { RatingInfo } from '@blitzkit/core/src/blitz/leagues';
|
||||
import { RatingPlayer } from '@blitzkit/core/src/statistics/deltaBkrlBlitzStats';
|
||||
import { blackA, orangeDark } from '@radix-ui/colors';
|
||||
import { MagnifyingGlassIcon } from '@radix-ui/react-icons';
|
||||
import {
|
||||
@@ -22,11 +25,6 @@ import { produce } from 'immer';
|
||||
import { debounce, range } from 'lodash';
|
||||
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
||||
import { create } from 'zustand';
|
||||
import {
|
||||
RatingInfo,
|
||||
RatingPlayer,
|
||||
} from '../../../../../bot/src/commands/ratingLeaderboard';
|
||||
import { theme } from '../../../../../bot/src/stitches.config';
|
||||
import PageWrapper from '../../../components/PageWrapper';
|
||||
import { Skeleton } from '../../../components/Skeleton';
|
||||
import fetchBlitz from '../../../core/blitz/fetchBlitz';
|
||||
@@ -1008,9 +1006,7 @@ export default function Page() {
|
||||
return (
|
||||
<Table.Row
|
||||
style={{
|
||||
backgroundColor: highlight
|
||||
? theme.colors.componentInteractiveActive_orange
|
||||
: 'unset',
|
||||
backgroundColor: highlight ? Var('orange-9') : 'unset',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
key={`${region}${season}${index}`}
|
||||
@@ -1023,14 +1019,14 @@ export default function Page() {
|
||||
<Flex gap="2">
|
||||
{names[region][id] === null
|
||||
? `Deleted player ${id}`
|
||||
: names[region][id]?.nickname ?? (
|
||||
: (names[region][id]?.nickname ?? (
|
||||
<Skeleton
|
||||
style={{
|
||||
height: 16,
|
||||
width: Math.random() * 128 + 128,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
))}
|
||||
{clan ? (
|
||||
<Text color="gray">{`[${clan}]`}</Text>
|
||||
) : (
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
idToRegion,
|
||||
tankDefinitions,
|
||||
} from '@blitzkit/core';
|
||||
import { blitzStarsTankAverages } from '@blitzkit/core/src/blitzstars/tankAverages';
|
||||
import {
|
||||
ArrowDownIcon,
|
||||
MagnifyingGlassIcon,
|
||||
@@ -45,7 +46,6 @@ import getTankStats from '../../../core/blitz/getTankStats';
|
||||
import searchPlayersAcrossRegions, {
|
||||
AccountListWithServer,
|
||||
} from '../../../core/blitz/searchPlayersAcrossRegions';
|
||||
import { tankAverages } from '../../../core/blitzstars/tankAverages';
|
||||
import * as Session from '../../../stores/session';
|
||||
|
||||
export default function Page({
|
||||
@@ -55,7 +55,7 @@ export default function Page({
|
||||
}) {
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const awaitedTankDefinitions = use(tankDefinitions);
|
||||
const awaitedTankAvearges = use(tankAverages);
|
||||
const awaitedTankAvearges = use(blitzStarsTankAverages);
|
||||
const [showSearch, setShowSearch] = useState(false);
|
||||
const [searching, setSearching] = useState(false);
|
||||
const [searchResults, setSearchResults] = useState<AccountListWithServer>([]);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { provisionDefinitions } from '@blitzkit/core';
|
||||
import { TREE_TYPE_ICONS } from '@blitzkit/core/src/blitzkit/tankDefinitions/constants';
|
||||
import { CaretRightIcon, UpdateIcon } from '@radix-ui/react-icons';
|
||||
import { Button, Dialog, Flex, Heading } from '@radix-ui/themes';
|
||||
import Link from 'next/link';
|
||||
@@ -6,8 +8,6 @@ import { pushTankopediaPath } from '../../../../../core/blitzkit/pushTankopediaP
|
||||
import { tankToDuelMember } from '../../../../../core/blitzkit/tankToDuelMember';
|
||||
import * as Duel from '../../../../../stores/duel';
|
||||
import { TankSearch } from '../../components/TankSearch';
|
||||
import { provisionDefinitions } from '@blitzkit/core';
|
||||
import { TREE_TYPE_ICONS } from '../../../../../../../bot/src/components/Tanks/components/Item/constants';
|
||||
|
||||
export function Title() {
|
||||
const awaitedProvisionDefinitions = use(provisionDefinitions);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { RatingInfo } from '../../../../bot/src/commands/ratingLeaderboard';
|
||||
import { RatingInfo, Region } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import {
|
||||
LeagueTop,
|
||||
RatingPlayer,
|
||||
} from '../../../../bot/src/commands/ratingLeaderboard';
|
||||
import { LeagueTop } from '@blitzkit/core/src/blitz/rating';
|
||||
import { RatingPlayer } from '@blitzkit/core/src/statistics/deltaBkrlBlitzStats';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { RatingNeighbors } from '../../../../bot/src/commands/ratingLeaderboard';
|
||||
import { RatingNeighbors, Region } from '@blitzkit/core';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import { withCORSProxy } from '../blitzkit/withCORSProxy';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import { tankDefinitions, tankNames } from '@blitzkit/core';
|
||||
import { Locale } from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { tankNamesTechTreeOnly } from '../../../../bot/src/core/discord/autocompleteTanks';
|
||||
import { translator } from '../../../../bot/src/core/localization/translator';
|
||||
import { UserError } from '../../hooks/userError';
|
||||
|
||||
export default async function resolveTankId(
|
||||
tank: string | number,
|
||||
locale: Locale,
|
||||
techTreeOnly = false,
|
||||
) {
|
||||
const { translate } = translator(locale);
|
||||
const number = typeof tank === 'string' ? Number(tank) : tank;
|
||||
|
||||
if (Number.isNaN(number)) {
|
||||
const searchResult = go(
|
||||
`${tank}`,
|
||||
await (techTreeOnly ? tankNamesTechTreeOnly : tankNames),
|
||||
{
|
||||
keys: ['searchableName', 'searchableNameDeburr', 'camouflages'],
|
||||
limit: 1,
|
||||
},
|
||||
);
|
||||
|
||||
if (searchResult.length === 0) {
|
||||
throw new UserError(
|
||||
translate('bot.common.errors.tank_name_not_found', [
|
||||
markdownEscape(`${tank}`),
|
||||
]),
|
||||
);
|
||||
} else {
|
||||
return searchResult[0].obj.id;
|
||||
}
|
||||
} else {
|
||||
if ((await tankDefinitions)[number]) {
|
||||
return number;
|
||||
} else {
|
||||
throw new UserError(
|
||||
translate('bot.common.errors.tank_id_not_found', [`${number}`]),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { ClanList } from '../../../../bot/src/types/clanList';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
|
||||
export default async function searchClansAcrossRegions(
|
||||
search: string,
|
||||
limit = 25,
|
||||
) {
|
||||
const trimmed = search.trim();
|
||||
if (trimmed.length < 3 && trimmed.length > 100) return [];
|
||||
const normalizedLimit = Math.floor(limit / 3);
|
||||
|
||||
// TODO: remove splice once wargaming fixes the functionality of the limit felid
|
||||
|
||||
return (
|
||||
await Promise.all([
|
||||
fetchBlitz<ClanList>('com', 'clans/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then((value) =>
|
||||
value
|
||||
.map((account) => ({
|
||||
...account,
|
||||
region: 'com' as Region,
|
||||
}))
|
||||
.splice(0, normalizedLimit),
|
||||
),
|
||||
fetchBlitz<ClanList>('eu', 'clans/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then((value) =>
|
||||
value
|
||||
.map((account) => ({
|
||||
...account,
|
||||
region: 'eu' as Region,
|
||||
}))
|
||||
.splice(0, normalizedLimit),
|
||||
),
|
||||
fetchBlitz<ClanList>('asia', 'clans/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then((value) =>
|
||||
value
|
||||
.map((account) => ({
|
||||
...account,
|
||||
region: 'asia' as Region,
|
||||
}))
|
||||
.splice(0, normalizedLimit),
|
||||
),
|
||||
])
|
||||
)
|
||||
.filter(Boolean)
|
||||
.flat();
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import {
|
||||
StatFilters,
|
||||
tankDefinitions,
|
||||
Tier,
|
||||
TIER_ROMAN_NUMERALS,
|
||||
} from '@blitzkit/core';
|
||||
import { Locale } from 'discord.js';
|
||||
import { translator } from '../../../../bot/src/core/localization/translator';
|
||||
|
||||
export async function filtersToDescription(
|
||||
{ nation, tier, tankType, treeType, tank }: StatFilters,
|
||||
locale: Locale,
|
||||
) {
|
||||
const { translate } = translator(locale);
|
||||
const awaitedTankDefinitions = await tankDefinitions;
|
||||
const info: string[] = [];
|
||||
|
||||
// TODO: somehow localize tank names?
|
||||
if (tank) return awaitedTankDefinitions[tank].name;
|
||||
if (nation) info.push(translate(`common.nations.${nation}`));
|
||||
if (tier) {
|
||||
info.push(
|
||||
translate('bot.common.filters.tier', [TIER_ROMAN_NUMERALS[tier as Tier]]),
|
||||
);
|
||||
}
|
||||
if (tankType) info.push(translate(`common.tank_class_short.${tankType}`));
|
||||
if (treeType) info.push(translate(`common.tree_type.${treeType}`));
|
||||
|
||||
return info.length === 0
|
||||
? translate('bot.common.filters.none')
|
||||
: info.join(', ');
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Region, asset } from '@blitzkit/core';
|
||||
import { RatingInfo } from '@blitzkit/core/src/blitz/leagues';
|
||||
import { superDecompress } from '@blitzkit/core/src/blitzkit/superDecompress';
|
||||
import { RatingInfo } from '../../../../bot/src/commands/ratingLeaderboard';
|
||||
|
||||
const cache: Record<
|
||||
Region,
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import { usersDatabase } from '@blitzkit/core';
|
||||
import { client } from '../../../../bot/src/core/discord/client';
|
||||
|
||||
const EXIT_EVENTS = [
|
||||
'beforeExit',
|
||||
'exit',
|
||||
'SIGINT',
|
||||
'SIGTERM',
|
||||
'SIGUSR1',
|
||||
'SIGUSR2',
|
||||
];
|
||||
|
||||
async function cleanup() {
|
||||
console.log('Cleaning up...');
|
||||
|
||||
await Promise.all([usersDatabase.$disconnect(), client.destroy()]);
|
||||
|
||||
console.log('Gracefully exiting...');
|
||||
|
||||
EXIT_EVENTS.forEach((event) => process.off(event, cleanup));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
export function registerProcesses() {
|
||||
process.on('uncaughtException', console.error);
|
||||
client.on('error', console.error);
|
||||
|
||||
EXIT_EVENTS.forEach((event) => process.on(event, cleanup));
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import buttonLink from '../../../../bot/src/core/discord/buttonLink';
|
||||
import { getAccountInfo } from '../blitz/getAccountInfo';
|
||||
|
||||
export async function getBlitzStarsLinkButton(
|
||||
region: Region,
|
||||
id: number,
|
||||
tankId?: number,
|
||||
) {
|
||||
const { nickname } = await getAccountInfo(region, id);
|
||||
|
||||
return buttonLink(
|
||||
`https://www.blitzstars.com/player/${region}/${nickname}${
|
||||
tankId ? `/tank/${tankId!}` : ''
|
||||
}`,
|
||||
'BlitzStars',
|
||||
);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
import { Region, emptyAllStats } from '@blitzkit/core';
|
||||
import {
|
||||
GetHistoriesOptions,
|
||||
Histories,
|
||||
History,
|
||||
getHistoriesDefaultOptions,
|
||||
} from '../../../../bot/src/types/histories';
|
||||
import { getAccountInfo } from '../blitz/getAccountInfo';
|
||||
import { PlayerStats } from './getPlayerStats';
|
||||
|
||||
export default async function getPlayerHistories(
|
||||
server: Region,
|
||||
id: number,
|
||||
options?: Partial<GetHistoriesOptions>,
|
||||
) {
|
||||
const mergedOptions = { ...getHistoriesDefaultOptions, ...options };
|
||||
const response = await fetch(
|
||||
`https://www.blitzstars.com/api/playerstats/${id}`,
|
||||
);
|
||||
const playerHistories = ((await response.json()) as PlayerStats).map(
|
||||
(history) =>
|
||||
({
|
||||
all: history.statistics.all,
|
||||
last_battle_time: history.last_battle_time,
|
||||
} satisfies History),
|
||||
);
|
||||
let lastNonCompliantIndex = -1;
|
||||
let hasCompliedOnce = false;
|
||||
const filtered = playerHistories.filter(({ last_battle_time }, index) => {
|
||||
const complies =
|
||||
last_battle_time >= mergedOptions.start &&
|
||||
last_battle_time <= mergedOptions.end;
|
||||
|
||||
if (complies && !hasCompliedOnce) hasCompliedOnce = true;
|
||||
if (!hasCompliedOnce) lastNonCompliantIndex = index;
|
||||
|
||||
return complies;
|
||||
});
|
||||
|
||||
const latestNodes: Histories = [];
|
||||
|
||||
if (mergedOptions.includeLatestHistories) {
|
||||
const { last_battle_time, statistics } = await getAccountInfo(server, id);
|
||||
|
||||
latestNodes.push({ all: statistics.all, last_battle_time });
|
||||
}
|
||||
|
||||
const previousNodes: Histories = [];
|
||||
|
||||
if (mergedOptions.includePreviousHistories) {
|
||||
if (lastNonCompliantIndex !== -1) {
|
||||
previousNodes.push(
|
||||
playerHistories[lastNonCompliantIndex] ??
|
||||
({
|
||||
all: emptyAllStats,
|
||||
last_battle_time: -Infinity,
|
||||
} satisfies History),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return [...latestNodes, ...filtered, ...previousNodes] satisfies Histories;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import { BlitzStats, Region } from '@blitzkit/core';
|
||||
|
||||
interface IndividualPlayerStats {
|
||||
clan: { clan_id: number; name: string; tag: string };
|
||||
statistics: {
|
||||
all: BlitzStats;
|
||||
wn8: number;
|
||||
wn7: number;
|
||||
average_tier: number;
|
||||
};
|
||||
last_battle_time: number;
|
||||
nickname: string;
|
||||
account_id: number;
|
||||
achievements: {
|
||||
account_id: number;
|
||||
[key: string]: number;
|
||||
};
|
||||
region: Region;
|
||||
}
|
||||
|
||||
export type PlayerStats = IndividualPlayerStats[];
|
||||
|
||||
export async function getPlayerStats<
|
||||
Ids extends number | number[],
|
||||
ReturnType = Ids extends number ? PlayerStats : PlayerStats[],
|
||||
>(region: Region, ids: Ids) {
|
||||
const stats = await Promise.all(
|
||||
((typeof ids === 'number' ? [ids] : ids) as number[]).map((id) =>
|
||||
fetch(`https://www.blitzstars.com/api/playerstats/${id}`).then(
|
||||
(response) => response.json() as Promise<PlayerStats>,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (typeof ids === 'number') return stats[0] as ReturnType;
|
||||
return stats as ReturnType;
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
import { BlitzStats, tankDefinitions } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
|
||||
interface SpecialStats {
|
||||
winrate: number;
|
||||
damageRatio: number;
|
||||
kdr: number;
|
||||
damagePerBattle: number;
|
||||
killsPerBattle: number;
|
||||
hitsPerBattle: number;
|
||||
spotsPerBattle: number;
|
||||
wpm: number;
|
||||
dpm: number;
|
||||
kpm: number;
|
||||
hitRate: number;
|
||||
survivalRate: number;
|
||||
}
|
||||
|
||||
export type Percentiles = [
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
];
|
||||
|
||||
export interface SpecialPercentiles {
|
||||
winRate: Percentiles;
|
||||
damageRatio: Percentiles;
|
||||
kdr: Percentiles;
|
||||
damagePerBattle: Percentiles;
|
||||
killsPerBattle: Percentiles;
|
||||
hitsPerBattle: Percentiles;
|
||||
spotsPerBattle: Percentiles;
|
||||
wpm: Percentiles;
|
||||
dpm: Percentiles;
|
||||
kpm: Percentiles;
|
||||
hitRate: Percentiles;
|
||||
survivalRate: Percentiles;
|
||||
}
|
||||
|
||||
export interface MeanSd {
|
||||
winrateMean: number;
|
||||
winrateSd: number;
|
||||
hitRateMean: number;
|
||||
hitRateSd: number;
|
||||
survivalRateMean: number;
|
||||
survivalRateSd: number;
|
||||
damageRatioMean: number;
|
||||
damageRatioSd: number;
|
||||
kdrMean: number;
|
||||
kdrSd: number;
|
||||
dpbMean: number;
|
||||
dpbSd: number;
|
||||
kpbMean: number;
|
||||
kpbSd: number;
|
||||
hpbMean: number;
|
||||
hpbSd: number;
|
||||
spbMean: number;
|
||||
spbSd: number;
|
||||
}
|
||||
|
||||
export interface IndividualTankAverage {
|
||||
_id: number;
|
||||
battle_life_time: number;
|
||||
total_battle_life_time: number;
|
||||
number_of_players: number;
|
||||
tank_id: number;
|
||||
all: BlitzStats;
|
||||
special: SpecialStats;
|
||||
percentiles: SpecialPercentiles;
|
||||
percentiles_player_count: number;
|
||||
meanSd: MeanSd;
|
||||
shotEff: number;
|
||||
last_update: number;
|
||||
}
|
||||
|
||||
tankDefinitions;
|
||||
|
||||
export type TankAverages = Record<number, IndividualTankAverage>;
|
||||
|
||||
export const tankAverages = fetch(
|
||||
context === 'website'
|
||||
? '/api/tank-averages'
|
||||
: 'https://www.blitzstars.com/api/tankaverages.json',
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
if (context === 'server') {
|
||||
const partialTankAverages: TankAverages = {};
|
||||
|
||||
(json as IndividualTankAverage[]).forEach((individualTankAverage) => {
|
||||
partialTankAverages[individualTankAverage.tank_id] =
|
||||
individualTankAverage;
|
||||
});
|
||||
|
||||
return partialTankAverages;
|
||||
} else {
|
||||
return json as TankAverages;
|
||||
}
|
||||
});
|
||||
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
declare module '*.glsl' {
|
||||
const value: string;
|
||||
export default value;
|
||||
}
|
||||
Reference in new issue
Block a user