refactor into smaller units
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// HitCalculatorView.swift
|
||||
// Bunch O' Dice
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct HitCalculatorView: View {
|
||||
@EnvironmentObject var current: Roll
|
||||
private let controlSize = 30.0
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack(alignment: .top) {
|
||||
Spacer()
|
||||
StatStepper(
|
||||
top: "Hit",
|
||||
value: (current.modifier.rawValue > 0 ? "+" : "") + String(current.modifier.rawValue),
|
||||
bottom: "Modifier",
|
||||
increment: { current.modifier = current.modifier.add() },
|
||||
decrement: { current.modifier = current.modifier.remove() }
|
||||
)
|
||||
.disabledWithOpacity(current.torrent || current.psychic)
|
||||
Spacer()
|
||||
VStack {
|
||||
Text("Blow Up")
|
||||
VStack {
|
||||
Button(action: { current.applyBlowup(face: .six) }) {
|
||||
Image(systemName: "die.face.6")
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
Button(action: { current.applyBlowup(face: .five) }) {
|
||||
Image(systemName: "die.face.5")
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.font(.system(size: controlSize))
|
||||
}
|
||||
.disabledWithOpacity(current.blowupUsed || current.torrent)
|
||||
Spacer()
|
||||
}
|
||||
RerollPickerView(mode: $current.hitRerollMode)
|
||||
.disabledWithOpacity(current.torrent)
|
||||
HStack(spacing: 6) {
|
||||
ToggleChip(label: "Torrent", isOn: $current.torrent)
|
||||
ToggleChip(label: "Psychic", isOn: $current.psychic)
|
||||
.disabledWithOpacity(current.torrent)
|
||||
ToggleChip(label: "Lethal Hits", isOn: $current.lethalHits)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
VStack(spacing: 8) {
|
||||
HStack {
|
||||
ToggleChip(label: "Sust. Hits", isOn: $current.sustainedHits)
|
||||
Spacer()
|
||||
if current.sustainedHits {
|
||||
Text("X:")
|
||||
Text("▲")
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.sustainedHitsX < 6 { current.sustainedHitsX += 1 }
|
||||
})
|
||||
Text(String(current.sustainedHitsX))
|
||||
.frame(minWidth: 30, alignment: .center)
|
||||
Text("▼")
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.sustainedHitsX > 1 { current.sustainedHitsX -= 1 }
|
||||
})
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
ToggleChip(label: "Anti-X", isOn: $current.antiX)
|
||||
Spacer()
|
||||
if current.antiX {
|
||||
Text("▲")
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.antiXThreshold < 6 { current.antiXThreshold += 1 }
|
||||
})
|
||||
Text("\(current.antiXThreshold)+")
|
||||
.frame(minWidth: 34, alignment: .center)
|
||||
Text("▼")
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.antiXThreshold > 2 { current.antiXThreshold -= 1 }
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
.font(.system(size: 18))
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
HitCalculatorView()
|
||||
.environmentObject(Roll())
|
||||
}
|
||||
Reference in New Issue
Block a user