feat: tier rendering

This commit is contained in:
TrèsAbhi committed 2026-04-29 10:31:36 -05:00
1 parent e3db886923
commit ff56f1441e
3 files changed
+41 -13

No files matched your search

+11
View File
@@ -1,4 +1,15 @@
{ {
"tiers": {
"vintage": "Vintage",
"four": "IV",
"five": "V",
"six": "VI",
"seven": "VII",
"eight": "VIII",
"nine": "IX",
"ten": "X"
},
"common": { "common": {
"name": "BlitzKit" "name": "BlitzKit"
}, },
@@ -1,3 +1,4 @@
import type { Strings } from "@blitzkit/i18n";
import { import {
Nation, Nation,
TankClass, TankClass,
@@ -19,7 +20,11 @@ export interface CharacteristicRenderConfig {
decimals?: number; decimals?: number;
units?: string; units?: string;
strings?: string; strings?: string;
render?: (output: CharacteristicOutput) => string; render?: (data: {
output: CharacteristicOutput;
strings: Strings;
gameStrings: Record<string, string>;
}) => string;
} }
type CharacteristicsOrder = { type CharacteristicsOrder = {
@@ -36,23 +41,35 @@ export const characteristicsOrder: CharacteristicsOrder = [
{ {
group: "meta", group: "meta",
order: [ order: [
{ name: "name", strings: "TankEntity" }, {
{ name: "tier" }, name: "name",
strings: "TankEntity",
render({ output, gameStrings }) {
return gameStrings[output as string];
},
},
{
name: "tier",
render({ output, strings }) {
const [, name] = (output as string).split(".");
return strings.tiers[name as keyof typeof strings.tiers];
},
},
{ {
name: "nation", name: "nation",
render(output) { render({ output }) {
return Nation[output as Nation]; return Nation[output as Nation];
}, },
}, },
{ {
name: "class", name: "class",
render(output) { render({ output }) {
return TankClass[output as TankClass]; return TankClass[output as TankClass];
}, },
}, },
{ {
name: "type", name: "type",
render(output) { render({ output }) {
return TankType[output as TankType]; return TankType[output as TankType];
}, },
}, },
@@ -66,7 +83,7 @@ export const characteristicsOrder: CharacteristicsOrder = [
order: [ order: [
{ {
name: "gun_type", name: "gun_type",
render(output) { render({ output }) {
return GunType[output as GunType]; return GunType[output as GunType];
}, },
}, },
@@ -5,6 +5,7 @@ import {
type CharacteristicRenderConfig, type CharacteristicRenderConfig,
} from "../core/tankopedia/characteristicsOrder"; } from "../core/tankopedia/characteristicsOrder";
import { useGameStrings } from "./useGameStrings"; import { useGameStrings } from "./useGameStrings";
import { useStrings } from "./useStrings";
export function useCharacteristicRenderer() { export function useCharacteristicRenderer() {
const groups = useMemo(() => { const groups = useMemo(() => {
@@ -20,7 +21,9 @@ export function useCharacteristicRenderer() {
return groups; return groups;
}, []); }, []);
const tankEntityStrings = useGameStrings(groups);
const strings = useStrings();
const gameStrings = useGameStrings(groups);
function renderCharacteristic( function renderCharacteristic(
characteristic: CharacteristicOutput, characteristic: CharacteristicOutput,
@@ -28,7 +31,8 @@ export function useCharacteristicRenderer() {
): string | null { ): string | null {
if (characteristic === null) return null; if (characteristic === null) return null;
if (config.render) return config.render(characteristic); if (config.render)
return config.render({ output: characteristic, strings, gameStrings });
if (typeof characteristic === "number") { if (typeof characteristic === "number") {
if (Number.isFinite(characteristic)) { if (Number.isFinite(characteristic)) {
@@ -43,10 +47,6 @@ export function useCharacteristicRenderer() {
} }
if (typeof characteristic === "string") { if (typeof characteristic === "string") {
if (config.strings) {
return tankEntityStrings[characteristic];
}
return characteristic; return characteristic;
} }