Skip to content

Commit 58e3560

Browse files
committed
Merge branch 'develop'
2 parents 5b4d173 + bfddc05 commit 58e3560

File tree

8 files changed

+175
-55
lines changed

8 files changed

+175
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ media/*
99
!media/panda.png
1010
*.mobileprovision
1111
*.p12
12+
plugin

src/engine/core.js

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var game = {
9999
Engine version.
100100
@property {String} version
101101
**/
102-
version: '2.8.1',
102+
version: '2.9.0',
103103
/**
104104
@property {Boolean} _booted
105105
@private
@@ -254,7 +254,7 @@ var game = {
254254
var l, c, i;
255255
if (
256256
!object || typeof object !== 'object' ||
257-
object instanceof HTMLElement ||
257+
(typeof document !== 'undefined' && object instanceof HTMLElement) ||
258258
object instanceof this.Class ||
259259
(this.Container && object instanceof this.Container)
260260
) {
@@ -559,11 +559,11 @@ var game = {
559559

560560
// Required classes
561561
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);
563563

564564
// 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();
567567
if (this.Pool) this.pool = new this.Pool();
568568
if (this.config.id && !this.Storage.id) this.Storage.id = this.config.id;
569569
if (this.Storage && this.Storage.id) this.storage = new this.Storage();
@@ -576,15 +576,17 @@ var game = {
576576
if (this.Debug && this.Debug.enabled) this.debug = new this.Debug();
577577

578578
// 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+
588590
this.isStarted = true;
589591
if (!this.system._rotateScreenVisible) this.onStart();
590592
},
@@ -597,11 +599,12 @@ var game = {
597599
this._booted = true;
598600
this._loadNativeExtensions();
599601
this._loadDeviceInformation();
602+
if (typeof window === 'object') {
603+
this._normalizeVendorAttribute(window, 'requestAnimationFrame');
604+
this._normalizeVendorAttribute(navigator, 'vibrate');
605+
}
600606

601-
this._normalizeVendorAttribute(window, 'requestAnimationFrame');
602-
this._normalizeVendorAttribute(navigator, 'vibrate');
603-
604-
if (document.location.href.match(/\?nocache/) || this.config.disableCache) this._nocache = '?' + Date.now();
607+
if (typeof document === 'object' && document.location.href.match(/\?nocache/) || this.config.disableCache) this._nocache = '?' + Date.now();
605608

606609
// Default config
607610
if (typeof this.config.sourceFolder === 'undefined') this.config.sourceFolder = 'src';
@@ -631,7 +634,7 @@ var game = {
631634

632635
this.module('engine.core');
633636

634-
if (document.readyState === 'complete') {
637+
if (typeof document === 'undefined' || document.readyState === 'complete') {
635638
this._DOMReady();
636639
}
637640
else {
@@ -646,7 +649,7 @@ var game = {
646649
**/
647650
_clearGameLoop: function(id) {
648651
if (this._gameLoops[id]) delete this._gameLoops[id];
649-
else window.clearInterval(id);
652+
else clearInterval(id);
650653
},
651654

