|
|
|
@ -9,38 +9,47 @@ import SwiftUI
|
|
|
|
|
import PhotosUI
|
|
|
|
|
|
|
|
|
|
struct NewGameView: View {
|
|
|
|
|
@State private var p2: PlayerType = .AISimpleNegaMax
|
|
|
|
|
@State private var rules_type: RulesType = .Classic
|
|
|
|
|
@State private var width: UInt = 7
|
|
|
|
|
@State private var height: UInt = 7
|
|
|
|
|
@State private var alignedTokens: UInt = 4
|
|
|
|
|
@StateObject
|
|
|
|
|
private var vm: NewGameVM = NewGameVM()
|
|
|
|
|
@StateObject
|
|
|
|
|
private var p1: PlayerSettingsVM = PlayerSettingsVM(type: .Human)
|
|
|
|
|
@StateObject
|
|
|
|
|
private var p2: PlayerSettingsVM = PlayerSettingsVM(type: .AISimpleNegaMax)
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
VStack {
|
|
|
|
|
Form {
|
|
|
|
|
Section("generic.player1.name") {
|
|
|
|
|
PlayerSectionView(initialType: .Human)
|
|
|
|
|
Section(header: Label("generic.player1.name", systemImage: "person")) {
|
|
|
|
|
PlayerSectionView(settings: p1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Section("generic.player2.name") {
|
|
|
|
|
PlayerSectionView(initialType: .AISimpleNegaMax)
|
|
|
|
|
Section(header: Label("generic.player2.name", systemImage: "person")) {
|
|
|
|
|
PlayerSectionView(settings: p2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
|
Picker("newGame.rules.title", systemImage: "globe", selection: $rules_type) {
|
|
|
|
|
Picker("newGame.rules.title", systemImage: "slider.horizontal.3", selection: $vm.rulesType) {
|
|
|
|
|
Text("generic.rules.classic.name").tag(RulesType.Classic)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Image(systemName: "globe")
|
|
|
|
|
Button(action: {
|
|
|
|
|
// TODO
|
|
|
|
|
}) {
|
|
|
|
|
Image(systemName: "questionmark.circle")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Section("newGame.dimensions") {
|
|
|
|
|
Stepper("newGame.dimensions.width \(width)", value: $width)
|
|
|
|
|
Stepper("newGame.dimensions.height \(height)", value: $height)
|
|
|
|
|
Stepper("newGame.dimensions.alignedTokens \(alignedTokens)", value: $alignedTokens)
|
|
|
|
|
Section(header: Label("newGame.dimensions", systemImage: "crop")) {
|
|
|
|
|
Stepper("newGame.dimensions.width \(vm.width)", value: $vm.width)
|
|
|
|
|
Stepper("newGame.dimensions.height \(vm.height)", value: $vm.height)
|
|
|
|
|
Stepper("newGame.dimensions.alignedTokens \(vm.alignedTokens)", value: $vm.alignedTokens)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button("newGame.play") {
|
|
|
|
|
Section(header: Label("newGame.timeLimit", systemImage: "stopwatch")) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button("newGame.play", systemImage: "play") {
|
|
|
|
|
// TODO: yes
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -49,19 +58,21 @@ struct NewGameView: View {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private struct PlayerSectionView: View {
|
|
|
|
|
@State private var type: PlayerType
|
|
|
|
|
@State private var name: String
|
|
|
|
|
@ObservedObject
|
|
|
|
|
private var settings: PlayerSettingsVM
|
|
|
|
|
|
|
|
|
|
@State private var name: String = ""
|
|
|
|
|
@State private var photo: PhotosPickerItem? = nil
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
Picker("newGame.player.type", selection: $type) {
|
|
|
|
|
Picker("newGame.player.type", selection: $settings.type) {
|
|
|
|
|
Text("generic.player.type.human").tag(PlayerType.Human)
|
|
|
|
|
Text("generic.player.type.aiRandom").tag(PlayerType.AIRandom)
|
|
|
|
|
Text("generic.player.type.aiFinnishHim").tag(PlayerType.AIFinnishHim)
|
|
|
|
|
Text("generic.player.type.aiSimpleNegaMax").tag(PlayerType.AISimpleNegaMax)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let binding: Binding<String> = if (self.type == .Human) {
|
|
|
|
|
let binding: Binding<String> = if (settings.type == .Human) {
|
|
|
|
|
$name
|
|
|
|
|
} else {
|
|
|
|
|
// FIXME: make text field readonly
|
|
|
|
@ -74,27 +85,18 @@ private struct PlayerSectionView: View {
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// TODO: actual photo support
|
|
|
|
|
Image(systemName: "globe").overlay {
|
|
|
|
|
Image(systemName: "camera.viewfinder").overlay {
|
|
|
|
|
PhotosPicker(selection: $photo) {
|
|
|
|
|
Text("newGame.player.photo.picker")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init(initialType type: PlayerType) {
|
|
|
|
|
self.type = type
|
|
|
|
|
self.name = "TODO default name"
|
|
|
|
|
init(settings: PlayerSettingsVM) {
|
|
|
|
|
self.settings = settings
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum PlayerType {
|
|
|
|
|
case Human, AIRandom, AIFinnishHim, AISimpleNegaMax
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum RulesType {
|
|
|
|
|
case Classic
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#Preview {
|
|
|
|
|
NewGameView()
|
|
|
|
|
}
|
|
|
|
|