Adds MarkdownUI dependency and abilities.
This commit is contained in:
64
iOS/MonsterCards/Views/EditAbilities.swift
Normal file
64
iOS/MonsterCards/Views/EditAbilities.swift
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// EditAbilities.swift
|
||||
// MonsterCards
|
||||
//
|
||||
// Created by Tom Hicks on 3/25/21.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EditAbilities: View {
|
||||
@ObservedObject var viewModel: MonsterViewModel
|
||||
var path: ReferenceWritableKeyPath<MonsterViewModel, [AbilityViewModel]>
|
||||
var title: String
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
ForEach(viewModel[keyPath: path]) { ability in
|
||||
NavigationLink(
|
||||
ability.name,
|
||||
destination: EditAbility(viewModel: ability))
|
||||
}
|
||||
.onDelete(perform: { indexSet in
|
||||
for index in indexSet {
|
||||
viewModel[keyPath: path].remove(at: index)
|
||||
}
|
||||
})
|
||||
.onMove(perform: { indices, newOffset in
|
||||
viewModel[keyPath: path].move(fromOffsets: indices, toOffset: newOffset)
|
||||
|
||||
})
|
||||
}
|
||||
.toolbar(content: {
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
EditButton()
|
||||
|
||||
Button(
|
||||
action: {
|
||||
let newAbility = AbilityViewModel()
|
||||
viewModel[keyPath: path].append(newAbility)
|
||||
viewModel[keyPath: path] = viewModel[keyPath: path].sorted()
|
||||
},
|
||||
label: {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
.onAppear(perform: {
|
||||
viewModel[keyPath: path] = viewModel[keyPath: path].sorted()
|
||||
})
|
||||
.navigationTitle(title)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct EditAbilities_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let viewModel = MonsterViewModel()
|
||||
EditAbilities(
|
||||
viewModel: viewModel,
|
||||
path: \.abilities,
|
||||
title: "Abilities")
|
||||
}
|
||||
}
|
||||
29
iOS/MonsterCards/Views/EditAbility.swift
Normal file
29
iOS/MonsterCards/Views/EditAbility.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// EditAbility.swift
|
||||
// MonsterCards
|
||||
//
|
||||
// Created by Tom Hicks on 3/25/21.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EditAbility: View {
|
||||
@ObservedObject var viewModel: AbilityViewModel
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
MCTextField(
|
||||
label: "Name",
|
||||
value: $viewModel.name)
|
||||
|
||||
TextEditor(text: $viewModel.abilityDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct EditAbility_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let viewModel = AbilityViewModel()
|
||||
EditAbility(viewModel: viewModel)
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,9 @@ struct EditMonster: View {
|
||||
NavigationLink(
|
||||
"Challenge Rating",
|
||||
destination: EditChallengeRating(viewModel: monsterViewModel))
|
||||
|
||||
NavigationLink(
|
||||
"Abilities", destination: EditAbilities(viewModel: monsterViewModel, path: \.abilities, title: "Abilities"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ struct EditStrings: View {
|
||||
.toolbar(content: {
|
||||
Button(
|
||||
action: {
|
||||
let newDamageType = StringViewModel()
|
||||
viewModel[keyPath: path].append(newDamageType)
|
||||
let newString = StringViewModel()
|
||||
viewModel[keyPath: path].append(newString)
|
||||
viewModel[keyPath: path] = viewModel[keyPath: path].sorted()
|
||||
},
|
||||
label: {
|
||||
@@ -44,13 +44,17 @@ struct EditStrings: View {
|
||||
})
|
||||
.onAppear(perform: {
|
||||
viewModel[keyPath: path] = viewModel[keyPath: path].sorted()
|
||||
}).navigationTitle(title)
|
||||
})
|
||||
.navigationTitle(title)
|
||||
}
|
||||
}
|
||||
|
||||
struct EditStrings_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let viewModel = MonsterViewModel()
|
||||
EditStrings(viewModel: viewModel, path: \.damageImmunities, title: "Damage Types")
|
||||
EditStrings(
|
||||
viewModel: viewModel,
|
||||
path: \.damageImmunities,
|
||||
title: "Damage Types")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import MarkdownUI
|
||||
|
||||
struct LabeledField<Content: View>: View {
|
||||
@Environment(\.horizontalSizeClass) var sizeClass
|
||||
@@ -209,6 +210,7 @@ struct MonsterDetail: View {
|
||||
VStack (alignment: .leading) {
|
||||
let monsterLanguagesDescription = monster.languagesDescription
|
||||
let monsterChallengeRatingDescription = monster.challengeRatingDescription
|
||||
let monsterAbilities: [AbilityViewModel] = monster.abilities ?? []
|
||||
|
||||
BasicInfoView(monster: monster)
|
||||
|
||||
@@ -243,7 +245,15 @@ struct MonsterDetail: View {
|
||||
}
|
||||
|
||||
// Abilities
|
||||
|
||||
if (monsterAbilities.count > 0) {
|
||||
ForEach(monsterAbilities) { ability in
|
||||
VStack {
|
||||
Markdown(Document(ability.renderedText(monster)/*.fullText*/))
|
||||
Divider()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
// Legendary Actions
|
||||
|
||||
Reference in New Issue
Block a user