From b060e65af566b20effc83e405b5b7d5abd786925 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Sun, 2 Aug 2026 20:28:57 -0500 Subject: [PATCH] dynamically import client api --- .../core/src/statistics/getTierWeights.ts | 22 --- packages/core/src/statistics/index.ts | 17 +-- packages/scripts/src/applyPatches.ts | 140 +++++++++--------- .../website/src/components/TankCard/index.tsx | 6 +- packages/website/src/core/blitzkit/api.ts | 8 +- 5 files changed, 82 insertions(+), 111 deletions(-) delete mode 100644 packages/core/src/statistics/getTierWeights.ts diff --git a/packages/core/src/statistics/getTierWeights.ts b/packages/core/src/statistics/getTierWeights.ts deleted file mode 100644 index 6144b078f..000000000 --- a/packages/core/src/statistics/getTierWeights.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { fetchTankDefinitions } from '../blitzkit'; -import type { BlitzStats } from './compositeStats/constants'; - -export async function getTierWeights( - stats: Record, - order: number[] = Object.keys(stats).map(parseInt), -) { - const tankDefinitions = await fetchTankDefinitions(); - const tierWeights: TierWeightsRecord = {}; - - order.forEach((id) => { - const entry = tankDefinitions.tanks[id]; - - if (!entry) return; - if (!tierWeights[entry.tier]) tierWeights[entry.tier] = 0; - - tierWeights[entry.tier]! += stats[id].battles; - }); - - return tierWeights; -} -export type TierWeightsRecord = Partial>; diff --git a/packages/core/src/statistics/index.ts b/packages/core/src/statistics/index.ts index 81288f813..adad33644 100644 --- a/packages/core/src/statistics/index.ts +++ b/packages/core/src/statistics/index.ts @@ -1,9 +1,8 @@ -export * from './calculateWN8'; -export * from './compositeStats'; -export * from './deltaBkrlBlitzStats'; -export * from './deltaTankStats'; -export * from './getBkniPercentile'; -export * from './getTierWeights'; -export * from './getWN8Percentile'; -export * from './percentiles'; -export * from './sumAllStats'; +export * from "./calculateWN8"; +export * from "./compositeStats"; +export * from "./deltaBkrlBlitzStats"; +export * from "./deltaTankStats"; +export * from "./getBkniPercentile"; +export * from "./getWN8Percentile"; +export * from "./percentiles"; +export * from "./sumAllStats"; diff --git a/packages/scripts/src/applyPatches.ts b/packages/scripts/src/applyPatches.ts index 2c3833188..18aaf6ba3 100644 --- a/packages/scripts/src/applyPatches.ts +++ b/packages/scripts/src/applyPatches.ts @@ -5,7 +5,6 @@ import { parse as parsePath } from "path"; import ProgressBar from "progress"; import { parse as parseYaml, stringify as stringifyYaml } from "yaml"; import { PATCHES_ROOT, vfs } from "./buildAssets/constants"; -import { writeDVPL } from "./core/blitz/writeDVPL"; const versionTextFile = await vfs.text(`Data/version.txt`); const currentVersion = versionTextFile @@ -24,83 +23,80 @@ while (true) { )}/dlc/s${currentVersion}_${patchIndex}.yaml`, ); - console.log(patchIndex, response.status) + console.log(patchIndex, response.status); if (!response.ok) break; - - console.log(`Applying patch ${patchIndex}...`); - const data = parseYaml(await response.text()); - const dvpm = await fetch( - `${assertSecret(import.meta.env.WOTB_DLC_CDN)}/dlc/${data.dx11}`, - ).then((response) => response.arrayBuffer()); - const dvpd = await fetch( - `${assertSecret(import.meta.env.WOTB_DLC_CDN)}/dlc/${data.dx11.replace( - ".dvpm", - ".dvpd", - )}`, - ).then((response) => response.arrayBuffer()); - const files = await dvp(dvpm, dvpd); - const bar = new ProgressBar( - `Patching ${files.length} files :bar`, - files.length, + console.log(`Applying patch ${patchIndex}...`); + + const data = parseYaml(await response.text()); + const dvpm = await fetch( + `${assertSecret(import.meta.env.WOTB_DLC_CDN)}/dlc/${data.dx11}`, + ).then((response) => response.arrayBuffer()); + const dvpd = await fetch( + `${assertSecret(import.meta.env.WOTB_DLC_CDN)}/dlc/${data.dx11.replace( + ".dvpm", + ".dvpd", + )}`, + ).then((response) => response.arrayBuffer()); + const files = await dvp(dvpm, dvpd); + const bar = new ProgressBar( + `Patching ${files.length} files :bar`, + files.length, + ); + + for (const { path, data } of files) { + console.log(`Patching "${path}"...`); + + const { dir } = parsePath(path); + + try { + await mkdir(`${PATCHES_ROOT}/Data/${dir}`, { recursive: true }); + } catch (error) { + console.warn(`Failed to make directory "${dir}"`); + } + + const buffer = Buffer.from(data); + + await writeFile(`${PATCHES_ROOT}/Data/${path}`, new Uint8Array(buffer)); + + bar.tick(); + } + + console.log("patches done for patch"); + + if ("dynamicContentLocalizationsDir" in data) { + console.log( + `${assertSecret(import.meta.env.WOTB_DLC_CDN)}/dlc/${ + data.dynamicContentLocalizationsDir + }/en.yaml`, ); + const localizationsResponse = await fetch( + `${assertSecret(import.meta.env.WOTB_DLC_CDN)}/dlc/${ + data.dynamicContentLocalizationsDir + }/en.yaml`, + ); + console.log("fetched"); + const newStrings = parseYaml(await localizationsResponse.text()); + console.log("got new strings"); + const oldStrings = + await vfs.yaml>(`Data/Strings/en.yaml`); + console.log("got old strings"); + const patchedStrings = { ...oldStrings, ...newStrings }; + const patchedContent = stringifyYaml(patchedStrings); + console.log("stringified"); - for (const { path, data } of files) { - console.log(`Patching "${path}"...`); + await mkdir(`${PATCHES_ROOT}/Data/Strings`, { recursive: true }); + console.log("mkdir"); + await writeFile( + `${PATCHES_ROOT}/Data/Strings/en.yaml`, + new Uint8Array(Buffer.from(patchedContent)), + ); + console.log("file"); + } - const { dir } = parsePath(path); - - try { - await mkdir(`${PATCHES_ROOT}/Data/${dir}`, { recursive: true }); - } catch (error) { - console.warn(`Failed to make directory "${dir}"`); - } - - const buffer = Buffer.from(data); - - await writeFile( - `${PATCHES_ROOT}/Data/${path}`, - new Uint8Array(buffer), - ); - - bar.tick(); - } - - console.log('patches done for patch') - - if ("dynamicContentLocalizationsDir" in data) { - console.log( - `${assertSecret(import.meta.env.WOTB_DLC_CDN)}/dlc/${ - data.dynamicContentLocalizationsDir - }/en.yaml`, - ); - const localizationsResponse = await fetch( - `${assertSecret(import.meta.env.WOTB_DLC_CDN)}/dlc/${ - data.dynamicContentLocalizationsDir - }/en.yaml`, - ); - console.log('fetched') - const newStrings = parseYaml(await localizationsResponse.text()); - console.log('got new strings') - const oldStrings = - await vfs.yaml>(`Data/Strings/en.yaml`); - console.log('got old strings') - const patchedStrings = { ...oldStrings, ...newStrings }; - const patchedContent = stringifyYaml(patchedStrings); - console.log('stringified') - - await mkdir(`${PATCHES_ROOT}/Data/Strings`, { recursive: true }); - console.log('mkdir') - await writeFile( - `${PATCHES_ROOT}/Data/Strings/en.yaml`, - new Uint8Array((Buffer.from(patchedContent))), - ); - console.log('file') - } - - patchIndex++; + patchIndex++; } -vfs.dispose() +vfs.dispose(); process.exit(0); diff --git a/packages/website/src/components/TankCard/index.tsx b/packages/website/src/components/TankCard/index.tsx index 6d3cfa96d..c09fc8477 100644 --- a/packages/website/src/components/TankCard/index.tsx +++ b/packages/website/src/components/TankCard/index.tsx @@ -1,4 +1,4 @@ -import { asset, TankType, type TankDefinition } from "@blitzkit/core"; +import { TankType, type TankDefinition } from "@blitzkit/core"; import { Flex, Text, type TextProps } from "@radix-ui/themes"; import { uniq } from "lodash-es"; import { forwardRef, type ReactNode } from "react"; @@ -60,7 +60,7 @@ export const TankCard = forwardRef( className="tank-search-card" data-provide-link={provideLink} style={{ - backgroundImage: `url(${asset(`flags/scratched/${tank.nation}.webp`)})`, + backgroundImage: `url(/api/flags/scratched/${tank.nation}.webp)`, ...style, }} {...props} @@ -76,7 +76,7 @@ export const TankCard = forwardRef( > {unwrap(tank.name!)} diff --git a/packages/website/src/core/blitzkit/api.ts b/packages/website/src/core/blitzkit/api.ts index 21e5c4b9f..79af8cbe8 100644 --- a/packages/website/src/core/blitzkit/api.ts +++ b/packages/website/src/core/blitzkit/api.ts @@ -1,15 +1,13 @@ -import { - ClientBlitzKitAPI, - ServerBlitzKitAPI, - type BlitzKitAPI, -} from "@blitzkit/core"; +import { type BlitzKitAPI } from "@blitzkit/core"; import { vfs } from "./vfs"; let _api: BlitzKitAPI; if (import.meta.env.SSR) { + const { ServerBlitzKitAPI } = await import("@blitzkit/core"); _api = await new ServerBlitzKitAPI(vfs).init(); } else { + const { ClientBlitzKitAPI } = await import("@blitzkit/core"); _api = new ClientBlitzKitAPI(); }