@@ -99,7 +99,7 @@ var game = {
99
99
Engine version.
100
100
@property {String } version
101
101
**/
102
- version : '2.8.1 ' ,
102
+ version : '2.9.0 ' ,
103
103
/**
104
104
@property {Boolean } _booted
105
105
@private
@@ -254,7 +254,7 @@ var game = {
254
254
var l , c , i ;
255
255
if (
256
256
! object || typeof object !== 'object' ||
257
- object instanceof HTMLElement ||
257
+ ( typeof document !== 'undefined' && object instanceof HTMLElement ) ||
258
258
object instanceof this . Class ||
259
259
( this . Container && object instanceof this . Container )
260
260
) {
@@ -559,11 +559,11 @@ var game = {
559
559
560
560
// Required classes
561
561
this . system = new this . System ( ) ;
562
- this . input = new this . Input ( this . renderer . canvas ) ;
562
+ if ( this . renderer ) this . input = new this . Input ( this . renderer . canvas ) ;
563
563
564
564
// Optional classes
565
- if ( this . Keyboard ) this . keyboard = new this . Keyboard ( ) ;
566
- if ( this . Audio ) this . audio = new this . Audio ( ) ;
565
+ if ( this . renderer && this . Keyboard ) this . keyboard = new this . Keyboard ( ) ;
566
+ if ( this . renderer && this . Audio ) this . audio = new this . Audio ( ) ;
567
567
if ( this . Pool ) this . pool = new this . Pool ( ) ;
568
568
if ( this . config . id && ! this . Storage . id ) this . Storage . id = this . config . id ;
569
569
if ( this . Storage && this . Storage . id ) this . storage = new this . Storage ( ) ;
@@ -576,15 +576,17 @@ var game = {
576
576
if ( this . Debug && this . Debug . enabled ) this . debug = new this . Debug ( ) ;
577
577
578
578
// Logo
579
- var canvas = document . createElement ( 'canvas' ) ;
580
- canvas . width = canvas . height = 120 * game . scale ;
581
- var ctx = canvas . getContext ( '2d' ) ;
582
- ctx . drawImage ( this . _logoSource , 0 , 0 , canvas . width , canvas . height / 2 ) ;
583
- ctx . rotate ( Math . PI ) ;
584
- ctx . translate ( - canvas . width , - canvas . height ) ;
585
- ctx . drawImage ( this . _logoSource , 0 , 0 , canvas . width , canvas . height / 2 ) ;
586
- this . logo = new game . Texture ( new game . BaseTexture ( canvas ) ) ;
587
-
579
+ if ( typeof document !== 'undefined' ) {
580
+ var canvas = document . createElement ( 'canvas' ) ;
581
+ canvas . width = canvas . height = 120 * game . scale ;
582
+ var ctx = canvas . getContext ( '2d' ) ;
583
+ ctx . drawImage ( this . _logoSource , 0 , 0 , canvas . width , canvas . height / 2 ) ;
584
+ ctx . rotate ( Math . PI ) ;
585
+ ctx . translate ( - canvas . width , - canvas . height ) ;
586
+ ctx . drawImage ( this . _logoSource , 0 , 0 , canvas . width , canvas . height / 2 ) ;
587
+ this . logo = new game . Texture ( new game . BaseTexture ( canvas ) ) ;
588
+ }
589
+
588
590
this . isStarted = true ;
589
591
if ( ! this . system . _rotateScreenVisible ) this . onStart ( ) ;
590
592
} ,
@@ -597,11 +599,12 @@ var game = {
597
599
this . _booted = true ;
598
600
this . _loadNativeExtensions ( ) ;
599
601
this . _loadDeviceInformation ( ) ;
602
+ if ( typeof window === 'object' ) {
603
+ this . _normalizeVendorAttribute ( window , 'requestAnimationFrame' ) ;
604
+ this . _normalizeVendorAttribute ( navigator , 'vibrate' ) ;
605
+ }
600
606
601
- this . _normalizeVendorAttribute ( window , 'requestAnimationFrame' ) ;
602
- this . _normalizeVendorAttribute ( navigator , 'vibrate' ) ;
603
-
604
- if ( document . location . href . match ( / \? n o c a c h e / ) || this . config . disableCache ) this . _nocache = '?' + Date . now ( ) ;
607
+ if ( typeof document === 'object' && document . location . href . match ( / \? n o c a c h e / ) || this . config . disableCache ) this . _nocache = '?' + Date . now ( ) ;
605
608
606
609
// Default config
607
610
if ( typeof this . config . sourceFolder === 'undefined' ) this . config . sourceFolder = 'src' ;
@@ -631,7 +634,7 @@ var game = {
631
634
632
635
this . module ( 'engine.core' ) ;
633
636
634
- if ( document . readyState === 'complete' ) {
637
+ if ( typeof document === 'undefined' || document . readyState === 'complete' ) {
635
638
this . _DOMReady ( ) ;
636
639
}
637
640
else {
@@ -646,7 +649,7 @@ var game = {
646
649
**/
647
650
_clearGameLoop : function ( id ) {
648
651
if ( this . _gameLoops [ id ] ) delete this . _gameLoops [ id ] ;
649
- else window . clearInterval ( id ) ;
652
+ else clearInterval ( id ) ;
650
653
} ,
651
654
652
655
/**
@@ -655,7 +658,7 @@ var game = {
655
658
**/
656
659
_DOMReady : function ( ) {
657
660
if ( this . _DOMLoaded ) return ;
658
- if ( ! document . body ) return setTimeout ( this . _DOMReady . bind ( this ) , 13 ) ;
661
+ if ( typeof document === 'object' && ! document . body ) return setTimeout ( this . _DOMReady . bind ( this ) , 13 ) ;
659
662
this . _DOMLoaded = true ;
660
663
if ( this . _gameModuleDefined ) this . _loadModules ( ) ;
661
664
} ,
@@ -701,6 +704,10 @@ var game = {
701
704
@private
702
705
**/
703
706
_loadDeviceInformation : function ( ) {
707
+ if ( typeof window === 'undefined' ) {
708
+ this . device . headless = true ;
709
+ return ;
710
+ }
704
711
this . device . pixelRatio = window . devicePixelRatio || 1 ;
705
712
this . device . screen = {
706
713
width : window . screen . availWidth * this . device . pixelRatio ,
@@ -938,7 +945,7 @@ var game = {
938
945
return this . charAt ( 0 ) . toUpperCase ( ) + this . slice ( 1 ) ;
939
946
} ;
940
947
941
- if ( window . Intl ) {
948
+ if ( typeof Intl === 'object' ) {
942
949
// Natural alphanumerical sort
943
950
var collator = new Intl . Collator ( undefined , { numeric : true , sensitivity : 'base' } ) ;
944
951
this . compare = collator . compare ;
@@ -955,6 +962,12 @@ var game = {
955
962
956
963
var path = name . replace ( / \. / g, '/' ) + '.js' + this . _nocache ;
957
964
if ( this . config . sourceFolder ) path = this . config . sourceFolder + '/' + path ;
965
+
966
+ if ( typeof document === 'undefined' ) {
967
+ require ( '../../' + path ) ;
968
+ this . _scriptLoaded ( ) ;
969
+ return ;
970
+ }
958
971
959
972
var script = document . createElement ( 'script' ) ;
960
973
script . type = 'text/javascript' ;
@@ -1008,7 +1021,8 @@ var game = {
1008
1021
}
1009
1022
}
1010
1023
}
1011
-
1024
+
1025
+ if ( typeof document === 'undefined' ) return ;
1012
1026
this . _logoSource = document . createElement ( 'img' ) ;
1013
1027
this . _logoSource . src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAA8BAMAAABfg2ObAAAALVBMVEUAAAD4uABHR0f4uABHR0f4uAD4uABHR0dHR0dHR0f4uABHR0f4uABHR0f4uADOcJEWAAAADXRSTlMAqqpV6UQkUMmUdBvjKrIhowAAAH1JREFUSMdjKLmLB7gz4Ae++DRfIaD5Ll4wqnlU8xDQzCqIDKRI05z3DgUsIEmzHapmgVHNo5qpovkGInkS1uykhApmo2cMGTyaFRgIAMZRzaOaRzUPJs2sEM0BZGlmSDYGAjMG0jUjwKjmUc2jmontlE0gUXMJckNgA2l6ASc7KJOPBNRIAAAAAElFTkSuQmCC' ;
1014
1028
this . _logoSource . onload = this . _readyLogo . bind ( this ) ;
@@ -1040,8 +1054,8 @@ var game = {
1040
1054
@return {Number }
1041
1055
**/
1042
1056
_setGameLoop : function ( callback ) {
1043
- if ( this . System . frameRate ) return window . setInterval ( callback , 1000 / this . System . frameRate ) ;
1044
- if ( window . requestAnimationFrame ) {
1057
+ if ( this . System . frameRate ) return setInterval ( callback , 1000 / this . System . frameRate ) ;
1058
+ if ( typeof requestAnimationFrame === 'function' ) {
1045
1059
var id = this . _gameLoopId ++ ;
1046
1060
this . _gameLoops [ id ] = true ;
1047
1061
@@ -1053,7 +1067,7 @@ var game = {
1053
1067
window . requestAnimationFrame ( animate ) ;
1054
1068
return id ;
1055
1069
}
1056
- return window . setInterval ( callback , 1000 / 60 ) ;
1070
+ return setInterval ( callback , 1000 / 60 ) ;
1057
1071
} ,
1058
1072
1059
1073
/**
0 commit comments