@@ -2262,6 +2262,7 @@ cc.game = /** @lends cc.game# */{
2262
2262
2263
2263
// states
2264
2264
_paused : true , //whether the game is paused
2265
+ _configLoaded : false , //whether config loaded
2265
2266
_prepareCalled : false , //whether the prepare function has been called
2266
2267
_prepared : false , //whether the engine has prepared
2267
2268
_rendererInitialized : false ,
@@ -2397,7 +2398,13 @@ cc.game = /** @lends cc.game# */{
2397
2398
config = self . config ,
2398
2399
CONFIG_KEY = self . CONFIG_KEY ;
2399
2400
2400
- this . _loadConfig ( ) ;
2401
+ // Config loaded
2402
+ if ( ! this . _configLoaded ) {
2403
+ this . _loadConfig ( function ( ) {
2404
+ self . prepare ( cb ) ;
2405
+ } ) ;
2406
+ return ;
2407
+ }
2401
2408
2402
2409
// Already prepared
2403
2410
if ( this . _prepared ) {
@@ -2553,46 +2560,42 @@ cc.game = /** @lends cc.game# */{
2553
2560
} ,
2554
2561
2555
2562
// @Game loading section
2556
- _loadConfig : function ( ) {
2563
+ _loadConfig : function ( cb ) {
2557
2564
// 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 ( ) ;
2566
2570
}
2567
2571
// Load from project.json
2568
2572
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 ;
2587
2578
}
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' ) ;
2590
2593
}
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 ) ;
2594
2598
}
2595
- this . _initConfig ( data ) ;
2596
2599
}
2597
2600
} ,
2598
2601
@@ -2605,6 +2608,7 @@ cc.game = /** @lends cc.game# */{
2605
2608
config [ CONFIG_KEY . engineDir ] = config [ CONFIG_KEY . engineDir ] || "frameworks/cocos2d-html5" ;
2606
2609
if ( config [ CONFIG_KEY . debugMode ] == null )
2607
2610
config [ CONFIG_KEY . debugMode ] = 0 ;
2611
+ config [ CONFIG_KEY . exposeClassName ] = ! ! config [ CONFIG_KEY . exposeClassName ] ;
2608
2612
config [ CONFIG_KEY . frameRate ] = config [ CONFIG_KEY . frameRate ] || 60 ;
2609
2613
if ( config [ CONFIG_KEY . renderMode ] == null )
2610
2614
config [ CONFIG_KEY . renderMode ] = 0 ;
@@ -2615,6 +2619,7 @@ cc.game = /** @lends cc.game# */{
2615
2619
if ( modules && modules . indexOf ( "core" ) < 0 ) modules . splice ( 0 , 0 , "core" ) ;
2616
2620
modules && ( config [ CONFIG_KEY . modules ] = modules ) ;
2617
2621
this . config = config ;
2622
+ this . _configLoaded = true ;
2618
2623
} ,
2619
2624
2620
2625
_initRenderer : function ( width , height ) {
0 commit comments