Adds monster type to editor.
Sets all entity attributes for monster to default to empty string instead of null. Adds test for copyFromMonster. Makes initWithMonster:andContext call copyFromMonster to ensure they use the same logic to clone the other monster.
This commit is contained in:
@@ -73,6 +73,7 @@
|
|||||||
|
|
||||||
self.name = [jsonRoot objectForKey:@"name"] ?: @"";
|
self.name = [jsonRoot objectForKey:@"name"] ?: @"";
|
||||||
self.size = [jsonRoot objectForKey:@"size"] ?: @"";
|
self.size = [jsonRoot objectForKey:@"size"] ?: @"";
|
||||||
|
self.type = [jsonRoot objectForKey:@"type"] ?: @"";
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -80,7 +81,7 @@
|
|||||||
-(id)initWithMonster:(Monster* _Nonnull)monster {
|
-(id)initWithMonster:(Monster* _Nonnull)monster {
|
||||||
self = [self initWithContext:monster.managedObjectContext];
|
self = [self initWithContext:monster.managedObjectContext];
|
||||||
|
|
||||||
self.name = monster.name;
|
[self copyFromMonster:monster];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -334,6 +335,7 @@
|
|||||||
-(void)copyFromMonster:(Monster*)monster {
|
-(void)copyFromMonster:(Monster*)monster {
|
||||||
self.name = monster.name;
|
self.name = monster.name;
|
||||||
self.size = monster.size;
|
self.size = monster.size;
|
||||||
|
self.type = monster.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<?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="16119" systemVersion="19G2021" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
|
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="16119" systemVersion="19G2021" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
|
||||||
<entity name="Monster" representedClassName="Monster" syncable="YES" codeGenerationType="category">
|
<entity name="Monster" representedClassName="Monster" syncable="YES" codeGenerationType="category">
|
||||||
<attribute name="alignment" optional="YES" attributeType="String"/>
|
<attribute name="alignment" attributeType="String" defaultValueString=""/>
|
||||||
<attribute name="name" attributeType="String" defaultValueString=""/>
|
<attribute name="name" attributeType="String" defaultValueString=""/>
|
||||||
<attribute name="size" optional="YES" attributeType="String" defaultValueString=""/>
|
<attribute name="size" attributeType="String" defaultValueString=""/>
|
||||||
<attribute name="subtype" optional="YES" attributeType="String"/>
|
<attribute name="subtype" attributeType="String" defaultValueString=""/>
|
||||||
<attribute name="type" optional="YES" attributeType="String"/>
|
<attribute name="type" attributeType="String" defaultValueString=""/>
|
||||||
</entity>
|
</entity>
|
||||||
<elements>
|
<elements>
|
||||||
<element name="Monster" positionX="-63" positionY="-18" width="128" height="118"/>
|
<element name="Monster" positionX="-63" positionY="-18" width="128" height="118"/>
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
// * Subtype
|
// * Subtype
|
||||||
// * Alignment
|
// * Alignment
|
||||||
|
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
|
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
|
||||||
@@ -91,6 +91,17 @@
|
|||||||
shortStringCell.textField.text = self.editingMonster.size;
|
shortStringCell.textField.text = self.editingMonster.size;
|
||||||
shortStringCell.textField.placeholder = NSLocalizedString(@"Size", @"Placehodler text for the size of a monster or NPC.");
|
shortStringCell.textField.placeholder = NSLocalizedString(@"Size", @"Placehodler text for the size of a monster or NPC.");
|
||||||
return shortStringCell;
|
return shortStringCell;
|
||||||
|
case 2:
|
||||||
|
shortStringCell = [self.monsterTableView dequeueReusableCellWithIdentifier:@"EditableShortString"];
|
||||||
|
if (shortStringCell == nil) {
|
||||||
|
shortStringCell = [[EditableShortStringTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EditableShortString"];
|
||||||
|
}
|
||||||
|
shortStringCell.delegate = self;
|
||||||
|
shortStringCell.identifier = @"monster.type";
|
||||||
|
// TODO: make these use setters on EditableShortStringTableViewCell
|
||||||
|
shortStringCell.textField.text = self.editingMonster.type;
|
||||||
|
shortStringCell.textField.placeholder = NSLocalizedString(@"Type", @"Placehodler text for the type of a monster or NPC.");
|
||||||
|
return shortStringCell;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -106,6 +117,8 @@
|
|||||||
self.editingMonster.name = (NSString*)value;
|
self.editingMonster.name = (NSString*)value;
|
||||||
} else if ([@"monster.size" isEqualToString:identifier]) {
|
} else if ([@"monster.size" isEqualToString:identifier]) {
|
||||||
self.editingMonster.size = (NSString*)value;
|
self.editingMonster.size = (NSString*)value;
|
||||||
|
} else if ([@"monster.type" isEqualToString:identifier]) {
|
||||||
|
self.editingMonster.type = (NSString*)value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
- (void)setUp {
|
- (void)setUp {
|
||||||
_context = nil;
|
_context = nil;
|
||||||
_monster = [[Monster alloc] initWithContext:_context];
|
_monster = [[Monster alloc] initWithContext:_context];
|
||||||
_jsonString = @"{\"name\":\"Acolyte\",\"size\":\"large\"}";
|
_jsonString = @"{\"name\":\"Acolyte\",\"size\":\"medium\",\"type\":\"humanoid\"}";
|
||||||
_jsonData = [_jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
_jsonData = [_jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
XCTAssertNotNil(_monster);
|
XCTAssertNotNil(_monster);
|
||||||
XCTAssertEqualObjects(@"", _monster.name);
|
XCTAssertEqualObjects(@"", _monster.name);
|
||||||
XCTAssertEqualObjects(@"", _monster.size);
|
XCTAssertEqualObjects(@"", _monster.size);
|
||||||
|
XCTAssertEqualObjects(@"", _monster.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testInitWithJSONString {
|
- (void)testInitWithJSONString {
|
||||||
@@ -44,7 +45,8 @@
|
|||||||
|
|
||||||
XCTAssertNotNil(_monster);
|
XCTAssertNotNil(_monster);
|
||||||
XCTAssertEqualObjects(@"Acolyte", _monster.name);
|
XCTAssertEqualObjects(@"Acolyte", _monster.name);
|
||||||
XCTAssertEqualObjects(@"large", _monster.size);
|
XCTAssertEqualObjects(@"medium", _monster.size);
|
||||||
|
XCTAssertEqualObjects(@"humanoid", _monster.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testInitWithEmptyJSONString {
|
- (void)testInitWithEmptyJSONString {
|
||||||
@@ -53,13 +55,15 @@
|
|||||||
XCTAssertNotNil(_monster);
|
XCTAssertNotNil(_monster);
|
||||||
XCTAssertEqualObjects(@"", _monster.name);
|
XCTAssertEqualObjects(@"", _monster.name);
|
||||||
XCTAssertEqualObjects(@"", _monster.size);
|
XCTAssertEqualObjects(@"", _monster.size);
|
||||||
|
XCTAssertEqualObjects(@"", _monster.type);
|
||||||
}
|
}
|
||||||
- (void)testInitWithJSONData {
|
- (void)testInitWithJSONData {
|
||||||
_monster = [[Monster alloc] initWithJSONData:_jsonData andContext:_context];
|
_monster = [[Monster alloc] initWithJSONData:_jsonData andContext:_context];
|
||||||
|
|
||||||
XCTAssertNotNil(_monster);
|
XCTAssertNotNil(_monster);
|
||||||
XCTAssertEqualObjects(@"Acolyte", _monster.name);
|
XCTAssertEqualObjects(@"Acolyte", _monster.name);
|
||||||
XCTAssertEqualObjects(@"large", _monster.size);
|
XCTAssertEqualObjects(@"medium", _monster.size);
|
||||||
|
XCTAssertEqualObjects(@"humanoid", _monster.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testNameGetterAndSetter {
|
- (void)testNameGetterAndSetter {
|
||||||
@@ -74,4 +78,20 @@
|
|||||||
XCTAssertEqualObjects(size, _monster.size);
|
XCTAssertEqualObjects(size, _monster.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testTypeGetterAndSetter {
|
||||||
|
NSString *type = @"fey";
|
||||||
|
_monster.type = type;
|
||||||
|
XCTAssertEqualObjects(type, _monster.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testCopyFromMonster {
|
||||||
|
Monster *otherMonster = [[Monster alloc] initWithJSONString:_jsonString andContext:_context];
|
||||||
|
[_monster copyFromMonster:otherMonster];
|
||||||
|
|
||||||
|
XCTAssertNotNil(_monster);
|
||||||
|
XCTAssertEqualObjects(@"Acolyte", _monster.name);
|
||||||
|
XCTAssertEqualObjects(@"medium", _monster.size);
|
||||||
|
XCTAssertEqualObjects(@"humanoid", _monster.type);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user