Refactors DamageTypes to String since we using it as a generic list of strings editor.
This commit is contained in:
@@ -49,10 +49,10 @@ class MonsterViewModel: ObservableObject {
|
||||
@Published var charismaSavingThrowProficiency: ProficiencyType
|
||||
@Published var charismaSavingThrowAdvantage: AdvantageType
|
||||
@Published var skills: [SkillViewModel]
|
||||
@Published var damageImmunities: [DamageTypeViewModel]
|
||||
@Published var damageResistances: [DamageTypeViewModel]
|
||||
@Published var damageVulnerabilities: [DamageTypeViewModel]
|
||||
@Published var conditionImmunities: [DamageTypeViewModel]
|
||||
@Published var damageImmunities: [StringViewModel]
|
||||
@Published var damageResistances: [StringViewModel]
|
||||
@Published var damageVulnerabilities: [StringViewModel]
|
||||
@Published var conditionImmunities: [StringViewModel]
|
||||
|
||||
init(_ rawMonster: Monster? = nil) {
|
||||
self.name = ""
|
||||
@@ -146,19 +146,19 @@ class MonsterViewModel: ObservableObject {
|
||||
self.skills = (monster.skills?.allObjects.map {SkillViewModel(($0 as! Skill))})!.sorted()
|
||||
|
||||
self.damageImmunities = (monster.damageImmunities ?? [])
|
||||
.map {DamageTypeViewModel($0)}
|
||||
.map {StringViewModel($0)}
|
||||
.sorted()
|
||||
|
||||
self.damageResistances = (monster.damageResistances ?? [])
|
||||
.map {DamageTypeViewModel($0)}
|
||||
.map {StringViewModel($0)}
|
||||
.sorted()
|
||||
|
||||
self.damageVulnerabilities = (monster.damageVulnerabilities ?? [])
|
||||
.map {DamageTypeViewModel($0)}
|
||||
.map {StringViewModel($0)}
|
||||
.sorted()
|
||||
|
||||
self.conditionImmunities = (monster.conditionImmunities ?? [])
|
||||
.map {DamageTypeViewModel($0)}
|
||||
.map {StringViewModel($0)}
|
||||
.sorted()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class DamageTypeViewModel: ObservableObject, Comparable, Identifiable {
|
||||
static func < (lhs: DamageTypeViewModel, rhs: DamageTypeViewModel) -> Bool {
|
||||
class StringViewModel: ObservableObject, Comparable, Identifiable {
|
||||
static func < (lhs: StringViewModel, rhs: StringViewModel) -> Bool {
|
||||
lhs.name < rhs.name
|
||||
}
|
||||
|
||||
static func == (lhs: DamageTypeViewModel, rhs: DamageTypeViewModel) -> Bool {
|
||||
static func == (lhs: StringViewModel, rhs: StringViewModel) -> Bool {
|
||||
lhs.name == rhs.name
|
||||
}
|
||||
|
||||
@@ -46,19 +46,19 @@ struct EditMonster: View {
|
||||
|
||||
NavigationLink(
|
||||
"Condition Immunities",
|
||||
destination: EditDamageTypes(viewModel: monsterViewModel, path: \.conditionImmunities, title: "Condition Immunities"))
|
||||
destination: EditStrings(viewModel: monsterViewModel, path: \.conditionImmunities, title: "Condition Immunities"))
|
||||
|
||||
NavigationLink(
|
||||
"Damage Immunities",
|
||||
destination: EditDamageTypes(viewModel: monsterViewModel, path: \.damageImmunities, title: "Damage Immunities"))
|
||||
destination: EditStrings(viewModel: monsterViewModel, path: \.damageImmunities, title: "Damage Immunities"))
|
||||
|
||||
NavigationLink(
|
||||
"Damage Resistances",
|
||||
destination: EditDamageTypes(viewModel: monsterViewModel, path: \.damageResistances, title: "Damage Resistances"))
|
||||
destination: EditStrings(viewModel: monsterViewModel, path: \.damageResistances, title: "Damage Resistances"))
|
||||
|
||||
NavigationLink(
|
||||
"Damage Vulnerabilities",
|
||||
destination: EditDamageTypes(viewModel: monsterViewModel, path: \.damageVulnerabilities, title: "Damage Vulnerabilities"))
|
||||
destination: EditStrings(viewModel: monsterViewModel, path: \.damageVulnerabilities, title: "Damage Vulnerabilities"))
|
||||
}
|
||||
.onAppear(perform: copyMonsterToLocal)
|
||||
.toolbar(content: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// EditDamageTypes.swift
|
||||
// EditStrings.swift
|
||||
// MonsterCards
|
||||
//
|
||||
// Created by Tom Hicks on 3/22/21.
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EditDamageTypes: View {
|
||||
struct EditStrings: View {
|
||||
@ObservedObject var viewModel: MonsterViewModel
|
||||
var path: ReferenceWritableKeyPath<MonsterViewModel, [DamageTypeViewModel]>
|
||||
var path: ReferenceWritableKeyPath<MonsterViewModel, [StringViewModel]>
|
||||
var title: String
|
||||
|
||||
var body: some View {
|
||||
@@ -33,7 +33,7 @@ struct EditDamageTypes: View {
|
||||
.toolbar(content: {
|
||||
Button(
|
||||
action: {
|
||||
let newDamageType = DamageTypeViewModel()
|
||||
let newDamageType = StringViewModel()
|
||||
viewModel[keyPath: path].append(newDamageType)
|
||||
viewModel[keyPath: path] = viewModel[keyPath: path].sorted()
|
||||
},
|
||||
@@ -48,9 +48,9 @@ struct EditDamageTypes: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct EditDamageTypes_Previews: PreviewProvider {
|
||||
struct EditStrings_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let viewModel = MonsterViewModel()
|
||||
EditDamageTypes(viewModel: viewModel, path: \.damageImmunities, title: "Damage Types")
|
||||
EditStrings(viewModel: viewModel, path: \.damageImmunities, title: "Damage Types")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user