mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
adrenaline inclusivitiy
This commit is contained in:
1 parent
f945786e2f
commit
7a7c73d77b
4 files changed
+41
-30
No files matched your search
@@ -5,7 +5,6 @@ import { StandardPrice } from "@protos/blitz_static_standard_price";
|
|||||||
import type { UpgradeLine } from "@protos/blitz_static_tank_upgrade_line";
|
import type { UpgradeLine } from "@protos/blitz_static_tank_upgrade_line";
|
||||||
import type { StageParameters } from "@protos/blitz_static_tank_upgrade_single_stage";
|
import type { StageParameters } from "@protos/blitz_static_tank_upgrade_single_stage";
|
||||||
import {
|
import {
|
||||||
ButtonIcon,
|
|
||||||
CornerBottomLeftIcon,
|
CornerBottomLeftIcon,
|
||||||
DoubleArrowLeftIcon,
|
DoubleArrowLeftIcon,
|
||||||
DoubleArrowRightIcon,
|
DoubleArrowRightIcon,
|
||||||
@@ -30,15 +29,18 @@ import { useUpgradePreset } from "../../hooks/useUpgradePreset";
|
|||||||
import { Tankopedia } from "../../stores/tankopedia";
|
import { Tankopedia } from "../../stores/tankopedia";
|
||||||
import { Button } from "../Button";
|
import { Button } from "../Button";
|
||||||
import { Heading } from "../Heading";
|
import { Heading } from "../Heading";
|
||||||
import { Link } from "../Link";
|
import { IconButton } from "../IconButton";
|
||||||
import { Price } from "../Price";
|
import { Price } from "../Price";
|
||||||
import { Section } from "../Section";
|
import { Section } from "../Section";
|
||||||
import { Text } from "../Text";
|
import { Text } from "../Text";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
import { IconButton } from "../IconButton";
|
import type { ComputedCharacteristics } from "../../tankopedia/computeCharacteristics";
|
||||||
import { Tank } from "@protos/tank";
|
|
||||||
|
|
||||||
export function TankopediaLoadout() {
|
interface TankopediaLoadoutProps {
|
||||||
|
characteristics: ComputedCharacteristics;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TankopediaLoadout({ characteristics }: TankopediaLoadoutProps) {
|
||||||
const tank = useProtagonist();
|
const tank = useProtagonist();
|
||||||
|
|
||||||
const showModules = tank.tank!.upgrade_lines.some(
|
const showModules = tank.tank!.upgrade_lines.some(
|
||||||
@@ -49,22 +51,30 @@ export function TankopediaLoadout() {
|
|||||||
<Section>
|
<Section>
|
||||||
{showModules && <Modules />}
|
{showModules && <Modules />}
|
||||||
<Equipment />
|
<Equipment />
|
||||||
<Consumables />
|
<Consumables characteristics={characteristics} />
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Consumables() {
|
interface ConsumablesProps {
|
||||||
|
characteristics: ComputedCharacteristics;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Consumables({ characteristics }: ConsumablesProps) {
|
||||||
const consumables = useConsumables();
|
const consumables = useConsumables();
|
||||||
const tierPrices = useTierPrices();
|
const tierPrices = useTierPrices();
|
||||||
const tank = useProtagonist();
|
const tank = useProtagonist();
|
||||||
const isCompatible = useCompatibility(tank);
|
const isCompatible = useCompatibility(tank, characteristics);
|
||||||
|
|
||||||
return Object.values(consumables.consumables).map(
|
return Object.entries(consumables.consumables).map(
|
||||||
({ compatibility, consumable, purchase }) => {
|
([id, { compatibility, consumable, purchase }]) => {
|
||||||
if (!isCompatible(compatibility!)) return null;
|
if (!isCompatible(compatibility!)) return null;
|
||||||
|
|
||||||
return <span>{JSON.stringify(consumable, null, 2)}</span>;
|
return (
|
||||||
|
<span>
|
||||||
|
{id} {JSON.stringify(consumable, null, 2)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,13 @@ import { TankAttributeChange_AttributeName } from "@protos/blitz_static_tank_upg
|
|||||||
import type { Sets } from "@protos/sets";
|
import type { Sets } from "@protos/sets";
|
||||||
import type { Tank } from "@protos/tank";
|
import type { Tank } from "@protos/tank";
|
||||||
import { useSets } from "./useSets";
|
import { useSets } from "./useSets";
|
||||||
|
import type { ComputedCharacteristics } from "../tankopedia/computeCharacteristics";
|
||||||
|
import { GunType } from "../tankopedia/characteristics";
|
||||||
|
|
||||||
export function useCompatibility(tank: Tank) {
|
export function useCompatibility(
|
||||||
|
tank: Tank,
|
||||||
|
characteristics: ComputedCharacteristics,
|
||||||
|
) {
|
||||||
const sets = useSets();
|
const sets = useSets();
|
||||||
|
|
||||||
return function (compatibility: CompatibilityComponent) {
|
return function (compatibility: CompatibilityComponent) {
|
||||||
@@ -26,11 +31,13 @@ export function useCompatibility(tank: Tank) {
|
|||||||
compatibility.tank_compatibility.include,
|
compatibility.tank_compatibility.include,
|
||||||
tank,
|
tank,
|
||||||
sets,
|
sets,
|
||||||
|
characteristics,
|
||||||
) &&
|
) &&
|
||||||
!tankCompatibilityApplies(
|
!tankCompatibilityApplies(
|
||||||
compatibility.tank_compatibility.exclude,
|
compatibility.tank_compatibility.exclude,
|
||||||
tank,
|
tank,
|
||||||
sets,
|
sets,
|
||||||
|
characteristics,
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -40,6 +47,7 @@ function tankCompatibilityApplies(
|
|||||||
include: TankCompatibility_Include | undefined,
|
include: TankCompatibility_Include | undefined,
|
||||||
tank: Tank,
|
tank: Tank,
|
||||||
sets: Sets,
|
sets: Sets,
|
||||||
|
characteristics: ComputedCharacteristics,
|
||||||
) {
|
) {
|
||||||
if (include === undefined) {
|
if (include === undefined) {
|
||||||
return true;
|
return true;
|
||||||
@@ -57,7 +65,9 @@ function tankCompatibilityApplies(
|
|||||||
) ||
|
) ||
|
||||||
include.classes.some((_class) => _class === tank.tank!.tank_class) ||
|
include.classes.some((_class) => _class === tank.tank!.tank_class) ||
|
||||||
include.catalogs_id.some((id) => id === tank.id) ||
|
include.catalogs_id.some((id) => id === tank.id) ||
|
||||||
include.tank_traits.some((trait) => tankHasTraits(trait, tank)) ||
|
include.tank_traits.some((trait) =>
|
||||||
|
tankHasTraits(trait, tank, characteristics),
|
||||||
|
) ||
|
||||||
include.types.some((type) => type === tank.tank!.tank_type) ||
|
include.types.some((type) => type === tank.tank!.tank_type) ||
|
||||||
include.tank_sets_catalog_ids.some((id) =>
|
include.tank_sets_catalog_ids.some((id) =>
|
||||||
Object.entries(sets.sets).some(
|
Object.entries(sets.sets).some(
|
||||||
@@ -74,23 +84,14 @@ function tankCompatibilityApplies(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tankHasTraits(traits: TankTraits, tank: Tank) {
|
function tankHasTraits(
|
||||||
|
traits: TankTraits,
|
||||||
|
tank: Tank,
|
||||||
|
characteristics: ComputedCharacteristics,
|
||||||
|
) {
|
||||||
switch (traits) {
|
switch (traits) {
|
||||||
case TankTraits.TANK_TRAITS_HAS_CLIP:
|
case TankTraits.TANK_TRAITS_HAS_CLIP:
|
||||||
// TODO: use current tank state to check if the current gun has a clip
|
return characteristics.gun_type !== GunType.Regular;
|
||||||
|
|
||||||
return tank.tank!.upgrade_lines.some((line) =>
|
|
||||||
line.stages.some((stage) =>
|
|
||||||
stage.attributes.every((attribute) =>
|
|
||||||
attribute.attribute_name !==
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP &&
|
|
||||||
attribute.attribute_name ===
|
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE
|
|
||||||
? attribute.value === 1
|
|
||||||
: true,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown trait: ${traits}`);
|
throw new Error(`Unknown trait: ${traits}`);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export const Page = withErrorWrapper(
|
|||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<TankopediaLoadout />
|
<TankopediaLoadout characteristics={characteristics} />
|
||||||
|
|
||||||
<h2>characteristics</h2>
|
<h2>characteristics</h2>
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export enum GunType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const characteristics = {
|
export const characteristics = {
|
||||||
gun_type({ attributeSafe, attribute }) {
|
gun_type({ attributeSafe }) {
|
||||||
const isPump =
|
const isPump =
|
||||||
attributeSafe(TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP) ??
|
attributeSafe(TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP) ??
|
||||||
0;
|
0;
|
||||||
|
|||||||
Reference in new issue
Block a user