UNPKG

phaser-ce

Version:

Phaser CE (Community Edition) is a fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.

212 lines (182 loc) 5.41 kB
/** * @copyright 2016 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ if (typeof AudioBufferSourceNode !== 'undefined') { if (!AudioBufferSourceNode.prototype.start) { AudioBufferSourceNode.prototype.start = AudioBufferSourceNode.prototype.noteGrainOn; } if (!AudioBufferSourceNode.prototype.stop) { AudioBufferSourceNode.prototype.stop = AudioBufferSourceNode.prototype.noteOff; } } // ES6 Math.trunc - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc if (!Math.trunc) { Math.trunc = function trunc (x) { return x < 0 ? Math.ceil(x) : Math.floor(x); }; } /** * A polyfill for Function.prototype.bind */ if (!Function.prototype.bind) { Function.prototype.bind = (function () { var slice = Array.prototype.slice; return function (thisArg) { var target = this, boundArgs = slice.call(arguments, 1); if (typeof target !== 'function') { throw new TypeError(); } function bound () { var args = boundArgs.concat(slice.call(arguments)); target.apply(this instanceof bound ? this : thisArg, args); } bound.prototype = (function F (proto) { if (proto) { F.prototype = proto; } if (!(this instanceof F)) { return new F(); } })(target.prototype); return bound; }; })(); } /** * A polyfill for Array.isArray */ if (!Array.isArray) { Array.isArray = function (arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; } /** * A polyfill for Array.forEach * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach */ if (!Array.prototype.forEach) { Array.prototype.forEach = function (fun /* , thisArg */) { 'use strict'; if (this === void 0 || this === null) { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (typeof fun !== 'function') { throw new TypeError(); } var thisArg = arguments.length >= 2 ? arguments[1] : void 0; for (var i = 0; i < len; i++) { if (i in t) { fun.call(thisArg, t[i], i, t); } } }; } /** * Low-budget Float32Array knock-off, suitable for use with P2.js in IE9 * Source: http://www.html5gamedevs.com/topic/5988-phaser-12-ie9/ * Cameron Foale (http://www.kibibu.com) */ if (typeof window.Uint32Array !== 'function' && typeof window.Uint32Array !== 'object') { var CheapArray = function (type) { /* eslint-disable no-array-constructor */ var proto = new Array(); /* eslint-enable no-array-constructor */ window[type] = function (arg) { if (typeof(arg) === 'number') { Array.call(this, arg); this.length = arg; for (var i = 0; i < this.length; i++) { this[i] = 0; } } else { Array.call(this, arg.length); this.length = arg.length; for (var i = 0; i < this.length; i++) { this[i] = arg[i]; } } }; window[type].prototype = proto; window[type].constructor = window[type]; }; CheapArray('Float32Array'); // jshint ignore:line CheapArray('Uint32Array'); // jshint ignore:line CheapArray('Uint16Array'); // jshint ignore:line CheapArray('Int16Array'); // jshint ignore:line CheapArray('ArrayBuffer'); // jshint ignore:line } /** * Also fix for the absent console in IE9 */ if (!window.console) { window.console = {}; window.console.log = window.console.assert = function () {}; window.console.warn = window.console.assert = function () {}; } /** * Fix for Object.assign not existing on older devices */ if (!Object.assign) { // We include `varArgs` (unused) to ensure Object.assign.length === 2 Object.assign = function (target, varArgs) // eslint-disable-line no-unused-vars { 'use strict'; if (target == null) { // TypeError if undefined or null throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); var hasOwn = Object.prototype.hasOwnProperty; for (var index = 1; index < arguments.length; index++) { var nextSource = arguments[index]; if (nextSource != null) { // Skip over if undefined or null for (var nextKey in nextSource) { // Avoid bugs when hasOwnProperty is shadowed if (hasOwn.call(nextSource, nextKey)) { to[nextKey] = nextSource[nextKey]; } } } } return to; }; }