diff --git a/CLAUDE.md b/CLAUDE.md index 165528abc..daab51a09 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,6 +31,7 @@ Pages that are not migrated yet are named `_index.astro` so Astro skips them. Mi - No return type annotations. Put `satisfies Type` on the returned expression instead. - Wrap functions defined inside React components in `useCallback`. - Never inline a complex type (a union of object shapes, etc.) in a signature; name it as an interface or type. +- A lookup table that is read by key and checked for missing keys is a `Map`, not an object literal. - Use a string `enum` (`Page = "page"`) instead of a union of string literals (`"page" | "dialog"`) whenever the values can be enumerated. - In object literals, `...spread` entries come first, each on its own line, followed by a blank line, then the custom entries. A single-line object with a spread becomes multi-line. - When an object literal's values are long expressions, compute them first into `const`s named after their keys, then build the object with shorthand (`{ name, color, tanks: [] }`). Short values stay inline. diff --git a/packages/core/src/blitzkit/api/server/6_consumables.ts b/packages/core/src/blitzkit/api/server/6_consumables.ts index 839c18589..1ea15ca5b 100644 --- a/packages/core/src/blitzkit/api/server/6_consumables.ts +++ b/packages/core/src/blitzkit/api/server/6_consumables.ts @@ -1,8 +1,19 @@ import { BlitzTankFilterDefinitionCategory } from "@blitzkit/core"; -import { Consumable, ConsumableDefinitions } from "@blitzkit/protos"; +import { + Consumable, + ConsumableCategory, + ConsumableDefinitions, +} from "@blitzkit/protos"; import { Cache } from "../cache"; import { ServerBlitzKitAPI5 } from "./5_equipments"; +const CATEGORIES = new Map([ + ["free", ConsumableCategory.CONSUMABLE_CATEGORY_FREE], + ["common", ConsumableCategory.CONSUMABLE_CATEGORY_COMMON], + ["potent", ConsumableCategory.CONSUMABLE_CATEGORY_POTENT], + ["radical", ConsumableCategory.CONSUMABLE_CATEGORY_RADICAL], +]); + export abstract class ServerBlitzKitAPI6 extends ServerBlitzKitAPI5 { @Cache() async consumables() { @@ -19,9 +30,21 @@ export abstract class ServerBlitzKitAPI6 extends ServerBlitzKitAPI5 { (includeRaw !== undefined && "minLevel" in includeRaw && includeRaw.minLevel > includeRaw.maxLevel); + const category = + consumable.category === undefined + ? ConsumableCategory.CONSUMABLE_CATEGORY_FREE + : CATEGORIES.get(consumable.category); + + if (category === undefined) { + throw new SyntaxError( + `Unhandled consumable category ${consumable.category}`, + ); + } + const entry: Consumable = { id: consumable.id, game_mode_exclusive, + category, name: this.getString(consumable.userString), exclude: [], include: [], diff --git a/packages/core/src/types/consumablesCommon.ts b/packages/core/src/types/consumablesCommon.ts index 3ead5fc85..e5788500b 100644 --- a/packages/core/src/types/consumablesCommon.ts +++ b/packages/core/src/types/consumablesCommon.ts @@ -7,7 +7,8 @@ export interface ConsumablesCommon { userString: string; description: string; icon: string; - category: string; + // absent on built-in vehicle abilities + category?: string; tags: string; vehicleFilter?: { include: { vehicle: ConsumablesVehicleFilter; nations?: string }; diff --git a/packages/protos/src/blitzkit/consumable_definitions.proto b/packages/protos/src/blitzkit/consumable_definitions.proto index b17f4f39a..8d9ae240d 100644 --- a/packages/protos/src/blitzkit/consumable_definitions.proto +++ b/packages/protos/src/blitzkit/consumable_definitions.proto @@ -14,6 +14,15 @@ message Consumable { bool game_mode_exclusive = 5; repeated TankInclusivityFilter include = 6; repeated TankInclusivityFilter exclude = 7; + ConsumableCategory category = 8; +} + +// ordered by in-game price, cheapest first +enum ConsumableCategory { + CONSUMABLE_CATEGORY_FREE = 0; + CONSUMABLE_CATEGORY_COMMON = 1; + CONSUMABLE_CATEGORY_POTENT = 2; + CONSUMABLE_CATEGORY_RADICAL = 3; } message TankInclusivityFilter { diff --git a/packages/website/src/components/TankSearchFilters/index.tsx b/packages/website/src/components/TankSearchFilters/index.tsx index 796112766..6e38ce7be 100644 --- a/packages/website/src/components/TankSearchFilters/index.tsx +++ b/packages/website/src/components/TankSearchFilters/index.tsx @@ -119,6 +119,7 @@ const consumablesArray = Object.values(consumableDefinitions.consumables) !consumable.game_mode_exclusive && consumable.name!.locales[locales.default], ) + .sort((a, b) => b.category - a.category) .map((consumable) => consumable.id); const provisionsArray = Array.from( Object.values(provisionDefinitions.provisions)