parent
dcdc6113d1
commit
a171478e2c
@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// HistoricListVM.swift
|
||||||
|
// DouShouQi_App
|
||||||
|
//
|
||||||
|
// Created by étudiant on 24/06/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
import DouShouQiModel
|
||||||
|
|
||||||
|
class HistoricListVM: ObservableObject {
|
||||||
|
|
||||||
|
@Published var historicList: [HistoricVM]
|
||||||
|
|
||||||
|
public func SavePlayer(historic: HistoricVM){
|
||||||
|
historicList.append(historic)
|
||||||
|
CoreDataManager.shared.saveHistorique(historique: historic)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func getAllHistoric() -> [HistoricVM]{
|
||||||
|
let coreDataPlayers = CoreDataManager.shared.fetchHistoriques()
|
||||||
|
self.historicList = coreDataPlayers.map { HistoricVM(historic: $0.toModel()) }
|
||||||
|
return historicList
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
historicList = []
|
||||||
|
|
||||||
|
historicList = getAllHistoric()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// HistoricVM.swift
|
||||||
|
// DouShouQi_App
|
||||||
|
//
|
||||||
|
// Created by Rémi REGNAULT on 29/05/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
import DouShouQiModel
|
||||||
|
|
||||||
|
class HistoricVM: ObservableObject, Identifiable, Hashable{
|
||||||
|
|
||||||
|
public static func == (lhs: HistoricVM, rhs: HistoricVM) -> Bool {
|
||||||
|
return lhs.id == rhs.id
|
||||||
|
}
|
||||||
|
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Published var historic: Historique
|
||||||
|
|
||||||
|
init(historic: Historique) {
|
||||||
|
self.historic = historic
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +0,0 @@
|
|||||||
//
|
|
||||||
// HistoricVM.swift
|
|
||||||
// DouShouQi_App
|
|
||||||
//
|
|
||||||
// Created by Rémi REGNAULT on 29/05/2024.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import SwiftUI
|
|
||||||
import DouShouQiModel
|
|
||||||
|
|
||||||
class HistoricVM: ObservableObject {
|
|
||||||
// Properties
|
|
||||||
public var gameVMs: [GameVM]
|
|
||||||
|
|
||||||
// Init
|
|
||||||
init() {
|
|
||||||
gameVMs = []
|
|
||||||
do {
|
|
||||||
let game = try Game(withRules: VerySimpleRules(), andPlayer1: HumanPlayer(withName: "Rémi", andId: .player1)!, andPlayer2: HumanPlayer(withName: "Nathan", andId: .player2)!)
|
|
||||||
gameVMs.append(GameVM(withGame: game, time: "11:01"))
|
|
||||||
} catch {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue