feat: rename a bit

This commit is contained in:
TrèsAbhi committed 2025-12-18 15:30:18 -06:00
1 parent 66eaaef6de
commit 6ce1135835
8 files changed
+104 -59

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ import AstroPWA from "@vite-pwa/astro";
import favicons from "astro-favicons"; import favicons from "astro-favicons";
import { defineConfig } from "astro/config"; import { defineConfig } from "astro/config";
import packageJSON from "../../package.json"; import packageJSON from "../../package.json";
import { tools } from "./src/constants/tools"; import { tools } from "./src/core/tools/tools";
const POSSIBLE_TARGETS = ["app", "web"]; const POSSIBLE_TARGETS = ["app", "web"];
@@ -183,7 +183,7 @@ function patch(stage0: StageParameters, stage1: StageParameters) {
} }
} }
export function aggregateStages( export function aggregateStageParameters(
base: StageParameters, base: StageParameters,
stages: StageParameters[], stages: StageParameters[],
stage: number stage: number
@@ -3,31 +3,21 @@ import {
TankAttributeChange_AttributeName, TankAttributeChange_AttributeName,
} from "@protos/blitz_static_tank_upgrade_single_stage"; } from "@protos/blitz_static_tank_upgrade_single_stage";
export enum CharacteristicsGroup { export type CharacteristicOutput = number | string | null;
Firepower = "firepower",
Maneuverability = "maneuverability",
Survivability = "survivability",
Miscellaneous = "miscellaneous",
}
interface Characteristic { interface Characteristic {
render: (helpers: { value: (helpers: {
characteristic: (name: CharacteristicName) => number; characteristic: (name: CharacteristicName) => CharacteristicOutput;
attribute: (name: TankAttributeChange_AttributeName) => number; attribute: (name: TankAttributeChange_AttributeName) => number;
shell: (name: ShellUpgrageSingleChange_AttributeName) => number; shell: (name: ShellUpgrageSingleChange_AttributeName) => number;
}) => number | string | null; }) => CharacteristicOutput;
} }
type CharacteristicName = keyof typeof characteristics; export type CharacteristicName = keyof typeof characteristics;
type CharacteristicsOrder = {
group: CharacteristicsGroup;
characteristics: CharacteristicName[];
}[];
export const characteristics = { export const characteristics = {
gun_type: { gun_type: {
render({ attribute }) { value({ attribute }) {
const isPump = attribute( const isPump = attribute(
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP
); );
@@ -45,7 +35,7 @@ export const characteristics = {
}, },
damage: { damage: {
render({ shell }) { value({ shell }) {
return shell( return shell(
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_ARMOR_DAMAGE ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_ARMOR_DAMAGE
); );
@@ -53,29 +43,10 @@ export const characteristics = {
}, },
dpm: { dpm: {
render({ characteristic }) { value({ characteristic }) {
const damage = characteristic("damage"); const damage = characteristic("damage");
return 1; return 1;
}, },
}, },
} satisfies Record<string, Characteristic>; } satisfies Record<string, Characteristic>;
export const characteristicsOrder: CharacteristicsOrder = [
{
group: CharacteristicsGroup.Firepower,
characteristics: ["gun_type", "dpm"],
},
{
group: CharacteristicsGroup.Maneuverability,
characteristics: [],
},
{
group: CharacteristicsGroup.Survivability,
characteristics: [],
},
{
group: CharacteristicsGroup.Miscellaneous,
characteristics: [],
},
];
@@ -0,0 +1,25 @@
import type { CharacteristicName } from "./characteristics";
type CharacteristicsOrder = {
group: string;
order: CharacteristicName[];
}[];
export const characteristicsGroups = [
{
group: "firepower",
order: ["gun_type", "dpm"],
},
{
group: "maneuverability",
order: [],
},
{
group: "survivability",
order: [],
},
{
group: "miscellaneous",
order: [],
},
] satisfies CharacteristicsOrder;
@@ -0,0 +1,56 @@
import type {
ShellUpgrageSingleChange_AttributeName,
StageParameters,
TankAttributeChange_AttributeName,
} from "@protos/blitz_static_tank_upgrade_single_stage";
import {
characteristics,
type CharacteristicName,
type CharacteristicOutput,
} from "./characteristics";
export function renderCharacteristics(
parameters: StageParameters,
shellId: number
) {
const computed: Partial<Record<CharacteristicName, CharacteristicOutput>> =
{};
function characteristic(name: CharacteristicName) {
if (name in computed) return computed[name] as CharacteristicOutput;
throw new Error(`${name} not computed yet`);
}
function attribute(name: TankAttributeChange_AttributeName) {
const attribute = parameters.attributes.find(
(attribute) => attribute.attribute_name === name
);
if (!attribute) throw new Error(`Attribute ${name} not found`);
("");
return attribute.value;
}
function shell(name: ShellUpgrageSingleChange_AttributeName) {
const shell = parameters.shells_upgrades.find(
(shell) => shell.shell_id === name
);
if (!shell) throw new Error(`Shell ${name} not found`);
const attribute = shell.changes.find(
(change) => change.attribute_name === name
);
if (!attribute) throw new Error(`Shell attribute ${name} not found`);
return attribute.value;
}
for (const _name in characteristics) {
const name = _name as CharacteristicName;
const _characteristic = characteristics[name];
const value = _characteristic.value({ characteristic, attribute, shell });
}
}
@@ -1,4 +1,4 @@
import { _characteristicsOrder } from "../../../../constants/characteristics"; import { _characteristicsOrder } from "../../../../core/tankopedia/characteristics";
export function GET() { export function GET() {
return Response.json(_characteristicsOrder); return Response.json(_characteristicsOrder);
@@ -1,7 +1,8 @@
import { times } from "lodash-es"; import { times } from "lodash-es";
import { Suspense, useMemo } from "react"; import { Suspense, useMemo } from "react";
import { api } from "../../../core/api/dynamic"; import { api } from "../../../core/api/dynamic";
import { aggregateStages } from "../../../core/blitz/aggregateStages"; import { aggregateStageParameters } from "../../../core/tankopedia/aggregateStageParameters";
import { characteristics } from "../../../core/tankopedia/characteristics";
import { useAwait } from "../../../hooks/useAwait"; import { useAwait } from "../../../hooks/useAwait";
import { Tankopedia } from "../../../stores/tankopedia"; import { Tankopedia } from "../../../stores/tankopedia";
@@ -18,7 +19,8 @@ function Content({ id }: { id: string }) {
const stage = Tankopedia.use((state) => state.stage); const stage = Tankopedia.use((state) => state.stage);
const parameters = useMemo( const parameters = useMemo(
() => aggregateStages(tank.base_stats!, tank.upgrade_stages, stage), () =>
aggregateStageParameters(tank.base_stats!, tank.upgrade_stages, stage),
[stage] [stage]
); );
@@ -39,26 +41,17 @@ function Content({ id }: { id: string }) {
))} ))}
</div> </div>
<pre children={JSON.stringify(parameters, null, 2)} /> {characteristicsOrder.map(({ group, order }) => (
<h1>{tank.name?.value}</h1>
<h2>Characteristics</h2>
{/* {_characteristicsOrder.map((group) => (
<> <>
<h2>{CharacteristicsGroup[group.group]}</h2> <h2>{group}</h2>
{group.attributes.map( {order.map((name) => {
(attribute) => const characteristic = characteristics[name];
attribute.name in attributes && (
<p> return <span>{}</span>;
{TankAttributeChange_AttributeName[attribute.name]}:{" "} })}
{attributes[attribute.name]}
</p>
)
)}
</> </>
))} */} ))}
</> </>
); );
} }