Skip to content

Commit c0e57cd

Browse files
committed
Support deserialization of Effectws.
1 parent 706dc5f commit c0e57cd

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

cocos2d-ui/CCBReader/CCBReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
NSMutableDictionary* actionManagers;
6161
NSMutableSet* animatedProps;
6262
NSMutableDictionary* nodeMapping;//Maps UUID -> Node
63+
NSMutableArray * postDeserializationUUIDFixup;
6364
}
6465

6566
/// -----------------------------------------------------------------------

cocos2d-ui/CCBReader/CCBReader.m

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,20 @@
5252
@interface CCBFile : CCNode
5353
{
5454
CCNode* ccbFile;
55+
5556
}
5657
@property (nonatomic,strong) CCNode* ccbFile;
5758
@end
5859

5960

6061
@interface CCBReader()
62+
{
63+
64+
}
6165

6266
@property (nonatomic, copy) NSString *currentCCBFile;
6367

68+
6469
@end
6570

6671

@@ -115,7 +120,7 @@ - (id) init
115120
animationManager.rootContainerSize = [CCDirector sharedDirector].designSize;
116121

117122
nodeMapping = [NSMutableDictionary dictionary];
118-
123+
postDeserializationUUIDFixup = [NSMutableArray array];
119124
return self;
120125
}
121126

@@ -905,10 +910,12 @@ - (void) readPropertyForNode:(CCNode*) node parent:(CCNode*)parent isExtraProp:(
905910
else if(type == kCCBPropTypeNodeReference)
906911
{
907912
int uuid = readIntWithSign(self, NO);
908-
CCNode * mappedNode = nodeMapping[@(uuid)];
909-
NSAssert(mappedNode != nil, @"CCBReader: Failed to find node UUID:%i", uuid);
910-
[node setValue:mappedNode forKey:name];
911-
}
913+
914+
//Node references are fixed after the whole node graph is deserialized (since since the node ref may not be deserialized yet)
915+
NSArray * queuedFixupTask = @[node, name, @(uuid)];
916+
[postDeserializationUUIDFixup addObject:queuedFixupTask];
917+
918+
}
912919
else if(type == kCCBPropTypeFloatCheck)
913920
{
914921
float f = readFloat(self);
@@ -939,7 +946,7 @@ - (void) readPropertyForNode:(CCNode*) node parent:(CCNode*)parent isExtraProp:(
939946
//Either returns a CCStackEffect or the one single effect.
940947
-(CCEffect*)readEffects
941948
{
942-
#if CC_ENABLE_EXPERIMENTAL_EFFECTS
949+
943950
int numberOfEffects = readIntWithSign(self, NO);
944951

945952
NSMutableArray * effectsStack = [NSMutableArray array];
@@ -974,9 +981,7 @@ -(CCEffect*)readEffects
974981
}
975982

976983
return [[CCEffectStack alloc] initWithEffects:effectsStack];
977-
#else
978-
return nil;
979-
#endif
984+
980985
}
981986

982987
- (BOOL)isPropertyKeySettable:(NSString *)key onInstance:(id)instance
@@ -1117,6 +1122,21 @@ - (void) didLoadFromCCB
11171122
{
11181123
}
11191124

1125+
-(void)postDeserialization
1126+
{
1127+
//Post deserialization fixup.
1128+
for (NSArray * task in postDeserializationUUIDFixup) {
1129+
id node = task[0];
1130+
NSString * name = task[1];
1131+
int uuid = (int)[task[2] integerValue];
1132+
1133+
CCNode * mappedNode = nodeMapping[@(uuid)];
1134+
NSAssert(mappedNode != nil, @"CCBReader: Failed to find node UUID:%i", uuid);
1135+
[node setValue:mappedNode forKey:name];
1136+
1137+
}
1138+
}
1139+
11201140
-(void)readJoints
11211141
{
11221142
int numJoints = readIntWithSign(self, NO);
@@ -1715,6 +1735,7 @@ - (CCNode*) readFileWithCleanUp:(BOOL)cleanUp actionManagers:(NSMutableDictionar
17151735

17161736
CCNode* node = [self readNodeGraphParent:NULL];
17171737
[self readJoints];
1738+
[self postDeserialization];
17181739

17191740
[actionManagers setObject:self.animationManager forKey:[NSValue valueWithPointer:(__bridge const void *)(node)]];
17201741

0 commit comments

Comments
 (0)