création du stub et changement de la liste + abandon de l'edit du joueur car impossible avec la lib donnée => go faire le jeu 💥

SpriteKit
Pierre FERREIRA 11 months ago
parent 516db63bde
commit 9158760e89

@ -29,6 +29,7 @@
7BDE976D2C0E13160079F2CD /* EditModalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDE976C2C0E13160079F2CD /* EditModalView.swift */; };
7BDE976F2C0E18160079F2CD /* PlayerVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDE976E2C0E18160079F2CD /* PlayerVM.swift */; };
7BE8C5652C09A29A00A6E8C9 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BE8C5642C09A29A00A6E8C9 /* Color.swift */; };
7BEAB78B2C19A26000DF39C9 /* StubbedPlayers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BEAB78A2C19A26000DF39C9 /* StubbedPlayers.swift */; };
BA5AFD332C09C7470056D332 /* ClassicTextDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5AFD322C09C7470056D332 /* ClassicTextDisplay.swift */; };
BA5AFD352C09CAC10056D332 /* NavButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5AFD342C09CAC10056D332 /* NavButton.swift */; };
BA5AFD392C09D1020056D332 /* DoubleTextDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5AFD382C09D1020056D332 /* DoubleTextDisplay.swift */; };
@ -78,6 +79,7 @@
7BDE976C2C0E13160079F2CD /* EditModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditModalView.swift; sourceTree = "<group>"; };
7BDE976E2C0E18160079F2CD /* PlayerVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerVM.swift; sourceTree = "<group>"; };
7BE8C5642C09A29A00A6E8C9 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
7BEAB78A2C19A26000DF39C9 /* StubbedPlayers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StubbedPlayers.swift; sourceTree = "<group>"; };
BA5AFD322C09C7470056D332 /* ClassicTextDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassicTextDisplay.swift; sourceTree = "<group>"; };
BA5AFD342C09CAC10056D332 /* NavButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavButton.swift; sourceTree = "<group>"; };
BA5AFD382C09D1020056D332 /* DoubleTextDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoubleTextDisplay.swift; sourceTree = "<group>"; };
@ -152,6 +154,7 @@
7B4508CB2BF206AF0027E1EF /* DouShouQiIOS */ = {
isa = PBXGroup;
children = (
7BEAB7892C19A24800DF39C9 /* Stub */,
BA5AFD312C09C6E90056D332 /* ContentView */,
7BE8C5632C09A27600A6E8C9 /* Extension */,
7B3B17652BF24EB1002BC817 /* Struct */,
@ -222,6 +225,14 @@
path = Extension;
sourceTree = "<group>";
};
7BEAB7892C19A24800DF39C9 /* Stub */ = {
isa = PBXGroup;
children = (
7BEAB78A2C19A26000DF39C9 /* StubbedPlayers.swift */,
);
path = Stub;
sourceTree = "<group>";
};
BA5AFD312C09C6E90056D332 /* ContentView */ = {
isa = PBXGroup;
children = (
@ -370,6 +381,7 @@
7BE8C5652C09A29A00A6E8C9 /* Color.swift in Sources */,
7B6426FB2C00BFF500575E16 /* SpriteMeeple.swift in Sources */,
7B4508CD2BF206AF0027E1EF /* DouShouQiIOSApp.swift in Sources */,
7BEAB78B2C19A26000DF39C9 /* StubbedPlayers.swift in Sources */,
7B6426F92C00BDEA00575E16 /* SpriteKitView.swift in Sources */,
7BDE976D2C0E13160079F2CD /* EditModalView.swift in Sources */,
7BDE976F2C0E18160079F2CD /* PlayerVM.swift in Sources */,

@ -8,7 +8,7 @@
import Foundation
import DouShouQiModel
class PlayerVM : ObservableObject {
class PlayerVM : ObservableObject, Identifiable {
@Published var player : Player
@Published var data : Player.Data
@Published var isEditing : Bool

@ -10,7 +10,17 @@ import DouShouQiModel
extension Player {
//var age : Int{get{return 0} set{age = newValue}}
var matches : [Match]{
return [Match(gameEndScreen: "DouShouQi", opponent: "BadBro", selfScore: 1, opScore: 1)]
}
/*public convenience init?(withId id : Owner, andName name : String, andAge _age : Int){
self.init(withName: name, andId: id)
//self.age = _age
}
*/
struct Data : Identifiable {
//var dataId: ObjectIdentifier = ObjectIdentifier()
@ -25,11 +35,13 @@ extension Player {
func update (from data : Data){
///Test de l'id
if (data.id == .noOne){
if (data.id == .noOne){ // gestion de l'id en fonction de l'utilisation.
print("Problème de mise a jour des données")
return
}
///Assignations
//self.id = data.id
//self.name = data.name
}
}

@ -0,0 +1,19 @@
//
// StubbedPlayers.swift
// DouShouQiIOS
//
// Created by Pierre FERREIRA on 12/06/2024.
//
import Foundation
import DouShouQiModel
struct StubbedPlayers{
let meruem : PlayerVM = PlayerVM(with: Player(withName: "Meruemu", andId: .player1)!)
let kumogi : PlayerVM = PlayerVM(with: Player(withName: "Kumogi", andId: .player2)!)
func getStubbedPlayer() -> [PlayerVM] {
return [meruem, kumogi]
}
}

@ -10,7 +10,7 @@ import DouShouQiModel
struct EditModalView: View {
@Binding var playerVM : PlayerVM
var playerVM : PlayerVM
@Binding var isEdited : Bool
var name : String = ""
var body: some View {
@ -27,6 +27,6 @@ struct EditModalView: View {
struct EditModalView_Previews: PreviewProvider {
static var previews: some View {
EditModalView(playerVM: .constant(PlayerVM(with:Player(withName: "toto", andId: .player2)! )), isEdited: .constant(true))
EditModalView(playerVM: PlayerVM(with:Player(withName: "toto", andId: .player2)!), isEdited: .constant(true))
}
}

@ -37,19 +37,19 @@ struct HistoryView: View {
VStack(alignment: .leading) {
Text(match.opponent)
.font(.headline)
Text("Score: \(match.score)")
Text("Score: \(match.selfScore) - \(match.opScore)")
.font(.subheadline)
}
.padding(.leading, 10)
Spacer()
Text(match.result)
.foregroundColor(match.result == "Victoire" ? .green : .red)
Text(match.selfScore > match.opScore ? "Victoire" : (match.selfScore == match.opScore ? "Nul" : "Défaite"))
.foregroundColor(match.selfScore > match.opScore ? .green : .red)
.padding(.trailing, 10)
}.listRowBackground(Color.yellow.opacity(0.1))
.padding()
.background(match.result == "Victoire" ? Color.green.opacity(0.3) : Color.red.opacity(0.3))
.background(match.selfScore > match.opScore ? Color.green.opacity(0.3) : Color.red.opacity(0.3))
.cornerRadius(10)
@ -66,16 +66,17 @@ struct Match: Identifiable {
var id = UUID()
var gameEndScreen: String
var opponent: String
var score: String
var result: String
var selfScore: Int
var opScore: Int
//var result: String
}
struct HistoryView_Previews: PreviewProvider {
static var previews: some View {
let sampleMatches = [
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 1", score: "3-0", result: "Victoire"),
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 2", score: "0-3", result: "Défaite"),
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 3", score: "2-2", result: "Nul")
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 1", selfScore: 3, opScore: 0),//result: "Victoire""
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 2", selfScore: 0, opScore: 3),// result: "Défaite"),
Match(gameEndScreen: "DouShouQi", opponent: "Opponent 3", selfScore: 2, opScore: 2),// result: "Nul")
]
HistoryView(playerName: "bro", matches: sampleMatches)
}

@ -6,8 +6,10 @@
//
import SwiftUI
import DouShouQiModel
struct PlayerListView: View {
var playerStub : StubbedPlayers = StubbedPlayers()
var body: some View {
//NavigationStack {
ZStack {
@ -16,13 +18,36 @@ struct PlayerListView: View {
/*Text("Classement des joueurs")
.scaleEffect(1.75)*/
List(playerStub.getStubbedPlayer()) { player in
NavigationLink {
PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
],
playerVm: player) //mettre player plus tard
} label:{Text("pif")}
}.navigationDestination(for: String.self) { name in
PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
],
playerVm: PlayerVM(with: Player(withName: "Toto", andId: .player2)!)) //mettre player plus tard
}
.navigationTitle("Leaderboard")
List {
NavigationLink{
PlayerView(name: "Billy", age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
Match(gameEndScreen: "opponent1", opponent: "Opponent 1", score: "3-2", result: "Victoire"),
Match(gameEndScreen: "opponent2", opponent: "Opponent 2", score: "1-3", result: "Défaite"),
Match(gameEndScreen: "opponent3", opponent: "Opponent 3", score: "2-2", result: "Nul")
]) //mettre player plus tard
PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
],
playerVm: PlayerVM(with: Player(withName: "Billy", andId: .player2)!)) //mettre player plus tard
} label:{Text("pif")}
@ -31,11 +56,12 @@ struct PlayerListView: View {
NavigationLink("Bromingo", value: "Bromingo")
}
.navigationDestination(for: String.self) { name in
PlayerView(name: name, age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
Match(gameEndScreen: "opponent1", opponent: "Opponent 1", score: "3-2", result: "Victoire"),
Match(gameEndScreen: "opponent2", opponent: "Opponent 2", score: "1-3", result: "Défaite"),
Match(gameEndScreen: "opponent3", opponent: "Opponent 3", score: "2-2", result: "Nul")
]) //mettre player plus tard
PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches: [
Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
],
playerVm: PlayerVM(with: Player(withName: "Toto", andId: .player2)!)) //mettre player plus tard
}
.navigationTitle("Leaderboard")
}

@ -11,7 +11,7 @@ import DouShouQiModel
struct PlayerView: View {
//var Player : Player;
var name : String
//var name : String
var age: Int
var winLossRatio: Double
var gamesPlayed: Int
@ -20,7 +20,7 @@ struct PlayerView: View {
var histoMatches : [ Match ]
@State var isEdited : Bool = false
//@ObservedObject var player : PlayerVM //TODO
@ObservedObject var playerVm : PlayerVM //TODO
//@Published var data : Data
var body: some View {
@ -39,7 +39,7 @@ struct PlayerView: View {
Spacer()
VStack(alignment: .center){
Text("\(name) Sname")
Text("\(playerVm.player.name) Sname")
.font(.largeTitle)
.foregroundColor(Color.white)
@ -94,7 +94,7 @@ struct PlayerView: View {
Spacer()
NavButton("Historique", destinationView: {HistoryView(playerName: name, matches: histoMatches)})
NavButton("Historique", destinationView: {HistoryView(playerName: playerVm.player.name, matches: histoMatches)})
.padding(.top, 20)
}
.toolbar {
@ -103,7 +103,7 @@ struct PlayerView: View {
//}
}
.sheet(isPresented: $isEdited, content: {
Text("CouCou")
EditModalView(playerVM: playerVm, isEdited: $isEdited)
})
//}//Zstack
}
@ -114,11 +114,11 @@ struct PlayerView_Previews: PreviewProvider {
static var previews: some View {
/*var player1 = new Player(Player(withName: "Meruemu", andSName: "Roi", andId: 2, andAge: 1)*/
let stubedMatches = [
Match(gameEndScreen: "opponent1", opponent: "Opponent 1", score: "3-2", result: "Victoire"),
Match(gameEndScreen: "opponent2", opponent: "Opponent 2", score: "1-3", result: "Défaite"),
Match(gameEndScreen: "opponent3", opponent: "Opponent 3", score: "2-2", result: "Nul")
Match(gameEndScreen: "opponent1", opponent: "Opponent 1", selfScore: 3, opScore: 2),
Match(gameEndScreen: "opponent2", opponent: "Opponent 2", selfScore: 1, opScore: 3),
Match(gameEndScreen: "opponent3", opponent: "Opponent 3", selfScore: 2, opScore: 2)
]
PlayerView(name: "bro", age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches : stubedMatches)
PlayerView(age: 18, winLossRatio: 1.0, gamesPlayed: 10, wins: 5, losses: 5, histoMatches : stubedMatches, playerVm: PlayerVM(with: Player(withName: "toto", andId: .player2)!))
}
}

Loading…
Cancel
Save