fix: find att0 correctly

This commit is contained in:
TrèsAbhi committed 2025-12-18 13:16:20 -06:00
1 parent 6ba6e10108
commit 0e0f4fbe9f
2 files changed
+17 -14

No files matched your search

@@ -28,23 +28,26 @@ function patch(stage0: StageParameters, stage1: StageParameters) {
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: case TankAttributeChange_Modifier.MODIFIER_MULTIPLY:
case TankAttributeChange_Modifier.MODIFIER_ADD: case TankAttributeChange_Modifier.MODIFIER_ADD:
if (!(attribute1.attribute_name in stage0)) { const attribute0 = stage0.attributes.find(
(attribute0) =>
attribute0.attribute_name === attribute1.attribute_name
);
if (!attribute0) {
throw new Error( throw new Error(
`Missing attribute ${ `Missing attribute ${
TankAttributeChange_AttributeName[attribute1.attribute_name] TankAttributeChange_AttributeName[attribute1.attribute_name]
} to modify` } (${attribute1.attribute_name}) to modify`
); );
} }
const oldValue = stage0.attributes[attribute1.attribute_name]!.value;
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: { case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: {
value1 = oldValue! * attribute1.value; value1 = attribute0!.value! * attribute1.value;
break; break;
} }
case TankAttributeChange_Modifier.MODIFIER_ADD: { case TankAttributeChange_Modifier.MODIFIER_ADD: {
value1 = oldValue! + attribute1.value; value1 = attribute0!.value! + attribute1.value;
break; break;
} }
@@ -17,33 +17,33 @@ function Content({ id }: { id: string }) {
const tank = useAwait(() => api.tank(id), `tank-${id}`); const tank = useAwait(() => api.tank(id), `tank-${id}`);
const stage = Tankopedia.use((state) => state.stage); const stage = Tankopedia.use((state) => state.stage);
const parameters = useMemo(
const aggregatedStages = useMemo(
() => aggregateStages(tank.base_stats!, tank.upgrade_stages, stage), () => aggregateStages(tank.base_stats!, tank.upgrade_stages, stage),
[stage] [stage]
); );
return ( return (
<> <>
<pre children={JSON.stringify(tank, null, 2)} />
<h1>{tank.name?.value}</h1>
<h2>Characteristics</h2>
<div style={{ display: "flex" }}> <div style={{ display: "flex" }}>
{times(tank.upgrade_stages.length, (index) => ( {times(tank.upgrade_stages.length, (index) => (
<button <button
key={index}
onClick={() => { onClick={() => {
Tankopedia.mutate((draft) => { Tankopedia.mutate((draft) => {
draft.stage = index; draft.stage = index;
}); });
}} }}
> >
Stage {index + 1} {index === stage && "(selected)"} Stage {index} {index === stage && "(selected)"}
</button> </button>
))} ))}
</div> </div>
<pre children={JSON.stringify(parameters, null, 2)} />
<h1>{tank.name?.value}</h1>
<h2>Characteristics</h2>
{/* {_characteristicsOrder.map((group) => ( {/* {_characteristicsOrder.map((group) => (
<> <>
<h2>{CharacteristicsGroup[group.group]}</h2> <h2>{CharacteristicsGroup[group.group]}</h2>