Compare commits

...
3 Commits
Author SHA1 Message Date
TrèsAbhiandCopilot 76dc9f0742 feat: node rendering
Co-authored-by: Copilot <[email protected]>
2026-04-29 10:46:37 -05:00
TrèsAbhi ff56f1441e feat: tier rendering 2026-04-29 10:31:36 -05:00
TrèsAbhiandCopilot e3db886923 feat: game strings in characteristics
Co-authored-by: Copilot <[email protected]>
2026-04-29 10:17:53 -05:00
9 changed files with 169 additions and 46 deletions

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,6 +1,6 @@
import type { CharacteristicOutput } from "../core/tankopedia/characteristics";
import type { CharacteristicRenderConfig } from "../core/tankopedia/characteristicsOrder";
import { renderCharacteristic } from "../core/tankopedia/renderCharacteristic";
import { renderCharacteristic } from "../hooks/useCharacteristicRenderer";
interface Props {
characteristic: CharacteristicOutput;
@@ -1,8 +1,11 @@
import type { Strings } from "@blitzkit/i18n";
import {
Nation,
TankClass,
TankType,
} from "@protos/game/proto/legacy/blitz_static_tank_component";
import type { ReactNode } from "react";
import { VintageIcon } from "../../icons/Vintage";
import {
GunType,
type CharacteristicName,
@@ -18,7 +21,12 @@ export interface CharacteristicRenderConfig {
name: CharacteristicName;
decimals?: number;
units?: string;
render?: (output: CharacteristicOutput) => string;
strings?: string;
render?: (data: {
output: CharacteristicOutput;
strings: Strings;
gameStrings: Record<string, string>;
}) => ReactNode;
}
type CharacteristicsOrder = {
@@ -35,23 +43,40 @@ export const characteristicsOrder: CharacteristicsOrder = [
{
group: "meta",
order: [
{ name: "name" },
{ 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(".");
if (name == "vintage") {
return <VintageIcon />;
}
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];
},
},
@@ -65,7 +90,7 @@ export const characteristicsOrder: CharacteristicsOrder = [
order: [
{
name: "gun_type",
render(output) {
render({ output }) {
return GunType[output as GunType];
},
},
@@ -1,29 +0,0 @@
import type { CharacteristicOutput } from "./characteristics";
import type { CharacteristicRenderConfig } from "./characteristicsOrder";
export function renderCharacteristic(
characteristic: CharacteristicOutput,
config: CharacteristicRenderConfig
): 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) {
return characteristic.toString();
}
return characteristic.toFixed(config.decimals);
}
return `${characteristic < 0 ? "-" : ""}∞`;
}
if (typeof characteristic === "string") {
return characteristic;
}
return characteristic.map((c) => renderCharacteristic(c, config)).join(", ");
}
@@ -0,0 +1,59 @@
import { useMemo, type ReactNode } from "react";
import type { CharacteristicOutput } from "../core/tankopedia/characteristics";
import {
characteristicsOrder,
type CharacteristicRenderConfig,
} from "../core/tankopedia/characteristicsOrder";
import { useGameStrings } from "./useGameStrings";
import { useStrings } from "./useStrings";
export function useCharacteristicRenderer() {
const groups = useMemo(() => {
const groups: string[] = [];
for (const group of characteristicsOrder) {
for (const item of group.order) {
if ("strings" in item && item.strings) {
groups.push(item.strings);
}
}
}
return groups;
}, []);
const strings = useStrings();
const gameStrings = useGameStrings(groups);
function renderCharacteristic(
characteristic: CharacteristicOutput,
config: CharacteristicRenderConfig,
): ReactNode {
if (characteristic === null) return null;
if (config.render)
return config.render({ output: characteristic, strings, gameStrings });
if (typeof characteristic === "number") {
if (Number.isFinite(characteristic)) {
if (config.decimals === undefined) {
return characteristic.toString();
}
return characteristic.toFixed(config.decimals);
}
return `${characteristic < 0 ? "-" : ""}∞`;
}
if (typeof characteristic === "string") {
return characteristic;
}
return characteristic
.map((c) => renderCharacteristic(c, config))
.join(", ");
}
return renderCharacteristic;
}
@@ -2,11 +2,24 @@ import { api } from "../core/api/dynamic";
import { useAwait } from "./useAwait";
import { useLocale } from "./useLocale";
export function useGameStrings(group: string) {
export function useGameStrings(groups: string | string[]) {
const resolved = typeof groups === "string" ? [groups] : groups;
const locale = useLocale();
const strings = useAwait(
() => api.groupedGameStrings(locale, group, true),
`game-strings-${locale}-${group}`,
async () => {
const accumulated: Record<string, string> = {};
await Promise.all(
resolved.map(async (group) => {
const strings = await api.groupedGameStrings(locale, group, true);
Object.assign(accumulated, strings);
}),
);
return accumulated;
},
`game-strings-${locale}-${resolved.sort().join("-")}`,
);
return strings;
}
+26
View File
@@ -0,0 +1,26 @@
import type { ComponentProps } from "react";
export function VintageIcon(props: ComponentProps<"svg">) {
return (
<svg
width="15"
height="15"
viewBox="0 0 15 15"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<g clip-path="url(#clip0_937_310)">
<path
d="M9.49367 14.2405L7.59494 15L6.45377 12.2612C6.02812 12.4529 5.60174 12.6027 5.12658 12.7215C4.36709 12.9114 4.28484 11.9701 4.74684 11.7722C5.18709 11.5835 5.60652 11.4156 6.02581 11.2341L2.8481 3.60759L2.08861 3.98734C1.99508 4.94119 1.59566 5.15783 0.759494 5.50633L0 3.03797L4.36709 1.13924L7.92912 10.2422C8.18694 10.0778 8.4541 9.8936 8.73418 9.68354C8.86727 9.58372 9.00334 9.48053 9.14147 9.3742L5.6962 0.56962L7.02532 0L10.3206 8.42121C12.0297 6.96104 13.6709 5.15033 13.6709 3.41772C13.6709 2.65823 12.9894 1.75812 12.1519 1.70886C12.1519 2.46835 11.5823 3.60759 10.6329 3.60759C9.84468 3.60759 9.13001 2.98135 9.11392 2.08861C9.09389 0.976535 10.1167 0.189873 11.3924 0.189873C14.0506 0.189873 15 1.70886 15 3.60759C15 5.74438 13.1597 7.75137 10.7611 9.54708L12.1519 13.1013L10.8228 13.6709L9.54669 10.4098C9.34119 10.5489 9.13342 10.6866 8.92405 10.8228C8.70862 10.9629 8.50508 11.0944 8.31083 11.2177L9.49367 14.2405Z"
fill="currentColor"
/>
</g>
<defs>
<clipPath id="clip0_937_310">
<rect width="15" height="15" fill="currentColor" />
</clipPath>
</defs>
</svg>
);
}
@@ -2,8 +2,10 @@ import { Grade } from "@blitzkit/closed/protos/game/proto/legacy/blitz_static_st
import { StageParameters_StageType } from "@blitzkit/closed/protos/game/proto/legacy/blitz_static_tank_upgrade_single_stage";
import { useMemo } from "react";
import { api } from "../../../../core/api/dynamic";
import { characteristicsOrder } from "../../../../core/tankopedia/characteristicsOrder";
import { computeCharacteristics } from "../../../../core/tankopedia/computeCharacteristics";
import { useAwait } from "../../../../hooks/useAwait";
import { useCharacteristicRenderer } from "../../../../hooks/useCharacteristicRenderer";
import { useGameStrings } from "../../../../hooks/useGameStrings";
import { LocaleProvider } from "../../../../hooks/useLocale";
import { Tankopedia } from "../../../../stores/tankopedia";
@@ -27,6 +29,7 @@ export function Page({ id, locale }: PageProps) {
function Content() {
const tankEntityGameStrings = useGameStrings("TankEntity");
const renderCharacteristic = useCharacteristicRenderer();
const protagonist = Tankopedia.use((state) => state.protagonist);
const protagonistTank = useAwait(
@@ -146,11 +149,26 @@ function Content() {
<h2>characteristics</h2>
{Object.entries(characteristics).map(([key, value]) => (
<p>
{key}: {value}
</p>
))}
{characteristicsOrder.map((group) => {
return (
<>
<h3>{group.group}</h3>
{group.order.map((item) => {
if ("toy" in item) {
return <span>toy: {item.toy}</span>;
}
return (
<span>
{item.name}:{" "}
{renderCharacteristic(characteristics[item.name], item)}
</span>
);
})}
</>
);
})}
</>
);