/** Typed content of tuning/supply-chests.jsonc. */ import type { LocalizedText } from '../game-data/datasets/unit-names.ts'; import { TuningError, type TuningReader } from '../tuning/tuning-reader.ts'; export type ChestPrizeSpec = | { readonly kind: 'classicItems'; readonly recyclePart: number; readonly pick: number; readonly weightEach: number } | { readonly kind: 'coupons'; readonly couponKind: 'skin' | 'decal' | 'attachable'; readonly skip: number; readonly pick: number; readonly weightEach: number } | { readonly kind: 'marketVehicles'; readonly minRank: number; readonly maxRank: number; readonly pick: number; readonly weightEach: number }; export interface SupplyChestSpec { readonly id: number; readonly openerId: number; readonly silverLions: number; readonly quality: number; readonly icon: string; readonly title: LocalizedText; readonly description: LocalizedText; readonly prizes: readonly ChestPrizeSpec[]; } export interface SupplyChestTuning { readonly maxPerPurchase: number; readonly chests: readonly SupplyChestSpec[]; } const COUPON_KINDS = ['skin', 'decal', 'attachable'] as const; export function readSupplyChestTuning(file: TuningReader): SupplyChestTuning { return { maxPerPurchase: file.int('maxPerPurchase', { min: 1 }), chests: file.list('chests', (entry) => ({ id: entry.int('id', { min: 1 }), openerId: entry.int('openerId', { min: 1 }), silverLions: entry.int('silverLions', { min: 1 }), quality: entry.int('quality', { min: 1, max: 5 }), icon: entry.string('icon'), title: localized(entry.object('title')), description: localized(entry.object('description')), prizes: entry.list('prizes', readPrize), })), }; } function readPrize(entry: TuningReader): ChestPrizeSpec { const weightEach = entry.number('weightEach', { min: 0 }); if (entry.has('classicItems')) { const group = entry.object('classicItems'); return { kind: 'classicItems', recyclePart: group.int('recyclePart', { min: 1 }), pick: group.int('pick', { min: 1 }), weightEach }; } if (entry.has('coupons')) { const group = entry.object('coupons'); const couponKind = group.string('kind'); if (!(COUPON_KINDS as readonly string[]).includes(couponKind)) throw new TuningError(`tuning file supply-chests.jsonc: coupons.kind must be one of ${COUPON_KINDS.join(', ')} (found "${couponKind}")`); return { kind: 'coupons', couponKind: couponKind as (typeof COUPON_KINDS)[number], skip: group.int('skip', { min: 0 }), pick: group.int('pick', { min: 1 }), weightEach }; } if (entry.has('marketVehicles')) { const group = entry.object('marketVehicles'); return { kind: 'marketVehicles', minRank: group.int('minRank', { min: 1 }), maxRank: group.int('maxRank', { min: 1 }), pick: group.int('pick', { min: 1 }), weightEach }; } throw new TuningError(`tuning file supply-chests.jsonc: a prize needs one of classicItems, coupons, marketVehicles (found ${JSON.stringify(entry.keys())})`); } function localized(entry: TuningReader): LocalizedText { return { zh: entry.string('zh'), en: entry.string('en') }; }