mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-17 10:53:57 +01:00
feat: shells
This commit is contained in:
1 parent
4f1c4421e5
commit
c6b7918525
5 files changed
+69
-27
No files matched your search
@@ -6,18 +6,10 @@ import {
|
||||
export type CharacteristicOutput = number | null;
|
||||
|
||||
type Characteristic = (helpers: {
|
||||
characteristic: (
|
||||
name: CharacteristicName,
|
||||
error?: boolean
|
||||
) => CharacteristicOutput;
|
||||
attribute: (
|
||||
name: TankAttributeChange_AttributeName,
|
||||
error?: boolean
|
||||
) => number;
|
||||
shell: (
|
||||
name: ShellUpgrageSingleChange_AttributeName,
|
||||
error?: boolean
|
||||
) => number;
|
||||
characteristic: (name: CharacteristicName) => CharacteristicOutput;
|
||||
attribute: (name: TankAttributeChange_AttributeName) => number;
|
||||
shell: (name: ShellUpgrageSingleChange_AttributeName) => number;
|
||||
shellSafe: (name: ShellUpgrageSingleChange_AttributeName) => number | null;
|
||||
}) => CharacteristicOutput;
|
||||
|
||||
export type CharacteristicName = keyof typeof characteristics;
|
||||
@@ -96,8 +88,8 @@ export const characteristics = {
|
||||
return shell(ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_CALIBER);
|
||||
},
|
||||
|
||||
normalization({ shell }) {
|
||||
return shell(
|
||||
normalization({ shellSafe }) {
|
||||
return shellSafe(
|
||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_NORMALIZATION
|
||||
);
|
||||
},
|
||||
@@ -112,15 +104,17 @@ export const characteristics = {
|
||||
return shell(ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_SPEED);
|
||||
},
|
||||
|
||||
shell_range({ shell }) {
|
||||
return shell(
|
||||
shell_range({ shellSafe }) {
|
||||
const maxDistance = shellSafe(
|
||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MAX_DISTANCE
|
||||
);
|
||||
return maxDistance === null ? Infinity : maxDistance;
|
||||
},
|
||||
|
||||
shell_capacity({ shell }) {
|
||||
return shell(
|
||||
shell_capacity({ shellSafe }) {
|
||||
const count = shellSafe(
|
||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MAX_COUNT
|
||||
);
|
||||
return count === -1 || count === null ? Infinity : count;
|
||||
},
|
||||
} satisfies Record<string, Characteristic>;
|
||||
@@ -36,7 +36,7 @@ export function computeCharacteristics(
|
||||
return attribute.value;
|
||||
}
|
||||
|
||||
function shell(name: ShellUpgrageSingleChange_AttributeName) {
|
||||
function shellSafe(name: ShellUpgrageSingleChange_AttributeName) {
|
||||
const shell = parameters.shells_upgrades.find(
|
||||
(shell) => shell.shell_id === state.shell
|
||||
);
|
||||
@@ -51,18 +51,29 @@ export function computeCharacteristics(
|
||||
(change) => change.attribute_name === name
|
||||
);
|
||||
|
||||
if (!attribute) {
|
||||
return attribute ? attribute.value : null;
|
||||
}
|
||||
|
||||
function shell(name: ShellUpgrageSingleChange_AttributeName) {
|
||||
const attribute = shellSafe(name);
|
||||
|
||||
if (attribute === null) {
|
||||
throw new Error(
|
||||
`Shell attribute ${ShellUpgrageSingleChange_AttributeName[name]} (${name}) not found`
|
||||
);
|
||||
}
|
||||
|
||||
return attribute.value;
|
||||
return attribute;
|
||||
}
|
||||
|
||||
for (const _name in characteristics) {
|
||||
const name = _name as CharacteristicName;
|
||||
const value = characteristics[name]({ characteristic, attribute, shell });
|
||||
const value = characteristics[name]({
|
||||
characteristic,
|
||||
attribute,
|
||||
shell,
|
||||
shellSafe,
|
||||
});
|
||||
computed[name] = value;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user