fix: proper pitch limits

This commit is contained in:
TrèsAbhi committed 2025-12-20 10:26:25 -06:00
1 parent 23751fbdf3
commit 9a30af3818
4 files changed
+48 -27

No files matched your search

@@ -1,5 +1,7 @@
import type { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import { import {
ShellUpgrageSingleChange_AttributeName, ShellUpgrageSingleChange_AttributeName,
StageParameters,
TankAttributeChange_AttributeName, TankAttributeChange_AttributeName,
} from "@protos/blitz_static_tank_upgrade_single_stage"; } from "@protos/blitz_static_tank_upgrade_single_stage";
import type { TankState } from "./tankState"; import type { TankState } from "./tankState";
@@ -13,6 +15,8 @@ type Characteristic = (helpers: {
shell: (name: ShellUpgrageSingleChange_AttributeName) => number; shell: (name: ShellUpgrageSingleChange_AttributeName) => number;
shellSafe: (name: ShellUpgrageSingleChange_AttributeName) => number | null; shellSafe: (name: ShellUpgrageSingleChange_AttributeName) => number | null;
state: TankState; state: TankState;
tank: TankCatalogComponent;
parameters: StageParameters;
}) => CharacteristicOutput; }) => CharacteristicOutput;
export type CharacteristicName = keyof typeof characteristics; export type CharacteristicName = keyof typeof characteristics;
@@ -208,20 +212,24 @@ export const characteristics = {
); );
}, },
gun_depression({ attributeSafe }) { gun_depression({ parameters }) {
return ( const pitchLimit = parameters.pitch_limits_down.find(
attributeSafe( (pitchLimit) => pitchLimit.angle === 0
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_PITCH_LIMIT_DOWN
) ?? -Infinity
); );
if (!pitchLimit) throw new Error("No angle 0 depression pitch limit found");
return pitchLimit.limit;
}, },
gun_elevation({ attributeSafe }) { gun_elevation({ parameters }) {
return ( const pitchLimit = parameters.pitch_limits_up.find(
attributeSafe( (pitchLimit) => pitchLimit.angle === 0
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_PITCH_LIMIT_UP
) ?? -Infinity
); );
if (!pitchLimit) throw new Error("No angle 0 elevation pitch limit found");
return pitchLimit.limit;
}, },
engine_power({ attribute }) { engine_power({ attribute }) {
@@ -1,8 +1,9 @@
import type { TankCatalogComponent } from "@protos/blitz_static_tank_component";
import { import {
ShellUpgrageSingleChange_AttributeName, ShellUpgrageSingleChange_AttributeName,
TankAttributeChange_AttributeName, TankAttributeChange_AttributeName,
type StageParameters,
} from "@protos/blitz_static_tank_upgrade_single_stage"; } from "@protos/blitz_static_tank_upgrade_single_stage";
import { aggregateStageParameters } from "./aggregateStageParameters";
import { import {
characteristics, characteristics,
type CharacteristicName, type CharacteristicName,
@@ -11,9 +12,14 @@ import {
import type { TankState } from "./tankState"; import type { TankState } from "./tankState";
export function computeCharacteristics( export function computeCharacteristics(
parameters: StageParameters, tank: TankCatalogComponent,
state: TankState state: TankState
) { ) {
const parameters = aggregateStageParameters(
tank.base_stats!,
tank.upgrade_stages.slice(0, state.stage)
);
const computed: Partial<Record<CharacteristicName, CharacteristicOutput>> = const computed: Partial<Record<CharacteristicName, CharacteristicOutput>> =
{}; {};
@@ -81,9 +87,17 @@ export function computeCharacteristics(
shell, shell,
shellSafe, shellSafe,
state, state,
tank,
parameters,
}); });
computed[name] = value; computed[name] = value;
} }
return computed as Record<CharacteristicName, CharacteristicOutput>; return {
characteristics: computed as Record<
CharacteristicName,
CharacteristicOutput
>,
parameters,
};
} }
@@ -1,7 +1,6 @@
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 { aggregateStageParameters } from "../../../core/tankopedia/aggregateStageParameters";
import { characteristicsOrder } from "../../../core/tankopedia/characteristicsOrder"; import { characteristicsOrder } from "../../../core/tankopedia/characteristicsOrder";
import { computeCharacteristics } from "../../../core/tankopedia/computeCharacteristics"; import { computeCharacteristics } from "../../../core/tankopedia/computeCharacteristics";
import { useAwait } from "../../../hooks/useAwait"; import { useAwait } from "../../../hooks/useAwait";
@@ -21,16 +20,8 @@ function Content({ id }: { id: string }) {
Tankopedia.useInitialization(tank.upgrade_stages.length); Tankopedia.useInitialization(tank.upgrade_stages.length);
const protagonist = Tankopedia.use((state) => state.protagonist); const protagonist = Tankopedia.use((state) => state.protagonist);
const parameters = useMemo( const { characteristics, parameters } = useMemo(
() => () => computeCharacteristics(tank, protagonist),
aggregateStageParameters(
tank.base_stats!,
tank.upgrade_stages.slice(0, protagonist.stage)
),
[protagonist]
);
const characteristics = useMemo(
() => computeCharacteristics(parameters, protagonist),
[protagonist] [protagonist]
); );
@@ -77,7 +68,7 @@ function Content({ id }: { id: string }) {
{order.map((entry) => { {order.map((entry) => {
if ("toy" in entry) { if ("toy" in entry) {
return <p>toy: {entry.toy}</p>; return <p key={`toy-${entry.toy}`}>toy: {entry.toy}</p>;
} else { } else {
const characteristic = characteristics[entry.name]; const characteristic = characteristics[entry.name];
@@ -96,7 +87,7 @@ function Content({ id }: { id: string }) {
} }
return ( return (
<p key={entry.name}> <p key={`characteristic-${entry.name}`}>
{entry.name}: {rendered} {entry.units && `${entry.units}`} {entry.name}: {rendered} {entry.units && `${entry.units}`}
</p> </p>
); );
+9 -1
View File
@@ -6,5 +6,13 @@ interface Tankopedia {
} }
export const Tankopedia = new Varuna<Tankopedia, number>((maxStage) => ({ export const Tankopedia = new Varuna<Tankopedia, number>((maxStage) => ({
protagonist: { stage: maxStage, shell: 0 }, protagonist: {
stage: maxStage,
shell: 0,
isGunDamaged: false,
isHullTraversing: false,
isShooting: false,
isTurretTraversing: false,
speed: 0,
},
})); }));