Skip to content

Commit

Permalink
Merge pull request cocos2d#12832 from pandamicro/jsb_loader_fix
Browse files Browse the repository at this point in the history
Fix jsb loader
  • Loading branch information
pandamicro committed Jul 14, 2015
2 parents 365c51c + 09775d6 commit 48376db
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
30 changes: 19 additions & 11 deletions cocos/scripting/js-bindings/script/jsb_boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
},

/**
Expand Down Expand Up @@ -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];
}

};
Expand Down
40 changes: 26 additions & 14 deletions cocos/scripting/js-bindings/script/jsb_loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
//

cc._emptyLoader = {
load : function(realUrl, url){
load : function(realUrl, url, res, cb){
cb && cb(null, null);
return null;
}
};
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

0 comments on commit 48376db

Please sign in to comment.