Skip to content

Commit 8eeb997

Browse files
committed
Inline documentation added.
1 parent b33c8c4 commit 8eeb997

18 files changed

+522
-104
lines changed

cocos2d/CCPackage+InstallData.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,32 @@
88

99
- (CCPackageInstallData *)installData;
1010

11-
// Attaches install data to the package as an associated object
11+
/**
12+
* Attaches install data to the package as an associated object
13+
*
14+
* @param installData The install data to be attached to the package
15+
*/
1216
- (void)setInstallData:(CCPackageInstallData *)installData;
1317

14-
// Removes any install data attached to the package if there is any
18+
/**
19+
* Removes any install data attached to the package if there is any
20+
*/
1521
- (void)removeInstallData;
1622

17-
// Reads values of dictionary and sets them on the install data
18-
// InstallData has to be attached to the package already
23+
/**
24+
* Reads values of dictionary and sets them on the install data.
25+
* Install data has to be attached to package already.
26+
*
27+
* @param dictionary Dictionary containing values to populate the install data with
28+
*/
1929
- (void)populateInstallDataWithDictionary:(NSDictionary *)dictionary;
2030

21-
// Returns a dictionary with the install data's values
31+
//
32+
/**
33+
* Writes the install data values into the provided dictionary.
34+
*
35+
* @param dictionary Dictionary that shouöd be used to serialize the install data to
36+
*/
2237
- (void)writeInstallDataToDictionary:(NSMutableDictionary *)dictionary;
2338

2439
@end

