// // DiePoolView.swift // Bunch O' Dice // import SwiftUI struct DiePoolView: View { var body: some View { HStack(spacing: 0) { ForEach(Dice.DiceType.allCases, id: \.rawValue) { i in DieView(whichDie: i) } } } } private struct DieView: View { let whichDie: Dice.DiceType @EnvironmentObject var current: Roll @Environment(\.dieColorSelected) var colorSelected @Environment(\.dieColorPrimary) var colorPrimary 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 { DiePoolView() .environmentObject(Roll()) }