Compare commits

...
4 Commits
Author SHA1 Message Date
TrèsAbhi fcfc97b964 feat: start of all tanks 2025-12-26 14:59:09 -06:00
TrèsAbhi 53d05e73a6 feat: some docs 2025-12-26 14:21:04 -06:00
TrèsAbhi 40a1eb861d feat: meta section 2025-12-26 14:14:29 -06:00
TrèsAbhi 1d3cb95b89 fix: assert wotb server 2025-12-26 11:33:04 -06:00
23 changed files with 328 additions and 76 deletions

No files matched your search

+1
View File
@@ -186,6 +186,7 @@
"@blitzkit/closed": "workspace:*",
"@blitzkit/core": "workspace:*",
"@blitzkit/i18n": "workspace:*",
"@bufbuild/protobuf": "^2.10.2",
"@fontsource-variable/inter": "^5.2.8",
"@radix-ui/colors": "^3.0.0",
"@radix-ui/react-icons": "^1.3.2",
+3 -2
View File
@@ -56,7 +56,7 @@ for (const root of roots) {
"--ts_proto_opt=unrecognizedEnum=false",
"--ts_proto_opt=snakeToCamel=false",
`--ts_proto_out=${root}`,
`-I=${root}`,
...roots.map((root) => `-I=${root}`),
].join(" ");
while (true) {
@@ -66,8 +66,9 @@ for (const root of roots) {
const newLine = ` ${root}/${file}`;
if (command.length + newLine.length < MAX_COMMAND_LENGTH) {
const file = files.pop();
command += newLine;
console.log(` ${files.pop()}`);
// console.log(` ${file}`);
} else {
break;
}
+1
View File
@@ -16,6 +16,7 @@
"@blitzkit/closed": "workspace:*",
"@blitzkit/core": "workspace:*",
"@blitzkit/i18n": "workspace:*",
"@bufbuild/protobuf": "^2.10.2",
"@fontsource-variable/inter": "^5.2.8",
"@radix-ui/colors": "^3.0.0",
"@radix-ui/react-icons": "^1.3.2",
@@ -0,0 +1,20 @@
import type { CharacteristicOutput } from "../core/tankopedia/characteristics";
import type { CharacteristicRenderConfig } from "../core/tankopedia/characteristicsOrder";
import { renderCharacteristic } from "../core/tankopedia/renderCharacteristic";
interface Props {
characteristic: CharacteristicOutput;
config: CharacteristicRenderConfig;
}
export function TankopediaCharacteristic({ characteristic, config }: Props) {
if (characteristic === null) return null;
const rendered = renderCharacteristic(characteristic, config);
return (
<p>
{config.name}: {rendered} {config.units && `${config.units}`} (1 / 1)
</p>
);
}
@@ -0,0 +1,7 @@
interface Props {
toy: string;
}
export function TankopediaToy({ toy }: Props) {
return <p>toy: {toy}</p>;
}
+5 -2
View File
@@ -1,13 +1,16 @@
import type { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import type { Tank } from "../../protos/tank";
import type { TankList } from "../../protos/tank_list";
import type { Tanks } from "../../protos/tanks";
export abstract class AbstractAPI {
abstract tanks(): Promise<Tanks>;
abstract tankList(): Promise<TankList>;
abstract strings(
locale: string,
prefix?: string
): Promise<Record<string, string>>;
abstract tank(id: string): Promise<TankCatalogComponent>;
abstract tank(id: string): Promise<Tank>;
}
+13 -6
View File
@@ -1,12 +1,19 @@
import { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import { fetchPB } from "@blitzkit/core";
import { Tank } from "../../protos/tank";
import { TankList } from "../../protos/tank_list";
import { Tanks } from "../../protos/tanks";
import { AbstractAPI } from "./abstract";
export class ClientAPI extends AbstractAPI {
async tank(id: string) {
const response = await fetch(`/api/tanks/${id}.pb`);
const buffer = await response.arrayBuffer();
const array = new Uint8Array(buffer);
tanks() {
return fetchPB("/api/tanks.pb", Tanks);
}
return TankCatalogComponent.decode(array);
tankList() {
return fetchPB("/api/tanks/list.pb", TankList);
}
tank(id: string) {
return fetchPB(`/api/tanks/${id}.pb`, Tank);
}
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { assertSecret } from "@blitzkit/core";
import type { AbstractAPI } from "./abstract";
let dynamicAPI: AbstractAPI;
@@ -7,7 +8,7 @@ if (typeof window === "undefined") {
const { ServerAPI } = await import("./server");
const proxyClient = await new ProxyClient(
import.meta.env.WOTB_SERVER
assertSecret(import.meta.env.WOTB_SERVER)
).handshake();
const metadata = await proxyClient.metadata();
+31 -8
View File
@@ -2,7 +2,9 @@ import type { MetadataAccessor } from "@blitzkit/closed";
import { sluggify } from "@blitzkit/core";
import type { RemoteStorageComponent } from "@protos/blitz_static_remote_storage_component";
import { parse } from "yaml";
import type { TanksEntry } from "../../protos/tanks";
import type { Tank } from "../../protos/tank";
import type { TankListEntry } from "../../protos/tank_list";
import type { Tanks } from "../../protos/tanks";
import { AbstractAPI } from "./abstract";
if (typeof window !== "undefined") {
@@ -90,9 +92,9 @@ export class ServerAPI extends AbstractAPI {
return strings;
}
async tanks() {
async tankList() {
const group = this.metadata.group("TankEntity");
const tanks: TanksEntry[] = [];
const list: TankListEntry[] = [];
const strings = await this.strings("en");
for (const item of group) {
@@ -107,16 +109,37 @@ export class ServerAPI extends AbstractAPI {
const id = item.name;
const slug = sluggify(name);
tanks.push({ id, slug });
list.push({ id, slug });
}
return { tanks };
return { list };
}
async tanks() {
const tankList = await this.tankList();
const data: Tanks = { tanks: {} };
for (const { id } of tankList.list) {
console.log(id);
data.tanks[id] = await this.tank(id);
}
return data;
}
async tank(id: string) {
const item = this.metadata.item(`TankEntity.${id}`);
const tankCatalog = item.TankCatalog();
const tankList = await this.tankList();
const tankListEntry = tankList.list.find((tank) => tank.id === id);
return tankCatalog;
if (!tankListEntry) {
throw new Error(`Tank with id ${id} not found`);
}
const { slug } = tankListEntry;
const item = this.metadata.item(`TankEntity.${id}`);
const tank = item.TankCatalog();
const compensation = item.Compensation();
return { tank, compensation, slug } satisfies Tank;
}
}
@@ -1,5 +1,6 @@
import { TankClass } from "@blitzkit/core";
import type { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import type { CompensationComponent } from "@protos/blitz_static_compensation_component";
import { type TankCatalogComponent } from "@protos/blitz_static_tank_component";
import {
ShellUpgrageSingleChange_AttributeName,
StageParameters,
@@ -9,7 +10,7 @@ import { radToDeg } from "three/src/math/MathUtils.js";
import { applyPitchYawLimits } from "./applyPitchYawLimits";
import { TerrainHardness, type TankState } from "./tankState";
export type CharacteristicOutput = number | number[] | null;
export type CharacteristicOutput = number | number[] | string | null;
type Characteristic = (helpers: {
characteristic: (name: CharacteristicName) => CharacteristicOutput;
@@ -20,6 +21,8 @@ type Characteristic = (helpers: {
state: TankState;
tank: TankCatalogComponent;
parameters: StageParameters;
compensation: CompensationComponent;
id: string;
}) => CharacteristicOutput;
export type CharacteristicName = keyof typeof characteristics;
@@ -391,4 +394,28 @@ export const characteristics = {
volume() {
return -Infinity;
},
nation({ tank }) {
return tank.nation;
},
name({ tank }) {
return tank.name!.value;
},
tier({ tank }) {
return tank.tier_catalog_id;
},
type({ tank }) {
return tank.tank_type;
},
id({ id }) {
return id;
},
compensation({ compensation }) {
return compensation.compensation?.currency_reward?.amount ?? null;
},
} satisfies Record<string, Characteristic>;
@@ -1,4 +1,13 @@
import type { CharacteristicName } from "./characteristics";
import {
Nation,
TankClass,
TankType,
} from "@protos/blitz_static_tank_component";
import {
GunType,
type CharacteristicName,
type CharacteristicOutput,
} from "./characteristics";
export enum BetterDirection {
Higher,
@@ -9,6 +18,7 @@ export interface CharacteristicRenderConfig {
name: CharacteristicName;
decimals?: number;
units?: string;
render?: (output: CharacteristicOutput) => string;
}
type CharacteristicsOrder = {
@@ -22,10 +32,42 @@ type CharacteristicsOrder = {
}[];
export const characteristicsOrder: CharacteristicsOrder = [
{
group: "meta",
order: [
{ name: "name" },
{ name: "tier" },
{
name: "nation",
render(output) {
return Nation[output as Nation];
},
},
{
name: "class",
render(output) {
return TankClass[output as TankClass];
},
},
{
name: "type",
render(output) {
return TankType[output as TankType];
},
},
{ name: "compensation" },
{ name: "id" },
],
},
{
group: "firepower",
order: [
{ name: "gun_type" },
{
name: "gun_type",
render(output) {
return GunType[output as GunType];
},
},
{ name: "dpm", decimals: 0, units: "hp_min" },
{ name: "reload", decimals: 2, units: "s" },
{ name: "reloads", decimals: 2, units: "s" },
@@ -1,3 +1,4 @@
import type { CompensationComponent } from "@protos/blitz_static_compensation_component";
import type { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import {
ShellUpgrageSingleChange_AttributeName,
@@ -11,8 +12,15 @@ import {
} from "./characteristics";
import type { TankState } from "./tankState";
export type ComputedCharacteristics = Record<
CharacteristicName,
CharacteristicOutput
>;
export function computeCharacteristics(
id: string,
tank: TankCatalogComponent,
compensation: CompensationComponent,
state: TankState
) {
const parameters = aggregateStageParameters(
@@ -20,8 +28,7 @@ export function computeCharacteristics(
tank.upgrade_stages.slice(0, state.stage)
);
const computed: Partial<Record<CharacteristicName, CharacteristicOutput>> =
{};
const computed: Partial<ComputedCharacteristics> = {};
function characteristic(name: CharacteristicName) {
if (name in computed) return computed[name] as CharacteristicOutput;
@@ -89,15 +96,14 @@ export function computeCharacteristics(
state,
tank,
parameters,
id,
compensation,
});
computed[name] = value;
}
return {
characteristics: computed as Record<
CharacteristicName,
CharacteristicOutput
>,
characteristics: computed as ComputedCharacteristics,
parameters,
};
}
@@ -0,0 +1,16 @@
import type { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import { TerrainHardness } from "./tankState";
export function createTankState(tank: TankCatalogComponent) {
return {
stage: tank.upgrade_stages.length,
shell: 0,
isGunDamaged: false,
isHullTraversing: false,
isShooting: false,
isTurretTraversing: false,
speed: 0,
terrainHardness: TerrainHardness.Hard,
isCaughtOnFire: false,
};
}
@@ -7,6 +7,8 @@ export function renderCharacteristic(
): string | null {
if (characteristic === null) return null;
if (config.render) return config.render(characteristic);
if (typeof characteristic === "number") {
if (Number.isFinite(characteristic)) {
if (config.decimals === undefined) {
@@ -19,5 +21,9 @@ export function renderCharacteristic(
return `${characteristic < 0 ? "-" : ""}∞`;
}
if (typeof characteristic === "string") {
return characteristic;
}
return characteristic.map((c) => renderCharacteristic(c, config)).join(", ");
}
@@ -0,0 +1,39 @@
import { TankClass, TankType } from "@blitzkit/core";
import { Nation } from "@protos/blitz_static_tank_component";
import type { APIContext, GetStaticPaths } from "astro";
import { GunType } from "../../../core/tankopedia/characteristics";
const enums = {
nation: Nation,
"tank-class": TankClass,
"tank-type": TankType,
"gun-type": GunType,
};
export const getStaticPaths = (() => {
return Object.keys(enums).map((name) => ({ params: { enum: name } }));
}) satisfies GetStaticPaths;
/**
* Enumerations used within BlitzKit, for nominal development reference only.
*
* DO NOT programmatically use this API as it is designed solely for human
* reference.
*
* DO NOT blindly copy entries as naming conventions vary. Most enums come
* directly from the game which uses a SCREAMING_SNAKE_CASE convention while
* BlitzKit uses PascalCase.
*/
export function GET({
params,
}: APIContext<never, { enum: keyof typeof enums }>) {
const map: Record<number, string> = {};
for (const key in enums[params.enum]) {
const value = enums[params.enum][key];
if (typeof value !== "string") continue;
map[key] = value;
}
return Response.json(map);
}
@@ -51,7 +51,7 @@ paths.sort((a, b) => a.path.localeCompare(b.path));
paths.map(({ path, documentation }) => (
<>
<h2>{path}</h2>
<p>{documentation}</p>
<pre>{documentation}</pre>
</>
))
}
@@ -0,0 +1,10 @@
import { api } from "../../core/api/dynamic";
import { Tanks } from "../../protos/tanks";
/**
* Literally all the tanks in one place lmao.
*/
export async function GET() {
const tanks = await api.tanks();
return new Response(Tanks.encode(tanks).finish());
}
@@ -1,11 +1,11 @@
import { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import type { APIContext, GetStaticPaths } from "astro";
import { api } from "../../../core/api/dynamic";
import { Tank } from "../../../protos/tank";
export const getStaticPaths = (async () => {
const { tanks } = await api.tanks();
const { list } = await api.tankList();
return tanks.map(({ id }) => ({ params: { id } }));
return list.map(({ id }) => ({ params: { id } }));
}) satisfies GetStaticPaths;
/**
@@ -13,5 +13,5 @@ export const getStaticPaths = (async () => {
*/
export async function GET({ params }: APIContext<never, { id: string }>) {
const tank = await api.tank(params.id);
return new Response(TankCatalogComponent.encode(tank).finish());
return new Response(Tank.encode(tank).finish());
}
@@ -1,12 +1,13 @@
import { times } from "lodash-es";
import { Suspense, useMemo } from "react";
import { TankopediaCharacteristic } from "../../../components/TankopediaCharacteristic";
import { TankopediaToy } from "../../../components/TankopediaToy";
import { api } from "../../../core/api/dynamic";
import { characteristicsOrder } from "../../../core/tankopedia/characteristicsOrder";
import { computeCharacteristics } from "../../../core/tankopedia/computeCharacteristics";
import { renderCharacteristic } from "../../../core/tankopedia/renderCharacteristic";
import { TerrainHardness } from "../../../core/tankopedia/tankState";
import { useAwait } from "../../../hooks/useAwait";
import { Tankopedia } from "../../../stores/tankopedia";
import { Tankopedia, TankopediaCompare } from "../../../stores/tankopedia";
export function Page({ id }: { id: string }) {
return (
@@ -17,13 +18,15 @@ export function Page({ id }: { id: string }) {
}
function Content({ id }: { id: string }) {
const tank = useAwait(() => api.tank(id), `tank-${id}`);
const { tank, compensation } = useAwait(() => api.tank(id), `tank-${id}`);
const otherTanks = useAwait(() => api.tanks(), "tanks");
Tankopedia.useInitialization(tank.upgrade_stages.length);
Tankopedia.useInitialization(tank!);
const protagonist = Tankopedia.use((state) => state.protagonist);
const compare = Tankopedia.use((state) => state.compare);
const { characteristics, parameters } = useMemo(
() => computeCharacteristics(tank, protagonist),
() => computeCharacteristics(id, tank!, compensation!, protagonist),
[protagonist]
);
@@ -34,7 +37,7 @@ function Content({ id }: { id: string }) {
<br />
<div style={{ display: "flex", flexWrap: "wrap" }}>
{times(tank.upgrade_stages.length + 1, (index) => (
{times(tank!.upgrade_stages.length + 1, (index) => (
<button
key={index}
onClick={() => {
@@ -181,27 +184,41 @@ function Content({ id }: { id: string }) {
<br />
<div style={{ display: "flex", flexWrap: "wrap" }}>
{Object.values(TankopediaCompare).map(
(c) =>
typeof c === "number" && (
<button
key={c}
onClick={() => {
Tankopedia.mutate((draft) => {
draft.compare = c;
});
}}
>
{TankopediaCompare[c]} {c === compare && "(selected)"}
</button>
)
)}
</div>
<br />
{characteristicsOrder.map(({ group, order }) => (
<>
<h2 key={group}>{group}</h2>
{order.map((config) => {
if ("toy" in config) {
return <p key={`toy-${config.toy}`}>toy: {config.toy}</p>;
} else {
const characteristic = characteristics[config.name];
if (characteristic === null) return null;
const rendered = renderCharacteristic(characteristic, config);
return (
<p key={`characteristic-${config.name}`}>
{config.name}: {rendered} {config.units && `${config.units}`}
</p>
);
}
})}
{order.map((config) =>
"toy" in config ? (
<TankopediaToy key={`toy-${config.toy}`} toy={config.toy} />
) : (
<TankopediaCharacteristic
key={`characteristic-${config.name}`}
characteristic={characteristics[config.name]}
config={config}
/>
)
)}
</>
))}
</>
+13
View File
@@ -0,0 +1,13 @@
syntax = "proto3";
package blitzkit;
import "blitz_static_compensation_component.proto";
import "blitz_static_tank_component.proto";
message Tank {
blitz_static_tank_component.TankCatalogComponent tank = 1;
blitz_static_compensation_component.CompensationComponent compensation = 2;
string slug = 3;
}
@@ -0,0 +1,12 @@
syntax = "proto3";
package blitzkit;
message TankList {
repeated TankListEntry list = 1;
}
message TankListEntry {
string id = 1;
string slug = 2;
}
+3 -6
View File
@@ -2,11 +2,8 @@ syntax = "proto3";
package blitzkit;
message Tanks {
repeated TanksEntry tanks = 1;
}
import "tank.proto";
message TanksEntry {
string id = 1;
string slug = 2;
message Tanks {
map<string, Tank> tanks = 1;
}
+16 -13
View File
@@ -1,19 +1,22 @@
import type { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import { Varuna } from "varuna";
import { TerrainHardness, type TankState } from "../core/tankopedia/tankState";
import { createTankState } from "../core/tankopedia/createTankState";
import { type TankState } from "../core/tankopedia/tankState";
interface Tankopedia {
compare: TankopediaCompare;
protagonist: TankState;
}
export const Tankopedia = new Varuna<Tankopedia, number>((maxStage) => ({
protagonist: {
stage: maxStage,
shell: 0,
isGunDamaged: false,
isHullTraversing: false,
isShooting: false,
isTurretTraversing: false,
speed: 0,
terrainHardness: TerrainHardness.Hard,
},
}));
export enum TankopediaCompare {
TierAndClass,
Tier,
All,
}
export const Tankopedia = new Varuna<Tankopedia, TankCatalogComponent>(
(tank) => ({
compare: TankopediaCompare.TierAndClass,
protagonist: createTankState(tank),
})
);