dynamically import client api

This commit is contained in:
tresabhi committed 2026-08-02 20:28:57 -05:00
1 parent 8a3e57637d
commit b060e65af5
5 files changed
+25 -54

No files matched your search

@@ -1,22 +0,0 @@
import { fetchTankDefinitions } from '../blitzkit';
import type { BlitzStats } from './compositeStats/constants';
export async function getTierWeights(
stats: Record<number, BlitzStats>,
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<Record<number, number>>;
+8 -9
View File
@@ -1,9 +1,8 @@
export * from './calculateWN8'; export * from "./calculateWN8";
export * from './compositeStats'; export * from "./compositeStats";
export * from './deltaBkrlBlitzStats'; export * from "./deltaBkrlBlitzStats";
export * from './deltaTankStats'; export * from "./deltaTankStats";
export * from './getBkniPercentile'; export * from "./getBkniPercentile";
export * from './getTierWeights'; export * from "./getWN8Percentile";
export * from './getWN8Percentile'; export * from "./percentiles";
export * from './percentiles'; export * from "./sumAllStats";
export * from './sumAllStats';
+11 -15
View File
@@ -5,7 +5,6 @@ import { parse as parsePath } from "path";
import ProgressBar from "progress"; import ProgressBar from "progress";
import { parse as parseYaml, stringify as stringifyYaml } from "yaml"; import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
import { PATCHES_ROOT, vfs } from "./buildAssets/constants"; import { PATCHES_ROOT, vfs } from "./buildAssets/constants";
import { writeDVPL } from "./core/blitz/writeDVPL";
const versionTextFile = await vfs.text(`Data/version.txt`); const versionTextFile = await vfs.text(`Data/version.txt`);
const currentVersion = versionTextFile const currentVersion = versionTextFile
@@ -24,7 +23,7 @@ while (true) {
)}/dlc/s${currentVersion}_${patchIndex}.yaml`, )}/dlc/s${currentVersion}_${patchIndex}.yaml`,
); );
console.log(patchIndex, response.status) console.log(patchIndex, response.status);
if (!response.ok) break; if (!response.ok) break;
@@ -59,15 +58,12 @@ while (true) {
const buffer = Buffer.from(data); const buffer = Buffer.from(data);
await writeFile( await writeFile(`${PATCHES_ROOT}/Data/${path}`, new Uint8Array(buffer));
`${PATCHES_ROOT}/Data/${path}`,
new Uint8Array(buffer),
);
bar.tick(); bar.tick();
} }
console.log('patches done for patch') console.log("patches done for patch");
if ("dynamicContentLocalizationsDir" in data) { if ("dynamicContentLocalizationsDir" in data) {
console.log( console.log(
@@ -80,27 +76,27 @@ while (true) {
data.dynamicContentLocalizationsDir data.dynamicContentLocalizationsDir
}/en.yaml`, }/en.yaml`,
); );
console.log('fetched') console.log("fetched");
const newStrings = parseYaml(await localizationsResponse.text()); const newStrings = parseYaml(await localizationsResponse.text());
console.log('got new strings') console.log("got new strings");
const oldStrings = const oldStrings =
await vfs.yaml<Record<string, string>>(`Data/Strings/en.yaml`); await vfs.yaml<Record<string, string>>(`Data/Strings/en.yaml`);
console.log('got old strings') console.log("got old strings");
const patchedStrings = { ...oldStrings, ...newStrings }; const patchedStrings = { ...oldStrings, ...newStrings };
const patchedContent = stringifyYaml(patchedStrings); const patchedContent = stringifyYaml(patchedStrings);
console.log('stringified') console.log("stringified");
await mkdir(`${PATCHES_ROOT}/Data/Strings`, { recursive: true }); await mkdir(`${PATCHES_ROOT}/Data/Strings`, { recursive: true });
console.log('mkdir') console.log("mkdir");
await writeFile( await writeFile(
`${PATCHES_ROOT}/Data/Strings/en.yaml`, `${PATCHES_ROOT}/Data/Strings/en.yaml`,
new Uint8Array((Buffer.from(patchedContent))), new Uint8Array(Buffer.from(patchedContent)),
); );
console.log('file') console.log("file");
} }
patchIndex++; patchIndex++;
} }
vfs.dispose() vfs.dispose();
process.exit(0); process.exit(0);
@@ -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 { Flex, Text, type TextProps } from "@radix-ui/themes";
import { uniq } from "lodash-es"; import { uniq } from "lodash-es";
import { forwardRef, type ReactNode } from "react"; import { forwardRef, type ReactNode } from "react";
@@ -60,7 +60,7 @@ export const TankCard = forwardRef<HTMLSpanElement, TankCardProps>(
className="tank-search-card" className="tank-search-card"
data-provide-link={provideLink} data-provide-link={provideLink}
style={{ style={{
backgroundImage: `url(${asset(`flags/scratched/${tank.nation}.webp`)})`, backgroundImage: `url(/api/flags/scratched/${tank.nation}.webp)`,
...style, ...style,
}} }}
{...props} {...props}
@@ -76,7 +76,7 @@ export const TankCard = forwardRef<HTMLSpanElement, TankCardProps>(
> >
<img <img
alt={unwrap(tank.name!)} alt={unwrap(tank.name!)}
src={asset(`icons/tanks/big/${tank.id}.webp`)} src={`/api/tanks/${tank.id}/icons/big.webp`}
className="image" className="image"
draggable={false} draggable={false}
/> />
+3 -5
View File
@@ -1,15 +1,13 @@
import { import { type BlitzKitAPI } from "@blitzkit/core";
ClientBlitzKitAPI,
ServerBlitzKitAPI,
type BlitzKitAPI,
} from "@blitzkit/core";
import { vfs } from "./vfs"; import { vfs } from "./vfs";
let _api: BlitzKitAPI; let _api: BlitzKitAPI;
if (import.meta.env.SSR) { if (import.meta.env.SSR) {
const { ServerBlitzKitAPI } = await import("@blitzkit/core");
_api = await new ServerBlitzKitAPI(vfs).init(); _api = await new ServerBlitzKitAPI(vfs).init();
} else { } else {
const { ClientBlitzKitAPI } = await import("@blitzkit/core");
_api = new ClientBlitzKitAPI(); _api = new ClientBlitzKitAPI();
} }