From 885b0e08f7f19e42d4cf85cbd63fa881b2e0f9ac Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sun, 4 Apr 2021 03:27:00 -0700 Subject: [PATCH] Adds lair actions, regional actions, and reactions to the data model. Renames baseSpeed to walkSpeed. --- .../Models/Monster+CoreDataClass.swift | 4 +- MonsterCards/Models/MonsterViewModel.swift | 38 +++++++++++++++---- MonsterCards/Models/SkillViewModel.swift | 7 ++++ .../MonsterCards.xcdatamodel/contents | 7 +++- MonsterCards/Views/EditMonster.swift | 8 +++- MonsterCards/Views/EditSpeed.swift | 4 +- MonsterCards/Views/MonsterDetail.swift | 6 ++- 7 files changed, 58 insertions(+), 16 deletions(-) diff --git a/MonsterCards/Models/Monster+CoreDataClass.swift b/MonsterCards/Models/Monster+CoreDataClass.swift index 90dffba..21d6c8d 100644 --- a/MonsterCards/Models/Monster+CoreDataClass.swift +++ b/MonsterCards/Models/Monster+CoreDataClass.swift @@ -100,8 +100,8 @@ public class Monster: NSManagedObject { } else { var parts: [String] = [] - if (baseSpeed > 0) { - parts.append("\(baseSpeed) ft.") + if (walkSpeed > 0) { + parts.append("\(walkSpeed) ft.") } if (burrowSpeed > 0) { parts.append("burrow \(burrowSpeed) ft.") diff --git a/MonsterCards/Models/MonsterViewModel.swift b/MonsterCards/Models/MonsterViewModel.swift index 44188ef..a99d3e7 100644 --- a/MonsterCards/Models/MonsterViewModel.swift +++ b/MonsterCards/Models/MonsterViewModel.swift @@ -24,7 +24,7 @@ class MonsterViewModel: ObservableObject { } @Published var naturalArmorBonus: Int64 @Published var customArmor: String - @Published var baseSpeed: Int64 + @Published var walkSpeed: Int64 @Published var burrowSpeed: Int64 @Published var climbSpeed: Int64 @Published var flySpeed: Int64 @@ -65,6 +65,10 @@ class MonsterViewModel: ObservableObject { @Published var abilities: [AbilityViewModel] @Published var actions: [AbilityViewModel] @Published var legendaryActions: [AbilityViewModel] + @Published var lairActions: [AbilityViewModel] + @Published var regionalActions: [AbilityViewModel] + @Published var reactions: [AbilityViewModel] + @Published var isBlind: Bool private var shieldBonus: Int private var otherArmorDescription: String @@ -97,7 +101,7 @@ class MonsterViewModel: ObservableObject { self.hasShield = false self.naturalArmorBonus = 0 self.customArmor = "" - self.baseSpeed = 0 + self.walkSpeed = 0 self.burrowSpeed = 0 self.climbSpeed = 0 self.flySpeed = 0 @@ -138,6 +142,10 @@ class MonsterViewModel: ObservableObject { self.abilities = [] self.actions = [] self.legendaryActions = [] + self.lairActions = [] + self.regionalActions = [] + self.reactions = [] + self.isBlind = false // Private properties self.shieldBonus = 0 @@ -162,7 +170,7 @@ class MonsterViewModel: ObservableObject { self.hasShield = monster.hasShield self.naturalArmorBonus = monster.naturalArmorBonus self.customArmor = monster.customArmor ?? "" - self.baseSpeed = monster.baseSpeed + self.walkSpeed = monster.walkSpeed self.burrowSpeed = monster.burrowSpeed self.climbSpeed = monster.climbSpeed self.flySpeed = monster.flySpeed @@ -193,6 +201,7 @@ class MonsterViewModel: ObservableObject { self.challengeRating = monster.challengeRatingEnum self.customChallengeRating = monster.customChallengeRating ?? "" self.customProficiencyBonus = monster.customProficiencyBonus + self.isBlind = monster.isBlind self.skills = (monster.skills?.allObjects.map {SkillViewModel(($0 as! Skill))})!.sorted() @@ -230,6 +239,15 @@ class MonsterViewModel: ObservableObject { self.legendaryActions = (monster.legendaryActions ?? []) .map {AbilityViewModel($0.name, $0.abilityDescription)} + self.lairActions = (monster.lairActions ?? []) + .map {AbilityViewModel($0.name, $0.abilityDescription)} + + self.regionalActions = (monster.regionalActions ?? []) + .map {AbilityViewModel($0.name, $0.abilityDescription)} + + self.reactions = (monster.reactions ?? []) + .map {AbilityViewModel($0.name, $0.abilityDescription)} + // Private fields self.shieldBonus = Int(monster.shieldBonus) @@ -249,7 +267,7 @@ class MonsterViewModel: ObservableObject { monster.hasShield = hasShield monster.naturalArmorBonus = naturalArmorBonus monster.customArmor = customArmor - monster.baseSpeed = baseSpeed + monster.walkSpeed = walkSpeed monster.burrowSpeed = burrowSpeed monster.climbSpeed = climbSpeed monster.flySpeed = flySpeed @@ -280,6 +298,7 @@ class MonsterViewModel: ObservableObject { monster.challengeRatingEnum = challengeRating monster.customChallengeRating = customChallengeRating monster.customProficiencyBonus = customProficiencyBonus + monster.isBlind = isBlind // Remove missing skills from raw monster monster.skills?.forEach {s in @@ -316,6 +335,12 @@ class MonsterViewModel: ObservableObject { monster.legendaryActions = legendaryActions.map {AbilityViewModel($0.name, $0.abilityDescription)} + monster.lairActions = lairActions.map {AbilityViewModel($0.name, $0.abilityDescription)} + + monster.regionalActions = regionalActions.map {AbilityViewModel($0.name, $0.abilityDescription)} + + monster.reactions = reactions.map {AbilityViewModel($0.name, $0.abilityDescription)} + monster.shieldBonus = Int64(shieldBonus) monster.otherArmorDescription = otherArmorDescription } @@ -382,8 +407,8 @@ class MonsterViewModel: ObservableObject { } else { var parts: [String] = [] - if (baseSpeed > 0) { - parts.append("\(baseSpeed) ft.") + if (walkSpeed > 0) { + parts.append("\(walkSpeed) ft.") } if (burrowSpeed > 0) { parts.append("burrow \(burrowSpeed) ft.") @@ -467,7 +492,6 @@ class MonsterViewModel: ObservableObject { var armorClassDescription: String { get { - let hasShield = shieldBonus != 0 var armorClassTotal = 0 if (armorType == ArmorType.none) { // 10 + dexMod + 2 for shieldBonus "15" or "17 (shield)" diff --git a/MonsterCards/Models/SkillViewModel.swift b/MonsterCards/Models/SkillViewModel.swift index eb32593..557cb2e 100644 --- a/MonsterCards/Models/SkillViewModel.swift +++ b/MonsterCards/Models/SkillViewModel.swift @@ -65,6 +65,13 @@ class SkillViewModel: ObservableObject, Comparable, Hashable, Identifiable { } } + init(_ name: String, _ abilityScore: AbilityScore, _ proficiency: ProficiencyType = .proficient, _ advantage: AdvantageType = .none) { + _name = name + _abilityScore = abilityScore + _proficiency = proficiency + _advantage = advantage + } + private var _name: String = "" var name: String { get { diff --git a/MonsterCards/MonsterCards.xcdatamodeld/MonsterCards.xcdatamodel/contents b/MonsterCards/MonsterCards.xcdatamodeld/MonsterCards.xcdatamodel/contents index 39ff24a..d51cf96 100644 --- a/MonsterCards/MonsterCards.xcdatamodeld/MonsterCards.xcdatamodel/contents +++ b/MonsterCards/MonsterCards.xcdatamodeld/MonsterCards.xcdatamodel/contents @@ -5,7 +5,6 @@ - @@ -39,11 +38,14 @@ + + + @@ -57,6 +59,7 @@ + @@ -70,7 +73,7 @@ - + \ No newline at end of file diff --git a/MonsterCards/Views/EditMonster.swift b/MonsterCards/Views/EditMonster.swift index 4b27545..7a838f5 100644 --- a/MonsterCards/Views/EditMonster.swift +++ b/MonsterCards/Views/EditMonster.swift @@ -9,7 +9,11 @@ import CoreData import SwiftUI struct EditMonster: View { - // TODO: add challengeRating/challengeRatingEnum and customChallengeRating maybe in basicInfo + // TODO: Add challengeRating/challengeRatingEnum and customChallengeRating maybe in basicInfo + // TODO: Add a way to edit the monster being blind. Probably a header section to the senses section. + // TODO: Add a way to edit lair actions + // TODO: Add a way to edit regional actions + // TODO: Add a way to edit reactions @Environment(\.presentationMode) var presentationMode: Binding @Environment(\.managedObjectContext) private var viewContext @@ -141,7 +145,7 @@ struct EditMonster_Previews: PreviewProvider { monster.hitDice = 6 monster.hasCustomHP = true monster.customHP = "12 (1d10)+2" - monster.baseSpeed = 5 + monster.walkSpeed = 5 monster.burrowSpeed = 10 monster.climbSpeed = 15 monster.flySpeed = 20 diff --git a/MonsterCards/Views/EditSpeed.swift b/MonsterCards/Views/EditSpeed.swift index 6c99fb8..e935bd0 100644 --- a/MonsterCards/Views/EditSpeed.swift +++ b/MonsterCards/Views/EditSpeed.swift @@ -12,12 +12,12 @@ struct EditSpeed: View { var body: some View { List { - // Number bound to monster.baseSpeed + // Number bound to monster.walkSpeed MCStepperField( label: "Base", step: 5, suffix: " ft.", - value: $monsterViewModel.baseSpeed) + value: $monsterViewModel.walkSpeed) // Number bound to monster.burrowSpeed MCStepperField( diff --git a/MonsterCards/Views/MonsterDetail.swift b/MonsterCards/Views/MonsterDetail.swift index d3bcc5f..c6ed665 100644 --- a/MonsterCards/Views/MonsterDetail.swift +++ b/MonsterCards/Views/MonsterDetail.swift @@ -293,6 +293,10 @@ struct MonsterDetailView: View { } struct MonsterDetailWrapper: View { + // TODO: Add display for when the monster is blind + // TODO: Add display for lair actions + // TODO: Add display for regional actions + // TODO: Add display for reactions let kTextColor: Color = Color(hex: 0x982818) @ObservedObject var monster: Monster @@ -330,7 +334,7 @@ struct MonsterDetailWrapper_Previews: PreviewProvider { monster.hitDice = 6 monster.hasCustomHP = true monster.customHP = "12 (1d10)+2" - monster.baseSpeed = 5 + monster.walkSpeed = 5 monster.burrowSpeed = 10 monster.climbSpeed = 15 monster.flySpeed = 20