Skip to content

Commit 56710d4

Browse files
author
pandamicro
committed
Async loading project.json file, avoid chrome warning
1 parent 35d19b7 commit 56710d4

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

CCBoot.js

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,6 +2262,7 @@ cc.game = /** @lends cc.game# */{
22622262

22632263
// states
22642264
_paused: true,//whether the game is paused
2265+
_configLoaded: false,//whether config loaded
22652266
_prepareCalled: false,//whether the prepare function has been called
22662267
_prepared: false,//whether the engine has prepared
22672268
_rendererInitialized: false,
@@ -2397,7 +2398,13 @@ cc.game = /** @lends cc.game# */{
23972398
config = self.config,
23982399
CONFIG_KEY = self.CONFIG_KEY;
23992400

2400-
this._loadConfig();
2401+
// Config loaded
2402+
if (!this._configLoaded) {
2403+
this._loadConfig(function () {
2404+
self.prepare(cb);
2405+
});
2406+
return;
2407+
}
24012408

24022409
// Already prepared
24032410
if (this._prepared) {
@@ -2553,46 +2560,42 @@ cc.game = /** @lends cc.game# */{
25532560
},
25542561

25552562
// @Game loading section
2556-
_loadConfig: function () {
2563+
_loadConfig: function (cb) {
25572564
// Load config
2558-
// Already loaded
2559-
if (this.config) {
2560-
this._initConfig(this.config);
2561-
return;
2562-
}
2563-
// Load from document.ccConfig
2564-
if (document["ccConfig"]) {
2565-
this._initConfig(document["ccConfig"]);
2565+
var config = this.config || document["ccConfig"];
2566+
// Already loaded or Load from document.ccConfig
2567+
if (config) {
2568+
this._initConfig(config);
2569+
cb && cb();
25662570
}
25672571
// Load from project.json
25682572
else {
2569-
var data = {};
2570-
try {
2571-
var cocos_script = document.getElementsByTagName('script');
2572-
for(var i = 0; i < cocos_script.length; i++){
2573-
var _t = cocos_script[i].getAttribute('cocos');
2574-
if(_t === '' || _t) {
2575-
break;
2576-
}
2577-
}
2578-
var _src, txt, _resPath;
2579-
if(i < cocos_script.length){
2580-
_src = cocos_script[i].src;
2581-
if(_src){
2582-
_resPath = /(.*)\//.exec(_src)[0];
2583-
cc.loader.resPath = _resPath;
2584-
_src = cc.path.join(_resPath, 'project.json');
2585-
}
2586-
txt = cc.loader._loadTxtSync(_src);
2573+
var cocos_script = document.getElementsByTagName('script');
2574+
for (var i = 0; i < cocos_script.length; i++) {
2575+
var _t = cocos_script[i].getAttribute('cocos');
2576+
if (_t === '' || _t) {
2577+
break;
25872578
}
2588-
if(!txt){
2589-
txt = cc.loader._loadTxtSync("project.json");
2579+
}
2580+
var self = this;
2581+
var loaded = function (err, txt) {
2582+
var data = JSON.parse(txt);
2583+
self._initConfig(data);
2584+
cb && cb();
2585+
};
2586+
var _src, txt, _resPath;
2587+
if (i < cocos_script.length) {
2588+
_src = cocos_script[i].src;
2589+
if (_src) {
2590+
_resPath = /(.*)\//.exec(_src)[0];
2591+
cc.loader.resPath = _resPath;
2592+
_src = cc.path.join(_resPath, 'project.json');
25902593
}
2591-
data = JSON.parse(txt);
2592-
} catch (e) {
2593-
cc.log("Failed to read or parse project.json");
2594+
cc.loader.loadTxt(_src, loaded);
2595+
}
2596+
if (!txt) {
2597+
cc.loader.loadTxt("project.json", loaded);
25942598
}
2595-
this._initConfig(data);
25962599
}
25972600
},
25982601

@@ -2605,6 +2608,7 @@ cc.game = /** @lends cc.game# */{
26052608
config[CONFIG_KEY.engineDir] = config[CONFIG_KEY.engineDir] || "frameworks/cocos2d-html5";
26062609
if (config[CONFIG_KEY.debugMode] == null)
26072610
config[CONFIG_KEY.debugMode] = 0;
2611+
config[CONFIG_KEY.exposeClassName] = !!config[CONFIG_KEY.exposeClassName];
26082612
config[CONFIG_KEY.frameRate] = config[CONFIG_KEY.frameRate] || 60;
26092613
if (config[CONFIG_KEY.renderMode] == null)
26102614
config[CONFIG_KEY.renderMode] = 0;
@@ -2615,6 +2619,7 @@ cc.game = /** @lends cc.game# */{
26152619
if (modules && modules.indexOf("core") < 0) modules.splice(0, 0, "core");
26162620
modules && (config[CONFIG_KEY.modules] = modules);
26172621
this.config = config;
2622+
this._configLoaded = true;
26182623
},
26192624

26202625
_initRenderer: function (width, height) {

0 commit comments

Comments
 (0)