// // DieView.swift // Bunch O' Dice // import SwiftUI struct DieView: View { let whichDie: Dice.DiceType @EnvironmentObject var current: Roll var colorSelected: Color = Color.green.opacity(0.75) var colorPrimary: Color = Color.yellow var body: some View { let size = 42.0 let displayColorHit = (whichDie.rawValue >= current.cutoff.rawValue) ? colorSelected : colorPrimary let displayColorArmor = (whichDie.rawValue <= current.cutoff.rawValue) ? colorSelected : colorPrimary let displayColorArmorText = (whichDie.rawValue < current.cutoff.rawValue) ? colorSelected : colorPrimary VStack(spacing: 2) { Text(String(current.dice.value(which: whichDie))) .foregroundColor(current.state == .armour ? displayColorArmorText : displayColorHit) .frame(minWidth: 30, alignment: .center) Image(systemName: "die.face." + String(whichDie.rawValue) + ".fill") .foregroundColor(current.state == .armour ? displayColorArmor : displayColorHit) } .font(.system(size: size)) .padding(4) .frame(maxWidth: .infinity) .gesture(TapGesture().onEnded { if current.state == .hit { if whichDie.rawValue != 1 { current.hitCutoff = whichDie } } else if current.state == .armour { current.armourSave = Int(whichDie.rawValue) } }) } } #Preview { DieView(whichDie: .four) .environmentObject(Roll()) }