|
52 | 52 | @interface CCBFile : CCNode
|
53 | 53 | {
|
54 | 54 | CCNode* ccbFile;
|
| 55 | + |
55 | 56 | }
|
56 | 57 | @property (nonatomic,strong) CCNode* ccbFile;
|
57 | 58 | @end
|
58 | 59 |
|
59 | 60 |
|
60 | 61 | @interface CCBReader()
|
| 62 | +{ |
| 63 | + |
| 64 | +} |
61 | 65 |
|
62 | 66 | @property (nonatomic, copy) NSString *currentCCBFile;
|
63 | 67 |
|
| 68 | + |
64 | 69 | @end
|
65 | 70 |
|
66 | 71 |
|
@@ -115,7 +120,7 @@ - (id) init
|
115 | 120 | animationManager.rootContainerSize = [CCDirector sharedDirector].designSize;
|
116 | 121 |
|
117 | 122 | nodeMapping = [NSMutableDictionary dictionary];
|
118 |
| - |
| 123 | + postDeserializationUUIDFixup = [NSMutableArray array]; |
119 | 124 | return self;
|
120 | 125 | }
|
121 | 126 |
|
@@ -905,10 +910,12 @@ - (void) readPropertyForNode:(CCNode*) node parent:(CCNode*)parent isExtraProp:(
|
905 | 910 | else if(type == kCCBPropTypeNodeReference)
|
906 | 911 | {
|
907 | 912 | 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 | + } |
912 | 919 | else if(type == kCCBPropTypeFloatCheck)
|
913 | 920 | {
|
914 | 921 | float f = readFloat(self);
|
@@ -939,7 +946,7 @@ - (void) readPropertyForNode:(CCNode*) node parent:(CCNode*)parent isExtraProp:(
|
939 | 946 | //Either returns a CCStackEffect or the one single effect.
|
940 | 947 | -(CCEffect*)readEffects
|
941 | 948 | {
|
942 |
| -#if CC_ENABLE_EXPERIMENTAL_EFFECTS |
| 949 | + |
943 | 950 | int numberOfEffects = readIntWithSign(self, NO);
|
944 | 951 |
|
945 | 952 | NSMutableArray * effectsStack = [NSMutableArray array];
|
@@ -974,9 +981,7 @@ -(CCEffect*)readEffects
|
974 | 981 | }
|
975 | 982 |
|
976 | 983 | return [[CCEffectStack alloc] initWithEffects:effectsStack];
|
977 |
| -#else |
978 |
| - return nil; |
979 |
| -#endif |
| 984 | + |
980 | 985 | }
|
981 | 986 |
|
982 | 987 | - (BOOL)isPropertyKeySettable:(NSString *)key onInstance:(id)instance
|
@@ -1117,6 +1122,21 @@ - (void) didLoadFromCCB
|
1117 | 1122 | {
|
1118 | 1123 | }
|
1119 | 1124 |
|
| 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 | + |
1120 | 1140 | -(void)readJoints
|
1121 | 1141 | {
|
1122 | 1142 | int numJoints = readIntWithSign(self, NO);
|
@@ -1715,6 +1735,7 @@ - (CCNode*) readFileWithCleanUp:(BOOL)cleanUp actionManagers:(NSMutableDictionar
|
1715 | 1735 |
|
1716 | 1736 | CCNode* node = [self readNodeGraphParent:NULL];
|
1717 | 1737 | [self readJoints];
|
| 1738 | + [self postDeserialization]; |
1718 | 1739 |
|
1719 | 1740 | [actionManagers setObject:self.animationManager forKey:[NSValue valueWithPointer:(__bridge const void *)(node)]];
|
1720 | 1741 |
|
|
0 commit comments