Skip to content

Commit 1d091c2

Browse files
committed
Revert "Remove _loadTxtSync, Because chrome(40) deprecated this API"
1 parent 223b5d3 commit 1d091c2

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

CCBoot.js

+31-27
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,26 @@ cc.loader = /** @lends cc.loader# */{
689689
});
690690
}
691691
},
692+
_loadTxtSync: function (url) {
693+
if (!cc._isNodeJs) {
694+
var xhr = this.getXMLHttpRequest();
695+
xhr.open("GET", url, false);
696+
if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
697+
// IE-specific logic here
698+
xhr.setRequestHeader("Accept-Charset", "utf-8");
699+
} else {
700+
if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=utf-8");
701+
}
702+
xhr.send(null);
703+
if (!xhr.readyState == 4 || xhr.status != 200) {
704+
return null;
705+
}
706+
return xhr.responseText;
707+
} else {
708+
var fs = require("fs");
709+
return fs.readFileSync(url).toString();
710+
}
711+
},
692712

693713
loadCsb: function(url, cb){
694714
var xhr = new XMLHttpRequest();
@@ -1944,7 +1964,6 @@ cc.game = /** @lends cc.game# */{
19441964
DEBUG_MODE_INFO_FOR_WEB_PAGE: 4,
19451965
DEBUG_MODE_WARN_FOR_WEB_PAGE: 5,
19461966
DEBUG_MODE_ERROR_FOR_WEB_PAGE: 6,
1947-
_ready: false,
19481967

19491968
EVENT_HIDE: "game_on_hide",
19501969
EVENT_SHOW: "game_on_show",
@@ -2082,12 +2101,6 @@ cc.game = /** @lends cc.game# */{
20822101
* Run game.
20832102
*/
20842103
run: function (id) {
2085-
if(this._ready === false){
2086-
this._ready = id === undefined ? true : id;
2087-
return;
2088-
}else if(typeof this._ready !== "boolean"){
2089-
id = this._ready;
2090-
}
20912104
var self = this;
20922105
var _run = function () {
20932106
if (id) {
@@ -2130,13 +2143,7 @@ cc.game = /** @lends cc.game# */{
21302143
cfg[CONFIG_KEY.frameRate] = cfg[CONFIG_KEY.frameRate] || 60;
21312144
if(cfg[CONFIG_KEY.renderMode] == null)
21322145
cfg[CONFIG_KEY.renderMode] = 1;
2133-
//init debug move to CCDebugger
2134-
cc._initSys(cfg, CONFIG_KEY);
2135-
self.config = cfg;
2136-
if(cc.game._ready !== false){
2137-
self._ready = true;
2138-
cc.game.run();
2139-
}
2146+
return cfg;
21402147
};
21412148
if (document["ccConfig"]) {
21422149
self.config = _init(document["ccConfig"]);
@@ -2147,31 +2154,28 @@ cc.game = /** @lends cc.game# */{
21472154
var _t = cocos_script[i].getAttribute('cocos');
21482155
if(_t == '' || _t){break;}
21492156
}
2150-
var _src, _resPath;
2157+
var _src, txt, _resPath;
21512158
if(i < cocos_script.length){
21522159
_src = cocos_script[i].src;
21532160
if(_src){
21542161
_resPath = /(.*)\//.exec(_src)[0];
21552162
cc.loader.resPath = _resPath;
21562163
_src = cc.path.join(_resPath, 'project.json');
21572164
}
2158-
cc.loader.loadTxt(_src, function(err, txt){
2159-
if(err)
2160-
return cc.error(err);
2161-
_init(JSON.parse(txt) || {});
2162-
});
2163-
}else{
2164-
cc.loader.loadTxt("project.json", function(err, txt){
2165-
if(err)
2166-
return cc.error(err);
2167-
_init(JSON.parse(txt) || {});
2168-
});
2165+
txt = cc.loader._loadTxtSync(_src);
2166+
}
2167+
if(!txt){
2168+
txt = cc.loader._loadTxtSync("project.json");
21692169
}
2170+
var data = JSON.parse(txt);
2171+
self.config = _init(data || {});
21702172
} catch (e) {
21712173
cc.log("Failed to read or parse project.json");
2172-
_init({});
2174+
self.config = _init({});
21732175
}
21742176
}
2177+
//init debug move to CCDebugger
2178+
cc._initSys(self.config, CONFIG_KEY);
21752179
},
21762180

21772181
//cache for js and module that has added into jsList to be loaded.

0 commit comments

Comments
 (0)