feat: meta section

This commit is contained in:
TrèsAbhi committed 2025-12-26 14:14:29 -06:00
1 parent 1d3cb95b89
commit 40a1eb861d
14 files changed
+141 -18

No files matched your search

@@ -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,
@@ -12,7 +13,9 @@ import {
import type { TankState } from "./tankState";
export function computeCharacteristics(
id: string,
tank: TankCatalogComponent,
compensation: CompensationComponent,
state: TankState
) {
const parameters = aggregateStageParameters(
@@ -89,6 +92,8 @@ export function computeCharacteristics(
state,
tank,
parameters,
id,
compensation,
});
computed[name] = value;
}
@@ -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(", ");
}