From 57bf1f2e3aedea0d119916695cd960ccf6e60266 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sat, 26 Sep 2020 17:12:35 -0700 Subject: [PATCH] Renames armorName to armorType. Sets default values for core data fields. Moves hit dice and hp related fields into the basic info section of the editor. --- iOS/MonsterCards.xcodeproj/project.pbxproj | 2 +- iOS/MonsterCards/Models/Monster.m | 38 ++++---- .../MonsterCards.xcdatamodel/contents | 47 +++++----- .../Views/EditMonsterViewController.m | 91 +++++++++++-------- iOS/MonsterCardsTests/Models/MonsterTests.m | 14 +-- 5 files changed, 107 insertions(+), 85 deletions(-) diff --git a/iOS/MonsterCards.xcodeproj/project.pbxproj b/iOS/MonsterCards.xcodeproj/project.pbxproj index 3a2a671..13c13ae 100644 --- a/iOS/MonsterCards.xcodeproj/project.pbxproj +++ b/iOS/MonsterCards.xcodeproj/project.pbxproj @@ -333,8 +333,8 @@ isa = PBXGroup; children = ( E22F837D2511E8350072105C /* Helpers */, - E2592B8B250D6B6000906A40 /* Views */, E2FD91E225047C1D00D5E935 /* Models */, + E2592B8B250D6B6000906A40 /* Views */, E2F7249525005E8A007D87ED /* MonsterCardsTests.m */, E2F7249725005E8A007D87ED /* Info.plist */, ); diff --git a/iOS/MonsterCards/Models/Monster.m b/iOS/MonsterCards/Models/Monster.m index 9b77cd8..3215174 100644 --- a/iOS/MonsterCards/Models/Monster.m +++ b/iOS/MonsterCards/Models/Monster.m @@ -112,7 +112,7 @@ NSString* const kMonsterSizeGargantuan = @"gargantuan"; self.hpText = [JSONHelper readStringFromDictionary:jsonRoot forKey:@"hpText" withDefaultValue:@""]; self.alignment = [JSONHelper readStringFromDictionary:jsonRoot forKey:@"alignment" withDefaultValue:@""]; - self.armorName = [JSONHelper readStringFromDictionary:jsonRoot forKey:@"armorName" withDefaultValue:@""]; + self.armorType = [JSONHelper readStringFromDictionary:jsonRoot forKey:@"armorName" withDefaultValue:@""]; self.otherArmorDescription = [JSONHelper readStringFromDictionary:jsonRoot forKey:@"otherArmorDesc" withDefaultValue:@""]; self.strengthScore = [JSONHelper readIntFromDictionary:jsonRoot forKey:@"strPoints" withDefaultValue:0]; self.dexterityScore = [JSONHelper readIntFromDictionary:jsonRoot forKey:@"dexPoints" withDefaultValue:0]; @@ -195,69 +195,69 @@ NSString* const kMonsterSizeGargantuan = @"gargantuan"; //getArmorClass -(NSString*)armorClassDescription { BOOL hasShield = [self shieldBonus] != 0; - NSString *armorName = [self armorName]; - if ([StringHelper isStringNilOrEmpty:armorName] || [kArmorNameNone isEqualToString:armorName]) { + NSString *armorType = [self armorType]; + if ([StringHelper isStringNilOrEmpty:armorType] || [kArmorNameNone isEqualToString:armorType]) { // 10 + dexMod + 2 for shieldBonus "15" or "17 (shield)" int armorClass = kArmorClassUnarmored + self.dexterityModifier + self.shieldBonus; return [NSString stringWithFormat:@"%d%@", armorClass, (hasShield ? @" (shield)" : @"")]; - } else if ([kArmorNameNaturalArmor isEqualToString:armorName]) { + } else if ([kArmorNameNaturalArmor isEqualToString:armorType]) { // 10 + dexMod + naturalArmorBonus + 2 for shieldBonus "16 (natural armor)" or "18 (natural armor, shield)" int armorClass = kArmorClassUnarmored + self.dexterityModifier + self.naturalArmorBonus + self.shieldBonus; return [NSString stringWithFormat:@"%d (natural armor%@)", armorClass, (hasShield ? @" (shield)" : @"")]; - } else if ([kArmorNameMageArmor isEqualToString:armorName]) { + } else if ([kArmorNameMageArmor isEqualToString:armorType]) { // 10 + dexMod + 2 for shield + 3 for mage armor "15 (18 with mage armor)" or 17 (shield, 20 with mage armor) int armorClass = kArmorClassUnarmored + self.dexterityModifier + self.shieldBonus; int armorClassWithMageArmor = kArmorClassMageArmor + self.dexterityModifier + self.shieldBonus; return [NSString stringWithFormat:@"%d (%@%d with mage armor)", armorClass, (hasShield ? @"shield, " : @""), armorClassWithMageArmor]; - } else if ([kArmorNamePadded isEqualToString:armorName]) { + } else if ([kArmorNamePadded isEqualToString:armorType]) { // 11 + dexMod + 2 for shield "18 (padded armor, shield)" int armorClass = kArmorClassPadded + self.dexterityModifier + self.shieldBonus; return [NSString stringWithFormat:@"%d (padded%@)", armorClass, (hasShield ? @"shield, " : @"")]; - } else if ([kArmorNameLeather isEqualToString:armorName]) { + } else if ([kArmorNameLeather isEqualToString:armorType]) { // 11 + dexMod + 2 for shield "18 (leather, shield)" int armorClass = kArmorClassLeather + self.dexterityModifier + self.shieldBonus; return [NSString stringWithFormat:@"%d (leather%@)", armorClass, (hasShield ? @"shield, " : @"")]; - } else if ([kArmorNameStuddedLeather isEqualToString:armorName]) { + } else if ([kArmorNameStuddedLeather isEqualToString:armorType]) { // 12 + dexMod +2 for shield "17 (studded leather)" int armorClass = kArmorClassStudded + self.dexterityModifier + self.shieldBonus; return [NSString stringWithFormat:@"%d (studded leather%@)", armorClass, (hasShield ? @"shield, " : @"")]; - } else if ([kArmorNameHide isEqualToString:armorName]) { + } else if ([kArmorNameHide isEqualToString:armorType]) { // 12 + Min(2, dexMod) + 2 for shield "12 (hide armor)" int armorClass = kArmorClassHide + MIN(2, self.dexterityModifier) + self.shieldBonus; return [NSString stringWithFormat:@"%d (hide%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNameChainShirt isEqualToString:armorName]) { + } else if ([kArmorNameChainShirt isEqualToString:armorType]) { // 13 + Min(2, dexMod) + 2 for shield "12 (chain shirt)" int armorClass = kArmorClassChainShirt + MIN(2, self.dexterityModifier) + self.shieldBonus; return [NSString stringWithFormat:@"%d (chain shirt%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNameScaleMail isEqualToString:armorName]) { + } else if ([kArmorNameScaleMail isEqualToString:armorType]) { // 14 + Min(2, dexMod) + 2 for shield "14 (scale mail)" int armorClass = kArmorClassScaleMail + MIN(2, self.dexterityModifier) + self.shieldBonus; return [NSString stringWithFormat:@"%d (scale mail%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNameBreastplate isEqualToString:armorName]) { + } else if ([kArmorNameBreastplate isEqualToString:armorType]) { // 14 + Min(2, dexMod) + 2 for shield "16 (breastplate)" int armorClass = kArmorClassBreastplate + MIN(2, self.dexterityModifier) + self.shieldBonus; return [NSString stringWithFormat:@"%d (breastplate%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNameHalfPlate isEqualToString:armorName]) { + } else if ([kArmorNameHalfPlate isEqualToString:armorType]) { // 15 + Min(2, dexMod) + 2 for shield "17 (half plate)" int armorClass = kArmorClassHalfPlate + MIN(2, self.dexterityModifier) + self.shieldBonus; return [NSString stringWithFormat:@"%d (half plate%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNameRingMail isEqualToString:armorName]) { + } else if ([kArmorNameRingMail isEqualToString:armorType]) { // 14 + 2 for shield "14 (ring mail) int armorClass = kArmorClassRingMail + self.shieldBonus; return [NSString stringWithFormat:@"%d (ring mail%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNameChainMail isEqualToString:armorName]) { + } else if ([kArmorNameChainMail isEqualToString:armorType]) { // 16 + 2 for shield "16 (chain mail)" int armorClass = kArmorClassChainMail + self.shieldBonus; return [NSString stringWithFormat:@"%d (chain mail%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNameSplintMail isEqualToString:armorName]) { + } else if ([kArmorNameSplintMail isEqualToString:armorType]) { // 17 + 2 for shield "17 (splint)" int armorClass = kArmorClassSplintMail + self.shieldBonus; return [NSString stringWithFormat:@"%d (splint%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNamePlateMail isEqualToString:armorName]) { + } else if ([kArmorNamePlateMail isEqualToString:armorType]) { // 18 + 2 for shield "18 (plate)" int armorClass = kArmorClassPlate + self.shieldBonus; return [NSString stringWithFormat:@"%d (plate%@)", armorClass, (hasShield ? @", shield" : @"")]; - } else if ([kArmorNameOther isEqualToString:armorName]) { + } else if ([kArmorNameOther isEqualToString:armorType]) { // pure string value shield check does nothing just copies the string from otherArmorDesc return self.otherArmorDescription; } else { @@ -490,7 +490,7 @@ NSString* const kMonsterSizeGargantuan = @"gargantuan"; self.intelligenceScore = monster.intelligenceScore; self.wisdomScore = monster.wisdomScore; self.charismaScore = monster.charismaScore; - self.armorName = monster.armorName; + self.armorType = monster.armorType; self.otherArmorDescription = monster.otherArmorDescription; self.shieldBonus = monster.shieldBonus; self.customHP = monster.customHP; diff --git a/iOS/MonsterCards/MonsterCards.xcdatamodeld/MonsterCards.xcdatamodel/contents b/iOS/MonsterCards/MonsterCards.xcdatamodeld/MonsterCards.xcdatamodel/contents index baf8099..f7d4b9f 100644 --- a/iOS/MonsterCards/MonsterCards.xcdatamodeld/MonsterCards.xcdatamodel/contents +++ b/iOS/MonsterCards/MonsterCards.xcdatamodeld/MonsterCards.xcdatamodel/contents @@ -1,33 +1,36 @@ - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + + - + - + - + - + \ No newline at end of file diff --git a/iOS/MonsterCards/Views/EditMonsterViewController.m b/iOS/MonsterCards/Views/EditMonsterViewController.m index d7f99af..2b9c0e5 100644 --- a/iOS/MonsterCards/Views/EditMonsterViewController.m +++ b/iOS/MonsterCards/Views/EditMonsterViewController.m @@ -28,10 +28,14 @@ const int kBasicInfoSectionRowIndexSize = 1; const int kBasicInfoSectionRowIndexType = 2; const int kBasicInfoSectionRowIndexSubtype = 3; const int kBasicInfoSectionRowIndexAlignment = 4; +const int kBasicInfoSectionRowIndexHitDice = 5; +const int kBasicInfoSectionRowIndexCustomHP = 6; +const int kBasicInfoSectionRowIndexCustomHPText = 7; -const int kArmorSectionRowIndexHitDice = 0; -const int kArmorSectionRowIndexCustomHP = 1; -const int kArmorSectionRowIndexCustomHPText = 2; +const int kArmorSectionRowIndexArmorType = 0; +const int kArmorSectionRowIndexHasShield = 1; +const int kArmorSectionRowIndexNaturalArmorBonus = 2; +const int kArmorSectionRowIndexCustomArmor = 3; const int kSpeedSectionRowIndexBaseSpeed = 0; const int kSpeedSectionRowIndexBurrowSpeed = 1; @@ -154,9 +158,9 @@ const int kAbilityScoreSectionRowIndexCharisma = 5; // * Type // * Subtype // * Alignment - return 5; + return 8; case kSectionIndexArmor: - return 3; + return 0; case kSectionIndexSpeed: return 8; case kSectionIndexAbilityScores: @@ -224,105 +228,120 @@ titleForHeaderInSection:(NSInteger)section { label: NSLocalizedString(@"Alignment", @"Placeholder text for the alignment of a monster or NPC.") andInitialValue:self.editingMonster.alignment]; break; + case kBasicInfoSectionRowIndexHitDice: + newCell = [self makeIntegerCellFromTableView:self.monsterTableView + withIdentifier:@"monster.hitDice" + label:NSLocalizedString(@"Hit Dice", @"") + andInitialValue:self.editingMonster.hitDice]; + break; + case kBasicInfoSectionRowIndexCustomHP: + newCell = [self makeBooleanCellFromTableView:self.monsterTableView + withIdentifier:@"monster.customHP" + label:NSLocalizedString(@"Custom HP", @"") + andInitialValue:self.editingMonster.customHP]; + break; + case kBasicInfoSectionRowIndexCustomHPText: + newCell = [self makeShortStringCellFromTableView:self.monsterTableView + withIdentifier:@"monster.customHPText" + label:NSLocalizedString(@"Custom HP Text", @"") + andInitialValue:self.editingMonster.hpText]; + break; } break; case kSectionIndexArmor: switch (indexPath.row) { - case kArmorSectionRowIndexHitDice: - return [self makeIntegerCellFromTableView:self.monsterTableView - withIdentifier:@"monster.hitDice" - label:NSLocalizedString(@"Hit Dice", @"") - andInitialValue:self.editingMonster.hitDice]; - case kArmorSectionRowIndexCustomHP: - return [self makeBooleanCellFromTableView:self.monsterTableView - withIdentifier:@"monster.customHP" - label:NSLocalizedString(@"Custom HP", @"") - andInitialValue:self.editingMonster.customHP]; - return nil; - case kArmorSectionRowIndexCustomHPText: - return [self makeShortStringCellFromTableView:self.monsterTableView - withIdentifier:@"monster.customHPText" - label:NSLocalizedString(@"Custom HP Text", @"") - andInitialValue:self.editingMonster.hpText]; } break; case kSectionIndexSpeed: switch (indexPath.row) { case kSpeedSectionRowIndexBaseSpeed: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.baseSpeed" label:NSLocalizedString(@"Base", @"") andInitialValue:self.editingMonster.baseSpeed]; + break; case kSpeedSectionRowIndexBurrowSpeed: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.burrowSpeed" label:NSLocalizedString(@"Burrow", @"") andInitialValue:self.editingMonster.burrowSpeed]; + break; case kSpeedSectionRowIndexClimbSpeed: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.climbSpeed" label:NSLocalizedString(@"Climb", @"") andInitialValue:self.editingMonster.climbSpeed]; + break; case kSpeedSectionRowIndexFlySpeed: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.flySpeed" label:NSLocalizedString(@"Fly", @"") andInitialValue:self.editingMonster.flySpeed]; + break; case kSpeedSectionRowIndexCanHover: - return [self makeBooleanCellFromTableView:self.monsterTableView + newCell = [self makeBooleanCellFromTableView:self.monsterTableView withIdentifier:@"monster.canHover" label:NSLocalizedString(@"Hover", @"") andInitialValue:self.editingMonster.canHover]; + break; case kSpeedSectionRowIndexSwimSpeed: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.swimSpeed" label:NSLocalizedString(@"Swim", @"") andInitialValue:self.editingMonster.swimSpeed]; + break; case kSpeedSectionRowIndexHasCustomSpeed: - return [self makeBooleanCellFromTableView:self.monsterTableView + newCell = [self makeBooleanCellFromTableView:self.monsterTableView withIdentifier:@"monster.hasCustomSpeed" label:NSLocalizedString(@"Custom Speed", @"") andInitialValue:self.editingMonster.hasCustomSpeed]; + break; case kSpeedSectionRowIndexCustomSpeed: - return [self makeShortStringCellFromTableView:self.monsterTableView + newCell = [self makeShortStringCellFromTableView:self.monsterTableView withIdentifier:@"monster.customSpeed" label:NSLocalizedString(@"Custom Speed", @"") andInitialValue:self.editingMonster.customSpeed]; - + break; } break; case kSectionIndexAbilityScores: switch (indexPath.row) { case kAbilityScoreSectionRowIndexStrength: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.strengthScore" label:NSLocalizedString(@"STR", @"Placeholder abbreviation for the strength score of a monster or NPC.") andInitialValue:self.editingMonster.strengthScore]; + break; case kAbilityScoreSectionRowIndexDexterity: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.dexterityScore" label:NSLocalizedString(@"DEX", @"Placeholder abbreviation for the dexterity score of a monster or NPC.") andInitialValue:self.editingMonster.dexterityScore]; + break; case kAbilityScoreSectionRowIndexConstitution: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.constitutionScore" label:NSLocalizedString(@"CON", @"Placeholder abbreviation for the constitution score of a monster or NPC.") andInitialValue:self.editingMonster.constitutionScore]; + break; case kAbilityScoreSectionRowIndexIntelligence: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.intelligenceScore" label:NSLocalizedString(@"INT", @"Placeholder abbreviation for the intelligence score of a monster or NPC.") andInitialValue:self.editingMonster.intelligenceScore]; + break; case kAbilityScoreSectionRowIndexWisdom: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.wisdomScore" label:NSLocalizedString(@"WIS", @"Placeholder abbreviation for the wisdom score of a monster or NPC.") andInitialValue:self.editingMonster.wisdomScore]; + break; case kAbilityScoreSectionRowIndexCharisma: - return [self makeIntegerCellFromTableView:self.monsterTableView + newCell = [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.charismaScore" label:NSLocalizedString(@"CHA", @"Placeholder abbreviation for the charisma score of a monster or NPC.") andInitialValue:self.editingMonster.charismaScore]; + break; } break; diff --git a/iOS/MonsterCardsTests/Models/MonsterTests.m b/iOS/MonsterCardsTests/Models/MonsterTests.m index 72dcbd5..e999514 100644 --- a/iOS/MonsterCardsTests/Models/MonsterTests.m +++ b/iOS/MonsterCardsTests/Models/MonsterTests.m @@ -46,7 +46,7 @@ XCTAssertEqual(0, _monster.intelligenceScore); XCTAssertEqual(0, _monster.wisdomScore); XCTAssertEqual(0, _monster.charismaScore); - XCTAssertEqualObjects(@"", _monster.armorName); + XCTAssertEqualObjects(@"", _monster.armorType); XCTAssertEqualObjects(@"", _monster.otherArmorDescription); XCTAssertEqual(0, _monster.shieldBonus); XCTAssertEqual(NO, _monster.customHP); @@ -68,7 +68,7 @@ XCTAssertEqual(14, _monster.intelligenceScore); XCTAssertEqual(16, _monster.wisdomScore); XCTAssertEqual(18, _monster.charismaScore); - XCTAssertEqualObjects(@"none", _monster.armorName); + XCTAssertEqualObjects(@"none", _monster.armorType); XCTAssertEqualObjects(@"10", _monster.otherArmorDescription); XCTAssertEqual(2, _monster.shieldBonus); XCTAssertEqual(YES, _monster.customHP); @@ -91,7 +91,7 @@ XCTAssertEqual(0, _monster.intelligenceScore); XCTAssertEqual(0, _monster.wisdomScore); XCTAssertEqual(0, _monster.charismaScore); - XCTAssertEqualObjects(@"", _monster.armorName); + XCTAssertEqualObjects(@"", _monster.armorType); XCTAssertEqualObjects(@"", _monster.otherArmorDescription); XCTAssertEqual(0, _monster.shieldBonus); XCTAssertEqual(NO, _monster.customHP); @@ -114,7 +114,7 @@ XCTAssertEqual(14, _monster.intelligenceScore); XCTAssertEqual(16, _monster.wisdomScore); XCTAssertEqual(18, _monster.charismaScore); - XCTAssertEqualObjects(@"none", _monster.armorName); + XCTAssertEqualObjects(@"none", _monster.armorType); XCTAssertEqualObjects(@"10", _monster.otherArmorDescription); XCTAssertEqual(2, _monster.shieldBonus); XCTAssertEqual(YES, _monster.customHP); @@ -167,7 +167,7 @@ XCTAssertEqual(14, _monster.intelligenceScore); XCTAssertEqual(16, _monster.wisdomScore); XCTAssertEqual(18, _monster.charismaScore); - XCTAssertEqualObjects(@"none", _monster.armorName); + XCTAssertEqualObjects(@"none", _monster.armorType); XCTAssertEqualObjects(@"10", _monster.otherArmorDescription); XCTAssertEqual(2, _monster.shieldBonus); } @@ -385,8 +385,8 @@ } - (void)testGetterAndSetterForArmorName { - _monster.armorName = @"dandelion"; - XCTAssertEqualObjects(@"dandelion", _monster.armorName); + _monster.armorType = @"dandelion"; + XCTAssertEqualObjects(@"dandelion", _monster.armorType); } - (void)testGetterAndSetterForOtherArmorDescription {