mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
some data driven characteristics
This commit is contained in:
1 parent
b6f9ae9187
commit
8842283f0e
4 files changed
+110
-7
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
export function computeCharacteristics() {
|
||||||
|
const characteristics = {};
|
||||||
|
|
||||||
|
return characteristics;
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import {
|
||||||
|
CharacteristicType,
|
||||||
|
type Characteristic,
|
||||||
|
} from "../types/characteristics";
|
||||||
|
|
||||||
|
export const characteristics = {
|
||||||
|
gun_type: {
|
||||||
|
type: CharacteristicType.Enum,
|
||||||
|
compute({ gun }) {
|
||||||
|
return gun.gun_type!.$case;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
clip_size: {
|
||||||
|
type: CharacteristicType.Number,
|
||||||
|
|
||||||
|
should_render({ gun }) {
|
||||||
|
return gun.gun_type!.$case !== "regular";
|
||||||
|
},
|
||||||
|
|
||||||
|
compute({ gun }) {
|
||||||
|
if (gun.gun_type!.$case === "regular") return 1;
|
||||||
|
return gun.gun_type!.value.shell_count;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
assault_damage_coefficient: {
|
||||||
|
type: CharacteristicType.Number,
|
||||||
|
|
||||||
|
compute({ gun, shell, assault_distance }) {
|
||||||
|
if (
|
||||||
|
!gun.assault_ranges ||
|
||||||
|
!gun.assault_ranges.types.includes(shell.type)
|
||||||
|
) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
gun.assault_ranges.ranges.find(
|
||||||
|
({ distance }) => distance >= assault_distance,
|
||||||
|
)?.factor ?? 0
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
armor_damage_coefficient: {
|
||||||
|
type: CharacteristicType.Number,
|
||||||
|
|
||||||
|
compute() {
|
||||||
|
let coefficient = 1;
|
||||||
|
|
||||||
|
return coefficient;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
damage: {
|
||||||
|
type: CharacteristicType.Number,
|
||||||
|
compute({ characteristic, shell, equalizer }) {
|
||||||
|
let coefficient = 1;
|
||||||
|
|
||||||
|
coefficient *= characteristic("armor_damage_coefficient") as number;
|
||||||
|
coefficient *= characteristic("assault_damage_coefficient") as number;
|
||||||
|
coefficient *= equalizer.damage;
|
||||||
|
|
||||||
|
return coefficient * shell.armor_damage;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies Record<string, Characteristic>;
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { api } from "../../../../../blitzkit/api";
|
import { api } from "../../../../../blitzkit/api";
|
||||||
|
import { computeCharacteristics } from "../../../../../blitzkit/computeCharacteristics";
|
||||||
import { withErrorWrapper } from "../../../../../hocs/withErrorWrapper";
|
import { withErrorWrapper } from "../../../../../hocs/withErrorWrapper";
|
||||||
import { withLocale } from "../../../../../hocs/withLocale";
|
import { withLocale } from "../../../../../hocs/withLocale";
|
||||||
import { useAwait } from "../../../../../hooks/useAwait";
|
import { useAwait } from "../../../../../hooks/useAwait";
|
||||||
|
import { useEquipment } from "../../../../../hooks/useEquipment";
|
||||||
import { Tankopedia } from "../../../../../stores/tankopedia";
|
import { Tankopedia } from "../../../../../stores/tankopedia";
|
||||||
import styles from "./_index.module.css";
|
import styles from "./_index.module.css";
|
||||||
|
|
||||||
@@ -19,13 +21,8 @@ export const Page = withErrorWrapper(
|
|||||||
const protagonist = Tankopedia.use((state) => state.protagonist);
|
const protagonist = Tankopedia.use((state) => state.protagonist);
|
||||||
const protagonistEquipment = useEquipment(protagonistTank.tank!);
|
const protagonistEquipment = useEquipment(protagonistTank.tank!);
|
||||||
|
|
||||||
const { characteristics, parameters } = useMemo(
|
const characteristics = useMemo(
|
||||||
() =>
|
() => computeCharacteristics(),
|
||||||
computeCharacteristics(
|
|
||||||
protagonistTank,
|
|
||||||
protagonistEquipment,
|
|
||||||
protagonist,
|
|
||||||
),
|
|
||||||
[protagonist],
|
[protagonist],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { Equalizer, GunDefinition, ShellDefinition } from "@blitzkit/core";
|
||||||
|
import { characteristics } from "../config/characteristics";
|
||||||
|
|
||||||
|
export type Characteristic = {
|
||||||
|
should_render?(context: CharacteristicContext): boolean;
|
||||||
|
} & (
|
||||||
|
| {
|
||||||
|
type: CharacteristicType.Enum;
|
||||||
|
compute(context: CharacteristicContext): string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: CharacteristicType.Number;
|
||||||
|
compute(context: CharacteristicContext): number;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
interface CharacteristicContext {
|
||||||
|
gun: GunDefinition;
|
||||||
|
shell: ShellDefinition;
|
||||||
|
|
||||||
|
equalizer: Equalizer;
|
||||||
|
|
||||||
|
assault_distance: number;
|
||||||
|
|
||||||
|
characteristic(
|
||||||
|
name: keyof typeof characteristics,
|
||||||
|
): ReturnType<Characteristic["compute"]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum CharacteristicType {
|
||||||
|
Enum,
|
||||||
|
Number,
|
||||||
|
}
|
||||||
Reference in new issue
Block a user