Adds challenge rating and proficiency bonus to the monster editor.

This commit is contained in:
2021-03-25 00:30:58 -07:00
parent 33e2b52dc3
commit 9fd5f55e9d
10 changed files with 304 additions and 79 deletions

View File

@@ -0,0 +1,41 @@
//
// EditChallengeRating.swift
// MonsterCards
//
// Created by Tom Hicks on 3/24/21.
//
import SwiftUI
struct EditChallengeRating: View {
@ObservedObject var viewModel: MonsterViewModel
var body: some View {
let isUsingCustomProficiencyBonus = viewModel.challengeRating == ChallengeRating.custom
VStack(alignment: .leading) {
MCChallengeRatingPicker(
label: "Rating",
value: $viewModel.challengeRating)
MCTextField(
label: "Custom Text",
value: $viewModel.customChallengeRating)
.disabled(!isUsingCustomProficiencyBonus)
MCStepperField(
label: "Custom Proficiency Bonus",
value: $viewModel.customProficiencyBonus)
.disabled(!isUsingCustomProficiencyBonus)
Spacer()
}
.padding()
}
}
struct EditChallengeRating_Previews: PreviewProvider {
static var previews: some View {
let viewModel = MonsterViewModel()
EditChallengeRating(viewModel: viewModel)
}
}

View File

@@ -69,6 +69,10 @@ struct EditMonster: View {
NavigationLink(
"Languages",
destination: EditLanguages(viewModel: monsterViewModel))
NavigationLink(
"Challenge Rating",
destination: EditChallengeRating(viewModel: monsterViewModel))
}
}

View File

@@ -0,0 +1,35 @@
//
// MCChallengeRatingPicker.swift
// MonsterCards
//
// Created by Tom Hicks on 3/24/21.
//
import SwiftUI
struct MCChallengeRatingPicker: View {
var label: String = ""
var value: Binding<ChallengeRating>
var body: some View {
VStack(alignment: .leading) {
Text(label)
.font(.caption2)
Picker(
selection: value,
label: Text(value.wrappedValue.displayName)) {
ForEach(ChallengeRating.allCases) {abilityScore in
Text(abilityScore.displayName).tag(abilityScore)
}
}
.pickerStyle(MenuPickerStyle())
}
}
}
struct MCChallengeRatingPicker_Previews: PreviewProvider {
static var previews: some View {
MCChallengeRatingPicker(
label: "Rating",
value: .constant(ChallengeRating.ten))
}
}

View File

@@ -235,7 +235,7 @@ struct MonsterDetail: View {
// Challenge Rating
if (!monsterChallengeRatingDescription.isEmpty) {
LabeledField("Challenge Rating") {
LabeledField("Challenge") {
Text(monsterChallengeRatingDescription)
}
}