-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathjsb.d.ts
500 lines (466 loc) · 21.3 KB
/
jsb.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/**
* API for jsb module
* Author: haroel
* Homepage: https://github.com/haroel/creatorexDTS
*/
declare namespace jsb{
export module reflection{
/**
* https://docs.cocos.com/creator/manual/zh/advanced-topics/java-reflection.html
* call OBJC/Java static methods
*
* @param className
* @param methodName
* @param methodSignature
* @param parameters
*/
export function callStaticMethod (className: string, methodName: string, methodSignature: string, ...parameters:any): any;
}
/**
* 下载任务对象
*/
export type DownloaderTask = { requestURL: string, storagePath: string, identifier: string };
/**
* Http file downloader for jsb!
*/
export class Downloader{
/**
* create a download task
* @param requestURL
* @param storagePath
* @param identifier
*/
createDownloadFileTask (requestURL:string, storagePath:string, identifier?:string): DownloaderTask;
setOnFileTaskSuccess (onSucceed: (task: DownloaderTask) => void): void;
setOnTaskProgress (onProgress: (task: DownloaderTask, bytesReceived: number, totalBytesReceived: number, totalBytesExpected: number) => void): void;
setOnTaskError (onError: (task: DownloaderTask, errorCode: number, errorCodeInternal: number, errorStr: string) => void): void;
}
export interface ManifestAsset {
md5: string;
path: string;
compressed: boolean;
size: number;
downloadState: number;
}
export class Manifest {
constructor (manifestUrl: string);
constructor (content: string, manifestRoot: string);
parseFile (manifestUrl: string): void;
parseJSONString (content: string, manifestRoot: string): void;
getManifestRoot (): string;
getManifestFileUrl (): string;
getVersionFileUrl (): string;
getSearchPaths (): [string];
getVersion (): string;
getPackageUrl (): boolean;
setUpdating (isUpdating: boolean): void;
isUpdating (): boolean;
isVersionLoaded (): boolean;
isLoaded (): boolean;
}
export class EventAssetsManager {
// EventCode
static ERROR_NO_LOCAL_MANIFEST: number;
static ERROR_DOWNLOAD_MANIFEST: number;
static ERROR_PARSE_MANIFEST: number;
static NEW_VERSION_FOUND: number;
static ALREADY_UP_TO_DATE: number;
static UPDATE_PROGRESSION: number;
static ASSET_UPDATED: number;
static ERROR_UPDATING: number;
static UPDATE_FINISHED: number;
static UPDATE_FAILED: number;
static ERROR_DECOMPRESS: number;
constructor (eventName: string, manager: AssetsManager, eventCode: number,
assetId?: string, message?: string, curleCode?: number, curlmCode?: number);
getAssetsManagerEx (): AssetsManager;
isResuming (): boolean;
getDownloadedFiles (): number;
getDownloadedBytes (): number;
getTotalFiles (): number;
getTotalBytes (): number;
getPercent (): number;
getPercentByFile (): number;
getEventCode (): number;
getMessage (): string;
getAssetId (): string;
getCURLECode (): number;
getCURLMCode (): number;
}
export module AssetsManager {
export enum State {
UNINITED,
UNCHECKED,
PREDOWNLOAD_VERSION,
DOWNLOADING_VERSION,
VERSION_LOADED,
PREDOWNLOAD_MANIFEST,
DOWNLOADING_MANIFEST,
MANIFEST_LOADED,
NEED_UPDATE,
READY_TO_UPDATE,
UPDATING,
UNZIPPING,
UP_TO_DATE,
FAIL_TO_UPDATE,
}
}
export class AssetsManager {
constructor (manifestUrl: string, storagePath: string, versionCompareHandle?: (versionA: string, versionB: string) => number);
static create (manifestUrl: string, storagePath: string): AssetsManager;
getState (): AssetsManager.State;
getStoragePath (): string
getMaxConcurrentTask (): number;
// setMaxConcurrentTask (max: number): void; // actually not supported
checkUpdate (): void;
prepareUpdate (): void;
update (): void;
isResuming (): boolean;
getDownloadedFiles (): number;
getDownloadedBytes (): number;
getTotalFiles (): number;
getTotalBytes (): number;
downloadFailedAssets (): void;
getLocalManifest (): Manifest;
loadLocalManifest (manifestUrl: string): boolean;
loadLocalManifest (localManifest: Manifest, storagePath: string): boolean;
getRemoteManifest (): Manifest;
loadRemoteManifest (remoteManifest: Manifest): boolean;
/**
* Setup your own version compare handler, versionA and B is versions in string.
* if the return value greater than 0, versionA is greater than B,
* if the return value equals 0, versionA equals to B,
* if the return value smaller than 0, versionA is smaller than B.
*/
setVersionCompareHandle (versionCompareHandle?: (versionA: string, versionB: string) => number): void;
/**
* Setup the verification callback, Return true if the verification passed, otherwise return false
*/
setVerifyCallback (verifyCallback: (path: string, asset: ManifestAsset) => boolean): void;
setEventCallback (eventCallback: (event: EventAssetsManager) => void): void;
}
/**
* FileUtils Helper class to handle file operations.
*/
export module fileUtils{
/**
* Checks whether the path is an absolute path.
*
* @note On Android, if the parameter passed in is relative to "@assets/", this method will treat it as an absolute path.
* Also on Blackberry, path starts with "app/native/Resources/" is treated as an absolute path.
*
* @param path The path that needs to be checked.
* @return True if it's an absolute path, false if not.
*/
export function isAbsolutePath (path:string):boolean;
/** Returns the fullpath for a given filename.
First it will try to get a new filename from the "filenameLookup" dictionary.
If a new filename can't be found on the dictionary, it will use the original filename.
Then it will try to obtain the full path of the filename using the FileUtils search rules: resolutions, and search paths.
The file search is based on the array element order of search paths and resolution directories.
For instance:
We set two elements("/mnt/sdcard/", "internal_dir/") to search paths vector by setSearchPaths,
and set three elements("resources-ipadhd/", "resources-ipad/", "resources-iphonehd")
to resolutions vector by setSearchResolutionsOrder. The "internal_dir" is relative to "Resources/".
If we have a file named 'sprite.png', the mapping in fileLookup dictionary contains `key: sprite.png -> value: sprite.pvr.gz`.
Firstly, it will replace 'sprite.png' with 'sprite.pvr.gz', then searching the file sprite.pvr.gz as follows:
/mnt/sdcard/resources-ipadhd/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/resources-ipad/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/resources-iphonehd/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/sprite.pvr.gz (if not found, search next)
internal_dir/resources-ipadhd/sprite.pvr.gz (if not found, search next)
internal_dir/resources-ipad/sprite.pvr.gz (if not found, search next)
internal_dir/resources-iphonehd/sprite.pvr.gz (if not found, search next)
internal_dir/sprite.pvr.gz (if not found, return "sprite.png")
If the filename contains relative path like "gamescene/uilayer/sprite.png",
and the mapping in fileLookup dictionary contains `key: gamescene/uilayer/sprite.png -> value: gamescene/uilayer/sprite.pvr.gz`.
The file search order will be:
/mnt/sdcard/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/gamescene/uilayer/sprite.pvr.gz (if not found, search next)
internal_dir/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)
internal_dir/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)
internal_dir/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)
internal_dir/gamescene/uilayer/sprite.pvr.gz (if not found, return "gamescene/uilayer/sprite.png")
If the new file can't be found on the file system, it will return the parameter filename directly.
This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable,
you might need to load different resources for a given file in the different platforms.
@since v2.1
*/
export function fullPathForFilename (filename:string):string;
/**
* Gets string from a file.
*/
export function getStringFromFile (filename:string):string;
/**
* Removes a file.
*
* @param filepath The full path of the file, it must be an absolute path.
* @return True if the file have been removed successfully, false if not.
*/
export function removeFile (filepath:string):boolean;
/**
* Checks whether the path is a directory.
*
* @param dirPath The path of the directory, it could be a relative or an absolute path.
* @return True if the directory exists, false if not.
*/
export function isDirectoryExist (dirPath:string):boolean;
/**
* Normalize: remove . and ..
* @param filepath
*/
export function normalizePath (filepath:string):string;
/**
* Get default resource root path.
*/
export function getDefaultResourceRootPath ():string;
/**
* Loads the filenameLookup dictionary from the contents of a filename.
*
* @note The plist file name should follow the format below:
*
* @code
* <?xml version="1.0" encoding="UTF-8"?>
* <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
* <plist version="1.0">
* <dict>
* <key>filenames</key>
* <dict>
* <key>sounds/click.wav</key>
* <string>sounds/click.caf</string>
* <key>sounds/endgame.wav</key>
* <string>sounds/endgame.caf</string>
* <key>sounds/gem-0.wav</key>
* <string>sounds/gem-0.caf</string>
* </dict>
* <key>metadata</key>
* <dict>
* <key>version</key>
* <integer>1</integer>
* </dict>
* </dict>
* </plist>
* @endcode
* @param filename The plist file name.
*
@since v2.1
* @js loadFilenameLookup
* @lua loadFilenameLookup
*/
export function loadFilenameLookup (filepath:string):void;
/** Checks whether to pop up a message box when failed to load an image.
* @return True if pop up a message box when failed to load an image, false if not.
*/
export function isPopupNotify ():boolean;
/**
* Sets whether to pop-up a message box when failed to load an image.
*/
export function setPopupNotify (notify:boolean):void;
// Converts the contents of a file to a ValueVector.
// This method is used internally.
export function getValueVectorFromFile (filepath:string):Array<any>;
/**
* Gets the array of search paths.
*
* @return The array of search paths which may contain the prefix of default resource root path.
* @note In best practise, getter function should return the value of setter function passes in.
* But since we should not break the compatibility, we keep using the old logic.
* Therefore, If you want to get the original search paths, please call 'getOriginalSearchPaths()' instead.
* @see fullPathForFilename(const char*).
* @lua NA
*/
export function getSearchPaths ():Array<string>;
/**
*
* @param filepath
*/
export function getFileDir (filepath:string):string;
/**
* write a ValueMap into a plist file
*
*@param dict the ValueMap want to save (key,value)
*@param fullPath The full path to the file you want to save a string
*@return bool
*/
export function writeToFile ( valueMap:any ):boolean;
/**
* Gets the original search path array set by 'setSearchPaths' or 'addSearchPath'.
* @return The array of the original search paths
*/
export function getOriginalSearchPaths ():Array<string>;
/**
* List all files in a directory.
*
* @param dirPath The path of the directory, it could be a relative or an absolute path.
* @return File paths in a string vector
*/
export function listFiles (filepath:string):Array<string>;
/**
* Converts the contents of a file to a ValueMap.
* @param filename The filename of the file to gets content.
* @return ValueMap of the file contents.
* @note This method is used internally.
*/
export function getValueMapFromFile (filepath:string):any;
/**
* Retrieve the file size.
*
* @note If a relative path was passed in, it will be inserted a default root path at the beginning.
* @param filepath The path of the file, it could be a relative or absolute path.
* @return The file size.
*/
export function getFileSize (filepath:string):number;
/** Converts the contents of a file to a ValueMap.
* This method is used internally.
*/
export function getValueMapFromData (filedata:string,filesize:number):any;
/**
* Removes a directory.
*
* @param dirPath The full path of the directory, it must be an absolute path.
* @return True if the directory have been removed successfully, false if not.
*/
export function removeDirectory (dirPath:string):boolean;
/**
* Sets the array of search paths.
*
* You can use this array to modify the search path of the resources.
* If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.
*
* @note This method could access relative path and absolute path.
* If the relative path was passed to the vector, FileUtils will add the default resource directory before the relative path.
* For instance:
* On Android, the default resource root path is "@assets/".
* If "/mnt/sdcard/" and "resources-large" were set to the search paths vector,
* "resources-large" will be converted to "@assets/resources-large" since it was a relative path.
*
* @param searchPaths The array contains search paths.
* @see fullPathForFilename(const char*)
* @since v2.1
* In js:var setSearchPaths(var jsval);
* @lua NA
*/
export function setSearchPaths ( searchPath:Array<string>):void;
/**
* write a string into a file
*
* @param dataStr the string want to save
* @param fullPath The full path to the file you want to save a string
* @return bool True if write success
*/
export function writeStringToFile (dataStr:string,fullPath:string):boolean;
/**
* Sets the array that contains the search order of the resources.
*
* @param searchResolutionsOrder The source array that contains the search order of the resources.
* @see getSearchResolutionsOrder(), fullPathForFilename(const char*).
* @since v2.1
* In js:var setSearchResolutionsOrder(var jsval)
* @lua NA
*/
export function setSearchResolutionsOrder (searchResolutionsOrder:Array<string>):void;
/**
* Append search order of the resources.
*
* @see setSearchResolutionsOrder(), fullPathForFilename().
* @since v2.1
*/
export function addSearchResolutionsOrder (order:string,front:boolean):void;
/**
* Add search path.
*
* @since v2.1
*/
export function addSearchPath (path:string,front:boolean):void;
/**
* write ValueVector into a plist file
*
*@param vecData the ValueVector want to save
*@param fullPath The full path to the file you want to save a string
*@return bool
*/
export function writeValueVectorToFile (vecData:Array<any>,fullPath:string):boolean;
/**
* Checks whether a file exists.
*
* @note If a relative path was passed in, it will be inserted a default root path at the beginning.
* @param filename The path of the file, it could be a relative or absolute path.
* @return True if the file exists, false if not.
*/
export function isFileExist (filename:string):boolean;
/**©∫
* Purges full path caches.
*/
export function purgeCachedEntries ():void;
/**
* Gets full path from a file name and the path of the relative file.
* @param filename The file name.
* @param relativeFile The path of the relative file.
* @return The full path.
* e.g. filename: hello.png, pszRelativeFile: /User/path1/path2/hello.plist
* Return: /User/path1/path2/hello.pvr (If there a a key(hello.png)-value(hello.pvr) in FilenameLookup dictionary. )
*
*/
export function fullPathFromRelativeFile (filename:string,relativeFile:string):string;
/**
* Windows fopen can't support UTF-8 filename
* Need convert all parameters fopen and other 3rd-party libs
*
* @param filenameUtf8 std::string name file for conversion from utf-8
* @return std::string ansi filename in current locale
*/
export function getSuitableFOpen (filenameUtf8:string):string;
/**
* write ValueMap into a plist file
*
*@param dict the ValueMap want to save
*@param fullPath The full path to the file you want to save a string
*@return bool
*/
export function writeValueMapToFile (dict:any,fullPath:string):string;
/**
* Gets filename extension is a suffix (separated from the base filename by a dot) in lower case.
* Examples of filename extensions are .png, .jpeg, .exe, .dmg and .txt.
* @param filePath The path of the file, it could be a relative or absolute path.
* @return suffix for filename in lower case or empty if a dot not found.
*/
export function getFileExtension (filePath:string):string;
/**
* Sets writable path.
*/
export function setWritablePath (writablePath:string):void;
/**
* Set default resource root path.
*/
export function setDefaultResourceRootPath (filepath:string):void;
/**
* Gets the array that contains the search order of the resources.
*
* @see setSearchResolutionsOrder(const std::vector<std::string>&), fullPathForFilename(const char*).
* @since v2.1
* @lua NA
*/
export function getSearchResolutionsOrder ():Array<string>;
/**
* Creates a directory.
*
* @param dirPath The path of the directory, it must be an absolute path.
* @return True if the directory have been created successfully, false if not.
*/
export function createDirectory (dirPath:string):string;
/**
* List all files recursively in a directory.
*
* @param dirPath The path of the directory, it could be a relative or an absolute path.
* @return File paths in a string vector
*/
export function listFilesRecursively (dirPath:string, files:Array<string>):void;
/**
* Gets the writable path.
* @return The path that can be write/read a file in
*/
export function getWritablePath ():string;
}
}