Files
blitzkit/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts
T

59 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-12-18 15:30:18 -06:00
import type {
ShellUpgrageSingleChange_AttributeName,
StageParameters,
TankAttributeChange_AttributeName,
} from "@protos/blitz_static_tank_upgrade_single_stage";
import {
characteristics,
type CharacteristicName,
type CharacteristicOutput,
} from "./characteristics";
2025-12-18 16:12:01 -06:00
import type { TankState } from "./tankState";
2025-12-18 15:30:18 -06:00
2025-12-18 16:12:01 -06:00
export function computeCharacteristics(
2025-12-18 15:30:18 -06:00
parameters: StageParameters,
2025-12-18 16:12:01 -06:00
state: TankState
2025-12-18 15:30:18 -06:00
) {
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(
2025-12-18 16:12:01 -06:00
(shell) => shell.shell_id === state.shell
2025-12-18 15:30:18 -06:00
);
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;
2025-12-18 16:12:01 -06:00
const value = characteristics[name]({ characteristic, attribute, shell });
computed[name] = value;
2025-12-18 15:30:18 -06:00
}
2025-12-18 16:12:01 -06:00
return computed as Record<CharacteristicName, CharacteristicOutput>;
2025-12-18 15:30:18 -06:00
}