krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

DayByDay/Quiz/GameDestination.swift

062549ad26607ce9e973ed2a9a7ef6f853885f83
daybyday/DayByDay/Quiz/GameDestination.swift history · blame · raw

57 lines · 1791 bytes

1 symbol in this file
 1//
 2//  GameDestination.swift
 3//  DayByDay
 4//
 5
 6import SwiftUI
 7
 8/// The screen a hub button opens for one game.
 9struct GameDestination: View {
10    let category: Category
11    let game: Game
12
13    @Environment(ProfileSession.self) private var session
14
15    var body: some View {
16        content.navigationTitle(game.title)
17    }
18
19    /// Weights as of this render: the open round keeps its first question,
20    /// and the next round uses the latest answers.
21    private var source: any QuestionSource {
22        let weights = session.current.map { session.store.reviewWeights(for: $0, category: category) } ?? [:]
23        return category.questionSource(for: game, weights: weights)
24    }
25
26    @ViewBuilder
27    private var content: some View {
28        switch game {
29        case .most:
30            RoundView(source: source, game: game) { PileTile(item: $0) }
31        case .dressUp:
32            RoundView(source: source, game: game) { ClothingTile(item: $0) }
33        case .findIt, .oddOneOut, .listen, .comesNext, .whichSeason, .mixColors:
34            RoundView(source: source, game: game) { ChoiceTile(item: $0) }
35        case .weekTrain:
36            SequencePuzzleView(game: game) {
37                var rng = SystemRandomNumberGenerator()
38                return .weekTrain(using: &rng)
39            }
40        case .yesterdayTomorrow:
41            SequencePuzzleView(game: game) {
42                var rng = SystemRandomNumberGenerator()
43                return .yesterdayTomorrow(today: .current, using: &rng)
44            }
45        case .yearWheel:
46            YearWheelView()
47        case .counting:
48            CountingView()
49        case .trace:
50            TraceView(category: category)
51        case .sortFood:
52            SortView()
53        case .moves:
54            MovesView()
55        }
56    }
57}