phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.
1,862 lines (1,626 loc) • 6.78 MB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("Phaser", [], factory);
else if(typeof exports === 'object')
exports["Phaser"] = factory();
else
root["Phaser"] = factory();
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1497);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
// Taken from klasse by mattdesl https://github.com/mattdesl/klasse
function hasGetterOrSetter (def)
{
return (!!def.get && typeof def.get === 'function') || (!!def.set && typeof def.set === 'function');
}
function getProperty (definition, k, isClassDescriptor)
{
// This may be a lightweight object, OR it might be a property that was defined previously.
// For simple class descriptors we can just assume its NOT previously defined.
var def = (isClassDescriptor) ? definition[k] : Object.getOwnPropertyDescriptor(definition, k);
if (!isClassDescriptor && def.value && typeof def.value === 'object')
{
def = def.value;
}
// This might be a regular property, or it may be a getter/setter the user defined in a class.
if (def && hasGetterOrSetter(def))
{
if (typeof def.enumerable === 'undefined')
{
def.enumerable = true;
}
if (typeof def.configurable === 'undefined')
{
def.configurable = true;
}
return def;
}
else
{
return false;
}
}
function hasNonConfigurable (obj, k)
{
var prop = Object.getOwnPropertyDescriptor(obj, k);
if (!prop)
{
return false;
}
if (prop.value && typeof prop.value === 'object')
{
prop = prop.value;
}
if (prop.configurable === false)
{
return true;
}
return false;
}
/**
* Extends the given `myClass` object's prototype with the properties of `definition`.
*
* @function extend
* @ignore
* @param {Object} ctor The constructor object to mix into.
* @param {Object} definition A dictionary of functions for the class.
* @param {boolean} isClassDescriptor Is the definition a class descriptor?
* @param {Object} [extend] The parent constructor object.
*/
function extend (ctor, definition, isClassDescriptor, extend)
{
for (var k in definition)
{
if (!definition.hasOwnProperty(k))
{
continue;
}
var def = getProperty(definition, k, isClassDescriptor);
if (def !== false)
{
// If Extends is used, we will check its prototype to see if the final variable exists.
var parent = extend || ctor;
if (hasNonConfigurable(parent.prototype, k))
{
// Just skip the final property
if (Class.ignoreFinals)
{
continue;
}
// We cannot re-define a property that is configurable=false.
// So we will consider them final and throw an error. This is by
// default so it is clear to the developer what is happening.
// You can set ignoreFinals to true if you need to extend a class
// which has configurable=false; it will simply not re-define final properties.
throw new Error('cannot override final property \'' + k + '\', set Class.ignoreFinals = true to skip');
}
Object.defineProperty(ctor.prototype, k, def);
}
else
{
ctor.prototype[k] = definition[k];
}
}
}
/**
* Applies the given `mixins` to the prototype of `myClass`.
*
* @function mixin
* @ignore
* @param {Object} myClass The constructor object to mix into.
* @param {Object|Array<Object>} mixins The mixins to apply to the constructor.
*/
function mixin (myClass, mixins)
{
if (!mixins)
{
return;
}
if (!Array.isArray(mixins))
{
mixins = [ mixins ];
}
for (var i = 0; i < mixins.length; i++)
{
extend(myClass, mixins[i].prototype || mixins[i]);
}
}
/**
* Creates a new class with the given descriptor.
* The constructor, defined by the name `initialize`,
* is an optional function. If unspecified, an anonymous
* function will be used which calls the parent class (if
* one exists).
*
* You can also use `Extends` and `Mixins` to provide subclassing
* and inheritance.
*
* @class Phaser.Class
* @constructor
* @param {Object} definition a dictionary of functions for the class
* @example
*
* var MyClass = new Phaser.Class({
*
* initialize: function() {
* this.foo = 2.0;
* },
*
* bar: function() {
* return this.foo + 5;
* }
* });
*/
function Class (definition)
{
if (!definition)
{
definition = {};
}
// The variable name here dictates what we see in Chrome debugger
var initialize;
var Extends;
if (definition.initialize)
{
if (typeof definition.initialize !== 'function')
{
throw new Error('initialize must be a function');
}
initialize = definition.initialize;
// Usually we should avoid 'delete' in V8 at all costs.
// However, its unlikely to make any performance difference
// here since we only call this on class creation (i.e. not object creation).
delete definition.initialize;
}
else if (definition.Extends)
{
var base = definition.Extends;
initialize = function ()
{
base.apply(this, arguments);
};
}
else
{
initialize = function () {};
}
if (definition.Extends)
{
initialize.prototype = Object.create(definition.Extends.prototype);
initialize.prototype.constructor = initialize;
// For getOwnPropertyDescriptor to work, we need to act directly on the Extends (or Mixin)
Extends = definition.Extends;
delete definition.Extends;
}
else
{
initialize.prototype.constructor = initialize;
}
// Grab the mixins, if they are specified...
var mixins = null;
if (definition.Mixins)
{
mixins = definition.Mixins;
delete definition.Mixins;
}
// First, mixin if we can.
mixin(initialize, mixins);
// Now we grab the actual definition which defines the overrides.
extend(initialize, definition, true, Extends);
return initialize;
}
Class.extend = extend;
Class.mixin = mixin;
Class.ignoreFinals = false;
module.exports = Class;
/***/ }),
/* 1 */
/***/ (function(module, exports) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* A NOOP (No Operation) callback function.
*
* Used internally by Phaser when it's more expensive to determine if a callback exists
* than it is to just invoke an empty function.
*
* @function Phaser.Utils.NOOP
* @since 3.0.0
*/
var NOOP = function ()
{
// NOOP
};
module.exports = NOOP;
/***/ }),
/* 2 */
/***/ (function(module, exports) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Finds the key within the top level of the {@link source} object, or returns {@link defaultValue}
*
* @function Phaser.Utils.Objects.GetFastValue
* @since 3.0.0
*
* @param {object} source - The object to search
* @param {string} key - The key for the property on source. Must exist at the top level of the source object (no periods)
* @param {*} [defaultValue] - The default value to use if the key does not exist.
*
* @return {*} The value if found; otherwise, defaultValue (null if none provided)
*/
var GetFastValue = function (source, key, defaultValue)
{
var t = typeof(source);
if (!source || t === 'number' || t === 'string')
{
return defaultValue;
}
else if (source.hasOwnProperty(key) && source[key] !== undefined)
{
return source[key];
}
else
{
return defaultValue;
}
};
module.exports = GetFastValue;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
// Adapted from [gl-matrix](https://github.com/toji/gl-matrix) by toji
// and [vecmath](https://github.com/mattdesl/vecmath) by mattdesl
var Class = __webpack_require__(0);
var FuzzyEqual = __webpack_require__(123);
/**
* @classdesc
* A representation of a vector in 2D space.
*
* A two-component vector.
*
* @class Vector2
* @memberof Phaser.Math
* @constructor
* @since 3.0.0
*
* @param {number|Phaser.Types.Math.Vector2Like} [x] - The x component, or an object with `x` and `y` properties.
* @param {number} [y] - The y component.
*/
var Vector2 = new Class({
initialize:
function Vector2 (x, y)
{
/**
* The x component of this Vector.
*
* @name Phaser.Math.Vector2#x
* @type {number}
* @default 0
* @since 3.0.0
*/
this.x = 0;
/**
* The y component of this Vector.
*
* @name Phaser.Math.Vector2#y
* @type {number}
* @default 0
* @since 3.0.0
*/
this.y = 0;
if (typeof x === 'object')
{
this.x = x.x || 0;
this.y = x.y || 0;
}
else
{
if (y === undefined) { y = x; }
this.x = x || 0;
this.y = y || 0;
}
},
/**
* Make a clone of this Vector2.
*
* @method Phaser.Math.Vector2#clone
* @since 3.0.0
*
* @return {Phaser.Math.Vector2} A clone of this Vector2.
*/
clone: function ()
{
return new Vector2(this.x, this.y);
},
/**
* Copy the components of a given Vector into this Vector.
*
* @method Phaser.Math.Vector2#copy
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to copy the components from.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
copy: function (src)
{
this.x = src.x || 0;
this.y = src.y || 0;
return this;
},
/**
* Set the component values of this Vector from a given Vector2Like object.
*
* @method Phaser.Math.Vector2#setFromObject
* @since 3.0.0
*
* @param {Phaser.Types.Math.Vector2Like} obj - The object containing the component values to set for this Vector.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
setFromObject: function (obj)
{
this.x = obj.x || 0;
this.y = obj.y || 0;
return this;
},
/**
* Set the `x` and `y` components of the this Vector to the given `x` and `y` values.
*
* @method Phaser.Math.Vector2#set
* @since 3.0.0
*
* @param {number} x - The x value to set for this Vector.
* @param {number} [y=x] - The y value to set for this Vector.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
set: function (x, y)
{
if (y === undefined) { y = x; }
this.x = x;
this.y = y;
return this;
},
/**
* This method is an alias for `Vector2.set`.
*
* @method Phaser.Math.Vector2#setTo
* @since 3.4.0
*
* @param {number} x - The x value to set for this Vector.
* @param {number} [y=x] - The y value to set for this Vector.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
setTo: function (x, y)
{
return this.set(x, y);
},
/**
* Sets the `x` and `y` values of this object from a given polar coordinate.
*
* @method Phaser.Math.Vector2#setToPolar
* @since 3.0.0
*
* @param {number} azimuth - The angular coordinate, in radians.
* @param {number} [radius=1] - The radial coordinate (length).
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
setToPolar: function (azimuth, radius)
{
if (radius == null) { radius = 1; }
this.x = Math.cos(azimuth) * radius;
this.y = Math.sin(azimuth) * radius;
return this;
},
/**
* Check whether this Vector is equal to a given Vector.
*
* Performs a strict equality check against each Vector's components.
*
* @method Phaser.Math.Vector2#equals
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} v - The vector to compare with this Vector.
*
* @return {boolean} Whether the given Vector is equal to this Vector.
*/
equals: function (v)
{
return ((this.x === v.x) && (this.y === v.y));
},
/**
* Check whether this Vector is approximately equal to a given Vector.
*
* @method Phaser.Math.Vector2#fuzzyEquals
* @since 3.23.0
*
* @param {Phaser.Math.Vector2} v - The vector to compare with this Vector.
* @param {number} [epsilon=0.0001] - The tolerance value.
*
* @return {boolean} Whether both absolute differences of the x and y components are smaller than `epsilon`.
*/
fuzzyEquals: function (v, epsilon)
{
return (FuzzyEqual(this.x, v.x, epsilon) && FuzzyEqual(this.y, v.y, epsilon));
},
/**
* Calculate the angle between this Vector and the positive x-axis, in radians.
*
* @method Phaser.Math.Vector2#angle
* @since 3.0.0
*
* @return {number} The angle between this Vector, and the positive x-axis, given in radians.
*/
angle: function ()
{
// computes the angle in radians with respect to the positive x-axis
var angle = Math.atan2(this.y, this.x);
if (angle < 0)
{
angle += 2 * Math.PI;
}
return angle;
},
/**
* Set the angle of this Vector.
*
* @method Phaser.Math.Vector2#setAngle
* @since 3.23.0
*
* @param {number} angle - The angle, in radians.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
setAngle: function (angle)
{
return this.setToPolar(angle, this.length());
},
/**
* Add a given Vector to this Vector. Addition is component-wise.
*
* @method Phaser.Math.Vector2#add
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to add to this Vector.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
add: function (src)
{
this.x += src.x;
this.y += src.y;
return this;
},
/**
* Subtract the given Vector from this Vector. Subtraction is component-wise.
*
* @method Phaser.Math.Vector2#subtract
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to subtract from this Vector.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
subtract: function (src)
{
this.x -= src.x;
this.y -= src.y;
return this;
},
/**
* Perform a component-wise multiplication between this Vector and the given Vector.
*
* Multiplies this Vector by the given Vector.
*
* @method Phaser.Math.Vector2#multiply
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to multiply this Vector by.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
multiply: function (src)
{
this.x *= src.x;
this.y *= src.y;
return this;
},
/**
* Scale this Vector by the given value.
*
* @method Phaser.Math.Vector2#scale
* @since 3.0.0
*
* @param {number} value - The value to scale this Vector by.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
scale: function (value)
{
if (isFinite(value))
{
this.x *= value;
this.y *= value;
}
else
{
this.x = 0;
this.y = 0;
}
return this;
},
/**
* Perform a component-wise division between this Vector and the given Vector.
*
* Divides this Vector by the given Vector.
*
* @method Phaser.Math.Vector2#divide
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to divide this Vector by.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
divide: function (src)
{
this.x /= src.x;
this.y /= src.y;
return this;
},
/**
* Negate the `x` and `y` components of this Vector.
*
* @method Phaser.Math.Vector2#negate
* @since 3.0.0
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
negate: function ()
{
this.x = -this.x;
this.y = -this.y;
return this;
},
/**
* Calculate the distance between this Vector and the given Vector.
*
* @method Phaser.Math.Vector2#distance
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to calculate the distance to.
*
* @return {number} The distance from this Vector to the given Vector.
*/
distance: function (src)
{
var dx = src.x - this.x;
var dy = src.y - this.y;
return Math.sqrt(dx * dx + dy * dy);
},
/**
* Calculate the distance between this Vector and the given Vector, squared.
*
* @method Phaser.Math.Vector2#distanceSq
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to calculate the distance to.
*
* @return {number} The distance from this Vector to the given Vector, squared.
*/
distanceSq: function (src)
{
var dx = src.x - this.x;
var dy = src.y - this.y;
return dx * dx + dy * dy;
},
/**
* Calculate the length (or magnitude) of this Vector.
*
* @method Phaser.Math.Vector2#length
* @since 3.0.0
*
* @return {number} The length of this Vector.
*/
length: function ()
{
var x = this.x;
var y = this.y;
return Math.sqrt(x * x + y * y);
},
/**
* Set the length (or magnitude) of this Vector.
*
* @method Phaser.Math.Vector2#setLength
* @since 3.23.0
*
* @param {number} length
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
setLength: function (length)
{
return this.normalize().scale(length);
},
/**
* Calculate the length of this Vector squared.
*
* @method Phaser.Math.Vector2#lengthSq
* @since 3.0.0
*
* @return {number} The length of this Vector, squared.
*/
lengthSq: function ()
{
var x = this.x;
var y = this.y;
return x * x + y * y;
},
/**
* Normalize this Vector.
*
* Makes the vector a unit length vector (magnitude of 1) in the same direction.
*
* @method Phaser.Math.Vector2#normalize
* @since 3.0.0
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
normalize: function ()
{
var x = this.x;
var y = this.y;
var len = x * x + y * y;
if (len > 0)
{
len = 1 / Math.sqrt(len);
this.x = x * len;
this.y = y * len;
}
return this;
},
/**
* Rotate this Vector to its perpendicular, in the positive direction.
*
* @method Phaser.Math.Vector2#normalizeRightHand
* @since 3.0.0
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
normalizeRightHand: function ()
{
var x = this.x;
this.x = this.y * -1;
this.y = x;
return this;
},
/**
* Rotate this Vector to its perpendicular, in the negative direction.
*
* @method Phaser.Math.Vector2#normalizeLeftHand
* @since 3.23.0
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
normalizeLeftHand: function ()
{
var x = this.x;
this.x = this.y;
this.y = x * -1;
return this;
},
/**
* Calculate the dot product of this Vector and the given Vector.
*
* @method Phaser.Math.Vector2#dot
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector2 to dot product with this Vector2.
*
* @return {number} The dot product of this Vector and the given Vector.
*/
dot: function (src)
{
return this.x * src.x + this.y * src.y;
},
/**
* Calculate the cross product of this Vector and the given Vector.
*
* @method Phaser.Math.Vector2#cross
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector2 to cross with this Vector2.
*
* @return {number} The cross product of this Vector and the given Vector.
*/
cross: function (src)
{
return this.x * src.y - this.y * src.x;
},
/**
* Linearly interpolate between this Vector and the given Vector.
*
* Interpolates this Vector towards the given Vector.
*
* @method Phaser.Math.Vector2#lerp
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector2 to interpolate towards.
* @param {number} [t=0] - The interpolation percentage, between 0 and 1.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
lerp: function (src, t)
{
if (t === undefined) { t = 0; }
var ax = this.x;
var ay = this.y;
this.x = ax + t * (src.x - ax);
this.y = ay + t * (src.y - ay);
return this;
},
/**
* Transform this Vector with the given Matrix.
*
* @method Phaser.Math.Vector2#transformMat3
* @since 3.0.0
*
* @param {Phaser.Math.Matrix3} mat - The Matrix3 to transform this Vector2 with.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
transformMat3: function (mat)
{
var x = this.x;
var y = this.y;
var m = mat.val;
this.x = m[0] * x + m[3] * y + m[6];
this.y = m[1] * x + m[4] * y + m[7];
return this;
},
/**
* Transform this Vector with the given Matrix.
*
* @method Phaser.Math.Vector2#transformMat4
* @since 3.0.0
*
* @param {Phaser.Math.Matrix4} mat - The Matrix4 to transform this Vector2 with.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
transformMat4: function (mat)
{
var x = this.x;
var y = this.y;
var m = mat.val;
this.x = m[0] * x + m[4] * y + m[12];
this.y = m[1] * x + m[5] * y + m[13];
return this;
},
/**
* Make this Vector the zero vector (0, 0).
*
* @method Phaser.Math.Vector2#reset
* @since 3.0.0
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
reset: function ()
{
this.x = 0;
this.y = 0;
return this;
},
/**
* Limit the length (or magnitude) of this Vector.
*
* @method Phaser.Math.Vector2#limit
* @since 3.23.0
*
* @param {number} max - The maximum length.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
limit: function (max)
{
var len = this.length();
if (len && len > max)
{
this.scale(max / len);
}
return this;
},
/**
* Reflect this Vector off a line defined by a normal.
*
* @method Phaser.Math.Vector2#reflect
* @since 3.23.0
*
* @param {Phaser.Math.Vector2} normal - A vector perpendicular to the line.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
reflect: function (normal)
{
normal = normal.clone().normalize();
return this.subtract(normal.scale(2 * this.dot(normal)));
},
/**
* Reflect this Vector across another.
*
* @method Phaser.Math.Vector2#mirror
* @since 3.23.0
*
* @param {Phaser.Math.Vector2} axis - A vector to reflect across.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
mirror: function (axis)
{
return this.reflect(axis).negate();
},
/**
* Rotate this Vector by an angle amount.
*
* @method Phaser.Math.Vector2#rotate
* @since 3.23.0
*
* @param {number} delta - The angle to rotate by, in radians.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
rotate: function (delta)
{
var cos = Math.cos(delta);
var sin = Math.sin(delta);
return this.set(cos * this.x - sin * this.y, sin * this.x + cos * this.y);
}
});
/**
* A static zero Vector2 for use by reference.
*
* This constant is meant for comparison operations and should not be modified directly.
*
* @constant
* @name Phaser.Math.Vector2.ZERO
* @type {Phaser.Math.Vector2}
* @since 3.1.0
*/
Vector2.ZERO = new Vector2();
/**
* A static right Vector2 for use by reference.
*
* This constant is meant for comparison operations and should not be modified directly.
*
* @constant
* @name Phaser.Math.Vector2.RIGHT
* @type {Phaser.Math.Vector2}
* @since 3.16.0
*/
Vector2.RIGHT = new Vector2(1, 0);
/**
* A static left Vector2 for use by reference.
*
* This constant is meant for comparison operations and should not be modified directly.
*
* @constant
* @name Phaser.Math.Vector2.LEFT
* @type {Phaser.Math.Vector2}
* @since 3.16.0
*/
Vector2.LEFT = new Vector2(-1, 0);
/**
* A static up Vector2 for use by reference.
*
* This constant is meant for comparison operations and should not be modified directly.
*
* @constant
* @name Phaser.Math.Vector2.UP
* @type {Phaser.Math.Vector2}
* @since 3.16.0
*/
Vector2.UP = new Vector2(0, -1);
/**
* A static down Vector2 for use by reference.
*
* This constant is meant for comparison operations and should not be modified directly.
*
* @constant
* @name Phaser.Math.Vector2.DOWN
* @type {Phaser.Math.Vector2}
* @since 3.16.0
*/
Vector2.DOWN = new Vector2(0, 1);
/**
* A static one Vector2 for use by reference.
*
* This constant is meant for comparison operations and should not be modified directly.
*
* @constant
* @name Phaser.Math.Vector2.ONE
* @type {Phaser.Math.Vector2}
* @since 3.16.0
*/
Vector2.ONE = new Vector2(1, 1);
module.exports = Vector2;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = __webpack_require__(0);
var GEOM_CONST = __webpack_require__(55);
/**
* @classdesc
* Defines a Point in 2D space, with an x and y component.
*
* @class Point
* @memberof Phaser.Geom
* @constructor
* @since 3.0.0
*
* @param {number} [x=0] - The x coordinate of this Point.
* @param {number} [y=x] - The y coordinate of this Point.
*/
var Point = new Class({
initialize:
function Point (x, y)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = x; }
/**
* The geometry constant type of this object: `GEOM_CONST.POINT`.
* Used for fast type comparisons.
*
* @name Phaser.Geom.Point#type
* @type {number}
* @readonly
* @since 3.19.0
*/
this.type = GEOM_CONST.POINT;
/**
* The x coordinate of this Point.
*
* @name Phaser.Geom.Point#x
* @type {number}
* @default 0
* @since 3.0.0
*/
this.x = x;
/**
* The y coordinate of this Point.
*
* @name Phaser.Geom.Point#y
* @type {number}
* @default 0
* @since 3.0.0
*/
this.y = y;
},
/**
* Set the x and y coordinates of the point to the given values.
*
* @method Phaser.Geom.Point#setTo
* @since 3.0.0
*
* @param {number} [x=0] - The x coordinate of this Point.
* @param {number} [y=x] - The y coordinate of this Point.
*
* @return {this} This Point object.
*/
setTo: function (x, y)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = x; }
this.x = x;
this.y = y;
return this;
}
});
module.exports = Point;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = __webpack_require__(0);
var PluginCache = __webpack_require__(24);
var SceneEvents = __webpack_require__(21);
/**
* @classdesc
* The Game Object Factory is a Scene plugin that allows you to quickly create many common
* types of Game Objects and have them automatically registered with the Scene.
*
* Game Objects directly register themselves with the Factory and inject their own creation
* methods into the class.
*
* @class GameObjectFactory
* @memberof Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object Factory belongs.
*/
var GameObjectFactory = new Class({
initialize:
function GameObjectFactory (scene)
{
/**
* The Scene to which this Game Object Factory belongs.
*
* @name Phaser.GameObjects.GameObjectFactory#scene
* @type {Phaser.Scene}
* @protected
* @since 3.0.0
*/
this.scene = scene;
/**
* A reference to the Scene.Systems.
*
* @name Phaser.GameObjects.GameObjectFactory#systems
* @type {Phaser.Scenes.Systems}
* @protected
* @since 3.0.0
*/
this.systems = scene.sys;
/**
* A reference to the Scene Event Emitter.
*
* @name Phaser.GameObjects.GameObjectFactory#events
* @type {Phaser.Events.EventEmitter}
* @protected
* @since 3.50.0
*/
this.events = scene.sys.events;
/**
* A reference to the Scene Display List.
*
* @name Phaser.GameObjects.GameObjectFactory#displayList
* @type {Phaser.GameObjects.DisplayList}
* @protected
* @since 3.0.0
*/
this.displayList;
/**
* A reference to the Scene Update List.
*
* @name Phaser.GameObjects.GameObjectFactory#updateList
* @type {Phaser.GameObjects.UpdateList}
* @protected
* @since 3.0.0
*/
this.updateList;
this.events.once(SceneEvents.BOOT, this.boot, this);
this.events.on(SceneEvents.START, this.start, this);
},
/**
* This method is called automatically, only once, when the Scene is first created.
* Do not invoke it directly.
*
* @method Phaser.GameObjects.GameObjectFactory#boot
* @private
* @since 3.5.1
*/
boot: function ()
{
this.displayList = this.systems.displayList;
this.updateList = this.systems.updateList;
this.events.once(SceneEvents.DESTROY, this.destroy, this);
},
/**
* This method is called automatically by the Scene when it is starting up.
* It is responsible for creating local systems, properties and listening for Scene events.
* Do not invoke it directly.
*
* @method Phaser.GameObjects.GameObjectFactory#start
* @private
* @since 3.5.0
*/
start: function ()
{
this.events.once(SceneEvents.SHUTDOWN, this.shutdown, this);
},
/**
* Adds an existing Game Object to this Scene.
*
* If the Game Object renders, it will be added to the Display List.
* If it has a `preUpdate` method, it will be added to the Update List.
*
* @method Phaser.GameObjects.GameObjectFactory#existing
* @since 3.0.0
*
* @generic {Phaser.GameObjects.GameObject} G - [child,$return]
*
* @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.Group)} child - The child to be added to this Scene.
*
* @return {Phaser.GameObjects.GameObject} The Game Object that was added.
*/
existing: function (child)
{
if (child.renderCanvas || child.renderWebGL)
{
this.displayList.add(child);
}
// For when custom objects have overridden `preUpdate` but don't hook into the ADDED_TO_SCENE event:
// Adding to the list multiple times is safe, as it won't add duplicates into the list anyway.
if (child.preUpdate)
{
this.updateList.add(child);
}
return child;
},
/**
* The Scene that owns this plugin is shutting down.
* We need to kill and reset all internal properties as well as stop listening to Scene events.
*
* @method Phaser.GameObjects.GameObjectFactory#shutdown
* @private
* @since 3.0.0
*/
shutdown: function ()
{
this.events.off(SceneEvents.SHUTDOWN, this.shutdown, this);
},
/**
* The Scene that owns this plugin is being destroyed.
* We need to shutdown and then kill off all external references.
*
* @method Phaser.GameObjects.GameObjectFactory#destroy
* @private
* @since 3.0.0
*/
destroy: function ()
{
this.shutdown();
this.events.off(SceneEvents.START, this.start, this);
this.scene = null;
this.systems = null;
this.events = null;
this.displayList = null;
this.updateList = null;
}
});
/**
* Static method called directly by the Game Object factory functions.
* With this method you can register a custom GameObject factory in the GameObjectFactory,
* providing a name (`factoryType`) and the constructor (`factoryFunction`) in order
* to be called when you call to Phaser.Scene.add[ factoryType ] method.
*
* @method Phaser.GameObjects.GameObjectFactory.register
* @static
* @since 3.0.0
*
* @param {string} factoryType - The key of the factory that you will use to call to Phaser.Scene.add[ factoryType ] method.
* @param {function} factoryFunction - The constructor function to be called when you invoke to the Phaser.Scene.add method.
*/
GameObjectFactory.register = function (factoryType, factoryFunction)
{
if (!GameObjectFactory.prototype.hasOwnProperty(factoryType))
{
GameObjectFactory.prototype[factoryType] = factoryFunction;
}
};
/**
* Static method called directly by the Game Object factory functions.
* With this method you can remove a custom GameObject factory registered in the GameObjectFactory,
* providing a its `factoryType`.
*
* @method Phaser.GameObjects.GameObjectFactory.remove
* @static
* @since 3.0.0
*
* @param {string} factoryType - The key of the factory that you want to remove from the GameObjectFactory.
*/
GameObjectFactory.remove = function (factoryType)
{
if (GameObjectFactory.prototype.hasOwnProperty(factoryType))
{
delete GameObjectFactory.prototype[factoryType];
}
};
PluginCache.register('GameObjectFactory', GameObjectFactory, 'add');
module.exports = GameObjectFactory;
/***/ }),
/* 6 */
/***/ (function(module, exports) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
// Source object
// The key as a string, or an array of keys, i.e. 'banner', or 'banner.hideBanner'
// The default value to use if the key doesn't exist
/**
* Retrieves a value from an object.
*
* @function Phaser.Utils.Objects.GetValue
* @since 3.0.0
*
* @param {object} source - The object to retrieve the value from.
* @param {string} key - The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot (`.`) - `banner.hideBanner` would return the value of the `hideBanner` property from the object stored in the `banner` property of the `source` object.
* @param {*} defaultValue - The value to return if the `key` isn't found in the `source` object.
*
* @return {*} The value of the requested key.
*/
var GetValue = function (source, key, defaultValue)
{
if (!source || typeof source === 'number')
{
return defaultValue;
}
else if (source.hasOwnProperty(key))
{
return source[key];
}
else if (key.indexOf('.') !== -1)
{
var keys = key.split('.');
var parent = source;
var value = defaultValue;
// Use for loop here so we can break early
for (var i = 0; i < keys.length; i++)
{
if (parent.hasOwnProperty(keys[i]))
{
// Yes it has a key property, let's carry on down
value = parent[keys[i]];
parent = parent[keys[i]];
}
else
{
// Can't go any further, so reset to default
value = defaultValue;
break;
}
}
return value;
}
else
{
return defaultValue;
}
};
module.exports = GetValue;
/***/ }),
/* 7 */
/***/ (function(module, exports) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* This is a slightly modified version of jQuery.isPlainObject.
* A plain object is an object whose internal class property is [object Object].
*
* @function Phaser.Utils.Objects.IsPlainObject
* @since 3.0.0
*
* @param {object} obj - The object to inspect.
*
* @return {boolean} `true` if the object is plain, otherwise `false`.
*/
var IsPlainObject = function (obj)
{
// Not plain objects:
// - Any object or value whose internal [[Class]] property is not "[object Object]"
// - DOM nodes
// - window
if (typeof(obj) !== 'object' || obj.nodeType || obj === obj.window)
{
return false;
}
// Support: Firefox <20
// The try/catch suppresses exceptions thrown when attempting to access
// the "constructor" property of certain host objects, ie. |window.location|
// https://bugzilla.mozilla.org/show_bug.cgi?id=814622
try
{
if (obj.constructor && !({}).hasOwnProperty.call(obj.constructor.prototype, 'isPrototypeOf'))
{
return false;
}
}
catch (e)
{
return false;
}
// If the function hasn't returned already, we're confident that
// |obj| is a plain object, created by {} or constructed with new Object
return true;
};
module.exports = IsPlainObject;
/***/ }),
/* 8 */
/***/ (function(module, exports) {
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var types = {};
/**
* @namespace Phaser.Loader.FileTypesManager
*/
var FileTypesManager = {
/**
* Static method called when a LoaderPlugin is created.
*
* Loops through the local types object and injects all of them as
* properties into the LoaderPlugin instance.
*
* @method Phaser.Loader.FileTypesManager.install
* @since 3.0.0
*
* @param {Phaser.Loader.LoaderPlugin} loader - The LoaderPlugin to install the types into.
*/
install: function (loader)
{
for (var key in types)
{
loader[key] = types[key];
}
},
/**
* Static method called directly by the File Types.
*
* The key is a reference to the function used to load the files via the Loader, i.e. `image`.
*
* @method Phaser.Loader.FileTypesManager.register
* @since 3.0.0
*
* @param {string} key - The key that will be used as the method name in the LoaderPlugin.
* @param {function} factoryFunction - The function that will be called when LoaderPlugin.key is invoked.
*/
register: function (key, factoryFunction)
{
types[key] = factoryFunction;
},
/**
* Removed all associated file types.
*
* @method Phaser.Loader.FileTypesManager.destroy
* @since 3.0.0
*/
destroy: function ()
{
types = {};
}
};
module.exports = FileTypesManager;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var has = Object.prototype.hasOwnProperty
, prefix = '~';
/**
* Constructor to create a storage for our `EE` objects.
* An `Events` instance is a plain object whose properties are event names.
*
* @constructor
* @private
*/
function Events() {}
//
// We try to not inherit from `Object.prototype`. In some engines creating an
// instance in this way is faster than calling `Object.create(null)` directly.
// If `Object.create(null)` is not supported we prefix the event names with a
// character to make sure that the built-in object properties are not
// overridden or used as an attack vector.
//
if (Object.create) {
Events.prototype = Object.create(null);
//
// This hack is needed because the `__proto__` property is still inherited in
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
//
if (!new Events().__proto__) prefix = false;
}
/**
* Representation of a single event listener.
*
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
* @constructor
* @private
*/
function EE(fn, context, once) {
this.fn = fn;
this.context = context;
this.once = once || false;
}
/**
* Add a listener for a given event.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} once Specify if the listener is a one-time listener.
* @returns {EventEmitter}
* @private
*/
function addListener(emitter, event, fn, context, once) {
if (typeof fn !== 'function') {
throw new TypeError('The listener must be a function');
}
var listener = new EE(fn, context || emitter, once)
, evt = prefix ? prefix + event : event;
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
else emitter._events[evt] = [emitter._events[evt], listener];
return emitter;
}
/**
* Clear event by name.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} evt The Event name.
* @private
*/
function clearEvent(emitter, evt) {
if (--emitter._eventsCount === 0) emitter._events = new Events();
else delete emitter._events[evt];
}
/**
* Minimal `EventEmitter` interface that is molded against the Node.js
* `EventEmitter` interface.
*
* @constructor
* @public
*/
function EventEmitter() {
this._events = new Events();
this._eventsCount = 0;
}
/**
* Return an array listing the events for which the emitter has registered
* listeners.
*
* @returns {Array}
* @public
*/
EventEmitter.prototype.eventNames = function eventNames() {
var names = []
, events
, name;
if (this._eventsCount === 0) return names;
for (name in (events = this._events)) {
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
}
if (Object.getOwnPropertySymbols) {
return names.concat(Object.getOwnPropertySymbols(events));
}
return names;
};
/**
* Return the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Array} The registered listeners.
* @public
*/
EventEmitter.prototype.listeners = function listeners(event) {
var evt = prefix ? prefix + event : event
, handlers = this._events[evt];
if (!handlers) return [];
if (handlers.fn) return [handlers.fn];
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
ee[i] = handlers[i]