Makes EditMonster use MonsterViewModel instead of binding directly to the Core Data types.
This commit is contained in:
@@ -6,3 +6,209 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import CoreData
|
||||||
|
|
||||||
|
class MonsterViewModel: ObservableObject {
|
||||||
|
|
||||||
|
private var rawMonster: Monster?
|
||||||
|
|
||||||
|
@Published var name: String
|
||||||
|
@Published var size: String
|
||||||
|
@Published var type: String
|
||||||
|
@Published var subType: String
|
||||||
|
@Published var alignment: String
|
||||||
|
@Published var hitDice: Int64
|
||||||
|
@Published var hasCustomHP: Bool
|
||||||
|
@Published var customHP: String
|
||||||
|
@Published var armorType: ArmorType
|
||||||
|
@Published var hasShield: Bool
|
||||||
|
@Published var naturalArmorBonus: Int64
|
||||||
|
@Published var customArmor: String
|
||||||
|
@Published var baseSpeed: Int64
|
||||||
|
@Published var burrowSpeed: Int64
|
||||||
|
@Published var climbSpeed: Int64
|
||||||
|
@Published var flySpeed: Int64
|
||||||
|
@Published var canHover: Bool
|
||||||
|
@Published var swimSpeed: Int64
|
||||||
|
@Published var hasCustomSpeed: Bool
|
||||||
|
@Published var customSpeed: String
|
||||||
|
@Published var strengthScore: Int64
|
||||||
|
@Published var dexterityScore: Int64
|
||||||
|
@Published var constitutionScore: Int64
|
||||||
|
@Published var intelligenceScore: Int64
|
||||||
|
@Published var wisdomScore: Int64
|
||||||
|
@Published var charismaScore: Int64
|
||||||
|
@Published var strengthSavingThrowProficiency: ProficiencyType
|
||||||
|
@Published var strengthSavingThrowAdvantage: AdvantageType
|
||||||
|
@Published var dexteritySavingThrowProficiency: ProficiencyType
|
||||||
|
@Published var dexteritySavingThrowAdvantage: AdvantageType
|
||||||
|
@Published var constitutionSavingThrowProficiency: ProficiencyType
|
||||||
|
@Published var constitutionSavingThrowAdvantage: AdvantageType
|
||||||
|
@Published var intelligenceSavingThrowProficiency: ProficiencyType
|
||||||
|
@Published var intelligenceSavingThrowAdvantage: AdvantageType
|
||||||
|
@Published var wisdomSavingThrowProficiency: ProficiencyType
|
||||||
|
@Published var wisdomSavingThrowAdvantage: AdvantageType
|
||||||
|
@Published var charismaSavingThrowProficiency: ProficiencyType
|
||||||
|
@Published var charismaSavingThrowAdvantage: AdvantageType
|
||||||
|
@Published var skills: [SkillViewModel]
|
||||||
|
|
||||||
|
init(_ rawMonster: Monster?) {
|
||||||
|
self.name = ""
|
||||||
|
self.size = ""
|
||||||
|
self.type = ""
|
||||||
|
self.subType = ""
|
||||||
|
self.alignment = ""
|
||||||
|
self.hitDice = 0
|
||||||
|
self.hasCustomHP = false
|
||||||
|
self.customHP = ""
|
||||||
|
self.armorType = .none
|
||||||
|
self.hasShield = false
|
||||||
|
self.naturalArmorBonus = 0
|
||||||
|
self.customArmor = ""
|
||||||
|
self.baseSpeed = 0
|
||||||
|
self.burrowSpeed = 0
|
||||||
|
self.climbSpeed = 0
|
||||||
|
self.flySpeed = 0
|
||||||
|
self.canHover = false
|
||||||
|
self.swimSpeed = 0
|
||||||
|
self.hasCustomSpeed = false
|
||||||
|
self.customSpeed = ""
|
||||||
|
self.strengthScore = 10
|
||||||
|
self.strengthSavingThrowAdvantage = .none
|
||||||
|
self.strengthSavingThrowProficiency = .none
|
||||||
|
self.dexterityScore = 10
|
||||||
|
self.dexteritySavingThrowAdvantage = .none
|
||||||
|
self.dexteritySavingThrowProficiency = .none
|
||||||
|
self.constitutionScore = 10
|
||||||
|
self.constitutionSavingThrowAdvantage = .none
|
||||||
|
self.constitutionSavingThrowProficiency = .none
|
||||||
|
self.intelligenceScore = 10
|
||||||
|
self.intelligenceSavingThrowAdvantage = .none
|
||||||
|
self.intelligenceSavingThrowProficiency = .none
|
||||||
|
self.wisdomScore = 10
|
||||||
|
self.wisdomSavingThrowAdvantage = .none
|
||||||
|
self.wisdomSavingThrowProficiency = .none
|
||||||
|
self.charismaScore = 10
|
||||||
|
self.charismaSavingThrowAdvantage = .none
|
||||||
|
self.charismaSavingThrowProficiency = .none
|
||||||
|
self.skills = []
|
||||||
|
|
||||||
|
if (rawMonster != nil) {
|
||||||
|
self.rawMonster = rawMonster
|
||||||
|
self.copyFromMonster(monster: rawMonster!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyFromMonster(monster: Monster) {
|
||||||
|
self.name = monster.name ?? ""
|
||||||
|
self.size = monster.size ?? ""
|
||||||
|
self.type = monster.type ?? ""
|
||||||
|
self.subType = monster.subtype ?? ""
|
||||||
|
self.alignment = monster.alignment ?? ""
|
||||||
|
self.hitDice = monster.hitDice
|
||||||
|
self.hasCustomHP = monster.hasCustomHP
|
||||||
|
self.customHP = monster.customHP ?? ""
|
||||||
|
self.armorType = monster.armorTypeEnum
|
||||||
|
self.hasShield = monster.hasShield
|
||||||
|
self.naturalArmorBonus = monster.naturalArmorBonus
|
||||||
|
self.customArmor = monster.customArmor ?? ""
|
||||||
|
self.baseSpeed = monster.baseSpeed
|
||||||
|
self.burrowSpeed = monster.burrowSpeed
|
||||||
|
self.climbSpeed = monster.climbSpeed
|
||||||
|
self.flySpeed = monster.flySpeed
|
||||||
|
self.canHover = monster.canHover
|
||||||
|
self.swimSpeed = monster.swimSpeed
|
||||||
|
self.hasCustomSpeed = monster.hasCustomSpeed
|
||||||
|
self.customSpeed = monster.customSpeed ?? ""
|
||||||
|
self.strengthScore = monster.strengthScore
|
||||||
|
self.strengthSavingThrowAdvantage = monster.strengthSavingThrowAdvantageEnum
|
||||||
|
self.strengthSavingThrowProficiency = monster.strengthSavingThrowProficiencyEnum
|
||||||
|
self.dexterityScore = monster.dexterityScore
|
||||||
|
self.dexteritySavingThrowAdvantage = monster.dexteritySavingThrowAdvantageEnum
|
||||||
|
self.dexteritySavingThrowProficiency = monster.dexteritySavingThrowProficiencyEnum
|
||||||
|
self.constitutionScore = monster.constitutionScore
|
||||||
|
self.constitutionSavingThrowAdvantage = monster.constitutionSavingThrowAdvantageEnum
|
||||||
|
self.constitutionSavingThrowProficiency = monster.constitutionSavingThrowProficiencyEnum
|
||||||
|
self.intelligenceScore = monster.intelligenceScore
|
||||||
|
self.intelligenceSavingThrowAdvantage = monster.intelligenceSavingThrowAdvantageEnum
|
||||||
|
self.intelligenceSavingThrowProficiency = monster.intelligenceSavingThrowProficiencyEnum
|
||||||
|
self.wisdomScore = monster.wisdomScore
|
||||||
|
self.wisdomSavingThrowAdvantage = monster.wisdomSavingThrowAdvantageEnum
|
||||||
|
self.wisdomSavingThrowProficiency = monster.wisdomSavingThrowProficiencyEnum
|
||||||
|
self.charismaScore = monster.charismaScore
|
||||||
|
self.charismaSavingThrowAdvantage = monster.charismaSavingThrowAdvantageEnum
|
||||||
|
self.charismaSavingThrowProficiency = monster.charismaSavingThrowProficiencyEnum
|
||||||
|
self.skills = (monster.skills?.allObjects.map {SkillViewModel(($0 as! Skill))})!
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyToMonster(monster: Monster) {
|
||||||
|
monster.name = name
|
||||||
|
monster.size = size
|
||||||
|
monster.type = type
|
||||||
|
monster.subtype = subType
|
||||||
|
monster.alignment = alignment
|
||||||
|
monster.hitDice = hitDice
|
||||||
|
monster.hasCustomHP = hasCustomHP
|
||||||
|
monster.customHP = customHP
|
||||||
|
monster.armorTypeEnum = armorType
|
||||||
|
monster.hasShield = hasShield
|
||||||
|
monster.naturalArmorBonus = naturalArmorBonus
|
||||||
|
monster.customArmor = customArmor
|
||||||
|
monster.baseSpeed = baseSpeed
|
||||||
|
monster.burrowSpeed = burrowSpeed
|
||||||
|
monster.climbSpeed = climbSpeed
|
||||||
|
monster.flySpeed = flySpeed
|
||||||
|
monster.canHover = canHover
|
||||||
|
monster.swimSpeed = swimSpeed
|
||||||
|
monster.hasCustomSpeed = hasCustomSpeed
|
||||||
|
monster.customSpeed = customSpeed
|
||||||
|
monster.strengthScore = strengthScore
|
||||||
|
monster.strengthSavingThrowAdvantageEnum = strengthSavingThrowAdvantage
|
||||||
|
monster.strengthSavingThrowProficiencyEnum = strengthSavingThrowProficiency
|
||||||
|
monster.dexterityScore = dexterityScore
|
||||||
|
monster.dexteritySavingThrowAdvantageEnum = dexteritySavingThrowAdvantage
|
||||||
|
monster.dexteritySavingThrowProficiencyEnum = dexteritySavingThrowProficiency
|
||||||
|
monster.constitutionScore = constitutionScore
|
||||||
|
monster.constitutionSavingThrowAdvantageEnum = constitutionSavingThrowAdvantage
|
||||||
|
monster.constitutionSavingThrowProficiencyEnum = constitutionSavingThrowProficiency
|
||||||
|
monster.intelligenceScore = intelligenceScore
|
||||||
|
monster.intelligenceSavingThrowAdvantageEnum = intelligenceSavingThrowAdvantage
|
||||||
|
monster.intelligenceSavingThrowProficiencyEnum = intelligenceSavingThrowProficiency
|
||||||
|
monster.wisdomScore = wisdomScore
|
||||||
|
monster.wisdomSavingThrowAdvantageEnum = wisdomSavingThrowAdvantage
|
||||||
|
monster.wisdomSavingThrowProficiencyEnum = wisdomSavingThrowProficiency
|
||||||
|
monster.charismaScore = charismaScore
|
||||||
|
monster.charismaSavingThrowAdvantageEnum = charismaSavingThrowAdvantage
|
||||||
|
monster.charismaSavingThrowProficiencyEnum = charismaSavingThrowProficiency
|
||||||
|
|
||||||
|
// // Remove missing skills from raw monster
|
||||||
|
// monster.skills?.forEach {s in
|
||||||
|
// let skill = s as! Skill
|
||||||
|
// let skillVM = skills.first { $0.isEqualTo(rawSkill: skill) }
|
||||||
|
// if (skillVM != nil) {
|
||||||
|
// skillVM!.copyToSkill(skill: skill)
|
||||||
|
// } else {
|
||||||
|
// monster.removeFromSkills(skill)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // Add new skills to raw monster
|
||||||
|
// skills.forEach {skillVM in
|
||||||
|
// if (!(monster.skills?.contains(
|
||||||
|
// where: {
|
||||||
|
// skillVM.isEqualTo(rawSkill: $0 as? Skill)
|
||||||
|
// }) ?? true)){
|
||||||
|
// monster.addToSkills(skillVM.buildRawSkill(context: monster.managedObjectContext))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyFromRaw() {
|
||||||
|
if (self.rawMonster != nil) {
|
||||||
|
self.copyFromMonster(monster: self.rawMonster!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyToRaw() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,47 +15,7 @@ struct EditMonster: View {
|
|||||||
|
|
||||||
var monster: Monster
|
var monster: Monster
|
||||||
|
|
||||||
@State private var monsterName: String = ""
|
@ObservedObject private var monsterViewModel: MonsterViewModel = MonsterViewModel(nil)
|
||||||
@State private var monsterSize: String = ""
|
|
||||||
@State private var monsterType: String = ""
|
|
||||||
@State private var monsterSubtype: String = ""
|
|
||||||
@State private var monsterAlignment: String = ""
|
|
||||||
@State private var monsterHitDice: Int64 = 0
|
|
||||||
@State private var monsterHasCustomHP: Bool = false
|
|
||||||
@State private var monsterCustomHP: String = ""
|
|
||||||
@State private var monsterArmorType: ArmorType = ArmorType.none
|
|
||||||
@State private var monsterHasShield: Bool = false
|
|
||||||
@State private var monsterNaturalArmorBonus: Int64 = 0
|
|
||||||
@State private var monsterCustomArmor: String = ""
|
|
||||||
@State private var monsterBaseSpeed: Int64 = 0
|
|
||||||
@State private var monsterBurrowSpeed: Int64 = 0
|
|
||||||
@State private var monsterClimbSpeed: Int64 = 0
|
|
||||||
@State private var monsterFlySpeed: Int64 = 0
|
|
||||||
@State private var monsterCanHover: Bool = false
|
|
||||||
@State private var monsterSwimSpeed: Int64 = 0
|
|
||||||
@State private var monsterHasCustomSpeed: Bool = false
|
|
||||||
@State private var monsterCustomSpeed: String = ""
|
|
||||||
@State private var monsterStrengthScore: Int64 = 10
|
|
||||||
@State private var monsterDexterityScore: Int64 = 10
|
|
||||||
@State private var monsterConstitutionScore: Int64 = 10
|
|
||||||
@State private var monsterIntelligenceScore: Int64 = 10
|
|
||||||
@State private var monsterWisdomScore: Int64 = 10
|
|
||||||
@State private var monsterCharismaScore: Int64 = 10
|
|
||||||
|
|
||||||
@State private var monsterStrengthSavingThrowProficiency: ProficiencyType = .none
|
|
||||||
@State private var monsterStrengthSavingThrowAdvantage: AdvantageType = .none
|
|
||||||
@State private var monsterDexteritySavingThrowProficiency: ProficiencyType = .none
|
|
||||||
@State private var monsterDexteritySavingThrowAdvantage: AdvantageType = .none
|
|
||||||
@State private var monsterConstitutionSavingThrowProficiency: ProficiencyType = .none
|
|
||||||
@State private var monsterConstitutionSavingThrowAdvantage: AdvantageType = .none
|
|
||||||
@State private var monsterIntelligenceSavingThrowProficiency: ProficiencyType = .none
|
|
||||||
@State private var monsterIntelligenceSavingThrowAdvantage: AdvantageType = .none
|
|
||||||
@State private var monsterWisdomSavingThrowProficiency: ProficiencyType = .none
|
|
||||||
@State private var monsterWisdomSavingThrowAdvantage: AdvantageType = .none
|
|
||||||
@State private var monsterCharismaSavingThrowProficiency: ProficiencyType = .none
|
|
||||||
@State private var monsterCharismaSavingThrowAdvantage: AdvantageType = .none
|
|
||||||
@State private var monsterSkills: [Skill] = []
|
|
||||||
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
@@ -63,42 +23,42 @@ struct EditMonster: View {
|
|||||||
// Editable Text field bound to monster.name
|
// Editable Text field bound to monster.name
|
||||||
MCTextField(
|
MCTextField(
|
||||||
label: "Name",
|
label: "Name",
|
||||||
value: $monsterName)
|
value: $monsterViewModel.name)
|
||||||
|
|
||||||
// Editable Text field bound to monster.size
|
// Editable Text field bound to monster.size
|
||||||
MCTextField(
|
MCTextField(
|
||||||
label: "Size",
|
label: "Size",
|
||||||
value: $monsterSize)
|
value: $monsterViewModel.size)
|
||||||
|
|
||||||
// Editable Text field bound to monster.type
|
// Editable Text field bound to monster.type
|
||||||
MCTextField(
|
MCTextField(
|
||||||
label: "Type",
|
label: "Type",
|
||||||
value: $monsterType)
|
value: $monsterViewModel.type)
|
||||||
|
|
||||||
// Editable Text field bound to monster.subType
|
// Editable Text field bound to monster.subType
|
||||||
MCTextField(
|
MCTextField(
|
||||||
label: "Subtype",
|
label: "Subtype",
|
||||||
value: $monsterSubtype)
|
value: $monsterViewModel.subType)
|
||||||
|
|
||||||
// Editable Text field bound to monster.alignment
|
// Editable Text field bound to monster.alignment
|
||||||
MCTextField(
|
MCTextField(
|
||||||
label: "Alignment",
|
label: "Alignment",
|
||||||
value: $monsterAlignment)
|
value: $monsterViewModel.alignment)
|
||||||
|
|
||||||
// Number with -/+ buttons bound to monster.hitDice
|
// Number with -/+ buttons bound to monster.hitDice
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "Hit Dice",
|
label: "Hit Dice",
|
||||||
value: $monsterHitDice)
|
value: $monsterViewModel.hitDice)
|
||||||
|
|
||||||
// Toggle bound to monster.hasCustomHP?
|
// Toggle bound to monster.hasCustomHP?
|
||||||
Toggle(
|
Toggle(
|
||||||
"Has Custom HP",
|
"Has Custom HP",
|
||||||
isOn:$monsterHasCustomHP)
|
isOn:$monsterViewModel.hasCustomHP)
|
||||||
|
|
||||||
// Editable Text field bound to monster.customHpText?
|
// Editable Text field bound to monster.customHpText?
|
||||||
MCTextField(
|
MCTextField(
|
||||||
label: "Custom HP",
|
label: "Custom HP",
|
||||||
value: $monsterCustomHP)
|
value: $monsterViewModel.customHP)
|
||||||
|
|
||||||
}
|
}
|
||||||
.textCase(nil)
|
.textCase(nil)
|
||||||
@@ -107,22 +67,22 @@ struct EditMonster: View {
|
|||||||
// Armor Type select bound to monster.armorTypeEnum
|
// Armor Type select bound to monster.armorTypeEnum
|
||||||
MCArmorTypePicker(
|
MCArmorTypePicker(
|
||||||
label: "Armor Type",
|
label: "Armor Type",
|
||||||
value: $monsterArmorType)
|
value: $monsterViewModel.armorType)
|
||||||
|
|
||||||
// Toggle bound to monster.hasShield?
|
// Toggle bound to monster.hasShield?
|
||||||
Toggle(
|
Toggle(
|
||||||
"Has Shield",
|
"Has Shield",
|
||||||
isOn: $monsterHasShield)
|
isOn: $monsterViewModel.hasShield)
|
||||||
|
|
||||||
// Number with -/+ buttons bound to monster.naturalArmorBonus
|
// Number with -/+ buttons bound to monster.naturalArmorBonus
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "Natural Armor Bonus",
|
label: "Natural Armor Bonus",
|
||||||
value: $monsterNaturalArmorBonus)
|
value: $monsterViewModel.naturalArmorBonus)
|
||||||
|
|
||||||
// Editable Text field bound to monster.customArmorText?
|
// Editable Text field bound to monster.customArmorText?
|
||||||
MCTextField(
|
MCTextField(
|
||||||
label: "Custom Armor",
|
label: "Custom Armor",
|
||||||
value: $monsterCustomArmor)
|
value: $monsterViewModel.customArmor)
|
||||||
|
|
||||||
}
|
}
|
||||||
.textCase(nil)
|
.textCase(nil)
|
||||||
@@ -133,72 +93,72 @@ struct EditMonster: View {
|
|||||||
label: "Base",
|
label: "Base",
|
||||||
step: 5,
|
step: 5,
|
||||||
suffix: " ft.",
|
suffix: " ft.",
|
||||||
value: $monsterBaseSpeed)
|
value: $monsterViewModel.baseSpeed)
|
||||||
|
|
||||||
// Number bound to monster.burrowSpeed
|
// Number bound to monster.burrowSpeed
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "Burrow",
|
label: "Burrow",
|
||||||
step: 5,
|
step: 5,
|
||||||
suffix: " ft.",
|
suffix: " ft.",
|
||||||
value: $monsterBurrowSpeed)
|
value: $monsterViewModel.burrowSpeed)
|
||||||
|
|
||||||
// Number bound to monster.climbSpeed
|
// Number bound to monster.climbSpeed
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "Climb",
|
label: "Climb",
|
||||||
step: 5,
|
step: 5,
|
||||||
suffix: " ft.",
|
suffix: " ft.",
|
||||||
value: $monsterClimbSpeed)
|
value: $monsterViewModel.climbSpeed)
|
||||||
|
|
||||||
// Number bound to monster.flySpeed
|
// Number bound to monster.flySpeed
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "Fly",
|
label: "Fly",
|
||||||
step: 5,
|
step: 5,
|
||||||
suffix: " ft.",
|
suffix: " ft.",
|
||||||
value: $monsterFlySpeed)
|
value: $monsterViewModel.flySpeed)
|
||||||
|
|
||||||
// Toggle bound to monster.canHover
|
// Toggle bound to monster.canHover
|
||||||
Toggle(
|
Toggle(
|
||||||
"Can Hover",
|
"Can Hover",
|
||||||
isOn: $monsterCanHover)
|
isOn: $monsterViewModel.canHover)
|
||||||
|
|
||||||
// Number bound to monster.swimSpeed
|
// Number bound to monster.swimSpeed
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "Swim",
|
label: "Swim",
|
||||||
step: 5,
|
step: 5,
|
||||||
suffix: " ft.",
|
suffix: " ft.",
|
||||||
value: $monsterSwimSpeed)
|
value: $monsterViewModel.swimSpeed)
|
||||||
|
|
||||||
// Toggle bound to monster.hasCustomSpeed
|
// Toggle bound to monster.hasCustomSpeed
|
||||||
Toggle(
|
Toggle(
|
||||||
"Has Custom Speed",
|
"Has Custom Speed",
|
||||||
isOn: $monsterHasCustomSpeed)
|
isOn: $monsterViewModel.hasCustomSpeed)
|
||||||
|
|
||||||
// Editable Text field bound to monster.customSpeedText
|
// Editable Text field bound to monster.customSpeedText
|
||||||
MCTextField(
|
MCTextField(
|
||||||
label: "Custom Speed",
|
label: "Custom Speed",
|
||||||
value: $monsterCustomSpeed)
|
value: $monsterViewModel.customSpeed)
|
||||||
}
|
}
|
||||||
.textCase(nil)
|
.textCase(nil)
|
||||||
|
|
||||||
Section(header: Text("Ability Scores")) {
|
Section(header: Text("Ability Scores")) {
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "STR",
|
label: "STR",
|
||||||
value: $monsterStrengthScore)
|
value: $monsterViewModel.strengthScore)
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "DEX",
|
label: "DEX",
|
||||||
value: $monsterDexterityScore)
|
value: $monsterViewModel.dexterityScore)
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "CON",
|
label: "CON",
|
||||||
value: $monsterConstitutionScore)
|
value: $monsterViewModel.constitutionScore)
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "INT",
|
label: "INT",
|
||||||
value: $monsterIntelligenceScore)
|
value: $monsterViewModel.intelligenceScore)
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "WIS",
|
label: "WIS",
|
||||||
value: $monsterWisdomScore)
|
value: $monsterViewModel.wisdomScore)
|
||||||
MCStepperField(
|
MCStepperField(
|
||||||
label: "CHA",
|
label: "CHA",
|
||||||
value: $monsterCharismaScore)
|
value: $monsterViewModel.charismaScore)
|
||||||
}
|
}
|
||||||
.textCase(nil)
|
.textCase(nil)
|
||||||
|
|
||||||
@@ -206,103 +166,60 @@ struct EditMonster: View {
|
|||||||
VStack {
|
VStack {
|
||||||
MCAdvantagePicker(
|
MCAdvantagePicker(
|
||||||
label: "Strength Advantage",
|
label: "Strength Advantage",
|
||||||
value: $monsterStrengthSavingThrowAdvantage)
|
value: $monsterViewModel.strengthSavingThrowAdvantage)
|
||||||
|
|
||||||
MCProficiencyPicker(
|
MCProficiencyPicker(
|
||||||
label: "Strength Proficiency",
|
label: "Strength Proficiency",
|
||||||
value: $monsterStrengthSavingThrowProficiency)
|
value: $monsterViewModel.strengthSavingThrowProficiency)
|
||||||
}
|
}
|
||||||
VStack {
|
VStack {
|
||||||
MCAdvantagePicker(
|
MCAdvantagePicker(
|
||||||
label: "Dexterity Advantage",
|
label: "Dexterity Advantage",
|
||||||
value: $monsterDexteritySavingThrowAdvantage)
|
value: $monsterViewModel.dexteritySavingThrowAdvantage)
|
||||||
|
|
||||||
MCProficiencyPicker(
|
MCProficiencyPicker(
|
||||||
label: "Dexterity Proficiency",
|
label: "Dexterity Proficiency",
|
||||||
value: $monsterDexteritySavingThrowProficiency)
|
value: $monsterViewModel.dexteritySavingThrowProficiency)
|
||||||
}
|
}
|
||||||
VStack {
|
VStack {
|
||||||
MCAdvantagePicker(
|
MCAdvantagePicker(
|
||||||
label: "Constitution Advantage",
|
label: "Constitution Advantage",
|
||||||
value: $monsterConstitutionSavingThrowAdvantage)
|
value: $monsterViewModel.constitutionSavingThrowAdvantage)
|
||||||
|
|
||||||
MCProficiencyPicker(
|
MCProficiencyPicker(
|
||||||
label: "Constitution Proficiency",
|
label: "Constitution Proficiency",
|
||||||
value: $monsterConstitutionSavingThrowProficiency)
|
value: $monsterViewModel.constitutionSavingThrowProficiency)
|
||||||
}
|
}
|
||||||
VStack {
|
VStack {
|
||||||
MCAdvantagePicker(
|
MCAdvantagePicker(
|
||||||
label: "Intelligence Advantage",
|
label: "Intelligence Advantage",
|
||||||
value: $monsterIntelligenceSavingThrowAdvantage)
|
value: $monsterViewModel.intelligenceSavingThrowAdvantage)
|
||||||
|
|
||||||
MCProficiencyPicker(
|
MCProficiencyPicker(
|
||||||
label: "Intelligence Proficiency",
|
label: "Intelligence Proficiency",
|
||||||
value: $monsterIntelligenceSavingThrowProficiency)
|
value: $monsterViewModel.intelligenceSavingThrowProficiency)
|
||||||
}
|
}
|
||||||
VStack {
|
VStack {
|
||||||
MCAdvantagePicker(
|
MCAdvantagePicker(
|
||||||
label: "Wisdom Advantage",
|
label: "Wisdom Advantage",
|
||||||
value: $monsterWisdomSavingThrowAdvantage)
|
value: $monsterViewModel.wisdomSavingThrowAdvantage)
|
||||||
|
|
||||||
MCProficiencyPicker(
|
MCProficiencyPicker(
|
||||||
label: "Wisdom Proficiency",
|
label: "Wisdom Proficiency",
|
||||||
value: $monsterWisdomSavingThrowProficiency)
|
value: $monsterViewModel.wisdomSavingThrowProficiency)
|
||||||
}
|
}
|
||||||
VStack {
|
VStack {
|
||||||
MCAdvantagePicker(
|
MCAdvantagePicker(
|
||||||
label: "Charisma Advantage",
|
label: "Charisma Advantage",
|
||||||
value: $monsterCharismaSavingThrowAdvantage)
|
value: $monsterViewModel.charismaSavingThrowAdvantage)
|
||||||
|
|
||||||
MCProficiencyPicker(
|
MCProficiencyPicker(
|
||||||
label: "Charisma Proficiency",
|
label: "Charisma Proficiency",
|
||||||
value: $monsterCharismaSavingThrowProficiency)
|
value: $monsterViewModel.charismaSavingThrowProficiency)
|
||||||
}
|
|
||||||
}
|
|
||||||
.textCase(nil)
|
|
||||||
Section(header: HStack {
|
|
||||||
Text("Skills")
|
|
||||||
Spacer()
|
|
||||||
Button(action: addSkill) {
|
|
||||||
Image(systemName:"plus")
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
VStack {
|
|
||||||
// ForEach((1...10).reversed(), id: \.self) {
|
|
||||||
// Text("\($0)…")
|
|
||||||
// }
|
|
||||||
// List(monster.skillsArray) {_ in
|
|
||||||
// Text ("Name")
|
|
||||||
// }
|
|
||||||
ForEach(monsterSkills, id: \.self) { skill in
|
|
||||||
VStack {
|
|
||||||
Text("---")
|
|
||||||
Text(skill.wrappedName)
|
|
||||||
Text(skill.wrappedProficiency.displayName)
|
|
||||||
Text(skill.wrappedAbilityScore.displayName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.textCase(nil)
|
.textCase(nil)
|
||||||
|
|
||||||
// Section(header: HStack {
|
|
||||||
// Text("Skills")
|
|
||||||
// Spacer()
|
|
||||||
// Button(action: addSkill) {
|
|
||||||
// Image(systemName:"plus")
|
|
||||||
// }
|
|
||||||
// }) {
|
|
||||||
// VStack {
|
|
||||||
//// let skills2: [Skill] = monster.skills?.allObjects)
|
|
||||||
// ForEach(monster.allSkills)) { skill in
|
|
||||||
// Text("A SKill")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//// ForEach(arrayLiteral: Array(monster.skills)) { skill in
|
|
||||||
//// Text("A Skill")
|
|
||||||
//// }
|
|
||||||
// }
|
|
||||||
// .textCase(nil)
|
|
||||||
}
|
}
|
||||||
.onAppear(perform: copyMonsterToLocal)
|
.onAppear(perform: copyMonsterToLocal)
|
||||||
.toolbar(content: {
|
.toolbar(content: {
|
||||||
@@ -320,25 +237,18 @@ struct EditMonster: View {
|
|||||||
|
|
||||||
private func addSkill() {
|
private func addSkill() {
|
||||||
print("Add Skill pressed")
|
print("Add Skill pressed")
|
||||||
|
|
||||||
let newSkill = Skill.init(context: viewContext)
|
|
||||||
newSkill.name = "Acrobatics"
|
|
||||||
newSkill.wrappedAbilityScore = .dexterity
|
|
||||||
newSkill.wrappedProficiency = .proficient
|
|
||||||
monster.addToSkills(newSkill);
|
|
||||||
// newSkill.monster = monster
|
|
||||||
// monster.addSkill(newSkill)
|
|
||||||
// (monster.skills as! NSMutableSet).add(newSkill)
|
|
||||||
// var s1: NSMutableSet = ["A", "S", "D", "F"]
|
|
||||||
// var s2: Set = ["A", "S", "D", "F"]
|
|
||||||
// s1.add
|
|
||||||
//
|
//
|
||||||
do {
|
// let newSkill = Skill.init(context: viewContext)
|
||||||
try viewContext.save()
|
// newSkill.name = "Acrobatics"
|
||||||
monsterSkills = monster.skillsArray
|
// newSkill.wrappedAbilityScore = .dexterity
|
||||||
} catch {
|
// newSkill.wrappedProficiency = .proficient
|
||||||
print("error")
|
// monster.addToSkills(newSkill);
|
||||||
}
|
// do {
|
||||||
|
// try viewContext.save()
|
||||||
|
// monsterSkills = monster.skillsArray
|
||||||
|
// } catch {
|
||||||
|
// print("error")
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private func dismissView() {
|
private func dismissView() {
|
||||||
@@ -365,96 +275,11 @@ struct EditMonster: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func copyMonsterToLocal() {
|
private func copyMonsterToLocal() {
|
||||||
monsterName = monster.name ?? ""
|
monsterViewModel.copyFromMonster(monster: monster)
|
||||||
monsterSize = monster.size ?? ""
|
|
||||||
monsterType = monster.type ?? ""
|
|
||||||
monsterSubtype = monster.subtype ?? ""
|
|
||||||
monsterAlignment = monster.alignment ?? ""
|
|
||||||
monsterHitDice = monster.hitDice
|
|
||||||
monsterHasCustomHP = monster.hasCustomHP
|
|
||||||
monsterCustomHP = monster.customHP ?? ""
|
|
||||||
monsterArmorType = monster.armorTypeEnum
|
|
||||||
monsterHasShield = monster.hasShield
|
|
||||||
monsterNaturalArmorBonus = monster.naturalArmorBonus
|
|
||||||
monsterCustomArmor = monster.customArmor ?? ""
|
|
||||||
monsterBaseSpeed = monster.baseSpeed
|
|
||||||
monsterBurrowSpeed = monster.burrowSpeed
|
|
||||||
monsterClimbSpeed = monster.climbSpeed
|
|
||||||
monsterFlySpeed = monster.flySpeed
|
|
||||||
monsterCanHover = monster.canHover
|
|
||||||
monsterSwimSpeed = monster.swimSpeed
|
|
||||||
monsterHasCustomSpeed = monster.hasCustomSpeed
|
|
||||||
monsterCustomSpeed = monster.customSpeed ?? ""
|
|
||||||
monsterStrengthScore = monster.strengthScore
|
|
||||||
monsterDexterityScore = monster.dexterityScore
|
|
||||||
monsterConstitutionScore = monster.constitutionScore
|
|
||||||
monsterIntelligenceScore = monster.intelligenceScore
|
|
||||||
monsterWisdomScore = monster.wisdomScore
|
|
||||||
monsterCharismaScore = monster.charismaScore
|
|
||||||
monsterStrengthSavingThrowProficiency = monster.strengthSavingThrowProficiencyEnum
|
|
||||||
monsterStrengthSavingThrowAdvantage = monster.strengthSavingThrowAdvantageEnum
|
|
||||||
monsterDexteritySavingThrowProficiency = monster.dexteritySavingThrowProficiencyEnum
|
|
||||||
monsterDexteritySavingThrowAdvantage = monster.dexteritySavingThrowAdvantageEnum
|
|
||||||
monsterConstitutionSavingThrowProficiency = monster.constitutionSavingThrowProficiencyEnum
|
|
||||||
monsterConstitutionSavingThrowAdvantage = monster.constitutionSavingThrowAdvantageEnum
|
|
||||||
monsterIntelligenceSavingThrowProficiency = monster.intelligenceSavingThrowProficiencyEnum
|
|
||||||
monsterIntelligenceSavingThrowAdvantage = monster.intelligenceSavingThrowAdvantageEnum
|
|
||||||
monsterWisdomSavingThrowProficiency = monster.wisdomSavingThrowProficiencyEnum
|
|
||||||
monsterWisdomSavingThrowAdvantage = monster.wisdomSavingThrowAdvantageEnum
|
|
||||||
monsterCharismaSavingThrowProficiency = monster.charismaSavingThrowProficiencyEnum
|
|
||||||
monsterCharismaSavingThrowAdvantage = monster.charismaSavingThrowAdvantageEnum
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func copyLocalToMonster() {
|
private func copyLocalToMonster() {
|
||||||
monster.name = monsterName
|
monsterViewModel.copyToMonster(monster: monster)
|
||||||
monster.size = monsterSize
|
|
||||||
monster.type = monsterType
|
|
||||||
monster.subtype = monsterSubtype
|
|
||||||
monster.alignment = monsterAlignment
|
|
||||||
monster.hitDice = monsterHitDice
|
|
||||||
monster.hasCustomHP = monsterHasCustomHP
|
|
||||||
monster.customHP = monsterCustomHP
|
|
||||||
monster.armorType = monsterArmorType.rawValue
|
|
||||||
monster.hasShield = monsterHasShield
|
|
||||||
monster.naturalArmorBonus = monsterNaturalArmorBonus
|
|
||||||
monster.customArmor = monsterCustomArmor
|
|
||||||
monster.baseSpeed = monsterBaseSpeed
|
|
||||||
monster.burrowSpeed = monsterBurrowSpeed
|
|
||||||
monster.climbSpeed = monsterClimbSpeed
|
|
||||||
monster.flySpeed = monsterFlySpeed
|
|
||||||
monster.canHover = monsterCanHover
|
|
||||||
monster.swimSpeed = monsterSwimSpeed
|
|
||||||
monster.hasCustomSpeed = monsterHasCustomSpeed
|
|
||||||
monster.customSpeed = monsterCustomSpeed
|
|
||||||
monster.strengthScore = monsterStrengthScore
|
|
||||||
monster.dexterityScore = monsterDexterityScore
|
|
||||||
monster.constitutionScore = monsterConstitutionScore
|
|
||||||
monster.intelligenceScore = monsterIntelligenceScore
|
|
||||||
monster.wisdomScore = monsterWisdomScore
|
|
||||||
monster.charismaScore = monsterCharismaScore
|
|
||||||
monster.strengthSavingThrowProficiencyEnum = monsterStrengthSavingThrowProficiency
|
|
||||||
monster.strengthSavingThrowAdvantageEnum = monsterStrengthSavingThrowAdvantage
|
|
||||||
monster.dexteritySavingThrowProficiencyEnum = monsterDexteritySavingThrowProficiency
|
|
||||||
monster.dexteritySavingThrowAdvantageEnum = monsterDexteritySavingThrowAdvantage
|
|
||||||
monster.constitutionSavingThrowProficiencyEnum = monsterConstitutionSavingThrowProficiency
|
|
||||||
monster.constitutionSavingThrowAdvantageEnum = monsterConstitutionSavingThrowAdvantage
|
|
||||||
monster.intelligenceSavingThrowProficiencyEnum = monsterIntelligenceSavingThrowProficiency
|
|
||||||
monster.intelligenceSavingThrowAdvantageEnum = monsterIntelligenceSavingThrowAdvantage
|
|
||||||
monster.wisdomSavingThrowProficiencyEnum = monsterWisdomSavingThrowProficiency
|
|
||||||
monster.wisdomSavingThrowAdvantageEnum = monsterWisdomSavingThrowAdvantage
|
|
||||||
monster.charismaSavingThrowProficiencyEnum = monsterCharismaSavingThrowProficiency
|
|
||||||
monster.charismaSavingThrowAdvantageEnum = monsterCharismaSavingThrowAdvantage
|
|
||||||
monster.skills?.forEach { s in
|
|
||||||
let skill = s as! Skill
|
|
||||||
if (!monsterSkills.contains(skill)) {
|
|
||||||
monster.removeFromSkills(skill)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
monster.skillsArray.forEach { skill in
|
|
||||||
if (!(monster.skills?.contains(skill) ?? false)) {
|
|
||||||
monster.addToSkills(skill)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user