mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
useCompatibility
This commit is contained in:
1 parent
33bb8ead3c
commit
750bdd236a
7 files changed
+59
-38
No files matched your search
@@ -9,14 +9,14 @@ message ConsumableDefinitions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message Consumable {
|
message Consumable {
|
||||||
required uint32 id = 1;
|
required uint32 id = 1;
|
||||||
required I18nString name = 2;
|
required I18nString name = 2;
|
||||||
required bool game_mode_exclusive = 5;
|
required bool game_mode_exclusive = 5;
|
||||||
repeated ConsumableTankFilter include = 6;
|
repeated TankInclusivityFilter include = 6;
|
||||||
repeated ConsumableTankFilter exclude = 7;
|
repeated TankInclusivityFilter exclude = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ConsumableTankFilter {
|
message TankInclusivityFilter {
|
||||||
oneof filter_type {
|
oneof filter_type {
|
||||||
ConsumableTankTierFilter tiers = 1;
|
ConsumableTankTierFilter tiers = 1;
|
||||||
ConsumableTankIdsFilter ids = 2;
|
ConsumableTankIdsFilter ids = 2;
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ message ProvisionDefinitions {
|
|||||||
message Provision {
|
message Provision {
|
||||||
reserved 3; // crew
|
reserved 3; // crew
|
||||||
|
|
||||||
required uint32 id = 1;
|
required uint32 id = 1;
|
||||||
required I18nString name = 2;
|
required I18nString name = 2;
|
||||||
required bool game_mode_exclusive = 5;
|
required bool game_mode_exclusive = 5;
|
||||||
repeated ConsumableTankFilter include = 6;
|
repeated TankInclusivityFilter include = 6;
|
||||||
repeated ConsumableTankFilter exclude = 7;
|
repeated TankInclusivityFilter exclude = 7;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
|
import type { Consumable } from "@blitzkit/core";
|
||||||
import { TrashIcon } from "@radix-ui/react-icons";
|
import { TrashIcon } from "@radix-ui/react-icons";
|
||||||
|
import { useCompatibility } from "../../hooks/useCompatibility";
|
||||||
|
import { useConsumables } from "../../hooks/useConsumables";
|
||||||
import { useProtagonist } from "../../hooks/useProtagonist";
|
import { useProtagonist } from "../../hooks/useProtagonist";
|
||||||
|
import { useProtagonistGun } from "../../hooks/useProtagonistGun";
|
||||||
import { useStrings } from "../../hooks/useStrings";
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
import { Tankopedia } from "../../stores/tankopedia";
|
import { Tankopedia } from "../../stores/tankopedia";
|
||||||
import { hasUpgrades } from "../../tankopedia/hasUpgrades";
|
import { hasUpgrades } from "../../tankopedia/hasUpgrades";
|
||||||
@@ -116,7 +120,8 @@ function Consumables({ characteristics }: ConsumablesProps) {
|
|||||||
const strings = useStrings();
|
const strings = useStrings();
|
||||||
const consumables = useConsumables();
|
const consumables = useConsumables();
|
||||||
const tank = useProtagonist();
|
const tank = useProtagonist();
|
||||||
const isCompatible = useCompatibility(tank, characteristics);
|
const gun = useProtagonistGun();
|
||||||
|
const isCompatible = useCompatibility(tank, gun);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.section}>
|
<div className={styles.section}>
|
||||||
@@ -136,20 +141,13 @@ function Consumables({ characteristics }: ConsumablesProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.consumables}>
|
<div className={styles.consumables}>
|
||||||
{Object.entries(consumables.consumables).map(
|
{Object.entries(consumables.consumables).map(([id, consumable]) => {
|
||||||
([id, { compatibility, consumable, purchase }]) => {
|
if (!isCompatible(consumable.include, consumable.exclude)) {
|
||||||
if (!isCompatible(compatibility!)) return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return <Consumable key={id} id={id} consumable={consumable} />;
|
||||||
<Consumable
|
})}
|
||||||
key={id}
|
|
||||||
id={id}
|
|
||||||
consumable={consumable!}
|
|
||||||
purchase={purchase!}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -157,8 +155,7 @@ function Consumables({ characteristics }: ConsumablesProps) {
|
|||||||
|
|
||||||
interface ConsumableProps {
|
interface ConsumableProps {
|
||||||
id: string;
|
id: string;
|
||||||
consumable: ConsumableComponent;
|
consumable: Consumable;
|
||||||
purchase: BlitzStaticPurchaseComponent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Consumable({ id, consumable, purchase }: ConsumableProps) {
|
function Consumable({ id, consumable, purchase }: ConsumableProps) {
|
||||||
|
|||||||
+19
-10
@@ -1,17 +1,26 @@
|
|||||||
import {
|
import {
|
||||||
Consumable,
|
|
||||||
ConsumableTankCategoryFilterCategory,
|
ConsumableTankCategoryFilterCategory,
|
||||||
GunDefinition,
|
type GunDefinition,
|
||||||
Provision,
|
type TankDefinition,
|
||||||
TankDefinition,
|
type TankInclusivityFilter,
|
||||||
} from "@blitzkit/protos";
|
} from "@blitzkit/core";
|
||||||
|
|
||||||
export function checkConsumableProvisionInclusivity(
|
export function useCompatibility(tank: TankDefinition, gun: GunDefinition) {
|
||||||
consumableProvision: Consumable | Provision,
|
return function (
|
||||||
|
include?: TankInclusivityFilter[],
|
||||||
|
exclude?: TankInclusivityFilter[],
|
||||||
|
) {
|
||||||
|
return tankCompatibility(tank, gun, include, exclude);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function tankCompatibility(
|
||||||
tank: TankDefinition,
|
tank: TankDefinition,
|
||||||
gun: GunDefinition,
|
gun: GunDefinition,
|
||||||
|
include?: TankInclusivityFilter[],
|
||||||
|
exclude?: TankInclusivityFilter[],
|
||||||
) {
|
) {
|
||||||
const included = consumableProvision.include?.every((rule) => {
|
const included = include?.every((rule) => {
|
||||||
switch (rule.filter_type!.$case) {
|
switch (rule.filter_type!.$case) {
|
||||||
case "tiers":
|
case "tiers":
|
||||||
return (
|
return (
|
||||||
@@ -29,7 +38,7 @@ export function checkConsumableProvisionInclusivity(
|
|||||||
throw new SyntaxError("Category filtering found in include rule");
|
throw new SyntaxError("Category filtering found in include rule");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const excluded = consumableProvision.exclude?.some((rule) => {
|
const excluded = exclude?.some((rule) => {
|
||||||
switch (rule.filter_type!.$case) {
|
switch (rule.filter_type!.$case) {
|
||||||
case "tiers":
|
case "tiers":
|
||||||
return (
|
return (
|
||||||
@@ -53,5 +62,5 @@ export function checkConsumableProvisionInclusivity(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return consumableProvision.include?.length > 0 && included && !excluded;
|
return include !== undefined && include?.length > 0 && included && !excluded;
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,5 @@ import { useAwait } from "./useAwait";
|
|||||||
export function useProtagonist() {
|
export function useProtagonist() {
|
||||||
const id = Tankopedia.use((state) => state.protagonist.tank);
|
const id = Tankopedia.use((state) => state.protagonist.tank);
|
||||||
const tank = useAwait(() => api.tank(id), `tank-${id}`);
|
const tank = useAwait(() => api.tank(id), `tank-${id}`);
|
||||||
|
|
||||||
return tank;
|
return tank;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { Tankopedia } from "../stores/tankopedia";
|
||||||
|
import { useProtagonistTurret } from "./useProtagonistTurret";
|
||||||
|
|
||||||
|
export function useProtagonistGun() {
|
||||||
|
const id = Tankopedia.use((state) => state.protagonist.gun);
|
||||||
|
const turret = useProtagonistTurret();
|
||||||
|
return turret.guns[id];
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { Tankopedia } from "../stores/tankopedia";
|
||||||
|
import { useProtagonist } from "./useProtagonist";
|
||||||
|
|
||||||
|
export function useProtagonistTurret() {
|
||||||
|
const id = Tankopedia.use((state) => state.protagonist.gun);
|
||||||
|
const tank = useProtagonist();
|
||||||
|
return tank.turrets[id];
|
||||||
|
}
|
||||||
Reference in new issue
Block a user