mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
feat: upgrade stages
This commit is contained in:
1 parent
4033e8618f
commit
ed4b72d85c
2 files changed
+65
-8
No files matched your search
@@ -248,3 +248,21 @@ export const characteristicsOrder: CharacteristicsOrder = [
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
for (const name of Object.values(TankAttributeChange_AttributeName).filter(
|
||||||
|
(value) => typeof value === "number"
|
||||||
|
)) {
|
||||||
|
if (name === TankAttributeChange_AttributeName.ATTRIBUTE_NAME_UNSPECIFIED) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isImplemented = characteristicsOrder.some((group) =>
|
||||||
|
group.attributes.some((attribute) => attribute.name === name)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isImplemented) {
|
||||||
|
throw new Error(`Attribute ${name} is not implemented`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
|
TankAttributeChange,
|
||||||
TankAttributeChange_AttributeName,
|
TankAttributeChange_AttributeName,
|
||||||
TankAttributeChange_Modifier,
|
TankAttributeChange_Modifier,
|
||||||
} from "@protos/blitz_static_tank_upgrade_single_stage";
|
} from "@protos/blitz_static_tank_upgrade_single_stage";
|
||||||
|
import { times } from "lodash-es";
|
||||||
import { Suspense, useMemo } from "react";
|
import { Suspense, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
CharacteristicsGroup,
|
CharacteristicsGroup,
|
||||||
@@ -29,17 +31,40 @@ function Content({ id }: { id: string }) {
|
|||||||
Record<TankAttributeChange_AttributeName, number>
|
Record<TankAttributeChange_AttributeName, number>
|
||||||
> = {};
|
> = {};
|
||||||
|
|
||||||
for (const { attribute_name, value, modifier } of tank.base_stats!
|
function patch(changes: TankAttributeChange[]) {
|
||||||
.attributes) {
|
for (const { attribute_name, value, modifier } of changes) {
|
||||||
if (modifier !== TankAttributeChange_Modifier.MODIFIER_OVERRIDE) {
|
switch (modifier) {
|
||||||
throw new Error(
|
case TankAttributeChange_Modifier.MODIFIER_OVERRIDE:
|
||||||
`Unexpected modifier ${TankAttributeChange_Modifier[modifier]}`
|
attributes[attribute_name] = value;
|
||||||
);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
attributes[attribute_name] = value;
|
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: {
|
||||||
|
if (!(attribute_name in attributes)) {
|
||||||
|
throw new Error(
|
||||||
|
`Missing attribute ${TankAttributeChange_AttributeName[attribute_name]} to modify`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: {
|
||||||
|
attributes[attribute_name]! *= value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(
|
||||||
|
`Unhandled modified ${TankAttributeChange_Modifier[modifier]}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patch(tank.base_stats!.attributes);
|
||||||
|
|
||||||
|
times(stage, (index) => {
|
||||||
|
patch(tank.upgrade_stages[index].attributes);
|
||||||
|
});
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}, [stage]);
|
}, [stage]);
|
||||||
|
|
||||||
@@ -49,6 +74,20 @@ function Content({ id }: { id: string }) {
|
|||||||
|
|
||||||
<h2>Characteristics</h2>
|
<h2>Characteristics</h2>
|
||||||
|
|
||||||
|
<div style={{ display: "flex" }}>
|
||||||
|
{times(tank.upgrade_stages.length, (index) => (
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
Tankopedia.mutate((draft) => {
|
||||||
|
draft.stage = index;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Stage {index + 1} {index === stage && "(selected)"}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
{characteristicsOrder.map((group) => (
|
{characteristicsOrder.map((group) => (
|
||||||
<>
|
<>
|
||||||
<h2>{CharacteristicsGroup[group.group]}</h2>
|
<h2>{CharacteristicsGroup[group.group]}</h2>
|
||||||
|
|||||||
Reference in new issue
Block a user