mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
simplify compatibility logic
This commit is contained in:
1 parent
2627aba938
commit
17264c1adc
2 files changed
+39
-55
No files matched your search
@@ -55,12 +55,11 @@ function Consumables() {
|
|||||||
const consumables = useConsumables();
|
const consumables = useConsumables();
|
||||||
const tierPrices = useTierPrices();
|
const tierPrices = useTierPrices();
|
||||||
const tank = useProtagonist();
|
const tank = useProtagonist();
|
||||||
const isCompatible = useCompatibility();
|
const isCompatible = useCompatibility(tank);
|
||||||
|
|
||||||
return Object.values(consumables.consumables).map(
|
return Object.values(consumables.consumables).map(
|
||||||
({ compatibility, consumable }) => {
|
({ compatibility, consumable }) => {
|
||||||
if (!isCompatible(compatibility!, tank)) return null;
|
if (!isCompatible(compatibility!)) return null;
|
||||||
|
|
||||||
return <span>{consumable!.name_key}</span>;
|
return <span>{consumable!.name_key}</span>;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,75 +6,60 @@ 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";
|
||||||
|
|
||||||
export function useCompatibility(
|
export function useCompatibility(tank: Tank) {
|
||||||
compatibility: CompatibilityComponent,
|
|
||||||
tank: Tank,
|
|
||||||
) {
|
|
||||||
const sets = useSets();
|
const sets = useSets();
|
||||||
|
|
||||||
return function (
|
return function (compatibility: CompatibilityComponent) {
|
||||||
{
|
|
||||||
tank_compatibility,
|
|
||||||
tank_set_compatibility,
|
|
||||||
game_type_compatibility,
|
|
||||||
quest_compatibility,
|
|
||||||
quest_slots_compatibility,
|
|
||||||
tank_style_compatibility,
|
|
||||||
}: CompatibilityComponent,
|
|
||||||
tank: Tank,
|
|
||||||
) {
|
|
||||||
if (
|
if (
|
||||||
tank_set_compatibility ||
|
compatibility.tank_set_compatibility ||
|
||||||
game_type_compatibility ||
|
compatibility.game_type_compatibility ||
|
||||||
quest_compatibility ||
|
compatibility.quest_compatibility ||
|
||||||
quest_slots_compatibility ||
|
compatibility.quest_slots_compatibility ||
|
||||||
tank_style_compatibility
|
compatibility.tank_style_compatibility
|
||||||
) {
|
) {
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
return (
|
||||||
tank_compatibility !== undefined &&
|
compatibility.tank_compatibility === undefined ||
|
||||||
(!tankCompatibilityApplies(tank_compatibility.include!, tank, sets) ||
|
(tankCompatibilityApplies(
|
||||||
tankCompatibilityApplies(tank_compatibility.exclude!, tank, sets))
|
compatibility.tank_compatibility.include,
|
||||||
) {
|
tank,
|
||||||
return false;
|
sets,
|
||||||
}
|
) &&
|
||||||
|
!tankCompatibilityApplies(
|
||||||
return true;
|
compatibility.tank_compatibility.exclude,
|
||||||
|
tank,
|
||||||
|
sets,
|
||||||
|
))
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function tankCompatibilityApplies(
|
function tankCompatibilityApplies(
|
||||||
{
|
include: TankCompatibility_Include | undefined,
|
||||||
nations,
|
|
||||||
tiers,
|
|
||||||
tier_catalog_ids,
|
|
||||||
classes,
|
|
||||||
catalogs_id,
|
|
||||||
tank_traits,
|
|
||||||
types,
|
|
||||||
tank_sets_catalog_ids,
|
|
||||||
is_special,
|
|
||||||
tech_tags,
|
|
||||||
...rest
|
|
||||||
}: TankCompatibility_Include,
|
|
||||||
tank: Tank,
|
tank: Tank,
|
||||||
sets: Sets,
|
sets: Sets,
|
||||||
) {
|
) {
|
||||||
if (is_special) {
|
if (include === undefined) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (include.is_special) {
|
||||||
throw new Error("is_special Not implemented");
|
throw new Error("is_special Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
nations.some((nation) => nation === tank.tank!.nation) ||
|
include.nations.some((nation) => nation === tank.tank!.nation) ||
|
||||||
tiers.some((tier) => tier === tank.tank!.tier) ||
|
include.tiers.some((tier) => tier === tank.tank!.tier) ||
|
||||||
tier_catalog_ids.some((tier) => tier === tank.tank!.tier_catalog_id) ||
|
include.tier_catalog_ids.some(
|
||||||
classes.some((_class) => _class === tank.tank!.tank_class) ||
|
(tier) => tier === tank.tank!.tier_catalog_id,
|
||||||
catalogs_id.some((id) => id === tank.id) ||
|
) ||
|
||||||
tank_traits.some((trait) => tankHasTraits(trait, tank)) ||
|
include.classes.some((_class) => _class === tank.tank!.tank_class) ||
|
||||||
types.some((type) => type === tank.tank!.tank_type) ||
|
include.catalogs_id.some((id) => id === tank.id) ||
|
||||||
tank_sets_catalog_ids.some((id) =>
|
include.tank_traits.some((trait) => tankHasTraits(trait, tank)) ||
|
||||||
|
include.types.some((type) => type === tank.tank!.tank_type) ||
|
||||||
|
include.tank_sets_catalog_ids.some((id) =>
|
||||||
Object.entries(sets.sets).some(
|
Object.entries(sets.sets).some(
|
||||||
([setId, set]) =>
|
([setId, set]) =>
|
||||||
setId === id &&
|
setId === id &&
|
||||||
@@ -85,7 +70,7 @@ function tankCompatibilityApplies(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
) ||
|
) ||
|
||||||
tech_tags.some((tag) => tank.tank!.tech_tags.includes(tag))
|
include.tech_tags.some((tag) => tank.tank!.tech_tags.includes(tag))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user