Files
diehammer/Bunch-O--Dice/Views/PortraitVariants/DieHorizontal.swift
T

55 lines
1.6 KiB
Swift

//
// DieHorizontal.swift
// Bunch O' Dice
//
// Created by Rory Hinnen on 22/6/12.
//
import SwiftUI
struct DieHorizontal: View {
@EnvironmentObject var current: Roll
@State var whichDie: Dice.DiceType
var body: some View {
HStack {
Text(String(current.dice.value(which: whichDie)))
.offset(x: 0.0, y: 2.0)
Group {
if (current.state != .armour) && (whichDie.rawValue >= current.cutoff.rawValue) {
Text(whichDie.print())
.foregroundColor(Color.red)
} else if (current.state == .armour) && (whichDie.rawValue < current.cutoff.rawValue) {
Text(whichDie.print())
.foregroundColor(Color.red)
} else {
Text(whichDie.print())
.foregroundColor(Color.black)
}
}
.font(.system(size: 40))
}
.font(.system(size: 25))
.padding(.horizontal, 5.0)
.gesture(TapGesture().onEnded {
if current.state == .hit {
current.hitCutoff = whichDie
}
else if current.state == .armour {
current.armourSave = Int(whichDie.rawValue)
}
})
}
}
struct DieHorizontal_Previews: PreviewProvider {
static var previews: some View {
VStack {
DieHorizontal(whichDie: .four).environmentObject(Roll())
DieHorizontal(whichDie: .three).environmentObject(Roll())
}
}
//.environmentObject(Roll())
}