From 0b9c8f1581cbb93a4b45c8c5a3a30fe2a7be868b Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 4 Jun 2024 15:53:44 +0200 Subject: [PATCH 01/19] =?UTF-8?q?=E2=9C=A8=20Add:=20navigation=20for=20sel?= =?UTF-8?q?ectPlayerView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift index 26b6bc3..66a868f 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift @@ -21,7 +21,7 @@ struct SelectPlayerView: View { HStack { VStack(alignment: .trailing) { - MainMenuButton(text: "Start", destination: ContentView(), sound: "TitleScreenButtonSound", horizontalAlignment: .trailing, topLeftCorner: 10, bottomLeftCorner: 10) + MainMenuButton(text: "Start", destination: GameView(), sound: "TitleScreenButtonSound", horizontalAlignment: .trailing, topLeftCorner: 10, bottomLeftCorner: 10) MainMenuButton(text: "Settings", destination: ContentView(), sound: "TitleScreenButtonSound", horizontalAlignment: .trailing, topLeftCorner: 10, bottomLeftCorner: 10) } } From 4e4b92843160396c09e907671b9e2ab89481441f Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 4 Jun 2024 15:54:30 +0200 Subject: [PATCH 02/19] =?UTF-8?q?=E2=9C=A8=20Add:=20navigation=20for=20sel?= =?UTF-8?q?ectPlayer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift index e23095d..1738496 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift @@ -36,7 +36,7 @@ struct MainMenuView: View { VStack { HStack { VStack(spacing: 25) { - MainMenuButton(text: "Play", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "Play", destination: SelectPlayerView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) MainMenuButton(text: "Historique", destination: HistoricView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) From ff2f0be54500ff37c4480c337d0ea6482032c006 Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 4 Jun 2024 15:56:36 +0200 Subject: [PATCH 03/19] =?UTF-8?q?=F0=9F=94=A5=20Remove:=20unused=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift b/DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift index 474c9a5..eff6f22 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift @@ -54,7 +54,6 @@ class GameScene : SKScene { } func initializeBoard(_ board: Board) { - for (lineIndex, currentLine) in game.board.grid.enumerated() { for (cellIndex, currentCell) in currentLine.enumerated() { if let piece = currentCell.piece { From befb5e731dccfed8d910a6452287e93c24e39942 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 09:35:46 +0200 Subject: [PATCH 04/19] :construction: Update: SpriteMeeple move for add vm --- .../Components/Player/ShowAllPlayer.swift | 8 ++++++ .../Components/Scene/GameScene.swift | 28 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift b/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift new file mode 100644 index 0000000..07139f8 --- /dev/null +++ b/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift @@ -0,0 +1,8 @@ +// +// ShowAllPlayer.swift +// DouShouQi_App +// +// Created by etudiant on 14/06/2024. +// + +import Foundation diff --git a/DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift b/DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift index eff6f22..6f955a2 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Scene/GameScene.swift @@ -10,7 +10,11 @@ import SpriteKit import DouShouQiModel class GameScene : SKScene { - var game: Game = try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Rayhan", andId: .player1)!, andPlayer2: RandomPlayer(withName: "Rémi", andId: .player2)!) + + var player1: HumanPlayer = HumanPlayer(withName: "Rémi", andId: .player1)! + var player2: HumanPlayer = HumanPlayer(withName: "Rayhan", andId: .player2)! + + var game: Game let pieces: [Owner : [Animal:SpriteMeeple]] = [ .player1: [ @@ -38,6 +42,7 @@ class GameScene : SKScene { let imageBoard: SKSpriteNode = SKSpriteNode(imageNamed: AppImages.boardGame) override init(size: CGSize) { + game = try! Game(withRules: ClassicRules(), andPlayer1: player1, andPlayer2: player2) super.init(size: size) imageBoard.size = size //self.scaleMode = .aspectFit @@ -48,9 +53,11 @@ class GameScene : SKScene { for piece in pieces.flatMap({owner, pieces in pieces.values}) { self.addChild(piece) + //piece.setOnMove(onMove: onMeepleMove) } initializeBoard(game.board) + } func initializeBoard(_ board: Board) { @@ -66,6 +73,25 @@ class GameScene : SKScene { } required init?(coder aDecoder: NSCoder) { + game = try! Game(withRules: ClassicRules(), andPlayer1: player1, andPlayer2: player2) super.init(coder: aDecoder); } + + func onMeepleMove(_ start: CGPoint, _ end: CGPoint) async { + + let owner = game.rules.getNextPlayer() + let player = game.players[owner] + + let move = Move(of: owner, fromRow: Int(start.x), andFromColumn: Int(start.y), toRow: Int(end.x), andToColumn: Int(end.y)) + + print("Meeple moved") + + try! await (player as! HumanPlayer).chooseMove(move) + + + } + + public func start() async throws { + try await game.start() + } } From 30b3d43e929a0e2bb9eca62b9f9381613022ffa6 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 09:36:08 +0200 Subject: [PATCH 05/19] :construction: Update: SpriteMeeple move for add vm --- .../DouShouQi_App/Components/Scene/SpriteMeeple.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/DouShouQi_App/DouShouQi_App/Components/Scene/SpriteMeeple.swift b/DouShouQi_App/DouShouQi_App/Components/Scene/SpriteMeeple.swift index f9e74c4..0a74775 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Scene/SpriteMeeple.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Scene/SpriteMeeple.swift @@ -19,6 +19,8 @@ class SpriteMeeple : SKNode { var originalSize: CGSize var originalEllipseSize: CGSize + var onMove: ((CGPoint, CGPoint) async -> ())? + var cellPosition: CGPoint{ didSet(cellPosition){ self.position.x = SpriteMeeple.offset.x + SpriteMeeple.direction.dx*cellPosition.x @@ -56,6 +58,8 @@ class SpriteMeeple : SKNode { originalEllipseSize = CGSize(width: 0, height: 0) super.init(coder: aDecoder) } + + public func setOnMove(onMove: @escaping (CGPoint, CGPoint) -> ()) { self.onMove = onMove } override var isUserInteractionEnabled: Bool{ set { } @@ -83,6 +87,10 @@ class SpriteMeeple : SKNode { imageNode.size = originalSize ellipseNode.path = SKShapeNode(ellipseOf: originalEllipseSize).path + + if let onMove: (CGPoint, CGPoint) async -> () = onMove { + //onMove(CGPoint(x: 100, y: 100), CGPoint(x: 200, y: 100)) + } self.zPosition = 0 } From 626f32c60506348b6daefcecaf0741d0d8a9ef59 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 09:36:49 +0200 Subject: [PATCH 06/19] :construction: Update: SelectPlayerView for call ShowAllPlayer sheet --- DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift index 66a868f..7a7e873 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import SpriteKit struct SelectPlayerView: View { var body: some View { From 581d2a5a2d13b89953d43628d600dfda5afa3b16 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 09:39:18 +0200 Subject: [PATCH 07/19] :construction: Update: ShowAllPlayer for list all player --- .../Components/Player/ShowAllPlayer.swift | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift b/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift index 07139f8..566cfb4 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift @@ -2,7 +2,49 @@ // ShowAllPlayer.swift // DouShouQi_App // -// Created by etudiant on 14/06/2024. +// Created by Nathan Verdier on 14/06/2024. // -import Foundation +import SwiftUI +import UIKit + +struct ShowAllPlayer: View { + @Binding var isShowingSheet: Bool + @Binding var players: [Player] + var body: some View { + Button(action: { + self.isShowingSheet = true + }) { + Text("Afficher les joueurs") + } + .sheet(isPresented: $isShowingSheet) { + PlayerSheetView(isShowingSheet: $isShowingSheet, players: $players) + } + } +} + +struct PlayerSheetView: View { + @Environment(\.dismiss) var dismiss + @Binding var isShowingSheet: Bool + @Binding var players: [Player] + + var body: some View { + VStack { + /*List(players, id: \.self) { player in + Text(player.name) // Assumant que Player a une propriété 'name' + }*/ + Button(action: { + self.isShowingSheet = true + }) { + Text("Add Player") + .foregroundColor(.white) + .padding() + .background(Color.red) + .cornerRadius(10) + } + .sheet(isPresented: $isShowingSheet) { + AddPlayerView(isPresented: $isShowingSheet, players: $players) + } + } + } +} From b4a98873a8de61fbd4e1e808346e065062394d90 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 09:41:31 +0200 Subject: [PATCH 08/19] :construction: Update: SelectPlayerButtonView for call ShowAllPlayer sheet --- .../Player/SelectPlayerButtonView.swift | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift b/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift index 93bf37b..ab8c7a3 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift @@ -35,8 +35,17 @@ struct CustomShapeRightButton: Shape { struct SelectPlayerButtonView: View { - var player1:String = "IA" - var player2:String = "IA" + @State var player1:String = "IA" + @State var player2:String = "IA" + + @State private var players = [ + Player(name: "Rayhan", wins: 7, losses: 6, photo: "shrek"), + Player(name: "Remi", wins: 7, losses: 2, photo: "shrek"), + Player(name: "Nathan", wins: 14, losses: 5, photo: "shrek") + ] + + @State private var showingPopup = false + var body: some View { ZStack{ Image("vs-custom") @@ -51,6 +60,15 @@ struct SelectPlayerButtonView: View { .padding(3) Button(action: { print("Button j1 pressé!") + if (player1 == "IA"){ + if (player2 == "Player1"){ + player1="Player2" + }else{ + player1="Player1" + } + }else{ + player1="IA" + } }) { VStack { Text("+") @@ -62,9 +80,8 @@ struct SelectPlayerButtonView: View { } .frame(width: 150, height: 150) .padding() - .border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: 4) - .foregroundColor(.black) - .foregroundColor(.white) + .border(Colors.TitleText, width: 4) + .foregroundColor(Colors.TitleText) .cornerRadius(10) .clipShape(CustomShapeLeftButton()) } @@ -76,6 +93,7 @@ struct SelectPlayerButtonView: View { Button(action: { print("Button j2 pressé!") + showingPopup = true }) { VStack { Text("+") @@ -84,11 +102,13 @@ struct SelectPlayerButtonView: View { Text("Add a player") .font(.body) .bold() + /*.sheet(isPresented: $showingPopup) { + ShowAllPlayer + }*/ } .frame(width: 150, height: 150) .padding() - .foregroundColor(.black) - .border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: 4) - .foregroundColor(.white) + .border(Colors.TitleText, width: 4) + .foregroundColor(Colors.TitleText) .cornerRadius(10) .clipShape(CustomShapeRightButton()) } From 7eaa6049c2fbd2f8a52bcb53b47c8f02fa17955c Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 09:43:34 +0200 Subject: [PATCH 09/19] :heavy_plus_sign: Update: Depency --- DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj index 9eb86f1..7188be3 100644 --- a/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj +++ b/DouShouQi_App/DouShouQi_App.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ EC05BFCB2C05F470000F7B19 /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC05BFCA2C05F470000F7B19 /* GameScene.swift */; }; EC2DD03B2C0CDE7C00FC55C0 /* DSQ.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC2DD03A2C0CDE7C00FC55C0 /* DSQ.xcframework */; }; EC2DD03F2C0CDF0C00FC55C0 /* MainMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC2DD03E2C0CDF0C00FC55C0 /* MainMenuView.swift */; }; + EC2DD0412C1C203000FC55C0 /* ShowAllPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC2DD0402C1C203000FC55C0 /* ShowAllPlayer.swift */; }; EC3EE4B12C0CD46000710153 /* ButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3EE4B02C0CD46000710153 /* ButtonView.swift */; }; EC3EE4B32C0CD47000710153 /* MainButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3EE4B22C0CD47000710153 /* MainButton.swift */; }; EC62C4FB2C038BD20048CD0B /* PlayersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC62C4FA2C038BD20048CD0B /* PlayersView.swift */; }; @@ -108,6 +109,7 @@ EC05BFCA2C05F470000F7B19 /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = ""; }; EC2DD03A2C0CDE7C00FC55C0 /* DSQ.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = DSQ.xcframework; path = ../Dependencies/DSQ.xcframework; sourceTree = ""; }; EC2DD03E2C0CDF0C00FC55C0 /* MainMenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainMenuView.swift; sourceTree = ""; }; + EC2DD0402C1C203000FC55C0 /* ShowAllPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowAllPlayer.swift; sourceTree = ""; }; EC3EE4B02C0CD46000710153 /* ButtonView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonView.swift; sourceTree = ""; }; EC3EE4B22C0CD47000710153 /* MainButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainButton.swift; sourceTree = ""; }; EC62C4FA2C038BD20048CD0B /* PlayersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayersView.swift; sourceTree = ""; }; @@ -224,6 +226,7 @@ 647D565B2BFD0212008D02EA /* PlayerResumeFrame.swift */, EC62C4FC2C0391D30048CD0B /* PlayerRow.swift */, EC62C50E2C05D06A0048CD0B /* AddPlayerView.swift */, + EC2DD0402C1C203000FC55C0 /* ShowAllPlayer.swift */, ); path = Player; sourceTree = ""; @@ -530,6 +533,7 @@ EC62C5092C0467240048CD0B /* SplashScreenView.swift in Sources */, EC2DD03F2C0CDF0C00FC55C0 /* MainMenuView.swift in Sources */, 64FC4D692C09C78000D08B8B /* SelectPlayerView.swift in Sources */, + EC2DD0412C1C203000FC55C0 /* ShowAllPlayer.swift in Sources */, EC62C4FD2C0391D30048CD0B /* PlayerRow.swift in Sources */, EC62C4FB2C038BD20048CD0B /* PlayersView.swift in Sources */, 6458345C2BF5F92300E18321 /* DouShouQi_AppApp.swift in Sources */, From 77ce09091a0a5131dbf774f35c2fe2c85b976921 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 13:49:19 +0200 Subject: [PATCH 10/19] :bug: Update: Call AddPlayerView --- .../Components/Player/SelectPlayerButtonView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift b/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift index ab8c7a3..8666a37 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift @@ -102,9 +102,9 @@ struct SelectPlayerButtonView: View { Text("Add a player") .font(.body) .bold() - /*.sheet(isPresented: $showingPopup) { - ShowAllPlayer - }*/ + .sheet(isPresented: $showingPopup) { + ShowAllPlayer(isShowingSheet: $showingPopup, players: $players) + } } .frame(width: 150, height: 150) .padding() .border(Colors.TitleText, width: 4) From a790d1e26cd2ac724dd72dd2ff8440f0e1777fe5 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 14:38:33 +0200 Subject: [PATCH 11/19] :construction: Update call fonction ShowAllPlayer --- .../Components/Player/SelectPlayerButtonView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift b/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift index 8666a37..b9903a0 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift @@ -103,7 +103,7 @@ struct SelectPlayerButtonView: View { .font(.body) .bold() .sheet(isPresented: $showingPopup) { - ShowAllPlayer(isShowingSheet: $showingPopup, players: $players) + ShowAllPlayer(players: $players) } } .frame(width: 150, height: 150) .padding() From cacf6d85d6ef94c9c0b4def6f2853d96e277b06d Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Jun 2024 14:40:08 +0200 Subject: [PATCH 12/19] :construction: Update param function --- .../Components/Player/ShowAllPlayer.swift | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift b/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift index 566cfb4..b0173ae 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift @@ -9,30 +9,14 @@ import SwiftUI import UIKit struct ShowAllPlayer: View { - @Binding var isShowingSheet: Bool + @State var isShowingSheet = false @Binding var players: [Player] - var body: some View { - Button(action: { - self.isShowingSheet = true - }) { - Text("Afficher les joueurs") - } - .sheet(isPresented: $isShowingSheet) { - PlayerSheetView(isShowingSheet: $isShowingSheet, players: $players) - } - } -} - -struct PlayerSheetView: View { - @Environment(\.dismiss) var dismiss - @Binding var isShowingSheet: Bool - @Binding var players: [Player] - var body: some View { VStack { - /*List(players, id: \.self) { player in - Text(player.name) // Assumant que Player a une propriété 'name' - }*/ + Button(action: { + }) { + Text("Afficher les joueurs") + } Button(action: { self.isShowingSheet = true }) { @@ -41,9 +25,9 @@ struct PlayerSheetView: View { .padding() .background(Color.red) .cornerRadius(10) - } - .sheet(isPresented: $isShowingSheet) { - AddPlayerView(isPresented: $isShowingSheet, players: $players) + .sheet(isPresented: $isShowingSheet) { + AddPlayerView(isPresented: $isShowingSheet, players: $players) + } } } } From fb1a4e94665582c9d927fe1499b568f17005184b Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 17 Jun 2024 15:07:16 +0200 Subject: [PATCH 13/19] =?UTF-8?q?=E2=9C=A8=20Update:=20AddPlayerView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DouShouQi_App/Components/Player/AddPlayerView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift b/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift index 1b288b2..8b5cc75 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/AddPlayerView.swift @@ -10,7 +10,7 @@ import UIKit struct AddPlayerView: View { @Binding var isPresented: Bool - @Binding var playersVM: PlayersVM + @ObservedObject var playersVM: PlayersVM @State private var playerName: String = "" @State private var showAlert = false @State private var showImagePicker = false From df0f29331ec24452b6fb17db681788d004fdef1b Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 17 Jun 2024 15:16:03 +0200 Subject: [PATCH 14/19] =?UTF-8?q?=F0=9F=90=9B=20Update:=20call=20ShowAllPl?= =?UTF-8?q?ayer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Player/SelectPlayerButtonView.swift | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift b/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift index b9903a0..ce3ebb0 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/SelectPlayerButtonView.swift @@ -38,11 +38,7 @@ struct SelectPlayerButtonView: View { @State var player1:String = "IA" @State var player2:String = "IA" - @State private var players = [ - Player(name: "Rayhan", wins: 7, losses: 6, photo: "shrek"), - Player(name: "Remi", wins: 7, losses: 2, photo: "shrek"), - Player(name: "Nathan", wins: 14, losses: 5, photo: "shrek") - ] + @ObservedObject var playersVM: PlayersVM @State private var showingPopup = false @@ -103,7 +99,7 @@ struct SelectPlayerButtonView: View { .font(.body) .bold() .sheet(isPresented: $showingPopup) { - ShowAllPlayer(players: $players) + ShowAllPlayer(playersVM: playersVM) } } .frame(width: 150, height: 150) .padding() @@ -120,6 +116,7 @@ struct SelectPlayerButtonView: View { struct SelectPlayerButtonView_Previews: PreviewProvider { static var previews: some View { - SelectPlayerButtonView() + @StateObject var playersVM = PlayersVM() + SelectPlayerButtonView(playersVM: PlayersVM()) } } From 86912bf1fff9fe3217b1dd1385e843072916124e Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 17 Jun 2024 15:17:14 +0200 Subject: [PATCH 15/19] =?UTF-8?q?=E2=9C=A8=20Update:=20Show=20button=20and?= =?UTF-8?q?=20affiche=20all=20player?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Player/ShowAllPlayer.swift | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift b/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift index b0173ae..cf706fc 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Player/ShowAllPlayer.swift @@ -6,29 +6,45 @@ // import SwiftUI -import UIKit struct ShowAllPlayer: View { - @State var isShowingSheet = false - @Binding var players: [Player] + @State private var isShowingSheet = false + @ObservedObject var playersVM: PlayersVM + var body: some View { - VStack { - Button(action: { - }) { - Text("Afficher les joueurs") - } + VStack(alignment: .leading) { + Text("Liste des joueurs actuelle :") + List { + ForEach($playersVM.players, id: \.self) { playerVM in + Button(action: { + + }) { + HStack { + Image(systemName: "person.fill") + .resizable() + .frame(width: 30, height: 30) + Text(playerVM.player.name.wrappedValue) + } + } + } + } Button(action: { self.isShowingSheet = true }) { - Text("Add Player") + Text("Add a player") + .font(.headline) .foregroundColor(.white) .padding() + .frame(maxWidth: .infinity) .background(Color.red) .cornerRadius(10) - .sheet(isPresented: $isShowingSheet) { - AddPlayerView(isPresented: $isShowingSheet, players: $players) - } + .padding(.horizontal) + } + .padding(.bottom) + .sheet(isPresented: $isShowingSheet) { + AddPlayerView(isPresented: $isShowingSheet, playersVM: playersVM) } } } } + From 3a569bea57a2fc1b4b2736c0aa8f3782a4d637d3 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 17 Jun 2024 15:21:14 +0200 Subject: [PATCH 16/19] =?UTF-8?q?=F0=9F=90=9B=20Update:=20Binding=20to=20P?= =?UTF-8?q?ublished?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DouShouQi_App/DouShouQi_App/ViewModel/Players/PlayersVM.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/ViewModel/Players/PlayersVM.swift b/DouShouQi_App/DouShouQi_App/ViewModel/Players/PlayersVM.swift index ec46dfc..8104965 100644 --- a/DouShouQi_App/DouShouQi_App/ViewModel/Players/PlayersVM.swift +++ b/DouShouQi_App/DouShouQi_App/ViewModel/Players/PlayersVM.swift @@ -12,7 +12,6 @@ import Combine public class PlayersVM: ObservableObject{ - @Published var players: [PlayerVM] public func SavePlayer(player: PlayerVM){ From 94b49e99cb73f1dcf97e564879e3ef86f87522c1 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 17 Jun 2024 15:22:19 +0200 Subject: [PATCH 17/19] =?UTF-8?q?=F0=9F=9A=A7=20Add:=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift index cd001d3..2642ee8 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift @@ -38,7 +38,7 @@ struct MainMenuView: View { HStack { VStack(spacing: 25) { MainMenuButton(text: "Play", destination: SelectPlayerView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) - MainMenuButton(text: "Historique", destination: HistoricView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) + //MainMenuButton(text: "Historique", destination: HistoricView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) MainMenuButton(text: "Best Scores", destination: ScoreBoardView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) MainMenuButton(text: "Players", destination: PlayersView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) MainMenuButton(text: "Settings", destination: SettingsView(), sound: "TitleScreenButtonSound", topRightCorner: 10, bottomRightCorner: 10) From d28d25f150c0a6b6931c8e3419cfafd10f3f8fa6 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 17 Jun 2024 15:22:48 +0200 Subject: [PATCH 18/19] =?UTF-8?q?=F0=9F=90=9B=20Update:=20Binding=20to=20o?= =?UTF-8?q?bservableObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift index ac6a060..3b8e5fc 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Player/PlayersView.swift @@ -61,7 +61,7 @@ struct PlayersView: View { } .padding(.bottom) .sheet(isPresented: $showingPopup) { - AddPlayerView(isPresented: $showingPopup, playersVM: $playersVM) + AddPlayerView(isPresented: $showingPopup, playersVM: playersVM) } } } From a93d4e26b202f524781858011e41bdf0a16afee0 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 17 Jun 2024 15:23:26 +0200 Subject: [PATCH 19/19] =?UTF-8?q?=F0=9F=9A=A7=20Add:=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift index 7a7e873..cc532b0 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift @@ -15,7 +15,7 @@ struct SelectPlayerView: View { Spacer() - SelectPlayerButtonView() + //SelectPlayerButtonView() Spacer()