annotate GeoQuiz/GameStatsModalView.swift @ 4:de54f05adb78

add prototype game stats
author Dennis C. M. <dennis@denniscm.com>
date Thu, 22 Sep 2022 11:38:42 +0200
parents
children 1946bbfde4af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
1 //
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
2 // GameStatsModalView.swift
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
3 // GeoQuiz
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
4 //
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
5 // Created by Dennis Concepción Martín on 22/9/22.
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
6 //
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
7
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
8 import SwiftUI
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
9
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
10 struct GameStatsModalView<T: Game>: View {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
11 @ObservedObject var game: T
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
12 @Environment(\.dismiss) var dismiss
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
13
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
14 var body: some View {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
15 NavigationView {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
16 List {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
17 Section {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
18 ForEach(Array(game.correctAnswers.keys), id: \.self) { key in
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
19 Text(key)
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
20 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
21 } header: {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
22 Text("Correct answers")
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
23 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
24
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
25 Section {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
26 ForEach(Array(game.wrongAnswers.keys), id: \.self) { key in
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
27 Text(key)
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
28 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
29 } header: {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
30 Text("Wrong answers")
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
31 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
32 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
33 .navigationTitle("Game stats")
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
34 .toolbar {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
35 ToolbarItem(placement: .cancellationAction) {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
36 Button {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
37 dismiss()
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
38 } label: {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
39 Label("Exit", systemImage: "multiply")
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
40 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
41 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
42 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
43 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
44 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
45 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
46
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
47 struct GameStatsModalView_Previews: PreviewProvider {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
48 static var previews: some View {
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
49 GameStatsModalView(game: GuessTheFlag())
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
50 }
de54f05adb78 add prototype game stats
Dennis C. M. <dennis@denniscm.com>
parents:
diff changeset
51 }