DayByDay/Screenshots/ScreenshotScene.swift
104 lines · 4882 bytes
3 symbols in this file
1//
2// ScreenshotScene.swift
3// DayByDay
4//
5
6#if DEBUG
7import SwiftUI
8
9/// App Store screens, opened by `scripts/take-screenshots.sh` with
10/// `-screenshot <name>`. The app then runs on an in-memory store seeded with
11/// one demo child. `setup` (no children) and `picker` (two children, none
12/// picked) are for the UI tests.
13enum ScreenshotScene: String, CaseIterable {
14 case home, routine, animals, train, trace, counting, calendar, progress
15 case setup, picker
16
17 static var requested: ScreenshotScene? {
18 let args = ProcessInfo.processInfo.arguments
19 guard let i = args.firstIndex(of: "-screenshot"), i + 1 < args.count else { return nil }
20 return ScreenshotScene(rawValue: args[i + 1])
21 }
22
23 @ViewBuilder @MainActor
24 func view(_ session: ProfileSession) -> some View {
25 switch self {
26 case .home, .setup, .picker:
27 ContentView()
28 case .routine:
29 NavigationStack { TodayRoutineView().navigationTitle(Category.today.label) }
30 case .animals:
31 NavigationStack { Category.animals.lookAndListenView.navigationTitle(Category.animals.label) }
32 case .train:
33 NavigationStack {
34 SequencePuzzleView(game: .weekTrain) {
35 var rng = SystemRandomNumberGenerator()
36 var train = SequencePuzzle.weekTrain(using: &rng)
37 _ = train.place(Category.days.item(DayOfWeek.sunday))
38 return train
39 }
40 .navigationTitle(Game.weekTrain.title)
41 }
42 case .trace:
43 NavigationStack { GameDestination(category: .alphabet, game: .trace) }
44 case .counting:
45 NavigationStack { GameDestination(category: .numbers, game: .counting) }
46 case .calendar:
47 NavigationStack {
48 ScrollView { StickerCalendarView(profile: session.current).frame(maxWidth: 560).padding() }
49 .navigationTitle("Stickers")
50 }
51 case .progress:
52 NavigationStack {
53 if let profile = session.current { ChildProgressView(profile: profile) }
54 }
55 }
56 }
57
58 /// One child with a birthday this month, a day picture today, stickers on
59 /// earlier days this month, and answers that leave a few months to practice.
60 @MainActor
61 static func seed(_ session: ProfileSession, calendar: Calendar = AppCalendar.current, now: Date = .now) {
62 switch requested {
63 case .setup:
64 return
65 case .picker:
66 _ = try? session.store.create(name: "Olive", avatar: .hare, color: .teal, birthday: nil)
67 _ = try? session.store.create(name: "Max", avatar: .dog, color: .blue, birthday: nil)
68 session.profilesChanged()
69 return
70 default:
71 break
72 }
73 let today = calendar.dateComponents([.year, .month, .day], from: now)
74 guard let olive = try? session.store.create(name: "Olive", avatar: .hare, color: .teal,
75 birthday: (month: today.month!, day: today.day! == 28 ? 27 : 28)) else { return }
76 session.store.setPicture(.swim, on: .current, for: olive)
77 let weathers: [LearnWeather] = [.sunny, .cloudy, .rainy, .sunny, .windy, .snowy, .sunny]
78 for (i, day) in (1..<today.day!).reversed().prefix(10).enumerated() {
79 session.store.addSticker(for: olive, on: DateComponents(year: today.year, month: today.month, day: day),
80 weather: weathers[i % weathers.count])
81 }
82 let days = Category.days.quizItems, months = Category.months.quizItems
83 let t = now.addingTimeInterval(-86_400)
84 for (i, day) in days.enumerated() {
85 session.store.record(day, correct: true, for: olive, at: t + Double(i) * 300)
86 session.store.record(day, correct: true, for: olive, at: t + 5000 + Double(i) * 300)
87 }
88 for (i, month) in months.enumerated() where i < 5 {
89 session.store.record(month, correct: true, for: olive, at: t + Double(i) * 300)
90 session.store.record(month, correct: true, for: olive, at: t + 5000 + Double(i) * 300)
91 }
92 for month in months[5...7] { session.store.record(month, correct: false, for: olive, at: t + 9000) }
93 for category in [Category.numbers, .colors, .shapes, .seasons] {
94 for (i, item) in category.quizItems.enumerated() {
95 session.store.record(item, correct: true, for: olive, at: t + Double(i) * 60)
96 session.store.record(item, correct: true, for: olive, at: t + 5000 + Double(i) * 60)
97 }
98 }
99 session.store.record(Category.shapes.quizItems[0], correct: false, for: olive, at: t + 9000)
100 session.profilesChanged()
101 session.select(olive)
102 }
103}
104#endif