Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ekelokorpi committed Jul 16, 2018
2 parents 5b4d173 + bfddc05 commit 58e3560
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ media/*
!media/panda.png
*.mobileprovision
*.p12
plugin
66 changes: 40 additions & 26 deletions src/engine/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var game = {
Engine version.
@property {String} version
**/
version: '2.8.1',
version: '2.9.0',
/**
@property {Boolean} _booted
@private
Expand Down Expand Up @@ -254,7 +254,7 @@ var game = {
var l, c, i;
if (
!object || typeof object !== 'object' ||
object instanceof HTMLElement ||
(typeof document !== 'undefined' && object instanceof HTMLElement) ||
object instanceof this.Class ||
(this.Container && object instanceof this.Container)
) {
Expand Down Expand Up @@ -559,11 +559,11 @@ var game = {

// Required classes
this.system = new this.System();
this.input = new this.Input(this.renderer.canvas);
if (this.renderer) this.input = new this.Input(this.renderer.canvas);

// Optional classes
if (this.Keyboard) this.keyboard = new this.Keyboard();
if (this.Audio) this.audio = new this.Audio();
if (this.renderer && this.Keyboard) this.keyboard = new this.Keyboard();
if (this.renderer && this.Audio) this.audio = new this.Audio();
if (this.Pool) this.pool = new this.Pool();
if (this.config.id && !this.Storage.id) this.Storage.id = this.config.id;
if (this.Storage && this.Storage.id) this.storage = new this.Storage();
Expand All @@ -576,15 +576,17 @@ var game = {
if (this.Debug && this.Debug.enabled) this.debug = new this.Debug();

// Logo
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 120 * game.scale;
var ctx = canvas.getContext('2d');
ctx.drawImage(this._logoSource, 0, 0, canvas.width, canvas.height / 2);
ctx.rotate(Math.PI);
ctx.translate(-canvas.width, -canvas.height);
ctx.drawImage(this._logoSource, 0, 0, canvas.width, canvas.height / 2);
this.logo = new game.Texture(new game.BaseTexture(canvas));

if (typeof document !== 'undefined') {
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 120 * game.scale;
var ctx = canvas.getContext('2d');
ctx.drawImage(this._logoSource, 0, 0, canvas.width, canvas.height / 2);
ctx.rotate(Math.PI);
ctx.translate(-canvas.width, -canvas.height);
ctx.drawImage(this._logoSource, 0, 0, canvas.width, canvas.height / 2);
this.logo = new game.Texture(new game.BaseTexture(canvas));
}

this.isStarted = true;
if (!this.system._rotateScreenVisible) this.onStart();
},
Expand All @@ -597,11 +599,12 @@ var game = {
this._booted = true;
this._loadNativeExtensions();
this._loadDeviceInformation();
if (typeof window === 'object') {
this._normalizeVendorAttribute(window, 'requestAnimationFrame');
this._normalizeVendorAttribute(navigator, 'vibrate');
}

this._normalizeVendorAttribute(window, 'requestAnimationFrame');
this._normalizeVendorAttribute(navigator, 'vibrate');

if (document.location.href.match(/\?nocache/) || this.config.disableCache) this._nocache = '?' + Date.now();
if (typeof document === 'object' && document.location.href.match(/\?nocache/) || this.config.disableCache) this._nocache = '?' + Date.now();

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

this.module('engine.core');

if (document.readyState === 'complete') {
if (typeof document === 'undefined' || document.readyState === 'complete') {
this._DOMReady();
}
else {
Expand All @@ -646,7 +649,7 @@ var game = {
**/
_clearGameLoop: function(id) {
if (this._gameLoops[id]) delete this._gameLoops[id];
else window.clearInterval(id);
else clearInterval(id);
},

