Improve Pipeline / CCLoader APIs

This commit is contained in:
pandamicro
2016-02-24 19:52:28 +08:00
parent f4ae47f300
commit f0c7b7218a
5 changed files with 42 additions and 3 deletions
+1 -1
View File
@@ -259,7 +259,7 @@ var game = /** @lends cc.game# */{
// Load game scripts
var jsList = config[CONFIG_KEY.jsList];
if (jsList) {
if (jsList && jsList.length > 0) {
cc.loader.load(jsList, function (err) {
if (err) throw new Error(JSON.stringify(err));
self._prepared = true;
+18
View File
@@ -42,6 +42,24 @@ cc.loader = new Pipeline([
JS.mixin(cc.loader, {
/**
* The downloader in cc.loader's pipeline, it's by default the first pipe.
* It's used to download files with several handlers: pure text, image, script, audio, font, uuid.
* You can add your own download function with addDownloadHandlers
* @property downloader
* @type {Object}
*/
downloader: downloader,
/**
* The downloader in cc.loader's pipeline, it's by default the second pipe.
* It's used to parse downloaded content with several handlers: JSON, image, plist, fnt, uuid.
* You can add your own download function with addLoadHandlers
* @property loader
* @type {Object}
*/
loader: loader,
/**
* Get XMLHttpRequest.
* @returns {XMLHttpRequest}
+4 -1
View File
@@ -316,6 +316,8 @@ var defaultMap = {
'default' : downloadText
};
var ID = 'Downloader';
/**
* The downloader pipe, it can download several types of files:
* 1. Text
@@ -338,7 +340,7 @@ var defaultMap = {
* @param {Object} extMap Custom supported types with corresponded handler
*/
var Downloader = function (extMap) {
this.id = 'Downloader';
this.id = ID;
this.async = true;
this.pipeline = null;
this.maxConcurrent = 2;
@@ -347,6 +349,7 @@ var Downloader = function (extMap) {
this.extMap = JS.mixin(extMap, defaultMap);
};
Downloader.ID = ID;
JS.mixin(Downloader.prototype, {
/**
* Add custom supported types handler or modify existing type handler.
+4 -1
View File
@@ -182,6 +182,8 @@ var defaultMap = {
'default' : loadNothing
};
var ID = 'Loader';
/**
* The loader pipe, it can load several types of files:
* 1. Images
@@ -206,12 +208,13 @@ var defaultMap = {
* @param {Object} extMap Custom supported types with corresponded handler
*/
var Loader = function (extMap) {
this.id = 'Loader';
this.id = ID;
this.async = true;
this.pipeline = null;
this.extMap = JS.mixin(extMap, defaultMap);
};
Loader.ID = ID;
JS.mixin(Loader.prototype, {
/**
* Add custom supported types handler or modify existing type handler.
+15
View File
@@ -202,6 +202,14 @@ Pipeline.ItemState = new cc.Enum(ItemState);
Pipeline.getXMLHttpRequest = getXMLHttpRequest;
JS.mixin(Pipeline.prototype, {
/**
* Insert a new pipe at the given index of the pipeline.
* A pipe must contain an `id` in string and a `handle` function, the id must be unique in the pipeline.
*
* @method insertPipe
* @param {Object} pipe The pipe to be inserted
* @param {Number} index The index to insert
*/
insertPipe: function (pipe, index) {
// Must have handle and id, handle for flow, id for state flag
if (!pipe.handle || !pipe.id) {
@@ -225,6 +233,13 @@ JS.mixin(Pipeline.prototype, {
}
},
/**
* Add a new pipe at the end of the pipeline.
* A pipe must contain an `id` in string and a `handle` function, the id must be unique in the pipeline.
*
* @method appendPipe
* @param {Object} pipe The pipe to be appended
*/
appendPipe: function (pipe) {
// Must have handle and id, handle for flow, id for state flag
if (!pipe.handle || !pipe.id) {