mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +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 { StageParameters } from "@protos/blitz_static_tank_upgrade_single_stage";
|
||||
import {
|
||||
ButtonIcon,
|
||||
CornerBottomLeftIcon,
|
||||
DoubleArrowLeftIcon,
|
||||
DoubleArrowRightIcon,
|
||||
@@ -30,15 +29,18 @@ import { useUpgradePreset } from "../../hooks/useUpgradePreset";
|
||||
import { Tankopedia } from "../../stores/tankopedia";
|
||||
import { Button } from "../Button";
|
||||
import { Heading } from "../Heading";
|
||||
import { Link } from "../Link";
|
||||
import { IconButton } from "../IconButton";
|
||||
import { Price } from "../Price";
|
||||
import { Section } from "../Section";
|
||||
import { Text } from "../Text";
|
||||
import styles from "./index.module.css";
|
||||
import { IconButton } from "../IconButton";
|
||||
import { Tank } from "@protos/tank";
|
||||
import type { ComputedCharacteristics } from "../../tankopedia/computeCharacteristics";
|
||||
|
||||
export function TankopediaLoadout() {
|
||||
interface TankopediaLoadoutProps {
|
||||
characteristics: ComputedCharacteristics;
|
||||
}
|
||||
|
||||
export function TankopediaLoadout({ characteristics }: TankopediaLoadoutProps) {
|
||||
const tank = useProtagonist();
|
||||
|
||||
const showModules = tank.tank!.upgrade_lines.some(
|
||||
@@ -49,22 +51,30 @@ export function TankopediaLoadout() {
|
||||
<Section>
|
||||
{showModules && <Modules />}
|
||||
<Equipment />
|
||||
<Consumables />
|
||||
<Consumables characteristics={characteristics} />
|
||||
</Section>
|
||||
);
|
||||
}
|
||||
|
||||
function Consumables() {
|
||||
interface ConsumablesProps {
|
||||
characteristics: ComputedCharacteristics;
|
||||
}
|
||||
|
||||
function Consumables({ characteristics }: ConsumablesProps) {
|
||||
const consumables = useConsumables();
|
||||
const tierPrices = useTierPrices();
|
||||
const tank = useProtagonist();
|
||||
const isCompatible = useCompatibility(tank);
|
||||
const isCompatible = useCompatibility(tank, characteristics);
|
||||
|
||||
return Object.values(consumables.consumables).map(
|
||||
({ compatibility, consumable, purchase }) => {
|
||||
return Object.entries(consumables.consumables).map(
|
||||
([id, { compatibility, consumable, purchase }]) => {
|
||||
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 { Tank } from "@protos/tank";
|
||||
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();
|
||||
|
||||
return function (compatibility: CompatibilityComponent) {
|
||||
@@ -26,11 +31,13 @@ export function useCompatibility(tank: Tank) {
|
||||
compatibility.tank_compatibility.include,
|
||||
tank,
|
||||
sets,
|
||||
characteristics,
|
||||
) &&
|
||||
!tankCompatibilityApplies(
|
||||
compatibility.tank_compatibility.exclude,
|
||||
tank,
|
||||
sets,
|
||||
characteristics,
|
||||
))
|
||||
);
|
||||
};
|
||||
@@ -40,6 +47,7 @@ function tankCompatibilityApplies(
|
||||
include: TankCompatibility_Include | undefined,
|
||||
tank: Tank,
|
||||
sets: Sets,
|
||||
characteristics: ComputedCharacteristics,
|
||||
) {
|
||||
if (include === undefined) {
|
||||
return true;
|
||||
@@ -57,7 +65,9 @@ function tankCompatibilityApplies(
|
||||
) ||
|
||||
include.classes.some((_class) => _class === tank.tank!.tank_class) ||
|
||||
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.tank_sets_catalog_ids.some((id) =>
|
||||
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) {
|
||||
case TankTraits.TANK_TRAITS_HAS_CLIP:
|
||||
// TODO: use current tank state to check if the current gun has a clip
|
||||
|
||||
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,
|
||||
),
|
||||
),
|
||||
);
|
||||
return characteristics.gun_type !== GunType.Regular;
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown trait: ${traits}`);
|
||||
|
||||
@@ -41,7 +41,7 @@ export const Page = withErrorWrapper(
|
||||
|
||||
<br />
|
||||
|
||||
<TankopediaLoadout />
|
||||
<TankopediaLoadout characteristics={characteristics} />
|
||||
|
||||
<h2>characteristics</h2>
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export enum GunType {
|
||||
}
|
||||
|
||||
export const characteristics = {
|
||||
gun_type({ attributeSafe, attribute }) {
|
||||
gun_type({ attributeSafe }) {
|
||||
const isPump =
|
||||
attributeSafe(TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP) ??
|
||||
0;
|
||||
|
||||
Reference in new issue
Block a user