/**
Expand All @@ -655,7 +658,7 @@ var game = {
**/
_DOMReady: function() {
if (this._DOMLoaded) return;
if (!document.body) return setTimeout(this._DOMReady.bind(this), 13);
if (typeof document === 'object' && !document.body) return setTimeout(this._DOMReady.bind(this), 13);
this._DOMLoaded = true;
if (this._gameModuleDefined) this._loadModules();
},
Expand Down Expand Up @@ -701,6 +704,10 @@ var game = {
@private
**/
_loadDeviceInformation: function() {
if (typeof window === 'undefined') {
this.device.headless = true;
return;
}
this.device.pixelRatio = window.devicePixelRatio || 1;
this.device.screen = {
width: window.screen.availWidth * this.device.pixelRatio,
Expand Down Expand Up @@ -938,7 +945,7 @@ var game = {
return this.charAt(0).toUpperCase() + this.slice(1);
};

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

var path = name.replace(/\./g, '/') + '.js' + this._nocache;
if (this.config.sourceFolder) path = this.config.sourceFolder + '/' + path;

if (typeof document === 'undefined') {
require('../../' + path);
this._scriptLoaded();
return;
}

var script = document.createElement('script');
script.type = 'text/javascript';
Expand Down Expand Up @@ -1008,7 +1021,8 @@ var game = {
}
}
}


if (typeof document === 'undefined') return;
this._logoSource = document.createElement('img');
this._logoSource.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAA8BAMAAABfg2ObAAAALVBMVEUAAAD4uABHR0f4uABHR0f4uAD4uABHR0dHR0dHR0f4uABHR0f4uABHR0f4uADOcJEWAAAADXRSTlMAqqpV6UQkUMmUdBvjKrIhowAAAH1JREFUSMdjKLmLB7gz4Ae++DRfIaD5Ll4wqnlU8xDQzCqIDKRI05z3DgUsIEmzHapmgVHNo5qpovkGInkS1uykhApmo2cMGTyaFRgIAMZRzaOaRzUPJs2sEM0BZGlmSDYGAjMG0jUjwKjmUc2jmontlE0gUXMJckNgA2l6ASc7KJOPBNRIAAAAAElFTkSuQmCC';
this._logoSource.onload = this._readyLogo.bind(this);
Expand Down Expand Up @@ -1040,8 +1054,8 @@ var game = {
@return {Number}
**/
_setGameLoop: function(callback) {
if (this.System.frameRate) return window.setInterval(callback, 1000 / this.System.frameRate);
if (window.requestAnimationFrame) {
if (this.System.frameRate) return setInterval(callback, 1000 / this.System.frameRate);
if (typeof requestAnimationFrame === 'function') {
var id = this._gameLoopId++;
this._gameLoops[id] = true;

Expand All @@ -1053,7 +1067,7 @@ var game = {
window.requestAnimationFrame(animate);
return id;
}
return window.setInterval(callback, 1000 / 60);
return setInterval(callback, 1000 / 60);
},

/**
Expand Down
1 change: 1 addition & 0 deletions src/engine/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ game.createClass('DebugTouch', {
}
});

if (typeof document === 'undefined') return;
var href = document.location.href.toLowerCase();
if (href.match(/\?debug/)) game.Debug.enabled = true;
if (href.match(/\?debugdraw/)) {
Expand Down
44 changes: 44 additions & 0 deletions src/engine/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,40 @@ game.createClass('Circle', {
}
});

/**
@class Polygon
@constructor
@param {Array} points
**/
game.createClass('Polygon', {
/**
List of points in polygon. Can be list of numbers or vectors.
@property {Array} points
**/
points: [],

staticInit: function(points) {
if (!points) return;
for (var i = 0; i < points.length; i++) {
if (points[i] instanceof game.Vector) this.points.push(points[i]);
else {
this.points.push(new game.Vector(points[i], points[i + 1]));
i++;
}
}
},

/**
Close polygon.
@method close
**/
close: function() {
if (this.points[0] !== this.points[this.points.length - 1]) {
this.points.push(this.points[0]);
}
}
});

/**
@class Rectangle
@constructor
Expand Down Expand Up @@ -130,6 +164,16 @@ game.createClass('Rectangle', {
this.height = typeof height === 'number' ? height : this.width;
this.x = typeof x === 'number' ? x : this.x;
this.y = typeof y === 'number' ? y : this.y;
},

/**
Swap width and height values.
@method swap
**/
swap: function() {
var height = this.height;
this.height = this.width;
this.width = height;
}
});

Expand Down
5 changes: 4 additions & 1 deletion src/engine/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,10 @@ game.createClass('Keyboard', {
if (game.Keyboard.preventDefault) event.preventDefault();
var key = game.Keyboard.keys[event.keyCode];
if (!key) key = event.keyCode;
if (this._keysDown[key]) return;
if (this._keysDown[key]) {
event.preventDefault();
return;
}
this._keysDown[key] = true;
if (game.scene && game.scene.keydown) {
var prevent = game.scene.keydown(key, this.down('SHIFT'), this.down('CTRL'), this.down('ALT'));
Expand Down
Loading

0 comments on commit 58e3560

Please sign in to comment.