Commit 753b20e234
753b20e2347ec94c9abbdef192d219a76993b3b1
parent: d032beeaa4
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-22 22:10 UTC
Add Qlty config; share card shell and grid across categories
- TapCard holds the rounded card, highlight, tap bounce, and
accessibility every category card repeated; SymbolLabel the
symbol-over-name content five of them shared.
- CardGrid replaces eleven copies of the ScrollView/LazyVGrid screen.
Renders of every card and screen are pixel-identical before and after.
- render-voice-elevenlabs.py: plan and remove_stale split out of main.
- Qlty: switch statements excluded from Swift duplication (enum lookup
tables), return_statements and file_complexity disabled.
Layout: unified · split
.qlty/.gitignore
added
+7
| @@ -0,0 +1,7 @@ |
| 1 | * |
| 2 | !configs |
| 3 | !configs/** |
| 4 | !hooks |
| 5 | !hooks/** |
| 6 | !qlty.toml |
| 7 | !.gitignore |
.qlty/qlty.toml
added
+49
| @@ -0,0 +1,49 @@ |
| 1 | config_version = "0" |
| 2 | |
| 3 | exclude_patterns = [ |
| 4 | "**/vendor/**", |
| 5 | "**/node_modules/**", |
| 6 | "**/testdata/**", |
| 7 | "**/dist/**", |
| 8 | "**/.build/**", |
| 9 | "**/build/**", |
| 10 | "**/*.min.*", |
| 11 | "**/generated/**", |
| 12 | ".claude/**", |
| 13 | "**/Pods/**", |
| 14 | ] |
| 15 | |
| 16 | test_patterns = [ |
| 17 | "**/test/**", |
| 18 | "**/tests/**", |
| 19 | "**/Tests/**", |
| 20 | "**/*_test.*", |
| 21 | "**/test_*.*", |
| 22 | "**/*.test.*", |
| 23 | "**/*Tests.swift", |
| 24 | "e2e/**", |
| 25 | ] |
| 26 | |
| 27 | [[source]] |
| 28 | name = "default" |
| 29 | default = true |
| 30 | |
| 31 | [[plugin]] |
| 32 | name = "osv-scanner" |
| 33 | |
| 34 | [[plugin]] |
| 35 | name = "trufflehog" |
| 36 | |
| 37 | # Early returns are guard clauses, which keep the happy path unindented. |
| 38 | [smells.return_statements] |
| 39 | enabled = false |
| 40 | |
| 41 | # Total file complexity is the sum of its functions, which function_complexity |
| 42 | # already checks. |
| 43 | [smells.file_complexity] |
| 44 | enabled = false |
| 45 | |
| 46 | # Exhaustive switch-over-enum lookup tables (name, symbol, color per case) |
| 47 | # share shape but not content. |
| 48 | [language.swift.smells.duplication] |
| 49 | filter_patterns = ["(import_declaration _)", "(switch_statement _)"] |
AlphabetView.swift
+2 −12
| @@ -8,19 +8,9 @@ import SwiftUI |
| 8 | 8 | /// Displays all 26 letters A–Z as large, tappable cards in a scrollable grid. |
| 9 | 9 | /// Uses a smaller minimum size to fit more letters across the screen. |
| 10 | 10 | struct AlphabetView: View { |
| 11 | | private let columns = [ |
| 12 | | GridItem(.adaptive(minimum: 140, maximum: 300), spacing: 20) |
| 13 | | ] |
| 14 | | |
| 15 | 11 | var body: some View { |
| 16 | | ScrollView { |
| 17 | | LazyVGrid(columns: columns, spacing: 20) { |
| 18 | | ForEach(LearnLetter.allCases) { letter in |
| 19 | | LetterCard(letter: letter) |
| 20 | | .frame(minHeight: 160) |
| 21 | | } |
| 22 | | } |
| 23 | | .padding(32) |
| 12 | CardGrid(items: LearnLetter.allCases, column: GridItem(.adaptive(minimum: 140, maximum: 300), spacing: 20), spacing: 20, minHeight: 160) { letter in |
| 13 | LetterCard(letter: letter) |
| 24 | 14 | } |
| 25 | 15 | .onDisappear { CardVoice.shared.cancel() } |
| 26 | 16 | } |
AnimalCard.swift
+3 −20
| @@ -9,14 +9,11 @@ import SwiftUI |
| 9 | 9 | /// Tapping the card plays a bounce animation and speaks the animal name aloud. |
| 10 | 10 | struct AnimalCard: View { |
| 11 | 11 | let animal: LearnAnimal |
| 12 | | @State private var isTapped = false |
| 13 | 12 | |
| 14 | 13 | var body: some View { |
| 15 | | ZStack { |
| 16 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 17 | | .fill(animal.color) |
| 18 | | .shadow(color: animal.color.opacity(0.4), radius: 8, y: 4) |
| 19 | | |
| 14 | TapCard(color: animal.color, label: animal.name) { |
| 15 | CardVoice.shared.say(animal.cardLine, after: animal.sound) |
| 16 | } content: { |
| 20 | 17 | VStack(spacing: 16) { |
| 21 | 18 | AnimalIcon(animal: animal) |
| 22 | 19 | .font(.system(size: 64)) |
| @@ -29,20 +26,6 @@ struct AnimalCard: View { |
| 29 | 26 | } |
| 30 | 27 | .padding(16) |
| 31 | 28 | } |
| 32 | | .scaleEffect(isTapped ? 1.12 : 1.0) |
| 33 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 34 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 35 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 36 | | .onTapGesture { |
| 37 | | isTapped = true |
| 38 | | CardVoice.shared.say(animal.cardLine, after: animal.sound) |
| 39 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 40 | | isTapped = false |
| 41 | | } |
| 42 | | } |
| 43 | | .accessibilityElement(children: .ignore) |
| 44 | | .accessibilityLabel(animal.name) |
| 45 | | .accessibilityAddTraits(.isButton) |
| 46 | 29 | } |
| 47 | 30 | } |
| 48 | 31 | |
AnimalsView.swift
+2 −12
| @@ -8,19 +8,9 @@ import SwiftUI |
| 8 | 8 | /// Displays 12 animals as large, tappable cards in a scrollable grid. |
| 9 | 9 | /// Adapts between 1 and 2 columns depending on available width. |
| 10 | 10 | struct AnimalsView: View { |
| 11 | | private let columns = [ |
| 12 | | GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24) |
| 13 | | ] |
| 14 | | |
| 15 | 11 | var body: some View { |
| 16 | | ScrollView { |
| 17 | | LazyVGrid(columns: columns, spacing: 24) { |
| 18 | | ForEach(LearnAnimal.allCases) { animal in |
| 19 | | AnimalCard(animal: animal) |
| 20 | | .frame(minHeight: 200) |
| 21 | | } |
| 22 | | } |
| 23 | | .padding(32) |
| 12 | CardGrid(items: LearnAnimal.allCases) { animal in |
| 13 | AnimalCard(animal: animal) |
| 24 | 14 | } |
| 25 | 15 | .onDisappear { CardVoice.shared.cancel() } |
| 26 | 16 | } |
BodyPartCard.swift
+3 −30
| @@ -9,40 +9,13 @@ import SwiftUI |
| 9 | 9 | /// Tapping the card plays a bounce animation and speaks the body part name aloud. |
| 10 | 10 | struct BodyPartCard: View { |
| 11 | 11 | let bodyPart: LearnBodyPart |
| 12 | | @State private var isTapped = false |
| 13 | 12 | |
| 14 | 13 | var body: some View { |
| 15 | | ZStack { |
| 16 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 17 | | .fill(bodyPart.color) |
| 18 | | .shadow(color: bodyPart.color.opacity(0.4), radius: 8, y: 4) |
| 19 | | |
| 20 | | VStack(spacing: 16) { |
| 21 | | Image(systemName: bodyPart.symbol) |
| 22 | | .font(.system(size: 64)) |
| 23 | | .foregroundStyle(.white) |
| 24 | | .symbolRenderingMode(.hierarchical) |
| 25 | | |
| 26 | | Text(bodyPart.name) |
| 27 | | .font(.heading(32)) |
| 28 | | .foregroundStyle(.white) |
| 29 | | } |
| 30 | | .padding(16) |
| 31 | | } |
| 32 | | .scaleEffect(isTapped ? 1.12 : 1.0) |
| 33 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 34 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 35 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 36 | | .onTapGesture { |
| 37 | | isTapped = true |
| 14 | TapCard(color: bodyPart.color, label: bodyPart.name) { |
| 38 | 15 | SpeechSynthesizer.shared.speak(bodyPart.name) |
| 39 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 40 | | isTapped = false |
| 41 | | } |
| 16 | } content: { |
| 17 | SymbolLabel(symbol: bodyPart.symbol, name: bodyPart.name) |
| 42 | 18 | } |
| 43 | | .accessibilityElement(children: .ignore) |
| 44 | | .accessibilityLabel(bodyPart.name) |
| 45 | | .accessibilityAddTraits(.isButton) |
| 46 | 19 | } |
| 47 | 20 | } |
| 48 | 21 | |
BodyPartsView.swift
+2 −12
| @@ -7,19 +7,9 @@ import SwiftUI |
| 7 | 7 | |
| 8 | 8 | /// Displays all 12 body parts as large, tappable cards in a scrollable grid. |
| 9 | 9 | struct BodyPartsView: View { |
| 10 | | private let columns = [ |
| 11 | | GridItem(.adaptive(minimum: 280), spacing: 24) |
| 12 | | ] |
| 13 | | |
| 14 | 10 | var body: some View { |
| 15 | | ScrollView { |
| 16 | | LazyVGrid(columns: columns, spacing: 24) { |
| 17 | | ForEach(LearnBodyPart.allCases) { part in |
| 18 | | BodyPartCard(bodyPart: part) |
| 19 | | .frame(minHeight: 200) |
| 20 | | } |
| 21 | | } |
| 22 | | .padding(32) |
| 11 | CardGrid(items: LearnBodyPart.allCases, column: .narrowCards) { part in |
| 12 | BodyPartCard(bodyPart: part) |
| 23 | 13 | } |
| 24 | 14 | } |
| 25 | 15 | } |
ColorCard.swift
+3 −20
| @@ -8,32 +8,15 @@ import SwiftUI |
| 8 | 8 | /// A single large card filled with a color. Tapping speaks the color name aloud. |
| 9 | 9 | struct ColorCard: View { |
| 10 | 10 | let learnColor: LearnColor |
| 11 | | @State private var isTapped = false |
| 12 | 11 | |
| 13 | 12 | var body: some View { |
| 14 | | ZStack { |
| 15 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 16 | | .fill(learnColor.color) |
| 17 | | .shadow(color: learnColor.color.opacity(0.4), radius: 8, y: 4) |
| 18 | | |
| 13 | TapCard(color: learnColor.color, label: learnColor.name) { |
| 14 | SpeechSynthesizer.shared.speak(learnColor.name) |
| 15 | } content: { |
| 19 | 16 | Text(learnColor.name) |
| 20 | 17 | .font(.heading(36)) |
| 21 | 18 | .foregroundStyle(learnColor.labelColor) |
| 22 | 19 | } |
| 23 | | .scaleEffect(isTapped ? 1.12 : 1.0) |
| 24 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 25 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 26 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 27 | | .onTapGesture { |
| 28 | | isTapped = true |
| 29 | | SpeechSynthesizer.shared.speak(learnColor.name) |
| 30 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 31 | | isTapped = false |
| 32 | | } |
| 33 | | } |
| 34 | | .accessibilityElement(children: .ignore) |
| 35 | | .accessibilityLabel(learnColor.name) |
| 36 | | .accessibilityAddTraits(.isButton) |
| 37 | 20 | } |
| 38 | 21 | } |
| 39 | 22 | |
ColorsView.swift
+2 −12
| @@ -8,19 +8,9 @@ import SwiftUI |
| 8 | 8 | /// Displays 10 colors as large, tappable cards in a scrollable grid. |
| 9 | 9 | /// Adapts between 1 and 2 columns depending on available width. |
| 10 | 10 | struct ColorsView: View { |
| 11 | | private let columns = [ |
| 12 | | GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24) |
| 13 | | ] |
| 14 | | |
| 15 | 11 | var body: some View { |
| 16 | | ScrollView { |
| 17 | | LazyVGrid(columns: columns, spacing: 24) { |
| 18 | | ForEach(LearnColor.allCases) { color in |
| 19 | | ColorCard(learnColor: color) |
| 20 | | .frame(minHeight: 200) |
| 21 | | } |
| 22 | | } |
| 23 | | .padding(32) |
| 12 | CardGrid(items: LearnColor.allCases) { color in |
| 13 | ColorCard(learnColor: color) |
| 24 | 14 | } |
| 25 | 15 | } |
| 26 | 16 | } |
DayByDay/CardGrid.swift
added
+46
| @@ -0,0 +1,46 @@ |
| 1 | // |
| 2 | // CardGrid.swift |
| 3 | // DayByDay |
| 4 | // |
| 5 | |
| 6 | import SwiftUI |
| 7 | |
| 8 | /// Large, tappable cards in a scrollable adaptive grid. |
| 9 | struct CardGrid<Item: Identifiable, Card: View, Header: View>: View { |
| 10 | let items: [Item] |
| 11 | var column = GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24) |
| 12 | var spacing: CGFloat = 24 |
| 13 | var minHeight: CGFloat = 200 |
| 14 | @ViewBuilder var header: () -> Header |
| 15 | @ViewBuilder let card: (Item) -> Card |
| 16 | |
| 17 | var body: some View { |
| 18 | ScrollView { |
| 19 | header() |
| 20 | LazyVGrid(columns: [column], spacing: spacing) { |
| 21 | ForEach(items) { item in |
| 22 | card(item) |
| 23 | .frame(minHeight: minHeight) |
| 24 | } |
| 25 | } |
| 26 | .padding(32) |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | extension CardGrid where Header == EmptyView { |
| 32 | init( |
| 33 | items: [Item], |
| 34 | column: GridItem = GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24), |
| 35 | spacing: CGFloat = 24, |
| 36 | minHeight: CGFloat = 200, |
| 37 | @ViewBuilder card: @escaping (Item) -> Card |
| 38 | ) { |
| 39 | self.init(items: items, column: column, spacing: spacing, minHeight: minHeight, header: { EmptyView() }, card: card) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | extension GridItem { |
| 44 | /// Columns for cards with longer names, which need a narrower minimum to fit two across. |
| 45 | static let narrowCards = GridItem(.adaptive(minimum: 280), spacing: 24) |
| 46 | } |
DayByDay/DayCard.swift
+9 −47
| @@ -12,35 +12,17 @@ struct DayCard: View { |
| 12 | 12 | let day: DayOfWeek |
| 13 | 13 | var isHighlighted = false |
| 14 | 14 | var picture: DayPictureKind? = nil |
| 15 | | @State private var isTapped = false |
| 16 | | |
| 17 | | private var cardScale: CGFloat { |
| 18 | | if isTapped { return 1.12 } |
| 19 | | if isHighlighted { return 1.04 } |
| 20 | | return 1.0 |
| 21 | | } |
| 22 | 15 | |
| 23 | 16 | var body: some View { |
| 24 | | ZStack { |
| 25 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 26 | | .fill(day.color) |
| 27 | | .shadow(color: day.color.opacity(0.4), radius: 8, y: 4) |
| 28 | | // Glow on the card only: on the label it would lower the contrast. |
| 29 | | .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12) |
| 30 | | |
| 31 | | VStack(spacing: 16) { |
| 32 | | Image(systemName: day.symbol) |
| 33 | | .font(.system(size: 64)) |
| 34 | | .foregroundStyle(.white) |
| 35 | | .symbolRenderingMode(.hierarchical) |
| 36 | | |
| 37 | | Text(day.name) |
| 38 | | .font(.heading(32)) |
| 39 | | .foregroundStyle(.white) |
| 40 | | } |
| 41 | | .padding(16) |
| 42 | | } |
| 43 | | .overlay(alignment: .topTrailing) { |
| 17 | TapCard( |
| 18 | color: day.color, |
| 19 | label: picture.map { "\(day.name), \($0.name)" } ?? day.name, |
| 20 | isHighlighted: isHighlighted |
| 21 | ) { |
| 22 | CardVoice.shared.say(Lines.dayCard(day, picture: picture), after: nil) |
| 23 | } content: { |
| 24 | SymbolLabel(symbol: day.symbol, name: day.name) |
| 25 | } badge: { |
| 44 | 26 | if let picture { |
| 45 | 27 | Image(systemName: picture.symbol) |
| 46 | 28 | .font(.system(size: 30, weight: .bold)) |
| @@ -51,26 +33,6 @@ struct DayCard: View { |
| 51 | 33 | .accessibilityHidden(true) |
| 52 | 34 | } |
| 53 | 35 | } |
| 54 | | .overlay { |
| 55 | | if isHighlighted { |
| 56 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 57 | | .strokeBorder(.white, lineWidth: 5) |
| 58 | | } |
| 59 | | } |
| 60 | | .scaleEffect(cardScale) |
| 61 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 62 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 63 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 64 | | .onTapGesture { |
| 65 | | isTapped = true |
| 66 | | CardVoice.shared.say(Lines.dayCard(day, picture: picture), after: nil) |
| 67 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 68 | | isTapped = false |
| 69 | | } |
| 70 | | } |
| 71 | | .accessibilityElement(children: .ignore) |
| 72 | | .accessibilityLabel(picture.map { "\(day.name), \($0.name)" } ?? day.name) |
| 73 | | .accessibilityAddTraits(.isButton) |
| 74 | 36 | } |
| 75 | 37 | } |
| 76 | 38 | |
DayByDay/DaysOfWeekView.swift
+2 −12
| @@ -11,19 +11,9 @@ import SwiftUI |
| 11 | 11 | struct DaysOfWeekView: View { |
| 12 | 12 | @Environment(ProfileSession.self) private var session |
| 13 | 13 | |
| 14 | | private let columns = [ |
| 15 | | GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24) |
| 16 | | ] |
| 17 | | |
| 18 | 14 | var body: some View { |
| 19 | | ScrollView { |
| 20 | | LazyVGrid(columns: columns, spacing: 24) { |
| 21 | | ForEach(DayOfWeek.allCases) { day in |
| 22 | | DayCard(day: day, isHighlighted: day == .current, picture: picture(on: day)) |
| 23 | | .frame(minHeight: 200) |
| 24 | | } |
| 25 | | } |
| 26 | | .padding(32) |
| 15 | CardGrid(items: DayOfWeek.allCases) { day in |
| 16 | DayCard(day: day, isHighlighted: day == .current, picture: picture(on: day)) |
| 27 | 17 | } |
| 28 | 18 | .onDisappear { CardVoice.shared.cancel() } |
| 29 | 19 | } |
DayByDay/MonthCard.swift
+3 −44
| @@ -10,54 +10,13 @@ import SwiftUI |
| 10 | 10 | struct MonthCard: View { |
| 11 | 11 | let month: MonthOfYear |
| 12 | 12 | var isHighlighted = false |
| 13 | | @State private var isTapped = false |
| 14 | | |
| 15 | | private var cardScale: CGFloat { |
| 16 | | if isTapped { return 1.12 } |
| 17 | | if isHighlighted { return 1.04 } |
| 18 | | return 1.0 |
| 19 | | } |
| 20 | 13 | |
| 21 | 14 | var body: some View { |
| 22 | | ZStack { |
| 23 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 24 | | .fill(month.color) |
| 25 | | .shadow(color: month.color.opacity(0.4), radius: 8, y: 4) |
| 26 | | // Glow on the card only: on the label it would lower the contrast. |
| 27 | | .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12) |
| 28 | | |
| 29 | | VStack(spacing: 16) { |
| 30 | | Image(systemName: month.symbol) |
| 31 | | .font(.system(size: 64)) |
| 32 | | .foregroundStyle(.white) |
| 33 | | .symbolRenderingMode(.hierarchical) |
| 34 | | |
| 35 | | Text(month.name) |
| 36 | | .font(.heading(32)) |
| 37 | | .foregroundStyle(.white) |
| 38 | | } |
| 39 | | .padding(16) |
| 40 | | } |
| 41 | | .overlay { |
| 42 | | if isHighlighted { |
| 43 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 44 | | .strokeBorder(.white, lineWidth: 5) |
| 45 | | } |
| 46 | | } |
| 47 | | .scaleEffect(cardScale) |
| 48 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 49 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 50 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 51 | | .onTapGesture { |
| 52 | | isTapped = true |
| 15 | TapCard(color: month.color, label: month.name, isHighlighted: isHighlighted) { |
| 53 | 16 | SpeechSynthesizer.shared.speak(month.name) |
| 54 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 55 | | isTapped = false |
| 56 | | } |
| 17 | } content: { |
| 18 | SymbolLabel(symbol: month.symbol, name: month.name) |
| 57 | 19 | } |
| 58 | | .accessibilityElement(children: .ignore) |
| 59 | | .accessibilityLabel(month.name) |
| 60 | | .accessibilityAddTraits(.isButton) |
| 61 | 20 | } |
| 62 | 21 | } |
| 63 | 22 | |
DayByDay/MonthsOfYearView.swift
+2 −12
| @@ -8,19 +8,9 @@ import SwiftUI |
| 8 | 8 | /// Displays all twelve months as large, tappable cards in a scrollable grid. |
| 9 | 9 | /// Adapts between 1 and 2 columns depending on available width. |
| 10 | 10 | struct MonthsOfYearView: View { |
| 11 | | private let columns = [ |
| 12 | | GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24) |
| 13 | | ] |
| 14 | | |
| 15 | 11 | var body: some View { |
| 16 | | ScrollView { |
| 17 | | LazyVGrid(columns: columns, spacing: 24) { |
| 18 | | ForEach(MonthOfYear.allCases) { month in |
| 19 | | MonthCard(month: month, isHighlighted: month == .current) |
| 20 | | .frame(minHeight: 200) |
| 21 | | } |
| 22 | | } |
| 23 | | .padding(32) |
| 12 | CardGrid(items: MonthOfYear.allCases) { month in |
| 13 | MonthCard(month: month, isHighlighted: month == .current) |
| 24 | 14 | } |
| 25 | 15 | } |
| 26 | 16 | } |
DayByDay/SeasonCard.swift
+3 −44
| @@ -10,54 +10,13 @@ import SwiftUI |
| 10 | 10 | struct SeasonCard: View { |
| 11 | 11 | let season: Season |
| 12 | 12 | var isHighlighted = false |
| 13 | | @State private var isTapped = false |
| 14 | | |
| 15 | | private var cardScale: CGFloat { |
| 16 | | if isTapped { return 1.12 } |
| 17 | | if isHighlighted { return 1.04 } |
| 18 | | return 1.0 |
| 19 | | } |
| 20 | 13 | |
| 21 | 14 | var body: some View { |
| 22 | | ZStack { |
| 23 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 24 | | .fill(season.color) |
| 25 | | .shadow(color: season.color.opacity(0.4), radius: 8, y: 4) |
| 26 | | // Glow on the card only: on the label it would lower the contrast. |
| 27 | | .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12) |
| 28 | | |
| 29 | | VStack(spacing: 16) { |
| 30 | | Image(systemName: season.symbol) |
| 31 | | .font(.system(size: 64)) |
| 32 | | .foregroundStyle(.white) |
| 33 | | .symbolRenderingMode(.hierarchical) |
| 34 | | |
| 35 | | Text(season.name) |
| 36 | | .font(.heading(32)) |
| 37 | | .foregroundStyle(.white) |
| 38 | | } |
| 39 | | .padding(16) |
| 40 | | } |
| 41 | | .overlay { |
| 42 | | if isHighlighted { |
| 43 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 44 | | .strokeBorder(.white, lineWidth: 5) |
| 45 | | } |
| 46 | | } |
| 47 | | .scaleEffect(cardScale) |
| 48 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 49 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 50 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 51 | | .onTapGesture { |
| 52 | | isTapped = true |
| 15 | TapCard(color: season.color, label: season.name, isHighlighted: isHighlighted) { |
| 53 | 16 | SpeechSynthesizer.shared.speak(season.name) |
| 54 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 55 | | isTapped = false |
| 56 | | } |
| 17 | } content: { |
| 18 | SymbolLabel(symbol: season.symbol, name: season.name) |
| 57 | 19 | } |
| 58 | | .accessibilityElement(children: .ignore) |
| 59 | | .accessibilityLabel(season.name) |
| 60 | | .accessibilityAddTraits(.isButton) |
| 61 | 20 | } |
| 62 | 21 | } |
| 63 | 22 | |
DayByDay/SeasonsView.swift
+2 −12
| @@ -8,19 +8,9 @@ import SwiftUI |
| 8 | 8 | /// Displays all four seasons as large, tappable cards in a scrollable grid. |
| 9 | 9 | /// Adapts between 1 and 2 columns depending on available width. |
| 10 | 10 | struct SeasonsView: View { |
| 11 | | private let columns = [ |
| 12 | | GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24) |
| 13 | | ] |
| 14 | | |
| 15 | 11 | var body: some View { |
| 16 | | ScrollView { |
| 17 | | LazyVGrid(columns: columns, spacing: 24) { |
| 18 | | ForEach(Season.allCases) { season in |
| 19 | | SeasonCard(season: season, isHighlighted: season == .current) |
| 20 | | .frame(minHeight: 200) |
| 21 | | } |
| 22 | | } |
| 23 | | .padding(32) |
| 12 | CardGrid(items: Season.allCases) { season in |
| 13 | SeasonCard(season: season, isHighlighted: season == .current) |
| 24 | 14 | } |
| 25 | 15 | } |
| 26 | 16 | } |
DayByDay/TapCard.swift
added
+90
| @@ -0,0 +1,90 @@ |
| 1 | // |
| 2 | // TapCard.swift |
| 3 | // DayByDay |
| 4 | // |
| 5 | |
| 6 | import SwiftUI |
| 7 | |
| 8 | /// The rounded, colored card shared by every learning category. |
| 9 | /// Tapping it plays a bounce animation and runs `onTap`, which speaks the card. |
| 10 | /// A highlighted card (today's day, month, or season) is enlarged, glows, and has a white border. |
| 11 | struct TapCard<Content: View, Badge: View>: View { |
| 12 | let color: Color |
| 13 | let label: String |
| 14 | var isHighlighted = false |
| 15 | let onTap: () -> Void |
| 16 | @ViewBuilder let content: () -> Content |
| 17 | @ViewBuilder var badge: () -> Badge |
| 18 | @State private var isTapped = false |
| 19 | |
| 20 | private var cardScale: CGFloat { |
| 21 | if isTapped { return 1.12 } |
| 22 | if isHighlighted { return 1.04 } |
| 23 | return 1.0 |
| 24 | } |
| 25 | |
| 26 | var body: some View { |
| 27 | ZStack { |
| 28 | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 29 | .fill(color) |
| 30 | .shadow(color: color.opacity(0.4), radius: 8, y: 4) |
| 31 | // Glow on the card only: on the label it would lower the contrast. |
| 32 | .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12) |
| 33 | |
| 34 | content() |
| 35 | } |
| 36 | .overlay(alignment: .topTrailing) { badge() } |
| 37 | .overlay { |
| 38 | if isHighlighted { |
| 39 | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 40 | .strokeBorder(.white, lineWidth: 5) |
| 41 | } |
| 42 | } |
| 43 | .scaleEffect(cardScale) |
| 44 | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 45 | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 46 | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 47 | .onTapGesture { |
| 48 | isTapped = true |
| 49 | onTap() |
| 50 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 51 | isTapped = false |
| 52 | } |
| 53 | } |
| 54 | .accessibilityElement(children: .ignore) |
| 55 | .accessibilityLabel(label) |
| 56 | .accessibilityAddTraits(.isButton) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | extension TapCard where Badge == EmptyView { |
| 61 | init( |
| 62 | color: Color, |
| 63 | label: String, |
| 64 | isHighlighted: Bool = false, |
| 65 | onTap: @escaping () -> Void, |
| 66 | @ViewBuilder content: @escaping () -> Content |
| 67 | ) { |
| 68 | self.init(color: color, label: label, isHighlighted: isHighlighted, onTap: onTap, content: content, badge: { EmptyView() }) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /// An SF Symbol above a name, the content of most category cards. |
| 73 | struct SymbolLabel: View { |
| 74 | let symbol: String |
| 75 | let name: String |
| 76 | |
| 77 | var body: some View { |
| 78 | VStack(spacing: 16) { |
| 79 | Image(systemName: symbol) |
| 80 | .font(.system(size: 64)) |
| 81 | .foregroundStyle(.white) |
| 82 | .symbolRenderingMode(.hierarchical) |
| 83 | |
| 84 | Text(name) |
| 85 | .font(.heading(32)) |
| 86 | .foregroundStyle(.white) |
| 87 | } |
| 88 | .padding(16) |
| 89 | } |
| 90 | } |
FoodCard.swift
+3 −21
| @@ -10,14 +10,11 @@ import SwiftUI |
| 10 | 10 | /// Each food displays its emoji at large size for instant recognition. |
| 11 | 11 | struct FoodCard: View { |
| 12 | 12 | let food: LearnFood |
| 13 | | @State private var isTapped = false |
| 14 | 13 | |
| 15 | 14 | var body: some View { |
| 16 | | ZStack { |
| 17 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 18 | | .fill(food.color) |
| 19 | | .shadow(color: food.color.opacity(0.4), radius: 8, y: 4) |
| 20 | | |
| 15 | TapCard(color: food.color, label: food.name) { |
| 16 | SpeechSynthesizer.shared.speak(food.name) |
| 17 | } content: { |
| 21 | 18 | VStack(spacing: 16) { |
| 22 | 19 | Text(food.emoji) |
| 23 | 20 | .font(.system(size: 72)) |
| @@ -28,22 +25,7 @@ struct FoodCard: View { |
| 28 | 25 | } |
| 29 | 26 | .padding(16) |
| 30 | 27 | } |
| 31 | | .scaleEffect(isTapped ? 1.12 : 1.0) |
| 32 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 33 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 34 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 35 | | .onTapGesture { |
| 36 | | isTapped = true |
| 37 | | SpeechSynthesizer.shared.speak(food.name) |
| 38 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 39 | | isTapped = false |
| 40 | | } |
| 41 | | } |
| 42 | | .accessibilityElement(children: .ignore) |
| 43 | | .accessibilityLabel(food.name) |
| 44 | | .accessibilityAddTraits(.isButton) |
| 45 | 28 | } |
| 46 | | |
| 47 | 29 | } |
| 48 | 30 | |
| 49 | 31 | // MARK: - Food model |
FoodView.swift
+2 −12
| @@ -7,19 +7,9 @@ import SwiftUI |
| 7 | 7 | |
| 8 | 8 | /// Displays all 12 fruits and vegetables as large, tappable cards in a scrollable grid. |
| 9 | 9 | struct FoodView: View { |
| 10 | | private let columns = [ |
| 11 | | GridItem(.adaptive(minimum: 280), spacing: 24) |
| 12 | | ] |
| 13 | | |
| 14 | 10 | var body: some View { |
| 15 | | ScrollView { |
| 16 | | LazyVGrid(columns: columns, spacing: 24) { |
| 17 | | ForEach(LearnFood.allCases) { food in |
| 18 | | FoodCard(food: food) |
| 19 | | .frame(minHeight: 200) |
| 20 | | } |
| 21 | | } |
| 22 | | .padding(32) |
| 11 | CardGrid(items: LearnFood.allCases, column: .narrowCards) { food in |
| 12 | FoodCard(food: food) |
| 23 | 13 | } |
| 24 | 14 | } |
| 25 | 15 | } |
LetterCard.swift
+3 −20
| @@ -9,32 +9,15 @@ import SwiftUI |
| 9 | 9 | /// Tapping the card plays a bounce animation and speaks the letter aloud. |
| 10 | 10 | struct LetterCard: View { |
| 11 | 11 | let letter: LearnLetter |
| 12 | | @State private var isTapped = false |
| 13 | 12 | |
| 14 | 13 | var body: some View { |
| 15 | | ZStack { |
| 16 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 17 | | .fill(letter.color) |
| 18 | | .shadow(color: letter.color.opacity(0.4), radius: 8, y: 4) |
| 19 | | |
| 14 | TapCard(color: letter.color, label: letter.spokenName) { |
| 15 | CardVoice.shared.say(letter.cardLine, after: nil) |
| 16 | } content: { |
| 20 | 17 | Text(letter.character) |
| 21 | 18 | .font(.heading(64, weight: .heavy)) |
| 22 | 19 | .foregroundStyle(.white) |
| 23 | 20 | } |
| 24 | | .scaleEffect(isTapped ? 1.12 : 1.0) |
| 25 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 26 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 27 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 28 | | .onTapGesture { |
| 29 | | isTapped = true |
| 30 | | CardVoice.shared.say(letter.cardLine, after: nil) |
| 31 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 32 | | isTapped = false |
| 33 | | } |
| 34 | | } |
| 35 | | .accessibilityElement(children: .ignore) |
| 36 | | .accessibilityLabel(letter.spokenName) |
| 37 | | .accessibilityAddTraits(.isButton) |
| 38 | 21 | } |
| 39 | 22 | } |
| 40 | 23 | |
NumberCard.swift
+3 −34
| @@ -10,22 +10,11 @@ import SwiftUI |
| 10 | 10 | struct NumberCard: View { |
| 11 | 11 | let number: LearnNumber |
| 12 | 12 | var isHighlighted = false |
| 13 | | @State private var isTapped = false |
| 14 | | |
| 15 | | private var cardScale: CGFloat { |
| 16 | | if isTapped { return 1.12 } |
| 17 | | if isHighlighted { return 1.04 } |
| 18 | | return 1.0 |
| 19 | | } |
| 20 | 13 | |
| 21 | 14 | var body: some View { |
| 22 | | ZStack { |
| 23 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 24 | | .fill(number.color) |
| 25 | | .shadow(color: number.color.opacity(0.4), radius: 8, y: 4) |
| 26 | | // Glow on the card only: on the label it would lower the contrast. |
| 27 | | .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12) |
| 28 | | |
| 15 | TapCard(color: number.color, label: number.name, isHighlighted: isHighlighted) { |
| 16 | SpeechSynthesizer.shared.speak(number.name) |
| 17 | } content: { |
| 29 | 18 | VStack(spacing: 10) { |
| 30 | 19 | Text("\(number.numeral)") |
| 31 | 20 | .font(.heading(60, weight: .heavy)) |
| @@ -41,26 +30,6 @@ struct NumberCard: View { |
| 41 | 30 | } |
| 42 | 31 | .padding(16) |
| 43 | 32 | } |
| 44 | | .overlay { |
| 45 | | if isHighlighted { |
| 46 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 47 | | .strokeBorder(.white, lineWidth: 5) |
| 48 | | } |
| 49 | | } |
| 50 | | .scaleEffect(cardScale) |
| 51 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 52 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 53 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 54 | | .onTapGesture { |
| 55 | | isTapped = true |
| 56 | | SpeechSynthesizer.shared.speak(number.name) |
| 57 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 58 | | isTapped = false |
| 59 | | } |
| 60 | | } |
| 61 | | .accessibilityElement(children: .ignore) |
| 62 | | .accessibilityLabel(number.name) |
| 63 | | .accessibilityAddTraits(.isButton) |
| 64 | 33 | } |
| 65 | 34 | } |
| 66 | 35 | |
NumbersView.swift
+2 −15
| @@ -8,22 +8,9 @@ import SwiftUI |
| 8 | 8 | /// Displays numbers 1–10 as large, tappable cards in a scrollable grid. |
| 9 | 9 | /// Adapts between 1 and 2 columns depending on available width. |
| 10 | 10 | struct NumbersView: View { |
| 11 | | private let columns = [ |
| 12 | | GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24) |
| 13 | | ] |
| 14 | | |
| 15 | 11 | var body: some View { |
| 16 | | ScrollView { |
| 17 | | LazyVGrid(columns: columns, spacing: 24) { |
| 18 | | ForEach(LearnNumber.allCases) { number in |
| 19 | | NumberCard( |
| 20 | | number: number, |
| 21 | | isHighlighted: number == .current |
| 22 | | ) |
| 23 | | .frame(minHeight: 200) |
| 24 | | } |
| 25 | | } |
| 26 | | .padding(32) |
| 12 | CardGrid(items: LearnNumber.allCases) { number in |
| 13 | NumberCard(number: number, isHighlighted: number == .current) |
| 27 | 14 | } |
| 28 | 15 | } |
| 29 | 16 | } |
ShapeCard.swift
+3 −20
| @@ -9,14 +9,11 @@ import SwiftUI |
| 9 | 9 | /// Tapping the card plays a bounce animation and speaks the shape name aloud. |
| 10 | 10 | struct ShapeCard: View { |
| 11 | 11 | let shape: LearnShape |
| 12 | | @State private var isTapped = false |
| 13 | 12 | |
| 14 | 13 | var body: some View { |
| 15 | | ZStack { |
| 16 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 17 | | .fill(shape.color) |
| 18 | | .shadow(color: shape.color.opacity(0.4), radius: 8, y: 4) |
| 19 | | |
| 14 | TapCard(color: shape.color, label: shape.name) { |
| 15 | SpeechSynthesizer.shared.speak(shape.name) |
| 16 | } content: { |
| 20 | 17 | VStack(spacing: 16) { |
| 21 | 18 | shape.shapeView |
| 22 | 19 | .frame(width: 80, height: 80) |
| @@ -28,20 +25,6 @@ struct ShapeCard: View { |
| 28 | 25 | } |
| 29 | 26 | .padding(16) |
| 30 | 27 | } |
| 31 | | .scaleEffect(isTapped ? 1.12 : 1.0) |
| 32 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 33 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 34 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 35 | | .onTapGesture { |
| 36 | | isTapped = true |
| 37 | | SpeechSynthesizer.shared.speak(shape.name) |
| 38 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 39 | | isTapped = false |
| 40 | | } |
| 41 | | } |
| 42 | | .accessibilityElement(children: .ignore) |
| 43 | | .accessibilityLabel(shape.name) |
| 44 | | .accessibilityAddTraits(.isButton) |
| 45 | 28 | } |
| 46 | 29 | } |
| 47 | 30 | |
ShapesView.swift
+2 −12
| @@ -8,19 +8,9 @@ import SwiftUI |
| 8 | 8 | /// Displays 8 shapes as large, tappable cards in a scrollable grid. |
| 9 | 9 | /// Adapts between 1 and 2 columns depending on available width. |
| 10 | 10 | struct ShapesView: View { |
| 11 | | private let columns = [ |
| 12 | | GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24) |
| 13 | | ] |
| 14 | | |
| 15 | 11 | var body: some View { |
| 16 | | ScrollView { |
| 17 | | LazyVGrid(columns: columns, spacing: 24) { |
| 18 | | ForEach(LearnShape.allCases) { shape in |
| 19 | | ShapeCard(shape: shape) |
| 20 | | .frame(minHeight: 200) |
| 21 | | } |
| 22 | | } |
| 23 | | .padding(32) |
| 12 | CardGrid(items: LearnShape.allCases) { shape in |
| 13 | ShapeCard(shape: shape) |
| 24 | 14 | } |
| 25 | 15 | } |
| 26 | 16 | } |
WeatherCard.swift
+3 −30
| @@ -9,40 +9,13 @@ import SwiftUI |
| 9 | 9 | /// Tapping the card plays a bounce animation and speaks the weather name aloud. |
| 10 | 10 | struct WeatherCard: View { |
| 11 | 11 | let weather: LearnWeather |
| 12 | | @State private var isTapped = false |
| 13 | 12 | |
| 14 | 13 | var body: some View { |
| 15 | | ZStack { |
| 16 | | RoundedRectangle(cornerRadius: 32, style: .continuous) |
| 17 | | .fill(weather.color) |
| 18 | | .shadow(color: weather.color.opacity(0.4), radius: 8, y: 4) |
| 19 | | |
| 20 | | VStack(spacing: 16) { |
| 21 | | Image(systemName: weather.symbol) |
| 22 | | .font(.system(size: 64)) |
| 23 | | .foregroundStyle(.white) |
| 24 | | .symbolRenderingMode(.hierarchical) |
| 25 | | |
| 26 | | Text(weather.name) |
| 27 | | .font(.heading(32)) |
| 28 | | .foregroundStyle(.white) |
| 29 | | } |
| 30 | | .padding(16) |
| 31 | | } |
| 32 | | .scaleEffect(isTapped ? 1.12 : 1.0) |
| 33 | | .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous)) |
| 34 | | .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0)) |
| 35 | | .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped) |
| 36 | | .onTapGesture { |
| 37 | | isTapped = true |
| 14 | TapCard(color: weather.color, label: weather.name) { |
| 38 | 15 | SpeechSynthesizer.shared.speak(weather.name) |
| 39 | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { |
| 40 | | isTapped = false |
| 41 | | } |
| 16 | } content: { |
| 17 | SymbolLabel(symbol: weather.symbol, name: weather.name) |
| 42 | 18 | } |
| 43 | | .accessibilityElement(children: .ignore) |
| 44 | | .accessibilityLabel(weather.name) |
| 45 | | .accessibilityAddTraits(.isButton) |
| 46 | 19 | } |
| 47 | 20 | } |
| 48 | 21 | |
WeatherView.swift
+3 −13
| @@ -8,16 +8,12 @@ import SwiftUI |
| 8 | 8 | /// Displays all 8 weather types as large, tappable cards in a scrollable grid. |
| 9 | 9 | /// Shaking the device, or tapping the rain button, makes it rain. |
| 10 | 10 | struct WeatherView: View { |
| 11 | | private let columns = [ |
| 12 | | GridItem(.adaptive(minimum: 280), spacing: 24) |
| 13 | | ] |
| 14 | | |
| 15 | 11 | @State private var raining = false |
| 16 | 12 | /// Bumped when the screen goes away, so a pending stop does nothing. |
| 17 | 13 | @State private var generation = 0 |
| 18 | 14 | |
| 19 | 15 | var body: some View { |
| 20 | | ScrollView { |
| 16 | CardGrid(items: LearnWeather.allCases, column: .narrowCards) { |
| 21 | 17 | Button(action: rain) { |
| 22 | 18 | Label("Shake for rain!", systemImage: "cloud.rain.fill") |
| 23 | 19 | .font(.heading(22)) |
| @@ -27,14 +23,8 @@ struct WeatherView: View { |
| 27 | 23 | } |
| 28 | 24 | .buttonStyle(.plain) |
| 29 | 25 | .padding(.top, 16) |
| 30 | | |
| 31 | | LazyVGrid(columns: columns, spacing: 24) { |
| 32 | | ForEach(LearnWeather.allCases) { weather in |
| 33 | | WeatherCard(weather: weather) |
| 34 | | .frame(minHeight: 200) |
| 35 | | } |
| 36 | | } |
| 37 | | .padding(32) |
| 26 | } card: { weather in |
| 27 | WeatherCard(weather: weather) |
| 38 | 28 | } |
| 39 | 29 | .overlay { RainOverlay(isActive: raining) } |
| 40 | 30 | .onShake(rain) |
scripts/render-voice-elevenlabs.py
+21 −12
| @@ -120,6 +120,25 @@ def encode(audio: array.array, out: Path) -> None: |
| 120 | 120 | str(wav), str(out)], check=True) |
| 121 | 121 | |
| 122 | 122 | |
| 123 | def plan(lines: list, old: dict, out: Path, redo: list) -> tuple[list, list]: |
| 124 | """Splits lines into manifest entries to keep and (text, seed) pairs to render.""" |
| 125 | kept, todo = [], [] |
| 126 | for text in lines: |
| 127 | entry = old.get(text) |
| 128 | if entry and text not in redo and entry.get("engine") == MODEL and (out / entry["file"]).exists(): |
| 129 | kept.append(entry) |
| 130 | else: |
| 131 | seed = entry["seed"] + 1 if entry and text in redo else 0 |
| 132 | todo.append((text, seed)) |
| 133 | return kept, todo |
| 134 | |
| 135 | |
| 136 | def remove_stale(out: Path, keep: set) -> None: |
| 137 | for stale in [*out.glob("*.aac"), *out.glob("*.m4a")]: |
| 138 | if stale.name not in keep: |
| 139 | stale.unlink() |
| 140 | |
| 141 | |
| 123 | 142 | def main() -> None: |
| 124 | 143 | parser = argparse.ArgumentParser() |
| 125 | 144 | parser.add_argument("lines", type=Path) |
| @@ -142,14 +161,7 @@ def main() -> None: |
| 142 | 161 | manifest_path = args.out / "voice-manifest.json" |
| 143 | 162 | old = {e["text"]: e for e in json.loads(manifest_path.read_text())} if manifest_path.exists() else {} |
| 144 | 163 | |
| 145 | | kept, todo = [], [] |
| 146 | | for text in lines: |
| 147 | | entry = old.get(text) |
| 148 | | if entry and text not in args.redo and entry.get("engine") == MODEL and (args.out / entry["file"]).exists(): |
| 149 | | kept.append(entry) |
| 150 | | else: |
| 151 | | seed = entry["seed"] + 1 if entry and text in args.redo else 0 |
| 152 | | todo.append((text, seed)) |
| 164 | kept, todo = plan(lines, old, args.out, args.redo) |
| 153 | 165 | |
| 154 | 166 | def job(item): |
| 155 | 167 | text, seed = item |
| @@ -167,10 +179,7 @@ def main() -> None: |
| 167 | 179 | write_manifest(manifest_path, kept + done + [e for t, e in old.items() if t not in fresh and e not in kept]) |
| 168 | 180 | |
| 169 | 181 | entries = kept + done |
| 170 | | keep = {e["file"] for e in entries} |
| 171 | | for stale in [*args.out.glob("*.aac"), *args.out.glob("*.m4a")]: |
| 172 | | if stale.name not in keep: |
| 173 | | stale.unlink() |
| 182 | remove_stale(args.out, {e["file"] for e in entries}) |
| 174 | 183 | write_manifest(manifest_path, entries) |
| 175 | 184 | print(f"{len(done)} rendered, {len(kept)} kept") |
| 176 | 185 | |