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