iOS and Android Updates!
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 = 4;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
@@ -427,7 +427,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.1.0;
|
||||
MARKETING_VERSION = 1.2.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.MagicCounter;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||
@@ -447,7 +447,7 @@
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 4;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
@@ -463,7 +463,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.1.0;
|
||||
MARKETING_VERSION = 1.2.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.MagicCounter;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||
|
||||
Binary file not shown.
@@ -6,61 +6,180 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
/**
|
||||
* A circular button with an icon, used for game controls.
|
||||
* Supports optional long press to trigger a custom delta prompt.
|
||||
*/
|
||||
struct CircleButton: View {
|
||||
let icon: String
|
||||
let color: Color
|
||||
let size: CGFloat
|
||||
let action: () -> Void
|
||||
|
||||
init(icon: String, color: Color, size: CGFloat = 44, action: @escaping () -> Void) {
|
||||
var onLongPress: (() -> Void)? = nil
|
||||
|
||||
init(icon: String, color: Color, size: CGFloat = 44, action: @escaping () -> Void, onLongPress: (() -> Void)? = nil) {
|
||||
self.icon = icon
|
||||
self.color = color
|
||||
self.size = size
|
||||
self.action = action
|
||||
self.onLongPress = onLongPress
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
Button(action: action) {
|
||||
Image(systemName: icon)
|
||||
.font(size < 40 ? .caption : .title3)
|
||||
.frame(width: size, height: size)
|
||||
.background(color.opacity(0.2))
|
||||
.clipShape(Circle())
|
||||
.foregroundStyle(color)
|
||||
Image(systemName: icon)
|
||||
.font(size < 40 ? .caption : .title3)
|
||||
.frame(width: size, height: size)
|
||||
.background(color.opacity(0.2))
|
||||
.clipShape(Circle())
|
||||
.foregroundStyle(color)
|
||||
.contentShape(Circle())
|
||||
.onTapGesture {
|
||||
action()
|
||||
}
|
||||
.onLongPressGesture(minimumDuration: 0.5) {
|
||||
onLongPress?()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A view that shows the accumulated delta change near a counter button.
|
||||
* Automatically fades out after a delay.
|
||||
*/
|
||||
struct DeltaIndicator: View {
|
||||
let delta: Int
|
||||
let alignment: HorizontalAlignment
|
||||
|
||||
var body: some View {
|
||||
if delta != 0 {
|
||||
Text(delta > 0 ? "+\(delta)" : "\(delta)")
|
||||
.font(.system(size: 16, weight: .bold, design: .rounded))
|
||||
.foregroundStyle(delta > 0 ? .green : .red)
|
||||
.opacity(0.8)
|
||||
.transition(.opacity.combined(with: .scale))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Observable class to manage delta accumulation and fade-out timing.
|
||||
*/
|
||||
class DeltaTracker: ObservableObject {
|
||||
@Published var delta: Int = 0
|
||||
private var resetTimer: Timer?
|
||||
|
||||
func addDelta(_ amount: Int) {
|
||||
delta += amount
|
||||
resetTimer?.invalidate()
|
||||
resetTimer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false) { [weak self] _ in
|
||||
withAnimation(.easeOut(duration: 0.3)) {
|
||||
self?.delta = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func reset() {
|
||||
resetTimer?.invalidate()
|
||||
delta = 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A control for adjusting a large numerical value (like Life).
|
||||
* Shows delta indicators and supports long-press for custom delta input.
|
||||
*/
|
||||
struct LifeCounterControl: View {
|
||||
let value: Int
|
||||
let onDecrease: () -> Void
|
||||
let onIncrease: () -> Void
|
||||
|
||||
var onCustomDelta: ((Int) -> Void)? = nil
|
||||
|
||||
@StateObject private var deltaTracker = DeltaTracker()
|
||||
@State private var showingCustomDeltaAlert = false
|
||||
@State private var customDeltaText = ""
|
||||
@State private var isIncreasing = true
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 16) {
|
||||
CircleButton(icon: "minus", color: .red, action: onDecrease)
|
||||
|
||||
ZStack {
|
||||
CircleButton(
|
||||
icon: "minus",
|
||||
color: .red,
|
||||
action: {
|
||||
onDecrease()
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(-1)
|
||||
}
|
||||
},
|
||||
onLongPress: {
|
||||
isIncreasing = false
|
||||
customDeltaText = ""
|
||||
showingCustomDeltaAlert = true
|
||||
Haptics.play(.medium)
|
||||
}
|
||||
)
|
||||
|
||||
if deltaTracker.delta < 0 {
|
||||
DeltaIndicator(delta: deltaTracker.delta, alignment: .trailing)
|
||||
.offset(y: -35)
|
||||
}
|
||||
}
|
||||
|
||||
Text("\(value)")
|
||||
.font(.system(size: 56, weight: .bold, design: .rounded))
|
||||
.minimumScaleFactor(0.5)
|
||||
.lineLimit(1)
|
||||
.foregroundStyle(.primary)
|
||||
|
||||
CircleButton(icon: "plus", color: .green, action: onIncrease)
|
||||
|
||||
ZStack {
|
||||
CircleButton(
|
||||
icon: "plus",
|
||||
color: .green,
|
||||
action: {
|
||||
onIncrease()
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(1)
|
||||
}
|
||||
},
|
||||
onLongPress: {
|
||||
isIncreasing = true
|
||||
customDeltaText = ""
|
||||
showingCustomDeltaAlert = true
|
||||
Haptics.play(.medium)
|
||||
}
|
||||
)
|
||||
|
||||
if deltaTracker.delta > 0 {
|
||||
DeltaIndicator(delta: deltaTracker.delta, alignment: .leading)
|
||||
.offset(y: -35)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.alert("Enter Amount", isPresented: $showingCustomDeltaAlert) {
|
||||
TextField("Amount", text: $customDeltaText)
|
||||
.keyboardType(.numberPad)
|
||||
Button("Cancel", role: .cancel) { }
|
||||
Button(isIncreasing ? "Add" : "Subtract") {
|
||||
if let amount = Int(customDeltaText), amount > 0 {
|
||||
let delta = isIncreasing ? amount : -amount
|
||||
onCustomDelta?(delta)
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
} message: {
|
||||
Text(isIncreasing ? "Enter the amount to add" : "Enter the amount to subtract")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A smaller control for adjusting secondary values (like Poison).
|
||||
* Shows delta indicators and supports long-press for custom delta input.
|
||||
*/
|
||||
struct SmallCounterControl: View {
|
||||
let value: Int
|
||||
@@ -68,11 +187,41 @@ struct SmallCounterControl: View {
|
||||
let color: Color
|
||||
let onDecrease: () -> Void
|
||||
let onIncrease: () -> Void
|
||||
|
||||
var onCustomDelta: ((Int) -> Void)? = nil
|
||||
|
||||
@StateObject private var deltaTracker = DeltaTracker()
|
||||
@State private var showingCustomDeltaAlert = false
|
||||
@State private var customDeltaText = ""
|
||||
@State private var isIncreasing = true
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 4) {
|
||||
CircleButton(icon: "minus", color: .gray, size: 24, action: onDecrease)
|
||||
|
||||
ZStack {
|
||||
CircleButton(
|
||||
icon: "minus",
|
||||
color: .gray,
|
||||
size: 24,
|
||||
action: {
|
||||
onDecrease()
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(-1)
|
||||
}
|
||||
},
|
||||
onLongPress: {
|
||||
isIncreasing = false
|
||||
customDeltaText = ""
|
||||
showingCustomDeltaAlert = true
|
||||
Haptics.play(.medium)
|
||||
}
|
||||
)
|
||||
|
||||
if deltaTracker.delta < 0 {
|
||||
DeltaIndicator(delta: deltaTracker.delta, alignment: .trailing)
|
||||
.font(.system(size: 12, weight: .bold))
|
||||
.offset(y: -22)
|
||||
}
|
||||
}
|
||||
|
||||
VStack(spacing: 0) {
|
||||
Image(systemName: icon)
|
||||
.font(.caption2)
|
||||
@@ -82,12 +231,52 @@ struct SmallCounterControl: View {
|
||||
.foregroundStyle(color)
|
||||
}
|
||||
.frame(minWidth: 30)
|
||||
|
||||
CircleButton(icon: "plus", color: .gray, size: 24, action: onIncrease)
|
||||
|
||||
ZStack {
|
||||
CircleButton(
|
||||
icon: "plus",
|
||||
color: .gray,
|
||||
size: 24,
|
||||
action: {
|
||||
onIncrease()
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(1)
|
||||
}
|
||||
},
|
||||
onLongPress: {
|
||||
isIncreasing = true
|
||||
customDeltaText = ""
|
||||
showingCustomDeltaAlert = true
|
||||
Haptics.play(.medium)
|
||||
}
|
||||
)
|
||||
|
||||
if deltaTracker.delta > 0 {
|
||||
DeltaIndicator(delta: deltaTracker.delta, alignment: .leading)
|
||||
.font(.system(size: 12, weight: .bold))
|
||||
.offset(y: -22)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(6)
|
||||
.background(color.opacity(0.1))
|
||||
.cornerRadius(12)
|
||||
.alert("Enter Amount", isPresented: $showingCustomDeltaAlert) {
|
||||
TextField("Amount", text: $customDeltaText)
|
||||
.keyboardType(.numberPad)
|
||||
Button("Cancel", role: .cancel) { }
|
||||
Button(isIncreasing ? "Add" : "Subtract") {
|
||||
if let amount = Int(customDeltaText), amount > 0 {
|
||||
let delta = isIncreasing ? amount : -amount
|
||||
onCustomDelta?(delta)
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
} message: {
|
||||
Text(isIncreasing ? "Enter the amount to add" : "Enter the amount to subtract")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +288,7 @@ struct SettingSlider: View {
|
||||
let value: Binding<Double>
|
||||
let range: ClosedRange<Double>
|
||||
let step: Double
|
||||
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
@@ -122,7 +311,7 @@ enum Haptics {
|
||||
let generator = UIImpactFeedbackGenerator(style: style)
|
||||
generator.impactOccurred()
|
||||
}
|
||||
|
||||
|
||||
static func notification(_ type: UINotificationFeedbackGenerator.FeedbackType) {
|
||||
guard UserDefaults.standard.bool(forKey: "hapticFeedbackEnabled") else { return }
|
||||
let generator = UINotificationFeedbackGenerator()
|
||||
|
||||
@@ -22,12 +22,12 @@ struct GameView: View {
|
||||
@State private var draggedPlayer: PlayerState?
|
||||
@State private var elapsedTime: TimeInterval = 0
|
||||
let match: MatchRecord
|
||||
|
||||
|
||||
init(match: MatchRecord) {
|
||||
self.match = match
|
||||
self._gameState = State(initialValue: match.state)
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
GeometryReader { geometry in
|
||||
@@ -41,7 +41,7 @@ struct GameView: View {
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
.foregroundStyle(.white)
|
||||
|
||||
|
||||
if !gameState.stopped && gameState.winner == nil {
|
||||
Text(timeString(from: elapsedTime))
|
||||
.font(.subheadline.bold())
|
||||
@@ -61,12 +61,12 @@ struct GameView: View {
|
||||
.background(.secondary.opacity(0.2))
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 24)
|
||||
.padding(.top, 16)
|
||||
|
||||
|
||||
if gameState.stopped {
|
||||
Text("Game Stopped")
|
||||
.font(.headline)
|
||||
@@ -78,7 +78,7 @@ struct GameView: View {
|
||||
.foregroundStyle(.green)
|
||||
.padding(.horizontal, 24)
|
||||
}
|
||||
|
||||
|
||||
LazyVGrid(columns: columns, spacing: 24) {
|
||||
ForEach(gameState.players) { player in
|
||||
PlayerCell(
|
||||
@@ -87,13 +87,12 @@ struct GameView: View {
|
||||
isWinner: gameState.winner?.id == player.id,
|
||||
onUpdate: updatePlayer,
|
||||
onCommanderTap: { selectedPlayerForCommander = player },
|
||||
onScoop: { scoopPlayer(player) }
|
||||
onScoop: { scoopPlayer(player) },
|
||||
onDragStart: {
|
||||
self.draggedPlayer = player
|
||||
}
|
||||
)
|
||||
.frame(height: 260)
|
||||
.onDrag {
|
||||
self.draggedPlayer = player
|
||||
return NSItemProvider(object: String(player.id) as NSString)
|
||||
}
|
||||
.onDrop(of: [.text], delegate: PlayerDropDelegate(item: player, items: $gameState.players, draggedItem: $draggedPlayer))
|
||||
}
|
||||
}
|
||||
@@ -109,7 +108,7 @@ struct GameView: View {
|
||||
Image(systemName: "xmark")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
if !gameState.stopped && gameState.winner == nil {
|
||||
Button(action: { showingStopConfirmation = true }) {
|
||||
@@ -151,7 +150,7 @@ struct GameView: View {
|
||||
gameManager.updateActiveGame(state: newState)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func updateElapsedTime() {
|
||||
if !gameState.stopped && gameState.winner == nil {
|
||||
elapsedTime = Date().timeIntervalSince(match.startedAt)
|
||||
@@ -159,7 +158,7 @@ struct GameView: View {
|
||||
elapsedTime = match.lastUpdated.timeIntervalSince(match.startedAt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func timeString(from timeInterval: TimeInterval) -> String {
|
||||
let hours = Int(timeInterval) / 3600
|
||||
let minutes = Int(timeInterval) / 60 % 60
|
||||
@@ -170,23 +169,23 @@ struct GameView: View {
|
||||
return String(format: "%02i:%02i", minutes, seconds)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func updatePlayer(player: PlayerState) {
|
||||
if gameState.stopped || gameState.winner != nil { return }
|
||||
|
||||
|
||||
if let index = gameState.players.firstIndex(where: { $0.id == player.id }) {
|
||||
gameState.players[index] = player
|
||||
}
|
||||
|
||||
|
||||
// Update the sheet state if this is the player being edited to ensure the view refreshes
|
||||
if selectedPlayerForCommander?.id == player.id {
|
||||
selectedPlayerForCommander = player
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func scoopPlayer(_ player: PlayerState) {
|
||||
if gameState.stopped || gameState.winner != nil { return }
|
||||
|
||||
|
||||
var newPlayer = player
|
||||
newPlayer.scooped = true
|
||||
updatePlayer(player: newPlayer)
|
||||
@@ -210,9 +209,10 @@ struct PlayerCell: View {
|
||||
let onUpdate: (PlayerState) -> Void
|
||||
let onCommanderTap: () -> Void
|
||||
let onScoop: () -> Void
|
||||
|
||||
var onDragStart: (() -> Void)? = nil
|
||||
|
||||
@State private var showScoopConfirmation = false
|
||||
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 24)
|
||||
@@ -222,35 +222,42 @@ struct PlayerCell: View {
|
||||
RoundedRectangle(cornerRadius: 24)
|
||||
.stroke(isWinner ? Color.green : Color.clear, lineWidth: 3)
|
||||
)
|
||||
|
||||
|
||||
VStack(spacing: 12) {
|
||||
// Header
|
||||
// Header - drag handle area
|
||||
HStack {
|
||||
Text(player.name)
|
||||
.font(.headline)
|
||||
.font(.system(size: 22, weight: .semibold, design: .rounded))
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.8)
|
||||
.minimumScaleFactor(0.7)
|
||||
.foregroundStyle(.primary)
|
||||
.onDrag {
|
||||
onDragStart?()
|
||||
return NSItemProvider(object: String(player.id) as NSString)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
|
||||
Button(action: { showScoopConfirmation = true }) {
|
||||
Image(systemName: "flag.fill")
|
||||
.font(.system(size: 18))
|
||||
.foregroundStyle(.secondary)
|
||||
.padding(4)
|
||||
.padding(8)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.padding(.top, 12)
|
||||
|
||||
|
||||
// Life
|
||||
LifeCounterControl(
|
||||
value: player.life,
|
||||
onDecrease: { adjustLife(by: -1) },
|
||||
onIncrease: { adjustLife(by: 1) }
|
||||
onIncrease: { adjustLife(by: 1) },
|
||||
onCustomDelta: { adjustLife(by: $0) }
|
||||
)
|
||||
|
||||
|
||||
Spacer()
|
||||
|
||||
|
||||
// Counters Row
|
||||
HStack(spacing: 12) {
|
||||
if gameState.trackPoison {
|
||||
@@ -259,10 +266,11 @@ struct PlayerCell: View {
|
||||
icon: "drop.fill",
|
||||
color: .purple,
|
||||
onDecrease: { adjustPoison(by: -1) },
|
||||
onIncrease: { adjustPoison(by: 1) }
|
||||
onIncrease: { adjustPoison(by: 1) },
|
||||
onCustomDelta: { adjustPoison(by: $0) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
if gameState.trackCommanderDamage {
|
||||
Button(action: onCommanderTap) {
|
||||
VStack(spacing: 2) {
|
||||
@@ -280,7 +288,7 @@ struct PlayerCell: View {
|
||||
}
|
||||
.padding(.bottom, 16)
|
||||
}
|
||||
|
||||
|
||||
if player.isEliminated && !isWinner {
|
||||
ZStack {
|
||||
Color.black.opacity(0.6)
|
||||
@@ -304,32 +312,129 @@ struct PlayerCell: View {
|
||||
Text("Are you sure you want to scoop?")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func adjustLife(by amount: Int) {
|
||||
if player.isEliminated { return }
|
||||
Haptics.play(.light)
|
||||
var newPlayer = player
|
||||
newPlayer.life += amount
|
||||
onUpdate(newPlayer)
|
||||
|
||||
|
||||
if newPlayer.isEliminated && !player.isEliminated {
|
||||
Haptics.notification(.error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func adjustPoison(by amount: Int) {
|
||||
if player.isEliminated { return }
|
||||
Haptics.play(.light)
|
||||
var newPlayer = player
|
||||
newPlayer.poison = max(0, newPlayer.poison + amount)
|
||||
onUpdate(newPlayer)
|
||||
|
||||
|
||||
if newPlayer.isEliminated && !player.isEliminated {
|
||||
Haptics.notification(.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A row for managing commander damage from a single attacker.
|
||||
* Shows delta indicators and supports long-press for custom delta input.
|
||||
*/
|
||||
struct CommanderDamageRow: View {
|
||||
let attackerName: String
|
||||
let attackerId: Int
|
||||
let currentDamage: Int
|
||||
let onAdjust: (Int) -> Void
|
||||
|
||||
@StateObject private var deltaTracker = DeltaTracker()
|
||||
@State private var showingCustomDeltaAlert = false
|
||||
@State private var customDeltaText = ""
|
||||
@State private var isIncreasing = true
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text(attackerName)
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
HStack(spacing: 16) {
|
||||
ZStack {
|
||||
CircleButton(
|
||||
icon: "minus",
|
||||
color: .secondary,
|
||||
action: {
|
||||
onAdjust(-1)
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(-1)
|
||||
}
|
||||
},
|
||||
onLongPress: {
|
||||
isIncreasing = false
|
||||
customDeltaText = ""
|
||||
showingCustomDeltaAlert = true
|
||||
Haptics.play(.medium)
|
||||
}
|
||||
)
|
||||
.buttonStyle(.borderless)
|
||||
|
||||
if deltaTracker.delta < 0 {
|
||||
DeltaIndicator(delta: deltaTracker.delta, alignment: .trailing)
|
||||
.offset(y: -30)
|
||||
}
|
||||
}
|
||||
|
||||
Text("\(currentDamage)")
|
||||
.font(.title.bold())
|
||||
.frame(minWidth: 40)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
ZStack {
|
||||
CircleButton(
|
||||
icon: "plus",
|
||||
color: .primary,
|
||||
action: {
|
||||
onAdjust(1)
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(1)
|
||||
}
|
||||
},
|
||||
onLongPress: {
|
||||
isIncreasing = true
|
||||
customDeltaText = ""
|
||||
showingCustomDeltaAlert = true
|
||||
Haptics.play(.medium)
|
||||
}
|
||||
)
|
||||
.buttonStyle(.borderless)
|
||||
|
||||
if deltaTracker.delta > 0 {
|
||||
DeltaIndicator(delta: deltaTracker.delta, alignment: .leading)
|
||||
.offset(y: -30)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
.alert("Enter Amount", isPresented: $showingCustomDeltaAlert) {
|
||||
TextField("Amount", text: $customDeltaText)
|
||||
.keyboardType(.numberPad)
|
||||
Button("Cancel", role: .cancel) { }
|
||||
Button(isIncreasing ? "Add" : "Subtract") {
|
||||
if let amount = Int(customDeltaText), amount > 0 {
|
||||
let delta = isIncreasing ? amount : -amount
|
||||
onAdjust(delta)
|
||||
withAnimation(.easeOut(duration: 0.15)) {
|
||||
deltaTracker.addDelta(delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
} message: {
|
||||
Text(isIncreasing ? "Enter the amount to add" : "Enter the amount to subtract")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sheet for managing commander damage received by a player.
|
||||
*
|
||||
@@ -342,43 +447,25 @@ struct CommanderDamageView: View {
|
||||
let targetPlayer: PlayerState
|
||||
let gameState: GameState
|
||||
let onUpdate: (PlayerState) -> Void
|
||||
|
||||
|
||||
init(targetPlayer: PlayerState, gameState: GameState, onUpdate: @escaping (PlayerState) -> Void) {
|
||||
self.targetPlayer = targetPlayer
|
||||
self.gameState = gameState
|
||||
self.onUpdate = onUpdate
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
ForEach(gameState.players.filter { $0.id != targetPlayer.id }) { attacker in
|
||||
HStack {
|
||||
Text(attacker.name)
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
HStack(spacing: 16) {
|
||||
CircleButton(
|
||||
icon: "minus",
|
||||
color: .secondary,
|
||||
action: { adjustCommanderDamage(attackerId: attacker.id, by: -1) }
|
||||
)
|
||||
.buttonStyle(.borderless)
|
||||
|
||||
Text("\(targetPlayer.commanderDamages[attacker.id] ?? 0)")
|
||||
.font(.title.bold())
|
||||
.frame(minWidth: 40)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
CircleButton(
|
||||
icon: "plus",
|
||||
color: .primary,
|
||||
action: { adjustCommanderDamage(attackerId: attacker.id, by: 1) }
|
||||
)
|
||||
.buttonStyle(.borderless)
|
||||
CommanderDamageRow(
|
||||
attackerName: attacker.name,
|
||||
attackerId: attacker.id,
|
||||
currentDamage: targetPlayer.commanderDamages[attacker.id] ?? 0,
|
||||
onAdjust: { amount in
|
||||
adjustCommanderDamage(attackerId: attacker.id, by: amount)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Commander Damage to \(targetPlayer.name)")
|
||||
@@ -390,30 +477,30 @@ struct CommanderDamageView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func adjustCommanderDamage(attackerId: Int, by amount: Int) {
|
||||
Haptics.play(.light)
|
||||
let wasEliminated = targetPlayer.isEliminated
|
||||
|
||||
|
||||
// Get current damage value
|
||||
let current = targetPlayer.commanderDamages[attackerId] ?? 0
|
||||
let newDamage = max(0, current + amount)
|
||||
|
||||
|
||||
// Only proceed if there's an actual change
|
||||
guard newDamage != current else { return }
|
||||
|
||||
|
||||
// Update commander damages
|
||||
var updatedPlayer = targetPlayer
|
||||
var damages = updatedPlayer.commanderDamages
|
||||
damages[attackerId] = newDamage
|
||||
updatedPlayer.commanderDamages = damages
|
||||
|
||||
|
||||
// Adjust life total by the damage change
|
||||
updatedPlayer.life -= amount
|
||||
|
||||
|
||||
// Notify parent to update
|
||||
onUpdate(updatedPlayer)
|
||||
|
||||
|
||||
if updatedPlayer.isEliminated && !wasEliminated {
|
||||
Haptics.notification(.error)
|
||||
}
|
||||
@@ -441,8 +528,8 @@ struct PlayerDropDelegate: DropDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func dropUpdated(info: DropInfo) -> DropProposal? {
|
||||
return DropProposal(operation: .move)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user