cocos2d/CCPackage+InstallData.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ - (CCPackageInstallData *)installData
2222
- (void)populateInstallDataWithDictionary:(NSDictionary *)dictionary
2323
{
2424
CCPackageInstallData *installData = [self installData];
25+
NSAssert(installData != nil, @"Install data must not be nil");
2526

2627
if (dictionary[PACKAGE_SERIALIZATION_KEY_LOCAL_DOWNLOAD_URL])
2728
{

cocos2d/CCPackage.h

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,83 @@
55

66
@interface CCPackage : NSObject
77

8+
/**
9+
* Name of the package
10+
*/
811
@property (nonatomic, copy, readonly) NSString *name;
12+
13+
/**
14+
* Resolution of the package, e.g. tablethd, phonehd, etc.
15+
*/
916
@property (nonatomic, copy, readonly) NSString *resolution;
17+
18+
/**
19+
* OS of the package e.g. iOS, Android, Mac
20+
*/
1021
@property (nonatomic, copy, readonly) NSString *os;
22+
23+
/**
24+
* The remote URL of the package
25+
*/
1126
@property (nonatomic, copy, readonly) NSURL *remoteURL;
27+
28+
/**
29+
* The local URL where the package is installed. This value will be initially nil and set only if installation was successful.
30+
*/
1231
@property (nonatomic, copy, readonly) NSURL *installURL;
32+
33+
/**
34+
* The current status of the package
35+
*/
1336
@property (nonatomic, readonly) CCPackageStatus status;
1437

38+
39+
/**
40+
* Creates a new instance of a package.
41+
*
42+
* @param name Name of the package
43+
* @param resolution Resolution of the package
44+
* @param os OS of the package
45+
* @param remoteURL Remote URL of the package
46+
*
47+
* @return New instance of CCPackage
48+
*/
1549
- (instancetype)initWithName:(NSString *)name
1650
resolution:(NSString *)resolution
1751
os:(NSString *)os
1852
remoteURL:(NSURL *)remoteURL;
1953

20-
// Returns a new instance of a package populated with the contents of the dictionary
54+
/**
55+
* Creates a new instance of a package populated with the contents of the dictionary.
56+
* Used in context of serialization.
57+
*
58+
* @param dictionary Dictionary containing values to populate the package with.
59+
*
60+
* @return New instance of CCPackage
61+
*/
2162
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
2263

23-
// Returns a dictionary containing the values of the package's properties.
64+
/**
65+
* Returns a dictionary containing the values of the package's properties.
66+
* Used in context of serialization.
67+
*
68+
* @return A dictionary containing the values of the package
69+
*/
2470
- (NSDictionary *)toDictionary;
2571

26-
// Returns an identifier of the package: The pattern is <NAME>-<OS>-<RESOLUTION>. Example: DLC-iOS-phonehd.
27-
// This name can vary though and can be determined by delegation.
72+
/**
73+
* Returns an identifier of the package: The pattern is <NAME>-<OS>-<RESOLUTION>. Example: DLC-iOS-phonehd.
74+
*
75+
* @return A dictionary containing the values of the package
76+
*/
2877
- (NSString *)standardIdentifier;
2978

30-
// Debug
79+
/**
80+
* Returns the status as a string.
81+
* Debugging purposes.
82+
*
83+
* @return A string representation of the status property
84+
*/
3185
- (NSString *)statusToString;
3286

3387
@end

cocos2d/CCPackageCocos2dEnabler.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@
22

33
@interface CCPackageCocos2dEnabler : NSObject
44

5-
// Enables packages by adding to cocos2d's search path and loading sprite sheets and filename lookups
5+
/**
6+
* Enables packages by adding to cocos2d's search path and loading sprite sheets and filename lookups.
7+
* Note: This method won't check a package's status and it is meant to be used for initialization
8+
* of packages on startup by the CCPackagesManager.
9+
*
10+
* @param packages An array of CCPackage instance to be enabled
11+
*/
612
- (void)enablePackages:(NSArray *)packages;
713

8-
// Disables packages by removing them fromcocos2d's search path after that reloading sprite sheets and filename lookups of remaining search paths.
14+
/**
15+
* Disables packages by removing them fromcocos2d's search path after that reloading sprite sheets and filename lookups
16+
* of remaining search paths.
17+
* Note: This method won't check a package's status and it is meant to be used for initialization
18+
* of packages on startup by the CCPackagesManager.
19+
*
20+
* @param packages An array of CCPackage instance to be disabled
21+
*/
922
- (void)disablePackages:(NSArray *)array;
1023

1124
@end

cocos2d/CCPackageConstants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Errors
12
extern NSUInteger const PACKAGE_ERROR_DOWNLOAD_SERVER_RESPONSE_NOT_OK;
23

34
extern NSUInteger const PACKAGE_ERROR_INSTALL_PACKAGE_NOT_FOUND;
@@ -12,6 +13,8 @@ extern NSUInteger const PACKAGE_ERROR_MANAGER_CANNOT_ENABLE_NON_DISABLED_PACKAGE
1213

1314
extern NSUInteger const PACKAGE_ERROR_MANAGER_CANNOT_DISABLE_NON_ENABLED_PACKAGE;
1415

16+
17+
// Misc
1518
extern NSString *const PACKAGE_REL_DOWNLOAD_FOLDER;
1619

1720
extern NSString *const PACKAGE_REL_UNZIP_FOLDER;

cocos2d/CCPackageConstants.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import <objc/NSObjCRuntime.h>
22
#import <Foundation/Foundation.h>
33

4+
// Errors
45
NSUInteger const PACKAGE_ERROR_DOWNLOAD_SERVER_RESPONSE_NOT_OK = 10000;
56

67
NSUInteger const PACKAGE_ERROR_INSTALL_PACKAGE_NOT_FOUND = 10010;
@@ -15,6 +16,8 @@
1516

1617
NSUInteger const PACKAGE_ERROR_MANAGER_CANNOT_DISABLE_NON_ENABLED_PACKAGE = 10021;
1718

19+
20+
// Misc
1821
NSString *const PACKAGE_REL_DOWNLOAD_FOLDER = @"com.cocos2d/Packages/Downloads";
1922

2023
NSString *const PACKAGE_REL_UNZIP_FOLDER = @"com.cocos2d/Packages/Unzipped";

cocos2d/CCPackageDownload.h

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,60 @@
66

77
@interface CCPackageDownload : NSObject <NSURLConnectionDataDelegate>
88

9-
@property (nonatomic, copy) NSURL *packageURL;
10-
@property (nonatomic, copy) NSURL *localURL;
9+
/**
10+
* The URL of the package download, includes the filename
11+
*/
12+
@property (nonatomic, copy, readonly) NSURL *localURL;
13+
14+
/**
15+
* The package being downloaded
16+
*/
1117
@property (nonatomic, strong, readonly) CCPackage *package;
1218

19+
/**
20+
* Total bytes of the download. Might be 0 if no Content-Lenght header is sent by the
21+
* host.
22+
*/
1323
@property (nonatomic, readonly) NSUInteger totalBytes;
24+
25+
/**
26+
* Bytes downloaded.
27+
*/
1428
@property (nonatomic, readonly) NSUInteger downloadedBytes;
1529

30+
/**
31+
* The delegate of the download.
32+
*/
1633
@property (nonatomic, weak) id <CCPackageDownloadDelegate> delegate;
1734

35+
/**
36+
* Returns a new instance of a CCPackageDownload
37+
*
38+
* @param package The package that should be downloaded
39+
* @param localURL The URL of the package download, includes the filename
40+
*
41+
* @return A new instance of a CCPackageDownload
42+
*/
1843
- (instancetype)initWithPackage:(CCPackage *)package localURL:(NSURL *)localURL;
1944

20-
// Starts the download, if there is a downloaded data the delegate is asked if the download should be resumed
45+
/**
46+
* Starts the download, if there is a downloaded data the delegate is asked if the download should be resumed
47+
*/
2148
- (void)start;
2249

23-
// Stops the download and deletes the download file
50+
/**
51+
* Stops the download and deletes the download file
52+
*/
2453
- (void)cancel;
2554

26-
// Stops the download
55+
/**
56+
* Stops the download
57+
*/
2758
- (void)pause;
2859

29-
// Resumes a download, otherwise starts from the beginning
60+
/**
61+
* Resumes a download, otherwise starts from the beginning
62+
*/
3063
- (void)resume;
3164

3265
@end

cocos2d/CCPackageDownload.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ @interface CCPackageDownload()
1212
@property (nonatomic, strong) NSURLConnection *connection;
1313
@property (nonatomic, strong, readwrite) CCPackage *package;
1414
@property (nonatomic, copy) NSString *tempPath;
15+
@property (nonatomic, copy, readwrite) NSURL *localURL;
1516

1617
@property (nonatomic, readwrite) NSUInteger totalBytes;
1718
@property (nonatomic, readwrite) NSUInteger downloadedBytes;
@@ -31,7 +32,6 @@ - (instancetype)initWithPackage:(CCPackage *)package localURL:(NSURL *)localURL
3132
if (self)
3233
{
3334
self.package = package;
34-
self.packageURL = package.remoteURL;
3535
self.localURL = localURL;
3636
self.fileSize = [self fileSizeOfDownload];
3737
self.tempPath = [[_localURL.path stringByDeletingLastPathComponent] stringByAppendingPathComponent:[self createTempName]];
@@ -83,7 +83,7 @@ - (void)resume
8383

8484
- (NSString *)createTempName
8585
{
86-
return [NSString stringWithFormat:@"%@_%@", [self sha1:[_packageURL absoluteString]], [_package standardIdentifier]];
86+
return [NSString stringWithFormat:@"%@_%@", [self sha1:[_package.remoteURL absoluteString]], [_package standardIdentifier]];
8787
}
8888

8989
- (NSString *)sha1:(NSString *)str
@@ -247,7 +247,7 @@ - (void)removeTempFile
247247

248248
- (NSURLRequest *)createRequest
249249
{
250-
NSMutableURLRequest *result = [NSMutableURLRequest requestWithURL:_packageURL];
250+
NSMutableURLRequest *result = [NSMutableURLRequest requestWithURL:_package.remoteURL];
251251

252252
if ([_delegate respondsToSelector:@selector(request:ofDownload:)])
253253
{
@@ -465,7 +465,7 @@ - (void)closeConnectionAndFileHandle
465465

466466
- (NSString *)description
467467
{
468-
return [NSString stringWithFormat:@"PACKAGE URL: %@, LOCAL URL: %@", _packageURL, _localURL];
468+
return [NSString stringWithFormat:@"PACKAGE URL: %@, LOCAL URL: %@", _package.remoteURL, _localURL];
469469
}
470470

471471
@end

cocos2d/CCPackageDownloadDelegate.h

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,63 @@
55
@protocol CCPackageDownloadDelegate <NSObject>
66

77
@required
8-
// Called when the http request finishes
8+
9+
/**
10+
* Called when the http request finishes successfully
11+
*
12+
* @param download The download object that finished
13+
*/
914
- (void)downloadFinished:(CCPackageDownload *)download;
1015

11-
// Called when the http request fails, for example a timeout, not a 404 returned.
16+
/**
17+
* Called when the http request fails, for example a timeout, not a 404 returned.
18+
*
19+
* @param download The download object that failed
20+
* @param error Error pointer to an error object containing details
21+
*/
1222
- (void)downloadFailed:(CCPackageDownload *)download error:(NSError *)error;
1323

24+
1425
@optional
15-
// Called whenever new bytes are received from the host.
16-
// Returns the bytes downloaded and the total bytes.
17-
// Total bytes can be 0 throughout a download if the response does not contain a Content-Length header.
26+
27+
/**
28+
* Called whenever new bytes are received from the host.
29+
*
30+
* @param download The download object that reported progress
31+
* @param downloadedBytes bytes downloaded
32+
* @param totalBytes Total bytes downloaded. Total bytes can be 0 throughout a download if the response does not contain a Content-Length header.
33+
*/
1834
- (void)downlowdProgress:(CCPackageDownload *)download downloadedBytes:(NSUInteger)downloadedBytes totalBytes:(NSUInteger)totalBytes;
1935

20-
// Return YES if a partial download should be resume if the host accepts range requests otherwise it will start over
21-
// Return NO if the download should start over
22-
// This method will only be invoked if there is a downloaded file
23-
// If not implemented the default is as if returned YES
36+
37+
/**
38+
* Return YES if a download should be resumed. If not implemented YES is default.
39+
* Return NO if the download should start over.
40+
* This method will only be invoked if there is a downloaded file
41+
*
42+
* @param download The download object that should be resumed
43+
*
44+
* @return whether a download should be resumed(YES) or started over(NO)
45+
*/
2446
- (BOOL)shouldResumeDownload:(CCPackageDownload *)download;
2547

26-
// Return whether a completed download with the same filename should be overwritten.
48+
/**
49+
* Return whether a completed download with the same filename should be overwritten.
50+
* If not implemented default is NO.
51+
*
52+
* @param download The download object which downloaded file should be overwritten.
53+
*
54+
* @return whether an already downloaded file should be overwritten(YES) or started over(NO)
55+
*/
2756
- (BOOL)shouldOverwriteDownloadedFile:(CCPackageDownload *)download;
2857

29-
// Provides the request before it is sent to let delegate adjust headers etc.
30-
// If there is a partial download which should be resumed a Range header will be set after this invocation.
58+
/**
59+
* Provides the request before it is sent to let delegate adjust headers etc.
60+
* If there is a partial download which should be resumed a Range header will be set after this invocation.
61+
*
62+
* @param request The request object that will be used for the download
63+
* @param download The download object which will start with the given request
64+
*/
3165
- (void)request:(NSMutableURLRequest *)request ofDownload:(CCPackageDownload *)download;
3266

3367
@end

0 commit comments

Comments
 (0)