import 'stage.dart'; class SeasonTheme { const SeasonTheme({required this.tileSet, required this.background}); factory SeasonTheme.fromJson(Map json) => SeasonTheme( tileSet: json['tileSet'] as String, background: json['background'] as String, ); final String tileSet; final String background; Map toJson() => {'tileSet': tileSet, 'background': background}; } /// A season's full content: metadata, theme, and its stages. The unit of /// remote (or bundled) delivery. class SeasonPack { const SeasonPack({ required this.schemaVersion, required this.seasonId, required this.version, required this.title, required this.theme, required this.stages, }); /// Bump when the pack format changes incompatibly; older app builds skip /// packs with a newer schema instead of crashing. static const int supportedSchema = 1; factory SeasonPack.fromJson(Map json) { final schema = json['schemaVersion'] as int; if (schema > supportedSchema) { throw FormatException('Unsupported pack schema: $schema'); } return SeasonPack( schemaVersion: schema, seasonId: json['seasonId'] as String, version: json['version'] as int, title: (json['title'] as Map) .map((k, v) => MapEntry(k, v as String)), theme: SeasonTheme.fromJson(json['theme'] as Map), stages: [ for (final stage in json['stages'] as List) StageConfig.fromJson(stage as Map), ], ); } final int schemaVersion; final String seasonId; final int version; final Map title; final SeasonTheme theme; final List stages; String titleFor(String languageCode) => title[languageCode] ?? title['en'] ?? seasonId; Map toJson() => { 'schemaVersion': schemaVersion, 'seasonId': seasonId, 'version': version, 'title': title, 'theme': theme.toJson(), 'stages': [for (final stage in stages) stage.toJson()], }; }