diff --git a/packages/closed b/packages/closed index 58840ed37..2d6977bb4 160000 --- a/packages/closed +++ b/packages/closed @@ -1 +1 @@ -Subproject commit 58840ed37f5df93398171e96ddeb304111b43c84 +Subproject commit 2d6977bb4875026a9bb1d314b522d72bf3ef9a3d diff --git a/packages/website-ue/src/api/abstract.ts b/packages/website-ue/src/api/abstract.ts index e8ba5925b..c9cc3516b 100644 --- a/packages/website-ue/src/api/abstract.ts +++ b/packages/website-ue/src/api/abstract.ts @@ -6,12 +6,14 @@ import type { AvatarList } from "@protos/avatar_list"; import type { Avatars } from "@protos/avatars"; import type { Background } from "@protos/background"; import type { Backgrounds } from "@protos/backgrounds"; +import type { Consumables } from "@protos/consumables"; import type { Equipment } from "@protos/equipment"; import type { PopularTanks } from "@protos/popular_tanks"; import type { Tank } from "@protos/tank"; import type { TankList } from "@protos/tank_list"; import type { TankUpgradePresets } from "@protos/tank_upgrade_presets"; import type { Tanks } from "@protos/tanks"; +import type { TierPrices } from "@protos/tier_prices"; import type { Tiers } from "@protos/tiers"; export abstract class AbstractAPI { @@ -27,6 +29,8 @@ export abstract class AbstractAPI { abstract tiers(): Promise; abstract equipment(): Promise; + abstract consumables(): Promise; + abstract tierPrices(): Promise; abstract strings(locale: string): Promise; abstract gameStrings(locale: string): Promise>; diff --git a/packages/website-ue/src/api/client.ts b/packages/website-ue/src/api/client.ts index 6cd4ddcea..f6bd2f492 100644 --- a/packages/website-ue/src/api/client.ts +++ b/packages/website-ue/src/api/client.ts @@ -1,11 +1,13 @@ import { fetchPB } from "@blitzkit/core"; import type { Strings } from "@blitzkit/i18n"; import { Avatars } from "@protos/avatars"; +import { Consumables } from "@protos/consumables"; import { Equipment } from "@protos/equipment"; import { PopularTanks } from "@protos/popular_tanks"; import { TankList } from "@protos/tank_list"; import { TankUpgradePresets } from "@protos/tank_upgrade_presets"; import { Tanks } from "@protos/tanks"; +import { TierPrices } from "@protos/tier_prices"; import { Tiers } from "@protos/tiers"; import { AbstractAPI, Cache } from "./abstract"; @@ -59,6 +61,16 @@ export class ClientAPI extends AbstractAPI { return fetchPB("/api/equipment.pb", Equipment); } + @Cache() + consumables() { + return fetchPB("/api/consumables.pb", Consumables); + } + + @Cache() + tierPrices() { + return fetchPB("/api/tier-prices.pb", TierPrices); + } + @Cache() async strings(locale: string) { const response = await fetch(`/api/strings/${locale}.json`); diff --git a/packages/website-ue/src/api/server.ts b/packages/website-ue/src/api/server.ts index 64e14bcdb..ad6427f9b 100644 --- a/packages/website-ue/src/api/server.ts +++ b/packages/website-ue/src/api/server.ts @@ -5,12 +5,14 @@ import locales from "@blitzkit/i18n/locales.json"; import type { Avatar, DeepPartial } from "@protos/avatar"; import type { Background } from "@protos/background"; import type { RemoteStorageComponent } from "@protos/blitz_static_remote_storage_component"; +import { Consumables } from "@protos/consumables"; import { Equipment } from "@protos/equipment"; import type { PopularTanks } from "@protos/popular_tanks"; import type { Tank } from "@protos/tank"; import type { TankListEntry } from "@protos/tank_list"; import { TankUpgradePresets } from "@protos/tank_upgrade_presets"; import type { Tanks } from "@protos/tanks"; +import { TierPrices } from "@protos/tier_prices"; import type { Tiers } from "@protos/tiers"; import { existsSync } from "fs"; import { mkdir, readFile, writeFile } from "fs/promises"; @@ -262,6 +264,36 @@ export class ServerAPI extends AbstractAPI { return equipment; } + @Cache() + async consumables() { + const consumables = Consumables.create(); + + for (const item of this.metadata.group("ConsumableEntity")) { + const purchase = item.BlitzStaticPurchase("purchasable"); + const consumable = item.Consumable(); + const compatibility = item.Compatibility(); + + consumables.consumables[item.id] = { + purchase, + consumable, + compatibility, + }; + } + + return consumables; + } + + @Cache() + async tierPrices() { + const tierPrices = TierPrices.create(); + + for (const item of this.metadata.group("TierPricesEntity")) { + tierPrices.prices[item.id] = item.TierPrices(); + } + + return tierPrices; + } + @Cache(true) async strings(locale: string) { const localized = (await globbedStrings[ diff --git a/packages/website-ue/src/components/TankopediaLoadout/index.tsx b/packages/website-ue/src/components/TankopediaLoadout/index.tsx index b1cc21a1e..737e5f795 100644 --- a/packages/website-ue/src/components/TankopediaLoadout/index.tsx +++ b/packages/website-ue/src/components/TankopediaLoadout/index.tsx @@ -19,11 +19,14 @@ import { maxModulesPerRow, originalLineName, } from "../../config/modules"; +import { useConsumables } from "../../hooks/useConsumables"; import { useEquipment } from "../../hooks/useEquipment"; import { useProtagonist } from "../../hooks/useProtagonist"; import { useStrings } from "../../hooks/useStrings"; +import { useTierPrices } from "../../hooks/useTierPrices"; import { useUpgradePreset } from "../../hooks/useUpgradePreset"; import { Tankopedia } from "../../stores/tankopedia"; +import { isCompatible } from "../../tankopedia/isCompatible"; import { Button } from "../Button"; import { Heading } from "../Heading"; import { Link } from "../Link"; @@ -43,10 +46,24 @@ export function TankopediaLoadout() {
{showModules && } +
); } +function Consumables() { + const consumables = useConsumables(); + const tierPrices = useTierPrices(); + + return Object.values(consumables.consumables).map( + ({ compatibility, consumable }) => { + if (!isCompatible(compatibility!)) return null; + + return {consumable!.name_key}; + }, + ); +} + function Equipment() { const strings = useStrings(); const tank = useProtagonist(); diff --git a/packages/website-ue/src/hooks/useConsumables.ts b/packages/website-ue/src/hooks/useConsumables.ts new file mode 100644 index 000000000..175fe4751 --- /dev/null +++ b/packages/website-ue/src/hooks/useConsumables.ts @@ -0,0 +1,7 @@ +import { api } from "../api/dynamic"; +import { useAwait } from "./useAwait"; + +export function useConsumables() { + const consumables = useAwait(() => api.consumables(), "consumables"); + return consumables; +} diff --git a/packages/website-ue/src/hooks/useTierPrices.ts b/packages/website-ue/src/hooks/useTierPrices.ts new file mode 100644 index 000000000..2cca0c770 --- /dev/null +++ b/packages/website-ue/src/hooks/useTierPrices.ts @@ -0,0 +1,7 @@ +import { api } from "../api/dynamic"; +import { useAwait } from "./useAwait"; + +export function useTierPrices() { + const tierPrices = useAwait(() => api.tierPrices(), "tier-prices"); + return tierPrices; +} diff --git a/packages/website-ue/src/pages/[api]/consumables.pb.ts b/packages/website-ue/src/pages/[api]/consumables.pb.ts new file mode 100644 index 000000000..eba37be3b --- /dev/null +++ b/packages/website-ue/src/pages/[api]/consumables.pb.ts @@ -0,0 +1,9 @@ +import { Consumables } from "@protos/consumables"; +import { api } from "../../api/dynamic"; + +export { getStaticPaths } from "./_index"; + +export async function GET() { + const consumables = await api.consumables(); + return new Response(Consumables.encode(consumables).finish()); +} diff --git a/packages/website-ue/src/pages/[api]/tier-prices.pb.ts b/packages/website-ue/src/pages/[api]/tier-prices.pb.ts new file mode 100644 index 000000000..c9aee636b --- /dev/null +++ b/packages/website-ue/src/pages/[api]/tier-prices.pb.ts @@ -0,0 +1,9 @@ +import { TierPrices } from "@protos/tier_prices"; +import { api } from "../../api/dynamic"; + +export { getStaticPaths } from "./_index"; + +export async function GET() { + const tierPrices = await api.tierPrices(); + return new Response(TierPrices.encode(tierPrices).finish()); +} diff --git a/packages/website-ue/src/tankopedia/isCompatible.ts b/packages/website-ue/src/tankopedia/isCompatible.ts new file mode 100644 index 000000000..707b89249 --- /dev/null +++ b/packages/website-ue/src/tankopedia/isCompatible.ts @@ -0,0 +1,7 @@ +import type { CompatibilityComponent } from "@protos/blitz_static_compatibility_component"; + +export function isCompatible(compatibility: CompatibilityComponent) { + console.log(compatibility); + + return true; +}