@@ -689,6 +689,26 @@ cc.loader = /** @lends cc.loader# */{
689
689
} ) ;
690
690
}
691
691
} ,
692
+ _loadTxtSync : function ( url ) {
693
+ if ( ! cc . _isNodeJs ) {
694
+ var xhr = this . getXMLHttpRequest ( ) ;
695
+ xhr . open ( "GET" , url , false ) ;
696
+ if ( / m s i e / i. test ( navigator . userAgent ) && ! / o p e r a / 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
+ } ,
692
712
693
713
loadCsb : function ( url , cb ) {
694
714
var xhr = new XMLHttpRequest ( ) ;
@@ -1944,7 +1964,6 @@ cc.game = /** @lends cc.game# */{
1944
1964
DEBUG_MODE_INFO_FOR_WEB_PAGE : 4 ,
1945
1965
DEBUG_MODE_WARN_FOR_WEB_PAGE : 5 ,
1946
1966
DEBUG_MODE_ERROR_FOR_WEB_PAGE : 6 ,
1947
- _ready : false ,
1948
1967
1949
1968
EVENT_HIDE : "game_on_hide" ,
1950
1969
EVENT_SHOW : "game_on_show" ,
@@ -2082,12 +2101,6 @@ cc.game = /** @lends cc.game# */{
2082
2101
* Run game.
2083
2102
*/
2084
2103
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
- }
2091
2104
var self = this ;
2092
2105
var _run = function ( ) {
2093
2106
if ( id ) {
@@ -2130,13 +2143,7 @@ cc.game = /** @lends cc.game# */{
2130
2143
cfg [ CONFIG_KEY . frameRate ] = cfg [ CONFIG_KEY . frameRate ] || 60 ;
2131
2144
if ( cfg [ CONFIG_KEY . renderMode ] == null )
2132
2145
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 ;
2140
2147
} ;
2141
2148
if ( document [ "ccConfig" ] ) {
2142
2149
self . config = _init ( document [ "ccConfig" ] ) ;
@@ -2147,31 +2154,28 @@ cc.game = /** @lends cc.game# */{
2147
2154
var _t = cocos_script [ i ] . getAttribute ( 'cocos' ) ;
2148
2155
if ( _t == '' || _t ) { break ; }
2149
2156
}
2150
- var _src , _resPath ;
2157
+ var _src , txt , _resPath ;
2151
2158
if ( i < cocos_script . length ) {
2152
2159
_src = cocos_script [ i ] . src ;
2153
2160
if ( _src ) {
2154
2161
_resPath = / ( .* ) \/ / . exec ( _src ) [ 0 ] ;
2155
2162
cc . loader . resPath = _resPath ;
2156
2163
_src = cc . path . join ( _resPath , 'project.json' ) ;
2157
2164
}
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" ) ;
2169
2169
}
2170
+ var data = JSON . parse ( txt ) ;
2171
+ self . config = _init ( data || { } ) ;
2170
2172
} catch ( e ) {
2171
2173
cc . log ( "Failed to read or parse project.json" ) ;
2172
- _init ( { } ) ;
2174
+ self . config = _init ( { } ) ;
2173
2175
}
2174
2176
}
2177
+ //init debug move to CCDebugger
2178
+ cc . _initSys ( self . config , CONFIG_KEY ) ;
2175
2179
} ,
2176
2180
2177
2181
//cache for js and module that has added into jsList to be loaded.
0 commit comments