Fixed a few issues
This commit is contained in:
@@ -411,7 +411,7 @@
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
CURRENT_PROJECT_VERSION = 3;
|
||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
@@ -446,7 +446,7 @@
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
CURRENT_PROJECT_VERSION = 3;
|
||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
|
||||
Binary file not shown.
@@ -306,10 +306,16 @@ struct PlayerCell: View {
|
||||
*/
|
||||
struct CommanderDamageView: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
let targetPlayer: PlayerState
|
||||
@State private var targetPlayer: PlayerState
|
||||
let gameState: GameState
|
||||
let onUpdate: (PlayerState) -> Void
|
||||
|
||||
init(targetPlayer: PlayerState, gameState: GameState, onUpdate: @escaping (PlayerState) -> Void) {
|
||||
self._targetPlayer = State(initialValue: targetPlayer)
|
||||
self.gameState = gameState
|
||||
self.onUpdate = onUpdate
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
@@ -352,14 +358,21 @@ struct CommanderDamageView: View {
|
||||
|
||||
private func adjustCommanderDamage(attackerId: Int, by amount: Int) {
|
||||
Haptics.play(.light)
|
||||
let wasEliminated = targetPlayer.isEliminated
|
||||
var newPlayer = targetPlayer
|
||||
var damages = newPlayer.commanderDamages
|
||||
let current = damages[attackerId] ?? 0
|
||||
damages[attackerId] = max(0, current + amount)
|
||||
let newDamage = max(0, current + amount)
|
||||
let damageChange = newDamage - current
|
||||
damages[attackerId] = newDamage
|
||||
newPlayer.commanderDamages = damages
|
||||
// Commander damage also reduces life total
|
||||
newPlayer.life -= damageChange
|
||||
// Update local state so the view refreshes
|
||||
targetPlayer = newPlayer
|
||||
onUpdate(newPlayer)
|
||||
|
||||
if newPlayer.isEliminated && !targetPlayer.isEliminated {
|
||||
if newPlayer.isEliminated && !wasEliminated {
|
||||
Haptics.notification(.error)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user