652655
/**
@@ -655,7 +658,7 @@ var game = {
655658
**/
656659
_DOMReady: function() {
657660
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);
659662
this._DOMLoaded = true;
660663
if (this._gameModuleDefined) this._loadModules();
661664
},
@@ -701,6 +704,10 @@ var game = {
701704
@private
702705
**/
703706
_loadDeviceInformation: function() {
707+
if (typeof window === 'undefined') {
708+
this.device.headless = true;
709+
return;
710+
}
704711
this.device.pixelRatio = window.devicePixelRatio || 1;
705712
this.device.screen = {
706713
width: window.screen.availWidth * this.device.pixelRatio,
@@ -938,7 +945,7 @@ var game = {
938945
return this.charAt(0).toUpperCase() + this.slice(1);
939946
};
940947

941-
if (window.Intl) {
948+
if (typeof Intl === 'object') {
942949
// Natural alphanumerical sort
943950
var collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
944951
this.compare = collator.compare;
@@ -955,6 +962,12 @@ var game = {
955962

956963
var path = name.replace(/\./g, '/') + '.js' + this._nocache;
957964
if (this.config.sourceFolder) path = this.config.sourceFolder + '/' + path;
965+
966+
if (typeof document === 'undefined') {
967+
require('../../' + path);
968+
this._scriptLoaded();
969+
return;
970+
}
958971

959972
var script = document.createElement('script');
960973
script.type = 'text/javascript';
@@ -1008,7 +1021,8 @@ var game = {
10081021
}
10091022
}
10101023
}
1011-
1024+
1025+
if (typeof document === 'undefined') return;
10121026
this._logoSource = document.createElement('img');
10131027
this._logoSource.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAA8BAMAAABfg2ObAAAALVBMVEUAAAD4uABHR0f4uABHR0f4uAD4uABHR0dHR0dHR0f4uABHR0f4uABHR0f4uADOcJEWAAAADXRSTlMAqqpV6UQkUMmUdBvjKrIhowAAAH1JREFUSMdjKLmLB7gz4Ae++DRfIaD5Ll4wqnlU8xDQzCqIDKRI05z3DgUsIEmzHapmgVHNo5qpovkGInkS1uykhApmo2cMGTyaFRgIAMZRzaOaRzUPJs2sEM0BZGlmSDYGAjMG0jUjwKjmUc2jmontlE0gUXMJckNgA2l6ASc7KJOPBNRIAAAAAElFTkSuQmCC';
10141028
this._logoSource.onload = this._readyLogo.bind(this);
@@ -1040,8 +1054,8 @@ var game = {
10401054
@return {Number}
10411055
**/
10421056
_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') {
10451059
var id = this._gameLoopId++;
10461060
this._gameLoops[id] = true;
10471061

@@ -1053,7 +1067,7 @@ var game = {
10531067
window.requestAnimationFrame(animate);
10541068
return id;
10551069
}
1056-
return window.setInterval(callback, 1000 / 60);
1070+
return setInterval(callback, 1000 / 60);
10571071
},
10581072

10591073
/**

src/engine/debug.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ game.createClass('DebugTouch', {
801801
}
802802
});
803803

804+
if (typeof document === 'undefined') return;
804805
var href = document.location.href.toLowerCase();
805806
if (href.match(/\?debug/)) game.Debug.enabled = true;
806807
if (href.match(/\?debugdraw/)) {

src/engine/geometry.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,40 @@ game.createClass('Circle', {
8484
}
8585
});
8686

87+
/**
88+
@class Polygon
89+
@constructor
90+
@param {Array} points
91+
**/
92+
game.createClass('Polygon', {
93+
/**
94+
List of points in polygon. Can be list of numbers or vectors.
95+
@property {Array} points
96+
**/
97+
points: [],
98+
99+
staticInit: function(points) {
100+
if (!points) return;
101+
for (var i = 0; i < points.length; i++) {
102+
if (points[i] instanceof game.Vector) this.points.push(points[i]);
103+
else {
104+
this.points.push(new game.Vector(points[i], points[i + 1]));
105+
i++;
106+
}
107+
}
108+
},
109+
110+
/**
111+
Close polygon.
112+
@method close
113+
**/
114+
close: function() {
115+
if (this.points[0] !== this.points[this.points.length - 1]) {
116+
this.points.push(this.points[0]);
117+
}
118+
}
119+
});
120+
87121
/**
88122
@class Rectangle
89123
@constructor
@@ -130,6 +164,16 @@ game.createClass('Rectangle', {
130164
this.height = typeof height === 'number' ? height : this.width;
131165
this.x = typeof x === 'number' ? x : this.x;
132166
this.y = typeof y === 'number' ? y : this.y;
167+
},
168+
169+
/**
170+
Swap width and height values.
171+
@method swap
172+
**/
173+
swap: function() {
174+
var height = this.height;
175+
this.height = this.width;
176+
this.width = height;
133177
}
134178
});
135179

src/engine/input.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ game.createClass('Keyboard', {
443443
if (game.Keyboard.preventDefault) event.preventDefault();
444444
var key = game.Keyboard.keys[event.keyCode];
445445
if (!key) key = event.keyCode;
446-
if (this._keysDown[key]) return;
446+
if (this._keysDown[key]) {
447+
event.preventDefault();
448+
return;
449+
}
447450
this._keysDown[key] = true;
448451
if (game.scene && game.scene.keydown) {
449452
var prevent = game.scene.keydown(key, this.down('SHIFT'), this.down('CTRL'), this.down('ALT'));

0 commit comments

Comments
 (0)