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": {
"name": "BlitzKit"
},
@@ -1,3 +1,4 @@
import type { Strings } from "@blitzkit/i18n";
import {
Nation,
TankClass,
@@ -19,7 +20,11 @@ export interface CharacteristicRenderConfig {
decimals?: number;
units?: string;
strings?: string;
render?: (output: CharacteristicOutput) => string;
render?: (data: {
output: CharacteristicOutput;
strings: Strings;
gameStrings: Record<string, string>;
}) => string;
}
type CharacteristicsOrder = {
@@ -36,23 +41,35 @@ export const characteristicsOrder: CharacteristicsOrder = [
{
group: "meta",
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",
render(output) {
render({ output }) {
return Nation[output as Nation];
},
},
{
name: "class",
render(output) {
render({ output }) {
return TankClass[output as TankClass];
},
},
{
name: "type",
render(output) {
render({ output }) {
return TankType[output as TankType];
},
},
@@ -66,7 +83,7 @@ export const characteristicsOrder: CharacteristicsOrder = [
order: [
{
name: "gun_type",
render(output) {
render({ output }) {
return GunType[output as GunType];
},
},
@@ -5,6 +5,7 @@ import {
type CharacteristicRenderConfig,
} from "../core/tankopedia/characteristicsOrder";
import { useGameStrings } from "./useGameStrings";
import { useStrings } from "./useStrings";
export function useCharacteristicRenderer() {
const groups = useMemo(() => {
@@ -20,7 +21,9 @@ export function useCharacteristicRenderer() {
return groups;
}, []);
const tankEntityStrings = useGameStrings(groups);
const strings = useStrings();
const gameStrings = useGameStrings(groups);
function renderCharacteristic(
characteristic: CharacteristicOutput,
@@ -28,7 +31,8 @@ export function useCharacteristicRenderer() {
): string | 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 (Number.isFinite(characteristic)) {
@@ -43,10 +47,6 @@ export function useCharacteristicRenderer() {
}
if (typeof characteristic === "string") {
if (config.strings) {
return tankEntityStrings[characteristic];
}
return characteristic;
}