Last active
March 12, 2020 00:36
-
-
Save davyzhang/2812fe55366a1e08094460874a88708a to your computer and use it in GitHub Desktop.
jsb.assetsmanager.d.ts cocos creator的 jsb.assetsmanager ts定义文件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The namespace for jsb exclusive APIs, all APIs in this namespace should never be used in Web engine. | |
* So please check whether the running environment is native or not before any usage. | |
* @namespace | |
* @name jsb | |
* @example | |
* | |
* if(cc.sys.isNative) { | |
* cc.log(cc.fileUtils.fullPathForFilename("test.js")); | |
* } | |
*/ | |
declare namespace jsb { | |
// TODO: This is probably a bad idea to declare these as enums (since they clearly are not TS enums), but let's try it out and at least see if the values resolve properly | |
export enum DiffType { | |
ADDED, | |
DELETED, | |
MODIFIED | |
} | |
export enum DownloadState { | |
UNSTARTED, | |
DOWNLOADING, | |
SUCCESSED, | |
UNMARKED | |
} | |
export enum EventCode { | |
ERROR_NO_LOCAL_MANIFEST, | |
ERROR_DOWNLOAD_MANIFEST, | |
ERROR_PARSE_MANIFEST, | |
NEW_VERSION_FOUND, | |
ALREADY_UP_TO_DATE, | |
UPDATE_PROGRESSION, | |
ASSET_UPDATED, | |
ERROR_UPDATING, | |
UPDATE_FINISHED, | |
UPDATE_FAILED, | |
ERROR_DECOMPRESS | |
} | |
export enum ErrorCode { | |
CREATE_FILE, | |
NETWORK, | |
NO_NEW_VERSION, | |
UNCOMPRESS | |
} | |
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 | |
} | |
/** | |
* @class | |
*/ | |
//jsb.EventAssetsManager = cc.Class.extend(/** @lends jsb.EventAssetsManager# */{ | |
export class EventAssetsManager extends cc.Class { | |
static ERROR_NO_LOCAL_MANIFEST = 0; | |
static ERROR_DOWNLOAD_MANIFEST = 1; | |
static ERROR_PARSE_MANIFEST = 2; | |
static NEW_VERSION_FOUND = 3; | |
static ALREADY_UP_TO_DATE = 4; | |
static UPDATE_PROGRESSION = 5; | |
static ASSET_UPDATED = 6; | |
static ERROR_UPDATING = 7; | |
static UPDATE_FINISHED = 8; | |
static UPDATE_FAILED = 9; | |
static ERROR_DECOMPRESS = 10; | |
/** | |
* @function EventAssetsManager | |
* @constructor | |
* @param {String} eventName | |
* @param {AssetsManager} manager | |
* @param {EventCode} code | |
* @param {String} [assetId] | |
* @param {String} [message] | |
* @param {number} [curle_code] | |
* @param {number} [curlm_code] | |
*/ | |
public constructor( | |
eventName: string, | |
manager: AssetsManager, | |
code: EventCode, | |
assetId?: string, | |
message?: string, | |
curle_code?: number, | |
curlm_code?: number); | |
/** | |
* | |
* @return {AssetsManager} | |
*/ | |
public getAssetsManager(): AssetsManager; | |
/** | |
* | |
* @return {String} | |
*/ | |
public getAssetId(): string; | |
/** | |
* | |
* @return {int} | |
*/ | |
public getCURLECode(): number; | |
/** | |
* | |
* @return {String} | |
*/ | |
public getMessage(): string; | |
/** | |
* | |
* @return {int} | |
*/ | |
public getCURLMCode(): number; | |
/** | |
* | |
* @return {number} | |
*/ | |
public getPercentByFile(): number; | |
/** | |
* | |
* @return {EventCode} | |
*/ | |
public getEventCode(): EventCode; | |
/** | |
* | |
* @return {number} | |
*/ | |
public getPercent(): number; | |
public getDownloadedFiles(): number | |
public getTotalFiles(): number; | |
public getTotalBytes(): number; | |
public getDownloadedBytes(): number; | |
public isResuming(): number; | |
} | |
/** | |
* @class | |
*/ | |
export class EventListenerAssetsManager extends cc.Class { | |
/** | |
* @function init | |
* @param {AssetsManager} assetsmanager | |
* @param {function} callback | |
* @return {boolean} | |
*/ | |
public init(assetsmanager: AssetsManager, callback: (mgr: EventAssetsManager) => void): boolean; | |
/** | |
* @function create | |
* @param {AssetsManager} assetsmanager | |
* @param {function} callback | |
* @return {EventListenerAssetsManager} | |
*/ | |
public create(assetsmanager: AssetsManager, callback: (mgr: EventAssetsManager) => void): EventListenerAssetsManager; | |
} | |
/** | |
* @class | |
* jsb.AssetsManager is the native AssetsManager for your game resources or scripts. | |
* please refer to this document to know how to use it: http://www.cocos2d-x.org/docs/manual/framework/html5/v3/assets-manager/en | |
* Only available in JSB | |
*/ | |
export class AssetsManager extends cc.Class { | |
/** | |
* Gets the current update state. | |
* @return {State} | |
*/ | |
public getState(): State; | |
/** | |
* Check out if there is a new version of manifest. | |
* You may use this method before updating, then let user determine whether he wants to update resources. | |
*/ | |
public checkUpdate(): void; | |
/** | |
* Prepare the update process, this will cleanup download process flags, fill up download units with temporary manifest or remote manifest | |
*/ | |
public prepareUpdate(): void; | |
/** | |
* Gets storage path. | |
* @return {String} | |
*/ | |
public getStoragePath(): string; | |
/** | |
* Update with the current local manifest. | |
*/ | |
public update(): void; | |
/** | |
* Function for retrieving the local manifest object | |
* @return {jsb.Manifest} | |
*/ | |
public getLocalManifest(): Manifest; | |
/** | |
* Function for retrieving the remote manifest object | |
* @return {jsb.Manifest} | |
*/ | |
public getRemoteManifest(): Manifest; | |
/** | |
* Reupdate all failed assets under the current AssetsManager context | |
*/ | |
public downloadFailedAssets(): void; | |
/** | |
* Create function for creating a new AssetsManager | |
* @param {String}manifestUrl The url for the local manifest file | |
* @param {String}storagePath The storage path for downloaded assets | |
* @return {jsb.AssetsManager} | |
*/ | |
public create(manifestUrl: string, storagePath: string): AssetsManager; | |
/** | |
* Load a custom local manifest object, the local manifest must be loaded already. | |
* You can only manually load local manifest when the update state is UNCHECKED, it will fail once the update process is began. | |
* This API will do the following things: | |
* 1. Reset storage path | |
* 2. Set local storage | |
* 3. Search for cached manifest and compare with the local manifest | |
* 4. Init temporary manifest and remote manifest | |
* If successfully load the given local manifest and inited other manifests, it will return true, otherwise it will return false | |
* @param {jsb.Manifest}localManifest | |
* @param {String}storagePath | |
*/ | |
public loadLocalManifest(localManifest: Manifest, storagePath: string): boolean; | |
/** | |
* Load a local manifest from url. | |
* You can only manually load local manifest when the update state is UNCHECKED, it will fail once the update process is began. | |
* This API will do the following things: | |
* 1. Reset storage path | |
* 2. Set local storage | |
* 3. Search for cached manifest and compare with the local manifest | |
* 4. Init temporary manifest and remote manifest | |
* If successfully load the given local manifest and inited other manifests, it will return true, otherwise it will return false | |
* @param {String}manifestUrl | |
*/ | |
public loadLocalManifest(manifestUrl: string): boolean; | |
/** | |
* Load a custom remote manifest object, the manifest must be loaded already. | |
* You can only manually load remote manifest when the update state is UNCHECKED and local manifest is already inited, it will fail once the update process is began. | |
* @param {Manifest}remoteManifest | |
*/ | |
public loadRemoteManifest(remoteManifest: Manifest): boolean; | |
/** | |
* Gets the current downloaded files count of the update, this will only be available after READY_TO_UPDATE state, under unknown states it will return 0 by default. | |
*/ | |
public getDownloadedFiles(): number; | |
/** | |
* Function for retrieving the max concurrent task count | |
*/ | |
public getMaxConcurrentTask(): number; | |
/** | |
* Gets the total files count to be downloaded of the update, this will only be available after READY_TO_UPDATE state, under unknown states it will return 0 by default. | |
*/ | |
public getTotalFiles(): number; | |
/** | |
* Gets the total byte size to be downloaded of the update, this will only be available after READY_TO_UPDATE state, under unknown states it will return 0 by default. | |
*/ | |
public getTotalBytes(): number; | |
/** | |
* Set the verification function for checking whether downloaded asset is correct, e.g. using md5 verification | |
* @param callback | |
*/ | |
public setVerifyCallback(callback: (path: string, asset: ManifestAsset) => boolean): void; | |
/** | |
* Set the event callback for receiving update process events | |
* @param eventCallback | |
*/ | |
public setEventCallback(callback: (eventAssetsManager: EventAssetsManager) => void): void; | |
/** | |
* Set the handle function for comparing manifests versions | |
* @param callback | |
*/ | |
public setVersionCompareHandle(callback: (localVersion: string, remoteVersion: string) => number): void; | |
/** | |
* Gets the current downloaded byte size of the update, this will only be available after READY_TO_UPDATE state, under unknown states it will return 0 by default. | |
*/ | |
public getDownloadedBytes(): number; | |
/** | |
* Function for setting the max concurrent task count | |
* @param max max task count | |
*/ | |
public setMaxConcurrentTask(max: number): void; | |
/** | |
* Gets whether the current download is resuming previous unfinished job, this will only be available after READY_TO_UPDATE state, under unknown states it will return false by default. | |
*/ | |
public isResuming(): boolean; | |
/** | |
* | |
* @param manifestUrl | |
* @param storagePath | |
*/ | |
public constructor(manifestUrl: string, storagePath: string); | |
/** | |
* | |
* @param manifestUrl | |
* @param storagePath | |
* @param versionCompareHandle | |
*/ | |
public constructor(manifestUrl: string, storagePath: string, versionCompareHandle: (localVersion: string, remoteVersion: string) => number); | |
} | |
/** | |
* @class | |
*/ | |
export class Manifest extends cc.Class { | |
/** | |
* Gets remote manifest file url. | |
* @return {String} | |
*/ | |
public getManifestFileUrl(): string; | |
/** | |
* Check whether the version informations have been fully loaded | |
* @return {boolean} | |
*/ | |
public isVersionLoaded(): boolean; | |
/** | |
* Check whether the manifest have been fully loaded | |
* @return {boolean} | |
*/ | |
public isLoaded(): boolean; | |
/** | |
* Gets remote package url. | |
* @return {String} | |
*/ | |
public getPackageUrl(): string; | |
/** | |
* Gets manifest version. | |
* @return {String} | |
*/ | |
public getVersion(): string; | |
/** | |
* Gets remote version file url. | |
* @return {String} | |
*/ | |
public getVersionFileUrl(): string; | |
/** | |
* Get the manifest root path, normally it should also be the local storage path. | |
*/ | |
public getManifestRoot(): string; | |
/** | |
* Set whether the manifest is being updating | |
* @param updating updating or not | |
*/ | |
public setUpdating(updating: boolean): void; | |
/** | |
* Parse the manifest file information into this manifest | |
* @param manifestUrl url of the local manifest | |
*/ | |
public parseFile(manifestUrl: string): void; | |
/** | |
* Get whether the manifest is being updating | |
*/ | |
public isUpdating(): boolean; | |
/** | |
* Parse the manifest from json string into this manifest | |
* @param {String}content content Json string content | |
* @param {String}manifestRoot manifestRoot The root path of the manifest file (It should be local path, so that we can find assets path relative to the root path) | |
*/ | |
public parseJSONString(content: string, manifestRoot: string): void; | |
/** | |
* Get the search paths list related to the Manifest. | |
*/ | |
public getSearchPaths(): Array<string>; | |
/** | |
* | |
* @param manifestUrl | |
*/ | |
public constructor(manifestUrl: string = ''); | |
/** | |
* | |
* @param content | |
* @param manifestRoot | |
*/ | |
public constructor(content: string, manifestRoot: string); | |
} | |
// TODO: I don't know the best way to represent this, because I can't find a reference in the C++ docs. Just do this for now, fix it later on. | |
/** | |
* jsb.reflection is a bridge to let you invoke Java static functions. | |
* please refer to this document to know how to use it: http://www.cocos2d-x.org/docs/manual/framework/html5/v3/reflection/en | |
* Only available on iOS/Mac/Android platform | |
* @class | |
* @name jsb.reflection | |
*/ | |
export namespace reflection { | |
/** | |
* @function | |
*/ | |
export function callStaticMethod(): void; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moved ERROR_NO_LOCAL_MANIFEST stuff into the AssetsManager bock to fit the scenario better