UNPKG

phaser

Version:

A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.

1,997 lines (1,764 loc) 832 kB
var Camera3DPlugin = /******/ (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 = 42); /******/ }) /************************************************************************/ /******/ ([ /* 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 * @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 * @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, __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__(18); /** * @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; /***/ }), /* 2 */ /***/ (function(module, exports) { /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2020 Photon Storm Ltd. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var MATH_CONST = { /** * The value of PI * 2. * * @name Phaser.Math.PI2 * @type {number} * @since 3.0.0 */ PI2: Math.PI * 2, /** * The value of PI * 0.5. * * @name Phaser.Math.TAU * @type {number} * @since 3.0.0 */ TAU: Math.PI * 0.5, /** * An epsilon value (1.0e-6) * * @name Phaser.Math.EPSILON * @type {number} * @since 3.0.0 */ EPSILON: 1.0e-6, /** * For converting degrees to radians (PI / 180) * * @name Phaser.Math.DEG_TO_RAD * @type {number} * @since 3.0.0 */ DEG_TO_RAD: Math.PI / 180, /** * For converting radians to degrees (180 / PI) * * @name Phaser.Math.RAD_TO_DEG * @type {number} * @since 3.0.0 */ RAD_TO_DEG: 180 / Math.PI, /** * An instance of the Random Number Generator. * This is not set until the Game boots. * * @name Phaser.Math.RND * @type {Phaser.Math.RandomDataGenerator} * @since 3.0.0 */ RND: null, /** * The minimum safe integer this browser supports. * We use a const for backward compatibility with Internet Explorer. * * @name Phaser.Math.MIN_SAFE_INTEGER * @type {number} * @since 3.21.0 */ MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER || -9007199254740991, /** * The maximum safe integer this browser supports. * We use a const for backward compatibility with Internet Explorer. * * @name Phaser.Math.MAX_SAFE_INTEGER * @type {number} * @since 3.21.0 */ MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER || 9007199254740991 }; module.exports = MATH_CONST; /***/ }), /* 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); /** * @classdesc * A representation of a vector in 3D space. * * A three-component vector. * * @class Vector3 * @memberof Phaser.Math * @constructor * @since 3.0.0 * * @param {number} [x] - The x component. * @param {number} [y] - The y component. * @param {number} [z] - The z component. */ var Vector3 = new Class({ initialize: function Vector3 (x, y, z) { /** * The x component of this Vector. * * @name Phaser.Math.Vector3#x * @type {number} * @default 0 * @since 3.0.0 */ this.x = 0; /** * The y component of this Vector. * * @name Phaser.Math.Vector3#y * @type {number} * @default 0 * @since 3.0.0 */ this.y = 0; /** * The z component of this Vector. * * @name Phaser.Math.Vector3#z * @type {number} * @default 0 * @since 3.0.0 */ this.z = 0; if (typeof x === 'object') { this.x = x.x || 0; this.y = x.y || 0; this.z = x.z || 0; } else { this.x = x || 0; this.y = y || 0; this.z = z || 0; } }, /** * Set this Vector to point up. * * Sets the y component of the vector to 1, and the others to 0. * * @method Phaser.Math.Vector3#up * @since 3.0.0 * * @return {Phaser.Math.Vector3} This Vector3. */ up: function () { this.x = 0; this.y = 1; this.z = 0; return this; }, /** * Sets the components of this Vector to be the `Math.min` result from the given vector. * * @method Phaser.Math.Vector3#min * @since 3.50.0 * * @param {Phaser.Math.Vector3} v - The Vector3 to check the minimum values against. * * @return {Phaser.Math.Vector3} This Vector3. */ min: function (v) { this.x = Math.min(this.x, v.x); this.y = Math.min(this.y, v.y); this.z = Math.min(this.z, v.z); return this; }, /** * Sets the components of this Vector to be the `Math.max` result from the given vector. * * @method Phaser.Math.Vector3#max * @since 3.50.0 * * @param {Phaser.Math.Vector3} v - The Vector3 to check the maximum values against. * * @return {Phaser.Math.Vector3} This Vector3. */ max: function (v) { this.x = Math.max(this.x, v.x); this.y = Math.max(this.y, v.y); this.z = Math.max(this.z, v.z); return this; }, /** * Make a clone of this Vector3. * * @method Phaser.Math.Vector3#clone * @since 3.0.0 * * @return {Phaser.Math.Vector3} A new Vector3 object containing this Vectors values. */ clone: function () { return new Vector3(this.x, this.y, this.z); }, /** * Adds the two given Vector3s and sets the results into this Vector3. * * @method Phaser.Math.Vector3#addVectors * @since 3.50.0 * * @param {Phaser.Math.Vector3} a - The first Vector to add. * @param {Phaser.Math.Vector3} b - The second Vector to add. * * @return {Phaser.Math.Vector3} This Vector3. */ addVectors: function (a, b) { this.x = a.x + b.x; this.y = a.y + b.y; this.z = a.z + b.z; return this; }, /** * Calculate the cross (vector) product of two given Vectors. * * @method Phaser.Math.Vector3#crossVectors * @since 3.0.0 * * @param {Phaser.Math.Vector3} a - The first Vector to multiply. * @param {Phaser.Math.Vector3} b - The second Vector to multiply. * * @return {Phaser.Math.Vector3} This Vector3. */ crossVectors: function (a, b) { var ax = a.x; var ay = a.y; var az = a.z; var bx = b.x; var by = b.y; var bz = b.z; this.x = ay * bz - az * by; this.y = az * bx - ax * bz; this.z = ax * by - ay * bx; 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.Vector3#equals * @since 3.0.0 * * @param {Phaser.Math.Vector3} v - The Vector3 to compare against. * * @return {boolean} True if the two vectors strictly match, otherwise false. */ equals: function (v) { return ((this.x === v.x) && (this.y === v.y) && (this.z === v.z)); }, /** * Copy the components of a given Vector into this Vector. * * @method Phaser.Math.Vector3#copy * @since 3.0.0 * * @param {(Phaser.Math.Vector2|Phaser.Math.Vector3)} src - The Vector to copy the components from. * * @return {Phaser.Math.Vector3} This Vector3. */ copy: function (src) { this.x = src.x; this.y = src.y; this.z = src.z || 0; return this; }, /** * Set the `x`, `y`, and `z` components of this Vector to the given `x`, `y`, and `z` values. * * @method Phaser.Math.Vector3#set * @since 3.0.0 * * @param {(number|object)} x - The x value to set for this Vector, or an object containing x, y and z components. * @param {number} [y] - The y value to set for this Vector. * @param {number} [z] - The z value to set for this Vector. * * @return {Phaser.Math.Vector3} This Vector3. */ set: function (x, y, z) { if (typeof x === 'object') { this.x = x.x || 0; this.y = x.y || 0; this.z = x.z || 0; } else { this.x = x || 0; this.y = y || 0; this.z = z || 0; } return this; }, /** * Sets the components of this Vector3 from the position of the given Matrix4. * * @method Phaser.Math.Vector3#setFromMatrixPosition * @since 3.50.0 * * @param {Phaser.Math.Matrix4} mat4 - The Matrix4 to get the position from. * * @return {Phaser.Math.Vector3} This Vector3. */ setFromMatrixPosition: function (m) { return this.fromArray(m.val, 12); }, /** * Sets the components of this Vector3 from the Matrix4 column specified. * * @method Phaser.Math.Vector3#setFromMatrixColumn * @since 3.50.0 * * @param {Phaser.Math.Matrix4} mat4 - The Matrix4 to get the column from. * @param {number} index - The column index. * * @return {Phaser.Math.Vector3} This Vector3. */ setFromMatrixColumn: function (mat4, index) { return this.fromArray(mat4.val, index * 4); }, /** * Sets the components of this Vector3 from the given array, based on the offset. * * Vector3.x = array[offset] * Vector3.y = array[offset + 1] * Vector3.z = array[offset + 2] * * @method Phaser.Math.Vector3#fromArray * @since 3.50.0 * * @param {number[]} array - The array of values to get this Vector from. * @param {number} [offset=0] - The offset index into the array. * * @return {Phaser.Math.Vector3} This Vector3. */ fromArray: function (array, offset) { if (offset === undefined) { offset = 0; } this.x = array[offset]; this.y = array[offset + 1]; this.z = array[offset + 2]; return this; }, /** * Add a given Vector to this Vector. Addition is component-wise. * * @method Phaser.Math.Vector3#add * @since 3.0.0 * * @param {(Phaser.Math.Vector2|Phaser.Math.Vector3)} v - The Vector to add to this Vector. * * @return {Phaser.Math.Vector3} This Vector3. */ add: function (v) { this.x += v.x; this.y += v.y; this.z += v.z || 0; return this; }, /** * Add the given value to each component of this Vector. * * @method Phaser.Math.Vector3#addScalar * @since 3.50.0 * * @param {number} s - The amount to add to this Vector. * * @return {Phaser.Math.Vector3} This Vector3. */ addScalar: function (s) { this.x += s; this.y += s; this.z += s; return this; }, /** * Add and scale a given Vector to this Vector. Addition is component-wise. * * @method Phaser.Math.Vector3#addScale * @since 3.50.0 * * @param {(Phaser.Math.Vector2|Phaser.Math.Vector3)} v - The Vector to add to this Vector. * @param {number} scale - The amount to scale `v` by. * * @return {Phaser.Math.Vector3} This Vector3. */ addScale: function (v, scale) { this.x += v.x * scale; this.y += v.y * scale; this.z += v.z * scale || 0; return this; }, /** * Subtract the given Vector from this Vector. Subtraction is component-wise. * * @method Phaser.Math.Vector3#subtract * @since 3.0.0 * * @param {(Phaser.Math.Vector2|Phaser.Math.Vector3)} v - The Vector to subtract from this Vector. * * @return {Phaser.Math.Vector3} This Vector3. */ subtract: function (v) { this.x -= v.x; this.y -= v.y; this.z -= v.z || 0; return this; }, /** * Perform a component-wise multiplication between this Vector and the given Vector. * * Multiplies this Vector by the given Vector. * * @method Phaser.Math.Vector3#multiply * @since 3.0.0 * * @param {(Phaser.Math.Vector2|Phaser.Math.Vector3)} v - The Vector to multiply this Vector by. * * @return {Phaser.Math.Vector3} This Vector3. */ multiply: function (v) { this.x *= v.x; this.y *= v.y; this.z *= v.z || 1; return this; }, /** * Scale this Vector by the given value. * * @method Phaser.Math.Vector3#scale * @since 3.0.0 * * @param {number} scale - The value to scale this Vector by. * * @return {Phaser.Math.Vector3} This Vector3. */ scale: function (scale) { if (isFinite(scale)) { this.x *= scale; this.y *= scale; this.z *= scale; } else { this.x = 0; this.y = 0; this.z = 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.Vector3#divide * @since 3.0.0 * * @param {(Phaser.Math.Vector2|Phaser.Math.Vector3)} v - The Vector to divide this Vector by. * * @return {Phaser.Math.Vector3} This Vector3. */ divide: function (v) { this.x /= v.x; this.y /= v.y; this.z /= v.z || 1; return this; }, /** * Negate the `x`, `y` and `z` components of this Vector. * * @method Phaser.Math.Vector3#negate * @since 3.0.0 * * @return {Phaser.Math.Vector3} This Vector3. */ negate: function () { this.x = -this.x; this.y = -this.y; this.z = -this.z; return this; }, /** * Calculate the distance between this Vector and the given Vector. * * @method Phaser.Math.Vector3#distance * @since 3.0.0 * * @param {(Phaser.Math.Vector2|Phaser.Math.Vector3)} v - The Vector to calculate the distance to. * * @return {number} The distance from this Vector to the given Vector. */ distance: function (v) { var dx = v.x - this.x; var dy = v.y - this.y; var dz = v.z - this.z || 0; return Math.sqrt(dx * dx + dy * dy + dz * dz); }, /** * Calculate the distance between this Vector and the given Vector, squared. * * @method Phaser.Math.Vector3#distanceSq * @since 3.0.0 * * @param {(Phaser.Math.Vector2|Phaser.Math.Vector3)} v - The Vector to calculate the distance to. * * @return {number} The distance from this Vector to the given Vector, squared. */ distanceSq: function (v) { var dx = v.x - this.x; var dy = v.y - this.y; var dz = v.z - this.z || 0; return dx * dx + dy * dy + dz * dz; }, /** * Calculate the length (or magnitude) of this Vector. * * @method Phaser.Math.Vector3#length * @since 3.0.0 * * @return {number} The length of this Vector. */ length: function () { var x = this.x; var y = this.y; var z = this.z; return Math.sqrt(x * x + y * y + z * z); }, /** * Calculate the length of this Vector squared. * * @method Phaser.Math.Vector3#lengthSq * @since 3.0.0 * * @return {number} The length of this Vector, squared. */ lengthSq: function () { var x = this.x; var y = this.y; var z = this.z; return x * x + y * y + z * z; }, /** * Normalize this Vector. * * Makes the vector a unit length vector (magnitude of 1) in the same direction. * * @method Phaser.Math.Vector3#normalize * @since 3.0.0 * * @return {Phaser.Math.Vector3} This Vector3. */ normalize: function () { var x = this.x; var y = this.y; var z = this.z; var len = x * x + y * y + z * z; if (len > 0) { len = 1 / Math.sqrt(len); this.x = x * len; this.y = y * len; this.z = z * len; } return this; }, /** * Calculate the dot product of this Vector and the given Vector. * * @method Phaser.Math.Vector3#dot * @since 3.0.0 * * @param {Phaser.Math.Vector3} v - The Vector3 to dot product with this Vector3. * * @return {number} The dot product of this Vector and `v`. */ dot: function (v) { return this.x * v.x + this.y * v.y + this.z * v.z; }, /** * Calculate the cross (vector) product of this Vector (which will be modified) and the given Vector. * * @method Phaser.Math.Vector3#cross * @since 3.0.0 * * @param {Phaser.Math.Vector3} v - The Vector to cross product with. * * @return {Phaser.Math.Vector3} This Vector3. */ cross: function (v) { var ax = this.x; var ay = this.y; var az = this.z; var bx = v.x; var by = v.y; var bz = v.z; this.x = ay * bz - az * by; this.y = az * bx - ax * bz; this.z = ax * by - ay * bx; return this; }, /** * Linearly interpolate between this Vector and the given Vector. * * Interpolates this Vector towards the given Vector. * * @method Phaser.Math.Vector3#lerp * @since 3.0.0 * * @param {Phaser.Math.Vector3} v - The Vector3 to interpolate towards. * @param {number} [t=0] - The interpolation percentage, between 0 and 1. * * @return {Phaser.Math.Vector3} This Vector3. */ lerp: function (v, t) { if (t === undefined) { t = 0; } var ax = this.x; var ay = this.y; var az = this.z; this.x = ax + t * (v.x - ax); this.y = ay + t * (v.y - ay); this.z = az + t * (v.z - az); return this; }, /** * Takes a Matrix3 and applies it to this Vector3. * * @method Phaser.Math.Vector3#applyMatrix3 * @since 3.50.0 * * @param {Phaser.Math.Matrix3} mat3 - The Matrix3 to apply to this Vector3. * * @return {Phaser.Math.Vector3} This Vector3. */ applyMatrix3: function (mat3) { var x = this.x; var y = this.y; var z = this.z; var m = mat3.val; this.x = m[0] * x + m[3] * y + m[6] * z; this.y = m[1] * x + m[4] * y + m[7] * z; this.z = m[2] * x + m[5] * y + m[8] * z; return this; }, /** * Takes a Matrix4 and applies it to this Vector3. * * @method Phaser.Math.Vector3#applyMatrix4 * @since 3.50.0 * * @param {Phaser.Math.Matrix4} mat4 - The Matrix4 to apply to this Vector3. * * @return {Phaser.Math.Vector3} This Vector3. */ applyMatrix4: function (mat4) { var x = this.x; var y = this.y; var z = this.z; var m = mat4.val; var w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]); this.x = (m[0] * x + m[4] * y + m[8] * z + m[12]) * w; this.y = (m[1] * x + m[5] * y + m[9] * z + m[13]) * w; this.z = (m[2] * x + m[6] * y + m[10] * z + m[14]) * w; return this; }, /** * Transform this Vector with the given Matrix. * * @method Phaser.Math.Vector3#transformMat3 * @since 3.0.0 * * @param {Phaser.Math.Matrix3} mat - The Matrix3 to transform this Vector3 with. * * @return {Phaser.Math.Vector3} This Vector3. */ transformMat3: function (mat) { var x = this.x; var y = this.y; var z = this.z; var m = mat.val; this.x = x * m[0] + y * m[3] + z * m[6]; this.y = x * m[1] + y * m[4] + z * m[7]; this.z = x * m[2] + y * m[5] + z * m[8]; return this; }, /** * Transform this Vector with the given Matrix4. * * @method Phaser.Math.Vector3#transformMat4 * @since 3.0.0 * * @param {Phaser.Math.Matrix4} mat - The Matrix4 to transform this Vector3 with. * * @return {Phaser.Math.Vector3} This Vector3. */ transformMat4: function (mat) { var x = this.x; var y = this.y; var z = this.z; var m = mat.val; this.x = m[0] * x + m[4] * y + m[8] * z + m[12]; this.y = m[1] * x + m[5] * y + m[9] * z + m[13]; this.z = m[2] * x + m[6] * y + m[10] * z + m[14]; return this; }, /** * Transforms the coordinates of this Vector3 with the given Matrix4. * * @method Phaser.Math.Vector3#transformCoordinates * @since 3.0.0 * * @param {Phaser.Math.Matrix4} mat - The Matrix4 to transform this Vector3 with. * * @return {Phaser.Math.Vector3} This Vector3. */ transformCoordinates: function (mat) { var x = this.x; var y = this.y; var z = this.z; var m = mat.val; var tx = (x * m[0]) + (y * m[4]) + (z * m[8]) + m[12]; var ty = (x * m[1]) + (y * m[5]) + (z * m[9]) + m[13]; var tz = (x * m[2]) + (y * m[6]) + (z * m[10]) + m[14]; var tw = (x * m[3]) + (y * m[7]) + (z * m[11]) + m[15]; this.x = tx / tw; this.y = ty / tw; this.z = tz / tw; return this; }, /** * Transform this Vector with the given Quaternion. * * @method Phaser.Math.Vector3#transformQuat * @since 3.0.0 * * @para