comparison GeoQuiz/Components/GameAlertsModifier.swift @ 15:f1967f8cc67b

first iteration of core data
author Dennis C. M. <dennis@denniscm.com>
date Wed, 19 Oct 2022 10:04:17 +0200
parents a793f33f05fb
children
comparison
equal deleted inserted replaced
14:136928bae534 15:f1967f8cc67b
4 // 4 //
5 // Created by Dennis Concepción Martín on 22/9/22. 5 // Created by Dennis Concepción Martín on 22/9/22.
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 import CoreData
9 10
10 struct GameAlertsModifier<T: Game>: ViewModifier { 11 struct GameAlertsModifier<T: Game>: ViewModifier {
11 @ObservedObject var game: T 12 @ObservedObject var game: T
13
14 var gameType: GameType
15 var moc: NSManagedObjectContext
16
12 @Environment(\.dismiss) var dismiss 17 @Environment(\.dismiss) var dismiss
13 18
14 func body(content: Content) -> some View { 19 func body(content: Content) -> some View {
15 content 20 content
16 .alert(game.alertTitle, isPresented: $game.showingWrongAnswerAlert) { 21 .alert(game.alertTitle, isPresented: $game.showingWrongAnswerAlert) {
20 } 25 }
21 } 26 }
22 } message: { 27 } message: {
23 Text(game.alertMessage) 28 Text(game.alertMessage)
24 } 29 }
25
26 .alert(game.alertTitle, isPresented: $game.showingGameOverAlert) {
27 Button("Try again") {
28 game.reset {
29 game.selector()
30 }
31 }
32 Button("Exit", role: .cancel) { dismiss()}
33 } message: {
34 Text(game.alertMessage)
35 }
36 30
37 .alert(game.alertTitle, isPresented: $game.showingEndGameAlert) { 31 .alert(game.alertTitle, isPresented: $game.showingEndGameAlert) {
38 Button("Play again") { 32 Button("Exit", role: .cancel) {
39 game.reset() { 33 game.save(gameType, with: moc)
40 game.selector() 34 dismiss()
41 }
42 } 35 }
43 Button("Exit", role: .cancel) { dismiss() }
44 } message: { 36 } message: {
45 Text(game.alertMessage) 37 Text(game.alertMessage)
46 } 38 }
47 39
48 .alert("Are you sure?", isPresented: $game.showingExitGameAlert) { 40 .alert("Are you sure?", isPresented: $game.showingExitGameAlert) {