mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +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 {
|
||||
TankAttributeChange,
|
||||
TankAttributeChange_AttributeName,
|
||||
TankAttributeChange_Modifier,
|
||||
} from "@protos/blitz_static_tank_upgrade_single_stage";
|
||||
import { times } from "lodash-es";
|
||||
import { Suspense, useMemo } from "react";
|
||||
import {
|
||||
CharacteristicsGroup,
|
||||
@@ -29,17 +31,40 @@ function Content({ id }: { id: string }) {
|
||||
Record<TankAttributeChange_AttributeName, number>
|
||||
> = {};
|
||||
|
||||
for (const { attribute_name, value, modifier } of tank.base_stats!
|
||||
.attributes) {
|
||||
if (modifier !== TankAttributeChange_Modifier.MODIFIER_OVERRIDE) {
|
||||
throw new Error(
|
||||
`Unexpected modifier ${TankAttributeChange_Modifier[modifier]}`
|
||||
);
|
||||
}
|
||||
function patch(changes: TankAttributeChange[]) {
|
||||
for (const { attribute_name, value, modifier } of changes) {
|
||||
switch (modifier) {
|
||||
case TankAttributeChange_Modifier.MODIFIER_OVERRIDE:
|
||||
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;
|
||||
}, [stage]);
|
||||
|
||||
@@ -49,6 +74,20 @@ function Content({ id }: { id: string }) {
|
||||
|
||||
<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) => (
|
||||
<>
|
||||
<h2>{CharacteristicsGroup[group.group]}</h2>
|
||||
|
||||
Reference in new issue
Block a user