51 lines
1.5 KiB
Swift
51 lines
1.5 KiB
Swift
//
|
|
// Die.swift
|
|
// Bunch O' Dice
|
|
//
|
|
// Created by Rory Hinnen on 22/2/20.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SingleDie: View {
|
|
@EnvironmentObject var current: Roll
|
|
@State var whichDie: Dice.DiceType
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text(String(current.dice.value(which: whichDie)))
|
|
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)
|
|
.background(Color.white)
|
|
}
|
|
}
|
|
.font(.system(size: 45))
|
|
}
|
|
.font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
|
|
.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 Die_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
Die(whichDie: .one)
|
|
.environmentObject(Roll())
|
|
}
|
|
}
|