Skip to content

Commit f56fa7e

Browse files
committed
Package enabler won't re-add a package if it is already in the search path.
1 parent cf6d8dd commit f56fa7e

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

cocos2d/CCPackageCocos2dEnabler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Enables packages by adding to cocos2d's search path and loading sprite sheets and filename lookups.
77
* Note: This method won't check a package's status and it is meant to be used for initialization
88
* of packages on startup by the CCPackagesManager.
9+
* If a package is already among the search path then it won't be added again, spritesheets and file lookups not reloaded
910
*
1011
* @param packages An array of CCPackage instance to be enabled
1112
*/

cocos2d/CCPackageCocos2dEnabler.m

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77

88
@implementation CCPackageCocos2dEnabler
99

10-
- (void)enablePackages:(NSArray *)packages
10+
- (BOOL)isPackagInSearchPath:(CCPackage *)package
1111
{
12-
[self addPackagestoSearchPath:packages];
12+
NSString *newPackagePath = package.installURL.path;
1313

14-
CCLOGINFO(@"[PACKAGE/INSTALL][INFO] Enable packages - Search path: %@", [CCFileUtils sharedFileUtils].searchPath);
14+
return [[CCFileUtils sharedFileUtils].searchPath containsObject:newPackagePath];
15+
}
1516

16-
[self reloadCocos2dFiles];
17+
- (void)enablePackages:(NSArray *)packages
18+
{
19+
if ([self addPackagestoSearchPath:packages]);
20+
{
21+
CCLOGINFO(@"[PACKAGE/INSTALL][INFO] Enable packages - Search path: %@", [CCFileUtils sharedFileUtils].searchPath);
22+
23+
[self reloadCocos2dFiles];
24+
}
1725
}
1826

1927
- (void)disablePackages:(NSArray *)array
@@ -25,8 +33,10 @@ - (void)disablePackages:(NSArray *)array
2533
[self reloadCocos2dFiles];
2634
}
2735

28-
- (void)addPackagestoSearchPath:(NSArray *)packages
36+
- (BOOL)addPackagestoSearchPath:(NSArray *)packages
2937
{
38+
BOOL searchPathChanged = NO;
39+
3040
for (CCPackage *aPackage in packages)
3141
{
3242
NSMutableArray *newSearchPath = [[CCFileUtils sharedFileUtils].searchPath mutableCopy];
@@ -35,10 +45,12 @@ - (void)addPackagestoSearchPath:(NSArray *)packages
3545
if (![newSearchPath containsObject:newPackagePath])
3646
{
3747
[newSearchPath insertObject:newPackagePath atIndex:0];
48+
[CCFileUtils sharedFileUtils].searchPath = newSearchPath;
49+
searchPathChanged = YES;
3850
}
39-
40-
[CCFileUtils sharedFileUtils].searchPath = newSearchPath;
4151
}
52+
53+
return searchPathChanged;
4254
}
4355

4456
- (void)reloadCocos2dFiles

0 commit comments

Comments
 (0)