/** Typed content of tuning/trophies.jsonc. */ import { TuningError, type TuningReader } from '../tuning/tuning-reader.ts'; /** How the weight of a prize group is given: each prize's own, or the group's, split evenly. */ export type GroupWeight = { readonly each: number } | { readonly total: number }; export type TrophyPrizeSpec = | { readonly kind: 'silverLions'; readonly amount: number; readonly weight: number } | { readonly kind: 'goldenEagles'; readonly amount: number; readonly weight: number } | { readonly kind: 'item'; readonly item: string; readonly count: number; readonly weight: number } | { readonly kind: 'itemsOfType'; readonly itemType: string; readonly pick: number; readonly count: number; readonly weight: GroupWeight } | { readonly kind: 'eventVehicles'; readonly minRank: number; readonly maxRank: number; readonly pick: number; readonly weight: GroupWeight }; export interface SupplyTrophySpec { readonly id: string; readonly iconStyle: string; readonly silverLions: number; readonly goldenEagles: number; readonly prizes: readonly TrophyPrizeSpec[]; } export interface TrophyTuning { readonly supplyTrophies: readonly SupplyTrophySpec[]; readonly directVehicleGoldenEagles: number; } export function readTrophyTuning(file: TuningReader): TrophyTuning { return { supplyTrophies: file.list('supplyTrophies', (entry) => ({ id: entry.string('id'), iconStyle: entry.string('iconStyle'), silverLions: entry.int('silverLions', { min: 0 }), goldenEagles: entry.int('goldenEagles', { min: 0 }), prizes: entry.list('prizes', readPrize), })), directVehicleGoldenEagles: file.object('directVehicles').int('goldenEagles', { min: 1 }), }; } function readPrize(entry: TuningReader): TrophyPrizeSpec { const weight = () => entry.number('weight', { min: 0 }); if (entry.has('silverLions')) return { kind: 'silverLions', amount: entry.int('silverLions', { min: 1 }), weight: weight() }; if (entry.has('goldenEagles')) return { kind: 'goldenEagles', amount: entry.int('goldenEagles', { min: 1 }), weight: weight() }; if (entry.has('item')) return { kind: 'item', item: entry.string('item'), count: entry.int('count', { min: 1 }), weight: weight() }; if (entry.has('itemsOfType')) { return { kind: 'itemsOfType', itemType: entry.string('itemsOfType'), pick: entry.int('pick', { min: 1 }), count: entry.int('count', { min: 1 }), weight: groupWeight(entry) }; } if (entry.has('eventVehicles')) { const vehicles = entry.object('eventVehicles'); return { kind: 'eventVehicles', minRank: vehicles.int('minRank', { min: 1 }), maxRank: vehicles.int('maxRank', { min: 1 }), pick: vehicles.int('pick', { min: 1 }), weight: groupWeight(entry), }; } throw new TuningError(`tuning file trophies.jsonc: a prize needs one of silverLions, goldenEagles, item, itemsOfType, eventVehicles (found ${JSON.stringify(entry.keys())})`); } function groupWeight(entry: TuningReader): GroupWeight { if (entry.has('weightEach')) return { each: entry.number('weightEach', { min: 0 }) }; if (entry.has('weightTotal')) return { total: entry.number('weightTotal', { min: 0 }) }; throw new TuningError(`tuning file trophies.jsonc: a prize group needs weightEach or weightTotal (found ${JSON.stringify(entry.keys())})`); }