mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
fix: more imports
This commit is contained in:
1 parent
25cfb7db74
commit
4f24db0956
182 files changed
+456
-452
No files matched your search
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
PitchLimits,
|
||||
YawLimits,
|
||||
} from '@blitzkit/core/src/blitzkit/modelDefinitions';
|
||||
import { normalizeAngleRad } from '@blitzkit/core/src/math/normalizeAngleRad';
|
||||
import { normalizeAngleRad, PitchLimits, YawLimits } from '@blitzkit/core';
|
||||
import { clamp } from 'lodash';
|
||||
import { degToRad } from 'three/src/math/MathUtils';
|
||||
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import { assertSecret, Region } from '@blitzkit/core';
|
||||
import { EventManager } from '@blitzkit/core/src/blitzkit/eventManager';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
|
||||
const RETRY_ERRORS = ['REQUEST_LIMIT_EXCEEDED', 'SOURCE_NOT_AVAILABLE'];
|
||||
|
||||
export const retryAbleBlitzFetchEvent = new EventManager();
|
||||
export const blitzFetchQueueAvailableEvent = new EventManager();
|
||||
|
||||
type BlitzResponse<Data extends object> =
|
||||
| {
|
||||
status: 'error';
|
||||
error: { field: string; message: string; code: 402; value: null };
|
||||
}
|
||||
| {
|
||||
status: 'ok';
|
||||
data: Data;
|
||||
};
|
||||
|
||||
const MAX_CALLS_PER_SECOND = 10;
|
||||
|
||||
const queue: { url: string; resolve: (data: object) => void }[] = [];
|
||||
let inProgress = 0;
|
||||
|
||||
function decrement() {
|
||||
inProgress--;
|
||||
blitzFetchQueueAvailableEvent.emit(undefined);
|
||||
manageQueue();
|
||||
}
|
||||
|
||||
async function manageQueue() {
|
||||
if (queue.length > 0 && inProgress < MAX_CALLS_PER_SECOND) {
|
||||
inProgress++;
|
||||
|
||||
const timeout = setTimeout(decrement, 1000);
|
||||
const request = queue.shift()!;
|
||||
const data = (await patientFetch(request.url)
|
||||
.then((response) => response.json())
|
||||
.catch((error) => ({ status: 'error', error }))) as BlitzResponse<
|
||||
typeof request.resolve
|
||||
>;
|
||||
|
||||
if (data.status === 'ok') {
|
||||
request.resolve(data.data);
|
||||
} else {
|
||||
if (RETRY_ERRORS.includes(data.error.message)) {
|
||||
retryAbleBlitzFetchEvent.emit(undefined);
|
||||
clearTimeout(timeout);
|
||||
setTimeout(() => {
|
||||
queue.push(request);
|
||||
decrement();
|
||||
}, 1000 / MAX_CALLS_PER_SECOND);
|
||||
} else {
|
||||
clearTimeout(timeout);
|
||||
decrement();
|
||||
|
||||
throw new Error(`Wargaming response error status: "${data.status}"`, {
|
||||
cause: `Message: "${data.error.message}"\nURL: "${request.url}"`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type FetchBlitzParams = Record<string, string | number | undefined>;
|
||||
|
||||
export default function fetchBlitz<Data extends object>(
|
||||
region: Region,
|
||||
path: string,
|
||||
params: FetchBlitzParams = {},
|
||||
) {
|
||||
return new Promise<Data>((resolve) => {
|
||||
queue.push({
|
||||
url: `https://api.wotblitz.${region}/wotb/${path}/?${Object.entries({
|
||||
application_id: assertSecret(
|
||||
process.env.NEXT_PUBLIC_WARGAMING_APPLICATION_ID,
|
||||
),
|
||||
...params,
|
||||
})
|
||||
.filter(([_, value]) => value !== undefined)
|
||||
.map(([key, value]) => `${key}=${encodeURIComponent(value!)}`)
|
||||
.join('&')}`,
|
||||
resolve(data) {
|
||||
resolve(data as Data);
|
||||
},
|
||||
});
|
||||
manageQueue();
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BlitzStats } from '@blitzkit/core';
|
||||
import calculateWN8 from '@blitzkit/core/src/statistics/calculateWN8';
|
||||
import { BlitzStats, calculateWN8 } from '@blitzkit/core';
|
||||
|
||||
export type Stat = keyof ReturnType<typeof generateStats>;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
import { fetchBlitz } from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
interface IndividualAccountAchievements {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { BlitzStats, Region } from '@blitzkit/core';
|
||||
import fetchBlitz, { FetchBlitzParams } from './fetchBlitz';
|
||||
import {
|
||||
FetchBlitzParams,
|
||||
fetchBlitz,
|
||||
} from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
export interface SupplementaryStats {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
import { fetchBlitz } from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
type IndividualClanAccountInfo = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
import { fetchBlitz } from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
interface IndividualClanInfo {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { LEAGUES } from '@blitzkit/core';
|
||||
|
||||
export function getLeagueFromScore(score: number) {
|
||||
return LEAGUES.find(({ minScore }) => score >= minScore)!;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { RatingInfo, Region } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
const cache: Partial<Record<Region, RatingInfo>> = {};
|
||||
|
||||
export default async function getRatingInfo(region: Region) {
|
||||
if (cache[region]) return cache[region]!;
|
||||
|
||||
const response = await patientFetch(
|
||||
context === 'website'
|
||||
? `/api/${region}/rating/current/info`
|
||||
: `https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||
undefined,
|
||||
);
|
||||
const data = (await response.json()) as RatingInfo;
|
||||
|
||||
cache[region] = data;
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { LeagueTop } from '@blitzkit/core/src/blitz/rating';
|
||||
import { RatingPlayer } from '@blitzkit/core/src/statistics/deltaBkrlBlitzStats';
|
||||
import { LeagueTop, RatingPlayer, Region } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
export async function getRatingLeague(
|
||||
region: Region,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RatingNeighbors, Region } from '@blitzkit/core';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import { withCORSProxy } from '../blitzkit/withCORSProxy';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
export async function getRatingNeighbors(
|
||||
region: Region,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { Region, TanksStats } from '@blitzkit/core';
|
||||
import fetchBlitz, { FetchBlitzParams } from './fetchBlitz';
|
||||
import {
|
||||
fetchBlitz,
|
||||
FetchBlitzParams,
|
||||
} from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
|
||||
export default async function getTankStats(
|
||||
export async function getTankStats(
|
||||
region: Region,
|
||||
id: number,
|
||||
params?: FetchBlitzParams,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import getRatingInfo from './getRatingInfo';
|
||||
import { getRatingInfo } from '@blitzkit/core/src/blitz/getRatingInfo';
|
||||
|
||||
export async function isOnGoingRatingSeason() {
|
||||
const ratingInfo = await getRatingInfo('com');
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export function normalizeLeagueIcon(url: string) {
|
||||
return url.startsWith('http') ? url : `https:${url}`;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Region, RegionSubdomain } from "@blitzkit/core";
|
||||
|
||||
export default function regionSubdomainToRegion(
|
||||
regionDomain: RegionSubdomain,
|
||||
): Region {
|
||||
return regionDomain === 'na' ? 'com' : regionDomain;
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Region, RegionSubdomain } from "@blitzkit/core";
|
||||
import { Region, RegionSubdomain } from '@blitzkit/core';
|
||||
|
||||
export default function regionToRegionSubdomain(
|
||||
regionDomain: Region,
|
||||
): RegionSubdomain {
|
||||
export function regionToRegionSubdomain(regionDomain: Region): RegionSubdomain {
|
||||
return regionDomain === 'com' ? 'na' : regionDomain;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { I_HAT } from '@blitzkit/core/src/math/axis';
|
||||
import { I_HAT } from '@blitzkit/core';
|
||||
import { Vector3 } from 'three';
|
||||
|
||||
export function rotateDavaVector(vector: Vector3) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
type CurrentRatingPlayerSearch = Record<
|
||||
number,
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export const usernamePattern = /^[a-zA-Z0-9_]{3,24}$/;
|
||||
export const usernamePatternWithoutPosition = /[a-zA-Z0-9_]{3,24}/;
|
||||
@@ -1,64 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import fetchBlitz from '../fetchBlitz';
|
||||
import { usernamePattern } from './constants';
|
||||
|
||||
export interface AccountListItem {
|
||||
nickname: string;
|
||||
account_id: number;
|
||||
}
|
||||
export type AccountList = AccountListItem[];
|
||||
export type AccountListWithServer = (AccountListItem & {
|
||||
region: Region;
|
||||
})[];
|
||||
|
||||
export default async function searchPlayersAcrossRegions(
|
||||
search: string,
|
||||
limit = 25,
|
||||
) {
|
||||
const trimmedSearch = search.trim();
|
||||
const normalizedLimit = Math.floor(limit / 3);
|
||||
|
||||
if (usernamePattern.test(trimmedSearch)) {
|
||||
return (
|
||||
await Promise.all([
|
||||
fetchBlitz<AccountList>('com', 'account/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
(value) =>
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'com' as Region,
|
||||
})),
|
||||
),
|
||||
fetchBlitz<AccountList>('eu', 'account/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
(value) =>
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'eu' as Region,
|
||||
})),
|
||||
),
|
||||
fetchBlitz<AccountList>('asia', 'account/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
(value) =>
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'asia' as Region,
|
||||
})),
|
||||
),
|
||||
])
|
||||
)
|
||||
.filter(Boolean)
|
||||
.flat() as AccountListWithServer;
|
||||
} else {
|
||||
return [] as AccountListWithServer;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { I_HAT } from '@blitzkit/core/src/math/axis';
|
||||
import { I_HAT } from '@blitzkit/core';
|
||||
import { Vector3 } from 'three';
|
||||
|
||||
export function unrotateDavaVector(vector: Vector3) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { asset } from '@blitzkit/core/src/blitzkit/asset';
|
||||
import { asset } from '@blitzkit/core';
|
||||
|
||||
export interface DiscoveredIdsDefinitions {
|
||||
time: number;
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import getRatingInfo from '../blitz/getRatingInfo';
|
||||
|
||||
interface GitHubTrees {
|
||||
tree: { path: string; url: string }[];
|
||||
}
|
||||
|
||||
let cachedLatestArchivedSeasonNumber: number | null = null;
|
||||
|
||||
export async function getArchivedLatestSeasonNumber() {
|
||||
if (cachedLatestArchivedSeasonNumber !== null) {
|
||||
return cachedLatestArchivedSeasonNumber;
|
||||
}
|
||||
|
||||
const ratingInfo = await getRatingInfo('com');
|
||||
|
||||
if (ratingInfo.detail) {
|
||||
const regionsURL = (
|
||||
(await fetch(
|
||||
`https://api.github.com/repos/tresabhi/${assertSecret(
|
||||
process.env.NEXT_PUBLIC_ASSET_REPO,
|
||||
)}/git/trees/main`,
|
||||
).then((response) => response.json())) as GitHubTrees
|
||||
).tree.find(({ path }) => path === 'regions')!.url;
|
||||
const comURL = (
|
||||
(await fetch(regionsURL).then((response) =>
|
||||
response.json(),
|
||||
)) as GitHubTrees
|
||||
).tree.find(({ path }) => path === 'com')!.url;
|
||||
const ratingURL = (
|
||||
(await fetch(comURL).then((response) => response.json())) as {
|
||||
tree: [{ url: string }];
|
||||
}
|
||||
).tree[0].url;
|
||||
const latestSeason = Math.max(
|
||||
...(
|
||||
(await fetch(ratingURL).then((response) => response.json())) as {
|
||||
tree: { path: string }[];
|
||||
}
|
||||
).tree.map(({ path }) => Number(path)),
|
||||
);
|
||||
|
||||
cachedLatestArchivedSeasonNumber = latestSeason;
|
||||
} else {
|
||||
cachedLatestArchivedSeasonNumber = ratingInfo.current_season - 1;
|
||||
}
|
||||
|
||||
return cachedLatestArchivedSeasonNumber;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import { RatingInfo, Region, asset } from '@blitzkit/core';
|
||||
import { superDecompress } from '@blitzkit/core/src/blitzkit/superDecompress';
|
||||
|
||||
const cache: Record<
|
||||
Region,
|
||||
Record<
|
||||
number,
|
||||
RatingInfo & {
|
||||
detail: undefined;
|
||||
}
|
||||
>
|
||||
> = {
|
||||
com: {},
|
||||
eu: {},
|
||||
asia: {},
|
||||
};
|
||||
|
||||
export default async function getArchivedRatingInfo(
|
||||
region: Region,
|
||||
season: number,
|
||||
) {
|
||||
if (!cache[region][season]) {
|
||||
const info = await fetch(
|
||||
asset(`regions/${region}/rating/${season}/info.cdon.lz4`),
|
||||
)
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) =>
|
||||
superDecompress<RatingInfo & { detail: undefined }>(buffer),
|
||||
);
|
||||
cache[region][season] = info;
|
||||
}
|
||||
|
||||
return cache[region][season];
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import {
|
||||
asset,
|
||||
BkrlDiscriminatedEntries,
|
||||
BkrlReadStream,
|
||||
Region,
|
||||
} from '@blitzkit/core';
|
||||
|
||||
const cache: Record<Region, Record<number, BkrlDiscriminatedEntries>> = {
|
||||
asia: {},
|
||||
eu: {},
|
||||
com: {},
|
||||
};
|
||||
|
||||
export async function getArchivedRatingLeaderboard(
|
||||
region: Region,
|
||||
season: number,
|
||||
) {
|
||||
if (!cache[region][season]) {
|
||||
const info = await fetch(
|
||||
asset(`regions/${region}/rating/${season}/latest.bkrl`),
|
||||
)
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) => new BkrlReadStream(buffer).bkrl());
|
||||
cache[region][season] = info;
|
||||
}
|
||||
|
||||
return cache[region][season];
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import {
|
||||
asset,
|
||||
BkrlDiscriminatedEntries,
|
||||
BkrlReadStream,
|
||||
Region,
|
||||
} from '@blitzkit/core';
|
||||
|
||||
const cache: Record<Region, Record<number, BkrlDiscriminatedEntries | null>> = {
|
||||
com: {},
|
||||
eu: {},
|
||||
asia: {},
|
||||
};
|
||||
|
||||
export default async function getArchivedRatingMidnightLeaderboard(
|
||||
region: Region,
|
||||
season: number,
|
||||
) {
|
||||
if (!cache[region][season]) {
|
||||
const info = await fetch(
|
||||
asset(`regions/${region}/rating/${season}/midnight.bkrl`),
|
||||
)
|
||||
.then((response) =>
|
||||
response.status === 404 ? null : response.arrayBuffer(),
|
||||
)
|
||||
.then((buffer) =>
|
||||
buffer === null ? null : new BkrlReadStream(buffer).bkrl(),
|
||||
);
|
||||
cache[region][season] = info;
|
||||
}
|
||||
|
||||
return cache[region][season];
|
||||
}
|
||||
@@ -6,7 +6,7 @@ const TIME_ZONE_MAPPINGS: Record<Region, number> = {
|
||||
asia: +7, // Central Asia Standard Time
|
||||
};
|
||||
|
||||
export default function getTimeDaysAgo(region: Region, daysAgo: number) {
|
||||
export function getTimeDaysAgo(region: Region, daysAgo: number) {
|
||||
const now = new Date();
|
||||
if (daysAgo === 0) now.getTime() / 1000;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { equipmentDefinitions } from '@blitzkit/core/src/blitzkit/equipmentDefinitions';
|
||||
import { equipmentDefinitions } from '@blitzkit/core';
|
||||
import { EquipmentMatrix } from '../../stores/duel';
|
||||
|
||||
export async function hasEquipment(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { asset } from '@blitzkit/core/src/blitzkit/asset';
|
||||
import { fetchCdonLz4 } from '@blitzkit/core/src/blitzkit/fetchCdonLz4';
|
||||
import { asset, fetchCdonLz4 } from '@blitzkit/core';
|
||||
|
||||
export interface MapDefinitions {
|
||||
[id: number]: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EventManager } from '@blitzkit/core/src/blitzkit/eventManager';
|
||||
import { EventManager } from '@blitzkit/core';
|
||||
import { invalidate } from '@react-three/fiber';
|
||||
|
||||
export interface ModelTransformEventData {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BKNI_COLORS, BkniPercentile } from '@blitzkit/core';
|
||||
import getBkniPercentile from '@blitzkit/core/src/statistics/getBkniPercentile';
|
||||
import { BKNI_COLORS, BkniPercentile, getBkniPercentile } from '@blitzkit/core';
|
||||
|
||||
export function parseBkni(bkni: number) {
|
||||
const bkniFraction = (bkni + 1) / 2;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EventManager } from '@blitzkit/core/src/blitzkit/eventManager';
|
||||
import { EventManager } from '@blitzkit/core';
|
||||
|
||||
export enum Pose {
|
||||
HullDown,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ModelArmor } from '@blitzkit/core/src/blitzkit/modelDefinitions';
|
||||
import { ModelArmor } from '@blitzkit/core';
|
||||
|
||||
export function resolveArmor(armor: ModelArmor, index: number) {
|
||||
const spaced = armor.spaced?.includes(index) ?? false;
|
||||
const thickness = index === -1 ? 0 : armor.thickness[index] ?? 0;
|
||||
const thickness = index === -1 ? 0 : (armor.thickness[index] ?? 0);
|
||||
|
||||
return { spaced, thickness };
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { tankIcon } from '@blitzkit/core/src/blitzkit/tankIcon';
|
||||
import { tankIcon } from '@blitzkit/core';
|
||||
import { iconPng } from './iconPng';
|
||||
|
||||
export function tankIconPng(id: number) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { TankDefinition } from '@blitzkit/core';
|
||||
import { ProvisionDefinitions } from '@blitzkit/core/src/blitzkit/provisionDefinitions';
|
||||
import { ProvisionDefinitions, TankDefinition } from '@blitzkit/core';
|
||||
import { uniqueId } from 'lodash';
|
||||
import { CompareMember } from '../../stores/compareEphemeral';
|
||||
import { tankToDuelMember } from './tankToDuelMember';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { TankDefinition } from '@blitzkit/core';
|
||||
import { availableProvisions } from '@blitzkit/core/src/blitzkit/availableProvisions';
|
||||
import { ProvisionDefinitions } from '@blitzkit/core/src/blitzkit/provisionDefinitions';
|
||||
import {
|
||||
availableProvisions,
|
||||
ProvisionDefinitions,
|
||||
TankDefinition,
|
||||
} from '@blitzkit/core';
|
||||
import { DuelMember } from '../../stores/duel';
|
||||
import { genericDefaultEquipmentMatrix } from '../../stores/duel/constants';
|
||||
|
||||
|
||||
Reference in new issue
Block a user