Skip to content

Commit

Permalink
Can display round detail
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBernard03 committed Jul 22, 2024
1 parent 096afea commit 70ee281
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 39 deletions.
16 changes: 16 additions & 0 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
8127D2472C4EBB6D00ECBBFD /* PlayersViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8127D2462C4EBB6D00ECBBFD /* PlayersViewModel.swift */; };
8127D2492C4EE37B00ECBBFD /* HistoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8127D2482C4EE37B00ECBBFD /* HistoryViewModel.swift */; };
8127D24B2C4EEE3100ECBBFD /* HistoryGameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8127D24A2C4EEE3100ECBBFD /* HistoryGameView.swift */; };
8127D24E2C4EEEA900ECBBFD /* GameResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8127D24D2C4EEEA900ECBBFD /* GameResultView.swift */; };
814D210A2C4C0E3E00A5521D /* OudlerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814D21092C4C0E3E00A5521D /* OudlerView.swift */; };
814D210C2C4D6B2C00A5521D /* RoundListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814D210B2C4D6B2C00A5521D /* RoundListItemView.swift */; };
815A0DB72C46430800F6328F /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 815A0DB62C46430800F6328F /* SettingsView.swift */; };
Expand All @@ -38,6 +40,8 @@
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8127D2462C4EBB6D00ECBBFD /* PlayersViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayersViewModel.swift; sourceTree = "<group>"; };
8127D2482C4EE37B00ECBBFD /* HistoryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryViewModel.swift; sourceTree = "<group>"; };
8127D24A2C4EEE3100ECBBFD /* HistoryGameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryGameView.swift; sourceTree = "<group>"; };
8127D24D2C4EEEA900ECBBFD /* GameResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameResultView.swift; sourceTree = "<group>"; };
814D21092C4C0E3E00A5521D /* OudlerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OudlerView.swift; sourceTree = "<group>"; };
814D210B2C4D6B2C00A5521D /* RoundListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundListItemView.swift; sourceTree = "<group>"; };
815A0DB62C46430800F6328F /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -102,6 +106,7 @@
7555FF7D242A565900829871 /* iosApp */ = {
isa = PBXGroup;
children = (
8127D24C2C4EEE9900ECBBFD /* Components */,
818520622C4665B1001BAB49 /* Game */,
815A0DB52C4642EB00F6328F /* History */,
815A0DB42C4642E300F6328F /* Settings */,
Expand All @@ -116,6 +121,14 @@
path = iosApp;
sourceTree = "<group>";
};
8127D24C2C4EEE9900ECBBFD /* Components */ = {
isa = PBXGroup;
children = (
8127D24D2C4EEEA900ECBBFD /* GameResultView.swift */,
);
path = Components;
sourceTree = "<group>";
};
815A0DB42C4642E300F6328F /* Settings */ = {
isa = PBXGroup;
children = (
Expand All @@ -129,6 +142,7 @@
children = (
815A0DB82C46431400F6328F /* HistoryView.swift */,
8127D2482C4EE37B00ECBBFD /* HistoryViewModel.swift */,
8127D24A2C4EEE3100ECBBFD /* HistoryGameView.swift */,
);
path = History;
sourceTree = "<group>";
Expand Down Expand Up @@ -299,6 +313,7 @@
buildActionMask = 2147483647;
files = (
814D210A2C4C0E3E00A5521D /* OudlerView.swift in Sources */,
8127D24E2C4EEEA900ECBBFD /* GameResultView.swift in Sources */,
815A0DB92C46431400F6328F /* HistoryView.swift in Sources */,
81EB95582C45B5130039A5A7 /* PlayerColorExtensions.swift in Sources */,
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
Expand All @@ -310,6 +325,7 @@
81C625722C47D48600CCDD39 /* NewGameSheet.swift in Sources */,
818520652C4665CB001BAB49 /* GameView.swift in Sources */,
816F4FB62C4B938B004FC79B /* NewRoundSheet.swift in Sources */,
8127D24B2C4EEE3100ECBBFD /* HistoryGameView.swift in Sources */,
8127D2472C4EBB6D00ECBBFD /* PlayersViewModel.swift in Sources */,
81EB95542C45B3B60039A5A7 /* PlayerView.swift in Sources */,
81B591C92C49A5BE000CB7F9 /* BidExtensions.swift in Sources */,
Expand Down
55 changes: 55 additions & 0 deletions iosApp/iosApp/Components/GameResultView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// GameResultView.swift
// iosApp
//
// Created by Thomas Bernard on 22/07/2024.
// Copyright © 2024 orgName. All rights reserved.
//

import SwiftUI
import Shared

struct GameResultView: View {

let scores : [KotlinPair<PlayerModel, KotlinInt>]

var body: some View {
List {
ForEach(scores.sorted { Int(truncating: $0.second!) > Int(truncating: $1.second!) }, id: \.first!.id) { playerScore in

let index = scores.sorted { Int(truncating: $0.second!) > Int(truncating: $1.second!) }.firstIndex { $0.first!.id == playerScore.first!.id }!

HStack {
ZStack {
Circle()
.foregroundColor(playerScore.first!.color.toColor())
.frame(width: 25, height: 25)
Text("" + playerScore.first!.name.uppercased().prefix(1))
.foregroundColor(.white)
.font(.system(size: 12))
}

Text(playerScore.first!.name)

Spacer()

if index == 0 {
Image(systemName: "medal.fill")
.foregroundColor(.yellow)
} else if index == 1 {
Image(systemName: "medal.fill")
.foregroundColor(.gray)
} else if index == 2 {
Image(systemName: "medal.fill")
.foregroundColor(.brown)
}


Text(String(Int(truncating: playerScore.second!)))
.foregroundColor(Int(truncating: playerScore.second!) >= 0 ? Color.green : Color.red)
.frame(width:50)
}
}
}
}
}
38 changes: 1 addition & 37 deletions iosApp/iosApp/Game/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,7 @@ struct GameView: View {
} else {
Form {
Section("Résultats"){
List {
ForEach(currentGame!.calculateScore().sorted { Int(truncating: $0.second!) > Int(truncating: $1.second!) }, id: \.first!.id) { playerScore in

let index = currentGame!.calculateScore().sorted { Int(truncating: $0.second!) > Int(truncating: $1.second!) }.firstIndex { $0.first!.id == playerScore.first!.id }!

HStack {
ZStack {
Circle()
.foregroundColor(playerScore.first!.color.toColor())
.frame(width: 25, height: 25)
Text("" + playerScore.first!.name.uppercased().prefix(1))
.foregroundColor(.white)
.font(.system(size: 12))
}

Text(playerScore.first!.name)

Spacer()

if index == 0 {
Image(systemName: "medal.fill")
.foregroundColor(.yellow)
} else if index == 1 {
Image(systemName: "medal.fill")
.foregroundColor(.gray)
} else if index == 2 {
Image(systemName: "medal.fill")
.foregroundColor(.brown)
}


Text(String(Int(truncating: playerScore.second!)))
.foregroundColor(Int(truncating: playerScore.second!) >= 0 ? Color.green : Color.red)
.frame(width:50)
}
}
}
GameResultView(scores: currentGame!.calculateScore())
}

Section("Tours"){
Expand Down
37 changes: 37 additions & 0 deletions iosApp/iosApp/History/HistoryGameView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// HistoryGameView.swift
// iosApp
//
// Created by Thomas Bernard on 22/07/2024.
// Copyright © 2024 orgName. All rights reserved.
//

import SwiftUI
import Shared

struct HistoryGameView: View {

let game : GameModel

var body: some View {
Form {
Section("Résultats"){
GameResultView(scores: game.calculateScore())
}
Section("Tours"){
List(game.rounds, id: \.id){ round in
RoundListItemView(round: round)
}
}
}
.navigationTitle("Partie du ")
.toolbar {
Button(action : {}) {
Label("Reprendre", systemImage: "play.circle")
}
Button(action : {}) {
Label("Supprimer", systemImage: "trash")
}
}
}
}
4 changes: 2 additions & 2 deletions iosApp/iosApp/History/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ struct HistoryView: View {
@State private var viewModel = ViewModel()

var body: some View {
NavigationView {
NavigationStack {
VStack(alignment:.center) {
if viewModel.games.isEmpty {
Text("Aucune partie réalisée")
}
else {
List {
ForEach(viewModel.games, id: \.id){ game in
NavigationLink(destination: { EmptyView() }) {
NavigationLink(destination: { HistoryGameView(game: game) }) {
HStack(spacing: 2) {
ForEach(game.players, id : \.id){ player in
ZStack {
Expand Down

0 comments on commit 70ee281

Please sign in to comment.