Makes Monster a CoreData entity
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <CoreData/CoreData.h>
|
||||||
#import "Ability.h"
|
#import "Ability.h"
|
||||||
#import "Action.h"
|
#import "Action.h"
|
||||||
#import "DamageType.h"
|
#import "DamageType.h"
|
||||||
@@ -18,13 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@class Skill;
|
@class Skill;
|
||||||
|
|
||||||
@interface Monster : NSObject
|
@interface Monster : NSManagedObject
|
||||||
|
|
||||||
@property NSString *name;
|
|
||||||
@property NSString *size;
|
|
||||||
@property NSString *type;
|
|
||||||
@property NSString *tag;
|
|
||||||
@property NSString *alignment;
|
|
||||||
@property NSString *armorName;
|
@property NSString *armorName;
|
||||||
@property NSString *otherArmorDescription;
|
@property NSString *otherArmorDescription;
|
||||||
@property NSString *hpText;
|
@property NSString *hpText;
|
||||||
@@ -64,8 +60,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
+(int)abilityModifierForScore: (int)score;
|
+(int)abilityModifierForScore: (int)score;
|
||||||
+(int)hitDieForSize: (NSString*)size;
|
+(int)hitDieForSize: (NSString*)size;
|
||||||
|
|
||||||
-(id)initWithJSONString:(NSString*)jsonString;
|
-(id)initWithJSONString:(NSString*)jsonString andContext:(NSManagedObjectContext*)context;
|
||||||
-(id)initWithJSONData:(NSData*)jsonData;
|
-(id)initWithJSONData:(NSData*)jsonData andContext:(NSManagedObjectContext*)context;
|
||||||
-(id)initWithMonster:(Monster*)monster;
|
-(id)initWithMonster:(Monster*)monster;
|
||||||
-(NSString*)meta;
|
-(NSString*)meta;
|
||||||
-(int)abilityScoreForAbilityScoreName: (NSString*)abilityScoreName;
|
-(int)abilityScoreForAbilityScoreName: (NSString*)abilityScoreName;
|
||||||
@@ -130,3 +126,5 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#import "Monster+CoreDataProperties.h"
|
||||||
|
|||||||
@@ -10,6 +10,38 @@
|
|||||||
|
|
||||||
@implementation Monster
|
@implementation Monster
|
||||||
|
|
||||||
|
@synthesize armorName;
|
||||||
|
@synthesize blindsightDistance;
|
||||||
|
@synthesize burrowSpeed;
|
||||||
|
@synthesize challengeRating;
|
||||||
|
@synthesize charismaScore;
|
||||||
|
@synthesize climbSpeed;
|
||||||
|
@synthesize constitutionScore;
|
||||||
|
@synthesize customChallengeRating;
|
||||||
|
@synthesize customHP;
|
||||||
|
@synthesize customProficiencyBonus;
|
||||||
|
@synthesize customSpeed;
|
||||||
|
@synthesize customSpeedDescription;
|
||||||
|
@synthesize darkvisionDistance;
|
||||||
|
@synthesize dexterityScore;
|
||||||
|
@synthesize flySpeed;
|
||||||
|
@synthesize hitDice;
|
||||||
|
@synthesize hover;
|
||||||
|
@synthesize hpText;
|
||||||
|
@synthesize intelligenceScore;
|
||||||
|
@synthesize isBlind;
|
||||||
|
@synthesize naturalArmorBonus;
|
||||||
|
@synthesize otherArmorDescription;
|
||||||
|
@synthesize shieldBonus;
|
||||||
|
@synthesize speed;
|
||||||
|
@synthesize strengthScore;
|
||||||
|
@synthesize swimSpeed;
|
||||||
|
@synthesize telepathy;
|
||||||
|
@synthesize tremorsenseDistance;
|
||||||
|
@synthesize truesightDistance;
|
||||||
|
@synthesize understandsBut;
|
||||||
|
@synthesize wisdomScore;
|
||||||
|
|
||||||
+(int)abilityModifierForScore: (int)score {
|
+(int)abilityModifierForScore: (int)score {
|
||||||
@throw [[NSException alloc] initWithName:@"unimplemented" reason:@"Method not implemented." userInfo:nil];
|
@throw [[NSException alloc] initWithName:@"unimplemented" reason:@"Method not implemented." userInfo:nil];
|
||||||
}
|
}
|
||||||
@@ -26,14 +58,14 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initWithJSONString: (NSString*)jsonString {
|
-(id)initWithJSONString: (NSString*)jsonString andContext:(NSManagedObjectContext*)context {
|
||||||
NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
|
|
||||||
return [self initWithJSONData:jsonData];
|
return [self initWithJSONData:jsonData andContext:context];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initWithJSONData: (NSData*)jsonData {
|
-(id)initWithJSONData: (NSData*)jsonData andContext:(NSManagedObjectContext*)context {
|
||||||
self = [super init];
|
self = [self initWithContext:context];
|
||||||
|
|
||||||
NSDictionary *jsonRoot = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *jsonRoot = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
|
|
||||||
@@ -42,12 +74,8 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initWithMonster:(Monster*)monster {
|
-(id)initWithMonster:(Monster* _Nonnull)monster {
|
||||||
if (monster == nil) {
|
self = [self initWithContext:monster.managedObjectContext];
|
||||||
return [self init];
|
|
||||||
}
|
|
||||||
|
|
||||||
self = [super init];
|
|
||||||
|
|
||||||
self.name = monster.name;
|
self.name = monster.name;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" usedWithCloudKit="true" userDefinedModelVersionIdentifier="">
|
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="16119" systemVersion="19G2021" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
|
||||||
<elements/>
|
<entity name="Monster" representedClassName="Monster" syncable="YES" codeGenerationType="category">
|
||||||
|
<attribute name="alignment" optional="YES" attributeType="String"/>
|
||||||
|
<attribute name="name" attributeType="String" defaultValueString=""/>
|
||||||
|
<attribute name="size" optional="YES" attributeType="String"/>
|
||||||
|
<attribute name="subtype" optional="YES" attributeType="String"/>
|
||||||
|
<attribute name="type" optional="YES" attributeType="String"/>
|
||||||
|
</entity>
|
||||||
|
<elements>
|
||||||
|
<element name="Monster" positionX="-63" positionY="-18" width="128" height="118"/>
|
||||||
|
</elements>
|
||||||
</model>
|
</model>
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#import "LibraryViewController.h"
|
#import "LibraryViewController.h"
|
||||||
#import "Monster.h"
|
#import "Monster.h"
|
||||||
#import "MonsterViewController.h"
|
#import "MonsterViewController.h"
|
||||||
|
#import "AppDelegate.h"
|
||||||
|
|
||||||
@interface LibraryViewController ()
|
@interface LibraryViewController ()
|
||||||
|
|
||||||
@@ -20,9 +21,12 @@
|
|||||||
|
|
||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
AppDelegate *appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
|
||||||
|
NSManagedObjectContext *context = appDelegate.persistentContainer.viewContext;
|
||||||
|
|
||||||
// Temporary setup of allMonsters until we bind to CoreData.
|
// Temporary setup of allMonsters until we bind to CoreData.
|
||||||
Monster *pixie = [[Monster alloc] initWithJSONString:@"{\"name\":\"Pixie\"}"];
|
Monster *pixie = [[Monster alloc] initWithJSONString:@"{\"name\":\"Pixie\"}" andContext:context];
|
||||||
Monster *acolyte = [[Monster alloc] initWithJSONString:@"{\"name\":\"Acolyte\"}"];
|
Monster *acolyte = [[Monster alloc] initWithJSONString:@"{\"name\":\"Acolyte\"}" andContext:context];
|
||||||
self.allMonsters = [NSArray arrayWithObjects:acolyte, pixie, nil];
|
self.allMonsters = [NSArray arrayWithObjects:acolyte, pixie, nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +36,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)addNewMonster:(id)sender {
|
- (IBAction)addNewMonster:(id)sender {
|
||||||
Monster *monster = [[Monster alloc] init];
|
AppDelegate *appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
|
||||||
|
NSManagedObjectContext *context = appDelegate.persistentContainer.viewContext;
|
||||||
|
Monster *monster = [[Monster alloc] initWithContext:context];
|
||||||
monster.name = @"Unnamed Monster";
|
monster.name = @"Unnamed Monster";
|
||||||
self.allMonsters = [self.allMonsters arrayByAddingObject:monster];
|
self.allMonsters = [self.allMonsters arrayByAddingObject:monster];
|
||||||
[self.monstersTable reloadData];
|
[self.monstersTable reloadData];
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#import "SearchViewController.h"
|
#import "SearchViewController.h"
|
||||||
#import "MonsterViewController.h"
|
#import "MonsterViewController.h"
|
||||||
#import "Monster.h"
|
#import "Monster.h"
|
||||||
|
#import "AppDelegate.h"
|
||||||
|
|
||||||
@interface SearchViewController ()
|
@interface SearchViewController ()
|
||||||
|
|
||||||
@@ -21,8 +22,12 @@
|
|||||||
|
|
||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
Monster *pixie = [[Monster alloc] initWithJSONString:@"{\"name\":\"Pixie\"}"];
|
AppDelegate *appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
|
||||||
Monster *acolyte = [[Monster alloc] initWithJSONString:@"{\"name\":\"Acolyte\"}"];
|
NSManagedObjectContext *context = appDelegate.persistentContainer.viewContext;
|
||||||
|
Monster *pixie = [[Monster alloc] initWithContext:context];
|
||||||
|
pixie.name = @"Pixie";
|
||||||
|
Monster *acolyte = [[Monster alloc] initWithEntity:[NSEntityDescription entityForName:@"Monster" inManagedObjectContext:context] insertIntoManagedObjectContext:nil];
|
||||||
|
acolyte.name = @"Acolyte";
|
||||||
self.allMonsters = [NSArray arrayWithObjects:acolyte, pixie, nil];
|
self.allMonsters = [NSArray arrayWithObjects:acolyte, pixie, nil];
|
||||||
self.foundMonsters= self.allMonsters;
|
self.foundMonsters= self.allMonsters;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user