Checked number bounds & localized default player name

main
Mathieu GROUSSEAU 3 weeks ago
parent 3424529f43
commit a6c3d5ddca

@ -71,6 +71,23 @@
} }
} }
}, },
"generic.player.type.aiFinnishHim.name" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Finish Him"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Finish Him"
}
}
}
},
"generic.player.type.aiRandom" : { "generic.player.type.aiRandom" : {
"extractionState" : "manual", "extractionState" : "manual",
"localizations" : { "localizations" : {
@ -88,6 +105,23 @@
} }
} }
}, },
"generic.player.type.aiRandom.name" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Random"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Aléatoire"
}
}
}
},
"generic.player.type.aiSimpleNegaMax" : { "generic.player.type.aiSimpleNegaMax" : {
"extractionState" : "manual", "extractionState" : "manual",
"localizations" : { "localizations" : {
@ -105,6 +139,23 @@
} }
} }
}, },
"generic.player.type.aiSimpleNegaMax.name" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "NegaMax"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "NegaMax"
}
}
}
},
"generic.player.type.human" : { "generic.player.type.human" : {
"extractionState" : "manual", "extractionState" : "manual",
"localizations" : { "localizations" : {
@ -188,6 +239,9 @@
} }
} }
} }
},
"inGame.title" : {
}, },
"mainMenu.button.newGame" : { "mainMenu.button.newGame" : {
"extractionState" : "manual", "extractionState" : "manual",

@ -49,8 +49,8 @@ struct NewGameView: View {
} }
Button("newGame.play", systemImage: "play") { NavigationLink(destination: IngameView(settings: vm, player1: p1, player2: p2)/*.navigationTitle("inGame.title")*/) {
// TODO: yes Label("newGame.play", systemImage: "play")
} }
} }
} }
@ -66,17 +66,15 @@ private struct PlayerSectionView: View {
var body: some View { var body: some View {
Picker("newGame.player.type", selection: $settings.type) { Picker("newGame.player.type", selection: $settings.type) {
Text("generic.player.type.human").tag(PlayerType.Human) ForEach(PlayerType.allCases) {
Text("generic.player.type.aiRandom").tag(PlayerType.AIRandom) Text(LocalizedStringKey($0.baseTranslationKey)).tag($0)
Text("generic.player.type.aiFinnishHim").tag(PlayerType.AIFinnishHim) }
Text("generic.player.type.aiSimpleNegaMax").tag(PlayerType.AISimpleNegaMax)
} }
let binding: Binding<String> = if (settings.type == .Human) { let binding: Binding<String> = if (settings.type == .Human) {
$name $name
} else { } else {
// FIXME: make text field readonly .constant(String(localized: String.LocalizationValue("\(settings.type.baseTranslationKey).name" as String)))
.constant("TODO constant name")
} }
TextField("newGame.player.name", text: binding) TextField("newGame.player.name", text: binding)
// TODO: MacOS // TODO: MacOS
@ -97,6 +95,17 @@ private struct PlayerSectionView: View {
} }
} }
extension PlayerType {
var baseTranslationKey: String {
return switch (self) {
case .Human: "generic.player.type.human"
case .AIRandom: "generic.player.type.aiRandom"
case .AIFinnishHim: "generic.player.type.aiFinnishHim"
case .AISimpleNegaMax: "generic.player.type.aiSimpleNegaMax"
}
}
}
#Preview { #Preview {
NewGameView() NewGameView()
} }

@ -2,9 +2,9 @@ import Foundation
class NewGameVM : ObservableObject { class NewGameVM : ObservableObject {
@Published var rulesType: RulesType = .Classic @Published var rulesType: RulesType = .Classic
@Published var width: UInt = 7 @Published var width: UInt = 7 { didSet { if width < 1 { width = 1 } } }
@Published var height: UInt = 7 @Published var height: UInt = 7 { didSet { if height < 1 { height = 1 } } }
@Published var alignedTokens: UInt = 4 @Published var alignedTokens: UInt = 4 { didSet { if alignedTokens < 2 { alignedTokens = 2 } } }
} }
// Didn't manage to nest player settings under NewGameVM // Didn't manage to nest player settings under NewGameVM
@ -17,7 +17,9 @@ class PlayerSettingsVM : ObservableObject, Identifiable {
} }
} }
enum PlayerType { enum PlayerType: CaseIterable, Identifiable {
var id: Self { self }
case Human, AIRandom, AIFinnishHim, AISimpleNegaMax case Human, AIRandom, AIFinnishHim, AISimpleNegaMax
} }

Loading…
Cancel
Save