diff --git a/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift b/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift index c1a692b..9db4ca0 100644 --- a/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift +++ b/DouShouQi_App/DouShouQi_App/Components/MainMenuButton.swift @@ -92,6 +92,6 @@ struct RoundedCornersShape: Shape { struct MainMenuButton_Previews: PreviewProvider { static var previews: some View { - MainMenuButton(text: "test", destination: HistoricView(historicListVM: HistoricListVM()), sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) + MainMenuButton(text: "test", sound: "TitleScreenButtonSound", horizontalAlignment: .leading, topRightCorner: 10, bottomRightCorner: 10) } } diff --git a/DouShouQi_App/DouShouQi_App/Views/Game/GameView.swift b/DouShouQi_App/DouShouQi_App/Views/Game/GameView.swift index 2e9945b..719714c 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Game/GameView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Game/GameView.swift @@ -3,7 +3,6 @@ import SpriteKit import DouShouQiModel struct GameView: View { - var gameScene: GameScene = GameScene(size: CGSize(width: 700, height: 900)) @StateObject var gameVM: PlayingGameVM @StateObject var chronoVM = ChronometerViewModel() @@ -11,8 +10,6 @@ struct GameView: View { @Binding var isDisplayed: Bool @Binding var parentIsDisplayed: Bool - var player1_name: String - var player2_name: String @StateObject var historicVm = HistoricListVM() var body: some View { @@ -65,7 +62,9 @@ struct GameView: View { } private func saveHistoric() { - let newHistoric = HistoricVM(historic: Historique(player1_name: player1_name, player2_name: player2_name, time: chronoVM.formattedTime(), result: gameVM.winner)) + let player1_name = gameVM.game.players[.player1]?.name + let player2_name = gameVM.game.players[.player2]?.name + let newHistoric = HistoricVM(historic: Historique(player1_name: player1_name ?? "", player2_name: player2_name ?? "", time: chronoVM.formattedTime(), result: gameVM.winner)) historicVm.SavePlayer(historic: newHistoric) } } diff --git a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift index 3607083..2758ef4 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Menu/MainMenuView.swift @@ -54,7 +54,7 @@ struct MainMenuView: View { SelectPlayerView(isDisplayed: $showSelectPlayer) } .navigationDestination(isPresented: $showHistoric) { - HistoricView(historicVM: HistoricVM()) + HistoricView(historicListVM: historicList) } .navigationDestination(isPresented: $showBestScores) { ScoreBoardView() diff --git a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift index 7f2d81a..a7cff0f 100644 --- a/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift +++ b/DouShouQi_App/DouShouQi_App/Views/Player/SelectPlayerView.swift @@ -37,7 +37,7 @@ struct SelectPlayerView: View { } .navigationDestination(isPresented: $gameIsPlaying) { - GameView(gameVM: PlayingGameVM(withRules: ClassicRules(), andPlayer1: HumanPlayer(withName: player1.player.name, andId: .player1)!, andPlayer2: HumanPlayer(withName: player2.player.name, andId: .player2)!)!, isDisplayed: $gameIsPlaying, parentIsDisplayed: $isDisplayed) + GameView(gameVM: PlayingGameVM(withRules: ClassicRules(), andPlayer1: HumanPlayer(withName: player1.player.name, andId: .player1)!, andPlayer2: HumanPlayer(withName: player2.player.name, andId: .player2)!)!,isDisplayed: $gameIsPlaying, parentIsDisplayed: $isDisplayed) } .navigationDestination(isPresented: $gameSettings) { ContentView()