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" : {
"extractionState" : "manual",
"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" : {
"extractionState" : "manual",
"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" : {
"extractionState" : "manual",
"localizations" : {
@ -188,6 +239,9 @@
}
}
}
},
"inGame.title" : {
},
"mainMenu.button.newGame" : {
"extractionState" : "manual",

@ -49,8 +49,8 @@ struct NewGameView: View {
}
Button("newGame.play", systemImage: "play") {
// TODO: yes
NavigationLink(destination: IngameView(settings: vm, player1: p1, player2: p2)/*.navigationTitle("inGame.title")*/) {
Label("newGame.play", systemImage: "play")
}
}
}
@ -66,17 +66,15 @@ private struct PlayerSectionView: View {
var body: some View {
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)
ForEach(PlayerType.allCases) {
Text(LocalizedStringKey($0.baseTranslationKey)).tag($0)
}
}
let binding: Binding<String> = if (settings.type == .Human) {
$name
} else {
// FIXME: make text field readonly
.constant("TODO constant name")
.constant(String(localized: String.LocalizationValue("\(settings.type.baseTranslationKey).name" as String)))
}
TextField("newGame.player.name", text: binding)
// 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 {
NewGameView()
}

@ -2,9 +2,9 @@ import Foundation
class NewGameVM : ObservableObject {
@Published var rulesType: RulesType = .Classic
@Published var width: UInt = 7
@Published var height: UInt = 7
@Published var alignedTokens: UInt = 4
@Published var width: UInt = 7 { didSet { if width < 1 { width = 1 } } }
@Published var height: UInt = 7 { didSet { if height < 1 { height = 1 } } }
@Published var alignedTokens: UInt = 4 { didSet { if alignedTokens < 2 { alignedTokens = 2 } } }
}
// 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
}

Loading…
Cancel
Save