Merge pull request #12832 from pandamicro/jsb_loader_fix

Fix jsb loader
This commit is contained in:
pandamicro 2015-07-14 15:25:24 +08:00
commit 48376db17a
2 changed files with 45 additions and 25 deletions

View File

@ -625,15 +625,18 @@ cc.loader = {
}
var basePath = loader.getBasePath ? loader.getBasePath() : self.resPath;
var realUrl = self.getUrl(basePath, url);
var data = loader.load(realUrl, url);
if (data) {
self.cache[url] = data;
cb(null, data);
} else {
self.cache[url] = null;
delete self.cache[url];
cb();
}
loader.load(realUrl, url, item, function (err, data) {
if (err) {
cc.log(err);
self.cache[url] = null;
delete self.cache[url];
cb();
} else {
self.cache[url] = data;
cb(null, data);
}
});
},
/**
@ -776,13 +779,18 @@ cc.loader = {
* Release the cache of resource by url.
* @param url
*/
release : function(url){//do nothing in jsb
release : function(url){
var cache = this.cache;
delete cache[url];
},
/**
* Resource cache of all resources.
*/
releaseAll : function(){//do nothing in jsb
releaseAll : function(){
var locCache = this.cache;
for (var key in locCache)
delete locCache[key];
}
};

View File

@ -27,7 +27,8 @@
//
cc._emptyLoader = {
load : function(realUrl, url){
load : function(realUrl, url, res, cb){
cb && cb(null, null);
return null;
}
};
@ -39,21 +40,25 @@ cc.loader.register([
cc._emptyLoader);
cc._txtLoader = {
load : function(realUrl, url){
return jsb.fileUtils.getStringFromFile(realUrl);
load : function(realUrl, url, res, cb){
var result = jsb.fileUtils.getStringFromFile(realUrl);
cb && cb(null, result);
return result;
}
};
cc.loader.register(["txt", "xml", "vsh", "fsh", "tmx", "tsx"], cc._txtLoader);
cc._jsonLoader = {
load : function(realUrl, url){
var data = jsb.fileUtils.getStringFromFile(realUrl);
load : function(realUrl, url, res, cb){
var data = jsb.fileUtils.getStringFromFile(realUrl), result;
try{
return JSON.parse(data);
result = JSON.parse(data);
}catch(e){
cc.error(e);
return null;
result = null;
}
cb && cb(null, result);
return result;
}
};
cc.loader.register(["json", "ExportJson"], cc._jsonLoader);
@ -73,16 +78,20 @@ cc._imgLoader = {
cc.loader.register(["png", "jpg", "bmp","jpeg","gif"], cc._imgLoader);
cc._plistLoader = {
load : function(realUrl, url){
load : function(realUrl, url, res, cb){
var content = jsb.fileUtils.getStringFromFile(realUrl);
return cc.plistParser.parse(content);
var result = cc.plistParser.parse(content);
cb && cb(null, result);
return result;
}
};
cc.loader.register(["plist"], cc._plistLoader);
cc._binaryLoader = {
load : function(realUrl, url){
return cc.loader.loadBinarySync(realUrl);
load : function(realUrl, url, res, cb){
var result = cc.loader.loadBinarySync(realUrl);
cb && cb(null, result);
return result;
}
};
cc.loader.register(["ccbi"], cc._binaryLoader);
@ -166,9 +175,12 @@ cc._fntLoader = {
return fnt;
},
load : function(realUrl, url){
var data = jsb.fileUtils.getStringFromFile(realUrl);
return this.parseFnt(data, url);
load : function(realUrl, url, res, cb){
var data = jsb.fileUtils.getStringFromFile(realUrl), result = null;
if (data)
result = this.parseFnt(data, url);
cb && cb(null, result);
return result;
}
};
cc.loader.register(["fnt"], cc._fntLoader);