Mercurial > public > geoquiz
comparison GeoQuiz/Components/RecentGameHelper.swift @ 19:f140bb277c96
refactor code
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sun, 23 Oct 2022 00:11:38 +0100 |
parents | 8dac58bb4569 |
children |
comparison
equal
deleted
inserted
replaced
18:d20cf93c9812 | 19:f140bb277c96 |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct RecentGame: View { | 10 struct RecentGame: View { |
11 let game: PlayedGame | 11 let game: PlayedGame |
12 let name: String | 12 let gameInfo: GameInfo |
13 let gradient: Gradient | 13 |
14 let symbol: String | 14 init(game: PlayedGame) { |
15 self.game = game | |
16 self.gameInfo = GameInfoController.getInfo(for: game.type) | |
17 } | |
15 | 18 |
16 var body: some View { | 19 var body: some View { |
17 HStack(alignment: .center, spacing: 15) { | 20 HStack(alignment: .center, spacing: 15) { |
18 RoundedRectangle(cornerRadius: 5) | 21 RoundedRectangle(cornerRadius: 5) |
19 .fill( | 22 .fill( |
20 LinearGradient( | 23 LinearGradient( |
21 gradient: gradient, | 24 gradient: gameInfo.gradient, |
22 startPoint: .top, endPoint: .bottom | 25 startPoint: .top, endPoint: .bottom |
23 ) | 26 ) |
24 ) | 27 ) |
25 .frame(width: 35, height: 35) | 28 .frame(width: 35, height: 35) |
26 .overlay( | 29 .overlay( |
27 Image(systemName: symbol) | 30 Image(systemName: gameInfo.symbol) |
28 .font(.headline) | 31 .font(.headline) |
29 .foregroundColor(.white) | 32 .foregroundColor(.white) |
30 .padding(5) | 33 .padding(5) |
31 ) | 34 ) |
32 | 35 |
33 VStack(alignment: .leading) { | 36 VStack(alignment: .leading) { |
34 Text(name) | 37 Text(gameInfo.name) |
35 .font(.headline) | 38 .font(.headline) |
36 | 39 |
37 Text("\(game.date, format: .dateTime)") | 40 Text("\(game.date, format: .dateTime)") |
38 .font(.callout) | 41 .font(.callout) |
39 .foregroundColor(.secondary) | 42 .foregroundColor(.secondary) |
43 | 46 |
44 Text("\(game.score, format: .number) ⭐️") | 47 Text("\(game.score, format: .number) ⭐️") |
45 .font(.headline) | 48 .font(.headline) |
46 | 49 |
47 } | 50 } |
48 } | 51 .padding() |
49 | 52 .background(Color(.secondarySystemGroupedBackground)) |
50 init(game: PlayedGame) { | 53 .cornerRadius(20) |
51 self.game = game | |
52 | |
53 switch game.type { | |
54 case .guessTheFlag: | |
55 self.name = GuessTheFlagInfo.name | |
56 self.gradient = GuessTheFlagInfo.gradient | |
57 self.symbol = GuessTheFlagInfo.symbol | |
58 case .guessTheCapital: | |
59 self.name = GuessTheCapitalInfo.name | |
60 self.gradient = GuessTheCapitalInfo.gradient | |
61 self.symbol = GuessTheCapitalInfo.symbol | |
62 case .guessTheCountry: | |
63 self.name = GuessTheCountryInfo.name | |
64 self.gradient = GuessTheCountryInfo.gradient | |
65 self.symbol = GuessTheCountryInfo.symbol | |
66 case .guessThePopulation: | |
67 self.name = GuessThePopulationInfo.name | |
68 self.gradient = GuessThePopulationInfo.gradient | |
69 self.symbol = GuessThePopulationInfo.symbol | |
70 } | |
71 } | 54 } |
72 } | 55 } |