(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, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // 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 = 1026); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|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; } 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]; } } } 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 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 * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Finds the key within the top level of the {@link source} object, or returns {@link defaultValue} * * @function Phaser.Utils.Object.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; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Components = __webpack_require__(15); var DataManager = __webpack_require__(81); var EventEmitter = __webpack_require__(9); /** * @classdesc * The base class that all Game Objects extend. * You don't create GameObjects directly and they cannot be added to the display list. * Instead, use them as the base for your own custom classes. * * @class GameObject * @memberOf Phaser.GameObjects * @extends Phaser.Events.EventEmitter * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. * @param {string} type - A textual representation of the type of Game Object, i.e. `sprite`. */ var GameObject = new Class({ Extends: EventEmitter, initialize: function GameObject (scene, type) { EventEmitter.call(this); /** * The Scene to which this Game Object belongs. * Game Objects can only belong to one Scene. * * @name Phaser.GameObjects.GameObject#scene * @type {Phaser.Scene} * @protected * @since 3.0.0 */ this.scene = scene; /** * A textual representation of this Game Object, i.e. `sprite`. * Used internally by Phaser but is available for your own custom classes to populate. * * @name Phaser.GameObjects.GameObject#type * @type {string} * @since 3.0.0 */ this.type = type; /** * The parent Container of this Game Object, if it has one. * * @name Phaser.GameObjects.GameObject#parentContainer * @type {Phaser.GameObjects.Container} * @since 3.4.0 */ this.parentContainer = null; /** * The name of this Game Object. * Empty by default and never populated by Phaser, this is left for developers to use. * * @name Phaser.GameObjects.GameObject#name * @type {string} * @default '' * @since 3.0.0 */ this.name = ''; /** * The active state of this Game Object. * A Game Object with an active state of `true` is processed by the Scenes UpdateList, if added to it. * An active object is one which is having its logic and internal systems updated. * * @name Phaser.GameObjects.GameObject#active * @type {boolean} * @default true * @since 3.0.0 */ this.active = true; /** * The Tab Index of the Game Object. * Reserved for future use by plugins and the Input Manager. * * @name Phaser.GameObjects.GameObject#tabIndex * @type {integer} * @default -1 * @since 3.0.0 */ this.tabIndex = -1; /** * A Data Manager. * It allows you to store, query and get key/value paired information specific to this Game Object. * `null` by default. Automatically created if you use `getData` or `setData` or `setDataEnabled`. * * @name Phaser.GameObjects.GameObject#data * @type {Phaser.Data.DataManager} * @default null * @since 3.0.0 */ this.data = null; /** * The flags that are compared against `RENDER_MASK` to determine if this Game Object will render or not. * The bits are 0001 | 0010 | 0100 | 1000 set by the components Visible, Alpha, Transform and Texture respectively. * If those components are not used by your custom class then you can use this bitmask as you wish. * * @name Phaser.GameObjects.GameObject#renderFlags * @type {integer} * @default 15 * @since 3.0.0 */ this.renderFlags = 15; /** * A bitmask that controls if this Game Object is drawn by a Camera or not. * Not usually set directly. Instead call `Camera.ignore`. * * @name Phaser.GameObjects.GameObject#cameraFilter * @type {number} * @default 0 * @since 3.0.0 */ this.cameraFilter = 0; /** * If this Game Object is enabled for input then this property will contain an InteractiveObject instance. * Not usually set directly. Instead call `GameObject.setInteractive()`. * * @name Phaser.GameObjects.GameObject#input * @type {?Phaser.Input.InteractiveObject} * @default null * @since 3.0.0 */ this.input = null; /** * If this Game Object is enabled for physics then this property will contain a reference to a Physics Body. * * @name Phaser.GameObjects.GameObject#body * @type {?(object|Phaser.Physics.Arcade.Body|Phaser.Physics.Impact.Body)} * @default null * @since 3.0.0 */ this.body = null; /** * This Game Object will ignore all calls made to its destroy method if this flag is set to `true`. * This includes calls that may come from a Group, Container or the Scene itself. * While it allows you to persist a Game Object across Scenes, please understand you are entirely * responsible for managing references to and from this Game Object. * * @name Phaser.GameObjects.GameObject#ignoreDestroy * @type {boolean} * @default false * @since 3.5.0 */ this.ignoreDestroy = false; // Tell the Scene to re-sort the children scene.sys.queueDepthSort(); scene.sys.events.once('shutdown', this.destroy, this); }, /** * Sets the `active` property of this Game Object and returns this Game Object for further chaining. * A Game Object with its `active` property set to `true` will be updated by the Scenes UpdateList. * * @method Phaser.GameObjects.GameObject#setActive * @since 3.0.0 * * @param {boolean} value - True if this Game Object should be set as active, false if not. * * @return {Phaser.GameObjects.GameObject} This GameObject. */ setActive: function (value) { this.active = value; return this; }, /** * Sets the `name` property of this Game Object and returns this Game Object for further chaining. * The `name` property is not populated by Phaser and is presented for your own use. * * @method Phaser.GameObjects.GameObject#setName * @since 3.0.0 * * @param {string} value - The name to be given to this Game Object. * * @return {Phaser.GameObjects.GameObject} This GameObject. */ setName: function (value) { this.name = value; return this; }, /** * Adds a Data Manager component to this Game Object. * * @method Phaser.GameObjects.GameObject#setDataEnabled * @since 3.0.0 * @see Phaser.Data.DataManager * * @return {Phaser.GameObjects.GameObject} This GameObject. */ setDataEnabled: function () { if (!this.data) { this.data = new DataManager(this); } return this; }, /** * Allows you to store a key value pair within this Game Objects Data Manager. * * If the Game Object has not been enabled for data (via `setDataEnabled`) then it will be enabled * before setting the value. * * If the key doesn't already exist in the Data Manager then it is created. * * ```javascript * sprite.setData('name', 'Red Gem Stone'); * ``` * * You can also pass in an object of key value pairs as the first argument: * * ```javascript * sprite.setData({ name: 'Red Gem Stone', level: 2, owner: 'Link', gold: 50 }); * ``` * * To get a value back again you can call `getData`: * * ```javascript * sprite.getData('gold'); * ``` * * Or you can access the value directly via the `values` property, where it works like any other variable: * * ```javascript * sprite.data.values.gold += 50; * ``` * * When the value is first set, a `setdata` event is emitted from this Game Object. * * If the key already exists, a `changedata` event is emitted instead, along an event named after the key. * For example, if you updated an existing key called `PlayerLives` then it would emit the event `changedata_PlayerLives`. * These events will be emitted regardless if you use this method to set the value, or the direct `values` setter. * * Please note that the data keys are case-sensitive and must be valid JavaScript Object property strings. * This means the keys `gold` and `Gold` are treated as two unique values within the Data Manager. * * @method Phaser.GameObjects.GameObject#setData * @since 3.0.0 * * @param {(string|object)} key - The key to set the value for. Or an object or key value pairs. If an object the `data` argument is ignored. * @param {*} data - The value to set for the given key. If an object is provided as the key this argument is ignored. * * @return {this} This GameObject. */ setData: function (key, value) { if (!this.data) { this.data = new DataManager(this); } this.data.set(key, value); return this; }, /** * Retrieves the value for the given key in this Game Objects Data Manager, or undefined if it doesn't exist. * * You can also access values via the `values` object. For example, if you had a key called `gold` you can do either: * * ```javascript * sprite.getData('gold'); * ``` * * Or access the value directly: * * ```javascript * sprite.data.values.gold; * ``` * * You can also pass in an array of keys, in which case an array of values will be returned: * * ```javascript * sprite.getData([ 'gold', 'armor', 'health' ]); * ``` * * This approach is useful for destructuring arrays in ES6. * * @method Phaser.GameObjects.GameObject#getData * @since 3.0.0 * * @param {(string|string[])} key - The key of the value to retrieve, or an array of keys. * * @return {*} The value belonging to the given key, or an array of values, the order of which will match the input array. */ getData: function (key) { if (!this.data) { this.data = new DataManager(this); } return this.data.get(key); }, /** * Pass this Game Object to the Input Manager to enable it for Input. * * Input works by using hit areas, these are nearly always geometric shapes, such as rectangles or circles, that act as the hit area * for the Game Object. However, you can provide your own hit area shape and callback, should you wish to handle some more advanced * input detection. * * If no arguments are provided it will try and create a rectangle hit area based on the texture frame the Game Object is using. If * this isn't a texture-bound object, such as a Graphics or BitmapText object, this will fail, and you'll need to provide a specific * shape for it to use. * * You can also provide an Input Configuration Object as the only argument to this method. * * @method Phaser.GameObjects.GameObject#setInteractive * @since 3.0.0 * * @param {(Phaser.Input.InputConfiguration|any)} [shape] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used. * @param {HitAreaCallback} [callback] - A callback to be invoked when the Game Object is interacted with. If you provide a shape you must also provide a callback. * @param {boolean} [dropZone=false] - Should this Game Object be treated as a drop zone target? * * @return {Phaser.GameObjects.GameObject} This GameObject. */ setInteractive: function (shape, callback, dropZone) { this.scene.sys.input.enable(this, shape, callback, dropZone); return this; }, /** * If this Game Object has previously been enabled for input, this will disable it. * * An object that is disabled for input stops processing or being considered for * input events, but can be turned back on again at any time by simply calling * `setInteractive()` with no arguments provided. * * If want to completely remove interaction from this Game Object then use `removeInteractive` instead. * * @method Phaser.GameObjects.GameObject#disableInteractive * @since 3.7.0 * * @return {Phaser.GameObjects.GameObject} This GameObject. */ disableInteractive: function () { if (this.input) { this.input.enabled = (this.input.enabled) ? false : true; } return this; }, /** * If this Game Object has previously been enabled for input, this will remove it. * * The Interactive Object that was assigned to this Game Object will be destroyed, * removed from the Input Manager and cleared from this Game Object. * * If you wish to re-enable this Game Object at a later date you will need to * re-create its InteractiveOobject by calling `setInteractive` again. * * If you wish to only temporarily stop an object from receiving input then use * `disableInteractive` instead, as that toggles the interactive state, where-as * this erases it completely. * * @method Phaser.GameObjects.GameObject#removeInteractive * @since 3.7.0 * * @return {Phaser.GameObjects.GameObject} This GameObject. */ removeInteractive: function () { this.scene.sys.input.clear(this); this.input = undefined; return this; }, /** * To be overridden by custom GameObjects. Allows base objects to be used in a Pool. * * @method Phaser.GameObjects.GameObject#update * @since 3.0.0 */ update: function () { }, /** * Returns a JSON representation of the Game Object. * * @method Phaser.GameObjects.GameObject#toJSON * @since 3.0.0 * * @return {JSONGameObject} A JSON representation of the Game Object. */ toJSON: function () { return Components.ToJSON(this); }, /** * Compares the renderMask with the renderFlags to see if this Game Object will render or not. * * @method Phaser.GameObjects.GameObject#willRender * @since 3.0.0 * * @return {boolean} True if the Game Object should be rendered, otherwise false. */ willRender: function () { return (GameObject.RENDER_MASK === this.renderFlags); }, /** * Returns an array containing the display list index of either this Game Object, or if it has one, * its parent Container. It then iterates up through all of the parent containers until it hits the * root of the display list (which is index 0 in the returned array). * * Used internally by the InputPlugin but also useful if you wish to find out the display depth of * this Game Object and all of its ancestors. * * @method Phaser.GameObjects.GameObject#getIndexList * @since 3.4.0 * * @return {integer[]} An array of display list position indexes. */ getIndexList: function () { // eslint-disable-next-line consistent-this var child = this; var parent = this.parentContainer; var indexes = []; while (parent) { // indexes.unshift([parent.getIndex(child), parent.name]); indexes.unshift(parent.getIndex(child)); child = parent; if (!parent.parentContainer) { break; } else { parent = parent.parentContainer; } } // indexes.unshift([this.scene.sys.displayList.getIndex(child), 'root']); indexes.unshift(this.scene.sys.displayList.getIndex(child)); return indexes; }, /** * Destroys this Game Object removing it from the Display List and Update List and * severing all ties to parent resources. * * Also removes itself from the Input Manager and Physics Manager if previously enabled. * * Use this to remove a Game Object from your game if you don't ever plan to use it again. * As long as no reference to it exists within your own code it should become free for * garbage collection by the browser. * * If you just want to temporarily disable an object then look at using the * Game Object Pool instead of destroying it, as destroyed objects cannot be resurrected. * * @method Phaser.GameObjects.GameObject#destroy * @since 3.0.0 */ destroy: function () { // This Game Object had already been destroyed if (!this.scene || this.ignoreDestroy) { return; } if (this.preDestroy) { this.preDestroy.call(this); } this.emit('destroy', this); var sys = this.scene.sys; sys.displayList.remove(this); sys.updateList.remove(this); if (this.input) { sys.input.clear(this); this.input = undefined; } if (this.data) { this.data.destroy(); this.data = undefined; } if (this.body) { this.body.destroy(); this.body = undefined; } // Tell the Scene to re-sort the children sys.queueDepthSort(); this.active = false; this.visible = false; this.scene = undefined; this.parentContainer = undefined; this.removeAllListeners(); } }); /** * The bitmask that `GameObject.renderFlags` is compared against to determine if the Game Object will render or not. * * @constant {integer} RENDER_MASK * @memberOf Phaser.GameObjects.GameObject * @default */ GameObject.RENDER_MASK = 15; module.exports = GameObject; /***/ }), /* 3 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|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; /***/ }), /* 4 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|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 /** * [description] * * @function Phaser.Utils.Object.GetValue * @since 3.0.0 * * @param {object} source - [description] * @param {string} key - [description] * @param {*} defaultValue - [description] * * @return {*} [description] */ 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('.')) { 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; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @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 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 {Phaser.Geom.Point} 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; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|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); /** * @typedef {object} Vector2Like * * @property {number} x - The x component. * @property {number} y - The y component. */ /** * @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} [x] - The x component. * @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 {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 {float} azimuth - The angular coordinate, in radians. * @param {float} [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)); }, /** * 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; }, /** * 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); }, /** * 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; }, /** * Right-hand normalize (make unit length) this Vector. * * @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; }, /** * 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; }, /** * [description] * * @method Phaser.Math.Vector2#cross * @since 3.0.0 * * @param {Phaser.Math.Vector2} src - [description] * * @return {number} [description] */ 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; } }); /** * A static zero Vector2 for use by reference. * * @method Phaser.Math.Vector2.ZERO * @since 3.1.0 */ Vector2.ZERO = new Vector2(); module.exports = Vector2; /***/ }), /* 7 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var types = {}; 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.register * @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; /***/ }), /* 8 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|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.Object.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; /***/ }), /* 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].fn; } return ee; }; /** * Return the number of listeners listening to a given event. * * @param {(String|Symbol)} event The event name. * @returns {Number} The number of listeners. * @public */ EventEmitter.prototype.listenerCount = function listenerCount(event) { var evt = prefix ? prefix + event : event , listeners = this._events[evt]; if (!listeners) return 0; if (listeners.fn) return 1; return listeners.length; }; /** * Calls each of the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Boolean} `true` if the event had listeners, else `false`. * @public */ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return false; var listeners = this._events[evt] , len = arguments.length , args , i; if (listeners.fn) { if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); switch (len) { case 1: return listeners.fn.call(listeners.context), true; case 2: return listeners.fn.call(listeners.context, a1), true; case 3: return listeners.fn.call(listeners.context, a1, a2), true; case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; } for (i = 1, args = new Array(len -1); i < len; i++) { args[i - 1] = arguments[i]; } listeners.fn.apply(listeners.context, args); } else { var length = listeners.length , j; for (i = 0; i < length; i++) { if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); switch (len) { case 1: listeners[i].fn.call(listeners[i].context); break; case 2: listeners[i].fn.call(listeners[i].context, a1); break; case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; default: if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { args[j - 1] = arguments[j]; } listeners[i].fn.apply(listeners[i].context, args); } } } return true; }; /** * Add a listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.on = function on(event, fn, context) { return addListener(this, event, fn, context, false); }; /** * Add a one-time listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.once = function once(event, fn, context) { return addListener(this, event, fn, context, true); }; /** * Remove the listeners of a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn Only remove the listeners that match this function. * @param {*} context Only remove the listeners that have this context. * @param {Boolean} once Only remove one-time listeners. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return this; if (!fn) { clearEvent(this, evt); return this; } var listeners = this._events[evt]; if (listeners.fn) { if ( listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context) ) { clearEvent(this, evt); } } else { for (var i = 0, events = [], length = listeners.length; i < length; i++) { if ( listeners[i].fn !== fn || (once && !listeners[i].once) || (context && listeners[i].context !== context) ) { events.push(listeners[i]); } } // // Reset the array, or remove it completely if we have no more listeners. // if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; else clearEvent(this, evt); } return this; }; /** * Remove all listeners, or those of the specified event. * * @param {(String|Symbol)} [event] The event name. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { var evt; if (event) { evt = prefix ? prefix + event : event; if (this._events[evt]) clearEvent(this, evt); } else { this._events = new Events(); this._eventsCount = 0; } return this; }; // // Alias methods names because people roll like that. // EventEmitter.prototype.off = EventEmitter.prototype.removeListener; EventEmitter.prototype.addListener = EventEmitter.prototype.on; // // Expose the prefix. // EventEmitter.prefixed = prefix; // // Allow `EventEmitter` to be imported as module namespace. // EventEmitter.EventEmitter = EventEmitter; // // Expose the module. // if (true) { module.exports = EventEmitter; } /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var MATH = __webpack_require__(16); var GetValue = __webpack_require__(4); // Allowed types: // Implicit // { // x: 4 // } // // From function // { // x: function () // } // // Randomly pick one element from the array // { // x: [a, b, c, d, e, f] // } // // Random integer between min and max: // { // x: { randInt: [min, max] } // } // // Random float between min and max: // { // x: { randFloat: [min, max] } // } /** * [description] * * @function Phaser.Utils.Object.GetAdvancedValue * @since 3.0.0 * * @param {object} source - [description] * @param {string} key - [description] * @param {*} defaultValue - [description] * * @return {*} [description] */ var GetAdvancedValue = function (source, key, defaultValue) { var value = GetValue(source, key, null); if (value === null) { return defaultValue; } else if (Array.isArray(value)) { return MATH.RND.pick(value); } else if (typeof value === 'object') { if (value.hasOwnProperty('randInt')) { return MATH.RND.integerInRange(value.randInt[0], value.randInt[1]); } else if (value.hasOwnProperty('randFloat')) { return MATH.RND.realInRange(value.randFloat[0], value.randFloat[1]); } } else if (typeof value === 'function') { return value(key); } return value; }; module.exports = GetAdvancedValue; /***/ }), /* 11 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var PluginCache = __webpack_require__(12); /** * @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 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; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('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.systems.events.once('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.systems.events.once('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 * * @param {Phaser.GameObjects.GameObject} 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); } 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.systems.events.off('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.scene.sys.events.off('start', this.start, this); this.scene = null; this.systems = null; this.displayList = null; this.updateList = null; } }); // Static method called directly by the Game Object factory functions GameObjectFactory.register = function (factoryType, factoryFunction) { if (!GameObjectFactory.prototype.hasOwnProperty(factoryType)) { GameObjectFactory.prototype[factoryType] = factoryFunction; } }; PluginCache.register('GameObjectFactory', GameObjectFactory, 'add'); module.exports = GameObjectFactory; /***/ }), /* 12 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // Contains the plugins that Phaser uses globally and locally. // These are the source objects, not instantiated. var corePlugins = {}; // Contains the plugins that the dev has loaded into their game // These are the source objects, not instantiated. var customPlugins = {}; /** * @typedef {object} CorePluginContainer * * @property {string} key - The unique name of this plugin in the core plugin cache. * @property {function} plugin - The plugin to be stored. Should be the source object, not instantiated. * @property {string} [mapping] - If this plugin is to be injected into the Scene Systems, this is the property key map used. * @property {boolean} [custom=false] - Core Scene plugin or a Custom Scene plugin? */ /** * @typedef {object} CustomPluginContainer * * @property {string} key - The unique name of this plugin in the custom plugin cache. * @property {function} plugin - The plugin to be stored. Should be the source object, not instantiated. */ var PluginCache = {}; /** * Static method called directly by the Core internal Plugins. * Key is a reference used to get the plugin from the plugins object (i.e. InputPlugin) * Plugin is the object to instantiate to create the plugin * Mapping is what the plugin is injected into the Scene.Systems as (i.e. input) * * @method Phaser.Plugins.PluginCache.register * @since 3.8.0 * * @param {string} key - A reference used to get this plugin from the plugin cache. * @param {function} plugin - The plugin to be stored. Should be the core object, not instantiated. * @param {string} mapping - If this plugin is to be injected into the Scene Systems, this is the property key map used. * @param {boolean} [custom=false] - Core Scene plugin or a Custom Scene plugin? */ PluginCache.register = function (key, plugin, mapping, custom) { if (custom === undefined) { custom = false; } corePlugins[key] = { plugin: plugin, mapping: mapping, custom: custom }; }; /** * Stores a custom plugin in the global plugin cache. * The key must be unique, within the scope of the cache. * * @method Phaser.Plugins.PluginCache.registerCustom * @since 3.8.0 * * @param {string} key - A reference used to get this plugin from the plugin cache. * @param {function} plugin - The plugin to be stored. Should be the core object, not instantiated. * @param {string} mapping - If this plugin is to be injected into the Scene Systems, this is the property key map used. */ PluginCache.registerCustom = function (key, plugin, mapping) { customPlugins[key] = { plugin: plugin, mapping: mapping }; }; /** * Checks if the given key is already being used in the core plugin cache. * * @method Phaser.Plugins.PluginCache.hasCore * @since 3.8.0 * * @param {string} key - The key to check for. * * @return {boolean} `true` if the key is already in use in the core cache, otherwise `false`. */ PluginCache.hasCore = function (key) { return corePlugins.hasOwnProperty(key); }; /** * Checks if the given key is already being used in the custom plugin cache. * * @method Phaser.Plugins.PluginCache.hasCustom * @since 3.8.0 * * @param {string} key - The key to check for. * * @return {boolean} `true` if the key is already in use in the custom cache, otherwise `false`. */ PluginCache.hasCustom = function (key) { return customPlugins.hasOwnProperty(key); }; /** * Returns the core plugin object from the cache based on the given key. * * @method Phaser.Plugins.PluginCache.getCore * @since 3.8.0 * * @param {string} key - The key of the core plugin to get. * * @return {CorePluginContainer} The core plugin object. */ PluginCache.getCore = function (key) { return corePlugins[key]; }; /** * Returns the custom plugin object from the cache based on the given key. * * @method Phaser.Plugins.PluginCache.getCustom * @since 3.8.0 * * @param {string} key - The key of the custom plugin to get. * * @return {CustomPluginContainer} The custom plugin object. */ PluginCache.getCustom = function (key) { return customPlugins[key]; }; /** * Returns an object from the custom cache based on the given key that can be instantiated. * * @method Phaser.Plugins.PluginCache.getCustomClass * @since 3.8.0 * * @param {string} key - The key of the custom plugin to get. * * @return {function} The custom plugin object. */ PluginCache.getCustomClass = function (key) { return (customPlugins.hasOwnProperty(key)) ? customPlugins[key].plugin : null; }; /** * Removes a core plugin based on the given key. * * @method Phaser.Plugins.PluginCache.remove * @since 3.8.0 * * @param {string} key - The key of the core plugin to remove. */ PluginCache.remove = function (key) { if (corePlugins.hasOwnProperty(key)) { delete corePlugins[key]; } }; /** * Removes a custom plugin based on the given key. * * @method Phaser.Plugins.PluginCache.removeCustom * @since 3.8.0 * * @param {string} key - The key of the custom plugin to remove. */ PluginCache.removeCustom = function (key) { if (customPlugins.hasOwnProperty(key)) { delete customPlugins[key]; } }; module.exports = PluginCache; /***/ }), /* 13 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var PluginCache = __webpack_require__(12); /** * @classdesc * The Game Object Creator is a Scene plugin that allows you to quickly create many common * types of Game Objects and return them. Unlike the Game Object Factory, they are not automatically * added to the Scene. * * Game Objects directly register themselves with the Creator and inject their own creation * methods into the class. * * @class GameObjectCreator * @memberOf Phaser.GameObjects * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene to which this Game Object Factory belongs. */ var GameObjectCreator = new Class({ initialize: function GameObjectCreator (scene) { /** * The Scene to which this Game Object Creator belongs. * * @name Phaser.GameObjects.GameObjectCreator#scene * @type {Phaser.Scene} * @protected * @since 3.0.0 */ this.scene = scene; /** * A reference to the Scene.Systems. * * @name Phaser.GameObjects.GameObjectCreator#systems * @type {Phaser.Scenes.Systems} * @protected * @since 3.0.0 */ this.systems = scene.sys; /** * A reference to the Scene Display List. * * @name Phaser.GameObjects.GameObjectCreator#displayList * @type {Phaser.GameObjects.DisplayList} * @protected * @since 3.0.0 */ this.displayList; /** * A reference to the Scene Update List. * * @name Phaser.GameObjects.GameObjectCreator#updateList; * @type {Phaser.GameObjects.UpdateList} * @protected * @since 3.0.0 */ this.updateList; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('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.GameObjectCreator#boot * @private * @since 3.5.1 */ boot: function () { this.displayList = this.systems.displayList; this.updateList = this.systems.updateList; this.systems.events.once('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.GameObjectCreator#start * @private * @since 3.5.0 */ start: function () { this.systems.events.once('shutdown', this.shutdown, this); }, /** * 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.GameObjectCreator#shutdown * @private * @since 3.0.0 */ shutdown: function () { this.systems.events.off('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.GameObjectCreator#destroy * @private * @since 3.0.0 */ destroy: function () { this.shutdown(); this.scene.sys.events.off('start', this.start, this); this.scene = null; this.systems = null; this.displayList = null; this.updateList = null; } }); // Static method called directly by the Game Object creator functions GameObjectCreator.register = function (factoryType, factoryFunction) { if (!GameObjectCreator.prototype.hasOwnProperty(factoryType)) { GameObjectCreator.prototype[factoryType] = factoryFunction; } }; PluginCache.register('GameObjectCreator', GameObjectCreator, 'make'); module.exports = GameObjectCreator; /***/ }), /* 14 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Contains = __webpack_require__(31); var GetPoint = __webpack_require__(135); var GetPoints = __webpack_require__(294); var Line = __webpack_require__(96); var Random = __webpack_require__(154); /** * @classdesc * Encapsulates a 2D rectangle defined by its corner point in the top-left and its extends in x (width) and y (height) * * @class Rectangle * @memberOf Phaser.Geom * @constructor * @since 3.0.0 * * @param {number} [x=0] - [description] * @param {number} [y=0] - [description] * @param {number} [width=0] - [description] * @param {number} [height=0] - [description] */ var Rectangle = new Class({ initialize: function Rectangle (x, y, width, height) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = 0; } if (height === undefined) { height = 0; } /** * [description] * * @name Phaser.Geom.Rectangle#x * @type {number} * @default 0 * @since 3.0.0 */ this.x = x; /** * [description] * * @name Phaser.Geom.Rectangle#y * @type {number} * @default 0 * @since 3.0.0 */ this.y = y; /** * [description] * * @name Phaser.Geom.Rectangle#width * @type {number} * @default 0 * @since 3.0.0 */ this.width = width; /** * [description] * * @name Phaser.Geom.Rectangle#height * @type {number} * @default 0 * @since 3.0.0 */ this.height = height; }, /** * [description] * * @method Phaser.Geom.Rectangle#contains * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * * @return {boolean} [description] */ contains: function (x, y) { return Contains(this, x, y); }, /** * [description] * * @method Phaser.Geom.Rectangle#getPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [output,$return] * * @param {float} position - [description] * @param {(Phaser.Geom.Point|object)} [output] - [description] * * @return {(Phaser.Geom.Point|object)} [description] */ getPoint: function (position, output) { return GetPoint(this, position, output); }, /** * [description] * * @method Phaser.Geom.Rectangle#getPoints * @since 3.0.0 * * @generic {Phaser.Geom.Point[]} O - [output,$return] * * @param {integer} quantity - [description] * @param {number} [stepRate] - [description] * @param {(array|Phaser.Geom.Point[])} [output] - [description] * * @return {(array|Phaser.Geom.Point[])} [description] */ getPoints: function (quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); }, /** * [description] * * @method Phaser.Geom.Rectangle#getRandomPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [point,$return] * * @param {Phaser.Geom.Point} [point] - [description] * * @return {Phaser.Geom.Point} [description] */ getRandomPoint: function (point) { return Random(this, point); }, /** * [description] * * @method Phaser.Geom.Rectangle#setTo * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * @param {number} width - [description] * @param {number} height - [description] * * @return {Phaser.Geom.Rectangle} This Rectangle object. */ setTo: function (x, y, width, height) { this.x = x; this.y = y; this.width = width; this.height = height; return this; }, /** * [description] * * @method Phaser.Geom.Rectangle#setEmpty * @since 3.0.0 * * @return {Phaser.Geom.Rectangle} This Rectangle object. */ setEmpty: function () { return this.setTo(0, 0, 0, 0); }, /** * [description] * * @method Phaser.Geom.Rectangle#setPosition * @since 3.0.0 * * @param {number} x - [description] * @param {number} [y=x] - [description] * * @return {Phaser.Geom.Rectangle} This Rectangle object. */ setPosition: function (x, y) { if (y === undefined) { y = x; } this.x = x; this.y = y; return this; }, /** * [description] * * @method Phaser.Geom.Rectangle#setSize * @since 3.0.0 * * @param {number} width - [description] * @param {number} [height=width] - [description] * * @return {Phaser.Geom.Rectangle} This Rectangle object. */ setSize: function (width, height) { if (height === undefined) { height = width; } this.width = width; this.height = height; return this; }, /** * [description] * * @method Phaser.Geom.Rectangle#isEmpty * @since 3.0.0 * * @return {boolean} [description] */ isEmpty: function () { return (this.width <= 0 || this.height <= 0); }, /** * Returns a Line object that corresponds to the top of this Rectangle. * * @method Phaser.Geom.Rectangle#getLineA * @since 3.0.0 * * @generic {Phaser.Geom.Line} O - [line,$return] * * @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created. * * @return {Phaser.Geom.Line} A Line object that corresponds to the top of this Rectangle. */ getLineA: function (line) { if (line === undefined) { line = new Line(); } line.setTo(this.x, this.y, this.right, this.y); return line; }, /** * Returns a Line object that corresponds to the right of this Rectangle. * * @method Phaser.Geom.Rectangle#getLineB * @since 3.0.0 * * @generic {Phaser.Geom.Line} O - [line,$return] * * @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created. * * @return {Phaser.Geom.Line} A Line object that corresponds to the right of this Rectangle. */ getLineB: function (line) { if (line === undefined) { line = new Line(); } line.setTo(this.right, this.y, this.right, this.bottom); return line; }, /** * Returns a Line object that corresponds to the bottom of this Rectangle. * * @method Phaser.Geom.Rectangle#getLineC * @since 3.0.0 * * @generic {Phaser.Geom.Line} O - [line,$return] * * @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created. * * @return {Phaser.Geom.Line} A Line object that corresponds to the bottom of this Rectangle. */ getLineC: function (line) { if (line === undefined) { line = new Line(); } line.setTo(this.right, this.bottom, this.x, this.bottom); return line; }, /** * Returns a Line object that corresponds to the left of this Rectangle. * * @method Phaser.Geom.Rectangle#getLineD * @since 3.0.0 * * @generic {Phaser.Geom.Line} O - [line,$return] * * @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created. * * @return {Phaser.Geom.Line} A Line object that corresponds to the left of this Rectangle. */ getLineD: function (line) { if (line === undefined) { line = new Line(); } line.setTo(this.x, this.bottom, this.x, this.y); return line; }, /** * [description] * * @name Phaser.Geom.Rectangle#left * @type {number} * @since 3.0.0 */ left: { get: function () { return this.x; }, set: function (value) { if (value >= this.right) { this.width = 0; } else { this.width = this.right - value; } this.x = value; } }, /** * [description] * * @name Phaser.Geom.Rectangle#right * @type {number} * @since 3.0.0 */ right: { get: function () { return this.x + this.width; }, set: function (value) { if (value <= this.x) { this.width = 0; } else { this.width = value - this.x; } } }, /** * [description] * * @name Phaser.Geom.Rectangle#top * @type {number} * @since 3.0.0 */ top: { get: function () { return this.y; }, set: function (value) { if (value >= this.bottom) { this.height = 0; } else { this.height = (this.bottom - value); } this.y = value; } }, /** * [description] * * @name Phaser.Geom.Rectangle#bottom * @type {number} * @since 3.0.0 */ bottom: { get: function () { return this.y + this.height; }, set: function (value) { if (value <= this.y) { this.height = 0; } else { this.height = value - this.y; } } }, /** * [description] * * @name Phaser.Geom.Rectangle#centerX * @type {number} * @since 3.0.0 */ centerX: { get: function () { return this.x + (this.width / 2); }, set: function (value) { this.x = value - (this.width / 2); } }, /** * [description] * * @name Phaser.Geom.Rectangle#centerY * @type {number} * @since 3.0.0 */ centerY: { get: function () { return this.y + (this.height / 2); }, set: function (value) { this.y = value - (this.height / 2); } } }); module.exports = Rectangle; /***/ }), /* 15 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.GameObjects.Components */ module.exports = { Alpha: __webpack_require__(587), Animation: __webpack_require__(302), BlendMode: __webpack_require__(586), ComputedSize: __webpack_require__(585), Depth: __webpack_require__(584), Flip: __webpack_require__(583), GetBounds: __webpack_require__(582), Mask: __webpack_require__(581), MatrixStack: __webpack_require__(580), Origin: __webpack_require__(579), Pipeline: __webpack_require__(291), ScaleMode: __webpack_require__(578), ScrollFactor: __webpack_require__(577), Size: __webpack_require__(576), Texture: __webpack_require__(575), Tint: __webpack_require__(574), ToJSON: __webpack_require__(573), Transform: __webpack_require__(572), TransformMatrix: __webpack_require__(64), Visible: __webpack_require__(571) }; /***/ }), /* 16 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var RND = __webpack_require__(297); 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. * * @name Phaser.Math.RND * @type {Phaser.Math.RandomDataGenerator} * @since 3.0.0 */ RND: new RND() }; module.exports = MATH_CONST; /***/ }), /* 17 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var IsPlainObject = __webpack_require__(8); // @param {boolean} deep - Perform a deep copy? // @param {object} target - The target object to copy to. // @return {object} The extended object. /** * This is a slightly modified version of http://api.jquery.com/jQuery.extend/ * * @function Phaser.Utils.Object.Extend * @since 3.0.0 * * @return {object} [description] */ var Extend = function () { var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = false; // Handle a deep copy situation if (typeof target === 'boolean') { deep = target; target = arguments[1] || {}; // skip the boolean and the target i = 2; } // extend Phaser if only one argument is passed if (length === i) { target = this; --i; } for (; i < length; i++) { // Only deal with non-null/undefined values if ((options = arguments[i]) != null) { // Extend the base object for (name in options) { src = target[name]; copy = options[name]; // Prevent never-ending loop if (target === copy) { continue; } // Recurse if we're merging plain objects or arrays if (deep && copy && (IsPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) { if (copyIsArray) { copyIsArray = false; clone = src && Array.isArray(src) ? src : []; } else { clone = src && IsPlainObject(src) ? src : {}; } // Never move original objects, clone them target[name] = Extend(deep, clone, copy); // Don't bring in undefined values } else if (copy !== undefined) { target[name] = copy; } } } } // Return the modified object return target; }; module.exports = Extend; /***/ }), /* 18 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var FILE_CONST = { /** * The Loader is idle. * * @name Phaser.Loader.LOADER_IDLE * @type {integer} * @since 3.0.0 */ LOADER_IDLE: 0, /** * The Loader is actively loading. * * @name Phaser.Loader.LOADER_LOADING * @type {integer} * @since 3.0.0 */ LOADER_LOADING: 1, /** * The Loader is processing files is has loaded. * * @name Phaser.Loader.LOADER_PROCESSING * @type {integer} * @since 3.0.0 */ LOADER_PROCESSING: 2, /** * The Loader has completed loading and processing. * * @name Phaser.Loader.LOADER_COMPLETE * @type {integer} * @since 3.0.0 */ LOADER_COMPLETE: 3, /** * The Loader is shutting down. * * @name Phaser.Loader.LOADER_SHUTDOWN * @type {integer} * @since 3.0.0 */ LOADER_SHUTDOWN: 4, /** * The Loader has been destroyed. * * @name Phaser.Loader.LOADER_DESTROYED * @type {integer} * @since 3.0.0 */ LOADER_DESTROYED: 5, /** * File is in the load queue but not yet started * * @name Phaser.Loader.FILE_PENDING * @type {integer} * @since 3.0.0 */ FILE_PENDING: 10, /** * File has been started to load by the loader (onLoad called) * * @name Phaser.Loader.FILE_LOADING * @type {integer} * @since 3.0.0 */ FILE_LOADING: 11, /** * File has loaded successfully, awaiting processing * * @name Phaser.Loader.FILE_LOADED * @type {integer} * @since 3.0.0 */ FILE_LOADED: 12, /** * File failed to load * * @name Phaser.Loader.FILE_FAILED * @type {integer} * @since 3.0.0 */ FILE_FAILED: 13, /** * File is being processed (onProcess callback) * * @name Phaser.Loader.FILE_PROCESSING * @type {integer} * @since 3.0.0 */ FILE_PROCESSING: 14, /** * The File has errored somehow during processing. * * @name Phaser.Loader.FILE_ERRORED * @type {integer} * @since 3.0.0 */ FILE_ERRORED: 16, /** * File has finished processing. * * @name Phaser.Loader.FILE_COMPLETE * @type {integer} * @since 3.0.0 */ FILE_COMPLETE: 17, /** * File has been destroyed * * @name Phaser.Loader.FILE_DESTROYED * @type {integer} * @since 3.0.0 */ FILE_DESTROYED: 18, /** * File was populated from local data and doesn't need an HTTP request * * @name Phaser.Loader.FILE_POPULATED * @type {integer} * @since 3.0.0 */ FILE_POPULATED: 19 }; module.exports = FILE_CONST; /***/ }), /* 19 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(18); var GetFastValue = __webpack_require__(1); var GetURL = __webpack_require__(108); var MergeXHRSettings = __webpack_require__(107); var XHRLoader = __webpack_require__(169); var XHRSettings = __webpack_require__(75); /** * @typedef {object} FileConfig * * @property {string} type - The file type string (image, json, etc) for sorting within the Loader. * @property {string} key - Unique cache key (unique within its file type) * @property {string} [url] - The URL of the file, not including baseURL. * @property {string} [path] - The path of the file, not including the baseURL. * @property {string} [extension] - The default extension this file uses. * @property {XMLHttpRequestResponseType} [responseType] - The responseType to be used by the XHR request. * @property {(XHRSettingsObject|false)} [xhrSettings=false] - Custom XHR Settings specific to this file and merged with the Loader defaults. * @property {any} [config] - A config object that can be used by file types to store transitional data. */ /** * @classdesc * The base File class used by all File Types that the Loader can support. * You shouldn't create an instance of a File directly, but should extend it with your own class, setting a custom type and processing methods. * * @class File * @memberOf Phaser.Loader * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - The Loader that is going to load this File. * @param {FileConfig} fileConfig - The file configuration object, as created by the file type. */ var File = new Class({ initialize: function File (loader, fileConfig) { /** * A reference to the Loader that is going to load this file. * * @name Phaser.Loader.File#loader * @type {Phaser.Loader.LoaderPlugin} * @since 3.0.0 */ this.loader = loader; /** * A reference to the Cache, or Texture Manager, that is going to store this file if it loads. * * @name Phaser.Loader.File#cache * @type {(Phaser.Cache.BaseCache|Phaser.Textures.TextureManager)} * @since 3.7.0 */ this.cache = GetFastValue(fileConfig, 'cache', false); /** * The file type string (image, json, etc) for sorting within the Loader. * * @name Phaser.Loader.File#type * @type {string} * @since 3.0.0 */ this.type = GetFastValue(fileConfig, 'type', false); /** * Unique cache key (unique within its file type) * * @name Phaser.Loader.File#key * @type {string} * @since 3.0.0 */ this.key = GetFastValue(fileConfig, 'key', false); var loadKey = this.key; if (loader.prefix && loader.prefix !== '') { this.key = loader.prefix + loadKey; } if (!this.type || !this.key) { throw new Error('Error calling \'Loader.' + this.type + '\' invalid key provided.'); } /** * The URL of the file, not including baseURL. * Automatically has Loader.path prepended to it. * * @name Phaser.Loader.File#url * @type {string} * @since 3.0.0 */ this.url = GetFastValue(fileConfig, 'url'); if (this.url === undefined) { this.url = loader.path + loadKey + '.' + GetFastValue(fileConfig, 'extension', ''); } else if (typeof(this.url) !== 'function') { this.url = loader.path + this.url; } /** * The final URL this file will load from, including baseURL and path. * Set automatically when the Loader calls 'load' on this file. * * @name Phaser.Loader.File#src * @type {string} * @since 3.0.0 */ this.src = ''; /** * The merged XHRSettings for this file. * * @name Phaser.Loader.File#xhrSettings * @type {XHRSettingsObject} * @since 3.0.0 */ this.xhrSettings = XHRSettings(GetFastValue(fileConfig, 'responseType', undefined)); if (GetFastValue(fileConfig, 'xhrSettings', false)) { this.xhrSettings = MergeXHRSettings(this.xhrSettings, GetFastValue(fileConfig, 'xhrSettings', {})); } /** * The XMLHttpRequest instance (as created by XHR Loader) that is loading this File. * * @name Phaser.Loader.File#xhrLoader * @type {?XMLHttpRequest} * @since 3.0.0 */ this.xhrLoader = null; /** * The current state of the file. One of the FILE_CONST values. * * @name Phaser.Loader.File#state * @type {integer} * @since 3.0.0 */ this.state = (typeof(this.url) === 'function') ? CONST.FILE_POPULATED : CONST.FILE_PENDING; /** * The total size of this file. * Set by onProgress and only if loading via XHR. * * @name Phaser.Loader.File#bytesTotal * @type {number} * @default 0 * @since 3.0.0 */ this.bytesTotal = 0; /** * Updated as the file loads. * Only set if loading via XHR. * * @name Phaser.Loader.File#bytesLoaded * @type {number} * @default -1 * @since 3.0.0 */ this.bytesLoaded = -1; /** * A percentage value between 0 and 1 indicating how much of this file has loaded. * Only set if loading via XHR. * * @name Phaser.Loader.File#percentComplete * @type {float} * @default -1 * @since 3.0.0 */ this.percentComplete = -1; /** * For CORs based loading. * If this is undefined then the File will check BaseLoader.crossOrigin and use that (if set) * * @name Phaser.Loader.File#crossOrigin * @type {(string|undefined)} * @since 3.0.0 */ this.crossOrigin = undefined; /** * The processed file data, stored here after the file has loaded. * * @name Phaser.Loader.File#data * @type {*} * @since 3.0.0 */ this.data = undefined; /** * A config object that can be used by file types to store transitional data. * * @name Phaser.Loader.File#config * @type {*} * @since 3.0.0 */ this.config = GetFastValue(fileConfig, 'config', {}); /** * If this is a multipart file, i.e. an atlas and its json together, then this is a reference * to the parent MultiFile. Set and used internally by the Loader or specific file types. * * @name Phaser.Loader.File#multiFile * @type {?Phaser.Loader.MultiFile} * @since 3.7.0 */ this.multiFile; /** * Does this file have an associated linked file? Such as an image and a normal map. * Atlases and Bitmap Fonts use the multiFile, because those files need loading together but aren't * actually bound by data, where-as a linkFile is. * * @name Phaser.Loader.File#linkFile * @type {?Phaser.Loader.File} * @since 3.7.0 */ this.linkFile; }, /** * Links this File with another, so they depend upon each other for loading and processing. * * @method Phaser.Loader.File#setLink * @since 3.7.0 * * @param {Phaser.Loader.File} fileB - The file to link to this one. */ setLink: function (fileB) { this.linkFile = fileB; fileB.linkFile = this; }, /** * Resets the XHRLoader instance this file is using. * * @method Phaser.Loader.File#resetXHR * @since 3.0.0 */ resetXHR: function () { if (this.xhrLoader) { this.xhrLoader.onload = undefined; this.xhrLoader.onerror = undefined; this.xhrLoader.onprogress = undefined; } }, /** * Called by the Loader, starts the actual file downloading. * During the load the methods onLoad, onError and onProgress are called, based on the XHR events. * You shouldn't normally call this method directly, it's meant to be invoked by the Loader. * * @method Phaser.Loader.File#load * @since 3.0.0 */ load: function () { if (this.state === CONST.FILE_POPULATED) { // Can happen for example in a JSONFile if they've provided a JSON object instead of a URL this.loader.nextFile(this, true); } else { this.src = GetURL(this, this.loader.baseURL); if (this.src.indexOf('data:') === 0) { console.warn('Local data URIs are not supported: ' + this.key); } else { // The creation of this XHRLoader starts the load process going. // It will automatically call the following, based on the load outcome: // // xhr.onload = this.onLoad // xhr.onerror = this.onError // xhr.onprogress = this.onProgress this.xhrLoader = XHRLoader(this, this.loader.xhr); } } }, /** * Called when the file finishes loading, is sent a DOM ProgressEvent. * * @method Phaser.Loader.File#onLoad * @since 3.0.0 * * @param {XMLHttpRequest} xhr - The XMLHttpRequest that caused this onload event. * @param {ProgressEvent} event - The DOM ProgressEvent that resulted from this load. */ onLoad: function (xhr, event) { var success = !(event.target && event.target.status !== 200); // Handle HTTP status codes of 4xx and 5xx as errors, even if xhr.onerror was not called. if (xhr.readyState === 4 && xhr.status >= 400 && xhr.status <= 599) { success = false; } this.resetXHR(); this.loader.nextFile(this, success); }, /** * Called if the file errors while loading, is sent a DOM ProgressEvent. * * @method Phaser.Loader.File#onError * @since 3.0.0 * * @param {ProgressEvent} event - The DOM ProgressEvent that resulted from this error. */ onError: function () { this.resetXHR(); this.loader.nextFile(this, false); }, /** * Called during the file load progress. Is sent a DOM ProgressEvent. * * @method Phaser.Loader.File#onProgress * @since 3.0.0 * * @param {ProgressEvent} event - The DOM ProgressEvent. */ onProgress: function (event) { if (event.lengthComputable) { this.bytesLoaded = event.loaded; this.bytesTotal = event.total; this.percentComplete = Math.min((this.bytesLoaded / this.bytesTotal), 1); this.loader.emit('fileprogress', this, this.percentComplete); } }, /** * Usually overridden by the FileTypes and is called by Loader.nextFile. * This method controls what extra work this File does with its loaded data, for example a JSON file will parse itself during this stage. * * @method Phaser.Loader.File#onProcess * @since 3.0.0 */ onProcess: function () { this.state = CONST.FILE_PROCESSING; this.onProcessComplete(); }, /** * Called when the File has completed processing. * Checks on the state of its multifile, if set. * * @method Phaser.Loader.File#onProcessComplete * @since 3.7.0 */ onProcessComplete: function () { this.state = CONST.FILE_COMPLETE; if (this.multiFile) { this.multiFile.onFileComplete(this); } this.loader.fileProcessComplete(this); }, /** * Called when the File has completed processing but it generated an error. * Checks on the state of its multifile, if set. * * @method Phaser.Loader.File#onProcessError * @since 3.7.0 */ onProcessError: function () { this.state = CONST.FILE_ERRORED; if (this.multiFile) { this.multiFile.onFileFailed(this); } this.loader.fileProcessComplete(this); }, /** * Checks if a key matching the one used by this file exists in the target Cache or not. * This is called automatically by the LoaderPlugin to decide if the file can be safely * loaded or will conflict. * * @method Phaser.Loader.File#hasCacheConflict * @since 3.7.0 * * @return {boolean} `true` if adding this file will cause a conflict, otherwise `false`. */ hasCacheConflict: function () { return (this.cache && this.cache.exists(this.key)); }, /** * Adds this file to its target cache upon successful loading and processing. * This method is often overridden by specific file types. * * @method Phaser.Loader.File#addToCache * @since 3.7.0 */ addToCache: function () { if (this.cache) { this.cache.add(this.key, this.data); } this.pendingDestroy(); }, /** * You can listen for this event from the LoaderPlugin. It is dispatched _every time_ * a file loads and is sent 3 arguments, which allow you to identify the file: * * ```javascript * this.load.on('filecomplete', function (key, type, data) { * // Your handler code * }); * ``` * * @event Phaser.Loader.File#fileCompleteEvent * @param {string} key - The key of the file that just loaded and finished processing. * @param {string} type - The type of the file that just loaded and finished processing. * @param {any} data - The data of the file. */ /** * You can listen for this event from the LoaderPlugin. It is dispatched only once per * file and you have to use a special listener handle to pick it up. * * The string of the event is based on the file type and the key you gave it, split up * using hyphens. * * For example, if you have loaded an image with a key of `monster`, you can listen for it * using the following: * * ```javascript * this.load.on('filecomplete-image-monster', function (key, type, data) { * // Your handler code * }); * ``` * * Or, if you have loaded a texture atlas with a key of `Level1`: * * ```javascript * this.load.on('filecomplete-atlas-Level1', function (key, type, data) { * // Your handler code * }); * ``` * * Or, if you have loaded a sprite sheet with a key of `Explosion` and a prefix of `GAMEOVER`: * * ```javascript * this.load.on('filecomplete-spritesheet-GAMEOVERExplosion', function (key, type, data) { * // Your handler code * }); * ``` * * @event Phaser.Loader.File#singleFileCompleteEvent * @param {any} data - The data of the file. */ /** * Called once the file has been added to its cache and is now ready for deletion from the Loader. * It will emit a `filecomplete` event from the LoaderPlugin. * * @method Phaser.Loader.File#pendingDestroy * @fires Phaser.Loader.File#fileCompleteEvent * @fires Phaser.Loader.File#singleFileCompleteEvent * @since 3.7.0 */ pendingDestroy: function (data) { if (data === undefined) { data = this.data; } var key = this.key; var type = this.type; this.loader.emit('filecomplete', key, type, data); this.loader.emit('filecomplete_' + type + '_' + key, key, type, data); this.loader.flagForRemoval(this); }, /** * Destroy this File and any references it holds. * * @method Phaser.Loader.File#destroy * @since 3.7.0 */ destroy: function () { this.loader = null; this.cache = null; this.xhrSettings = null; this.multiFile = null; this.linkFile = null; this.data = null; } }); /** * Static method for creating object URL using URL API and setting it as image 'src' attribute. * If URL API is not supported (usually on old browsers) it falls back to creating Base64 encoded url using FileReader. * * @method Phaser.Loader.File.createObjectURL * @static * @param {HTMLImageElement} image - Image object which 'src' attribute should be set to object URL. * @param {Blob} blob - A Blob object to create an object URL for. * @param {string} defaultType - Default mime type used if blob type is not available. */ File.createObjectURL = function (image, blob, defaultType) { if (typeof URL === 'function') { image.src = URL.createObjectURL(blob); } else { var reader = new FileReader(); reader.onload = function () { image.removeAttribute('crossOrigin'); image.src = 'data:' + (blob.type || defaultType) + ';base64,' + reader.result.split(',')[1]; }; reader.onerror = image.onerror; reader.readAsDataURL(blob); } }; /** * Static method for releasing an existing object URL which was previously created * by calling {@link File#createObjectURL} method. * * @method Phaser.Loader.File.revokeObjectURL * @static * @param {HTMLImageElement} image - Image object which 'src' attribute should be revoked. */ File.revokeObjectURL = function (image) { if (typeof URL === 'function') { URL.revokeObjectURL(image.src); } }; module.exports = File; /***/ }), /* 20 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Global consts. * * @ignore */ var CONST = { /** * Phaser Release Version * * @name Phaser.VERSION * @readOnly * @type {string} * @since 3.0.0 */ VERSION: '3.10.1', BlendModes: __webpack_require__(51), ScaleModes: __webpack_require__(59), /** * AUTO Detect Renderer. * * @name Phaser.AUTO * @readOnly * @type {integer} * @since 3.0.0 */ AUTO: 0, /** * Canvas Renderer. * * @name Phaser.CANVAS * @readOnly * @type {integer} * @since 3.0.0 */ CANVAS: 1, /** * WebGL Renderer. * * @name Phaser.WEBGL * @readOnly * @type {integer} * @since 3.0.0 */ WEBGL: 2, /** * Headless Renderer. * * @name Phaser.HEADLESS * @readOnly * @type {integer} * @since 3.0.0 */ HEADLESS: 3, /** * In Phaser the value -1 means 'forever' in lots of cases, this const allows you to use it instead * to help you remember what the value is doing in your code. * * @name Phaser.FOREVER * @readOnly * @type {integer} * @since 3.0.0 */ FOREVER: -1, /** * Direction constant. * * @name Phaser.NONE * @readOnly * @type {integer} * @since 3.0.0 */ NONE: 4, /** * Direction constant. * * @name Phaser.UP * @readOnly * @type {integer} * @since 3.0.0 */ UP: 5, /** * Direction constant. * * @name Phaser.DOWN * @readOnly * @type {integer} * @since 3.0.0 */ DOWN: 6, /** * Direction constant. * * @name Phaser.LEFT * @readOnly * @type {integer} * @since 3.0.0 */ LEFT: 7, /** * Direction constant. * * @name Phaser.RIGHT * @readOnly * @type {integer} * @since 3.0.0 */ RIGHT: 8 }; module.exports = CONST; /***/ }), /* 21 */, /* 22 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CONST = __webpack_require__(20); var Smoothing = __webpack_require__(131); // The pool into which the canvas elements are placed. var pool = []; // Automatically apply smoothing(false) to created Canvas elements var _disableContextSmoothing = false; /** * The CanvasPool is a global static object, that allows Phaser to recycle and pool 2D Context Canvas DOM elements. * It does not pool WebGL Contexts, because once the context options are set they cannot be modified again, * which is useless for some of the Phaser pipelines / renderer. * * This singleton is instantiated as soon as Phaser loads, before a Phaser.Game instance has even been created. * Which means all instances of Phaser Games on the same page can share the one single pool. * * @namespace Phaser.Display.Canvas.CanvasPool * @since 3.0.0 */ var CanvasPool = function () { /** * Creates a new Canvas DOM element, or pulls one from the pool if free. * * @function Phaser.Display.Canvas.CanvasPool.create * @since 3.0.0 * * @param {*} parent - The parent of the Canvas object. * @param {integer} [width=1] - The width of the Canvas. * @param {integer} [height=1] - The height of the Canvas. * @param {integer} [canvasType=Phaser.CANVAS] - The type of the Canvas. Either `Phaser.CANVAS` or `Phaser.WEBGL`. * @param {boolean} [selfParent=false] - Use the generated Canvas element as the parent? * * @return {HTMLCanvasElement} [description] */ var create = function (parent, width, height, canvasType, selfParent) { if (width === undefined) { width = 1; } if (height === undefined) { height = 1; } if (canvasType === undefined) { canvasType = CONST.CANVAS; } if (selfParent === undefined) { selfParent = false; } var canvas; var container = first(canvasType); if (container === null) { container = { parent: parent, canvas: document.createElement('canvas'), type: canvasType }; if (canvasType === CONST.CANVAS) { pool.push(container); } canvas = container.canvas; } else { container.parent = parent; canvas = container.canvas; } if (selfParent) { container.parent = canvas; } canvas.width = width; canvas.height = height; if (_disableContextSmoothing && canvasType === CONST.CANVAS) { Smoothing.disable(canvas.getContext('2d')); } return canvas; }; /** * Creates a new Canvas DOM element, or pulls one from the pool if free. * * @function Phaser.Display.Canvas.CanvasPool.create2D * @since 3.0.0 * * @param {*} parent - The parent of the Canvas object. * @param {integer} [width=1] - The width of the Canvas. * @param {integer} [height=1] - The height of the Canvas. * * @return {HTMLCanvasElement} [description] */ var create2D = function (parent, width, height) { return create(parent, width, height, CONST.CANVAS); }; /** * Creates a new Canvas DOM element, or pulls one from the pool if free. * * @function Phaser.Display.Canvas.CanvasPool.createWebGL * @since 3.0.0 * * @param {*} parent - The parent of the Canvas object. * @param {integer} [width=1] - The width of the Canvas. * @param {integer} [height=1] - The height of the Canvas. * * @return {HTMLCanvasElement} [description] */ var createWebGL = function (parent, width, height) { return create(parent, width, height, CONST.WEBGL); }; /** * Gets the first free canvas index from the pool. * * @function Phaser.Display.Canvas.CanvasPool.first * @since 3.0.0 * * @param {integer} [canvasType=Phaser.CANVAS] - The type of the Canvas. Either `Phaser.CANVAS` or `Phaser.WEBGL`. * * @return {HTMLCanvasElement} [description] */ var first = function (canvasType) { if (canvasType === undefined) { canvasType = CONST.CANVAS; } if (canvasType === CONST.WEBGL) { return null; } for (var i = 0; i < pool.length; i++) { var container = pool[i]; if (!container.parent && container.type === canvasType) { return container; } } return null; }; /** * Looks up a canvas based on its parent, and if found puts it back in the pool, freeing it up for re-use. * The canvas has its width and height set to 1, and its parent attribute nulled. * * @function Phaser.Display.Canvas.CanvasPool.remove * @since 3.0.0 * * @param {*} parent - [description] */ var remove = function (parent) { // Check to see if the parent is a canvas object var isCanvas = parent instanceof HTMLCanvasElement; pool.forEach(function (container) { if ((isCanvas && container.canvas === parent) || (!isCanvas && container.parent === parent)) { container.parent = null; container.canvas.width = 1; container.canvas.height = 1; } }); }; /** * Gets the total number of used canvas elements in the pool. * * @function Phaser.Display.Canvas.CanvasPool.total * @since 3.0.0 * * @return {integer} [description] */ var total = function () { var c = 0; pool.forEach(function (container) { if (container.parent) { c++; } }); return c; }; /** * Gets the total number of free canvas elements in the pool. * * @function Phaser.Display.Canvas.CanvasPool.free * @since 3.0.0 * * @return {integer} [description] */ var free = function () { return pool.length - total(); }; /** * Disable context smoothing on any new Canvas element created. * * @function Phaser.Display.Canvas.CanvasPool.disableSmoothing * @since 3.0.0 */ var disableSmoothing = function () { _disableContextSmoothing = true; }; /** * Enable context smoothing on any new Canvas element created. * * @function Phaser.Display.Canvas.CanvasPool.enableSmoothing * @since 3.0.0 */ var enableSmoothing = function () { _disableContextSmoothing = false; }; return { create2D: create2D, create: create, createWebGL: createWebGL, disableSmoothing: disableSmoothing, enableSmoothing: enableSmoothing, first: first, free: free, pool: pool, remove: remove, total: total }; }; // If we export the called function here, it'll only be invoked once (not every time it's required). module.exports = CanvasPool(); /***/ }), /* 23 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Force a value within the boundaries by clamping it to the range `min`, `max`. * * @function Phaser.Math.Clamp * @since 3.0.0 * * @param {number} value - The value to be clamped. * @param {number} min - The minimum bounds. * @param {number} max - The maximum bounds. * * @return {number} The clamped value. */ var Clamp = function (value, min, max) { return Math.max(min, Math.min(max, value)); }; module.exports = Clamp; /***/ }), /* 24 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BlendModes = __webpack_require__(51); var GetAdvancedValue = __webpack_require__(10); var ScaleModes = __webpack_require__(59); /** * @typedef {object} GameObjectConfig * * @property {number} [x=0] - The x position of the Game Object. * @property {number} [y=0] - The y position of the Game Object. * @property {number} [depth=0] - The depth of the GameObject. * @property {boolean} [flipX=false] - The horizontally flipped state of the Game Object. * @property {boolean} [flipY=false] - The vertically flipped state of the Game Object. * @property {?(number|object)} [scale=null] - The scale of the GameObject. * @property {?(number|object)} [scrollFactor=null] - The scroll factor of the GameObject. * @property {number} [rotation=0] - The rotation angle of the Game Object, in radians. * @property {?number} [angle=null] - The rotation angle of the Game Object, in degrees. * @property {number} [alpha=1] - The alpha (opacity) of the Game Object. * @property {?(number|object)} [origin=null] - The origin of the Game Object. * @property {number} [scaleMode=ScaleModes.DEFAULT] - The scale mode of the GameObject. * @property {number} [blendMode=BlendModes.DEFAULT] - The blend mode of the GameObject. * @property {boolean} [visible=true] - The visible state of the Game Object. * @property {boolean} [add=true] - Add the GameObject to the scene. */ /** * Builds a Game Object using the provided configuration object. * * @function Phaser.GameObjects.BuildGameObject * @since 3.0.0 * * @param {Phaser.Scene} scene - A reference to the Scene. * @param {Phaser.GameObjects.GameObject} gameObject - The initial GameObject. * @param {GameObjectConfig} config - The config to build the GameObject with. * * @return {Phaser.GameObjects.GameObject} The built Game Object. */ var BuildGameObject = function (scene, gameObject, config) { // Position gameObject.x = GetAdvancedValue(config, 'x', 0); gameObject.y = GetAdvancedValue(config, 'y', 0); gameObject.depth = GetAdvancedValue(config, 'depth', 0); // Flip gameObject.flipX = GetAdvancedValue(config, 'flipX', false); gameObject.flipY = GetAdvancedValue(config, 'flipY', false); // Scale // Either: { scale: 2 } or { scale: { x: 2, y: 2 }} var scale = GetAdvancedValue(config, 'scale', null); if (typeof scale === 'number') { gameObject.setScale(scale); } else if (scale !== null) { gameObject.scaleX = GetAdvancedValue(scale, 'x', 1); gameObject.scaleY = GetAdvancedValue(scale, 'y', 1); } // ScrollFactor // Either: { scrollFactor: 2 } or { scrollFactor: { x: 2, y: 2 }} var scrollFactor = GetAdvancedValue(config, 'scrollFactor', null); if (typeof scrollFactor === 'number') { gameObject.setScrollFactor(scrollFactor); } else if (scrollFactor !== null) { gameObject.scrollFactorX = GetAdvancedValue(scrollFactor, 'x', 1); gameObject.scrollFactorY = GetAdvancedValue(scrollFactor, 'y', 1); } // Rotation gameObject.rotation = GetAdvancedValue(config, 'rotation', 0); var angle = GetAdvancedValue(config, 'angle', null); if (angle !== null) { gameObject.angle = angle; } // Alpha gameObject.alpha = GetAdvancedValue(config, 'alpha', 1); // Origin // Either: { origin: 0.5 } or { origin: { x: 0.5, y: 0.5 }} var origin = GetAdvancedValue(config, 'origin', null); if (typeof origin === 'number') { gameObject.setOrigin(origin); } else if (origin !== null) { var ox = GetAdvancedValue(origin, 'x', 0.5); var oy = GetAdvancedValue(origin, 'y', 0.5); gameObject.setOrigin(ox, oy); } // ScaleMode gameObject.scaleMode = GetAdvancedValue(config, 'scaleMode', ScaleModes.DEFAULT); // BlendMode gameObject.blendMode = GetAdvancedValue(config, 'blendMode', BlendModes.NORMAL); // Visible gameObject.visible = GetAdvancedValue(config, 'visible', true); // Add to Scene var add = GetAdvancedValue(config, 'add', true); if (add) { scene.sys.displayList.add(gameObject); } if (gameObject.preUpdate) { scene.sys.updateList.add(gameObject); } return gameObject; }; module.exports = BuildGameObject; /***/ }), /* 25 */, /* 26 */, /* 27 */ /***/ (function(module, exports) { /** * @author Richard Davey * @author Felipe Alfonso <@bitnenfer> * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Renderer.WebGL.Utils * @since 3.0.0 */ module.exports = { /** * Packs four floats on a range from 0.0 to 1.0 into a single Uint32 * * @function Phaser.Renderer.WebGL.Utils.getTintFromFloats * @since 3.0.0 * * @param {number} r - Red component in a range from 0.0 to 1.0 * @param {number} g - [description] * @param {number} b - [description] * @param {number} a - Alpha component in a range from 0.0 to 1.0 * * @return {number} [description] */ getTintFromFloats: function (r, g, b, a) { var ur = ((r * 255.0)|0) & 0xFF; var ug = ((g * 255.0)|0) & 0xFF; var ub = ((b * 255.0)|0) & 0xFF; var ua = ((a * 255.0)|0) & 0xFF; return ((ua << 24) | (ur << 16) | (ug << 8) | ub) >>> 0; }, /** * Packs a Uint24, representing RGB components, with a Float32, representing * the alpha component, with a range between 0.0 and 1.0 and return a Uint32 * * @function Phaser.Renderer.WebGL.Utils.getTintAppendFloatAlpha * @since 3.0.0 * * @param {number} rgb - Uint24 representing RGB components * @param {number} a - Float32 representing Alpha component * * @return {number} Packed RGBA as Uint32 */ getTintAppendFloatAlpha: function (rgb, a) { var ua = ((a * 255.0)|0) & 0xFF; return ((ua << 24) | rgb) >>> 0; }, /** * Packs a Uint24, representing RGB components, with a Float32, representing * the alpha component, with a range between 0.0 and 1.0 and return a * swizzled Uint32 * * @function Phaser.Renderer.WebGL.Utils.getTintAppendFloatAlphaAndSwap * @since 3.0.0 * * @param {number} rgb - Uint24 representing RGB components * @param {number} a - Float32 representing Alpha component * * @return {number} Packed RGBA as Uint32 */ getTintAppendFloatAlphaAndSwap: function (rgb, a) { var ur = ((rgb >> 16)|0) & 0xff; var ug = ((rgb >> 8)|0) & 0xff; var ub = (rgb|0) & 0xff; var ua = ((a * 255.0)|0) & 0xFF; return ((ua << 24) | (ub << 16) | (ug << 8) | ur) >>> 0; }, /** * Unpacks a Uint24 RGB into an array of floats of ranges of 0.0 and 1.0 * * @function Phaser.Renderer.WebGL.Utils.getFloatsFromUintRGB * @since 3.0.0 * * @param {number} rgb - RGB packed as a Uint24 * * @return {array} Array of floats representing each component as a float */ getFloatsFromUintRGB: function (rgb) { var ur = ((rgb >> 16)|0) & 0xff; var ug = ((rgb >> 8)|0) & 0xff; var ub = (rgb|0) & 0xff; return [ ur / 255.0, ug / 255.0, ub / 255.0 ]; }, /** * Counts how many attributes of 32 bits a vertex has * * @function Phaser.Renderer.WebGL.Utils.getComponentCount * @since 3.0.0 * * @param {array} attributes - Array of attributes * @param {WebGLRenderingContext} glContext - WebGLContext used for check types * * @return {number} Count of 32 bit attributes in vertex */ getComponentCount: function (attributes, glContext) { var count = 0; for (var index = 0; index < attributes.length; ++index) { var element = attributes[index]; if (element.type === glContext.FLOAT) { count += element.size; } else { count += 1; // We'll force any other type to be 32 bit. for now } } return count; } }; /***/ }), /* 28 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(18); var File = __webpack_require__(19); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var GetValue = __webpack_require__(4); var IsPlainObject = __webpack_require__(8); /** * @typedef {object} Phaser.Loader.FileTypes.JSONFileConfig * * @property {string} key - The key of the file. Must be unique within both the Loader and the JSON Cache. * @property {string|any} [url] - The absolute or relative URL to load the file from. Or can be a ready formed JSON object, in which case it will be directly added to the Cache. * @property {string} [extension='json'] - The default file extension to use if no url is provided. * @property {string} [dataKey] - If specified instead of the whole JSON file being parsed and added to the Cache, only the section corresponding to this property key will be added. If the property you want to extract is nested, use periods to divide it. * @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ /** * @classdesc * A single JSON File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#json method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#json. * * @class JSONFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.JSONFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. * @param {string} [dataKey] - When the JSON file loads only this property will be stored in the Cache. */ var JSONFile = new Class({ Extends: File, initialize: // url can either be a string, in which case it is treated like a proper url, or an object, in which case it is treated as a ready-made JS Object // dataKey allows you to pluck a specific object out of the JSON and put just that into the cache, rather than the whole thing function JSONFile (loader, key, url, xhrSettings, dataKey) { var extension = 'json'; if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); url = GetFastValue(config, 'url'); xhrSettings = GetFastValue(config, 'xhrSettings'); extension = GetFastValue(config, 'extension', extension); dataKey = GetFastValue(config, 'dataKey', dataKey); } var fileConfig = { type: 'json', cache: loader.cacheManager.json, extension: extension, responseType: 'text', key: key, url: url, xhrSettings: xhrSettings, config: dataKey }; File.call(this, loader, fileConfig); if (IsPlainObject(url)) { // Object provided instead of a URL, so no need to actually load it (populate data with value) if (dataKey) { this.data = GetValue(url, dataKey); } else { this.data = url; } this.state = CONST.FILE_POPULATED; } }, /** * Called automatically by Loader.nextFile. * This method controls what extra work this File does with its loaded data. * * @method Phaser.Loader.FileTypes.JSONFile#onProcess * @since 3.7.0 */ onProcess: function () { if (this.state !== CONST.FILE_POPULATED) { this.state = CONST.FILE_PROCESSING; var json = JSON.parse(this.xhrLoader.responseText); var key = this.config; if (typeof key === 'string') { this.data = GetValue(json, key, json); } else { this.data = json; } } this.onProcessComplete(); } }); /** * Adds a JSON file, or array of JSON files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.json('wavedata', 'files/AlienWaveData.json'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * The key must be a unique String. It is used to add the file to the global JSON Cache upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the JSON Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the JSON Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.json({ * key: 'wavedata', * url: 'files/AlienWaveData.json' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.JSONFileConfig` for more details. * * Once the file has finished loading you can access it from its Cache using its key: * * ```javascript * this.load.json('wavedata', 'files/AlienWaveData.json'); * // and later in your game ... * var data = this.cache.json.get('wavedata'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and * this is what you would use to retrieve the text from the JSON Cache. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" * and no URL is given then the Loader will set the URL to be "data.json". It will always add `.json` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * You can also optionally provide a `dataKey` to use. This allows you to extract only a part of the JSON and store it in the Cache, * rather than the whole file. For example, if your JSON data had a structure like this: * * ```json * { * "level1": { * "baddies": { * "aliens": {}, * "boss": {} * } * }, * "level2": {}, * "level3": {} * } * ``` * * And you only wanted to store the `boss` data in the Cache, then you could pass `level1.baddies.boss`as the `dataKey`. * * Note: The ability to load this type of file will only be available if the JSON File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#json * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.JSONFileConfig|Phaser.Loader.FileTypes.JSONFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param {string} [dataKey] - When the JSON file loads only this property will be stored in the Cache. * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('json', function (key, url, dataKey, xhrSettings) { if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object this.addFile(new JSONFile(this, key[i])); } } else { this.addFile(new JSONFile(this, key, url, xhrSettings, dataKey)); } return this; }); module.exports = JSONFile; /***/ }), /* 29 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Tests if the start and end indexes are a safe range for the given array. * * @function Phaser.Utils.Array.SafeRange * @since 3.4.0 * * @param {array} array - The array to check. * @param {integer} startIndex - The start index. * @param {integer} endIndex - The end index. * @param {boolean} [throwError=true] - Throw an error if the range is out of bounds. * * @return {boolean} True if the range is safe, otherwise false. */ var SafeRange = function (array, startIndex, endIndex, throwError) { var len = array.length; if (startIndex < 0 || startIndex > len || startIndex >= endIndex || endIndex > len || startIndex + endIndex > len) { if (throwError) { throw new Error('Range Error: Values outside acceptable range'); } return false; } else { return true; } }; module.exports = SafeRange; /***/ }), /* 30 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var GetColor = __webpack_require__(152); var GetColor32 = __webpack_require__(284); /** * @classdesc * The Color class holds a single color value and allows for easy modification and reading of it. * * @class Color * @memberOf Phaser.Display * @constructor * @since 3.0.0 * * @param {integer} [red=0] - The red color value. A number between 0 and 255. * @param {integer} [green=0] - The green color value. A number between 0 and 255. * @param {integer} [blue=0] - The blue color value. A number between 0 and 255. * @param {integer} [alpha=255] - The alpha value. A number between 0 and 255. */ var Color = new Class({ initialize: function Color (red, green, blue, alpha) { if (red === undefined) { red = 0; } if (green === undefined) { green = 0; } if (blue === undefined) { blue = 0; } if (alpha === undefined) { alpha = 255; } /** * The internal red color value. * * @name Phaser.Display.Color#r * @type {number} * @private * @default 0 * @since 3.0.0 */ this.r = 0; /** * The internal green color value. * * @name Phaser.Display.Color#g * @type {number} * @private * @default 0 * @since 3.0.0 */ this.g = 0; /** * The internal blue color value. * * @name Phaser.Display.Color#b * @type {number} * @private * @default 0 * @since 3.0.0 */ this.b = 0; /** * The internal alpha color value. * * @name Phaser.Display.Color#a * @type {number} * @private * @default 255 * @since 3.0.0 */ this.a = 255; /** * An array containing the calculated color values for WebGL use. * * @name Phaser.Display.Color#gl * @type {number[]} * @since 3.0.0 */ this.gl = [ 0, 0, 0, 1 ]; /** * Pre-calculated internal color value. * * @name Phaser.Display.Color#_color * @type {number} * @private * @default 0 * @since 3.0.0 */ this._color = 0; /** * Pre-calculated internal color32 value. * * @name Phaser.Display.Color#_color32 * @type {number} * @private * @default 0 * @since 3.0.0 */ this._color32 = 0; /** * Pre-calculated internal color rgb string value. * * @name Phaser.Display.Color#_rgba * @type {string} * @private * @default '' * @since 3.0.0 */ this._rgba = ''; this.setTo(red, green, blue, alpha); }, /** * Sets this color to be transparent. Sets all values to zero. * * @method Phaser.Display.Color#transparent * @since 3.0.0 * * @return {Phaser.Display.Color} This Color object. */ transparent: function () { this.red = 0; this.green = 0; this.blue = 0; this.alpha = 0; return this.update(); }, /** * Sets the color of this Color component. * * @method Phaser.Display.Color#setTo * @since 3.0.0 * * @param {integer} red - The red color value. A number between 0 and 255. * @param {integer} green - The green color value. A number between 0 and 255. * @param {integer} blue - The blue color value. A number between 0 and 255. * @param {integer} [alpha=255] - The alpha value. A number between 0 and 255. * * @return {Phaser.Display.Color} This Color object. */ setTo: function (red, green, blue, alpha) { if (alpha === undefined) { alpha = 255; } this.red = red; this.green = green; this.blue = blue; this.alpha = alpha; return this.update(); }, /** * Sets the red, green, blue and alpha GL values of this Color component. * * @method Phaser.Display.Color#setGLTo * @since 3.0.0 * * @param {float} red - The red color value. A number between 0 and 1. * @param {float} green - The green color value. A number between 0 and 1. * @param {float} blue - The blue color value. A number between 0 and 1. * @param {float} [alpha=1] - The alpha value. A number between 0 and 1. * * @return {Phaser.Display.Color} This Color object. */ setGLTo: function (red, green, blue, alpha) { if (alpha === undefined) { alpha = 1; } this.redGL = red; this.greenGL = green; this.blueGL = blue; this.alphaGL = alpha; return this.update(); }, /** * Sets the color based on the color object given. * * @method Phaser.Display.Color#setFromRGB * @since 3.0.0 * * @param {InputColorObject} color - An object containing `r`, `g`, `b` and optionally `a` values in the range 0 to 255. * * @return {Phaser.Display.Color} This Color object. */ setFromRGB: function (color) { this.red = color.r; this.green = color.g; this.blue = color.b; if (color.hasOwnProperty('a')) { this.alpha = color.a; } return this.update(); }, /** * Updates the internal cache values. * * @method Phaser.Display.Color#update * @since 3.0.0 * * @return {Phaser.Display.Color} This Color object. */ update: function () { this._color = GetColor(this.r, this.g, this.b); this._color32 = GetColor32(this.r, this.g, this.b, this.a); this._rgba = 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + (this.a / 255) + ')'; return this; }, /** * Returns a new Color component using the values from this one. * * @method Phaser.Display.Color#clone * @since 3.0.0 * * @return {Phaser.Display.Color} A new Color object. */ clone: function () { return new Color(this.r, this.g, this.b, this.a); }, /** * The color of this Color component, not including the alpha channel. * * @name Phaser.Display.Color#color * @type {number} * @readOnly * @since 3.0.0 */ color: { get: function () { return this._color; } }, /** * The color of this Color component, including the alpha channel. * * @name Phaser.Display.Color#color32 * @type {number} * @readOnly * @since 3.0.0 */ color32: { get: function () { return this._color32; } }, /** * The color of this Color component as a string which can be used in CSS color values. * * @name Phaser.Display.Color#rgba * @type {string} * @readOnly * @since 3.0.0 */ rgba: { get: function () { return this._rgba; } }, /** * The red color value, normalized to the range 0 to 1. * * @name Phaser.Display.Color#redGL * @type {float} * @since 3.0.0 */ redGL: { get: function () { return this.gl[0]; }, set: function (value) { this.gl[0] = Math.min(Math.abs(value), 1); this.r = Math.floor(this.gl[0] * 255); this.update(); } }, /** * The green color value, normalized to the range 0 to 1. * * @name Phaser.Display.Color#greenGL * @type {float} * @since 3.0.0 */ greenGL: { get: function () { return this.gl[1]; }, set: function (value) { this.gl[1] = Math.min(Math.abs(value), 1); this.g = Math.floor(this.gl[1] * 255); this.update(); } }, /** * The blue color value, normalized to the range 0 to 1. * * @name Phaser.Display.Color#blueGL * @type {float} * @since 3.0.0 */ blueGL: { get: function () { return this.gl[2]; }, set: function (value) { this.gl[2] = Math.min(Math.abs(value), 1); this.b = Math.floor(this.gl[2] * 255); this.update(); } }, /** * The alpha color value, normalized to the range 0 to 1. * * @name Phaser.Display.Color#alphaGL * @type {float} * @since 3.0.0 */ alphaGL: { get: function () { return this.gl[3]; }, set: function (value) { this.gl[3] = Math.min(Math.abs(value), 1); this.a = Math.floor(this.gl[3] * 255); this.update(); } }, /** * The red color value, normalized to the range 0 to 255. * * @name Phaser.Display.Color#red * @type {number} * @since 3.0.0 */ red: { get: function () { return this.r; }, set: function (value) { value = Math.floor(Math.abs(value)); this.r = Math.min(value, 255); this.gl[0] = value / 255; this.update(); } }, /** * The green color value, normalized to the range 0 to 255. * * @name Phaser.Display.Color#green * @type {number} * @since 3.0.0 */ green: { get: function () { return this.g; }, set: function (value) { value = Math.floor(Math.abs(value)); this.g = Math.min(value, 255); this.gl[1] = value / 255; this.update(); } }, /** * The blue color value, normalized to the range 0 to 255. * * @name Phaser.Display.Color#blue * @type {number} * @since 3.0.0 */ blue: { get: function () { return this.b; }, set: function (value) { value = Math.floor(Math.abs(value)); this.b = Math.min(value, 255); this.gl[2] = value / 255; this.update(); } }, /** * The alpha color value, normalized to the range 0 to 255. * * @name Phaser.Display.Color#alpha * @type {number} * @since 3.0.0 */ alpha: { get: function () { return this.a; }, set: function (value) { value = Math.floor(Math.abs(value)); this.a = Math.min(value, 255); this.gl[3] = value / 255; this.update(); } } }); module.exports = Color; /***/ }), /* 31 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Geom.Rectangle.Contains * @since 3.0.0 * * @param {Phaser.Geom.Rectangle} rect - [description] * @param {number} x - [description] * @param {number} y - [description] * * @return {boolean} [description] */ var Contains = function (rect, x, y) { if (rect.width <= 0 || rect.height <= 0) { return false; } return (rect.x <= x && rect.x + rect.width >= x && rect.y <= y && rect.y + rect.height >= y); }; module.exports = Contains; /***/ }), /* 32 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Check to see if the Circle contains the given x / y coordinates. * * @function Phaser.Geom.Circle.Contains * @since 3.0.0 * * @param {Phaser.Geom.Circle} circle - The Circle to check. * @param {number} x - The x coordinate to check within the circle. * @param {number} y - The y coordinate to check within the circle. * * @return {boolean} True if the coordinates are within the circle, otherwise false. */ var Contains = function (circle, x, y) { // Check if x/y are within the bounds first if (circle.radius > 0 && x >= circle.left && x <= circle.right && y >= circle.top && y <= circle.bottom) { var dx = (circle.x - x) * (circle.x - x); var dy = (circle.y - y) * (circle.y - y); return (dx + dy) <= (circle.radius * circle.radius); } else { return false; } }; module.exports = Contains; /***/ }), /* 33 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Shallow Object Clone. Will not clone nested objects. * * @function Phaser.Utils.Object.Clone * @since 3.0.0 * * @param {object} obj - the object from which to clone * * @return {object} a new object with the same properties as the input obj */ var Clone = function (obj) { var clone = {}; for (var key in obj) { if (Array.isArray(obj[key])) { clone[key] = obj[key].slice(0); } else { clone[key] = obj[key]; } } return clone; }; module.exports = Clone; /***/ }), /* 34 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Components = __webpack_require__(15); var GameObject = __webpack_require__(2); var SpriteRender = __webpack_require__(556); /** * @classdesc * A Sprite Game Object. * * A Sprite Game Object is used for the display of both static and animated images in your game. * Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled * and animated. * * The main difference between a Sprite and an Image Game Object is that you cannot animate Images. * As such, Sprites take a fraction longer to process and have a larger API footprint due to the Animation * Component. If you do not require animation then you can safely use Images to replace Sprites in all cases. * * @class Sprite * @extends Phaser.GameObjects.GameObject * @memberOf Phaser.GameObjects * @constructor * @since 3.0.0 * * @extends Phaser.GameObjects.Components.Alpha * @extends Phaser.GameObjects.Components.BlendMode * @extends Phaser.GameObjects.Components.Depth * @extends Phaser.GameObjects.Components.Flip * @extends Phaser.GameObjects.Components.GetBounds * @extends Phaser.GameObjects.Components.Mask * @extends Phaser.GameObjects.Components.Origin * @extends Phaser.GameObjects.Components.Pipeline * @extends Phaser.GameObjects.Components.ScaleMode * @extends Phaser.GameObjects.Components.ScrollFactor * @extends Phaser.GameObjects.Components.Size * @extends Phaser.GameObjects.Components.Texture * @extends Phaser.GameObjects.Components.Tint * @extends Phaser.GameObjects.Components.Transform * @extends Phaser.GameObjects.Components.Visible * * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param {number} x - The horizontal position of this Game Object in the world. * @param {number} y - The vertical position of this Game Object in the world. * @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with. */ var Sprite = new Class({ Extends: GameObject, Mixins: [ Components.Alpha, Components.BlendMode, Components.Depth, Components.Flip, Components.GetBounds, Components.Mask, Components.Origin, Components.Pipeline, Components.ScaleMode, Components.ScrollFactor, Components.Size, Components.Texture, Components.Tint, Components.Transform, Components.Visible, SpriteRender ], initialize: function Sprite (scene, x, y, texture, frame) { GameObject.call(this, scene, 'Sprite'); /** * The Animation Controller of this Sprite. * * @name Phaser.GameObjects.Sprite#anims * @type {Phaser.GameObjects.Components.Animation} * @since 3.0.0 */ this.anims = new Components.Animation(this); this.setTexture(texture, frame); this.setPosition(x, y); this.setSizeToFrame(); this.setOriginFromFrame(); this.initPipeline('TextureTintPipeline'); }, /** * Update this Sprite's animations. * * @method Phaser.GameObjects.Sprite#preUpdate * @protected * @since 3.0.0 * * @param {number} time - The current timestamp. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ preUpdate: function (time, delta) { this.anims.update(time, delta); }, /** * Start playing the given animation. * * @method Phaser.GameObjects.Sprite#play * @since 3.0.0 * * @param {string} key - The string-based key of the animation to play. * @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call. * @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index. * * @return {Phaser.GameObjects.Sprite} This Game Object. */ play: function (key, ignoreIfPlaying, startFrame) { this.anims.play(key, ignoreIfPlaying, startFrame); return this; }, /** * Build a JSON representation of this Sprite. * * @method Phaser.GameObjects.Sprite#toJSON * @since 3.0.0 * * @return {JSONGameObject} A JSON representation of the Game Object. */ toJSON: function () { var data = Components.ToJSON(this); // Extra Sprite data is added here return data; } }); module.exports = Sprite; /***/ }), /* 35 */, /* 36 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * A MultiFile is a special kind of parent that contains two, or more, Files as children and looks after * the loading and processing of them all. It is commonly extended and used as a base class for file types such as AtlasJSON or BitmapFont. * * You shouldn't create an instance of a MultiFile directly, but should extend it with your own class, setting a custom type and processing methods. * * @class MultiFile * @memberOf Phaser.Loader * @constructor * @since 3.7.0 * * @param {Phaser.Loader.LoaderPlugin} loader - The Loader that is going to load this File. * @param {string} type - The file type string for sorting within the Loader. * @param {string} key - The key of the file within the loader. * @param {Phaser.Loader.File[]} files - An array of Files that make-up this MultiFile. */ var MultiFile = new Class({ initialize: function MultiFile (loader, type, key, files) { /** * A reference to the Loader that is going to load this file. * * @name Phaser.Loader.MultiFile#loader * @type {Phaser.Loader.LoaderPlugin} * @since 3.7.0 */ this.loader = loader; /** * The file type string for sorting within the Loader. * * @name Phaser.Loader.MultiFile#type * @type {string} * @since 3.7.0 */ this.type = type; /** * Unique cache key (unique within its file type) * * @name Phaser.Loader.MultiFile#key * @type {string} * @since 3.7.0 */ this.key = key; /** * Array of files that make up this MultiFile. * * @name Phaser.Loader.MultiFile#files * @type {Phaser.Loader.File[]} * @since 3.7.0 */ this.files = files; /** * The completion status of this MultiFile. * * @name Phaser.Loader.MultiFile#complete * @type {boolean} * @default false * @since 3.7.0 */ this.complete = false; /** * The number of files to load. * * @name Phaser.Loader.MultiFile#pending * @type {integer} * @since 3.7.0 */ this.pending = files.length; /** * The number of files that failed to load. * * @name Phaser.Loader.MultiFile#failed * @type {integer} * @default 0 * @since 3.7.0 */ this.failed = 0; /** * A storage container for transient data that the loading files need. * * @name Phaser.Loader.MultiFile#config * @type {any} * @since 3.7.0 */ this.config = {}; // Link the files for (var i = 0; i < files.length; i++) { files[i].multiFile = this; } }, /** * Checks if this MultiFile is ready to process its children or not. * * @method Phaser.Loader.MultiFile#isReadyToProcess * @since 3.7.0 * * @return {boolean} `true` if all children of this MultiFile have loaded, otherwise `false`. */ isReadyToProcess: function () { return (this.pending === 0 && this.failed === 0 && !this.complete); }, /** * Adds another child to this MultiFile, increases the pending count and resets the completion status. * * @method Phaser.Loader.MultiFile#addToMultiFile * @since 3.7.0 * * @param {Phaser.Loader.File} files - The File to add to this MultiFile. * * @return {Phaser.Loader.MultiFile} This MultiFile instance. */ addToMultiFile: function (file) { this.files.push(file); file.multiFile = this; this.pending++; this.complete = false; return this; }, /** * Called by each File when it finishes loading. * * @method Phaser.Loader.MultiFile#onFileComplete * @since 3.7.0 * * @param {Phaser.Loader.File} file - The File that has completed processing. */ onFileComplete: function (file) { var index = this.files.indexOf(file); if (index !== -1) { this.pending--; } }, /** * Called by each File that fails to load. * * @method Phaser.Loader.MultiFile#onFileFailed * @since 3.7.0 * * @param {Phaser.Loader.File} file - The File that has failed to load. */ onFileFailed: function (file) { var index = this.files.indexOf(file); if (index !== -1) { this.failed++; } } }); module.exports = MultiFile; /***/ }), /* 37 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(18); var File = __webpack_require__(19); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var IsPlainObject = __webpack_require__(8); /** * @typedef {object} Phaser.Loader.FileTypes.ImageFrameConfig * * @property {integer} frameWidth - The width of the frame in pixels. * @property {integer} [frameHeight] - The height of the frame in pixels. Uses the `frameWidth` value if not provided. * @property {integer} [startFrame=0] - The first frame to start parsing from. * @property {integer} [endFrame] - The frame to stop parsing at. If not provided it will calculate the value based on the image and frame dimensions. * @property {integer} [margin=0] - The margin in the image. This is the space around the edge of the frames. * @property {integer} [spacing=0] - The spacing between each frame in the image. */ /** * @typedef {object} Phaser.Loader.FileTypes.ImageFileConfig * * @property {string} key - The key of the file. Must be unique within both the Loader and the Texture Manager. * @property {string} [url] - The absolute or relative URL to load the file from. * @property {string} [extension='png'] - The default file extension to use if no url is provided. * @property {string} [normalMap] - The filename of an associated normal map. It uses the same path and url to load as the image. * @property {Phaser.Loader.FileTypes.ImageFrameConfig} [frameConfig] - The frame configuration object. Only provided for, and used by, Sprite Sheets. * @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ /** * @classdesc * A single Image File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#image method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#image. * * @class ImageFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.ImageFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string|string[]} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. * @param {Phaser.Loader.FileTypes.ImageFrameConfig} [frameConfig] - The frame configuration object. Only provided for, and used by, Sprite Sheets. */ var ImageFile = new Class({ Extends: File, initialize: function ImageFile (loader, key, url, xhrSettings, frameConfig) { var extension = 'png'; var normalMapURL; if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); url = GetFastValue(config, 'url'); normalMapURL = GetFastValue(config, 'normalMap'); xhrSettings = GetFastValue(config, 'xhrSettings'); extension = GetFastValue(config, 'extension', extension); frameConfig = GetFastValue(config, 'frameConfig'); } if (Array.isArray(url)) { normalMapURL = url[1]; url = url[0]; } var fileConfig = { type: 'image', cache: loader.textureManager, extension: extension, responseType: 'blob', key: key, url: url, xhrSettings: xhrSettings, config: frameConfig }; File.call(this, loader, fileConfig); // Do we have a normal map to load as well? if (normalMapURL) { var normalMap = new ImageFile(loader, this.key, normalMapURL, xhrSettings, frameConfig); normalMap.type = 'normalMap'; this.setLink(normalMap); loader.addFile(normalMap); } }, /** * Called automatically by Loader.nextFile. * This method controls what extra work this File does with its loaded data. * * @method Phaser.Loader.FileTypes.ImageFile#onProcess * @since 3.7.0 */ onProcess: function () { this.state = CONST.FILE_PROCESSING; this.data = new Image(); this.data.crossOrigin = this.crossOrigin; var _this = this; this.data.onload = function () { File.revokeObjectURL(_this.data); _this.onProcessComplete(); }; this.data.onerror = function () { File.revokeObjectURL(_this.data); _this.onProcessError(); }; File.createObjectURL(this.data, this.xhrLoader.response, 'image/png'); }, /** * Adds this file to its target cache upon successful loading and processing. * * @method Phaser.Loader.FileTypes.ImageFile#addToCache * @since 3.7.0 */ addToCache: function () { var texture; var linkFile = this.linkFile; if (linkFile && linkFile.state === CONST.FILE_COMPLETE) { if (this.type === 'image') { texture = this.cache.addImage(this.key, this.data, linkFile.data); } else { texture = this.cache.addImage(linkFile.key, linkFile.data, this.data); } this.pendingDestroy(texture); linkFile.pendingDestroy(texture); } else if (!linkFile) { texture = this.cache.addImage(this.key, this.data); this.pendingDestroy(texture); } } }); /** * Adds an Image, or array of Images, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.image('logo', 'images/phaserLogo.png'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. * If you try to load an animated gif only the first frame will be rendered. Browsers do not natively support playback * of animated gifs to Canvas elements. * * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.image({ * key: 'logo', * url: 'images/AtariLogo.png' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.ImageFileConfig` for more details. * * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: * * ```javascript * this.load.image('logo', 'images/AtariLogo.png'); * // and later in your game ... * this.add.image(x, y, 'logo'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, * then you can specify it by providing an array as the `url` where the second element is the normal map: * * ```javascript * this.load.image('logo', [ 'images/AtariLogo.png', 'images/AtariLogo-n.png' ]); * ``` * * Or, if you are using a config object use the `normalMap` property: * * ```javascript * this.load.image({ * key: 'logo', * url: 'images/AtariLogo.png', * normalMap: 'images/AtariLogo-n.png' * }); * ``` * * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. * Normal maps are a WebGL only feature. * * Note: The ability to load this type of file will only be available if the Image File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#image * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.ImageFileConfig|Phaser.Loader.FileTypes.ImageFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string|string[]} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('image', function (key, url, xhrSettings) { if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object this.addFile(new ImageFile(this, key[i])); } } else { this.addFile(new ImageFile(this, key, url, xhrSettings)); } return this; }); module.exports = ImageFile; /***/ }), /* 38 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CONST = __webpack_require__(16); /** * Convert the given angle from degrees, to the equivalent angle in radians. * * @function Phaser.Math.DegToRad * @since 3.0.0 * * @param {integer} degrees - The angle (in degrees) to convert to radians. * * @return {float} The given angle converted to radians. */ var DegToRad = function (degrees) { return degrees * CONST.DEG_TO_RAD; }; module.exports = DegToRad; /***/ }), /* 39 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Wrap the given `value` between `min` and `max. * * @function Phaser.Math.Wrap * @since 3.0.0 * * @param {number} value - The value to wrap. * @param {number} min - The minimum value. * @param {number} max - The maximum value. * * @return {number} The wrapped value. */ var Wrap = function (value, min, max) { var range = max - min; return (min + ((((value - min) % range) + range) % range)); }; module.exports = Wrap; /***/ }), /* 40 */, /* 41 */, /* 42 */, /* 43 */, /* 44 */, /* 45 */, /* 46 */, /* 47 */, /* 48 */, /* 49 */, /* 50 */, /* 51 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Phaser Blend Modes. * * @name Phaser.BlendModes * @enum {integer} * @memberOf Phaser * @readOnly * @since 3.0.0 */ module.exports = { /** * Skips the Blend Mode check in the renderer. * * @name Phaser.BlendModes.SKIP_CHECK */ SKIP_CHECK: -1, /** * Normal blend mode. * * @name Phaser.BlendModes.NORMAL */ NORMAL: 0, /** * Add blend mode. * * @name Phaser.BlendModes.ADD */ ADD: 1, /** * Multiply blend mode. * * @name Phaser.BlendModes.MULTIPLY */ MULTIPLY: 2, /** * Screen blend mode. * * @name Phaser.BlendModes.SCREEN */ SCREEN: 3, /** * Overlay blend mode. * * @name Phaser.BlendModes.OVERLAY */ OVERLAY: 4, /** * Darken blend mode. * * @name Phaser.BlendModes.DARKEN */ DARKEN: 5, /** * Lighten blend mode. * * @name Phaser.BlendModes.LIGHTEN */ LIGHTEN: 6, /** * Color Dodge blend mode. * * @name Phaser.BlendModes.COLOR_DODGE */ COLOR_DODGE: 7, /** * Color Burn blend mode. * * @name Phaser.BlendModes.COLOR_BURN */ COLOR_BURN: 8, /** * Hard Light blend mode. * * @name Phaser.BlendModes.HARD_LIGHT */ HARD_LIGHT: 9, /** * Soft Light blend mode. * * @name Phaser.BlendModes.SOFT_LIGHT */ SOFT_LIGHT: 10, /** * Difference blend mode. * * @name Phaser.BlendModes.DIFFERENCE */ DIFFERENCE: 11, /** * Exclusion blend mode. * * @name Phaser.BlendModes.EXCLUSION */ EXCLUSION: 12, /** * Hue blend mode. * * @name Phaser.BlendModes.HUE */ HUE: 13, /** * Saturation blend mode. * * @name Phaser.BlendModes.SATURATION */ SATURATION: 14, /** * Color blend mode. * * @name Phaser.BlendModes.COLOR */ COLOR: 15, /** * Luminosity blend mode. * * @name Phaser.BlendModes.LUMINOSITY */ LUMINOSITY: 16 }; /***/ }), /* 52 */, /* 53 */, /* 54 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Check to see if the Ellipse contains the given x / y coordinates. * * @function Phaser.Geom.Ellipse.Contains * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to check. * @param {number} x - The x coordinate to check within the ellipse. * @param {number} y - The y coordinate to check within the ellipse. * * @return {boolean} True if the coordinates are within the ellipse, otherwise false. */ var Contains = function (ellipse, x, y) { if (ellipse.width <= 0 || ellipse.height <= 0) { return false; } // Normalize the coords to an ellipse with center 0,0 and a radius of 0.5 var normx = ((x - ellipse.x) / ellipse.width); var normy = ((y - ellipse.y) / ellipse.height); normx *= normx; normy *= normy; return (normx + normy < 0.25); }; module.exports = Contains; /***/ }), /* 55 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Scene consts. * * @ignore */ var CONST = { /** * Scene state. * * @name Phaser.Scenes.PENDING * @readOnly * @type {integer} * @since 3.0.0 */ PENDING: 0, /** * Scene state. * * @name Phaser.Scenes.INIT * @readOnly * @type {integer} * @since 3.0.0 */ INIT: 1, /** * Scene state. * * @name Phaser.Scenes.START * @readOnly * @type {integer} * @since 3.0.0 */ START: 2, /** * Scene state. * * @name Phaser.Scenes.LOADING * @readOnly * @type {integer} * @since 3.0.0 */ LOADING: 3, /** * Scene state. * * @name Phaser.Scenes.CREATING * @readOnly * @type {integer} * @since 3.0.0 */ CREATING: 4, /** * Scene state. * * @name Phaser.Scenes.RUNNING * @readOnly * @type {integer} * @since 3.0.0 */ RUNNING: 5, /** * Scene state. * * @name Phaser.Scenes.PAUSED * @readOnly * @type {integer} * @since 3.0.0 */ PAUSED: 6, /** * Scene state. * * @name Phaser.Scenes.SLEEPING * @readOnly * @type {integer} * @since 3.0.0 */ SLEEPING: 7, /** * Scene state. * * @name Phaser.Scenes.SHUTDOWN * @readOnly * @type {integer} * @since 3.0.0 */ SHUTDOWN: 8, /** * Scene state. * * @name Phaser.Scenes.DESTROYED * @readOnly * @type {integer} * @since 3.0.0 */ DESTROYED: 9 }; module.exports = CONST; /***/ }), /* 56 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Removes a single item from an array and returns it without creating gc, like the native splice does. * Based on code by Mike Reinstein. * * @function Phaser.Utils.Array.SpliceOne * @since 3.0.0 * * @param {array} array - [description] * @param {integer} index - [description] * * @return {*} [description] */ var SpliceOne = function (array, index) { if (index >= array.length) { return; } var len = array.length - 1; var item = array[index]; for (var i = index; i < len; i++) { array[i] = array[i + 1]; } array.length = len; return item; }; module.exports = SpliceOne; /***/ }), /* 57 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(process) {/** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Determines the operating system of the device running this Phaser Game instance. * These values are read-only and populated during the boot sequence of the game. * They are then referenced by internal game systems and are available for you to access * via `this.sys.game.device.os` from within any Scene. * * @typedef {object} Phaser.Device.OS * @since 3.0.0 * * @property {boolean} android - Is running on android? * @property {boolean} chromeOS - Is running on chromeOS? * @property {boolean} cocoonJS - Is the game running under CocoonJS? * @property {boolean} cocoonJSApp - Is this game running with CocoonJS.App? * @property {boolean} cordova - Is the game running under Apache Cordova? * @property {boolean} crosswalk - Is the game running under the Intel Crosswalk XDK? * @property {boolean} desktop - Is running on a desktop? * @property {boolean} ejecta - Is the game running under Ejecta? * @property {boolean} electron - Is the game running under GitHub Electron? * @property {boolean} iOS - Is running on iOS? * @property {boolean} iPad - Is running on iPad? * @property {boolean} iPhone - Is running on iPhone? * @property {boolean} kindle - Is running on an Amazon Kindle? * @property {boolean} linux - Is running on linux? * @property {boolean} macOS - Is running on macOS? * @property {boolean} node - Is the game running under Node.js? * @property {boolean} nodeWebkit - Is the game running under Node-Webkit? * @property {boolean} webApp - Set to true if running as a WebApp, i.e. within a WebView * @property {boolean} windows - Is running on windows? * @property {boolean} windowsPhone - Is running on a Windows Phone? * @property {number} iOSVersion - If running in iOS this will contain the major version number. * @property {number} pixelRatio - PixelRatio of the host device? */ var OS = { android: false, chromeOS: false, cocoonJS: false, cocoonJSApp: false, cordova: false, crosswalk: false, desktop: false, ejecta: false, electron: false, iOS: false, iOSVersion: 0, iPad: false, iPhone: false, kindle: false, linux: false, macOS: false, node: false, nodeWebkit: false, pixelRatio: 1, webApp: false, windows: false, windowsPhone: false }; function init () { var ua = navigator.userAgent; if (/Windows/.test(ua)) { OS.windows = true; } else if (/Mac OS/.test(ua)) { OS.macOS = true; } else if (/Android/.test(ua)) { OS.android = true; } else if (/Linux/.test(ua)) { OS.linux = true; } else if (/iP[ao]d|iPhone/i.test(ua)) { OS.iOS = true; (navigator.appVersion).match(/OS (\d+)/); OS.iOSVersion = parseInt(RegExp.$1, 10); } else if (/Kindle/.test(ua) || (/\bKF[A-Z][A-Z]+/).test(ua) || (/Silk.*Mobile Safari/).test(ua)) { OS.kindle = true; // This will NOT detect early generations of Kindle Fire, I think there is no reliable way... // E.g. "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true" } else if (/CrOS/.test(ua)) { OS.chromeOS = true; } if (/Windows Phone/i.test(ua) || (/IEMobile/i).test(ua)) { OS.android = false; OS.iOS = false; OS.macOS = false; OS.windows = true; OS.windowsPhone = true; } var silk = (/Silk/).test(ua); if (OS.windows || OS.macOS || (OS.linux && !silk) || OS.chromeOS) { OS.desktop = true; } // Windows Phone / Table reset if (OS.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua)))) { OS.desktop = false; } // WebApp mode in iOS if (navigator.standalone) { OS.webApp = true; } if (window.cordova !== undefined) { OS.cordova = true; } if (process && process.versions && process.versions.node) { OS.node = true; } if (OS.node && typeof process.versions === 'object') { OS.nodeWebkit = !!process.versions['node-webkit']; OS.electron = !!process.versions.electron; } if (navigator.isCocoonJS) { OS.cocoonJS = true; try { OS.cocoonJSApp = (typeof CocoonJS !== 'undefined'); } catch (error) { OS.cocoonJSApp = false; } } if (window.ejecta !== undefined) { OS.ejecta = true; } if ((/Crosswalk/).test(ua)) { OS.crosswalk = true; } OS.iPhone = ua.toLowerCase().indexOf('iphone') !== -1; OS.iPad = ua.toLowerCase().indexOf('ipad') !== -1; OS.pixelRatio = window['devicePixelRatio'] || 1; return OS; } module.exports = init(); /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(537))) /***/ }), /* 58 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Calculate the distance between two sets of coordinates (points). * * @function Phaser.Math.Distance.Between * @since 3.0.0 * * @param {number} x1 - The x coordinate of the first point. * @param {number} y1 - The y coordinate of the first point. * @param {number} x2 - The x coordinate of the second point. * @param {number} y2 - The y coordinate of the second point. * * @return {number} The distance between each point. */ var DistanceBetween = function (x1, y1, x2, y2) { var dx = x1 - x2; var dy = y1 - y2; return Math.sqrt(dx * dx + dy * dy); }; module.exports = DistanceBetween; /***/ }), /* 59 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Phaser Scale Modes. * * @name Phaser.ScaleModes * @enum {integer} * @memberOf Phaser * @readOnly * @since 3.0.0 */ module.exports = { /** * Default Scale Mode (Linear). * * @name Phaser.ScaleModes.DEFAULT */ DEFAULT: 0, /** * Linear Scale Mode. * * @name Phaser.ScaleModes.LINEAR */ LINEAR: 0, /** * Nearest Scale Mode. * * @name Phaser.ScaleModes.NEAREST */ NEAREST: 1 }; /***/ }), /* 60 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // http://www.blackpawn.com/texts/pointinpoly/ /** * [description] * * @function Phaser.Geom.Triangle.Contains * @since 3.0.0 * * @param {Phaser.Geom.Triangle} triangle - [description] * @param {number} x - [description] * @param {number} y - [description] * * @return {boolean} [description] */ var Contains = function (triangle, x, y) { var v0x = triangle.x3 - triangle.x1; var v0y = triangle.y3 - triangle.y1; var v1x = triangle.x2 - triangle.x1; var v1y = triangle.y2 - triangle.y1; var v2x = x - triangle.x1; var v2y = y - triangle.y1; var dot00 = (v0x * v0x) + (v0y * v0y); var dot01 = (v0x * v1x) + (v0y * v1y); var dot02 = (v0x * v2x) + (v0y * v2y); var dot11 = (v1x * v1x) + (v1y * v1y); var dot12 = (v1x * v2x) + (v1y * v2y); // Compute barycentric coordinates var b = ((dot00 * dot11) - (dot01 * dot01)); var inv = (b === 0) ? 0 : (1 / b); var u = ((dot11 * dot02) - (dot01 * dot12)) * inv; var v = ((dot00 * dot12) - (dot01 * dot02)) * inv; return (u >= 0 && v >= 0 && (u + v < 1)); }; module.exports = Contains; /***/ }), /* 61 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var TWEEN_CONST = { /** * TweenData state. * * @name Phaser.Tweens.CREATED * @type {integer} * @since 3.0.0 */ CREATED: 0, /** * TweenData state. * * @name Phaser.Tweens.INIT * @type {integer} * @since 3.0.0 */ INIT: 1, /** * TweenData state. * * @name Phaser.Tweens.DELAY * @type {integer} * @since 3.0.0 */ DELAY: 2, /** * TweenData state. * * @name Phaser.Tweens.OFFSET_DELAY * @type {integer} * @since 3.0.0 */ OFFSET_DELAY: 3, /** * TweenData state. * * @name Phaser.Tweens.PENDING_RENDER * @type {integer} * @since 3.0.0 */ PENDING_RENDER: 4, /** * TweenData state. * * @name Phaser.Tweens.PLAYING_FORWARD * @type {integer} * @since 3.0.0 */ PLAYING_FORWARD: 5, /** * TweenData state. * * @name Phaser.Tweens.PLAYING_BACKWARD * @type {integer} * @since 3.0.0 */ PLAYING_BACKWARD: 6, /** * TweenData state. * * @name Phaser.Tweens.HOLD_DELAY * @type {integer} * @since 3.0.0 */ HOLD_DELAY: 7, /** * TweenData state. * * @name Phaser.Tweens.REPEAT_DELAY * @type {integer} * @since 3.0.0 */ REPEAT_DELAY: 8, /** * TweenData state. * * @name Phaser.Tweens.COMPLETE * @type {integer} * @since 3.0.0 */ COMPLETE: 9, // Tween specific (starts from 20 to cleanly allow extra TweenData consts in the future) /** * Tween state. * * @name Phaser.Tweens.PENDING_ADD * @type {integer} * @since 3.0.0 */ PENDING_ADD: 20, /** * Tween state. * * @name Phaser.Tweens.PAUSED * @type {integer} * @since 3.0.0 */ PAUSED: 21, /** * Tween state. * * @name Phaser.Tweens.LOOP_DELAY * @type {integer} * @since 3.0.0 */ LOOP_DELAY: 22, /** * Tween state. * * @name Phaser.Tweens.ACTIVE * @type {integer} * @since 3.0.0 */ ACTIVE: 23, /** * Tween state. * * @name Phaser.Tweens.COMPLETE_DELAY * @type {integer} * @since 3.0.0 */ COMPLETE_DELAY: 24, /** * Tween state. * * @name Phaser.Tweens.PENDING_REMOVE * @type {integer} * @since 3.0.0 */ PENDING_REMOVE: 25, /** * Tween state. * * @name Phaser.Tweens.REMOVED * @type {integer} * @since 3.0.0 */ REMOVED: 26 }; module.exports = TWEEN_CONST; /***/ }), /* 62 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Tweens.Builders.GetBoolean * @since 3.0.0 * * @param {object} source - [description] * @param {string} key - [description] * @param {*} defaultValue - [description] * * @return {*} [description] */ var GetBoolean = function (source, key, defaultValue) { if (!source) { return defaultValue; } else if (source.hasOwnProperty(key)) { return source[key]; } else { return defaultValue; } }; module.exports = GetBoolean; /***/ }), /* 63 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var EaseMap = __webpack_require__(453); /** * [description] * * @function Phaser.Tweens.Builders.GetEaseFunction * @since 3.0.0 * * @param {(string|function)} ease - [description] * @param {array} easeParams - [description] * * @return {function} [description] */ var GetEaseFunction = function (ease, easeParams) { if (typeof ease === 'string' && EaseMap.hasOwnProperty(ease)) { if (easeParams) { var cloneParams = easeParams.slice(0); cloneParams.unshift(0); return function (v) { cloneParams[0] = v; return EaseMap[ease].apply(this, cloneParams); }; } else { // String based look-up return EaseMap[ease]; } } else if (typeof ease === 'function') { // Custom function return ease; } else if (Array.isArray(ease) && ease.length === 4) { // Bezier function (TODO) } return EaseMap.Power0; }; module.exports = GetEaseFunction; /***/ }), /* 64 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * [description] * * @class TransformMatrix * @memberOf Phaser.GameObjects.Components * @constructor * @since 3.0.0 * * @param {number} [a=1] - The Scale X value. * @param {number} [b=0] - The Shear Y value. * @param {number} [c=0] - The Shear X value. * @param {number} [d=1] - The Scale Y value. * @param {number} [tx=0] - The Translate X value. * @param {number} [ty=0] - The Translate Y value. */ var TransformMatrix = new Class({ initialize: function TransformMatrix (a, b, c, d, tx, ty) { if (a === undefined) { a = 1; } if (b === undefined) { b = 0; } if (c === undefined) { c = 0; } if (d === undefined) { d = 1; } if (tx === undefined) { tx = 0; } if (ty === undefined) { ty = 0; } /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#matrix * @type {Float32Array} * @since 3.0.0 */ this.matrix = new Float32Array([ a, b, c, d, tx, ty, 0, 0, 1 ]); /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#decomposedMatrix * @type {object} * @since 3.0.0 */ this.decomposedMatrix = { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, rotation: 0 }; }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#a * @type {number} * @since 3.4.0 */ a: { get: function () { return this.matrix[0]; }, set: function (value) { this.matrix[0] = value; } }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#b * @type {number} * @since 3.4.0 */ b: { get: function () { return this.matrix[1]; }, set: function (value) { this.matrix[1] = value; } }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#c * @type {number} * @since 3.4.0 */ c: { get: function () { return this.matrix[2]; }, set: function (value) { this.matrix[2] = value; } }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#d * @type {number} * @since 3.4.0 */ d: { get: function () { return this.matrix[3]; }, set: function (value) { this.matrix[3] = value; } }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#tx * @type {number} * @since 3.4.0 */ tx: { get: function () { return this.matrix[4]; }, set: function (value) { this.matrix[4] = value; } }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#ty * @type {number} * @since 3.4.0 */ ty: { get: function () { return this.matrix[5]; }, set: function (value) { this.matrix[5] = value; } }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#rotation * @type {number} * @readOnly * @since 3.4.0 */ rotation: { get: function () { return Math.acos(this.a / this.scaleX) * (Math.atan(-this.c / this.a) < 0 ? -1 : 1); } }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#scaleX * @type {number} * @readOnly * @since 3.4.0 */ scaleX: { get: function () { return Math.sqrt((this.a * this.a) + (this.c * this.c)); } }, /** * [description] * * @name Phaser.GameObjects.Components.TransformMatrix#scaleY * @type {number} * @readOnly * @since 3.4.0 */ scaleY: { get: function () { return Math.sqrt((this.b * this.b) + (this.d * this.d)); } }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#loadIdentity * @since 3.0.0 * * @return {this} This TransformMatrix. */ loadIdentity: function () { var matrix = this.matrix; matrix[0] = 1; matrix[1] = 0; matrix[2] = 0; matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; return this; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#translate * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * * @return {this} This TransformMatrix. */ translate: function (x, y) { var matrix = this.matrix; matrix[4] = matrix[0] * x + matrix[2] * y + matrix[4]; matrix[5] = matrix[1] * x + matrix[3] * y + matrix[5]; return this; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#scale * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * * @return {this} This TransformMatrix. */ scale: function (x, y) { var matrix = this.matrix; matrix[0] *= x; matrix[1] *= x; matrix[2] *= y; matrix[3] *= y; return this; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#rotate * @since 3.0.0 * * @param {number} radian - [description] * * @return {this} This TransformMatrix. */ rotate: function (radian) { var radianSin = Math.sin(radian); var radianCos = Math.cos(radian); var matrix = this.matrix; var a = matrix[0]; var b = matrix[1]; var c = matrix[2]; var d = matrix[3]; matrix[0] = a * radianCos + c * radianSin; matrix[1] = b * radianCos + d * radianSin; matrix[2] = a * -radianSin + c * radianCos; matrix[3] = b * -radianSin + d * radianCos; return this; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#multiply * @since 3.0.0 * * @param {Phaser.GameObjects.Components.TransformMatrix} rhs - [description] * * @return {this} This TransformMatrix. */ multiply: function (rhs) { var matrix = this.matrix; var otherMatrix = rhs.matrix; var a0 = matrix[0]; var b0 = matrix[1]; var c0 = matrix[2]; var d0 = matrix[3]; var tx0 = matrix[4]; var ty0 = matrix[5]; var a1 = otherMatrix[0]; var b1 = otherMatrix[1]; var c1 = otherMatrix[2]; var d1 = otherMatrix[3]; var tx1 = otherMatrix[4]; var ty1 = otherMatrix[5]; matrix[0] = a1 * a0 + b1 * c0; matrix[1] = a1 * b0 + b1 * d0; matrix[2] = c1 * a0 + d1 * c0; matrix[3] = c1 * b0 + d1 * d0; matrix[4] = tx1 * a0 + ty1 * c0 + tx0; matrix[5] = tx1 * b0 + ty1 * d0 + ty0; return this; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#transform * @since 3.0.0 * * @param {number} a - The Scale X value. * @param {number} b - The Shear Y value. * @param {number} c - The Shear X value. * @param {number} d - The Scale Y value. * @param {number} tx - The Translate X value. * @param {number} ty - The Translate Y value. * * @return {this} This TransformMatrix. */ transform: function (a, b, c, d, tx, ty) { var matrix = this.matrix; var a0 = matrix[0]; var b0 = matrix[1]; var c0 = matrix[2]; var d0 = matrix[3]; var tx0 = matrix[4]; var ty0 = matrix[5]; matrix[0] = a * a0 + b * c0; matrix[1] = a * b0 + b * d0; matrix[2] = c * a0 + d * c0; matrix[3] = c * b0 + d * d0; matrix[4] = tx * a0 + ty * c0 + tx0; matrix[5] = tx * b0 + ty * d0 + ty0; return this; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#transformPoint * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * @param {(Phaser.Geom.Point|Phaser.Math.Vector2|object)} point - [description] * * @return {(Phaser.Geom.Point|Phaser.Math.Vector2|object)} [description] */ transformPoint: function (x, y, point) { if (point === undefined) { point = { x: 0, y: 0 }; } var matrix = this.matrix; var a = matrix[0]; var b = matrix[1]; var c = matrix[2]; var d = matrix[3]; var tx = matrix[4]; var ty = matrix[5]; point.x = x * a + y * c + tx; point.y = x * b + y * d + ty; return point; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#invert * @since 3.0.0 * * @return {this} This TransformMatrix. */ invert: function () { var matrix = this.matrix; var a = matrix[0]; var b = matrix[1]; var c = matrix[2]; var d = matrix[3]; var tx = matrix[4]; var ty = matrix[5]; var n = a * d - b * c; matrix[0] = d / n; matrix[1] = -b / n; matrix[2] = -c / n; matrix[3] = a / n; matrix[4] = (c * ty - d * tx) / n; matrix[5] = -(a * ty - b * tx) / n; return this; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#setTransform * @since 3.0.0 * * @param {number} a - [description] * @param {number} b - [description] * @param {number} c - [description] * @param {number} d - [description] * @param {number} tx - [description] * @param {number} ty - [description] * * @return {this} This TransformMatrix. */ setTransform: function (a, b, c, d, tx, ty) { var matrix = this.matrix; matrix[0] = a; matrix[1] = b; matrix[2] = c; matrix[3] = d; matrix[4] = tx; matrix[5] = ty; return this; }, /** * [description] * * @method Phaser.GameObjects.Components.TransformMatrix#decomposeMatrix * @since 3.0.0 * * @return {object} [description] */ decomposeMatrix: function () { var decomposedMatrix = this.decomposedMatrix; var matrix = this.matrix; // a = scale X (1) // b = shear Y (0) // c = shear X (0) // d = scale Y (1) var a = matrix[0]; var b = matrix[1]; var c = matrix[2]; var d = matrix[3]; var a2 = a * a; var b2 = b * b; var c2 = c * c; var d2 = d * d; var sx = Math.sqrt(a2 + c2); var sy = Math.sqrt(b2 + d2); decomposedMatrix.translateX = matrix[4]; decomposedMatrix.translateY = matrix[5]; decomposedMatrix.scaleX = sx; decomposedMatrix.scaleY = sy; decomposedMatrix.rotation = Math.acos(a / sx) * (Math.atan(-c / a) < 0 ? -1 : 1); return decomposedMatrix; }, /** * Identity + Translate + Rotate + Scale * * @method Phaser.GameObjects.Components.TransformMatrix#applyITRS * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * @param {number} rotation - [description] * @param {number} scaleX - [description] * @param {number} scaleY - [description] * * @return {this} This TransformMatrix. */ applyITRS: function (x, y, rotation, scaleX, scaleY) { var matrix = this.matrix; var radianSin = Math.sin(rotation); var radianCos = Math.cos(rotation); // Translate matrix[4] = x; matrix[5] = y; // Rotate and Scale matrix[0] = radianCos * scaleX; matrix[1] = radianSin * scaleX; matrix[2] = -radianSin * scaleY; matrix[3] = radianCos * scaleY; return this; }, /** * Destroys this Transform Matrix. * * @method Phaser.GameObjects.Components.TransformMatrix#destroy * @since 3.4.0 */ destroy: function () { this.matrix = null; this.decomposedMatrix = null; } }); module.exports = TransformMatrix; /***/ }), /* 65 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clamp = __webpack_require__(23); /** * Return a value based on the range between `min` and `max` and the percentage given. * * @function Phaser.Math.FromPercent * @since 3.0.0 * * @param {float} percent - A value between 0 and 1 representing the percentage. * @param {number} min - The minimum value. * @param {number} [max] - The maximum value. * * @return {number} The value that is `percent` percent between `min` and `max`. */ var FromPercent = function (percent, min, max) { percent = Clamp(percent, 0, 1); return (max - min) * percent; }; module.exports = FromPercent; /***/ }), /* 66 */, /* 67 */, /* 68 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Contains = __webpack_require__(60); var GetPoint = __webpack_require__(227); var GetPoints = __webpack_require__(226); var Line = __webpack_require__(96); var Random = __webpack_require__(153); /** * @classdesc * A triangle is a plane created by connecting three points. * The first two arguments specify the first point, the middle two arguments * specify the second point, and the last two arguments specify the third point. * * @class Triangle * @memberOf Phaser.Geom * @constructor * @since 3.0.0 * * @param {number} [x1=0] - [description] * @param {number} [y1=0] - [description] * @param {number} [x2=0] - [description] * @param {number} [y2=0] - [description] * @param {number} [x3=0] - [description] * @param {number} [y3=0] - [description] */ var Triangle = new Class({ initialize: function Triangle (x1, y1, x2, y2, x3, y3) { if (x1 === undefined) { x1 = 0; } if (y1 === undefined) { y1 = 0; } if (x2 === undefined) { x2 = 0; } if (y2 === undefined) { y2 = 0; } if (x3 === undefined) { x3 = 0; } if (y3 === undefined) { y3 = 0; } /** * [description] * * @name Phaser.Geom.Triangle#x1 * @type {number} * @default 0 * @since 3.0.0 */ this.x1 = x1; /** * [description] * * @name Phaser.Geom.Triangle#y1 * @type {number} * @default 0 * @since 3.0.0 */ this.y1 = y1; /** * [description] * * @name Phaser.Geom.Triangle#x2 * @type {number} * @default 0 * @since 3.0.0 */ this.x2 = x2; /** * [description] * * @name Phaser.Geom.Triangle#y2 * @type {number} * @default 0 * @since 3.0.0 */ this.y2 = y2; /** * [description] * * @name Phaser.Geom.Triangle#x3 * @type {number} * @default 0 * @since 3.0.0 */ this.x3 = x3; /** * [description] * * @name Phaser.Geom.Triangle#y3 * @type {number} * @default 0 * @since 3.0.0 */ this.y3 = y3; }, /** * [description] * * @method Phaser.Geom.Triangle#contains * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * * @return {boolean} [description] */ contains: function (x, y) { return Contains(this, x, y); }, /** * [description] * * @method Phaser.Geom.Triangle#getPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [output,$return] * * @param {float} position - [description] * @param {(Phaser.Geom.Point|object)} [output] - [description] * * @return {(Phaser.Geom.Point|object)} [description] */ getPoint: function (position, output) { return GetPoint(this, position, output); }, /** * [description] * * @method Phaser.Geom.Triangle#getPoints * @since 3.0.0 * * @generic {Phaser.Geom.Point[]} O - [output,$return] * * @param {integer} quantity - [description] * @param {number} [stepRate] - [description] * @param {(array|Phaser.Geom.Point[])} [output] - [description] * * @return {(array|Phaser.Geom.Point[])} [description] */ getPoints: function (quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); }, /** * [description] * * @method Phaser.Geom.Triangle#getRandomPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [point,$return] * * @param {Phaser.Geom.Point} [point] - [description] * * @return {Phaser.Geom.Point} [description] */ getRandomPoint: function (point) { return Random(this, point); }, /** * [description] * * @method Phaser.Geom.Triangle#setTo * @since 3.0.0 * * @param {number} [x1=0] - [description] * @param {number} [y1=0] - [description] * @param {number} [x2=0] - [description] * @param {number} [y2=0] - [description] * @param {number} [x3=0] - [description] * @param {number} [y3=0] - [description] * * @return {Phaser.Geom.Triangle} This Triangle object. */ setTo: function (x1, y1, x2, y2, x3, y3) { if (x1 === undefined) { x1 = 0; } if (y1 === undefined) { y1 = 0; } if (x2 === undefined) { x2 = 0; } if (y2 === undefined) { y2 = 0; } if (x3 === undefined) { x3 = 0; } if (y3 === undefined) { y3 = 0; } this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; this.x3 = x3; this.y3 = y3; return this; }, /** * Returns a Line object that corresponds to Line A of this Triangle. * * @method Phaser.Geom.Triangle#getLineA * @since 3.0.0 * * @generic {Phaser.Geom.Line} O - [line,$return] * * @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created. * * @return {Phaser.Geom.Line} A Line object that corresponds to line A of this Triangle. */ getLineA: function (line) { if (line === undefined) { line = new Line(); } line.setTo(this.x1, this.y1, this.x2, this.y2); return line; }, /** * Returns a Line object that corresponds to Line B of this Triangle. * * @method Phaser.Geom.Triangle#getLineB * @since 3.0.0 * * @generic {Phaser.Geom.Line} O - [line,$return] * * @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created. * * @return {Phaser.Geom.Line} A Line object that corresponds to line B of this Triangle. */ getLineB: function (line) { if (line === undefined) { line = new Line(); } line.setTo(this.x2, this.y2, this.x3, this.y3); return line; }, /** * Returns a Line object that corresponds to Line C of this Triangle. * * @method Phaser.Geom.Triangle#getLineC * @since 3.0.0 * * @generic {Phaser.Geom.Line} O - [line,$return] * * @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created. * * @return {Phaser.Geom.Line} A Line object that corresponds to line C of this Triangle. */ getLineC: function (line) { if (line === undefined) { line = new Line(); } line.setTo(this.x3, this.y3, this.x1, this.y1); return line; }, /** * [description] * * @name Phaser.Geom.Triangle#left * @type {number} * @since 3.0.0 */ left: { get: function () { return Math.min(this.x1, this.x2, this.x3); }, set: function (value) { var diff = 0; if (this.x1 <= this.x2 && this.x1 <= this.x3) { diff = this.x1 - value; } else if (this.x2 <= this.x1 && this.x2 <= this.x3) { diff = this.x2 - value; } else { diff = this.x3 - value; } this.x1 -= diff; this.x2 -= diff; this.x3 -= diff; } }, /** * [description] * * @name Phaser.Geom.Triangle#right * @type {number} * @since 3.0.0 */ right: { get: function () { return Math.max(this.x1, this.x2, this.x3); }, set: function (value) { var diff = 0; if (this.x1 >= this.x2 && this.x1 >= this.x3) { diff = this.x1 - value; } else if (this.x2 >= this.x1 && this.x2 >= this.x3) { diff = this.x2 - value; } else { diff = this.x3 - value; } this.x1 -= diff; this.x2 -= diff; this.x3 -= diff; } }, /** * [description] * * @name Phaser.Geom.Triangle#top * @type {number} * @since 3.0.0 */ top: { get: function () { return Math.min(this.y1, this.y2, this.y3); }, set: function (value) { var diff = 0; if (this.y1 <= this.y2 && this.y1 <= this.y3) { diff = this.y1 - value; } else if (this.y2 <= this.y1 && this.y2 <= this.y3) { diff = this.y2 - value; } else { diff = this.y3 - value; } this.y1 -= diff; this.y2 -= diff; this.y3 -= diff; } }, /** * [description] * * @name Phaser.Geom.Triangle#bottom * @type {number} * @since 3.0.0 */ bottom: { get: function () { return Math.max(this.y1, this.y2, this.y3); }, set: function (value) { var diff = 0; if (this.y1 >= this.y2 && this.y1 >= this.y3) { diff = this.y1 - value; } else if (this.y2 >= this.y1 && this.y2 >= this.y3) { diff = this.y2 - value; } else { diff = this.y3 - value; } this.y1 -= diff; this.y2 -= diff; this.y3 -= diff; } } }); module.exports = Triangle; /***/ }), /* 69 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Components = __webpack_require__(15); var GameObject = __webpack_require__(2); var ImageRender = __webpack_require__(461); /** * @classdesc * An Image Game Object. * * An Image is a light-weight Game Object useful for the display of static images in your game, * such as logos, backgrounds, scenery or other non-animated elements. Images can have input * events and physics bodies, or be tweened, tinted or scrolled. The main difference between an * Image and a Sprite is that you cannot animate an Image as they do not have the Animation component. * * @class Image * @extends Phaser.GameObjects.GameObject * @memberOf Phaser.GameObjects * @constructor * @since 3.0.0 * * @extends Phaser.GameObjects.Components.Alpha * @extends Phaser.GameObjects.Components.BlendMode * @extends Phaser.GameObjects.Components.Depth * @extends Phaser.GameObjects.Components.Flip * @extends Phaser.GameObjects.Components.GetBounds * @extends Phaser.GameObjects.Components.Mask * @extends Phaser.GameObjects.Components.Origin * @extends Phaser.GameObjects.Components.Pipeline * @extends Phaser.GameObjects.Components.ScaleMode * @extends Phaser.GameObjects.Components.ScrollFactor * @extends Phaser.GameObjects.Components.Size * @extends Phaser.GameObjects.Components.Texture * @extends Phaser.GameObjects.Components.Tint * @extends Phaser.GameObjects.Components.Transform * @extends Phaser.GameObjects.Components.Visible * * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param {number} x - The horizontal position of this Game Object in the world. * @param {number} y - The vertical position of this Game Object in the world. * @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with. */ var Image = new Class({ Extends: GameObject, Mixins: [ Components.Alpha, Components.BlendMode, Components.Depth, Components.Flip, Components.GetBounds, Components.Mask, Components.Origin, Components.Pipeline, Components.ScaleMode, Components.ScrollFactor, Components.Size, Components.Texture, Components.Tint, Components.Transform, Components.Visible, ImageRender ], initialize: function Image (scene, x, y, texture, frame) { GameObject.call(this, scene, 'Image'); this.setTexture(texture, frame); this.setPosition(x, y); this.setSizeToFrame(); this.setOriginFromFrame(); this.initPipeline('TextureTintPipeline'); } }); module.exports = Image; /***/ }), /* 70 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @callback EachSetCallback * @generic E - [entry] * * @param {*} entry - [description] * @param {number} index - [description] * * @return {?boolean} [description] */ /** * @classdesc * A Set is a collection of unique elements. * * @class Set * @memberOf Phaser.Structs * @constructor * @since 3.0.0 * * @generic T * @genericUse {T[]} - [elements] * * @param {Array.<*>} [elements] - [description] */ var Set = new Class({ initialize: function Set (elements) { /** * [description] * * @genericUse {T[]} - [$type] * * @name Phaser.Structs.Set#entries * @type {Array.<*>} * @default [] * @since 3.0.0 */ this.entries = []; if (Array.isArray(elements)) { for (var i = 0; i < elements.length; i++) { this.set(elements[i]); } } }, /** * [description] * * @method Phaser.Structs.Set#set * @since 3.0.0 * * @genericUse {T} - [value] * @genericUse {Phaser.Structs.Set.} - [$return] * * @param {*} value - [description] * * @return {Phaser.Structs.Set} This Set object. */ set: function (value) { if (this.entries.indexOf(value) === -1) { this.entries.push(value); } return this; }, /** * [description] * * @method Phaser.Structs.Set#get * @since 3.0.0 * * @genericUse {T} - [value,$return] * * @param {string} property - [description] * @param {*} value - [description] * * @return {*} [description] */ get: function (property, value) { for (var i = 0; i < this.entries.length; i++) { var entry = this.entries[i]; if (entry[property] === value) { return entry; } } }, /** * [description] * * @method Phaser.Structs.Set#getArray * @since 3.0.0 * * @genericUse {T[]} - [$return] * * @return {Array.<*>} [description] */ getArray: function () { return this.entries.slice(0); }, /** * [description] * * @method Phaser.Structs.Set#delete * @since 3.0.0 * * @genericUse {T} - [value] * @genericUse {Phaser.Structs.Set.} - [$return] * * @param {*} value - [description] * * @return {Phaser.Structs.Set} This Set object. */ delete: function (value) { var index = this.entries.indexOf(value); if (index > -1) { this.entries.splice(index, 1); } return this; }, /** * [description] * * @method Phaser.Structs.Set#dump * @since 3.0.0 */ dump: function () { // eslint-disable-next-line no-console console.group('Set'); for (var i = 0; i < this.entries.length; i++) { var entry = this.entries[i]; console.log(entry); } // eslint-disable-next-line no-console console.groupEnd(); }, /** * For when you know this Set will be modified during the iteration. * * @method Phaser.Structs.Set#each * @since 3.0.0 * * @genericUse {EachSetCallback.} - [callback] * @genericUse {Phaser.Structs.Set.} - [$return] * * @param {EachSetCallback} callback - [description] * @param {*} callbackScope - [description] * * @return {Phaser.Structs.Set} This Set object. */ each: function (callback, callbackScope) { var i; var temp = this.entries.slice(); var len = temp.length; if (callbackScope) { for (i = 0; i < len; i++) { if (callback.call(callbackScope, temp[i], i) === false) { break; } } } else { for (i = 0; i < len; i++) { if (callback(temp[i], i) === false) { break; } } } return this; }, /** * For when you absolutely know this Set won't be modified during the iteration. * * @method Phaser.Structs.Set#iterate * @since 3.0.0 * * @genericUse {EachSetCallback.} - [callback] * @genericUse {Phaser.Structs.Set.} - [$return] * * @param {EachSetCallback} callback - [description] * @param {*} callbackScope - [description] * * @return {Phaser.Structs.Set} This Set object. */ iterate: function (callback, callbackScope) { var i; var len = this.entries.length; if (callbackScope) { for (i = 0; i < len; i++) { if (callback.call(callbackScope, this.entries[i], i) === false) { break; } } } else { for (i = 0; i < len; i++) { if (callback(this.entries[i], i) === false) { break; } } } return this; }, /** * [description] * * @method Phaser.Structs.Set#iterateLocal * @since 3.0.0 * * @genericUse {Phaser.Structs.Set.} - [$return] * * @param {string} callbackKey - [description] * @param {...*} [args] - Additional arguments that will be passed to the callback, after the child. * * @return {Phaser.Structs.Set} This Set object. */ iterateLocal: function (callbackKey) { var i; var args = []; for (i = 1; i < arguments.length; i++) { args.push(arguments[i]); } var len = this.entries.length; for (i = 0; i < len; i++) { var entry = this.entries[i]; entry[callbackKey].apply(entry, args); } return this; }, /** * [description] * * @method Phaser.Structs.Set#clear * @since 3.0.0 * * @genericUse {Phaser.Structs.Set.} - [$return] * * @return {Phaser.Structs.Set} This Set object. */ clear: function () { this.entries.length = 0; return this; }, /** * [description] * * @method Phaser.Structs.Set#contains * @since 3.0.0 * * @genericUse {T} - [value] * * @param {*} value - [description] * * @return {boolean} [description] */ contains: function (value) { return (this.entries.indexOf(value) > -1); }, /** * [description] * * @method Phaser.Structs.Set#union * @since 3.0.0 * * @genericUse {Phaser.Structs.Set.} - [set,$return] * * @param {Phaser.Structs.Set} set - [description] * * @return {Phaser.Structs.Set} [description] */ union: function (set) { var newSet = new Set(); set.entries.forEach(function (value) { newSet.set(value); }); this.entries.forEach(function (value) { newSet.set(value); }); return newSet; }, /** * [description] * * @method Phaser.Structs.Set#intersect * @since 3.0.0 * * @genericUse {Phaser.Structs.Set.} - [set,$return] * * @param {Phaser.Structs.Set} set - [description] * * @return {Phaser.Structs.Set} [description] */ intersect: function (set) { var newSet = new Set(); this.entries.forEach(function (value) { if (set.contains(value)) { newSet.set(value); } }); return newSet; }, /** * [description] * * @method Phaser.Structs.Set#difference * @since 3.0.0 * * @genericUse {Phaser.Structs.Set.} - [set,$return] * * @param {Phaser.Structs.Set} set - [description] * * @return {Phaser.Structs.Set} [description] */ difference: function (set) { var newSet = new Set(); this.entries.forEach(function (value) { if (!set.contains(value)) { newSet.set(value); } }); return newSet; }, /** * [description] * * @name Phaser.Structs.Set#size * @type {integer} * @since 3.0.0 */ size: { get: function () { return this.entries.length; }, set: function (value) { return this.entries.length = value; } } }); module.exports = Set; /***/ }), /* 71 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Geom.Line.Length * @since 3.0.0 * * @param {Phaser.Geom.Line} line - [description] * * @return {number} [description] */ var Length = function (line) { return Math.sqrt((line.x2 - line.x1) * (line.x2 - line.x1) + (line.y2 - line.y1) * (line.y2 - line.y1)); }; module.exports = Length; /***/ }), /* 72 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Defaults = __webpack_require__(100); var GetAdvancedValue = __webpack_require__(10); var GetBoolean = __webpack_require__(62); var GetEaseFunction = __webpack_require__(63); var GetNewValue = __webpack_require__(73); var GetProps = __webpack_require__(163); var GetTargets = __webpack_require__(102); var GetValue = __webpack_require__(4); var GetValueOp = __webpack_require__(101); var Tween = __webpack_require__(99); var TweenData = __webpack_require__(98); /** * [description] * * @function Phaser.Tweens.Builders.TweenBuilder * @since 3.0.0 * * @param {(Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline)} parent - [description] * @param {object} config - [description] * @param {Phaser.Tweens.TweenConfigDefaults} defaults - [description] * * @return {Phaser.Tweens.Tween} [description] */ var TweenBuilder = function (parent, config, defaults) { if (defaults === undefined) { defaults = Defaults; } // Create arrays of the Targets and the Properties var targets = (defaults.targets) ? defaults.targets : GetTargets(config); // var props = (defaults.props) ? defaults.props : GetProps(config); var props = GetProps(config); // Default Tween values var delay = GetNewValue(config, 'delay', defaults.delay); var duration = GetNewValue(config, 'duration', defaults.duration); var easeParams = GetValue(config, 'easeParams', defaults.easeParams); var ease = GetEaseFunction(GetValue(config, 'ease', defaults.ease), easeParams); var hold = GetNewValue(config, 'hold', defaults.hold); var repeat = GetNewValue(config, 'repeat', defaults.repeat); var repeatDelay = GetNewValue(config, 'repeatDelay', defaults.repeatDelay); var yoyo = GetBoolean(config, 'yoyo', defaults.yoyo); var flipX = GetBoolean(config, 'flipX', defaults.flipX); var flipY = GetBoolean(config, 'flipY', defaults.flipY); var data = []; // Loop through every property defined in the Tween, i.e.: props { x, y, alpha } for (var p = 0; p < props.length; p++) { var key = props[p].key; var value = props[p].value; // Create 1 TweenData per target, per property for (var t = 0; t < targets.length; t++) { var ops = GetValueOp(key, value); var tweenData = TweenData( targets[t], key, ops.getEnd, ops.getStart, GetEaseFunction(GetValue(value, 'ease', ease), easeParams), GetNewValue(value, 'delay', delay), GetNewValue(value, 'duration', duration), GetBoolean(value, 'yoyo', yoyo), GetNewValue(value, 'hold', hold), GetNewValue(value, 'repeat', repeat), GetNewValue(value, 'repeatDelay', repeatDelay), GetBoolean(value, 'flipX', flipX), GetBoolean(value, 'flipY', flipY) ); data.push(tweenData); } } var tween = new Tween(parent, data, targets); tween.offset = GetAdvancedValue(config, 'offset', null); tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0); tween.loop = Math.round(GetAdvancedValue(config, 'loop', 0)); tween.loopDelay = Math.round(GetAdvancedValue(config, 'loopDelay', 0)); tween.paused = GetBoolean(config, 'paused', false); tween.useFrames = GetBoolean(config, 'useFrames', false); // Set the Callbacks var scope = GetValue(config, 'callbackScope', tween); // Callback parameters: 0 = a reference to the Tween itself, 1 = the target/s of the Tween, ... your own params var tweenArray = [ tween, null ]; var callbacks = Tween.TYPES; for (var i = 0; i < callbacks.length; i++) { var type = callbacks[i]; var callback = GetValue(config, type, false); if (callback) { var callbackScope = GetValue(config, type + 'Scope', scope); var callbackParams = GetValue(config, type + 'Params', []); // The null is reset to be the Tween target tween.setCallback(type, callback, tweenArray.concat(callbackParams), callbackScope); } } return tween; }; module.exports = TweenBuilder; /***/ }), /* 73 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Tweens.Builders.GetNewValue * @since 3.0.0 * * @param {object} source - [description] * @param {string} key - [description] * @param {*} defaultValue - [description] * * @return {function} [description] */ var GetNewValue = function (source, key, defaultValue) { var valueCallback; if (source.hasOwnProperty(key)) { var t = typeof(source[key]); if (t === 'function') { valueCallback = function (index, totalTargets, target) { return source[key](index, totalTargets, target); }; } else { valueCallback = function () { return source[key]; }; } } else if (typeof defaultValue === 'function') { valueCallback = defaultValue; } else { valueCallback = function () { return defaultValue; }; } return valueCallback; }; module.exports = GetNewValue; /***/ }), /* 74 */, /* 75 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @typedef {object} XHRSettingsObject * * @property {XMLHttpRequestResponseType} responseType - The response type of the XHR request, i.e. `blob`, `text`, etc. * @property {boolean} [async=true] - Should the XHR request use async or not? * @property {string} [user=''] - Optional username for the XHR request. * @property {string} [password=''] - Optional password for the XHR request. * @property {integer} [timeout=0] - Optional XHR timeout value. * @property {(string|undefined)} [header] - This value is used to populate the XHR `setRequestHeader` and is undefined by default. * @property {(string|undefined)} [headerValue] - This value is used to populate the XHR `setRequestHeader` and is undefined by default. * @property {(string|undefined)} [requestedWith] - This value is used to populate the XHR `setRequestHeader` and is undefined by default. * @property {(string|undefined)} [overrideMimeType] - Provide a custom mime-type to use instead of the default. */ /** * Creates an XHRSettings Object with default values. * * @function Phaser.Loader.XHRSettings * @since 3.0.0 * * @param {XMLHttpRequestResponseType} [responseType=''] - The responseType, such as 'text'. * @param {boolean} [async=true] - Should the XHR request use async or not? * @param {string} [user=''] - Optional username for the XHR request. * @param {string} [password=''] - Optional password for the XHR request. * @param {integer} [timeout=0] - Optional XHR timeout value. * * @return {XHRSettingsObject} The XHRSettings object as used by the Loader. */ var XHRSettings = function (responseType, async, user, password, timeout) { if (responseType === undefined) { responseType = ''; } if (async === undefined) { async = true; } if (user === undefined) { user = ''; } if (password === undefined) { password = ''; } if (timeout === undefined) { timeout = 0; } // Before sending a request, set the xhr.responseType to "text", // "arraybuffer", "blob", or "document", depending on your data needs. // Note, setting xhr.responseType = '' (or omitting) will default the response to "text". return { // Ignored by the Loader, only used by File. responseType: responseType, async: async, // credentials user: user, password: password, // timeout in ms (0 = no timeout) timeout: timeout, // setRequestHeader header: undefined, headerValue: undefined, requestedWith: false, // overrideMimeType overrideMimeType: undefined }; }; module.exports = XHRSettings; /***/ }), /* 76 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetValue = __webpack_require__(4); // Contains the plugins that Phaser uses globally and locally. // These are the source objects, not instantiated. var inputPlugins = {}; /** * @typedef {object} InputPluginContainer * * @property {string} key - The unique name of this plugin in the input plugin cache. * @property {function} plugin - The plugin to be stored. Should be the source object, not instantiated. * @property {string} [mapping] - If this plugin is to be injected into the Input Plugin, this is the property key map used. */ var InputPluginCache = {}; /** * Static method called directly by the Core internal Plugins. * Key is a reference used to get the plugin from the plugins object (i.e. InputPlugin) * Plugin is the object to instantiate to create the plugin * Mapping is what the plugin is injected into the Scene.Systems as (i.e. input) * * @method Phaser.Input.InputPluginCache.register * @since 3.10.0 * * @param {string} key - A reference used to get this plugin from the plugin cache. * @param {function} plugin - The plugin to be stored. Should be the core object, not instantiated. * @param {string} mapping - If this plugin is to be injected into the Input Plugin, this is the property key used. * @param {string} settingsKey - The key in the Scene Settings to check to see if this plugin should install or not. * @param {string} configKey - The key in the Game Config to check to see if this plugin should install or not. */ InputPluginCache.register = function (key, plugin, mapping, settingsKey, configKey) { inputPlugins[key] = { plugin: plugin, mapping: mapping, settingsKey: settingsKey, configKey: configKey }; }; /** * Returns the input plugin object from the cache based on the given key. * * @method Phaser.Input.InputPluginCache.getCore * @since 3.10.0 * * @param {string} key - The key of the input plugin to get. * * @return {InputPluginContainer} The input plugin object. */ InputPluginCache.getPlugin = function (key) { return inputPlugins[key]; }; /** * Installs all of the registered Input Plugins into the given target. * * @method Phaser.Input.InputPluginCache.install * @since 3.10.0 * * @param {Phaser.Input.InputPlugin} target - The target InputPlugin to install the plugins into. */ InputPluginCache.install = function (target) { var sys = target.scene.sys; var settings = sys.settings.input; var config = sys.game.config; for (var key in inputPlugins) { var source = inputPlugins[key].plugin; var mapping = inputPlugins[key].mapping; var settingsKey = inputPlugins[key].settingsKey; var configKey = inputPlugins[key].configKey; if (GetValue(settings, settingsKey, config[configKey])) { target[mapping] = new source(target); } } }; /** * Removes an input plugin based on the given key. * * @method Phaser.Input.InputPluginCache.remove * @since 3.10.0 * * @param {string} key - The key of the input plugin to remove. */ InputPluginCache.remove = function (key) { if (inputPlugins.hasOwnProperty(key)) { delete inputPlugins[key]; } }; module.exports = InputPluginCache; /***/ }), /* 77 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // Based on the routine from {@link http://jsfiddle.net/MrPolywhirl/NH42z/}. var CheckMatrix = __webpack_require__(116); var TransposeMatrix = __webpack_require__(181); /** * [description] * * @function Phaser.Utils.Array.Matrix.RotateMatrix * @since 3.0.0 * * @param {array} matrix - The array to rotate. * @param {(number|string)} [direction=90] - The amount to rotate the matrix by. The value can be given in degrees: 90, -90, 270, -270 or 180, or a string command: `rotateLeft`, `rotateRight` or `rotate180`. * * @return {array} The rotated matrix array. The source matrix should be discard for the returned matrix. */ var RotateMatrix = function (matrix, direction) { if (direction === undefined) { direction = 90; } if (!CheckMatrix(matrix)) { return null; } if (typeof direction !== 'string') { direction = ((direction % 360) + 360) % 360; } if (direction === 90 || direction === -270 || direction === 'rotateLeft') { matrix = TransposeMatrix(matrix); matrix.reverse(); } else if (direction === -90 || direction === 270 || direction === 'rotateRight') { matrix.reverse(); matrix = TransposeMatrix(matrix); } else if (Math.abs(direction) === 180 || direction === 'rotate180') { for (var i = 0; i < matrix.length; i++) { matrix[i].reverse(); } matrix.reverse(); } return matrix; }; module.exports = RotateMatrix; /***/ }), /* 78 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var EventEmitter = __webpack_require__(9); var Extend = __webpack_require__(17); var NOOP = __webpack_require__(3); /** * @classdesc * Class containing all the shared state and behavior of a sound object, independent of the implementation. * * @class BaseSound * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Sound * @constructor * @since 3.0.0 * * @param {Phaser.Sound.BaseSoundManager} manager - Reference to the current sound manager instance. * @param {string} key - Asset key for the sound. * @param {SoundConfig} [config] - An optional config object containing default sound settings. */ var BaseSound = new Class({ Extends: EventEmitter, initialize: function BaseSound (manager, key, config) { EventEmitter.call(this); /** * Local reference to the sound manager. * * @name Phaser.Sound.BaseSound#manager * @type {Phaser.Sound.BaseSoundManager} * @private * @since 3.0.0 */ this.manager = manager; /** * Asset key for the sound. * * @name Phaser.Sound.BaseSound#key * @type {string} * @readOnly * @since 3.0.0 */ this.key = key; /** * Flag indicating if sound is currently playing. * * @name Phaser.Sound.BaseSound#isPlaying * @type {boolean} * @default false * @readOnly * @since 3.0.0 */ this.isPlaying = false; /** * Flag indicating if sound is currently paused. * * @name Phaser.Sound.BaseSound#isPaused * @type {boolean} * @default false * @readOnly * @since 3.0.0 */ this.isPaused = false; /** * A property that holds the value of sound's actual playback rate, * after its rate and detune values has been combined with global * rate and detune values. * * @name Phaser.Sound.BaseSound#totalRate * @type {number} * @default 1 * @readOnly * @since 3.0.0 */ this.totalRate = 1; /** * A value representing the duration, in seconds. * It could be total sound duration or a marker duration. * * @name Phaser.Sound.BaseSound#duration * @type {number} * @readOnly * @since 3.0.0 */ this.duration = this.duration || 0; /** * The total duration of the sound in seconds. * * @name Phaser.Sound.BaseSound#totalDuration * @type {number} * @readOnly * @since 3.0.0 */ this.totalDuration = this.totalDuration || 0; /** * A config object used to store default sound settings' values. * Default values will be set by properties' setters. * * @name Phaser.Sound.BaseSound#config * @type {SoundConfig} * @private * @since 3.0.0 */ this.config = { mute: false, volume: 1, rate: 1, detune: 0, seek: 0, loop: false, delay: 0 }; /** * Reference to the currently used config. * It could be default config or marker config. * * @name Phaser.Sound.BaseSound#currentConfig * @type {SoundConfig} * @private * @since 3.0.0 */ this.currentConfig = this.config; this.config = Extend(this.config, config); /** * Object containing markers definitions. * * @name Phaser.Sound.BaseSound#markers * @type {Object.} * @default {} * @readOnly * @since 3.0.0 */ this.markers = {}; /** * Currently playing marker. * 'null' if whole sound is playing. * * @name Phaser.Sound.BaseSound#currentMarker * @type {SoundMarker} * @default null * @readOnly * @since 3.0.0 */ this.currentMarker = null; /** * Flag indicating if destroy method was called on this sound. * * @name Phaser.Sound.BaseSound#pendingRemove * @type {boolean} * @private * @default false * @since 3.0.0 */ this.pendingRemove = false; }, /** * Adds a marker into the current sound. A marker is represented by name, start time, duration, and optionally config object. * This allows you to bundle multiple sounds together into a single audio file and use markers to jump between them for playback. * * @method Phaser.Sound.BaseSound#addMarker * @since 3.0.0 * * @param {SoundMarker} marker - Marker object. * * @return {boolean} Whether the marker was added successfully. */ addMarker: function (marker) { if (!marker || !marker.name || typeof marker.name !== 'string') { return false; } if (this.markers[marker.name]) { // eslint-disable-next-line no-console console.error('addMarker ' + marker.name + ' already exists in Sound'); return false; } marker = Extend(true, { name: '', start: 0, duration: this.totalDuration - (marker.start || 0), config: { mute: false, volume: 1, rate: 1, detune: 0, seek: 0, loop: false, delay: 0 } }, marker); this.markers[marker.name] = marker; return true; }, /** * Updates previously added marker. * * @method Phaser.Sound.BaseSound#updateMarker * @since 3.0.0 * * @param {SoundMarker} marker - Marker object with updated values. * * @return {boolean} Whether the marker was updated successfully. */ updateMarker: function (marker) { if (!marker || !marker.name || typeof marker.name !== 'string') { return false; } if (!this.markers[marker.name]) { // eslint-disable-next-line no-console console.warn('Audio Marker: ' + marker.name + ' missing in Sound: ' + this.key); return false; } this.markers[marker.name] = Extend(true, this.markers[marker.name], marker); return true; }, /** * Removes a marker from the sound. * * @method Phaser.Sound.BaseSound#removeMarker * @since 3.0.0 * * @param {string} markerName - The name of the marker to remove. * * @return {?SoundMarker} Removed marker object or 'null' if there was no marker with provided name. */ removeMarker: function (markerName) { var marker = this.markers[markerName]; if (!marker) { return null; } this.markers[markerName] = null; return marker; }, /** * Play this sound, or a marked section of it. * It always plays the sound from the start. If you want to start playback from a specific time * you can set 'seek' setting of the config object, provided to this call, to that value. * * @method Phaser.Sound.BaseSound#play * @since 3.0.0 * * @param {string} [markerName=''] - If you want to play a marker then provide the marker name here, otherwise omit it to play the full sound. * @param {SoundConfig} [config] - Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound. * * @return {boolean} Whether the sound started playing successfully. */ play: function (markerName, config) { if (markerName === undefined) { markerName = ''; } if (typeof markerName === 'object') { config = markerName; markerName = ''; } if (typeof markerName !== 'string') { return false; } if (!markerName) { this.currentMarker = null; this.currentConfig = this.config; this.duration = this.totalDuration; } else { if (!this.markers[markerName]) { // eslint-disable-next-line no-console console.warn('Marker: ' + markerName + ' missing in Sound: ' + this.key); return false; } this.currentMarker = this.markers[markerName]; this.currentConfig = this.currentMarker.config; this.duration = this.currentMarker.duration; } this.resetConfig(); this.currentConfig = Extend(this.currentConfig, config); this.isPlaying = true; this.isPaused = false; return true; }, /** * Pauses the sound. * * @method Phaser.Sound.BaseSound#pause * @since 3.0.0 * * @return {boolean} Whether the sound was paused successfully. */ pause: function () { if (this.isPaused || !this.isPlaying) { return false; } this.isPlaying = false; this.isPaused = true; return true; }, /** * Resumes the sound. * * @method Phaser.Sound.BaseSound#resume * @since 3.0.0 * * @return {boolean} Whether the sound was resumed successfully. */ resume: function () { if (!this.isPaused || this.isPlaying) { return false; } this.isPlaying = true; this.isPaused = false; return true; }, /** * Stop playing this sound. * * @method Phaser.Sound.BaseSound#stop * @since 3.0.0 * * @return {boolean} Whether the sound was stopped successfully. */ stop: function () { if (!this.isPaused && !this.isPlaying) { return false; } this.isPlaying = false; this.isPaused = false; this.resetConfig(); return true; }, /** * Method used internally for applying config values to some of the sound properties. * * @method Phaser.Sound.BaseSound#applyConfig * @protected * @since 3.0.0 */ applyConfig: function () { this.mute = this.currentConfig.mute; this.volume = this.currentConfig.volume; this.rate = this.currentConfig.rate; this.detune = this.currentConfig.detune; this.loop = this.currentConfig.loop; }, /** * Method used internally for resetting values of some of the config properties. * * @method Phaser.Sound.BaseSound#resetConfig * @protected * @since 3.0.0 */ resetConfig: function () { this.currentConfig.seek = 0; this.currentConfig.delay = 0; }, /** * Update method called automatically by sound manager on every game step. * * @method Phaser.Sound.BaseSound#update * @override * @protected * @since 3.0.0 * * @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time elapsed since the last frame. */ update: NOOP, /** * Method used internally to calculate total playback rate of the sound. * * @method Phaser.Sound.BaseSound#calculateRate * @protected * @since 3.0.0 */ calculateRate: function () { var cent = 1.0005777895065548; // Math.pow(2, 1/1200); var totalDetune = this.currentConfig.detune + this.manager.detune; var detuneRate = Math.pow(cent, totalDetune); this.totalRate = this.currentConfig.rate * this.manager.rate * detuneRate; }, /** * Destroys this sound and all associated events and marks it for removal from the sound manager. * * @method Phaser.Sound.BaseSound#destroy * @since 3.0.0 */ destroy: function () { if (this.pendingRemove) { return; } this.emit('destroy', this); this.pendingRemove = true; this.manager = null; this.key = ''; this.removeAllListeners(); this.isPlaying = false; this.isPaused = false; this.config = null; this.currentConfig = null; this.markers = null; this.currentMarker = null; } }); module.exports = BaseSound; /***/ }), /* 79 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Clone = __webpack_require__(33); var EventEmitter = __webpack_require__(9); var NOOP = __webpack_require__(3); /** * @callback EachActiveSoundCallback * * @param {Phaser.Sound.BaseSoundManager} manager - The SoundManager * @param {Phaser.Sound.BaseSound} sound - The current active Sound * @param {number} index - The index of the current active Sound * @param {Phaser.Sound.BaseSound[]} sounds - All sounds */ /** * Audio sprite sound type. * * @typedef {Phaser.Sound.BaseSound} Phaser.Sound.BaseSound.AudioSpriteSound * * @property {object} spritemap - Local reference to 'spritemap' object form json file generated by audiosprite tool. */ /** * @classdesc * The sound manager is responsible for playing back audio via Web Audio API or HTML Audio tag as fallback. * The audio file type and the encoding of those files are extremely important. * * Not all browsers can play all audio formats. * * There is a good guide to what's supported [here](https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics#Audio_Codec_Support). * * @class BaseSoundManager * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Sound * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - Reference to the current game instance. */ var BaseSoundManager = new Class({ Extends: EventEmitter, initialize: function BaseSoundManager (game) { EventEmitter.call(this); /** * Local reference to game. * * @name Phaser.Sound.BaseSoundManager#game * @type {Phaser.Game} * @readOnly * @since 3.0.0 */ this.game = game; /** * Local reference to the JSON Cache, as used by Audio Sprites. * * @name Phaser.Sound.BaseSoundManager#jsonCache * @type {Phaser.Cache.BaseCache} * @readOnly * @since 3.7.0 */ this.jsonCache = game.cache.json; /** * An array containing all added sounds. * * @name Phaser.Sound.BaseSoundManager#sounds * @type {Phaser.Sound.BaseSound[]} * @default [] * @private * @since 3.0.0 */ this.sounds = []; /** * Global mute setting. * * @name Phaser.Sound.BaseSoundManager#mute * @type {boolean} * @default false * @since 3.0.0 */ this.mute = false; /** * Global volume setting. * * @name Phaser.Sound.BaseSoundManager#volume * @type {number} * @default 1 * @since 3.0.0 */ this.volume = 1; /** * Flag indicating if sounds should be paused when game looses focus, * for instance when user switches to another tab/program/app. * * @name Phaser.Sound.BaseSoundManager#pauseOnBlur * @type {boolean} * @default true * @since 3.0.0 */ this.pauseOnBlur = true; /** * Property that actually holds the value of global playback rate. * * @name Phaser.Sound.BaseSoundManager#_rate * @type {number} * @private * @default 1 * @since 3.0.0 */ this._rate = 1; /** * Property that actually holds the value of global detune. * * @name Phaser.Sound.BaseSoundManager#_detune * @type {number} * @private * @default 0 * @since 3.0.0 */ this._detune = 0; /** * Mobile devices require sounds to be triggered from an explicit user action, * such as a tap, before any sound can be loaded/played on a web page. * Set to true if the audio system is currently locked awaiting user interaction. * * @name Phaser.Sound.BaseSoundManager#locked * @type {boolean} * @readOnly * @since 3.0.0 */ this.locked = this.locked || false; /** * Flag used internally for handling when the audio system * has been unlocked, if there ever was a need for it. * * @name Phaser.Sound.BaseSoundManager#unlocked * @type {boolean} * @default false * @private * @since 3.0.0 */ this.unlocked = false; game.events.on('blur', function () { if (this.pauseOnBlur) { this.onBlur(); } }, this); game.events.on('focus', function () { if (this.pauseOnBlur) { this.onFocus(); } }, this); game.events.on('prestep', this.update, this); game.events.once('destroy', this.destroy, this); }, /** * Adds a new sound into the sound manager. * * @method Phaser.Sound.BaseSoundManager#add * @override * @since 3.0.0 * * @param {string} key - Asset key for the sound. * @param {SoundConfig} [config] - An optional config object containing default sound settings. * * @return {Phaser.Sound.BaseSound} The new sound instance. */ add: NOOP, /** * Adds a new audio sprite sound into the sound manager. * Audio Sprites are a combination of audio files and a JSON configuration. * The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite * * @method Phaser.Sound.BaseSoundManager#addAudioSprite * @since 3.0.0 * * @param {string} key - Asset key for the sound. * @param {SoundConfig} [config] - An optional config object containing default sound settings. * * @return {Phaser.Sound.BaseSound.AudioSpriteSound} The new audio sprite sound instance. */ addAudioSprite: function (key, config) { if (config === undefined) { config = {}; } var sound = this.add(key, config); sound.spritemap = this.jsonCache.get(key).spritemap; for (var markerName in sound.spritemap) { if (!sound.spritemap.hasOwnProperty(markerName)) { continue; } var markerConfig = Clone(config); var marker = sound.spritemap[markerName]; markerConfig.loop = (marker.hasOwnProperty('loop')) ? marker.loop : false; sound.addMarker({ name: markerName, start: marker.start, duration: marker.end - marker.start, config: markerConfig }); } return sound; }, /** * Enables playing sound on the fly without the need to keep a reference to it. * Sound will auto destroy once its playback ends. * * @method Phaser.Sound.BaseSoundManager#play * @since 3.0.0 * * @param {string} key - Asset key for the sound. * @param {(SoundConfig|SoundMarker)} [extra] - An optional additional object containing settings to be applied to the sound. It could be either config or marker object. * * @return {boolean} Whether the sound started playing successfully. */ play: function (key, extra) { var sound = this.add(key); sound.once('ended', sound.destroy, sound); if (extra) { if (extra.name) { sound.addMarker(extra); return sound.play(extra.name); } else { return sound.play(extra); } } else { return sound.play(); } }, /** * Enables playing audio sprite sound on the fly without the need to keep a reference to it. * Sound will auto destroy once its playback ends. * * @method Phaser.Sound.BaseSoundManager#playAudioSprite * @since 3.0.0 * * @param {string} key - Asset key for the sound. * @param {string} spriteName - The name of the sound sprite to play. * @param {SoundConfig} [config] - An optional config object containing default sound settings. * * @return {boolean} Whether the audio sprite sound started playing successfully. */ playAudioSprite: function (key, spriteName, config) { var sound = this.addAudioSprite(key); sound.once('ended', sound.destroy, sound); return sound.play(spriteName, config); }, /** * Removes a sound from the sound manager. * The removed sound is destroyed before removal. * * @method Phaser.Sound.BaseSoundManager#remove * @since 3.0.0 * * @param {Phaser.Sound.BaseSound} sound - The sound object to remove. * * @return {boolean} True if the sound was removed successfully, otherwise false. */ remove: function (sound) { var index = this.sounds.indexOf(sound); if (index !== -1) { sound.destroy(); this.sounds.splice(index, 1); return true; } return false; }, /** * Removes all sounds from the sound manager that have an asset key matching the given value. * The removed sounds are destroyed before removal. * * @method Phaser.Sound.BaseSoundManager#removeByKey * @since 3.0.0 * * @param {string} key - The key to match when removing sound objects. * * @return {number} The number of matching sound objects that were removed. */ removeByKey: function (key) { var removed = 0; for (var i = this.sounds.length - 1; i >= 0; i--) { var sound = this.sounds[i]; if (sound.key === key) { sound.destroy(); this.sounds.splice(i, 1); removed++; } } return removed; }, /** * @event Phaser.Sound.BaseSoundManager#pauseall * @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event. */ /** * Pauses all the sounds in the game. * * @method Phaser.Sound.BaseSoundManager#pauseAll * @fires Phaser.Sound.BaseSoundManager#pauseall * @since 3.0.0 */ pauseAll: function () { this.forEachActiveSound(function (sound) { sound.pause(); }); this.emit('pauseall', this); }, /** * @event Phaser.Sound.BaseSoundManager#resumeall * @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event. */ /** * Resumes all the sounds in the game. * * @method Phaser.Sound.BaseSoundManager#resumeAll * @fires Phaser.Sound.BaseSoundManager#resumeall * @since 3.0.0 */ resumeAll: function () { this.forEachActiveSound(function (sound) { sound.resume(); }); this.emit('resumeall', this); }, /** * @event Phaser.Sound.BaseSoundManager#stopall * @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event. */ /** * Stops all the sounds in the game. * * @method Phaser.Sound.BaseSoundManager#stopAll * @fires Phaser.Sound.BaseSoundManager#stopall * @since 3.0.0 */ stopAll: function () { this.forEachActiveSound(function (sound) { sound.stop(); }); this.emit('stopall', this); }, /** * Method used internally for unlocking audio playback on devices that * require user interaction before any sound can be played on a web page. * * Read more about how this issue is handled here in [this article](https://medium.com/@pgoloskokovic/unlocking-web-audio-the-smarter-way-8858218c0e09). * * @method Phaser.Sound.BaseSoundManager#unlock * @override * @protected * @since 3.0.0 */ unlock: NOOP, /** * Method used internally for pausing sound manager if * Phaser.Sound.BaseSoundManager#pauseOnBlur is set to true. * * @method Phaser.Sound.BaseSoundManager#onBlur * @override * @protected * @since 3.0.0 */ onBlur: NOOP, /** * Method used internally for resuming sound manager if * Phaser.Sound.BaseSoundManager#pauseOnBlur is set to true. * * @method Phaser.Sound.BaseSoundManager#onFocus * @override * @protected * @since 3.0.0 */ onFocus: NOOP, /** * Update method called on every game step. * Removes destroyed sounds and updates every active sound in the game. * * @method Phaser.Sound.BaseSoundManager#update * @protected * @since 3.0.0 * * @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time elapsed since the last frame. */ update: function (time, delta) { if (this.unlocked) { this.unlocked = false; this.locked = false; /** * @event Phaser.Sound.BaseSoundManager#unlocked * @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event. */ this.emit('unlocked', this); } for (var i = this.sounds.length - 1; i >= 0; i--) { if (this.sounds[i].pendingRemove) { this.sounds.splice(i, 1); } } this.sounds.forEach(function (sound) { sound.update(time, delta); }); }, /** * Destroys all the sounds in the game and all associated events. * * @method Phaser.Sound.BaseSoundManager#destroy * @since 3.0.0 */ destroy: function () { this.removeAllListeners(); this.forEachActiveSound(function (sound) { sound.destroy(); }); this.sounds.length = 0; this.sounds = null; this.game = null; }, /** * Method used internally for iterating only over active sounds and skipping sounds that are marked for removal. * * @method Phaser.Sound.BaseSoundManager#forEachActiveSound * @private * @since 3.0.0 * * @param {EachActiveSoundCallback} callback - Callback function. (manager: Phaser.Sound.BaseSoundManager, sound: Phaser.Sound.BaseSound, index: number, sounds: Phaser.Manager.BaseSound[]) => void * @param {*} [scope] - Callback context. */ forEachActiveSound: function (callback, scope) { var _this = this; this.sounds.forEach(function (sound, index) { if (!sound.pendingRemove) { callback.call(scope || _this, sound, index, _this.sounds); } }); }, /** * @event Phaser.Sound.BaseSoundManager#rate * @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event. * @param {number} value - An updated value of Phaser.Sound.BaseSoundManager#rate property. */ /** * Sets the global playback rate at which all the sounds will be played. * * For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed * and 2.0 doubles the audios playback speed. * * @method Phaser.Sound.BaseSoundManager#setRate * @fires Phaser.Sound.BaseSoundManager#rate * @since 3.3.0 * * @param {number} value - Global playback rate at which all the sounds will be played. * * @return {Phaser.Sound.BaseSoundManager} This Sound Manager. */ setRate: function (value) { this.rate = value; return this; }, /** * Global playback rate at which all the sounds will be played. * Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed * and 2.0 doubles the audio's playback speed. * * @name Phaser.Sound.BaseSoundManager#rate * @type {number} * @default 1 * @since 3.0.0 */ rate: { get: function () { return this._rate; }, set: function (value) { this._rate = value; this.forEachActiveSound(function (sound) { sound.calculateRate(); }); this.emit('rate', this, value); } }, /** * Sets the global detuning of all sounds in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @method Phaser.Sound.BaseSoundManager#setDetune * @fires Phaser.Sound.BaseSoundManager#detune * @since 3.3.0 * * @param {number} value - The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @return {Phaser.Sound.BaseSoundManager} This Sound Manager. */ setDetune: function (value) { this.detune = value; return this; }, /** * @event Phaser.Sound.BaseSoundManager#detune * @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event. * @param {number} value - An updated value of Phaser.Sound.BaseSoundManager#detune property. */ /** * Global detuning of all sounds in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @name Phaser.Sound.BaseSoundManager#detune * @type {number} * @default 0 * @since 3.0.0 */ detune: { get: function () { return this._detune; }, set: function (value) { this._detune = value; this.forEachActiveSound(function (sound) { sound.calculateRate(); }); this.emit('detune', this, value); } } }); module.exports = BaseSoundManager; /***/ }), /* 80 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var OS = __webpack_require__(57); /** * Determines the browser type and version running this Phaser Game instance. * These values are read-only and populated during the boot sequence of the game. * They are then referenced by internal game systems and are available for you to access * via `this.sys.game.device.browser` from within any Scene. * * @typedef {object} Phaser.Device.Browser * @since 3.0.0 * * @property {boolean} chrome - Set to true if running in Chrome. * @property {boolean} edge - Set to true if running in Microsoft Edge browser. * @property {boolean} firefox - Set to true if running in Firefox. * @property {boolean} ie - Set to true if running in Internet Explorer 11 or less (not Edge). * @property {boolean} mobileSafari - Set to true if running in Mobile Safari. * @property {boolean} opera - Set to true if running in Opera. * @property {boolean} safari - Set to true if running in Safari. * @property {boolean} silk - Set to true if running in the Silk browser (as used on the Amazon Kindle) * @property {boolean} trident - Set to true if running a Trident version of Internet Explorer (IE11+) * @property {number} chromeVersion - If running in Chrome this will contain the major version number. * @property {number} firefoxVersion - If running in Firefox this will contain the major version number. * @property {number} ieVersion - If running in Internet Explorer this will contain the major version number. Beyond IE10 you should use Browser.trident and Browser.tridentVersion. * @property {number} safariVersion - If running in Safari this will contain the major version number. * @property {number} tridentVersion - If running in Internet Explorer 11 this will contain the major version number. See {@link http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx} */ var Browser = { chrome: false, chromeVersion: 0, edge: false, firefox: false, firefoxVersion: 0, ie: false, ieVersion: 0, mobileSafari: false, opera: false, safari: false, safariVersion: 0, silk: false, trident: false, tridentVersion: 0 }; function init () { var ua = navigator.userAgent; if (/Edge\/\d+/.test(ua)) { Browser.edge = true; } else if ((/Chrome\/(\d+)/).test(ua) && !OS.windowsPhone) { Browser.chrome = true; Browser.chromeVersion = parseInt(RegExp.$1, 10); } else if ((/Firefox\D+(\d+)/).test(ua)) { Browser.firefox = true; Browser.firefoxVersion = parseInt(RegExp.$1, 10); } else if ((/AppleWebKit/).test(ua) && OS.iOS) { Browser.mobileSafari = true; } else if ((/MSIE (\d+\.\d+);/).test(ua)) { Browser.ie = true; Browser.ieVersion = parseInt(RegExp.$1, 10); } else if ((/Opera/).test(ua)) { Browser.opera = true; } else if ((/Safari/).test(ua) && !OS.windowsPhone) { Browser.safari = true; } else if ((/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/).test(ua)) { Browser.ie = true; Browser.trident = true; Browser.tridentVersion = parseInt(RegExp.$1, 10); Browser.ieVersion = parseInt(RegExp.$3, 10); } // Silk gets its own if clause because its ua also contains 'Safari' if ((/Silk/).test(ua)) { Browser.silk = true; } return Browser; } module.exports = init(); /***/ }), /* 81 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @callback DataEachCallback * * @param {*} parent - The parent object of the DataManager. * @param {string} key - The key of the value. * @param {*} value - The value. * @param {...*} [args] - Additional arguments that will be passed to the callback, after the game object, key, and data. */ /** * @classdesc * The Data Component features a means to store pieces of data specific to a Game Object, System or Plugin. * You can then search, query it, and retrieve the data. The parent must either extend EventEmitter, * or have a property called `events` that is an instance of it. * * @class DataManager * @memberOf Phaser.Data * @constructor * @since 3.0.0 * * @param {object} parent - The object that this DataManager belongs to. * @param {Phaser.Events.EventEmitter} eventEmitter - The DataManager's event emitter. */ var DataManager = new Class({ initialize: function DataManager (parent, eventEmitter) { /** * The object that this DataManager belongs to. * * @name Phaser.Data.DataManager#parent * @type {*} * @since 3.0.0 */ this.parent = parent; /** * The DataManager's event emitter. * * @name Phaser.Data.DataManager#events * @type {Phaser.Events.EventEmitter} * @since 3.0.0 */ this.events = eventEmitter; if (!eventEmitter) { this.events = (parent.events) ? parent.events : parent; } /** * The data list. * * @name Phaser.Data.DataManager#list * @type {Object.} * @default {} * @since 3.0.0 */ this.list = {}; /** * The public values list. You can use this to access anything you have stored * in this Data Manager. For example, if you set a value called `gold` you can * access it via: * * ```javascript * this.data.values.gold; * ``` * * You can also modify it directly: * * ```javascript * this.data.values.gold += 1000; * ``` * * Doing so will emit a `setdata` event from the parent of this Data Manager. * * @name Phaser.Data.DataManager#values * @type {Object.} * @default {} * @since 3.10.0 */ this.values = {}; /** * Whether setting data is frozen for this DataManager. * * @name Phaser.Data.DataManager#_frozen * @type {boolean} * @private * @default false * @since 3.0.0 */ this._frozen = false; if (!parent.hasOwnProperty('sys') && this.events) { this.events.once('destroy', this.destroy, this); } }, /** * Retrieves the value for the given key, or undefined if it doesn't exist. * * You can also access values via the `values` object. For example, if you had a key called `gold` you can do either: * * ```javascript * this.data.get('gold'); * ``` * * Or access the value directly: * * ```javascript * this.data.values.gold; * ``` * * You can also pass in an array of keys, in which case an array of values will be returned: * * ```javascript * this.data.get([ 'gold', 'armor', 'health' ]); * ``` * * This approach is useful for destructuring arrays in ES6. * * @method Phaser.Data.DataManager#get * @since 3.0.0 * * @param {(string|string[])} key - The key of the value to retrieve, or an array of keys. * * @return {*} The value belonging to the given key, or an array of values, the order of which will match the input array. */ get: function (key) { var list = this.list; if (Array.isArray(key)) { var output = []; for (var i = 0; i < key.length; i++) { output.push(list[key[i]]); } return output; } else { return list[key]; } }, /** * Retrieves all data values in a new object. * * @method Phaser.Data.DataManager#getAll * @since 3.0.0 * * @return {Object.} All data values. */ getAll: function () { var results = {}; for (var key in this.list) { if (this.list.hasOwnProperty(key)) { results[key] = this.list[key]; } } return results; }, /** * Queries the DataManager for the values of keys matching the given regular expression. * * @method Phaser.Data.DataManager#query * @since 3.0.0 * * @param {RegExp} search - A regular expression object. If a non-RegExp object obj is passed, it is implicitly converted to a RegExp by using new RegExp(obj). * * @return {Object.} The values of the keys matching the search string. */ query: function (search) { var results = {}; for (var key in this.list) { if (this.list.hasOwnProperty(key) && key.match(search)) { results[key] = this.list[key]; } } return results; }, /** * Sets a value for the given key. If the key doesn't already exist in the Data Manager then it is created. * * ```javascript * data.set('name', 'Red Gem Stone'); * ``` * * You can also pass in an object of key value pairs as the first argument: * * ```javascript * data.set({ name: 'Red Gem Stone', level: 2, owner: 'Link', gold: 50 }); * ``` * * To get a value back again you can call `get`: * * ```javascript * data.get('gold'); * ``` * * Or you can access the value directly via the `values` property, where it works like any other variable: * * ```javascript * data.values.gold += 50; * ``` * * When the value is first set, a `setdata` event is emitted. * * If the key already exists, a `changedata` event is emitted instead, along an event named after the key. * For example, if you updated an existing key called `PlayerLives` then it would emit the event `changedata_PlayerLives`. * These events will be emitted regardless if you use this method to set the value, or the direct `values` setter. * * Please note that the data keys are case-sensitive and must be valid JavaScript Object property strings. * This means the keys `gold` and `Gold` are treated as two unique values within the Data Manager. * * @method Phaser.Data.DataManager#set * @since 3.0.0 * * @param {(string|object)} key - The key to set the value for. Or an object or key value pairs. If an object the `data` argument is ignored. * @param {*} data - The value to set for the given key. If an object is provided as the key this argument is ignored. * * @return {Phaser.Data.DataManager} This DataManager object. */ set: function (key, data) { if (this._frozen) { return this; } if (typeof key === 'string') { return this.setValue(key, data); } else { for (var entry in key) { this.setValue(entry, key[entry]); } } return this; }, /** * Internal value setter, called automatically by the `set` method. * * @method Phaser.Data.DataManager#setValue * @private * @since 3.10.0 * * @param {string} key - The key to set the value for. * @param {*} data - The value to set. * * @return {Phaser.Data.DataManager} This DataManager object. */ setValue: function (key, data) { if (this._frozen) { return this; } if (this.has(key)) { // Hit the key getter, which will in turn emit the events. this.values[key] = data; } else { var _this = this; var list = this.list; var events = this.events; var parent = this.parent; Object.defineProperty(this.values, key, { enumerable: true, get: function () { return list[key]; }, set: function (value) { if (!_this._frozen) { list[key] = value; events.emit('changedata', parent, key, data); events.emit('changedata_' + key, parent, data); } } }); list[key] = data; events.emit('setdata', parent, key, data); } return this; }, /** * Passes all data entries to the given callback. * * @method Phaser.Data.DataManager#each * @since 3.0.0 * * @param {DataEachCallback} callback - The function to call. * @param {*} [context] - Value to use as `this` when executing callback. * @param {...*} [args] - Additional arguments that will be passed to the callback, after the game object, key, and data. * * @return {Phaser.Data.DataManager} This DataManager object. */ each: function (callback, context) { var args = [ this.parent, null, undefined ]; for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); } for (var key in this.list) { args[1] = key; args[2] = this.list[key]; callback.apply(context, args); } return this; }, /** * Merge the given object of key value pairs into this DataManager. * * Any newly created values will emit a `setdata` event. Any updated values (see the `overwrite` argument) * will emit a `changedata` event. * * @method Phaser.Data.DataManager#merge * @since 3.0.0 * * @param {Object.} data - The data to merge. * @param {boolean} [overwrite=true] - Whether to overwrite existing data. Defaults to true. * * @return {Phaser.Data.DataManager} This DataManager object. */ merge: function (data, overwrite) { if (overwrite === undefined) { overwrite = true; } // Merge data from another component into this one for (var key in data) { if (data.hasOwnProperty(key) && (overwrite || (!overwrite && !this.has(key)))) { this.setValue(key, data[key]); } } return this; }, /** * Remove the value for the given key. * * If the key is found in this Data Manager it is removed from the internal lists and a * `removedata` event is emitted. * * You can also pass in an array of keys, in which case all keys in the array will be removed: * * ```javascript * this.data.remove([ 'gold', 'armor', 'health' ]); * ``` * * @method Phaser.Data.DataManager#remove * @since 3.0.0 * * @param {(string|string[])} key - The key to remove, or an array of keys to remove. * * @return {Phaser.Data.DataManager} This DataManager object. */ remove: function (key) { if (this._frozen) { return this; } if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { this.removeValue(key[i]); } } else { return this.removeValue(key); } return this; }, /** * Internal value remover, called automatically by the `remove` method. * * @method Phaser.Data.DataManager#removeValue * @private * @since 3.10.0 * * @param {string} key - The key to set the value for. * * @return {Phaser.Data.DataManager} This DataManager object. */ removeValue: function (key) { if (this.has(key)) { var data = this.list[key]; delete this.list[key]; delete this.values[key]; this.events.emit('removedata', this, key, data); } return this; }, /** * Retrieves the data associated with the given 'key', deletes it from this Data Manager, then returns it. * * @method Phaser.Data.DataManager#pop * @since 3.0.0 * * @param {string} key - The key of the value to retrieve and delete. * * @return {*} The value of the given key. */ pop: function (key) { var data = undefined; if (!this._frozen && this.has(key)) { data = this.list[key]; delete this.list[key]; delete this.values[key]; this.events.emit('removedata', this, key, data); } return data; }, /** * Determines whether the given key is set in this Data Manager. * * Please note that the keys are case-sensitive and must be valid JavaScript Object property strings. * This means the keys `gold` and `Gold` are treated as two unique values within the Data Manager. * * @method Phaser.Data.DataManager#has * @since 3.0.0 * * @param {string} key - The key to check. * * @return {boolean} Returns `true` if the key exists, otherwise `false`. */ has: function (key) { return this.list.hasOwnProperty(key); }, /** * Freeze or unfreeze this Data Manager. A frozen Data Manager will block all attempts * to create new values or update existing ones. * * @method Phaser.Data.DataManager#setFreeze * @since 3.0.0 * * @param {boolean} value - Whether to freeze or unfreeze the Data Manager. * * @return {Phaser.Data.DataManager} This DataManager object. */ setFreeze: function (value) { this._frozen = value; return this; }, /** * Delete all data in this Data Manager and unfreeze it. * * @method Phaser.Data.DataManager#reset * @since 3.0.0 * * @return {Phaser.Data.DataManager} This DataManager object. */ reset: function () { for (var key in this.list) { delete this.list[key]; delete this.values[key]; } this._frozen = false; return this; }, /** * Destroy this data manager. * * @method Phaser.Data.DataManager#destroy * @since 3.0.0 */ destroy: function () { this.reset(); this.events.off('changedata'); this.events.off('setdata'); this.events.off('removedata'); this.parent = null; }, /** * Gets or sets the frozen state of this Data Manager. * A frozen Data Manager will block all attempts to create new values or update existing ones. * * @name Phaser.Data.DataManager#freeze * @type {boolean} * @since 3.0.0 */ freeze: { get: function () { return this._frozen; }, set: function (value) { this._frozen = (value) ? true : false; } }, /** * Return the total number of entries in this Data Manager. * * @name Phaser.Data.DataManager#count * @type {integer} * @since 3.0.0 */ count: { get: function () { var i = 0; for (var key in this.list) { if (this.list[key] !== undefined) { i++; } } return i; } } }); module.exports = DataManager; /***/ }), /* 82 */, /* 83 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ //! stable.js 0.1.6, https://github.com/Two-Screen/stable //! © 2017 Angry Bytes and contributors. MIT licensed. (function() { // A stable array sort, because `Array#sort()` is not guaranteed stable. // This is an implementation of merge sort, without recursion. var stable = function(arr, comp) { return exec(arr.slice(), comp); }; stable.inplace = function(arr, comp) { var result = exec(arr, comp); // This simply copies back if the result isn't in the original array, // which happens on an odd number of passes. if (result !== arr) { pass(result, null, arr.length, arr); } return arr; }; // Execute the sort using the input array and a second buffer as work space. // Returns one of those two, containing the final result. function exec(arr, comp) { if (typeof(comp) !== 'function') { comp = function(a, b) { return String(a).localeCompare(b); }; } // Short-circuit when there's nothing to sort. var len = arr.length; if (len <= 1) { return arr; } // Rather than dividing input, simply iterate chunks of 1, 2, 4, 8, etc. // Chunks are the size of the left or right hand in merge sort. // Stop when the left-hand covers all of the array. var buffer = new Array(len); for (var chk = 1; chk < len; chk *= 2) { pass(arr, comp, chk, buffer); var tmp = arr; arr = buffer; buffer = tmp; } return arr; } // Run a single pass with the given chunk size. var pass = function(arr, comp, chk, result) { var len = arr.length; var i = 0; // Step size / double chunk size. var dbl = chk * 2; // Bounds of the left and right chunks. var l, r, e; // Iterators over the left and right chunk. var li, ri; // Iterate over pairs of chunks. for (l = 0; l < len; l += dbl) { r = l + chk; e = r + chk; if (r > len) r = len; if (e > len) e = len; // Iterate both chunks in parallel. li = l; ri = r; while (true) { // Compare the chunks. if (li < r && ri < e) { // This works for a regular `sort()` compatible comparator, // but also for a simple comparator like: `a > b` if (comp(arr[li], arr[ri]) <= 0) { result[i++] = arr[li++]; } else { result[i++] = arr[ri++]; } } // Nothing to compare, just flush what's left. else if (li < r) { result[i++] = arr[li++]; } else if (ri < e) { result[i++] = arr[ri++]; } // Both iterators are at the chunk ends. else { break; } } } }; // Export using CommonJS or to the window. if (true) { module.exports = stable; } else {} })(); /***/ }), /* 84 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Felipe Alfonso <@bitnenfer> * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Utils = __webpack_require__(27); /** * @classdesc * WebGLPipeline is a class that describes the way elements will be rendererd * in WebGL, specially focused on batching vertices (batching is not provided). * Pipelines are mostly used for describing 2D rendering passes but it's * flexible enough to be used for any type of rendering including 3D. * Internally WebGLPipeline will handle things like compiling shaders, * creating vertex buffers, assigning primitive topology and binding * vertex attributes. * * The config properties are: * - game: Current game instance. * - renderer: Current WebGL renderer. * - gl: Current WebGL context. * - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES. * Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants). * - vertShader: Source for vertex shader as a string. * - fragShader: Source for fragment shader as a string. * - vertexCapacity: The amount of vertices that shall be allocated * - vertexSize: The size of a single vertex in bytes. * - vertices: An optional buffer of vertices * - attributes: An array describing the vertex attributes * * The vertex attributes properties are: * - name : String - Name of the attribute in the vertex shader * - size : integer - How many components describe the attribute. For ex: vec3 = size of 3, float = size of 1 * - type : GLenum - WebGL type (gl.BYTE, gl.SHORT, gl.UNSIGNED_BYTE, gl.UNSIGNED_SHORT, gl.FLOAT) * - normalized : boolean - Is the attribute normalized * - offset : integer - The offset in bytes to the current attribute in the vertex. Equivalent to offsetof(vertex, attrib) in C * Here you can find more information of how to describe an attribute: * - https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer * * @class WebGLPipeline * @memberOf Phaser.Renderer.WebGL * @constructor * @since 3.0.0 * * @param {object} config - [description] */ var WebGLPipeline = new Class({ initialize: function WebGLPipeline (config) { /** * Name of the Pipeline. Used for identifying * * @name Phaser.Renderer.WebGL.WebGLPipeline#name * @type {string} * @since 3.0.0 */ this.name = 'WebGLPipeline'; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLPipeline#game * @type {Phaser.Game} * @since 3.0.0 */ this.game = config.game; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLPipeline#view * @type {HTMLCanvasElement} * @since 3.0.0 */ this.view = config.game.canvas; /** * Used to store the current game resolution * * @name Phaser.Renderer.WebGL.WebGLPipeline#resolution * @type {number} * @since 3.0.0 */ this.resolution = config.game.config.resolution; /** * Width of the current viewport * * @name Phaser.Renderer.WebGL.WebGLPipeline#width * @type {number} * @since 3.0.0 */ this.width = config.game.config.width * this.resolution; /** * Height of the current viewport * * @name Phaser.Renderer.WebGL.WebGLPipeline#height * @type {number} * @since 3.0.0 */ this.height = config.game.config.height * this.resolution; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLPipeline#gl * @type {WebGLRenderingContext} * @since 3.0.0 */ this.gl = config.gl; /** * How many vertices have been fed to the current pipeline. * * @name Phaser.Renderer.WebGL.WebGLPipeline#vertexCount * @type {number} * @default 0 * @since 3.0.0 */ this.vertexCount = 0; /** * The limit of vertices that the pipeline can hold * * @name Phaser.Renderer.WebGL.WebGLPipeline#vertexCapacity * @type {integer} * @since 3.0.0 */ this.vertexCapacity = config.vertexCapacity; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLPipeline#renderer * @type {Phaser.Renderer.WebGL.WebGLRenderer} * @since 3.0.0 */ this.renderer = config.renderer; /** * Raw byte buffer of vertices. * * @name Phaser.Renderer.WebGL.WebGLPipeline#vertexData * @type {ArrayBuffer} * @since 3.0.0 */ this.vertexData = (config.vertices ? config.vertices : new ArrayBuffer(config.vertexCapacity * config.vertexSize)); /** * The handle to a WebGL vertex buffer object. * * @name Phaser.Renderer.WebGL.WebGLPipeline#vertexBuffer * @type {WebGLBuffer} * @since 3.0.0 */ this.vertexBuffer = this.renderer.createVertexBuffer((config.vertices ? config.vertices : this.vertexData.byteLength), this.gl.STREAM_DRAW); /** * The handle to a WebGL program * * @name Phaser.Renderer.WebGL.WebGLPipeline#program * @type {WebGLProgram} * @since 3.0.0 */ this.program = this.renderer.createProgram(config.vertShader, config.fragShader); /** * Array of objects that describe the vertex attributes * * @name Phaser.Renderer.WebGL.WebGLPipeline#attributes * @type {object} * @since 3.0.0 */ this.attributes = config.attributes; /** * The size in bytes of the vertex * * @name Phaser.Renderer.WebGL.WebGLPipeline#vertexSize * @type {integer} * @since 3.0.0 */ this.vertexSize = config.vertexSize; /** * The primitive topology which the pipeline will use to submit draw calls * * @name Phaser.Renderer.WebGL.WebGLPipeline#topology * @type {integer} * @since 3.0.0 */ this.topology = config.topology; /** * Uint8 view to the vertex raw buffer. Used for uploading vertex buffer resources * to the GPU. * * @name Phaser.Renderer.WebGL.WebGLPipeline#bytes * @type {Uint8Array} * @since 3.0.0 */ this.bytes = new Uint8Array(this.vertexData); /** * This will store the amount of components of 32 bit length * * @name Phaser.Renderer.WebGL.WebGLPipeline#vertexComponentCount * @type {integer} * @since 3.0.0 */ this.vertexComponentCount = Utils.getComponentCount(config.attributes, this.gl); /** * Indicates if the current pipeline is flushing the contents to the GPU. * When the variable is set the flush function will be locked. * * @name Phaser.Renderer.WebGL.WebGLPipeline#flushLocked * @type {boolean} * @since 3.1.0 */ this.flushLocked = false; /** * Indicates if the current pipeline is active or not for this frame only. * Reset in the onRender method. * * @name Phaser.Renderer.WebGL.WebGLPipeline#active * @type {boolean} * @since 3.10.0 */ this.active = false; }, /** * Adds a description of vertex attribute to the pipeline * * @method Phaser.Renderer.WebGL.WebGLPipeline#addAttribute * @since 3.2.0 * * @param {string} name - Name of the vertex attribute * @param {integer} size - Vertex component size * @param {integer} type - Type of the attribute * @param {boolean} normalized - Is the value normalized to a range * @param {integer} offset - Byte offset to the beginning of the first element in the vertex * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ addAttribute: function (name, size, type, normalized, offset) { this.attributes.push({ name: name, size: size, type: this.renderer.glFormats[type], normalized: normalized, offset: offset }); return this; }, /** * Check if the current batch of vertices is full. * * @method Phaser.Renderer.WebGL.WebGLPipeline#shouldFlush * @since 3.0.0 * * @return {boolean} [description] */ shouldFlush: function () { return (this.vertexCount >= this.vertexCapacity); }, /** * Resizes the properties used to describe the viewport * * @method Phaser.Renderer.WebGL.WebGLPipeline#resize * @since 3.0.0 * * @param {number} width - [description] * @param {number} height - [description] * @param {number} resolution - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ resize: function (width, height, resolution) { this.width = width * resolution; this.height = height * resolution; return this; }, /** * Binds the pipeline resources, including programs, vertex buffers and binds attributes * * @method Phaser.Renderer.WebGL.WebGLPipeline#bind * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ bind: function () { var gl = this.gl; var vertexBuffer = this.vertexBuffer; var attributes = this.attributes; var program = this.program; var renderer = this.renderer; var vertexSize = this.vertexSize; renderer.setProgram(program); renderer.setVertexBuffer(vertexBuffer); for (var index = 0; index < attributes.length; ++index) { var element = attributes[index]; var location = gl.getAttribLocation(program, element.name); if (location >= 0) { gl.enableVertexAttribArray(location); gl.vertexAttribPointer(location, element.size, element.type, element.normalized, vertexSize, element.offset); } else { gl.disableVertexAttribArray(location); } } return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLPipeline#onBind * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ onBind: function () { // This is for updating uniform data it's called on each bind attempt. return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLPipeline#onPreRender * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ onPreRender: function () { // called once every frame return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLPipeline#onRender * @since 3.0.0 * * @param {Phaser.Scene} scene - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ onRender: function () { // called for each camera return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLPipeline#onPostRender * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ onPostRender: function () { // called once every frame return this; }, /** * Uploads the vertex data and emits a draw call * for the current batch of vertices. * * @method Phaser.Renderer.WebGL.WebGLPipeline#flush * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ flush: function () { if (this.flushLocked) { return this; } this.flushLocked = true; var gl = this.gl; var vertexCount = this.vertexCount; var topology = this.topology; var vertexSize = this.vertexSize; if (vertexCount === 0) { this.flushLocked = false; return; } gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.bytes.subarray(0, vertexCount * vertexSize)); gl.drawArrays(topology, 0, vertexCount); this.vertexCount = 0; this.flushLocked = false; return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLPipeline#destroy * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ destroy: function () { var gl = this.gl; gl.deleteProgram(this.program); gl.deleteBuffer(this.vertexBuffer); delete this.program; delete this.vertexBuffer; delete this.gl; return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat1 * @since 3.2.0 * * @param {string} name - [description] * @param {float} x - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setFloat1: function (name, x) { this.renderer.setFloat1(this.program, name, x); return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat2 * @since 3.2.0 * * @param {string} name - [description] * @param {float} x - [description] * @param {float} y - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setFloat2: function (name, x, y) { this.renderer.setFloat2(this.program, name, x, y); return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat3 * @since 3.2.0 * * @param {string} name - [description] * @param {float} x - [description] * @param {float} y - [description] * @param {float} z - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setFloat3: function (name, x, y, z) { this.renderer.setFloat3(this.program, name, x, y, z); return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat4 * @since 3.2.0 * * @param {string} name - Name of the uniform * @param {float} x - X component of the uniform * @param {float} y - Y component of the uniform * @param {float} z - Z component of the uniform * @param {float} w - W component of the uniform * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setFloat4: function (name, x, y, z, w) { this.renderer.setFloat4(this.program, name, x, y, z, w); return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setInt1 * @since 3.2.0 * * @param {string} name - [description] * @param {integer} x - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setInt1: function (name, x) { this.renderer.setInt1(this.program, name, x); return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setInt2 * @since 3.2.0 * * @param {string} name - [description] * @param {integer} x - [description] * @param {integer} y - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setInt2: function (name, x, y) { this.renderer.setInt2(this.program, name, x, y); return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setInt3 * @since 3.2.0 * * @param {string} name - [description] * @param {integer} x - [description] * @param {integer} y - [description] * @param {integer} z - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setInt3: function (name, x, y, z) { this.renderer.setInt3(this.program, name, x, y, z); return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setInt4 * @since 3.2.0 * * @param {string} name - Name of the uniform * @param {integer} x - X component of the uniform * @param {integer} y - Y component of the uniform * @param {integer} z - Z component of the uniform * @param {integer} w - W component of the uniform * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setInt4: function (name, x, y, z, w) { this.renderer.setInt4(this.program, name, x, y, z, w); return this; }, /** * Set a uniform value of the current pipeline program. * [description] * * @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix2 * @since 3.2.0 * * @param {string} name - [description] * @param {boolean} transpose - [description] * @param {Float32Array} matrix - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setMatrix2: function (name, transpose, matrix) { this.renderer.setMatrix2(this.program, name, transpose, matrix); return this; }, /** * Set a uniform value of the current pipeline program. * [description] * [description] * * @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix3 * @since 3.2.0 * * @param {string} name - [description] * @param {boolean} transpose - [description] * @param {Float32Array} matrix - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setMatrix3: function (name, transpose, matrix) { this.renderer.setMatrix3(this.program, name, transpose, matrix); return this; }, /** * Set a uniform value of the current pipeline program. * * @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix4 * @since 3.2.0 * * @param {string} name - Name of the uniform * @param {boolean} transpose - Should the matrix be transpose * @param {Float32Array} matrix - Matrix data * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setMatrix4: function (name, transpose, matrix) { this.renderer.setMatrix4(this.program, name, transpose, matrix); return this; } }); module.exports = WebGLPipeline; /***/ }), /* 85 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Checks if the given `width` and `height` are a power of two. * Useful for checking texture dimensions. * * @function Phaser.Math.Pow2.IsSizePowerOfTwo * @since 3.0.0 * * @param {number} width - The width. * @param {number} height - The height. * * @return {boolean} `true` if `width` and `height` are a power of two, otherwise `false`. */ var IsSizePowerOfTwo = function (width, height) { return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0); }; module.exports = IsSizePowerOfTwo; /***/ }), /* 86 */, /* 87 */, /* 88 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Contains = __webpack_require__(32); var GetPoint = __webpack_require__(298); var GetPoints = __webpack_require__(296); var Random = __webpack_require__(157); /** * @classdesc * A Circle object. * * This is a geometry object, containing numerical values and related methods to inspect and modify them. * It is not a Game Object, in that you cannot add it to the display list, and it has no texture. * To render a Circle you should look at the capabilities of the Graphics class. * * @class Circle * @memberOf Phaser.Geom * @constructor * @since 3.0.0 * * @param {number} [x=0] - The x position of the center of the circle. * @param {number} [y=0] - The y position of the center of the circle. * @param {number} [radius=0] - The radius of the circle. */ var Circle = new Class({ initialize: function Circle (x, y, radius) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (radius === undefined) { radius = 0; } /** * The x position of the center of the circle. * * @name Phaser.Geom.Circle#x * @type {number} * @default 0 * @since 3.0.0 */ this.x = x; /** * The y position of the center of the circle. * * @name Phaser.Geom.Circle#y * @type {number} * @default 0 * @since 3.0.0 */ this.y = y; /** * The internal radius of the circle. * * @name Phaser.Geom.Circle#_radius * @type {number} * @private * @since 3.0.0 */ this._radius = radius; /** * The internal diameter of the circle. * * @name Phaser.Geom.Circle#_diameter * @type {number} * @private * @since 3.0.0 */ this._diameter = radius * 2; }, /** * Check to see if the Circle contains the given x / y coordinates. * * @method Phaser.Geom.Circle#contains * @since 3.0.0 * * @param {number} x - The x coordinate to check within the circle. * @param {number} y - The y coordinate to check within the circle. * * @return {boolean} True if the coordinates are within the circle, otherwise false. */ contains: function (x, y) { return Contains(this, x, y); }, /** * Returns a Point object containing the coordinates of a point on the circumference of the Circle * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point * at 180 degrees around the circle. * * @method Phaser.Geom.Circle#getPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {float} position - A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle. * @param {(Phaser.Geom.Point|object)} [out] - An object to store the return values in. If not given a Point object will be created. * * @return {(Phaser.Geom.Point|object)} A Point, or point-like object, containing the coordinates of the point around the circle. */ getPoint: function (position, point) { return GetPoint(this, position, point); }, /** * Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, * based on the given quantity or stepRate values. * * @method Phaser.Geom.Circle#getPoints * @since 3.0.0 * * @generic {Phaser.Geom.Point[]} O - [output,$return] * * @param {integer} quantity - The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. * @param {number} [stepRate] - Sets the quantity by getting the circumference of the circle and dividing it by the stepRate. * @param {(array|Phaser.Geom.Point[])} [output] - An array to insert the points in to. If not provided a new array will be created. * * @return {(array|Phaser.Geom.Point[])} An array of Point objects pertaining to the points around the circumference of the circle. */ getPoints: function (quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); }, /** * Returns a uniformly distributed random point from anywhere within the Circle. * * @method Phaser.Geom.Circle#getRandomPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [point,$return] * * @param {(Phaser.Geom.Point|object)} [point] - A Point or point-like object to set the random `x` and `y` values in. * * @return {(Phaser.Geom.Point|object)} A Point object with the random values set in the `x` and `y` properties. */ getRandomPoint: function (point) { return Random(this, point); }, /** * Sets the x, y and radius of this circle. * * @method Phaser.Geom.Circle#setTo * @since 3.0.0 * * @param {number} [x=0] - The x position of the center of the circle. * @param {number} [y=0] - The y position of the center of the circle. * @param {number} [radius=0] - The radius of the circle. * * @return {Phaser.Geom.Circle} This Circle object. */ setTo: function (x, y, radius) { this.x = x; this.y = y; this._radius = radius; this._diameter = radius * 2; return this; }, /** * Sets this Circle to be empty with a radius of zero. * Does not change its position. * * @method Phaser.Geom.Circle#setEmpty * @since 3.0.0 * * @return {Phaser.Geom.Circle} This Circle object. */ setEmpty: function () { this._radius = 0; this._diameter = 0; return this; }, /** * Sets the position of this Circle. * * @method Phaser.Geom.Circle#setPosition * @since 3.0.0 * * @param {number} [x=0] - The x position of the center of the circle. * @param {number} [y=0] - The y position of the center of the circle. * * @return {Phaser.Geom.Circle} This Circle object. */ setPosition: function (x, y) { if (y === undefined) { y = x; } this.x = x; this.y = y; return this; }, /** * Checks to see if the Circle is empty: has a radius of zero. * * @method Phaser.Geom.Circle#isEmpty * @since 3.0.0 * * @return {boolean} True if the Circle is empty, otherwise false. */ isEmpty: function () { return (this._radius <= 0); }, /** * The radius of the Circle. * * @name Phaser.Geom.Circle#radius * @type {number} * @since 3.0.0 */ radius: { get: function () { return this._radius; }, set: function (value) { this._radius = value; this._diameter = value * 2; } }, /** * The diameter of the Circle. * * @name Phaser.Geom.Circle#diameter * @type {number} * @since 3.0.0 */ diameter: { get: function () { return this._diameter; }, set: function (value) { this._diameter = value; this._radius = value * 0.5; } }, /** * The left position of the Circle. * * @name Phaser.Geom.Circle#left * @type {number} * @since 3.0.0 */ left: { get: function () { return this.x - this._radius; }, set: function (value) { this.x = value + this._radius; } }, /** * The right position of the Circle. * * @name Phaser.Geom.Circle#right * @type {number} * @since 3.0.0 */ right: { get: function () { return this.x + this._radius; }, set: function (value) { this.x = value - this._radius; } }, /** * The top position of the Circle. * * @name Phaser.Geom.Circle#top * @type {number} * @since 3.0.0 */ top: { get: function () { return this.y - this._radius; }, set: function (value) { this.y = value + this._radius; } }, /** * The bottom position of the Circle. * * @name Phaser.Geom.Circle#bottom * @type {number} * @since 3.0.0 */ bottom: { get: function () { return this.y + this._radius; }, set: function (value) { this.y = value - this._radius; } } }); module.exports = Circle; /***/ }), /* 89 */, /* 90 */, /* 91 */, /* 92 */, /* 93 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var ArrayUtils = __webpack_require__(147); var Class = __webpack_require__(0); var NOOP = __webpack_require__(3); var StableSort = __webpack_require__(83); /** * @callback EachListCallback * @generic I - [item] * * @param {*} item - [description] * @param {...*} [args] - Additional arguments that will be passed to the callback, after the child. */ /** * @classdesc * [description] * * @class List * @memberOf Phaser.Structs * @constructor * @since 3.0.0 * * @generic T * * @param {*} parent - [description] */ var List = new Class({ initialize: function List (parent) { /** * The parent of this list. * * @name Phaser.Structs.List#parent * @type {*} * @since 3.0.0 */ this.parent = parent; /** * The objects that belong to this collection. * * @genericUse {T[]} - [$type] * * @name Phaser.Structs.List#list * @type {Array.<*>} * @default [] * @since 3.0.0 */ this.list = []; /** * [description] * * @name Phaser.Structs.List#position * @type {integer} * @default 0 * @since 3.0.0 */ this.position = 0; /** * A callback that is invoked every time a child is added to this list. * * @name Phaser.Structs.List#addCallback * @type {function} * @since 3.4.0 */ this.addCallback = NOOP; /** * A callback that is invoked every time a child is removed from this list. * * @name Phaser.Structs.List#removeCallback * @type {function} * @since 3.4.0 */ this.removeCallback = NOOP; /** * The property key to sort by. * * @name Phaser.Structs.List#_sortKey * @type {string} * @since 3.4.0 */ this._sortKey = ''; }, /** * [description] * * @method Phaser.Structs.List#add * @since 3.0.0 * * @genericUse {T} - [child,$return] * * @param {*|Array.<*>} child - [description] * @param {boolean} [skipCallback=false] - Skip calling the List.addCallback if this child is added successfully. * * @return {*} [description] */ add: function (child, skipCallback) { if (skipCallback) { return ArrayUtils.Add(this.list, child); } else { return ArrayUtils.Add(this.list, child, 0, this.addCallback, this); } }, /** * [description] * * @method Phaser.Structs.List#addAt * @since 3.0.0 * * @genericUse {T} - [child,$return] * * @param {*} child - [description] * @param {integer} [index=0] - [description] * @param {boolean} [skipCallback=false] - Skip calling the List.addCallback if this child is added successfully. * * @return {*} [description] */ addAt: function (child, index, skipCallback) { if (skipCallback) { return ArrayUtils.AddAt(this.list, child, index); } else { return ArrayUtils.AddAt(this.list, child, index, 0, this.addCallback, this); } }, /** * [description] * * @method Phaser.Structs.List#getAt * @since 3.0.0 * * @genericUse {T} - [$return] * * @param {integer} index - [description] * * @return {*} [description] */ getAt: function (index) { return this.list[index]; }, /** * [description] * * @method Phaser.Structs.List#getIndex * @since 3.0.0 * * @genericUse {T} - [child] * * @param {*} child - [description] * * @return {integer} [description] */ getIndex: function (child) { // Return -1 if given child isn't a child of this display list return this.list.indexOf(child); }, /** * Sort the contents of this List so the items are in order based * on the given property. For example, `sort('alpha')` would sort the List * contents based on the value of their `alpha` property. * * @method Phaser.Structs.List#sort * @since 3.0.0 * * @genericUse {T[]} - [children,$return] * * @param {string} property - The property to lexically sort by. * * @return {Array.<*>} [description] */ sort: function (property) { if (property) { this._sortKey = property; StableSort.inplace(this.list, this.sortHandler); } return this; }, /** * [description] * * @method Phaser.Structs.List#sortHandler * @private * @since 3.4.0 * * @genericUse {T} - [childA,childB] * * @param {*} childA - [description] * @param {*} childB - [description] * * @return {integer} [description] */ sortHandler: function (childA, childB) { return childA[this._sortKey] - childB[this._sortKey]; }, /** * Searches for the first instance of a child with its `name` * property matching the given argument. Should more than one child have * the same name only the first is returned. * * @method Phaser.Structs.List#getByName * @since 3.0.0 * * @genericUse {T | null} - [$return] * * @param {string} name - The name to search for. * * @return {?*} The first child with a matching name, or null if none were found. */ getByName: function (name) { return ArrayUtils.GetFirst(this.list, 'name', name); }, /** * Returns a random child from the group. * * @method Phaser.Structs.List#getRandom * @since 3.0.0 * * @genericUse {T | null} - [$return] * * @param {integer} [startIndex=0] - Offset from the front of the group (lowest child). * @param {integer} [length=(to top)] - Restriction on the number of values you want to randomly select from. * * @return {?*} A random child of this Group. */ getRandom: function (startIndex, length) { return ArrayUtils.GetRandom(this.list, startIndex, length); }, /** * [description] * * @method Phaser.Structs.List#getFirst * @since 3.0.0 * * @genericUse {T} - [value] * @genericUse {T | null} - [$return] * * @param {string} property - [description] * @param {*} value - [description] * @param {number} [startIndex=0] - [description] * @param {number} [endIndex] - [description] * * @return {?*} [description] */ getFirst: function (property, value, startIndex, endIndex) { return ArrayUtils.GetFirstElement(this.list, property, value, startIndex, endIndex); }, /** * Returns all children in this List. * * You can optionally specify a matching criteria using the `property` and `value` arguments. * * For example: `getAll('parent')` would return only children that have a property called `parent`. * * You can also specify a value to compare the property to: * * `getAll('visible', true)` would return only children that have their visible property set to `true`. * * Optionally you can specify a start and end index. For example if this List had 100 children, * and you set `startIndex` to 0 and `endIndex` to 50, it would return matches from only * the first 50 children in the List. * * @method Phaser.Structs.List#getAll * @since 3.0.0 * * @genericUse {T} - [value] * @genericUse {T[]} - [$return] * * @param {string} [property] - An optional property to test against the value argument. * @param {*} [value] - If property is set then Child.property must strictly equal this value to be included in the results. * @param {integer} [startIndex] - The first child index to start the search from. * @param {integer} [endIndex] - The last child index to search up until. * * @return {Array.<*>} [description] */ getAll: function (property, value, startIndex, endIndex) { return ArrayUtils.GetAll(this.list, property, value, startIndex, endIndex); }, /** * [description] * * @method Phaser.Structs.List#count * @since 3.0.0 * * @genericUse {T} - [value] * * @param {string} property - [description] * @param {*} value - [description] * * @return {integer} [description] */ count: function (property, value) { return ArrayUtils.CountAllMatching(this.list, property, value); }, /** * [description] * * @method Phaser.Structs.List#swap * @since 3.0.0 * * @genericUse {T} - [child1,child2] * * @param {*} child1 - [description] * @param {*} child2 - [description] */ swap: function (child1, child2) { ArrayUtils.Swap(this.list, child1, child2); }, /** * [description] * * @method Phaser.Structs.List#moveTo * @since 3.0.0 * * @genericUse {T} - [child,$return] * * @param {*} child - [description] * @param {integer} index - [description] * * @return {*} [description] */ moveTo: function (child, index) { return ArrayUtils.MoveTo(this.list, child, index); }, /** * [description] * * @method Phaser.Structs.List#remove * @since 3.0.0 * * @genericUse {T} - [child,$return] * * @param {*} child - [description] * @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback. * * @return {*} [description] */ remove: function (child, skipCallback) { if (skipCallback) { return ArrayUtils.Remove(this.list, child); } else { return ArrayUtils.Remove(this.list, child, this.removeCallback, this); } }, /** * [description] * * @method Phaser.Structs.List#removeAt * @since 3.0.0 * * @genericUse {T} - [$return] * * @param {integer} index - [description] * @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback. * * @return {*} [description] */ removeAt: function (index, skipCallback) { if (skipCallback) { return ArrayUtils.RemoveAt(this.list, index); } else { return ArrayUtils.RemoveAt(this.list, index, this.removeCallback, this); } }, /** * [description] * * @method Phaser.Structs.List#removeBetween * @since 3.0.0 * * @genericUse {T[]} - [$return] * * @param {integer} [startIndex=0] - [description] * @param {integer} [endIndex] - [description] * @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback. * * @return {Array.<*>} [description] */ removeBetween: function (startIndex, endIndex, skipCallback) { if (skipCallback) { return ArrayUtils.RemoveBetween(this.list, startIndex, endIndex); } else { return ArrayUtils.RemoveBetween(this.list, startIndex, endIndex, this.removeCallback, this); } }, /** * Removes all the items. * * @method Phaser.Structs.List#removeAll * @since 3.0.0 * * @genericUse {Phaser.Structs.List.} - [$return] * * @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback. * * @return {Phaser.Structs.List} This List object. */ removeAll: function (skipCallback) { var i = this.list.length; while (i--) { this.remove(this.list[i], skipCallback); } return this; }, /** * Brings the given child to the top of this List. * * @method Phaser.Structs.List#bringToTop * @since 3.0.0 * * @genericUse {T} - [child,$return] * * @param {*} child - [description] * * @return {*} [description] */ bringToTop: function (child) { return ArrayUtils.BringToTop(this.list, child); }, /** * Sends the given child to the bottom of this List. * * @method Phaser.Structs.List#sendToBack * @since 3.0.0 * * @genericUse {T} - [child,$return] * * @param {*} child - [description] * * @return {*} [description] */ sendToBack: function (child) { return ArrayUtils.SendToBack(this.list, child); }, /** * Moves the given child up one place in this group unless it's already at the top. * * @method Phaser.Structs.List#moveUp * @since 3.0.0 * * @genericUse {T} - [child,$return] * * @param {*} child - [description] * * @return {*} [description] */ moveUp: function (child) { ArrayUtils.MoveUp(this.list, child); return child; }, /** * Moves the given child down one place in this group unless it's already at the bottom. * * @method Phaser.Structs.List#moveDown * @since 3.0.0 * * @genericUse {T} - [child,$return] * * @param {*} child - [description] * * @return {*} [description] */ moveDown: function (child) { ArrayUtils.MoveDown(this.list, child); return child; }, /** * Reverses the order of all children in this List. * * @method Phaser.Structs.List#reverse * @since 3.0.0 * * @genericUse {Phaser.Structs.List.} - [$return] * * @return {Phaser.Structs.List} This List object. */ reverse: function () { this.list.reverse(); return this; }, /** * [description] * * @method Phaser.Structs.List#shuffle * @since 3.0.0 * * @genericUse {Phaser.Structs.List.} - [$return] * * @return {Phaser.Structs.List} This List object. */ shuffle: function () { ArrayUtils.Shuffle(this.list); return this; }, /** * Replaces a child of this List with the given newChild. The newChild cannot be a member of this List. * * @method Phaser.Structs.List#replace * @since 3.0.0 * * @genericUse {T} - [oldChild,newChild,$return] * * @param {*} oldChild - The child in this List that will be replaced. * @param {*} newChild - The child to be inserted into this List. * * @return {*} Returns the oldChild that was replaced within this group. */ replace: function (oldChild, newChild) { return ArrayUtils.Replace(this.list, oldChild, newChild); }, /** * [description] * * @method Phaser.Structs.List#exists * @since 3.0.0 * * @genericUse {T} - [child] * * @param {*} child - [description] * * @return {boolean} True if the item is found in the list, otherwise false. */ exists: function (child) { return (this.list.indexOf(child) > -1); }, /** * Sets the property `key` to the given value on all members of this List. * * @method Phaser.Structs.List#setAll * @since 3.0.0 * * @genericUse {T} - [value] * * @param {string} property - [description] * @param {*} value - [description] * @param {integer} [startIndex] - The first child index to start the search from. * @param {integer} [endIndex] - The last child index to search up until. */ setAll: function (property, value, startIndex, endIndex) { ArrayUtils.SetAll(this.list, property, value, startIndex, endIndex); return this; }, /** * Passes all children to the given callback. * * @method Phaser.Structs.List#each * @since 3.0.0 * * @genericUse {EachListCallback.} - [callback] * * @param {EachListCallback} callback - The function to call. * @param {*} [context] - Value to use as `this` when executing callback. * @param {...*} [args] - Additional arguments that will be passed to the callback, after the child. */ each: function (callback, context) { var args = [ null ]; for (var i = 2; i < arguments.length; i++) { args.push(arguments[i]); } for (i = 0; i < this.list.length; i++) { args[0] = this.list[i]; callback.apply(context, args); } }, /** * [description] * * @method Phaser.Structs.List#shutdown * @since 3.0.0 */ shutdown: function () { this.removeAll(); this.list = []; }, /** * [description] * * @method Phaser.Structs.List#destroy * @since 3.0.0 */ destroy: function () { this.removeAll(); this.parent = null; this.addCallback = null; this.removeCallback = null; }, /** * [description] * * @name Phaser.Structs.List#length * @type {integer} * @readOnly * @since 3.0.0 */ length: { get: function () { return this.list.length; } }, /** * [description] * * @name Phaser.Structs.List#first * @type {integer} * @readOnly * @since 3.0.0 */ first: { get: function () { this.position = 0; if (this.list.length > 0) { return this.list[0]; } else { return null; } } }, /** * [description] * * @name Phaser.Structs.List#last * @type {integer} * @readOnly * @since 3.0.0 */ last: { get: function () { if (this.list.length > 0) { this.position = this.list.length - 1; return this.list[this.position]; } else { return null; } } }, /** * [description] * * @name Phaser.Structs.List#next * @type {integer} * @readOnly * @since 3.0.0 */ next: { get: function () { if (this.position < this.list.length) { this.position++; return this.list[this.position]; } else { return null; } } }, /** * [description] * * @name Phaser.Structs.List#previous * @type {integer} * @readOnly * @since 3.0.0 */ previous: { get: function () { if (this.position > 0) { this.position--; return this.list[this.position]; } else { return null; } } } }); module.exports = List; /***/ }), /* 94 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clone = __webpack_require__(33); /** * Creates a new Object using all values from obj1 and obj2. * If a value exists in both obj1 and obj2, the value in obj1 is used. * * @function Phaser.Utils.Object.Merge * @since 3.0.0 * * @param {object} obj1 - [description] * @param {object} obj2 - [description] * * @return {object} [description] */ var Merge = function (obj1, obj2) { var clone = Clone(obj1); for (var key in obj2) { if (!clone.hasOwnProperty(key)) { clone[key] = obj2[key]; } } return clone; }; module.exports = Merge; /***/ }), /* 95 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Shuffles the contents of the given array using the Fisher-Yates implementation. * * The original array is modified directly and returned. * * @function Phaser.Utils.Array.Shuffle * @since 3.0.0 * * @param {array} array - The array to shuffle. This array is modified in place. * * @return {array} The shuffled array. */ var Shuffle = function (array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }; module.exports = Shuffle; /***/ }), /* 96 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var GetPoint = __webpack_require__(293); var GetPoints = __webpack_require__(156); var Random = __webpack_require__(155); var Vector2 = __webpack_require__(6); /** * @classdesc * Defines a Line segment, a part of a line between two endpoints. * * @class Line * @memberOf Phaser.Geom * @constructor * @since 3.0.0 * * @param {number} [x1=0] - The x coordinate of the lines starting point. * @param {number} [y1=0] - The y coordinate of the lines starting point. * @param {number} [x2=0] - The x coordinate of the lines ending point. * @param {number} [y2=0] - The y coordinate of the lines ending point. */ var Line = new Class({ initialize: function Line (x1, y1, x2, y2) { if (x1 === undefined) { x1 = 0; } if (y1 === undefined) { y1 = 0; } if (x2 === undefined) { x2 = 0; } if (y2 === undefined) { y2 = 0; } /** * The x coordinate of the lines starting point. * * @name Phaser.Geom.Line#x1 * @type {number} * @since 3.0.0 */ this.x1 = x1; /** * The y coordinate of the lines starting point. * * @name Phaser.Geom.Line#y1 * @type {number} * @since 3.0.0 */ this.y1 = y1; /** * The x coordinate of the lines ending point. * * @name Phaser.Geom.Line#x2 * @type {number} * @since 3.0.0 */ this.x2 = x2; /** * The y coordinate of the lines ending point. * * @name Phaser.Geom.Line#y2 * @type {number} * @since 3.0.0 */ this.y2 = y2; }, /** * [description] * * @method Phaser.Geom.Line#getPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [output,$return] * * @param {float} position - [description] * @param {(Phaser.Geom.Point|object)} [output] - [description] * * @return {(Phaser.Geom.Point|object)} A Point, or point-like object, containing the coordinates of the point on the line. */ getPoint: function (position, output) { return GetPoint(this, position, output); }, /** * [description] * * @method Phaser.Geom.Line#getPoints * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [output,$return] * * @param {integer} quantity - [description] * @param {integer} [stepRate] - [description] * @param {(array|Phaser.Geom.Point[])} [output] - [description] * * @return {(array|Phaser.Geom.Point[])} [description] */ getPoints: function (quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); }, /** * Get a random Point on the Line. * * @method Phaser.Geom.Line#getRandomPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [point,$return] * * @param {(Phaser.Geom.Point|object)} [point] - An instance of a Point to be modified. * * @return {Phaser.Geom.Point} A random Point on the Line. */ getRandomPoint: function (point) { return Random(this, point); }, /** * Set new coordinates for the line endpoints. * * @method Phaser.Geom.Line#setTo * @since 3.0.0 * * @param {number} [x1=0] - The x coordinate of the lines starting point. * @param {number} [y1=0] - The y coordinate of the lines starting point. * @param {number} [x2=0] - The x coordinate of the lines ending point. * @param {number} [y2=0] - The y coordinate of the lines ending point. * * @return {Phaser.Geom.Line} This Line object. */ setTo: function (x1, y1, x2, y2) { if (x1 === undefined) { x1 = 0; } if (y1 === undefined) { y1 = 0; } if (x2 === undefined) { x2 = 0; } if (y2 === undefined) { y2 = 0; } this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; return this; }, /** * Returns a Vector2 object that corresponds to the start of this Line. * * @method Phaser.Geom.Line#getPointA * @since 3.0.0 * * @generic {Phaser.Math.Vector2} O - [vec2,$return] * * @param {Phaser.Math.Vector2} [vec2] - A Vector2 object to set the results in. If `undefined` a new Vector2 will be created. * * @return {Phaser.Math.Vector2} A Vector2 object that corresponds to the start of this Line. */ getPointA: function (vec2) { if (vec2 === undefined) { vec2 = new Vector2(); } vec2.set(this.x1, this.y1); return vec2; }, /** * Returns a Vector2 object that corresponds to the start of this Line. * * @method Phaser.Geom.Line#getPointB * @since 3.0.0 * * @generic {Phaser.Math.Vector2} O - [vec2,$return] * * @param {Phaser.Math.Vector2} [vec2] - A Vector2 object to set the results in. If `undefined` a new Vector2 will be created. * * @return {Phaser.Math.Vector2} A Vector2 object that corresponds to the start of this Line. */ getPointB: function (vec2) { if (vec2 === undefined) { vec2 = new Vector2(); } vec2.set(this.x2, this.y2); return vec2; }, /** * The left position of the Line. * * @name Phaser.Geom.Line#left * @type {number} * @since 3.0.0 */ left: { get: function () { return Math.min(this.x1, this.x2); }, set: function (value) { if (this.x1 <= this.x2) { this.x1 = value; } else { this.x2 = value; } } }, /** * The right position of the Line. * * @name Phaser.Geom.Line#right * @type {number} * @since 3.0.0 */ right: { get: function () { return Math.max(this.x1, this.x2); }, set: function (value) { if (this.x1 > this.x2) { this.x1 = value; } else { this.x2 = value; } } }, /** * The top position of the Line. * * @name Phaser.Geom.Line#top * @type {number} * @since 3.0.0 */ top: { get: function () { return Math.min(this.y1, this.y2); }, set: function (value) { if (this.y1 <= this.y2) { this.y1 = value; } else { this.y2 = value; } } }, /** * The bottom position of the Line. * * @name Phaser.Geom.Line#bottom * @type {number} * @since 3.0.0 */ bottom: { get: function () { return Math.max(this.y1, this.y2); }, set: function (value) { if (this.y1 > this.y2) { this.y1 = value; } else { this.y2 = value; } } } }); module.exports = Line; /***/ }), /* 97 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Geom.Rectangle.Perimeter * @since 3.0.0 * * @param {Phaser.Geom.Rectangle} rect - [description] * * @return {number} [description] */ var Perimeter = function (rect) { return 2 * (rect.width + rect.height); }; module.exports = Perimeter; /***/ }), /* 98 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @typedef {object} TweenDataGenConfig * * @property {function} delay - [description] * @property {function} duration - [description] * @property {function} hold - [description] * @property {function} repeat - [description] * @property {function} repeatDelay - [description] */ /** * @typedef {object} Phaser.Tweens.TweenDataConfig * * @property {object} target - The target to tween. * @property {string} key - The property of the target being tweened. * @property {function} getEndValue - The returned value sets what the property will be at the END of the Tween. * @property {function} getStartValue - The returned value sets what the property will be at the START of the Tween. * @property {function} ease - The ease function this tween uses. * @property {number} [duration=0] - Duration of the tween in ms/frames, excludes time for yoyo or repeats. * @property {number} [totalDuration=0] - The total calculated duration of this TweenData (based on duration, repeat, delay and yoyo) * @property {number} [delay=0] - Time in ms/frames before tween will start. * @property {boolean} [yoyo=false] - Cause the tween to return back to its start value after hold has expired. * @property {number} [hold=0] - Time in ms/frames the tween will pause before running the yoyo or starting a repeat. * @property {integer} [repeat=0] - Number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice. * @property {number} [repeatDelay=0] - Time in ms/frames before the repeat will start. * @property {boolean} [flipX=false] - Automatically call toggleFlipX when the TweenData yoyos or repeats * @property {boolean} [flipY=false] - Automatically call toggleFlipY when the TweenData yoyos or repeats * @property {float} [progress=0] - Between 0 and 1 showing completion of this TweenData. * @property {float} [elapsed=0] - Delta counter * @property {integer} [repeatCounter=0] - How many repeats are left to run? * @property {number} [start=0] - Ease value data. * @property {number} [current=0] - Ease value data. * @property {number} [end=0] - Ease value data. * @property {number} [t1=0] - Time duration 1. * @property {number} [t2=0] - Time duration 2. * @property {TweenDataGenConfig} [gen] - LoadValue generation functions. * @property {integer} [state=0] - TWEEN_CONST.CREATED */ /** * [description] * * @function Phaser.Tweens.TweenData * @since 3.0.0 * * @param {object} target - [description] * @param {string} key - [description] * @param {function} getEnd - [description] * @param {function} getStart - [description] * @param {function} ease - [description] * @param {number} delay - [description] * @param {number} duration - [description] * @param {boolean} yoyo - [description] * @param {number} hold - [description] * @param {number} repeat - [description] * @param {number} repeatDelay - [description] * @param {boolean} flipX - [description] * @param {boolean} flipY - [description] * * @return {TweenDataConfig} [description] */ var TweenData = function (target, key, getEnd, getStart, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY) { return { // The target to tween target: target, // The property of the target to tween key: key, // The returned value sets what the property will be at the END of the Tween. getEndValue: getEnd, // The returned value sets what the property will be at the START of the Tween. getStartValue: getStart, // The ease function this tween uses. ease: ease, // Duration of the tween in ms/frames, excludes time for yoyo or repeats. duration: 0, // The total calculated duration of this TweenData (based on duration, repeat, delay and yoyo) totalDuration: 0, // Time in ms/frames before tween will start. delay: 0, // Cause the tween to return back to its start value after hold has expired. yoyo: yoyo, // Time in ms/frames the tween will pause before running the yoyo or starting a repeat. hold: 0, // Number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice. repeat: 0, // Time in ms/frames before the repeat will start. repeatDelay: 0, // Automatically call toggleFlipX when the TweenData yoyos or repeats flipX: flipX, // Automatically call toggleFlipY when the TweenData yoyos or repeats flipY: flipY, // Between 0 and 1 showing completion of this TweenData. progress: 0, // Delta counter. elapsed: 0, // How many repeats are left to run? repeatCounter: 0, // Ease Value Data: start: 0, current: 0, end: 0, // Time Durations t1: 0, t2: 0, // LoadValue generation functions gen: { delay: delay, duration: duration, hold: hold, repeat: repeat, repeatDelay: repeatDelay }, // TWEEN_CONST.CREATED state: 0 }; }; module.exports = TweenData; /***/ }), /* 99 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var GameObjectCreator = __webpack_require__(13); var GameObjectFactory = __webpack_require__(11); var TWEEN_CONST = __webpack_require__(61); /** * @classdesc * [description] * * @class Tween * @memberOf Phaser.Tweens * @constructor * @since 3.0.0 * * @param {(Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline)} parent - [description] * @param {Phaser.Tweens.TweenDataConfig[]} data - [description] * @param {array} targets - [description] */ var Tween = new Class({ initialize: function Tween (parent, data, targets) { /** * [description] * * @name Phaser.Tweens.Tween#parent * @type {(Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline)} * @since 3.0.0 */ this.parent = parent; /** * Is the parent of this Tween a Timeline? * * @name Phaser.Tweens.Tween#parentIsTimeline * @type {boolean} * @since 3.0.0 */ this.parentIsTimeline = parent.hasOwnProperty('isTimeline'); /** * An array of TweenData objects, each containing a unique property and target being tweened. * * @name Phaser.Tweens.Tween#data * @type {Phaser.Tweens.TweenDataConfig[]} * @since 3.0.0 */ this.data = data; /** * data array doesn't change, so we can cache the length * * @name Phaser.Tweens.Tween#totalData * @type {integer} * @since 3.0.0 */ this.totalData = data.length; /** * An array of references to the target/s this Tween is operating on * * @name Phaser.Tweens.Tween#targets * @type {object[]} * @since 3.0.0 */ this.targets = targets; /** * Cached target total (not necessarily the same as the data total) * * @name Phaser.Tweens.Tween#totalTargets * @type {integer} * @since 3.0.0 */ this.totalTargets = targets.length; /** * If true then duration, delay, etc values are all frame totals. * * @name Phaser.Tweens.Tween#useFrames * @type {boolean} * @default false * @since 3.0.0 */ this.useFrames = false; /** * Scales the time applied to this Tween. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on. * Value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only. * * @name Phaser.Tweens.Tween#timeScale * @type {number} * @default 1 * @since 3.0.0 */ this.timeScale = 1; /** * Loop this tween? Can be -1 for an infinite loop, or an integer. * When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD) * * @name Phaser.Tweens.Tween#loop * @type {number} * @default 0 * @since 3.0.0 */ this.loop = 0; /** * Time in ms/frames before the tween loops. * * @name Phaser.Tweens.Tween#loopDelay * @type {number} * @default 0 * @since 3.0.0 */ this.loopDelay = 0; /** * How many loops are left to run? * * @name Phaser.Tweens.Tween#loopCounter * @type {number} * @default 0 * @since 3.0.0 */ this.loopCounter = 0; /** * Time in ms/frames before the 'onComplete' event fires. This never fires if loop = -1 (as it never completes) * * @name Phaser.Tweens.Tween#completeDelay * @type {number} * @default 0 * @since 3.0.0 */ this.completeDelay = 0; /** * Countdown timer (used by timeline offset, loopDelay and completeDelay) * * @name Phaser.Tweens.Tween#countdown * @type {number} * @default 0 * @since 3.0.0 */ this.countdown = 0; /** * Set only if this Tween is part of a Timeline. * * @name Phaser.Tweens.Tween#offset * @type {number} * @default 0 * @since 3.0.0 */ this.offset = 0; /** * Set only if this Tween is part of a Timeline. The calculated offset amount. * * @name Phaser.Tweens.Tween#calculatedOffset * @type {number} * @default 0 * @since 3.0.0 */ this.calculatedOffset = 0; /** * The current state of the tween * * @name Phaser.Tweens.Tween#state * @type {integer} * @since 3.0.0 */ this.state = TWEEN_CONST.PENDING_ADD; /** * The state of the tween when it was paused (used by Resume) * * @name Phaser.Tweens.Tween#_pausedState * @type {integer} * @private * @since 3.0.0 */ this._pausedState = TWEEN_CONST.PENDING_ADD; /** * Does the Tween start off paused? (if so it needs to be started with Tween.play) * * @name Phaser.Tweens.Tween#paused * @type {boolean} * @default false * @since 3.0.0 */ this.paused = false; /** * Elapsed time in ms/frames of this run through the Tween. * * @name Phaser.Tweens.Tween#elapsed * @type {number} * @default 0 * @since 3.0.0 */ this.elapsed = 0; /** * Total elapsed time in ms/frames of the entire Tween, including looping. * * @name Phaser.Tweens.Tween#totalElapsed * @type {number} * @default 0 * @since 3.0.0 */ this.totalElapsed = 0; /** * Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays. * * @name Phaser.Tweens.Tween#duration * @type {number} * @default 0 * @since 3.0.0 */ this.duration = 0; /** * Value between 0 and 1. The amount through the Tween, excluding loops. * * @name Phaser.Tweens.Tween#progress * @type {number} * @default 0 * @since 3.0.0 */ this.progress = 0; /** * Time in ms/frames for the Tween to complete (including looping) * * @name Phaser.Tweens.Tween#totalDuration * @type {number} * @default 0 * @since 3.0.0 */ this.totalDuration = 0; /** * Value between 0 and 1. The amount through the entire Tween, including looping. * * @name Phaser.Tweens.Tween#totalProgress * @type {number} * @default 0 * @since 3.0.0 */ this.totalProgress = 0; /** * An object containing the various Tween callback references. * * @name Phaser.Tweens.Tween#callbacks * @type {object} * @default 0 * @since 3.0.0 */ this.callbacks = { onComplete: null, onLoop: null, onRepeat: null, onStart: null, onUpdate: null, onYoyo: null }; this.callbackScope; }, /** * [description] * * @method Phaser.Tweens.Tween#getValue * @since 3.0.0 * * @return {number} [description] */ getValue: function () { return this.data[0].current; }, /** * [description] * * @method Phaser.Tweens.Tween#setTimeScale * @since 3.0.0 * * @param {number} value - [description] * * @return {Phaser.Tweens.Tween} This Tween object. */ setTimeScale: function (value) { this.timeScale = value; return this; }, /** * [description] * * @method Phaser.Tweens.Tween#getTimeScale * @since 3.0.0 * * @return {number} [description] */ getTimeScale: function () { return this.timeScale; }, /** * [description] * * @method Phaser.Tweens.Tween#isPlaying * @since 3.0.0 * * @return {boolean} [description] */ isPlaying: function () { return (this.state === TWEEN_CONST.ACTIVE); }, /** * [description] * * @method Phaser.Tweens.Tween#isPaused * @since 3.0.0 * * @return {boolean} [description] */ isPaused: function () { return (this.state === TWEEN_CONST.PAUSED); }, /** * [description] * * @method Phaser.Tweens.Tween#hasTarget * @since 3.0.0 * * @param {object} target - [description] * * @return {boolean} [description] */ hasTarget: function (target) { return (this.targets.indexOf(target) !== -1); }, /** * [description] * * @method Phaser.Tweens.Tween#updateTo * @since 3.0.0 * * @param {string} key - [description] * @param {*} value - [description] * @param {boolean} startToCurrent - [description] * * @return {Phaser.Tweens.Tween} This Tween object. */ updateTo: function (key, value, startToCurrent) { for (var i = 0; i < this.totalData; i++) { var tweenData = this.data[i]; if (tweenData.key === key) { tweenData.end = value; if (startToCurrent) { tweenData.start = tweenData.current; } break; } } return this; }, /** * [description] * * @method Phaser.Tweens.Tween#restart * @since 3.0.0 */ restart: function () { if (this.state === TWEEN_CONST.REMOVED) { this.seek(0); this.parent.makeActive(this); } else { this.stop(); this.play(); } }, /** * [description] * * @method Phaser.Tweens.Tween#calcDuration * @since 3.0.0 */ calcDuration: function () { var max = 0; var data = this.data; for (var i = 0; i < this.totalData; i++) { var tweenData = data[i]; // Set t1 (duration + hold + yoyo) tweenData.t1 = tweenData.duration + tweenData.hold; if (tweenData.yoyo) { tweenData.t1 += tweenData.duration; } // Set t2 (repeatDelay + duration + hold + yoyo) tweenData.t2 = tweenData.t1 + tweenData.repeatDelay; // Total Duration tweenData.totalDuration = tweenData.delay + tweenData.t1; if (tweenData.repeat === -1) { tweenData.totalDuration += (tweenData.t2 * 999999999999); } else if (tweenData.repeat > 0) { tweenData.totalDuration += (tweenData.t2 * tweenData.repeat); } if (tweenData.totalDuration > max) { // Get the longest TweenData from the Tween, used to calculate the Tween TD max = tweenData.totalDuration; } } // Excludes loop values this.duration = max; this.loopCounter = (this.loop === -1) ? 999999999999 : this.loop; if (this.loopCounter > 0) { this.totalDuration = this.duration + this.completeDelay + ((this.duration + this.loopDelay) * this.loopCounter); } else { this.totalDuration = this.duration + this.completeDelay; } }, /** * Called by TweenManager.preUpdate as part of its loop to check pending and active tweens. * Should not be called directly. * * @method Phaser.Tweens.Tween#init * @since 3.0.0 * * @return {boolean} Returns `true` if this Tween should be moved from the pending list to the active list by the Tween Manager. */ init: function () { var data = this.data; var totalTargets = this.totalTargets; for (var i = 0; i < this.totalData; i++) { var tweenData = data[i]; var target = tweenData.target; var gen = tweenData.gen; tweenData.delay = gen.delay(i, totalTargets, target); tweenData.duration = gen.duration(i, totalTargets, target); tweenData.hold = gen.hold(i, totalTargets, target); tweenData.repeat = gen.repeat(i, totalTargets, target); tweenData.repeatDelay = gen.repeatDelay(i, totalTargets, target); } this.calcDuration(); this.progress = 0; this.totalProgress = 0; this.elapsed = 0; this.totalElapsed = 0; // You can't have a paused Tween if it's part of a Timeline if (this.paused && !this.parentIsTimeline) { this.state = TWEEN_CONST.PENDING_ADD; this._pausedState = TWEEN_CONST.INIT; return false; } else { this.state = TWEEN_CONST.INIT; return true; } }, /** * [description] * * @method Phaser.Tweens.Tween#nextState * @since 3.0.0 */ nextState: function () { if (this.loopCounter > 0) { this.elapsed = 0; this.progress = 0; this.loopCounter--; var onLoop = this.callbacks.onLoop; if (onLoop) { onLoop.params[1] = this.targets; onLoop.func.apply(onLoop.scope, onLoop.params); } this.resetTweenData(true); if (this.loopDelay > 0) { this.countdown = this.loopDelay; this.state = TWEEN_CONST.LOOP_DELAY; } else { this.state = TWEEN_CONST.ACTIVE; } } else if (this.completeDelay > 0) { this.countdown = this.completeDelay; this.state = TWEEN_CONST.COMPLETE_DELAY; } else { var onComplete = this.callbacks.onComplete; if (onComplete) { onComplete.params[1] = this.targets; onComplete.func.apply(onComplete.scope, onComplete.params); } this.state = TWEEN_CONST.PENDING_REMOVE; } }, /** * [description] * * @method Phaser.Tweens.Tween#pause * @since 3.0.0 * * @return {Phaser.Tweens.Tween} This Tween object. */ pause: function () { if (this.state === TWEEN_CONST.PAUSED) { return; } this.paused = true; this._pausedState = this.state; this.state = TWEEN_CONST.PAUSED; return this; }, /** * [description] * * @method Phaser.Tweens.Tween#play * @since 3.0.0 * * @param {boolean} resetFromTimeline - [description] */ play: function (resetFromTimeline) { if (this.state === TWEEN_CONST.ACTIVE) { return; } else if (this.state === TWEEN_CONST.PENDING_REMOVE || this.state === TWEEN_CONST.REMOVED) { this.init(); this.parent.makeActive(this); resetFromTimeline = true; } var onStart = this.callbacks.onStart; if (this.parentIsTimeline) { this.resetTweenData(resetFromTimeline); if (this.calculatedOffset === 0) { if (onStart) { onStart.params[1] = this.targets; onStart.func.apply(onStart.scope, onStart.params); } this.state = TWEEN_CONST.ACTIVE; } else { this.countdown = this.calculatedOffset; this.state = TWEEN_CONST.OFFSET_DELAY; } } else if (this.paused) { this.paused = false; this.parent.makeActive(this); } else { this.resetTweenData(resetFromTimeline); this.state = TWEEN_CONST.ACTIVE; if (onStart) { onStart.params[1] = this.targets; onStart.func.apply(onStart.scope, onStart.params); } } }, /** * [description] * * @method Phaser.Tweens.Tween#resetTweenData * @since 3.0.0 * * @param {boolean} resetFromLoop - [description] */ resetTweenData: function (resetFromLoop) { var data = this.data; for (var i = 0; i < this.totalData; i++) { var tweenData = data[i]; tweenData.progress = 0; tweenData.elapsed = 0; tweenData.repeatCounter = (tweenData.repeat === -1) ? 999999999999 : tweenData.repeat; if (resetFromLoop) { tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start); tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.end); tweenData.current = tweenData.start; tweenData.state = TWEEN_CONST.PLAYING_FORWARD; } else if (tweenData.delay > 0) { tweenData.elapsed = tweenData.delay; tweenData.state = TWEEN_CONST.DELAY; } else { tweenData.state = TWEEN_CONST.PENDING_RENDER; } } }, /** * [description] * * @method Phaser.Tweens.Tween#resume * @since 3.0.0 * * @return {Phaser.Tweens.Tween} This Tween object. */ resume: function () { if (this.state === TWEEN_CONST.PAUSED) { this.paused = false; this.state = this._pausedState; } else { this.play(); } return this; }, /** * [description] * * @method Phaser.Tweens.Tween#seek * @since 3.0.0 * * @param {float} toPosition - A value between 0 and 1. */ seek: function (toPosition) { var data = this.data; for (var i = 0; i < this.totalData; i++) { // This won't work with loop > 0 yet var ms = this.totalDuration * toPosition; var tweenData = data[i]; var progress = 0; var elapsed = 0; if (ms <= tweenData.delay) { progress = 0; elapsed = 0; } else if (ms >= tweenData.totalDuration) { progress = 1; elapsed = tweenData.duration; } else if (ms > tweenData.delay && ms <= tweenData.t1) { // Keep it zero bound ms = Math.max(0, ms - tweenData.delay); // Somewhere in the first playthru range progress = ms / tweenData.t1; elapsed = tweenData.duration * progress; } else if (ms > tweenData.t1 && ms < tweenData.totalDuration) { // Somewhere in repeat land ms -= tweenData.delay; ms -= tweenData.t1; // var repeats = Math.floor(ms / tweenData.t2); // remainder ms = ((ms / tweenData.t2) % 1) * tweenData.t2; if (ms > tweenData.repeatDelay) { progress = ms / tweenData.t1; elapsed = tweenData.duration * progress; } } tweenData.progress = progress; tweenData.elapsed = elapsed; var v = tweenData.ease(tweenData.progress); tweenData.current = tweenData.start + ((tweenData.end - tweenData.start) * v); // console.log(tweenData.key, 'Seek', tweenData.target[tweenData.key], 'to', tweenData.current, 'pro', tweenData.progress, 'marker', toPosition, progress); // if (tweenData.current === 0) // { // console.log('zero', tweenData.start, tweenData.end, v, 'progress', progress); // } tweenData.target[tweenData.key] = tweenData.current; } }, /** * [description] * * @method Phaser.Tweens.Tween#setCallback * @since 3.0.0 * * @param {string} type - [description] * @param {function} callback - [description] * @param {array} [params] - [description] * @param {object} [scope] - [description] * * @return {Phaser.Tweens.Tween} This Tween object. */ setCallback: function (type, callback, params, scope) { this.callbacks[type] = { func: callback, scope: scope, params: params }; return this; }, /** * Flags the Tween as being complete, whatever stage of progress it is at. * * If an onComplete callback has been defined it will automatically invoke it, unless a `delay` * argument is provided, in which case the Tween will delay for that period of time before calling the callback. * * If you don't need a delay, or have an onComplete callback, then call `Tween.stop` instead. * * @method Phaser.Tweens.Tween#complete * @since 3.2.0 * * @param {number} [delay=0] - The time to wait before invoking the complete callback. If zero it will fire immediately. */ complete: function (delay) { if (delay === undefined) { delay = 0; } if (delay) { this.countdown = delay; this.state = TWEEN_CONST.COMPLETE_DELAY; } else { var onComplete = this.callbacks.onComplete; if (onComplete) { onComplete.params[1] = this.targets; onComplete.func.apply(onComplete.scope, onComplete.params); } this.state = TWEEN_CONST.PENDING_REMOVE; } }, /** * Stops the Tween immediately, whatever stage of progress it is at and flags it for removal by the TweenManager. * * @method Phaser.Tweens.Tween#stop * @since 3.0.0 * * @param {float} [resetTo] - A value between 0 and 1. */ stop: function (resetTo) { if (this.state === TWEEN_CONST.ACTIVE) { if (resetTo !== undefined) { this.seek(resetTo); } } if (this.state !== TWEEN_CONST.REMOVED) { this.state = TWEEN_CONST.PENDING_REMOVE; } }, /** * [description] * * @method Phaser.Tweens.Tween#update * @since 3.0.0 * * @param {number} timestamp - [description] * @param {number} delta - [description] * * @return {boolean} Returns `true` if this Tween has finished and should be removed from the Tween Manager, otherwise returns `false`. */ update: function (timestamp, delta) { if (this.state === TWEEN_CONST.PAUSED) { return false; } if (this.useFrames) { delta = 1 * this.parent.timeScale; } delta *= this.timeScale; this.elapsed += delta; this.progress = Math.min(this.elapsed / this.duration, 1); this.totalElapsed += delta; this.totalProgress = Math.min(this.totalElapsed / this.totalDuration, 1); switch (this.state) { case TWEEN_CONST.ACTIVE: var stillRunning = false; for (var i = 0; i < this.totalData; i++) { if (this.updateTweenData(this, this.data[i], delta)) { stillRunning = true; } } // Anything still running? If not, we're done if (!stillRunning) { this.nextState(); } break; case TWEEN_CONST.LOOP_DELAY: this.countdown -= delta; if (this.countdown <= 0) { this.state = TWEEN_CONST.ACTIVE; } break; case TWEEN_CONST.OFFSET_DELAY: this.countdown -= delta; if (this.countdown <= 0) { var onStart = this.callbacks.onStart; if (onStart) { onStart.params[1] = this.targets; onStart.func.apply(onStart.scope, onStart.params); } this.state = TWEEN_CONST.ACTIVE; } break; case TWEEN_CONST.COMPLETE_DELAY: this.countdown -= delta; if (this.countdown <= 0) { var onComplete = this.callbacks.onComplete; if (onComplete) { onComplete.func.apply(onComplete.scope, onComplete.params); } this.state = TWEEN_CONST.PENDING_REMOVE; } break; } return (this.state === TWEEN_CONST.PENDING_REMOVE); }, /** * [description] * * @method Phaser.Tweens.Tween#setStateFromEnd * @since 3.0.0 * * @param {Phaser.Tweens.Tween} tween - [description] * @param {Phaser.Tweens.TweenDataConfig} tweenData - [description] * @param {number} diff - [description] * * @return {integer} The state of this Tween. */ setStateFromEnd: function (tween, tweenData, diff) { if (tweenData.yoyo) { // We've hit the end of a Playing Forward TweenData and we have a yoyo // Account for any extra time we got from the previous frame tweenData.elapsed = diff; tweenData.progress = diff / tweenData.duration; if (tweenData.flipX) { tweenData.target.toggleFlipX(); } // Problem: The flip and callback and so on gets called for every TweenData that triggers it at the same time. // If you're tweening several properties it can fire for all of them, at once. if (tweenData.flipY) { tweenData.target.toggleFlipY(); } var onYoyo = tween.callbacks.onYoyo; if (onYoyo) { // Element 1 is reserved for the target of the yoyo (and needs setting here) onYoyo.params[1] = tweenData.target; onYoyo.func.apply(onYoyo.scope, onYoyo.params); } tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start); return TWEEN_CONST.PLAYING_BACKWARD; } else if (tweenData.repeatCounter > 0) { // We've hit the end of a Playing Forward TweenData and we have a Repeat. // So we're going to go right back to the start to repeat it again. tweenData.repeatCounter--; // Account for any extra time we got from the previous frame tweenData.elapsed = diff; tweenData.progress = diff / tweenData.duration; if (tweenData.flipX) { tweenData.target.toggleFlipX(); } if (tweenData.flipY) { tweenData.target.toggleFlipY(); } var onRepeat = tween.callbacks.onRepeat; if (onRepeat) { // Element 1 is reserved for the target of the repeat (and needs setting here) onRepeat.params[1] = tweenData.target; onRepeat.func.apply(onRepeat.scope, onRepeat.params); } tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start); tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start); // Delay? if (tweenData.repeatDelay > 0) { tweenData.elapsed = tweenData.repeatDelay - diff; tweenData.current = tweenData.start; tweenData.target[tweenData.key] = tweenData.current; return TWEEN_CONST.REPEAT_DELAY; } else { return TWEEN_CONST.PLAYING_FORWARD; } } return TWEEN_CONST.COMPLETE; }, /** * Was PLAYING_BACKWARD and has hit the start. * * @method Phaser.Tweens.Tween#setStateFromStart * @since 3.0.0 * * @param {Phaser.Tweens.Tween} tween - [description] * @param {Phaser.Tweens.TweenDataConfig} tweenData - [description] * @param {number} diff - [description] * * @return {integer} The state of this Tween. */ setStateFromStart: function (tween, tweenData, diff) { if (tweenData.repeatCounter > 0) { tweenData.repeatCounter--; // Account for any extra time we got from the previous frame tweenData.elapsed = diff; tweenData.progress = diff / tweenData.duration; if (tweenData.flipX) { tweenData.target.toggleFlipX(); } if (tweenData.flipY) { tweenData.target.toggleFlipY(); } var onRepeat = tween.callbacks.onRepeat; if (onRepeat) { // Element 1 is reserved for the target of the repeat (and needs setting here) onRepeat.params[1] = tweenData.target; onRepeat.func.apply(onRepeat.scope, onRepeat.params); } tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start); // Delay? if (tweenData.repeatDelay > 0) { tweenData.elapsed = tweenData.repeatDelay - diff; tweenData.current = tweenData.start; tweenData.target[tweenData.key] = tweenData.current; return TWEEN_CONST.REPEAT_DELAY; } else { return TWEEN_CONST.PLAYING_FORWARD; } } return TWEEN_CONST.COMPLETE; }, // /** * [description] * * @method Phaser.Tweens.Tween#updateTweenData * @since 3.0.0 * * @param {Phaser.Tweens.Tween} tween - [description] * @param {Phaser.Tweens.TweenDataConfig} tweenData - [description] * @param {number} delta - Either a value in ms, or 1 if Tween.useFrames is true * * @return {boolean} [description] */ updateTweenData: function (tween, tweenData, delta) { switch (tweenData.state) { case TWEEN_CONST.PLAYING_FORWARD: case TWEEN_CONST.PLAYING_BACKWARD: if (!tweenData.target) { tweenData.state = TWEEN_CONST.COMPLETE; break; } var elapsed = tweenData.elapsed; var duration = tweenData.duration; var diff = 0; elapsed += delta; if (elapsed > duration) { diff = elapsed - duration; elapsed = duration; } var forward = (tweenData.state === TWEEN_CONST.PLAYING_FORWARD); var progress = elapsed / duration; var v; if (forward) { v = tweenData.ease(progress); } else { v = tweenData.ease(1 - progress); } tweenData.current = tweenData.start + ((tweenData.end - tweenData.start) * v); tweenData.target[tweenData.key] = tweenData.current; tweenData.elapsed = elapsed; tweenData.progress = progress; var onUpdate = tween.callbacks.onUpdate; if (onUpdate) { onUpdate.params[1] = tweenData.target; onUpdate.func.apply(onUpdate.scope, onUpdate.params); } if (progress === 1) { if (forward) { if (tweenData.hold > 0) { tweenData.elapsed = tweenData.hold - diff; tweenData.state = TWEEN_CONST.HOLD_DELAY; } else { tweenData.state = this.setStateFromEnd(tween, tweenData, diff); } } else { tweenData.state = this.setStateFromStart(tween, tweenData, diff); } } break; case TWEEN_CONST.DELAY: tweenData.elapsed -= delta; if (tweenData.elapsed <= 0) { tweenData.elapsed = Math.abs(tweenData.elapsed); tweenData.state = TWEEN_CONST.PENDING_RENDER; } break; case TWEEN_CONST.REPEAT_DELAY: tweenData.elapsed -= delta; if (tweenData.elapsed <= 0) { tweenData.elapsed = Math.abs(tweenData.elapsed); tweenData.state = TWEEN_CONST.PLAYING_FORWARD; } break; case TWEEN_CONST.HOLD_DELAY: tweenData.elapsed -= delta; if (tweenData.elapsed <= 0) { tweenData.state = this.setStateFromEnd(tween, tweenData, Math.abs(tweenData.elapsed)); } break; case TWEEN_CONST.PENDING_RENDER: if (tweenData.target) { tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.target[tweenData.key]); tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start); tweenData.current = tweenData.start; tweenData.target[tweenData.key] = tweenData.start; tweenData.state = TWEEN_CONST.PLAYING_FORWARD; } else { tweenData.state = TWEEN_CONST.COMPLETE; } break; } // Return TRUE if this TweenData still playing, otherwise return FALSE return (tweenData.state !== TWEEN_CONST.COMPLETE); } }); Tween.TYPES = [ 'onComplete', 'onLoop', 'onRepeat', 'onStart', 'onUpdate', 'onYoyo' ]; /** * Creates a new Tween object. * * Note: This method will only be available Tweens have been built into Phaser. * * @method Phaser.GameObjects.GameObjectFactory#tween * @since 3.0.0 * * @param {object} config - The Tween configuration. * * @return {Phaser.Tweens.Tween} The Tween that was created. */ GameObjectFactory.register('tween', function (config) { return this.scene.sys.tweens.add(config); }); // When registering a factory function 'this' refers to the GameObjectFactory context. // // There are several properties available to use: // // this.scene - a reference to the Scene that owns the GameObjectFactory // this.displayList - a reference to the Display List the Scene owns // this.updateList - a reference to the Update List the Scene owns /** * Creates a new Tween object and returns it. * * Note: This method will only be available if Tweens have been built into Phaser. * * @method Phaser.GameObjects.GameObjectCreator#tween * @since 3.0.0 * * @param {object} config - The Tween configuration. * * @return {Phaser.Tweens.Tween} The Tween that was created. */ GameObjectCreator.register('tween', function (config) { return this.scene.sys.tweens.create(config); }); // When registering a factory function 'this' refers to the GameObjectCreator context. module.exports = Tween; /***/ }), /* 100 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @typedef {object} Phaser.Tweens.TweenConfigDefaults * * @property {(object|object[])} targets - [description] * @property {number} [delay=0] - [description] * @property {number} [duration=1000] - [description] * @property {string} [ease='Power0'] - [description] * @property {array} [easeParams] - [description] * @property {number} [hold=0] - [description] * @property {number} [repeat=0] - [description] * @property {number} [repeatDelay=0] - [description] * @property {boolean} [yoyo=false] - [description] * @property {boolean} [flipX=false] - [description] * @property {boolean} [flipY=false] - [description] */ var TWEEN_DEFAULTS = { targets: null, delay: 0, duration: 1000, ease: 'Power0', easeParams: null, hold: 0, repeat: 0, repeatDelay: 0, yoyo: false, flipX: false, flipY: false }; module.exports = TWEEN_DEFAULTS; /***/ }), /* 101 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ function hasGetStart (def) { return (!!def.getStart && typeof def.getStart === 'function'); } function hasGetEnd (def) { return (!!def.getEnd && typeof def.getEnd === 'function'); } function hasGetters (def) { return hasGetStart(def) || hasGetEnd(def); } /** * [description] * * @function Phaser.Tweens.Builders.GetValueOp * @since 3.0.0 * * @param {string} key - [description] * @param {*} propertyValue - [description] * * @return {function} [description] */ var GetValueOp = function (key, propertyValue) { var callbacks; // The returned value sets what the property will be at the END of the Tween (usually called at the start of the Tween) var getEnd = function (target, key, value) { return value; }; // The returned value sets what the property will be at the START of the Tween (usually called at the end of the Tween) var getStart = function (target, key, value) { return value; }; var t = typeof(propertyValue); if (t === 'number') { // props: { // x: 400, // y: 300 // } getEnd = function () { return propertyValue; }; } else if (t === 'string') { // props: { // x: '+=400', // y: '-=300', // z: '*=2', // w: '/=2' // } var op = propertyValue[0]; var num = parseFloat(propertyValue.substr(2)); switch (op) { case '+': getEnd = function (target, key, value) { return value + num; }; break; case '-': getEnd = function (target, key, value) { return value - num; }; break; case '*': getEnd = function (target, key, value) { return value * num; }; break; case '/': getEnd = function (target, key, value) { return value / num; }; break; default: getEnd = function () { return parseFloat(propertyValue); }; } } else if (t === 'function') { // The same as setting just the getEnd function and no getStart // props: { // x: function (target, key, value) { return value + 50); }, // } getEnd = propertyValue; } else if (t === 'object' && hasGetters(propertyValue)) { /* x: { // Called at the start of the Tween. The returned value sets what the property will be at the END of the Tween. getEnd: function (target, key, value) { return value; }, // Called at the end of the Tween. The returned value sets what the property will be at the START of the Tween. getStart: function (target, key, value) { return value; } } */ if (hasGetEnd(propertyValue)) { getEnd = propertyValue.getEnd; } if (hasGetStart(propertyValue)) { getStart = propertyValue.getStart; } } else if (propertyValue.hasOwnProperty('value')) { // Value may still be a string, function or a number // props: { // x: { value: 400, ... }, // y: { value: 300, ... } // } callbacks = GetValueOp(key, propertyValue.value); } // If callback not set by the else if block above then set it here and return it if (!callbacks) { callbacks = { getEnd: getEnd, getStart: getStart }; } return callbacks; }; module.exports = GetValueOp; /***/ }), /* 102 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetValue = __webpack_require__(4); /** * [description] * * @function Phaser.Tweens.Builders.GetTargets * @since 3.0.0 * * @param {object} config - [description] * * @return {array} [description] */ var GetTargets = function (config) { var targets = GetValue(config, 'targets', null); if (targets === null) { return targets; } if (typeof targets === 'function') { targets = targets.call(); } if (!Array.isArray(targets)) { targets = [ targets ]; } return targets; }; module.exports = GetTargets; /***/ }), /* 103 */, /* 104 */, /* 105 */, /* 106 */, /* 107 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Extend = __webpack_require__(17); var XHRSettings = __webpack_require__(75); /** * Takes two XHRSettings Objects and creates a new XHRSettings object from them. * * The new object is seeded by the values given in the global settings, but any setting in * the local object overrides the global ones. * * @function Phaser.Loader.MergeXHRSettings * @since 3.0.0 * * @param {XHRSettingsObject} global - The global XHRSettings object. * @param {XHRSettingsObject} local - The local XHRSettings object. * * @return {XHRSettingsObject} A newly formed XHRSettings object. */ var MergeXHRSettings = function (global, local) { var output = (global === undefined) ? XHRSettings() : Extend({}, global); if (local) { for (var setting in local) { if (local[setting] !== undefined) { output[setting] = local[setting]; } } } return output; }; module.exports = MergeXHRSettings; /***/ }), /* 108 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Given a File and a baseURL value this returns the URL the File will use to download from. * * @function Phaser.Loader.GetURL * @since 3.0.0 * * @param {Phaser.Loader.File} file - The File object. * @param {string} baseURL - A default base URL. * * @return {string} The URL the File will use. */ var GetURL = function (file, baseURL) { if (!file.url) { return false; } if (file.url.match(/^(?:blob:|data:|http:\/\/|https:\/\/|\/\/)/)) { return file.url; } else { return baseURL + file.url; } }; module.exports = GetURL; /***/ }), /* 109 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Keyboard Codes. * * @name Phaser.Input.Keyboard.KeyCodes * @enum {integer} * @memberOf Phaser.Input.Keyboard * @readOnly * @since 3.0.0 */ var KeyCodes = { /** * @name Phaser.Input.Keyboard.KeyCodes.BACKSPACE */ BACKSPACE: 8, /** * @name Phaser.Input.Keyboard.KeyCodes.TAB */ TAB: 9, /** * @name Phaser.Input.Keyboard.KeyCodes.ENTER */ ENTER: 13, /** * @name Phaser.Input.Keyboard.KeyCodes.SHIFT */ SHIFT: 16, /** * @name Phaser.Input.Keyboard.KeyCodes.CTRL */ CTRL: 17, /** * @name Phaser.Input.Keyboard.KeyCodes.ALT */ ALT: 18, /** * @name Phaser.Input.Keyboard.KeyCodes.PAUSE */ PAUSE: 19, /** * @name Phaser.Input.Keyboard.KeyCodes.CAPS_LOCK */ CAPS_LOCK: 20, /** * @name Phaser.Input.Keyboard.KeyCodes.ESC */ ESC: 27, /** * @name Phaser.Input.Keyboard.KeyCodes.SPACE */ SPACE: 32, /** * @name Phaser.Input.Keyboard.KeyCodes.PAGE_UP */ PAGE_UP: 33, /** * @name Phaser.Input.Keyboard.KeyCodes.PAGE_DOWN */ PAGE_DOWN: 34, /** * @name Phaser.Input.Keyboard.KeyCodes.END */ END: 35, /** * @name Phaser.Input.Keyboard.KeyCodes.HOME */ HOME: 36, /** * @name Phaser.Input.Keyboard.KeyCodes.LEFT */ LEFT: 37, /** * @name Phaser.Input.Keyboard.KeyCodes.UP */ UP: 38, /** * @name Phaser.Input.Keyboard.KeyCodes.RIGHT */ RIGHT: 39, /** * @name Phaser.Input.Keyboard.KeyCodes.DOWN */ DOWN: 40, /** * @name Phaser.Input.Keyboard.KeyCodes.PRINT_SCREEN */ PRINT_SCREEN: 42, /** * @name Phaser.Input.Keyboard.KeyCodes.INSERT */ INSERT: 45, /** * @name Phaser.Input.Keyboard.KeyCodes.DELETE */ DELETE: 46, /** * @name Phaser.Input.Keyboard.KeyCodes.ZERO */ ZERO: 48, /** * @name Phaser.Input.Keyboard.KeyCodes.ONE */ ONE: 49, /** * @name Phaser.Input.Keyboard.KeyCodes.TWO */ TWO: 50, /** * @name Phaser.Input.Keyboard.KeyCodes.THREE */ THREE: 51, /** * @name Phaser.Input.Keyboard.KeyCodes.FOUR */ FOUR: 52, /** * @name Phaser.Input.Keyboard.KeyCodes.FIVE */ FIVE: 53, /** * @name Phaser.Input.Keyboard.KeyCodes.SIX */ SIX: 54, /** * @name Phaser.Input.Keyboard.KeyCodes.SEVEN */ SEVEN: 55, /** * @name Phaser.Input.Keyboard.KeyCodes.EIGHT */ EIGHT: 56, /** * @name Phaser.Input.Keyboard.KeyCodes.NINE */ NINE: 57, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_ZERO */ NUMPAD_ZERO: 96, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_ONE */ NUMPAD_ONE: 97, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_TWO */ NUMPAD_TWO: 98, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_THREE */ NUMPAD_THREE: 99, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_FOUR */ NUMPAD_FOUR: 100, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_FIVE */ NUMPAD_FIVE: 101, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_SIX */ NUMPAD_SIX: 102, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_SEVEN */ NUMPAD_SEVEN: 103, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_EIGHT */ NUMPAD_EIGHT: 104, /** * @name Phaser.Input.Keyboard.KeyCodes.NUMPAD_NINE */ NUMPAD_NINE: 105, /** * @name Phaser.Input.Keyboard.KeyCodes.A */ A: 65, /** * @name Phaser.Input.Keyboard.KeyCodes.B */ B: 66, /** * @name Phaser.Input.Keyboard.KeyCodes.C */ C: 67, /** * @name Phaser.Input.Keyboard.KeyCodes.D */ D: 68, /** * @name Phaser.Input.Keyboard.KeyCodes.E */ E: 69, /** * @name Phaser.Input.Keyboard.KeyCodes.F */ F: 70, /** * @name Phaser.Input.Keyboard.KeyCodes.G */ G: 71, /** * @name Phaser.Input.Keyboard.KeyCodes.H */ H: 72, /** * @name Phaser.Input.Keyboard.KeyCodes.I */ I: 73, /** * @name Phaser.Input.Keyboard.KeyCodes.J */ J: 74, /** * @name Phaser.Input.Keyboard.KeyCodes.K */ K: 75, /** * @name Phaser.Input.Keyboard.KeyCodes.L */ L: 76, /** * @name Phaser.Input.Keyboard.KeyCodes.M */ M: 77, /** * @name Phaser.Input.Keyboard.KeyCodes.N */ N: 78, /** * @name Phaser.Input.Keyboard.KeyCodes.O */ O: 79, /** * @name Phaser.Input.Keyboard.KeyCodes.P */ P: 80, /** * @name Phaser.Input.Keyboard.KeyCodes.Q */ Q: 81, /** * @name Phaser.Input.Keyboard.KeyCodes.R */ R: 82, /** * @name Phaser.Input.Keyboard.KeyCodes.S */ S: 83, /** * @name Phaser.Input.Keyboard.KeyCodes.T */ T: 84, /** * @name Phaser.Input.Keyboard.KeyCodes.U */ U: 85, /** * @name Phaser.Input.Keyboard.KeyCodes.V */ V: 86, /** * @name Phaser.Input.Keyboard.KeyCodes.W */ W: 87, /** * @name Phaser.Input.Keyboard.KeyCodes.X */ X: 88, /** * @name Phaser.Input.Keyboard.KeyCodes.Y */ Y: 89, /** * @name Phaser.Input.Keyboard.KeyCodes.Z */ Z: 90, /** * @name Phaser.Input.Keyboard.KeyCodes.F1 */ F1: 112, /** * @name Phaser.Input.Keyboard.KeyCodes.F2 */ F2: 113, /** * @name Phaser.Input.Keyboard.KeyCodes.F3 */ F3: 114, /** * @name Phaser.Input.Keyboard.KeyCodes.F4 */ F4: 115, /** * @name Phaser.Input.Keyboard.KeyCodes.F5 */ F5: 116, /** * @name Phaser.Input.Keyboard.KeyCodes.F6 */ F6: 117, /** * @name Phaser.Input.Keyboard.KeyCodes.F7 */ F7: 118, /** * @name Phaser.Input.Keyboard.KeyCodes.F8 */ F8: 119, /** * @name Phaser.Input.Keyboard.KeyCodes.F9 */ F9: 120, /** * @name Phaser.Input.Keyboard.KeyCodes.F10 */ F10: 121, /** * @name Phaser.Input.Keyboard.KeyCodes.F11 */ F11: 122, /** * @name Phaser.Input.Keyboard.KeyCodes.F12 */ F12: 123, /** * @name Phaser.Input.Keyboard.KeyCodes.SEMICOLON */ SEMICOLON: 186, /** * @name Phaser.Input.Keyboard.KeyCodes.PLUS */ PLUS: 187, /** * @name Phaser.Input.Keyboard.KeyCodes.COMMA */ COMMA: 188, /** * @name Phaser.Input.Keyboard.KeyCodes.MINUS */ MINUS: 189, /** * @name Phaser.Input.Keyboard.KeyCodes.PERIOD */ PERIOD: 190, /** * @name Phaser.Input.Keyboard.KeyCodes.FORWARD_SLASH */ FORWARD_SLASH: 191, /** * @name Phaser.Input.Keyboard.KeyCodes.BACK_SLASH */ BACK_SLASH: 220, /** * @name Phaser.Input.Keyboard.KeyCodes.QUOTES */ QUOTES: 222, /** * @name Phaser.Input.Keyboard.KeyCodes.BACKTICK */ BACKTICK: 192, /** * @name Phaser.Input.Keyboard.KeyCodes.OPEN_BRACKET */ OPEN_BRACKET: 219, /** * @name Phaser.Input.Keyboard.KeyCodes.CLOSED_BRACKET */ CLOSED_BRACKET: 221 }; module.exports = KeyCodes; /***/ }), /* 110 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var AddToDOM = __webpack_require__(130); var CanvasPool = __webpack_require__(22); var Class = __webpack_require__(0); var Components = __webpack_require__(15); var CONST = __webpack_require__(20); var GameObject = __webpack_require__(2); var GetTextSize = __webpack_require__(417); var GetValue = __webpack_require__(4); var RemoveFromDOM = __webpack_require__(269); var TextRender = __webpack_require__(416); var TextStyle = __webpack_require__(413); /** * @classdesc * [description] * * @class Text * @extends Phaser.GameObjects.GameObject * @memberOf Phaser.GameObjects * @constructor * @since 3.0.0 * * @extends Phaser.GameObjects.Components.Alpha * @extends Phaser.GameObjects.Components.BlendMode * @extends Phaser.GameObjects.Components.ComputedSize * @extends Phaser.GameObjects.Components.Depth * @extends Phaser.GameObjects.Components.Flip * @extends Phaser.GameObjects.Components.GetBounds * @extends Phaser.GameObjects.Components.Mask * @extends Phaser.GameObjects.Components.Origin * @extends Phaser.GameObjects.Components.Pipeline * @extends Phaser.GameObjects.Components.ScaleMode * @extends Phaser.GameObjects.Components.ScrollFactor * @extends Phaser.GameObjects.Components.Tint * @extends Phaser.GameObjects.Components.Transform * @extends Phaser.GameObjects.Components.Visible * * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param {number} x - The horizontal position of this Game Object in the world. * @param {number} y - The vertical position of this Game Object in the world. * @param {(string|string[])} text - The text this Text object will display. * @param {object} style - The text style configuration object. */ var Text = new Class({ Extends: GameObject, Mixins: [ Components.Alpha, Components.BlendMode, Components.ComputedSize, Components.Depth, Components.Flip, Components.GetBounds, Components.Mask, Components.Origin, Components.Pipeline, Components.ScaleMode, Components.ScrollFactor, Components.Tint, Components.Transform, Components.Visible, TextRender ], initialize: function Text (scene, x, y, text, style) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } GameObject.call(this, scene, 'Text'); this.setPosition(x, y); this.setOrigin(0, 0); this.initPipeline('TextureTintPipeline'); /** * The canvas element that the text is rendered to. * * @name Phaser.GameObjects.Text#canvas * @type {HTMLCanvasElement} * @since 3.0.0 */ this.canvas = CanvasPool.create(this); /** * The context of the canvas element that the text is rendered to. * * @name Phaser.GameObjects.Text#context * @type {CanvasRenderingContext2D} * @since 3.0.0 */ this.context = this.canvas.getContext('2d'); /** * [description] * * @name Phaser.GameObjects.Text#style * @type {Phaser.GameObjects.Text.TextStyle} * @since 3.0.0 */ this.style = new TextStyle(this, style); /** * [description] * * @name Phaser.GameObjects.Text#autoRound * @type {boolean} * @default true * @since 3.0.0 */ this.autoRound = true; /** * The Regular Expression that is used to split the text up into lines, in * multi-line text. By default this is `/(?:\r\n|\r|\n)/`. * You can change this RegExp to be anything else that you may need. * * @name Phaser.GameObjects.Text#splitRegExp * @type {object} * @since 3.0.0 */ this.splitRegExp = /(?:\r\n|\r|\n)/; /** * [description] * * @name Phaser.GameObjects.Text#text * @type {string} * @since 3.0.0 */ this.text = ''; /** * [description] * * @name Phaser.GameObjects.Text#resolution * @type {number} * @default 1 * @since 3.0.0 */ this.resolution = 1; /** * Specify a padding value which is added to the line width and height when calculating the Text size. * Allows you to add extra spacing if the browser is unable to accurately determine the true font dimensions. * * @name Phaser.GameObjects.Text#padding * @type {{left:number,right:number,top:number,bottom:number}} * @since 3.0.0 */ this.padding = { left: 0, right: 0, top: 0, bottom: 0 }; /** * [description] * * @name Phaser.GameObjects.Text#width * @type {number} * @default 1 * @since 3.0.0 */ this.width = 1; /** * [description] * * @name Phaser.GameObjects.Text#height * @type {number} * @default 1 * @since 3.0.0 */ this.height = 1; /** * [description] * * @name Phaser.GameObjects.Text#canvasTexture * @type {HTMLCanvasElement} * @default null * @since 3.0.0 */ this.canvasTexture = null; /** * [description] * * @name Phaser.GameObjects.Text#dirty * @type {boolean} * @default false * @since 3.0.0 */ this.dirty = false; this.initRTL(); if (style && style.padding) { this.setPadding(style.padding); } if (style && style.lineSpacing) { this._lineSpacing = style.lineSpacing; } this.setText(text); if (scene.sys.game.config.renderType === CONST.WEBGL) { scene.sys.game.renderer.onContextRestored(function () { this.canvasTexture = null; this.dirty = true; }, this); } }, /** * [description] * * @method Phaser.GameObjects.Text#initRTL * @since 3.0.0 */ initRTL: function () { if (!this.style.rtl) { return; } // Here is where the crazy starts. // // Due to browser implementation issues, you cannot fillText BiDi text to a canvas // that is not part of the DOM. It just completely ignores the direction property. this.canvas.dir = 'rtl'; // Experimental atm, but one day ... this.context.direction = 'rtl'; // Add it to the DOM, but hidden within the parent canvas. this.canvas.style.display = 'none'; AddToDOM(this.canvas, this.scene.sys.canvas); // And finally we set the x origin this.originX = 1; }, /** * Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal * bounds. * * @method Phaser.GameObjects.Text#runWordWrap * @since 3.0.0 * * @param {string} text - The text to perform word wrap detection against. * * @return {string} The text after wrapping has been applied. */ runWordWrap: function (text) { var style = this.style; if (style.wordWrapCallback) { var wrappedLines = style.wordWrapCallback.call(style.wordWrapCallbackScope, text, this); if (Array.isArray(wrappedLines)) { wrappedLines = wrappedLines.join('\n'); } return wrappedLines; } else if (style.wordWrapWidth) { if (style.wordWrapUseAdvanced) { return this.advancedWordWrap(text, this.context, this.style.wordWrapWidth); } else { return this.basicWordWrap(text, this.context, this.style.wordWrapWidth); } } else { return text; } }, /** * Advanced wrapping algorithm that will wrap words as the line grows longer than its horizontal * bounds. Consecutive spaces will be collapsed and replaced with a single space. Lines will be * trimmed of white space before processing. Throws an error if wordWrapWidth is less than a * single character. * * @method Phaser.GameObjects.Text#advancedWordWrap * @since 3.0.0 * * @param {string} text - The text to perform word wrap detection against. * @param {CanvasRenderingContext2D} context - [description] * @param {number} wordWrapWidth - [description] * * @return {string} The wrapped text. */ advancedWordWrap: function (text, context, wordWrapWidth) { var output = ''; // Condense consecutive spaces and split into lines var lines = text .replace(/ +/gi, ' ') .split(this.splitRegExp); var linesCount = lines.length; for (var i = 0; i < linesCount; i++) { var line = lines[i]; var out = ''; // Trim whitespace line = line.replace(/^ *|\s*$/gi, ''); // If entire line is less than wordWrapWidth append the entire line and exit early var lineWidth = context.measureText(line).width; if (lineWidth < wordWrapWidth) { output += line + '\n'; continue; } // Otherwise, calculate new lines var currentLineWidth = wordWrapWidth; // Split into words var words = line.split(' '); for (var j = 0; j < words.length; j++) { var word = words[j]; var wordWithSpace = word + ' '; var wordWidth = context.measureText(wordWithSpace).width; if (wordWidth > currentLineWidth) { // Break word if (j === 0) { // Shave off letters from word until it's small enough var newWord = wordWithSpace; while (newWord.length) { newWord = newWord.slice(0, -1); wordWidth = context.measureText(newWord).width; if (wordWidth <= currentLineWidth) { break; } } // If wordWrapWidth is too small for even a single letter, shame user // failure with a fatal error if (!newWord.length) { throw new Error('This text\'s wordWrapWidth setting is less than a single character!'); } // Replace current word in array with remainder var secondPart = word.substr(newWord.length); words[j] = secondPart; // Append first piece to output out += newWord; } // If existing word length is 0, don't include it var offset = (words[j].length) ? j : j + 1; // Collapse rest of sentence and remove any trailing white space var remainder = words.slice(offset).join(' ') .replace(/[ \n]*$/gi, ''); // Prepend remainder to next line lines[i + 1] = remainder + ' ' + (lines[i + 1] || ''); linesCount = lines.length; break; // Processing on this line // Append word with space to output } else { out += wordWithSpace; currentLineWidth -= wordWidth; } } // Append processed line to output output += out.replace(/[ \n]*$/gi, '') + '\n'; } // Trim the end of the string output = output.replace(/[\s|\n]*$/gi, ''); return output; }, /** * Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal * bounds. Spaces are not collapsed and whitespace is not trimmed. * * @method Phaser.GameObjects.Text#basicWordWrap * @since 3.0.0 * * @param {string} text - The text to perform word wrap detection against. * @param {CanvasRenderingContext2D} context - [description] * @param {number} wordWrapWidth - [description] * * @return {string} The wrapped text. */ basicWordWrap: function (text, context, wordWrapWidth) { var result = ''; var lines = text.split(this.splitRegExp); for (var i = 0; i < lines.length; i++) { var spaceLeft = wordWrapWidth; var words = lines[i].split(' '); for (var j = 0; j < words.length; j++) { var wordWidth = context.measureText(words[j]).width; var wordWidthWithSpace = wordWidth + context.measureText(' ').width; if (wordWidthWithSpace > spaceLeft) { // Skip printing the newline if it's the first word of the line that is greater // than the word wrap width. if (j > 0) { result += '\n'; } result += words[j] + ' '; spaceLeft = wordWrapWidth - wordWidth; } else { spaceLeft -= wordWidthWithSpace; result += words[j]; if (j < (words.length - 1)) { result += ' '; } } } if (i < lines.length - 1) { result += '\n'; } } return result; }, /** * Runs the given text through this Text objects word wrapping and returns the results as an * array, where each element of the array corresponds to a wrapped line of text. * * @method Phaser.GameObjects.Text#getWrappedText * @since 3.0.0 * * @param {string} text - The text for which the wrapping will be calculated. If unspecified, the Text objects current text will be used. * * @return {string[]} An array of strings with the pieces of wrapped text. */ getWrappedText: function (text) { if (text === undefined) { text = this.text; } this.style.syncFont(this.canvas, this.context); var wrappedLines = this.runWordWrap(text); return wrappedLines.split(this.splitRegExp); }, /** * [description] * * @method Phaser.GameObjects.Text#setText * @since 3.0.0 * * @param {(string|string[])} value - The string, or array of strings, to be set as the content of this Text object. * * @return {Phaser.GameObjects.Text} This Text object. */ setText: function (value) { if (!value && value !== 0) { value = ''; } if (Array.isArray(value)) { value = value.join('\n'); } if (value !== this.text) { this.text = value.toString(); this.updateText(); } return this; }, /** * [description] * * @method Phaser.GameObjects.Text#setStyle * @since 3.0.0 * * @param {object} style - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setStyle: function (style) { return this.style.setStyle(style); }, /** * [description] * * @method Phaser.GameObjects.Text#setFont * @since 3.0.0 * * @param {string} font - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setFont: function (font) { return this.style.setFont(font); }, /** * [description] * * @method Phaser.GameObjects.Text#setFontFamily * @since 3.0.0 * * @param {string} family - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setFontFamily: function (family) { return this.style.setFontFamily(family); }, /** * [description] * * @method Phaser.GameObjects.Text#setFontSize * @since 3.0.0 * * @param {number} size - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setFontSize: function (size) { return this.style.setFontSize(size); }, /** * [description] * * @method Phaser.GameObjects.Text#setFontStyle * @since 3.0.0 * * @param {string} style - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setFontStyle: function (style) { return this.style.setFontStyle(style); }, /** * [description] * * @method Phaser.GameObjects.Text#setFixedSize * @since 3.0.0 * * @param {number} width - [description] * @param {number} height - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setFixedSize: function (width, height) { return this.style.setFixedSize(width, height); }, /** * [description] * * @method Phaser.GameObjects.Text#setBackgroundColor * @since 3.0.0 * * @param {string} color - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setBackgroundColor: function (color) { return this.style.setBackgroundColor(color); }, /** * [description] * * @method Phaser.GameObjects.Text#setFill * @since 3.0.0 * * @param {string} color - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setFill: function (color) { return this.style.setFill(color); }, /** * [description] * * @method Phaser.GameObjects.Text#setColor * @since 3.0.0 * * @param {string} color - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setColor: function (color) { return this.style.setColor(color); }, /** * [description] * * @method Phaser.GameObjects.Text#setStroke * @since 3.0.0 * * @param {string} color - [description] * @param {number} thickness - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setStroke: function (color, thickness) { return this.style.setStroke(color, thickness); }, /** * [description] * * @method Phaser.GameObjects.Text#setShadow * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * @param {string} color - [description] * @param {number} blur - [description] * @param {boolean} shadowStroke - [description] * @param {boolean} shadowFill - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setShadow: function (x, y, color, blur, shadowStroke, shadowFill) { return this.style.setShadow(x, y, color, blur, shadowStroke, shadowFill); }, /** * [description] * * @method Phaser.GameObjects.Text#setShadowOffset * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setShadowOffset: function (x, y) { return this.style.setShadowOffset(x, y); }, /** * [description] * * @method Phaser.GameObjects.Text#setShadowColor * @since 3.0.0 * * @param {string} color - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setShadowColor: function (color) { return this.style.setShadowColor(color); }, /** * [description] * * @method Phaser.GameObjects.Text#setShadowBlur * @since 3.0.0 * * @param {number} blur - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setShadowBlur: function (blur) { return this.style.setShadowBlur(blur); }, /** * [description] * * @method Phaser.GameObjects.Text#setShadowStroke * @since 3.0.0 * * @param {boolean} enabled - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setShadowStroke: function (enabled) { return this.style.setShadowStroke(enabled); }, /** * [description] * * @method Phaser.GameObjects.Text#setShadowFill * @since 3.0.0 * * @param {boolean} enabled - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setShadowFill: function (enabled) { return this.style.setShadowFill(enabled); }, /** * Set the width (in pixels) to use for wrapping lines. Pass in null to remove wrapping by width. * * @method Phaser.GameObjects.Text#setWordWrapWidth * @since 3.0.0 * * @param {?number} width - The maximum width of a line in pixels. Set to null to remove wrapping. * @param {boolean} [useAdvancedWrap=false] - Whether or not to use the advanced wrapping * algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false, * spaces and whitespace are left as is. * * @return {Phaser.GameObjects.Text} This Text object. */ setWordWrapWidth: function (width, useAdvancedWrap) { return this.style.setWordWrapWidth(width, useAdvancedWrap); }, /** * Set a custom callback for wrapping lines. Pass in null to remove wrapping by callback. * * @method Phaser.GameObjects.Text#setWordWrapCallback * @since 3.0.0 * * @param {TextStyleWordWrapCallback} callback - A custom function that will be responsible for wrapping the * text. It will receive two arguments: text (the string to wrap), textObject (this Text * instance). It should return the wrapped lines either as an array of lines or as a string with * newline characters in place to indicate where breaks should happen. * @param {object} [scope=null] - The scope that will be applied when the callback is invoked. * * @return {Phaser.GameObjects.Text} This Text object. */ setWordWrapCallback: function (callback, scope) { return this.style.setWordWrapCallback(callback, scope); }, /** * [description] * * @method Phaser.GameObjects.Text#setAlign * @since 3.0.0 * * @param {string} align - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setAlign: function (align) { return this.style.setAlign(align); }, /** * 'left' can be an object. * If only 'left' and 'top' are given they are treated as 'x' and 'y' * * @method Phaser.GameObjects.Text#setPadding * @since 3.0.0 * * @param {(number|object)} left - [description] * @param {number} top - [description] * @param {number} right - [description] * @param {number} bottom - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setPadding: function (left, top, right, bottom) { if (typeof left === 'object') { var config = left; // If they specify x and/or y this applies to all var x = GetValue(config, 'x', null); if (x !== null) { left = x; right = x; } else { left = GetValue(config, 'left', 0); right = GetValue(config, 'right', left); } var y = GetValue(config, 'y', null); if (y !== null) { top = y; bottom = y; } else { top = GetValue(config, 'top', 0); bottom = GetValue(config, 'bottom', top); } } else { if (left === undefined) { left = 0; } if (top === undefined) { top = left; } if (right === undefined) { right = left; } if (bottom === undefined) { bottom = top; } } this.padding.left = left; this.padding.top = top; this.padding.right = right; this.padding.bottom = bottom; return this.updateText(); }, /** * [description] * * @method Phaser.GameObjects.Text#setMaxLines * @since 3.0.0 * * @param {integer} [max=0] - [description] * * @return {Phaser.GameObjects.Text} This Text object. */ setMaxLines: function (max) { return this.style.setMaxLines(max); }, /** * [description] * * @method Phaser.GameObjects.Text#updateText * @since 3.0.0 * * @return {Phaser.GameObjects.Text} This Text object. */ updateText: function () { var canvas = this.canvas; var context = this.context; var style = this.style; var resolution = this.resolution; var size = style.metrics; style.syncFont(canvas, context); var outputText = this.text; if (style.wordWrapWidth || style.wordWrapCallback) { outputText = this.runWordWrap(this.text); } // Split text into lines var lines = outputText.split(this.splitRegExp); var textSize = GetTextSize(this, size, lines); var padding = this.padding; var w = textSize.width + padding.left + padding.right; var h = textSize.height + padding.top + padding.bottom; if (style.fixedWidth === 0) { this.width = w; } if (style.fixedHeight === 0) { this.height = h; } this.updateDisplayOrigin(); w *= resolution; h *= resolution; w = Math.max(w, 1); h = Math.max(h, 1); if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; style.syncFont(canvas, context); // Resizing resets the context } else { context.clearRect(0, 0, w, h); } context.save(); // context.scale(resolution, resolution); if (style.backgroundColor) { context.fillStyle = style.backgroundColor; context.fillRect(0, 0, w, h); } style.syncStyle(canvas, context); context.textBaseline = 'alphabetic'; // Apply padding context.translate(padding.left, padding.top); var linePositionX; var linePositionY; // Draw text line by line for (var i = 0; i < textSize.lines; i++) { linePositionX = style.strokeThickness / 2; linePositionY = (style.strokeThickness / 2 + i * textSize.lineHeight) + size.ascent; if (i > 0) { linePositionY += (textSize.lineSpacing * i); } if (style.rtl) { linePositionX = w - linePositionX; } else if (style.align === 'right') { linePositionX += textSize.width - textSize.lineWidths[i]; } else if (style.align === 'center') { linePositionX += (textSize.width - textSize.lineWidths[i]) / 2; } if (this.autoRound) { linePositionX = Math.round(linePositionX); linePositionY = Math.round(linePositionY); } if (style.strokeThickness) { this.style.syncShadow(context, style.shadowStroke); context.strokeText(lines[i], linePositionX, linePositionY); } if (style.color) { this.style.syncShadow(context, style.shadowFill); context.fillText(lines[i], linePositionX, linePositionY); } } context.restore(); this.dirty = true; return this; }, /** * [description] * * @method Phaser.GameObjects.Text#getTextMetrics * @since 3.0.0 * * @return {object} [description] */ getTextMetrics: function () { return this.style.getTextMetrics(); }, /** * [description] * * @method Phaser.GameObjects.Text#toJSON * @since 3.0.0 * * @return {JSONGameObject} A JSON representation of the Game Object. */ toJSON: function () { var out = Components.ToJSON(this); // Extra Text data is added here var data = { autoRound: this.autoRound, text: this.text, style: this.style.toJSON(), resolution: this.resolution, padding: { left: this.padding.left, right: this.padding.right, top: this.padding.top, bottom: this.padding.bottom } }; out.data = data; return out; }, /** * Internal destroy handler, called as part of the destroy process. * * @method Phaser.GameObjects.Text#preDestroy * @protected * @since 3.0.0 */ preDestroy: function () { if (this.style.rtl) { RemoveFromDOM(this.canvas); } CanvasPool.remove(this.canvas); } }); module.exports = Text; /***/ }), /* 111 */, /* 112 */, /* 113 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); /** * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse based on the given angle. * * @function Phaser.Geom.Ellipse.CircumferencePoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to get the circumference point on. * @param {number} angle - The angle from the center of the Ellipse to the circumference to return the point from. Given in radians. * @param {(Phaser.Geom.Point|object)} [out] - A Point, or point-like object, to store the results in. If not given a Point will be created. * * @return {(Phaser.Geom.Point|object)} A Point object where the `x` and `y` properties are the point on the circumference. */ var CircumferencePoint = function (ellipse, angle, out) { if (out === undefined) { out = new Point(); } var halfWidth = ellipse.width / 2; var halfHeight = ellipse.height / 2; out.x = ellipse.x + halfWidth * Math.cos(angle); out.y = ellipse.y + halfHeight * Math.sin(angle); return out; }; module.exports = CircumferencePoint; /***/ }), /* 114 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Contains = __webpack_require__(54); var GetPoint = __webpack_require__(179); var GetPoints = __webpack_require__(178); var Random = __webpack_require__(134); /** * @classdesc * An Ellipse object. * * This is a geometry object, containing numerical values and related methods to inspect and modify them. * It is not a Game Object, in that you cannot add it to the display list, and it has no texture. * To render an Ellipse you should look at the capabilities of the Graphics class. * * @class Ellipse * @memberOf Phaser.Geom * @constructor * @since 3.0.0 * * @param {number} [x=0] - The x position of the center of the ellipse. * @param {number} [y=0] - The y position of the center of the ellipse. * @param {number} [width=0] - The width of the ellipse. * @param {number} [height=0] - The height of the ellipse. */ var Ellipse = new Class({ initialize: function Ellipse (x, y, width, height) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = 0; } if (height === undefined) { height = 0; } /** * The x position of the center of the ellipse. * * @name Phaser.Geom.Ellipse#x * @type {number} * @default 0 * @since 3.0.0 */ this.x = x; /** * The y position of the center of the ellipse. * * @name Phaser.Geom.Ellipse#y * @type {number} * @default 0 * @since 3.0.0 */ this.y = y; /** * The width of the ellipse. * * @name Phaser.Geom.Ellipse#width * @type {number} * @default 0 * @since 3.0.0 */ this.width = width; /** * The height of the ellipse. * * @name Phaser.Geom.Ellipse#height * @type {number} * @default 0 * @since 3.0.0 */ this.height = height; }, /** * Check to see if the Ellipse contains the given x / y coordinates. * * @method Phaser.Geom.Ellipse#contains * @since 3.0.0 * * @param {number} x - The x coordinate to check within the ellipse. * @param {number} y - The y coordinate to check within the ellipse. * * @return {boolean} True if the coordinates are within the ellipse, otherwise false. */ contains: function (x, y) { return Contains(this, x, y); }, /** * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point * at 180 degrees around the circle. * * @method Phaser.Geom.Ellipse#getPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {float} position - A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the ellipse. * @param {(Phaser.Geom.Point|object)} [out] - An object to store the return values in. If not given a Point object will be created. * * @return {(Phaser.Geom.Point|object)} A Point, or point-like object, containing the coordinates of the point around the ellipse. */ getPoint: function (position, point) { return GetPoint(this, position, point); }, /** * Returns an array of Point objects containing the coordinates of the points around the circumference of the Ellipse, * based on the given quantity or stepRate values. * * @method Phaser.Geom.Ellipse#getPoints * @since 3.0.0 * * @param {integer} quantity - The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. * @param {number} [stepRate] - Sets the quantity by getting the circumference of the ellipse and dividing it by the stepRate. * @param {array} [output] - An array to insert the points in to. If not provided a new array will be created. * * @return {Phaser.Geom.Point[]} An array of Point objects pertaining to the points around the circumference of the ellipse. */ getPoints: function (quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); }, /** * Returns a uniformly distributed random point from anywhere within the given Ellipse. * * @method Phaser.Geom.Ellipse#getRandomPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [point,$return] * * @param {(Phaser.Geom.Point|object)} [point] - A Point or point-like object to set the random `x` and `y` values in. * * @return {(Phaser.Geom.Point|object)} A Point object with the random values set in the `x` and `y` properties. */ getRandomPoint: function (point) { return Random(this, point); }, /** * Sets the x, y, width and height of this ellipse. * * @method Phaser.Geom.Ellipse#setTo * @since 3.0.0 * * @param {number} x - The x position of the center of the ellipse. * @param {number} y - The y position of the center of the ellipse. * @param {number} width - The width of the ellipse. * @param {number} height - The height of the ellipse. * * @return {Phaser.Geom.Ellipse} This Ellipse object. */ setTo: function (x, y, width, height) { this.x = x; this.y = y; this.width = width; this.height = height; return this; }, /** * Sets this Ellipse to be empty with a width and height of zero. * Does not change its position. * * @method Phaser.Geom.Ellipse#setEmpty * @since 3.0.0 * * @return {Phaser.Geom.Ellipse} This Ellipse object. */ setEmpty: function () { this.width = 0; this.height = 0; return this; }, /** * Sets the position of this Ellipse. * * @method Phaser.Geom.Ellipse#setPosition * @since 3.0.0 * * @param {number} x - The x position of the center of the ellipse. * @param {number} y - The y position of the center of the ellipse. * * @return {Phaser.Geom.Ellipse} This Ellipse object. */ setPosition: function (x, y) { if (y === undefined) { y = x; } this.x = x; this.y = y; return this; }, /** * Sets the size of this Ellipse. * Does not change its position. * * @method Phaser.Geom.Ellipse#setSize * @since 3.0.0 * * @param {number} width - The width of the ellipse. * @param {number} [height=width] - The height of the ellipse. * * @return {Phaser.Geom.Ellipse} This Ellipse object. */ setSize: function (width, height) { if (height === undefined) { height = width; } this.width = width; this.height = height; return this; }, /** * Checks to see if the Ellipse is empty: has a width or height equal to zero. * * @method Phaser.Geom.Ellipse#isEmpty * @since 3.0.0 * * @return {boolean} True if the Ellipse is empty, otherwise false. */ isEmpty: function () { return (this.width <= 0 || this.height <= 0); }, /** * Returns the minor radius of the ellipse. Also known as the Semi Minor Axis. * * @method Phaser.Geom.Ellipse#getMinorRadius * @since 3.0.0 * * @return {number} The minor radius. */ getMinorRadius: function () { return Math.min(this.width, this.height) / 2; }, /** * Returns the major radius of the ellipse. Also known as the Semi Major Axis. * * @method Phaser.Geom.Ellipse#getMajorRadius * @since 3.0.0 * * @return {number} The major radius. */ getMajorRadius: function () { return Math.max(this.width, this.height) / 2; }, /** * The left position of the Ellipse. * * @name Phaser.Geom.Ellipse#left * @type {number} * @since 3.0.0 */ left: { get: function () { return this.x - (this.width / 2); }, set: function (value) { this.x = value + (this.width / 2); } }, /** * The right position of the Ellipse. * * @name Phaser.Geom.Ellipse#right * @type {number} * @since 3.0.0 */ right: { get: function () { return this.x + (this.width / 2); }, set: function (value) { this.x = value - (this.width / 2); } }, /** * The top position of the Ellipse. * * @name Phaser.Geom.Ellipse#top * @type {number} * @since 3.0.0 */ top: { get: function () { return this.y - (this.height / 2); }, set: function (value) { this.y = value + (this.height / 2); } }, /** * The bottom position of the Ellipse. * * @name Phaser.Geom.Ellipse#bottom * @type {number} * @since 3.0.0 */ bottom: { get: function () { return this.y + (this.height / 2); }, set: function (value) { this.y = value - (this.height / 2); } } }); module.exports = Ellipse; /***/ }), /* 115 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Camera = __webpack_require__(123); var Class = __webpack_require__(0); var Commands = __webpack_require__(119); var Components = __webpack_require__(15); var Ellipse = __webpack_require__(249); var GameObject = __webpack_require__(2); var GetValue = __webpack_require__(4); var MATH_CONST = __webpack_require__(16); var Render = __webpack_require__(463); /** * Graphics line style (or stroke style) settings. * * @typedef {object} GraphicsLineStyle * * @property {number} width - The stroke width. * @property {number} color - The stroke color. * @property {number} alpha - The stroke alpha. */ /** * Graphics fill style settings. * * @typedef {object} GraphicsFillStyle * * @property {number} color - The fill color. * @property {number} alpha - The fill alpha. */ /** * Graphics style settings. * * @typedef {object} GraphicsStyles * * @property {GraphicsLineStyle} lineStyle - The style applied to shape outlines. * @property {GraphicsFillStyle} fillStyle - The style applied to shape areas. */ /** * Options for the Graphics game Object. * * @typedef {object} GraphicsOptions * @extends GraphicsStyles * * @property {number} x - The x coordinate of the Graphics. * @property {number} y - The y coordinate of the Graphics. */ /** * @classdesc * A Graphics object is a way to draw primitive shapes to you game. Primitives include forms of geometry, such as * Rectangles, Circles, and Polygons. They also include lines, arcs and curves. When you initially create a Graphics * object it will be empty. * * To draw to it you must first specify a line style or fill style (or both), draw shapes using paths, and finally * fill or stroke them. For example: * * ```javascript * graphics.lineStyle(5, 0xFF00FF, 1.0); * graphics.beginPath(); * graphics.moveTo(100, 100); * graphics.lineTo(200, 200); * graphics.closePath(); * graphics.strokePath(); * ``` * * There are also many helpful methods that draw and fill/stroke common shapes for you. * * ```javascript * graphics.lineStyle(5, 0xFF00FF, 1.0); * graphics.fillStyle(0xFFFFFF, 1.0); * graphics.fillRect(50, 50, 400, 200); * graphics.strokeRect(50, 50, 400, 200); * ``` * * When a Graphics object is rendered it will render differently based on if the game is running under Canvas or WebGL. * Under Canvas it will use the HTML Canvas context drawing operations to draw the path. * Under WebGL the graphics data is decomposed into polygons. Both of these are expensive processes, especially with * complex shapes. * * If your Graphics object doesn't change much (or at all) once you've drawn your shape to it, then you will help * performance by calling {@link Phaser.GameObjects.Graphics#generateTexture}. This will 'bake' the Graphics object into * a Texture, and return it. You can then use this Texture for Sprites or other display objects. If your Graphics object * updates frequently then you should avoid doing this, as it will constantly generate new textures, which will consume * memory. * * As you can tell, Graphics objects are a bit of a trade-off. While they are extremely useful, you need to be careful * in their complexity and quantity of them in your game. * * @class Graphics * @extends Phaser.GameObjects.GameObject * @memberOf Phaser.GameObjects * @constructor * @since 3.0.0 * * @extends Phaser.GameObjects.Components.Alpha * @extends Phaser.GameObjects.Components.BlendMode * @extends Phaser.GameObjects.Components.Depth * @extends Phaser.GameObjects.Components.Mask * @extends Phaser.GameObjects.Components.Pipeline * @extends Phaser.GameObjects.Components.Transform * @extends Phaser.GameObjects.Components.Visible * @extends Phaser.GameObjects.Components.ScrollFactor * * @param {Phaser.Scene} scene - The Scene to which this Graphics object belongs. * @param {GraphicsOptions} options - Options that set the position and default style of this Graphics object. */ var Graphics = new Class({ Extends: GameObject, Mixins: [ Components.Alpha, Components.BlendMode, Components.Depth, Components.Mask, Components.Pipeline, Components.Transform, Components.Visible, Components.ScrollFactor, Render ], initialize: function Graphics (scene, options) { var x = GetValue(options, 'x', 0); var y = GetValue(options, 'y', 0); GameObject.call(this, scene, 'Graphics'); this.setPosition(x, y); this.initPipeline('FlatTintPipeline'); /** * The horizontal display origin of the Graphics. * * @name Phaser.GameObjects.Graphics#displayOriginX * @type {number} * @default 0 * @since 3.0.0 */ this.displayOriginX = 0; /** * The vertical display origin of the Graphics. * * @name Phaser.GameObjects.Graphics#displayOriginY * @type {number} * @default 0 * @since 3.0.0 */ this.displayOriginY = 0; /** * The array of commands used to render the Graphics. * * @name Phaser.GameObjects.Graphics#commandBuffer * @type {array} * @default [] * @since 3.0.0 */ this.commandBuffer = []; /** * The default fill color for shapes rendered by this Graphics object. * * @name Phaser.GameObjects.Graphics#defaultFillColor * @type {number} * @default -1 * @since 3.0.0 */ this.defaultFillColor = -1; /** * The default fill alpha for shapes rendered by this Graphics object. * * @name Phaser.GameObjects.Graphics#defaultFillAlpha * @type {number} * @default 1 * @since 3.0.0 */ this.defaultFillAlpha = 1; /** * The default stroke width for shapes rendered by this Graphics object. * * @name Phaser.GameObjects.Graphics#defaultStrokeWidth * @type {number} * @default 1 * @since 3.0.0 */ this.defaultStrokeWidth = 1; /** * The default stroke color for shapes rendered by this Graphics object. * * @name Phaser.GameObjects.Graphics#defaultStrokeColor * @type {number} * @default -1 * @since 3.0.0 */ this.defaultStrokeColor = -1; /** * The default stroke alpha for shapes rendered by this Graphics object. * * @name Phaser.GameObjects.Graphics#defaultStrokeAlpha * @type {number} * @default 1 * @since 3.0.0 */ this.defaultStrokeAlpha = 1; /** * Internal property that keeps track of the line width style setting. * * @name Phaser.GameObjects.Graphics#_lineWidth * @type {number} * @private * @since 3.0.0 */ this._lineWidth = 1.0; this.setDefaultStyles(options); }, /** * Set the default style settings for this Graphics object. * * @method Phaser.GameObjects.Graphics#setDefaultStyles * @since 3.0.0 * * @param {GraphicsStyles} options - The styles to set as defaults. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ setDefaultStyles: function (options) { if (GetValue(options, 'lineStyle', null)) { this.defaultStrokeWidth = GetValue(options, 'lineStyle.width', 1); this.defaultStrokeColor = GetValue(options, 'lineStyle.color', 0xffffff); this.defaultStrokeAlpha = GetValue(options, 'lineStyle.alpha', 1); this.lineStyle(this.defaultStrokeWidth, this.defaultStrokeColor, this.defaultStrokeAlpha); } if (GetValue(options, 'fillStyle', null)) { this.defaultFillColor = GetValue(options, 'fillStyle.color', 0xffffff); this.defaultFillAlpha = GetValue(options, 'fillStyle.alpha', 1); this.fillStyle(this.defaultFillColor, this.defaultFillAlpha); } return this; }, /** * Set the current line style. * * @method Phaser.GameObjects.Graphics#lineStyle * @since 3.0.0 * * @param {number} lineWidth - The stroke width. * @param {number} color - The stroke color. * @param {number} [alpha=1] - The stroke alpha. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ lineStyle: function (lineWidth, color, alpha) { if (alpha === undefined) { alpha = 1; } this.commandBuffer.push( Commands.LINE_STYLE, lineWidth, color, alpha ); this._lineWidth = lineWidth; return this; }, /** * Set the current fill style. * * @method Phaser.GameObjects.Graphics#fillStyle * @since 3.0.0 * * @param {number} color - The fill color. * @param {number} [alpha=1] - The fill alpha. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillStyle: function (color, alpha) { if (alpha === undefined) { alpha = 1; } this.commandBuffer.push( Commands.FILL_STYLE, color, alpha ); return this; }, /** * Start a new shape path. * * @method Phaser.GameObjects.Graphics#beginPath * @since 3.0.0 * * @return {Phaser.GameObjects.Graphics} This Game Object. */ beginPath: function () { this.commandBuffer.push( Commands.BEGIN_PATH ); return this; }, /** * Close the current path. * * @method Phaser.GameObjects.Graphics#closePath * @since 3.0.0 * * @return {Phaser.GameObjects.Graphics} This Game Object. */ closePath: function () { this.commandBuffer.push( Commands.CLOSE_PATH ); return this; }, /** * Fill the current path. * * @method Phaser.GameObjects.Graphics#fillPath * @since 3.0.0 * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillPath: function () { this.commandBuffer.push( Commands.FILL_PATH ); return this; }, /** * Stroke the current path. * * @method Phaser.GameObjects.Graphics#strokePath * @since 3.0.0 * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokePath: function () { this.commandBuffer.push( Commands.STROKE_PATH ); return this; }, /** * Fill the given circle. * * @method Phaser.GameObjects.Graphics#fillCircleShape * @since 3.0.0 * * @param {Phaser.Geom.Circle} circle - The circle to fill. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillCircleShape: function (circle) { return this.fillCircle(circle.x, circle.y, circle.radius); }, /** * Stroke the given circle. * * @method Phaser.GameObjects.Graphics#strokeCircleShape * @since 3.0.0 * * @param {Phaser.Geom.Circle} circle - The circle to stroke. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeCircleShape: function (circle) { return this.strokeCircle(circle.x, circle.y, circle.radius); }, /** * Fill a circle with the given position and radius. * * @method Phaser.GameObjects.Graphics#fillCircle * @since 3.0.0 * * @param {number} x - The x coordinate of the center of the circle. * @param {number} y - The y coordinate of the center of the circle. * @param {number} radius - The radius of the circle. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillCircle: function (x, y, radius) { this.beginPath(); this.arc(x, y, radius, 0, MATH_CONST.PI2); this.fillPath(); return this; }, /** * Stroke a circle with the given position and radius. * * @method Phaser.GameObjects.Graphics#strokeCircle * @since 3.0.0 * * @param {number} x - The x coordinate of the center of the circle. * @param {number} y - The y coordinate of the center of the circle. * @param {number} radius - The radius of the circle. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeCircle: function (x, y, radius) { this.beginPath(); this.arc(x, y, radius, 0, MATH_CONST.PI2); this.strokePath(); return this; }, /** * Fill the given rectangle. * * @method Phaser.GameObjects.Graphics#fillRectShape * @since 3.0.0 * * @param {Phaser.Geom.Rectangle} rect - The rectangle to fill. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillRectShape: function (rect) { return this.fillRect(rect.x, rect.y, rect.width, rect.height); }, /** * Stroke the given rectangle. * * @method Phaser.GameObjects.Graphics#strokeRectShape * @since 3.0.0 * * @param {Phaser.Geom.Rectangle} rect - The rectangle to stroke. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeRectShape: function (rect) { return this.strokeRect(rect.x, rect.y, rect.width, rect.height); }, /** * Fill a rectangle with the given position and size. * * @method Phaser.GameObjects.Graphics#fillRect * @since 3.0.0 * * @param {number} x - The x coordinate of the top-left of the rectangle. * @param {number} y - The y coordinate of the top-left of the rectangle. * @param {number} width - The width of the rectangle. * @param {number} height - The height of the rectangle. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillRect: function (x, y, width, height) { this.commandBuffer.push( Commands.FILL_RECT, x, y, width, height ); return this; }, /** * Stroke a rectangle with the given position and size. * * @method Phaser.GameObjects.Graphics#strokeRect * @since 3.0.0 * * @param {number} x - The x coordinate of the top-left of the rectangle. * @param {number} y - The y coordinate of the top-left of the rectangle. * @param {number} width - The width of the rectangle. * @param {number} height - The height of the rectangle. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeRect: function (x, y, width, height) { var lineWidthHalf = this._lineWidth / 2; var minx = x - lineWidthHalf; var maxx = x + lineWidthHalf; this.beginPath(); this.moveTo(x, y); this.lineTo(x, y + height); this.strokePath(); this.beginPath(); this.moveTo(x + width, y); this.lineTo(x + width, y + height); this.strokePath(); this.beginPath(); this.moveTo(minx, y); this.lineTo(maxx + width, y); this.strokePath(); this.beginPath(); this.moveTo(minx, y + height); this.lineTo(maxx + width, y + height); this.strokePath(); return this; }, /** * Fill the given point. * * Draws a square at the given position, 1 pixel in size by default. * * @method Phaser.GameObjects.Graphics#fillPointShape * @since 3.0.0 * * @param {(Phaser.Geom.Point|Phaser.Math.Vector2|object)} point - The point to fill. * @param {number} [size=1] - The size of the square to draw. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillPointShape: function (point, size) { return this.fillPoint(point.x, point.y, size); }, /** * Fill a point at the given position. * * Draws a square at the given position, 1 pixel in size by default. * * @method Phaser.GameObjects.Graphics#fillPoint * @since 3.0.0 * * @param {number} x - The x coordinate of the point. * @param {number} y - The y coordinate of the point. * @param {number} [size=1] - The size of the square to draw. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillPoint: function (x, y, size) { if (!size || size < 1) { size = 1; } else { x -= (size / 2); y -= (size / 2); } this.commandBuffer.push( Commands.FILL_RECT, x, y, size, size ); return this; }, /** * Fill the given triangle. * * @method Phaser.GameObjects.Graphics#fillTriangleShape * @since 3.0.0 * * @param {Phaser.Geom.Triangle} triangle - The triangle to fill. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillTriangleShape: function (triangle) { return this.fillTriangle(triangle.x1, triangle.y1, triangle.x2, triangle.y2, triangle.x3, triangle.y3); }, /** * Stroke the given triangle. * * @method Phaser.GameObjects.Graphics#strokeTriangleShape * @since 3.0.0 * * @param {Phaser.Geom.Triangle} triangle - The triangle to stroke. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeTriangleShape: function (triangle) { return this.strokeTriangle(triangle.x1, triangle.y1, triangle.x2, triangle.y2, triangle.x3, triangle.y3); }, /** * Fill a triangle with the given points. * * @method Phaser.GameObjects.Graphics#fillTriangle * @since 3.0.0 * * @param {number} x0 - The x coordinate of the first point. * @param {number} y0 - The y coordinate of the first point. * @param {number} x1 - The x coordinate of the second point. * @param {number} y1 - The y coordinate of the second point. * @param {number} x2 - The x coordinate of the third point. * @param {number} y2 - The y coordinate of the third point. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillTriangle: function (x0, y0, x1, y1, x2, y2) { this.commandBuffer.push( Commands.FILL_TRIANGLE, x0, y0, x1, y1, x2, y2 ); return this; }, /** * Stroke a triangle with the given points. * * @method Phaser.GameObjects.Graphics#strokeTriangle * @since 3.0.0 * * @param {number} x0 - The x coordinate of the first point. * @param {number} y0 - The y coordinate of the first point. * @param {number} x1 - The x coordinate of the second point. * @param {number} y1 - The y coordinate of the second point. * @param {number} x2 - The x coordinate of the third point. * @param {number} y2 - The y coordinate of the third point. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeTriangle: function (x0, y0, x1, y1, x2, y2) { this.commandBuffer.push( Commands.STROKE_TRIANGLE, x0, y0, x1, y1, x2, y2 ); return this; }, /** * Draw the given line. * * @method Phaser.GameObjects.Graphics#strokeLineShape * @since 3.0.0 * * @param {Phaser.Geom.Line} line - The line to stroke. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeLineShape: function (line) { return this.lineBetween(line.x1, line.y1, line.x2, line.y2); }, /** * Draw a line between the given points. * * @method Phaser.GameObjects.Graphics#lineBetween * @since 3.0.0 * * @param {number} x1 - The x coordinate of the start point of the line. * @param {number} y1 - The y coordinate of the start point of the line. * @param {number} x2 - The x coordinate of the end point of the line. * @param {number} y2 - The y coordinate of the end point of the line. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ lineBetween: function (x1, y1, x2, y2) { this.beginPath(); this.moveTo(x1, y1); this.lineTo(x2, y2); this.strokePath(); return this; }, /** * Draw a line from the current drawing position to the given position. * * Moves the current drawing position to the given position. * * @method Phaser.GameObjects.Graphics#lineTo * @since 3.0.0 * * @param {number} x - The x coordinate to draw the line to. * @param {number} y - The y coordinate to draw the line to. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ lineTo: function (x, y) { this.commandBuffer.push( Commands.LINE_TO, x, y ); return this; }, /** * Move the current drawing position to the given position. * * @method Phaser.GameObjects.Graphics#moveTo * @since 3.0.0 * * @param {number} x - The x coordinate to move to. * @param {number} y - The y coordinate to move to. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ moveTo: function (x, y) { this.commandBuffer.push( Commands.MOVE_TO, x, y ); return this; }, /** * [description] * * @method Phaser.GameObjects.Graphics#lineFxTo * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * @param {number} width - [description] * @param {number} rgb - [description] * * @return {Phaser.GameObjects.Graphics} This Game Object. */ lineFxTo: function (x, y, width, rgb) { this.commandBuffer.push( Commands.LINE_FX_TO, x, y, width, rgb, 1 ); return this; }, /** * [description] * * @method Phaser.GameObjects.Graphics#moveFxTo * @since 3.0.0 * * @param {number} x - [description] * @param {number} y - [description] * @param {number} width - [description] * @param {number} rgb - [description] * * @return {Phaser.GameObjects.Graphics} This Game Object. */ moveFxTo: function (x, y, width, rgb) { this.commandBuffer.push( Commands.MOVE_FX_TO, x, y, width, rgb, 1 ); return this; }, /** * Stroke the shape represented by the given array of points. * * Pass `true` to `autoClose` to close the shape automatically. * * @method Phaser.GameObjects.Graphics#strokePoints * @since 3.0.0 * * @param {(array|Phaser.Geom.Point[])} points - The points to stroke. * @param {boolean} [autoClose=false] - When `true`, the shape is closed by joining the last point to the first point. * @param {integer} [endIndex] - The index of `points` to stop drawing at. Defaults to `points.length`. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokePoints: function (points, autoClose, endIndex) { if (autoClose === undefined) { autoClose = false; } if (endIndex === undefined) { endIndex = points.length; } this.beginPath(); this.moveTo(points[0].x, points[0].y); for (var i = 1; i < endIndex; i++) { this.lineTo(points[i].x, points[i].y); } if (autoClose) { this.lineTo(points[0].x, points[0].y); } this.strokePath(); return this; }, /** * Fill the shape represented by the given array of points. * * Pass `true` to `autoClose` to close the shape automatically. * * @method Phaser.GameObjects.Graphics#fillPoints * @since 3.0.0 * * @param {(array|Phaser.Geom.Point[])} points - The points to fill. * @param {boolean} [autoClose=false] - Whether to automatically close the polygon. * @param {integer} [endIndex] - The index of `points` to stop at. Defaults to `points.length`. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillPoints: function (points, autoClose, endIndex) { if (autoClose === undefined) { autoClose = false; } if (endIndex === undefined) { endIndex = points.length; } this.beginPath(); this.moveTo(points[0].x, points[0].y); for (var i = 1; i < endIndex; i++) { this.lineTo(points[i].x, points[i].y); } if (autoClose) { this.lineTo(points[0].x, points[0].y); } this.fillPath(); return this; }, /** * Stroke the given ellipse. * * @method Phaser.GameObjects.Graphics#strokeEllipseShape * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} ellipse - The ellipse to stroke. * @param {integer} [smoothness=32] - The number of points to draw the ellipse with. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeEllipseShape: function (ellipse, smoothness) { if (smoothness === undefined) { smoothness = 32; } var points = ellipse.getPoints(smoothness); return this.strokePoints(points, true); }, /** * Stroke an ellipse with the given position and size. * * @method Phaser.GameObjects.Graphics#strokeEllipse * @since 3.0.0 * * @param {number} x - The x coordinate of the center of the ellipse. * @param {number} y - The y coordinate of the center of the ellipse. * @param {number} width - The width of the ellipse. * @param {number} height - The height of the ellipse. * @param {integer} [smoothness=32] - The number of points to draw the ellipse with. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ strokeEllipse: function (x, y, width, height, smoothness) { if (smoothness === undefined) { smoothness = 32; } var ellipse = new Ellipse(x, y, width, height); var points = ellipse.getPoints(smoothness); return this.strokePoints(points, true); }, /** * Fill the given ellipse. * * @method Phaser.GameObjects.Graphics#fillEllipseShape * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} ellipse - The ellipse to fill. * @param {integer} [smoothness=32] - The number of points to draw the ellipse with. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillEllipseShape: function (ellipse, smoothness) { if (smoothness === undefined) { smoothness = 32; } var points = ellipse.getPoints(smoothness); return this.fillPoints(points, true); }, /** * Fill an ellipse with the given position and size. * * @method Phaser.GameObjects.Graphics#fillEllipse * @since 3.0.0 * * @param {number} x - The x coordinate of the center of the ellipse. * @param {number} y - The y coordinate of the center of the ellipse. * @param {number} width - The width of the ellipse. * @param {number} height - The height of the ellipse. * @param {integer} [smoothness=32] - The number of points to draw the ellipse with. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ fillEllipse: function (x, y, width, height, smoothness) { if (smoothness === undefined) { smoothness = 32; } var ellipse = new Ellipse(x, y, width, height); var points = ellipse.getPoints(smoothness); return this.fillPoints(points, true); }, /** * Draw an arc. * * This method can be used to create circles, or parts of circles. * * Call {@link Phaser.GameObjects.Graphics#fillPath} or {@link Phaser.GameObjects.Graphics#strokePath} after calling * this method to draw the arc. * * @method Phaser.GameObjects.Graphics#arc * @since 3.0.0 * * @param {number} x - The x coordinate of the center of the circle. * @param {number} y - The y coordinate of the center of the circle. * @param {number} radius - The radius of the circle. * @param {number} startAngle - The starting angle, in radians. * @param {number} endAngle - The ending angle, in radians. * @param {boolean} [anticlockwise=false] - Whether the drawing should be anticlockwise or clockwise. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ arc: function (x, y, radius, startAngle, endAngle, anticlockwise) { this.commandBuffer.push( Commands.ARC, x, y, radius, startAngle, endAngle, anticlockwise ); return this; }, /** * Creates a pie-chart slice shape centered at `x`, `y` with the given radius. * You must define the start and end angle of the slice. * * Setting the `anticlockwise` argument to `true` creates a shape similar to Pacman. * Setting it to `false` creates a shape like a slice of pie. * * This method will begin a new path and close the path at the end of it. * To display the actual slice you need to call either `strokePath` or `fillPath` after it. * * @method Phaser.GameObjects.Graphics#slice * @since 3.4.0 * * @param {number} x - The horizontal center of the slice. * @param {number} y - The vertical center of the slice. * @param {number} radius - The radius of the slice. * @param {number} startAngle - The start angle of the slice, given in radians. * @param {number} endAngle - The end angle of the slice, given in radians. * @param {boolean} [anticlockwise=false] - Draw the slice piece anticlockwise or clockwise? * * @return {Phaser.GameObjects.Graphics} This Game Object. */ slice: function (x, y, radius, startAngle, endAngle, anticlockwise) { if (anticlockwise === undefined) { anticlockwise = false; } this.commandBuffer.push(Commands.BEGIN_PATH); this.commandBuffer.push(Commands.MOVE_TO, x, y); this.commandBuffer.push(Commands.ARC, x, y, radius, startAngle, endAngle, anticlockwise); this.commandBuffer.push(Commands.CLOSE_PATH); return this; }, /** * [description] * * @method Phaser.GameObjects.Graphics#save * @since 3.0.0 * * @return {Phaser.GameObjects.Graphics} This Game Object. */ save: function () { this.commandBuffer.push( Commands.SAVE ); return this; }, /** * [description] * * @method Phaser.GameObjects.Graphics#restore * @since 3.0.0 * * @return {Phaser.GameObjects.Graphics} This Game Object. */ restore: function () { this.commandBuffer.push( Commands.RESTORE ); return this; }, /** * Translate the graphics. * * @method Phaser.GameObjects.Graphics#translate * @since 3.0.0 * * @param {number} x - The horizontal translation to apply. * @param {number} y - The vertical translation to apply. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ translate: function (x, y) { this.commandBuffer.push( Commands.TRANSLATE, x, y ); return this; }, /** * Scale the graphics. * * @method Phaser.GameObjects.Graphics#scale * @since 3.0.0 * * @param {number} x - The horizontal scale to apply. * @param {number} y - The vertical scale to apply. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ scale: function (x, y) { this.commandBuffer.push( Commands.SCALE, x, y ); return this; }, /** * Rotate the graphics. * * @method Phaser.GameObjects.Graphics#rotate * @since 3.0.0 * * @param {number} radians - The rotation angle, in radians. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ rotate: function (radians) { this.commandBuffer.push( Commands.ROTATE, radians ); return this; }, /** * Clear the command buffer and reset the fill style and line style to their defaults. * * @method Phaser.GameObjects.Graphics#clear * @since 3.0.0 * * @return {Phaser.GameObjects.Graphics} This Game Object. */ clear: function () { this.commandBuffer.length = 0; if (this.defaultFillColor > -1) { this.fillStyle(this.defaultFillColor, this.defaultFillAlpha); } if (this.defaultStrokeColor > -1) { this.lineStyle(this.defaultStrokeWidth, this.defaultStrokeColor, this.defaultStrokeAlpha); } return this; }, /** * Generate a texture from this Graphics object. * * If `key` is a string it'll generate a new texture using it and add it into the * Texture Manager (assuming no key conflict happens). * * If `key` is a Canvas it will draw the texture to that canvas context. Note that it will NOT * automatically upload it to the GPU in WebGL mode. * * @method Phaser.GameObjects.Graphics#generateTexture * @since 3.0.0 * * @param {(string|HTMLCanvasElement)} key - The key to store the texture with in the Texture Manager, or a Canvas to draw to. * @param {integer} [width] - The width of the graphics to generate. * @param {integer} [height] - The height of the graphics to generate. * * @return {Phaser.GameObjects.Graphics} This Game Object. */ generateTexture: function (key, width, height) { var sys = this.scene.sys; if (width === undefined) { width = sys.game.config.width; } if (height === undefined) { height = sys.game.config.height; } Graphics.TargetCamera.setViewport(0, 0, width, height); Graphics.TargetCamera.scrollX = this.x; Graphics.TargetCamera.scrollY = this.y; var texture; var ctx; if (typeof key === 'string') { if (sys.textures.exists(key)) { // Key is a string, it DOES exist in the Texture Manager AND is a canvas, so draw to it texture = sys.textures.get(key); var src = texture.getSourceImage(); if (src instanceof HTMLCanvasElement) { ctx = src.getContext('2d'); } } else { // Key is a string and doesn't exist in the Texture Manager, so generate and save it texture = sys.textures.createCanvas(key, width, height); ctx = texture.getSourceImage().getContext('2d'); } } else if (key instanceof HTMLCanvasElement) { // Key is a Canvas, so draw to it ctx = key.getContext('2d'); } if (ctx) { this.renderCanvas(sys.game.renderer, this, 0.0, Graphics.TargetCamera, null, ctx); if (sys.game.renderer.gl && texture) { texture.source[0].glTexture = sys.game.renderer.canvasToTexture(ctx.canvas, texture.source[0].glTexture); } } return this; }, /** * Internal destroy handler, called as part of the destroy process. * * @method Phaser.GameObjects.Graphics#preDestroy * @protected * @since 3.9.0 */ preDestroy: function () { this.commandBuffer = []; } }); /** * A Camera used specifically by the Graphics system for rendering to textures. * * @name Phaser.GameObjects.Graphics.TargetCamera * @type {Phaser.Cameras.Scene2D.Camera} * @since 3.1.0 */ Graphics.TargetCamera = new Camera(0, 0, 0, 0); module.exports = Graphics; /***/ }), /* 116 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * A Matrix is simply an array of arrays, where each sub-array (the rows) have the same length: * * let matrix2 = [ * [ 1, 1, 1, 1, 1, 1 ], * [ 2, 0, 0, 0, 0, 4 ], * [ 2, 0, 1, 2, 0, 4 ], * [ 2, 0, 3, 4, 0, 4 ], * [ 2, 0, 0, 0, 0, 4 ], * [ 3, 3, 3, 3, 3, 3 ] *]; */ /** * [description] * * @function Phaser.Utils.Array.Matrix.CheckMatrix * @since 3.0.0 * * @param {array} matrix - [description] * * @return {boolean} [description] */ var CheckMatrix = function (matrix) { if (!Array.isArray(matrix) || matrix.length < 2 || !Array.isArray(matrix[0])) { return false; } // How long is the first row? var size = matrix[0].length; // Validate the rest of the rows are the same length for (var i = 1; i < matrix.length; i++) { if (matrix[i].length !== size) { return false; } } return true; }; module.exports = CheckMatrix; /***/ }), /* 117 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Frame = __webpack_require__(128); var TextureSource = __webpack_require__(183); /** * @classdesc * A Texture consists of a source, usually an Image from the Cache, and a collection of Frames. * The Frames represent the different areas of the Texture. For example a texture atlas * may have many Frames, one for each element within the atlas. Where-as a single image would have * just one frame, that encompasses the whole image. * * Textures are managed by the global TextureManager. This is a singleton class that is * responsible for creating and delivering Textures and their corresponding Frames to Game Objects. * * Sprites and other Game Objects get the texture data they need from the TextureManager. * * @class Texture * @memberOf Phaser.Textures * @constructor * @since 3.0.0 * * @param {Phaser.Textures.TextureManager} manager - A reference to the Texture Manager this Texture belongs to. * @param {string} key - The unique string-based key of this Texture. * @param {(HTMLImageElement[]|HTMLCanvasElement[])} source - An array of sources that are used to create the texture. Usually Images, but can also be a Canvas. * @param {number} [width] - The width of the Texture. This is optional and automatically derived from the source images. * @param {number} [height] - The height of the Texture. This is optional and automatically derived from the source images. */ var Texture = new Class({ initialize: function Texture (manager, key, source, width, height) { if (!Array.isArray(source)) { source = [ source ]; } /** * A reference to the Texture Manager this Texture belongs to. * * @name Phaser.Textures.Texture#manager * @type {Phaser.Textures.TextureManager} * @since 3.0.0 */ this.manager = manager; /** * The unique string-based key of this Texture. * * @name Phaser.Textures.Texture#key * @type {string} * @since 3.0.0 */ this.key = key; /** * An array of TextureSource instances. * These are unique to this Texture and contain the actual Image (or Canvas) data. * * @name Phaser.Textures.Texture#source * @type {Phaser.Textures.TextureSource[]} * @since 3.0.0 */ this.source = []; /** * An array of TextureSource data instances. * Used to store additional data images, such as normal maps or specular maps. * * @name Phaser.Textures.Texture#dataSource * @type {array} * @since 3.0.0 */ this.dataSource = []; /** * A key-value object pair associating the unique Frame keys with the Frames objects. * * @name Phaser.Textures.Texture#frames * @type {object} * @since 3.0.0 */ this.frames = {}; /** * Any additional data that was set in the source JSON (if any), * or any extra data you'd like to store relating to this texture * * @name Phaser.Textures.Texture#customData * @type {object} * @since 3.0.0 */ this.customData = {}; /** * The name of the first frame of the Texture. * * @name Phaser.Textures.Texture#firstFrame * @type {string} * @since 3.0.0 */ this.firstFrame = '__BASE'; /** * The total number of Frames in this Texture. * * @name Phaser.Textures.Texture#frameTotal * @type {integer} * @default 0 * @since 3.0.0 */ this.frameTotal = 0; // Load the Sources for (var i = 0; i < source.length; i++) { this.source.push(new TextureSource(this, source[i], width, height)); } }, /** * Adds a new Frame to this Texture. * * A Frame is a rectangular region of a TextureSource with a unique index or string-based key. * * @method Phaser.Textures.Texture#add * @since 3.0.0 * * @param {(integer|string)} name - The name of this Frame. The name is unique within the Texture. * @param {integer} sourceIndex - The index of the TextureSource that this Frame is a part of. * @param {number} x - The x coordinate of the top-left of this Frame. * @param {number} y - The y coordinate of the top-left of this Frame. * @param {number} width - The width of this Frame. * @param {number} height - The height of this Frame. * * @return {Phaser.Textures.Frame} The Frame that was added to this Texture. */ add: function (name, sourceIndex, x, y, width, height) { var frame = new Frame(this, name, sourceIndex, x, y, width, height); this.frames[name] = frame; // Set the first frame of the Texture (other than __BASE) // This is used to ensure we don't spam the display with entire // atlases of sprite sheets, but instead just the first frame of them // should the dev incorrectly specify the frame index if (this.frameTotal === 1) { this.firstFrame = name; } this.frameTotal++; return frame; }, /** * Checks to see if a Frame matching the given key exists within this Texture. * * @method Phaser.Textures.Texture#has * @since 3.0.0 * * @param {string} name - The key of the Frame to check for. * * @return {boolean} True if a Frame with the matching key exists in this Texture. */ has: function (name) { return (this.frames[name]); }, /** * Gets a Frame from this Texture based on either the key or the index of the Frame. * * In a Texture Atlas Frames are typically referenced by a key. * In a Sprite Sheet Frames are referenced by an index. * Passing no value for the name returns the base texture. * * @method Phaser.Textures.Texture#get * @since 3.0.0 * * @param {(string|integer)} [name] - The string-based name, or integer based index, of the Frame to get from this Texture. * * @return {Phaser.Textures.Frame} The Texture Frame. */ get: function (name) { // null, undefined, empty string, zero if (!name) { name = this.firstFrame; } var frame = this.frames[name]; if (!frame) { console.warn('No Texture.frame found with name ' + name); frame = this.frames[this.firstFrame]; } return frame; }, /** * Takes the given TextureSource and returns the index of it within this Texture. * If it's not in this Texture, it returns -1. * Unless this Texture has multiple TextureSources, such as with a multi-atlas, this * method will always return zero or -1. * * @method Phaser.Textures.Texture#getTextureSourceIndex * @since 3.0.0 * * @param {Phaser.Textures.TextureSource} source - The TextureSource to check. * * @return {integer} The index of the TextureSource within this Texture, or -1 if not in this Texture. */ getTextureSourceIndex: function (source) { for (var i = 0; i < this.source.length; i++) { if (this.source[i] === source) { return i; } } return -1; }, /** * Returns an array of all the Frames in the given TextureSource. * * @method Phaser.Textures.Texture#getFramesFromTextureSource * @since 3.0.0 * * @param {integer} sourceIndex - The index of the TextureSource to get the Frames from. * * @return {Phaser.Textures.Frame[]} An array of Texture Frames. */ getFramesFromTextureSource: function (sourceIndex) { var out = []; for (var frameName in this.frames) { if (frameName === '__BASE') { continue; } var frame = this.frames[frameName]; if (frame.sourceIndex === sourceIndex) { out.push(frame.name); } } return out; }, /** * Returns an array with all of the names of the Frames in this Texture. * * Useful if you want to randomly assign a Frame to a Game Object, as you can * pick a random element from the returned array. * * @method Phaser.Textures.Texture#getFrameNames * @since 3.0.0 * * @param {boolean} [includeBase=false] - Include the `__BASE` Frame in the output array? * * @return {string[]} An array of all Frame names in this Texture. */ getFrameNames: function (includeBase) { if (includeBase === undefined) { includeBase = false; } var out = Object.keys(this.frames); if (!includeBase) { var idx = out.indexOf('__BASE'); if (idx !== -1) { out.splice(idx, 1); } } return out; }, /** * Given a Frame name, return the source image it uses to render with. * * This will return the actual DOM Image or Canvas element. * * @method Phaser.Textures.Texture#getSourceImage * @since 3.0.0 * * @param {(string|integer)} [name] - The string-based name, or integer based index, of the Frame to get from this Texture. * * @return {(HTMLImageElement|HTMLCanvasElement)} The DOM Image or Canvas Element. */ getSourceImage: function (name) { if (name === undefined || name === null || this.frameTotal === 1) { name = '__BASE'; } var frame = this.frames[name]; if (!frame) { console.warn('No Texture.frame found with name ' + name); return this.frames['__BASE'].source.image; } else { return frame.source.image; } }, /** * Given a Frame name, return the data source image it uses to render with. * You can use this to get the normal map for an image for example. * * This will return the actual DOM Image. * * @method Phaser.Textures.Texture#getDataSourceImage * @since 3.7.0 * * @param {(string|integer)} [name] - The string-based name, or integer based index, of the Frame to get from this Texture. * * @return {(HTMLImageElement|HTMLCanvasElement)} The DOM Image or Canvas Element. */ getDataSourceImage: function (name) { if (name === undefined || name === null || this.frameTotal === 1) { name = '__BASE'; } var frame = this.frames[name]; var idx; if (!frame) { console.warn('No Texture.frame found with name ' + name); idx = this.frames['__BASE'].sourceIndex; } else { idx = frame.sourceIndex; } return this.dataSource[idx].image; }, /** * Adds a data source image to this Texture. * * An example of a data source image would be a normal map, where all of the Frames for this Texture * equally apply to the normal map. * * @method Phaser.Textures.Texture#setDataSource * @since 3.0.0 * * @param {(HTMLImageElement|HTMLCanvasElement)} data - The source image. */ setDataSource: function (data) { if (!Array.isArray(data)) { data = [ data ]; } for (var i = 0; i < data.length; i++) { var source = this.source[i]; this.dataSource.push(new TextureSource(this, data[i], source.width, source.height)); } }, /** * Sets the Filter Mode for this Texture. * * The mode can be either Linear, the default, or Nearest. * * For pixel-art you should use Nearest. * * The mode applies to the entire Texture, not just a specific Frame of it. * * @method Phaser.Textures.Texture#setFilter * @since 3.0.0 * * @param {Phaser.Textures.FilterMode} filterMode - The Filter Mode. */ setFilter: function (filterMode) { var i; for (i = 0; i < this.source.length; i++) { this.source[i].setFilter(filterMode); } for (i = 0; i < this.dataSource.length; i++) { this.dataSource[i].setFilter(filterMode); } }, /** * Destroys this Texture and releases references to its sources and frames. * * @method Phaser.Textures.Texture#destroy * @since 3.0.0 */ destroy: function () { var i; for (i = 0; i < this.source.length; i++) { this.source[i].destroy(); } for (i = 0; i < this.dataSource.length; i++) { this.dataSource[i].destroy(); } for (var frameName in this.frames) { var frame = this.frames[frameName]; frame.destroy(); } this.source = []; this.dataSource = []; this.frames = {}; this.manager = null; } }); module.exports = Texture; /***/ }), /* 118 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(55); var DefaultPlugins = __webpack_require__(121); var GetPhysicsPlugins = __webpack_require__(518); var GetScenePlugins = __webpack_require__(517); var NOOP = __webpack_require__(3); var Settings = __webpack_require__(192); /** * @classdesc * The Scene Systems class. * * This class is available from within a Scene under the property `sys`. * It is responsible for managing all of the plugins a Scene has running, including the display list, and * handling the update step and renderer. It also contains references to global systems belonging to Game. * * @class Systems * @memberOf Phaser.Scenes * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene that owns this Systems instance. * @param {(string|Phaser.Scenes.Settings.Config)} config - Scene specific configuration settings. */ var Systems = new Class({ initialize: function Systems (scene, config) { /** * [description] * * @name Phaser.Scenes.Systems#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * [description] * * @name Phaser.Scenes.Systems#game * @type {Phaser.Game} * @since 3.0.0 */ this.game; /** * [description] * * @name Phaser.Scenes.Systems#config * @type {(string|Phaser.Scenes.Settings.Config)} * @since 3.0.0 */ this.config = config; /** * [description] * * @name Phaser.Scenes.Systems#settings * @type {Phaser.Scenes.Settings.Object} * @since 3.0.0 */ this.settings = Settings.create(config); /** * A handy reference to the Scene canvas / context. * * @name Phaser.Scenes.Systems#canvas * @type {HTMLCanvasElement} * @since 3.0.0 */ this.canvas; /** * [description] * * @name Phaser.Scenes.Systems#context * @type {CanvasRenderingContext2D} * @since 3.0.0 */ this.context; // Global Systems - these are single-instance global managers that belong to Game /** * [description] * * @name Phaser.Scenes.Systems#anims * @type {Phaser.Animations.AnimationManager} * @since 3.0.0 */ this.anims; /** * [description] * * @name Phaser.Scenes.Systems#cache * @type {Phaser.Cache.CacheManager} * @since 3.0.0 */ this.cache; /** * [description] * * @name Phaser.Scenes.Systems#plugins * @type {Phaser.Plugins.PluginManager} * @since 3.0.0 */ this.plugins; /** * [description] * * @name Phaser.Scenes.Systems#registry * @type {Phaser.Data.DataManager} * @since 3.0.0 */ this.registry; /** * [description] * * @name Phaser.Scenes.Systems#sound * @type {Phaser.Sound.BaseSoundManager} * @since 3.0.0 */ this.sound; /** * [description] * * @name Phaser.Scenes.Systems#textures * @type {Phaser.Textures.TextureManager} * @since 3.0.0 */ this.textures; // Core Plugins - these are non-optional Scene plugins, needed by lots of the other systems /** * [description] * * @name Phaser.Scenes.Systems#add * @type {Phaser.GameObjects.GameObjectFactory} * @since 3.0.0 */ this.add; /** * [description] * * @name Phaser.Scenes.Systems#cameras * @type {Phaser.Cameras.Scene2D.CameraManager} * @since 3.0.0 */ this.cameras; /** * [description] * * @name Phaser.Scenes.Systems#displayList * @type {Phaser.GameObjects.DisplayList} * @since 3.0.0 */ this.displayList; /** * [description] * * @name Phaser.Scenes.Systems#events * @type {Phaser.Events.EventEmitter} * @since 3.0.0 */ this.events; /** * [description] * * @name Phaser.Scenes.Systems#make * @type {Phaser.GameObjects.GameObjectCreator} * @since 3.0.0 */ this.make; /** * [description] * * @name Phaser.Scenes.Systems#scenePlugin * @type {Phaser.Scenes.ScenePlugin} * @since 3.0.0 */ this.scenePlugin; /** * [description] * * @name Phaser.Scenes.Systems#updateList * @type {Phaser.GameObjects.UpdateList} * @since 3.0.0 */ this.updateList; /** * The Scene Update function. * * This starts out as NOOP during init, preload and create, and at the end of create * it swaps to be whatever the Scene.update function is. * * @name Phaser.Scenes.Systems#sceneUpdate * @type {function} * @private * @since 3.10.0 */ this.sceneUpdate = NOOP; }, /** * This method is called only once by the Scene Manager when the Scene is instantiated. * It is responsible for setting up all of the Scene plugins and references. * It should never be called directly. * * @method Phaser.Scenes.Systems#init * @protected * @since 3.0.0 * * @param {Phaser.Game} game - A reference to the Phaser Game instance. */ init: function (game) { this.settings.status = CONST.INIT; // This will get replaced by the SceneManager with the actual update function, if it exists, once create is over. this.sceneUpdate = NOOP; this.game = game; this.canvas = game.canvas; this.context = game.context; var pluginManager = game.plugins; this.plugins = pluginManager; pluginManager.addToScene(this, DefaultPlugins.Global, [ DefaultPlugins.CoreScene, GetScenePlugins(this), GetPhysicsPlugins(this) ]); this.events.emit('boot', this); this.settings.isBooted = true; }, /** * Called by a plugin, it tells the System to install the plugin locally. * * @method Phaser.Scenes.Systems#install * @private * @since 3.0.0 * * @param {array} plugin - An array of plugins to install into this Scene. */ install: function (plugin) { if (!Array.isArray(plugin)) { plugin = [ plugin ]; } this.plugins.installLocal(this, plugin); }, /** * A single game step. Called automatically by the Scene Manager as a result of a Request Animation * Frame or Set Timeout call to the main Game instance. * * @method Phaser.Scenes.Systems#step * @since 3.0.0 * * @param {number} time - The time value from the most recent Game step. Typically a high-resolution timer value, or Date.now(). * @param {number} delta - The delta value since the last frame. This is smoothed to avoid delta spikes by the TimeStep class. */ step: function (time, delta) { this.events.emit('preupdate', time, delta); this.events.emit('update', time, delta); this.sceneUpdate.call(this.scene, time, delta); this.events.emit('postupdate', time, delta); }, /** * Called automatically by the Scene Manager. Instructs the Scene to render itself via * its Camera Manager to the renderer given. * * @method Phaser.Scenes.Systems#render * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] */ render: function (renderer) { var displayList = this.displayList; displayList.depthSort(); this.cameras.render(renderer, displayList); this.events.emit('render', renderer); }, /** * Force a sort of the display list on the next render. * * @method Phaser.Scenes.Systems#queueDepthSort * @since 3.0.0 */ queueDepthSort: function () { this.displayList.queueDepthSort(); }, /** * Immediately sorts the display list if the flag is set. * * @method Phaser.Scenes.Systems#depthSort * @since 3.0.0 */ depthSort: function () { this.displayList.depthSort(); }, /** * Pause this Scene. * A paused Scene still renders, it just doesn't run ANY of its update handlers or systems. * * @method Phaser.Scenes.Systems#pause * @since 3.0.0 * * @return {Phaser.Scenes.Systems} This Systems object. */ pause: function () { if (this.settings.active) { this.settings.status = CONST.PAUSED; this.settings.active = false; this.events.emit('pause', this); } return this; }, /** * Resume this Scene from a paused state. * * @method Phaser.Scenes.Systems#resume * @since 3.0.0 * * @return {Phaser.Scenes.Systems} This Systems object. */ resume: function () { if (!this.settings.active) { this.settings.status = CONST.RUNNING; this.settings.active = true; this.events.emit('resume', this); } return this; }, /** * Send this Scene to sleep. * * A sleeping Scene doesn't run it's update step or render anything, but it also isn't shut down * or have any of its systems or children removed, meaning it can be re-activated at any point and * will carry on from where it left off. It also keeps everything in memory and events and callbacks * from other Scenes may still invoke changes within it, so be careful what is left active. * * @method Phaser.Scenes.Systems#sleep * @since 3.0.0 * * @return {Phaser.Scenes.Systems} This Systems object. */ sleep: function () { this.settings.status = CONST.SLEEPING; this.settings.active = false; this.settings.visible = false; this.events.emit('sleep', this); return this; }, /** * Wake-up this Scene if it was previously asleep. * * @method Phaser.Scenes.Systems#wake * @since 3.0.0 * * @return {Phaser.Scenes.Systems} This Systems object. */ wake: function () { var settings = this.settings; settings.status = CONST.RUNNING; settings.active = true; settings.visible = true; this.events.emit('wake', this); if (settings.isTransition) { this.events.emit('transitionwake', settings.transitionFrom, settings.transitionDuration); } return this; }, /** * Is this Scene sleeping? * * @method Phaser.Scenes.Systems#isSleeping * @since 3.0.0 * * @return {boolean} [description] */ isSleeping: function () { return (this.settings.status === CONST.SLEEPING); }, /** * Is this Scene active? * * @method Phaser.Scenes.Systems#isActive * @since 3.0.0 * * @return {boolean} [description] */ isActive: function () { return (this.settings.status === CONST.RUNNING); }, /** * Is this Scene currently transitioning out to, or in from another Scene? * * @method Phaser.Scenes.Systems#isTransitioning * @since 3.5.0 * * @return {boolean} `true` if this Scene is currently transitioning, otherwise `false`. */ isTransitioning: function () { return (this.settings.isTransition || this.scenePlugin._target !== null); }, /** * Is this Scene currently transitioning out from itself to another Scene? * * @method Phaser.Scenes.Systems#isTransitionOut * @since 3.5.0 * * @return {boolean} `true` if this Scene is in transition to another Scene, otherwise `false`. */ isTransitionOut: function () { return (this.scenePlugin._target !== null && this.scenePlugin._duration > 0); }, /** * Is this Scene currently transitioning in from another Scene? * * @method Phaser.Scenes.Systems#isTransitionIn * @since 3.5.0 * * @return {boolean} `true` if this Scene is transitioning in from another Scene, otherwise `false`. */ isTransitionIn: function () { return (this.settings.isTransition); }, /** * Is this Scene visible and rendering? * * @method Phaser.Scenes.Systems#isVisible * @since 3.0.0 * * @return {boolean} [description] */ isVisible: function () { return this.settings.visible; }, /** * Sets the visible state of this Scene. * An invisible Scene will not render, but will still process updates. * * @method Phaser.Scenes.Systems#setVisible * @since 3.0.0 * * @param {boolean} value - [description] * * @return {Phaser.Scenes.Systems} This Systems object. */ setVisible: function (value) { this.settings.visible = value; return this; }, /** * Set the active state of this Scene. * An active Scene will run its core update loop. * * @method Phaser.Scenes.Systems#setActive * @since 3.0.0 * * @param {boolean} value - If `true` the Scene will be resumed, if previously paused. If `false` it will be paused. * * @return {Phaser.Scenes.Systems} This Systems object. */ setActive: function (value) { if (value) { return this.resume(); } else { return this.pause(); } }, /** * Start this Scene running and rendering. * Called automatically by the SceneManager. * * @method Phaser.Scenes.Systems#start * @since 3.0.0 * * @param {object} data - Optional data object that may have been passed to this Scene from another. */ start: function (data) { if (data) { this.settings.data = data; } this.settings.status = CONST.START; this.settings.active = true; this.settings.visible = true; // For plugins to listen out for this.events.emit('start', this); // For user-land code to listen out for this.events.emit('ready', this); }, /** * Called automatically by the SceneManager if the Game resizes. * Dispatches an event you can respond to in your game code. * * @method Phaser.Scenes.Systems#resize * @since 3.2.0 * * @param {number} width - The new width of the game. * @param {number} height - The new height of the game. */ resize: function (width, height) { this.events.emit('resize', width, height); }, /** * Shutdown this Scene and send a shutdown event to all of its systems. * A Scene that has been shutdown will not run its update loop or render, but it does * not destroy any of its plugins or references. It is put into hibernation for later use. * If you don't ever plan to use this Scene again, then it should be destroyed instead * to free-up resources. * * @method Phaser.Scenes.Systems#shutdown * @since 3.0.0 */ shutdown: function () { this.events.off('transitioninit'); this.events.off('transitionstart'); this.events.off('transitioncomplete'); this.events.off('transitionout'); this.settings.status = CONST.SHUTDOWN; this.settings.active = false; this.settings.visible = false; this.events.emit('shutdown', this); }, /** * Destroy this Scene and send a destroy event all of its systems. * A destroyed Scene cannot be restarted. * You should not call this directly, instead use `SceneManager.remove`. * * @method Phaser.Scenes.Systems#destroy * @private * @since 3.0.0 */ destroy: function () { this.settings.status = CONST.DESTROYED; this.settings.active = false; this.settings.visible = false; this.events.emit('destroy', this); this.events.removeAllListeners(); var props = [ 'scene', 'game', 'anims', 'cache', 'plugins', 'registry', 'sound', 'textures', 'add', 'camera', 'displayList', 'events', 'make', 'scenePlugin', 'updateList' ]; for (var i = 0; i < props.length; i++) { this[props[i]] = null; } } }); module.exports = Systems; /***/ }), /* 119 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.GameObjects.Graphics.Commands */ module.exports = { ARC: 0, BEGIN_PATH: 1, CLOSE_PATH: 2, FILL_RECT: 3, LINE_TO: 4, MOVE_TO: 5, LINE_STYLE: 6, FILL_STYLE: 7, FILL_PATH: 8, STROKE_PATH: 9, FILL_TRIANGLE: 10, STROKE_TRIANGLE: 11, LINE_FX_TO: 12, MOVE_FX_TO: 13, SAVE: 14, RESTORE: 15, TRANSLATE: 16, SCALE: 17, ROTATE: 18 }; /***/ }), /* 120 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var OS = __webpack_require__(57); var Browser = __webpack_require__(80); var CanvasPool = __webpack_require__(22); /** * Determines the features of the browser running this Phaser Game instance. * These values are read-only and populated during the boot sequence of the game. * They are then referenced by internal game systems and are available for you to access * via `this.sys.game.device.features` from within any Scene. * * @typedef {object} Phaser.Device.Features * @since 3.0.0 * * @property {?boolean} canvasBitBltShift - True if canvas supports a 'copy' bitblt onto itself when the source and destination regions overlap. * @property {boolean} canvas - Is canvas available? * @property {boolean} file - Is file available? * @property {boolean} fileSystem - Is fileSystem available? * @property {boolean} getUserMedia - Does the device support the getUserMedia API? * @property {boolean} littleEndian - Is the device big or little endian? (only detected if the browser supports TypedArrays) * @property {boolean} localStorage - Is localStorage available? * @property {boolean} pointerLock - Is Pointer Lock available? * @property {boolean} support32bit - Does the device context support 32bit pixel manipulation using array buffer views? * @property {boolean} vibration - Does the device support the Vibration API? * @property {boolean} webGL - Is webGL available? * @property {boolean} worker - Is worker available? */ var Features = { canvas: false, canvasBitBltShift: null, file: false, fileSystem: false, getUserMedia: true, littleEndian: false, localStorage: false, pointerLock: false, support32bit: false, vibration: false, webGL: false, worker: false }; // Check Little or Big Endian system. // @author Matt DesLauriers (@mattdesl) function checkIsLittleEndian () { var a = new ArrayBuffer(4); var b = new Uint8Array(a); var c = new Uint32Array(a); b[0] = 0xa1; b[1] = 0xb2; b[2] = 0xc3; b[3] = 0xd4; if (c[0] === 0xd4c3b2a1) { return true; } if (c[0] === 0xa1b2c3d4) { return false; } else { // Could not determine endianness return null; } } function init () { Features.canvas = !!window['CanvasRenderingContext2D'] || OS.cocoonJS; try { Features.localStorage = !!localStorage.getItem; } catch (error) { Features.localStorage = false; } Features.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob']; Features.fileSystem = !!window['requestFileSystem']; var isUint8 = false; var testWebGL = function () { if (window['WebGLRenderingContext']) { try { var canvas = CanvasPool.createWebGL(this); if (OS.cocoonJS) { canvas.screencanvas = false; } var ctx = canvas.getContext('webgl') || canvas.getContext('experimental-webgl'); var canvas2D = CanvasPool.create2D(this); var ctx2D = canvas2D.getContext('2d'); // Can't be done on a webgl context var image = ctx2D.createImageData(1, 1); // Test to see if ImageData uses CanvasPixelArray or Uint8ClampedArray. // @author Matt DesLauriers (@mattdesl) isUint8 = image.data instanceof Uint8ClampedArray; CanvasPool.remove(canvas); CanvasPool.remove(canvas2D); return !!ctx; } catch (e) { return false; } } return false; }; Features.webGL = testWebGL(); Features.worker = !!window['Worker']; Features.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia; window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; Features.getUserMedia = Features.getUserMedia && !!navigator.getUserMedia && !!window.URL; // Older versions of firefox (< 21) apparently claim support but user media does not actually work if (Browser.firefox && Browser.firefoxVersion < 21) { Features.getUserMedia = false; } // Excludes iOS versions as they generally wrap UIWebView (eg. Safari WebKit) and it // is safer to not try and use the fast copy-over method. if (!OS.iOS && (Browser.ie || Browser.firefox || Browser.chrome)) { Features.canvasBitBltShift = true; } // Known not to work if (Browser.safari || Browser.mobileSafari) { Features.canvasBitBltShift = false; } navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate; if (navigator.vibrate) { Features.vibration = true; } if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined') { Features.littleEndian = checkIsLittleEndian(); } Features.support32bit = ( typeof ArrayBuffer !== 'undefined' && typeof Uint8ClampedArray !== 'undefined' && typeof Int32Array !== 'undefined' && Features.littleEndian !== null && isUint8 ); return Features; } module.exports = init(); /***/ }), /* 121 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @typedef {object} Phaser.Plugins.DefaultPlugins * * @property {array} Global - These are the Global Managers that are created by the Phaser.Game instance. * @property {array} CoreScene - These are the core plugins that are installed into every Scene.Systems instance, no matter what. * @property {array} DefaultScene - These plugins are created in Scene.Systems in addition to the CoreScenePlugins. */ var DefaultPlugins = { /** * These are the Global Managers that are created by the Phaser.Game instance. * They are referenced from Scene.Systems so that plugins can use them. * * @name Phaser.Plugins.Global * @type {array} * @since 3.0.0 */ Global: [ 'anims', 'cache', 'plugins', 'registry', 'sound', 'textures' ], /** * These are the core plugins that are installed into every Scene.Systems instance, no matter what. * They are optionally exposed in the Scene as well (see the InjectionMap for details) * * They are created in the order in which they appear in this array and EventEmitter is always first. * * @name Phaser.Plugins.CoreScene * @type {array} * @since 3.0.0 */ CoreScene: [ 'EventEmitter', 'CameraManager', 'GameObjectCreator', 'GameObjectFactory', 'ScenePlugin', 'DisplayList', 'UpdateList' ], /** * These plugins are created in Scene.Systems in addition to the CoreScenePlugins. * * You can elect not to have these plugins by either creating a DefaultPlugins object as part * of the Game Config, by creating a Plugins object as part of a Scene Config, or by modifying this array * and building your own bundle. * * They are optionally exposed in the Scene as well (see the InjectionMap for details) * * They are always created in the order in which they appear in the array. * * @name Phaser.Plugins.DefaultScene * @type {array} * @since 3.0.0 */ DefaultScene: [ 'CameraManager3D', 'Clock', 'DataManagerPlugin', 'InputPlugin', 'Loader', 'TweenManager', 'LightsPlugin' ] }; module.exports = DefaultPlugins; /***/ }), /* 122 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Calculates a linear (interpolation) value over t. * * @function Phaser.Math.Linear * @since 3.0.0 * * @param {number} p0 - The first point. * @param {number} p1 - The second point. * @param {float} t - The percentage between p0 and p1 to return, represented as a number between 0 and 1. * * @return {number} The step t% of the way between p0 and p1. */ var Linear = function (p0, p1, t) { return (p1 - p0) * t + p0; }; module.exports = Linear; /***/ }), /* 123 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clamp = __webpack_require__(23); var Class = __webpack_require__(0); var DegToRad = __webpack_require__(38); var Effects = __webpack_require__(204); var EventEmitter = __webpack_require__(9); var Linear = __webpack_require__(122); var Rectangle = __webpack_require__(14); var TransformMatrix = __webpack_require__(64); var ValueToColor = __webpack_require__(132); var Vector2 = __webpack_require__(6); /** * @typedef {object} JSONCameraBounds * @property {number} x - The horizontal position of camera * @property {number} y - The vertical position of camera * @property {number} width - The width size of camera * @property {number} height - The height size of camera */ /** * @typedef {object} JSONCamera * * @property {string} name - The name of the camera * @property {number} x - The horizontal position of camera * @property {number} y - The vertical position of camera * @property {number} width - The width size of camera * @property {number} height - The height size of camera * @property {number} zoom - The zoom of camera * @property {number} rotation - The rotation of camera * @property {boolean} roundPixels - The round pixels st status of camera * @property {number} scrollX - The horizontal scroll of camera * @property {number} scrollY - The vertical scroll of camera * @property {string} backgroundColor - The background color of camera * @property {(JSONCameraBounds|undefined)} [bounds] - The bounds of camera */ /** * @classdesc * A Camera. * * The Camera is the way in which all games are rendered in Phaser. They provide a view into your game world, * and can be positioned, rotated, zoomed and scrolled accordingly. * * A Camera consists of two elements: The viewport and the scroll values. * * The viewport is the physical position and size of the Camera within your game. Cameras, by default, are * created the same size as your game, but their position and size can be set to anything. This means if you * wanted to create a camera that was 320x200 in size, positioned in the bottom-right corner of your game, * you'd adjust the viewport to do that (using methods like `setViewport` and `setSize`). * * If you wish to change where the Camera is looking in your game, then you scroll it. You can do this * via the properties `scrollX` and `scrollY` or the method `setScroll`. Scrolling has no impact on the * viewport, and changing the viewport has no impact on the scrolling. * * By default a Camera will render all Game Objects it can see. You can change this using the `ignore` method, * allowing you to filter Game Objects out on a per-Camera basis. * * A Camera also has built-in special effects including Fade, Flash and Camera Shake. * * @class Camera * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Cameras.Scene2D * @constructor * @since 3.0.0 * * @param {number} x - The x position of the Camera, relative to the top-left of the game canvas. * @param {number} y - The y position of the Camera, relative to the top-left of the game canvas. * @param {number} width - The width of the Camera, in pixels. * @param {number} height - The height of the Camera, in pixels. */ var Camera = new Class({ Extends: EventEmitter, initialize: function Camera (x, y, width, height) { EventEmitter.call(this); /** * A reference to the Scene this camera belongs to. * * @name Phaser.Cameras.Scene2D.Camera#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene; /** * The name of the Camera. This is left empty for your own use. * * @name Phaser.Cameras.Scene2D.Camera#name * @type {string} * @default '' * @since 3.0.0 */ this.name = ''; /** * The x position of the Camera, relative to the top-left of the game canvas. * * @name Phaser.Cameras.Scene2D.Camera#x * @type {number} * @since 3.0.0 */ this.x = x; /** * The y position of the Camera, relative to the top-left of the game canvas. * * @name Phaser.Cameras.Scene2D.Camera#y * @type {number} * @since 3.0.0 */ this.y = y; /** * The width of the Camera, in pixels. * * @name Phaser.Cameras.Scene2D.Camera#width * @type {number} * @since 3.0.0 */ this.width = width; /** * The height of the Camera, in pixels. * * @name Phaser.Cameras.Scene2D.Camera#height * @type {number} * @since 3.0.0 */ this.height = height; /** * Should this camera round its pixel values to integers? * * @name Phaser.Cameras.Scene2D.Camera#roundPixels * @type {boolean} * @default false * @since 3.0.0 */ this.roundPixels = false; /** * Is this Camera visible or not? * * A visible camera will render and perform input tests. * An invisible camera will not render anything and will skip input tests. * * @name Phaser.Cameras.Scene2D.Camera#visible * @type {boolean} * @default true * @since 3.10.0 */ this.visible = true; /** * Is this Camera using a bounds to restrict scrolling movement? * Set this property along with the bounds via `Camera.setBounds`. * * @name Phaser.Cameras.Scene2D.Camera#useBounds * @type {boolean} * @default false * @since 3.0.0 */ this.useBounds = false; /** * The bounds the camera is restrained to during scrolling. * * @name Phaser.Cameras.Scene2D.Camera#_bounds * @type {Phaser.Geom.Rectangle} * @private * @since 3.0.0 */ this._bounds = new Rectangle(); /** * Does this Camera allow the Game Objects it renders to receive input events? * * @name Phaser.Cameras.Scene2D.Camera#inputEnabled * @type {boolean} * @default true * @since 3.0.0 */ this.inputEnabled = true; /** * The horizontal scroll position of this camera. * Optionally restricted via the Camera bounds. * * @name Phaser.Cameras.Scene2D.Camera#scrollX * @type {number} * @default 0 * @since 3.0.0 */ this.scrollX = 0; /** * The vertical scroll position of this camera. * Optionally restricted via the Camera bounds. * * @name Phaser.Cameras.Scene2D.Camera#scrollY * @type {number} * @default 0 * @since 3.0.0 */ this.scrollY = 0; /** * The Camera zoom value. Change this value to zoom in, or out of, a Scene. * Set to 1 to return to the default zoom level. * * @name Phaser.Cameras.Scene2D.Camera#zoom * @type {float} * @default 1 * @since 3.0.0 */ this.zoom = 1; /** * The rotation of the Camera. This influences the rendering of all Game Objects visible by this camera. * * @name Phaser.Cameras.Scene2D.Camera#rotation * @type {number} * @default 0 * @since 3.0.0 */ this.rotation = 0; /** * A local transform matrix used for internal calculations. * * @name Phaser.Cameras.Scene2D.Camera#matrix * @type {Phaser.GameObjects.Components.TransformMatrix} * @since 3.0.0 */ this.matrix = new TransformMatrix(1, 0, 0, 1, 0, 0); /** * Does this Camera have a transparent background? * * @name Phaser.Cameras.Scene2D.Camera#transparent * @type {boolean} * @default true * @since 3.0.0 */ this.transparent = true; /** * The background color of this Camera. Only used if `transparent` is `false`. * * @name Phaser.Cameras.Scene2D.Camera#backgroundColor * @type {Phaser.Display.Color} * @since 3.0.0 */ this.backgroundColor = ValueToColor('rgba(0,0,0,0)'); /** * The Camera Fade effect handler. * To fade this camera see the `Camera.fade` methods. * * @name Phaser.Cameras.Scene2D.Camera#fadeEffect * @type {Phaser.Cameras.Scene2D.Effects.Fade} * @since 3.5.0 */ this.fadeEffect = new Effects.Fade(this); /** * The Camera Flash effect handler. * To flash this camera see the `Camera.flash` method. * * @name Phaser.Cameras.Scene2D.Camera#flashEffect * @type {Phaser.Cameras.Scene2D.Effects.Flash} * @since 3.5.0 */ this.flashEffect = new Effects.Flash(this); /** * The Camera Shake effect handler. * To shake this camera see the `Camera.shake` method. * * @name Phaser.Cameras.Scene2D.Camera#shakeEffect * @type {Phaser.Cameras.Scene2D.Effects.Shake} * @since 3.5.0 */ this.shakeEffect = new Effects.Shake(this); /** * Should the camera cull Game Objects before checking them for input hit tests? * In some special cases it may be beneficial to disable this. * * @name Phaser.Cameras.Scene2D.Camera#disableCull * @type {boolean} * @default false * @since 3.0.0 */ this.disableCull = false; /** * A temporary array of culled objects. * * @name Phaser.Cameras.Scene2D.Camera#culledObjects * @type {Phaser.GameObjects.GameObject[]} * @default [] * @since 3.0.0 */ this.culledObjects = []; /** * The linear interpolation value to use when following a target. * * Can also be set via `setLerp` or as part of the `startFollow` call. * * The default values of 1 means the camera will instantly snap to the target coordinates. * A lower value, such as 0.1 means the camera will more slowly track the target, giving * a smooth transition. You can set the horizontal and vertical values independently, and also * adjust this value in real-time during your game. * * Be sure to keep the value between 0 and 1. A value of zero will disable tracking on that axis. * * @name Phaser.Cameras.Scene2D.Camera#lerp * @type {Phaser.Math.Vector2} * @since 3.9.0 */ this.lerp = new Vector2(1, 1); /** * The values stored in this property are subtracted from the Camera targets position, allowing you to * offset the camera from the actual target x/y coordinates by this amount. * Can also be set via `setFollowOffset` or as part of the `startFollow` call. * * @name Phaser.Cameras.Scene2D.Camera#followOffset * @type {Phaser.Math.Vector2} * @since 3.9.0 */ this.followOffset = new Vector2(); /** * Internal follow target reference. * * @name Phaser.Cameras.Scene2D.Camera#_follow * @type {?any} * @private * @default null * @since 3.0.0 */ this._follow = null; /** * Internal camera ID. Assigned by the Camera Manager and used in the camera pool. * * @name Phaser.Cameras.Scene2D.Camera#_id * @type {integer} * @private * @default 0 * @since 3.0.0 */ this._id = 0; }, /** * Scrolls the Camera so that it is looking at the center of the Camera Bounds (if previously enabled) * * @method Phaser.Cameras.Scene2D.Camera#centerToBounds * @since 3.0.0 * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ centerToBounds: function () { if (this.useBounds) { this.scrollX = (this._bounds.width * 0.5) - (this.width * 0.5); this.scrollY = (this._bounds.height * 0.5) - (this.height * 0.5); } return this; }, /** * Scrolls the Camera so that it is re-centered based on its viewport size. * * @method Phaser.Cameras.Scene2D.Camera#centerToSize * @since 3.0.0 * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ centerToSize: function () { this.scrollX = this.width * 0.5; this.scrollY = this.height * 0.5; return this; }, /** * Takes an array of Game Objects and returns a new array featuring only those objects * visible by this camera. * * @method Phaser.Cameras.Scene2D.Camera#cull * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [renderableObjects,$return] * * @param {Phaser.GameObjects.GameObject[]} renderableObjects - An array of Game Objects to cull. * * @return {Phaser.GameObjects.GameObject[]} An array of Game Objects visible to this Camera. */ cull: function (renderableObjects) { if (this.disableCull) { return renderableObjects; } var cameraMatrix = this.matrix.matrix; var mva = cameraMatrix[0]; var mvb = cameraMatrix[1]; var mvc = cameraMatrix[2]; var mvd = cameraMatrix[3]; /* First Invert Matrix */ var determinant = (mva * mvd) - (mvb * mvc); if (!determinant) { return renderableObjects; } var mve = cameraMatrix[4]; var mvf = cameraMatrix[5]; var scrollX = this.scrollX; var scrollY = this.scrollY; var cameraW = this.width; var cameraH = this.height; var culledObjects = this.culledObjects; var length = renderableObjects.length; determinant = 1 / determinant; culledObjects.length = 0; for (var index = 0; index < length; ++index) { var object = renderableObjects[index]; if (!object.hasOwnProperty('width') || object.parentContainer) { culledObjects.push(object); continue; } var objectW = object.width; var objectH = object.height; var objectX = (object.x - (scrollX * object.scrollFactorX)) - (objectW * object.originX); var objectY = (object.y - (scrollY * object.scrollFactorY)) - (objectH * object.originY); var tx = (objectX * mva + objectY * mvc + mve); var ty = (objectX * mvb + objectY * mvd + mvf); var tw = ((objectX + objectW) * mva + (objectY + objectH) * mvc + mve); var th = ((objectX + objectW) * mvb + (objectY + objectH) * mvd + mvf); var cullW = cameraW + objectW; var cullH = cameraH + objectH; if (tx > -objectW && ty > -objectH && tx < cullW && ty < cullH && tw > -objectW && th > -objectH && tw < cullW && th < cullH) { culledObjects.push(object); } } return culledObjects; }, /** * Fades the Camera in from the given color over the duration specified. * * @method Phaser.Cameras.Scene2D.Camera#fadeIn * @since 3.3.0 * * @param {integer} [duration=1000] - The duration of the effect in milliseconds. * @param {integer} [red=0] - The amount to fade the red channel towards. A value between 0 and 255. * @param {integer} [green=0] - The amount to fade the green channel towards. A value between 0 and 255. * @param {integer} [blue=0] - The amount to fade the blue channel towards. A value between 0 and 255. * @param {function} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ fadeIn: function (duration, red, green, blue, callback, context) { return this.fadeEffect.start(false, duration, red, green, blue, true, callback, context); }, /** * Fades the Camera out to the given color over the duration specified. * This is an alias for Camera.fade that forces the fade to start, regardless of existing fades. * * @method Phaser.Cameras.Scene2D.Camera#fadeOut * @since 3.3.0 * * @param {integer} [duration=1000] - The duration of the effect in milliseconds. * @param {integer} [red=0] - The amount to fade the red channel towards. A value between 0 and 255. * @param {integer} [green=0] - The amount to fade the green channel towards. A value between 0 and 255. * @param {integer} [blue=0] - The amount to fade the blue channel towards. A value between 0 and 255. * @param {function} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ fadeOut: function (duration, red, green, blue, callback, context) { return this.fadeEffect.start(true, duration, red, green, blue, true, callback, context); }, /** * Fades the Camera from the given color to transparent over the duration specified. * * @method Phaser.Cameras.Scene2D.Camera#fadeFrom * @since 3.5.0 * * @param {integer} [duration=1000] - The duration of the effect in milliseconds. * @param {integer} [red=0] - The amount to fade the red channel towards. A value between 0 and 255. * @param {integer} [green=0] - The amount to fade the green channel towards. A value between 0 and 255. * @param {integer} [blue=0] - The amount to fade the blue channel towards. A value between 0 and 255. * @param {boolean} [force=false] - Force the effect to start immediately, even if already running. * @param {function} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ fadeFrom: function (duration, red, green, blue, force, callback, context) { return this.fadeEffect.start(false, duration, red, green, blue, force, callback, context); }, /** * Fades the Camera from transparent to the given color over the duration specified. * * @method Phaser.Cameras.Scene2D.Camera#fade * @since 3.0.0 * * @param {integer} [duration=1000] - The duration of the effect in milliseconds. * @param {integer} [red=0] - The amount to fade the red channel towards. A value between 0 and 255. * @param {integer} [green=0] - The amount to fade the green channel towards. A value between 0 and 255. * @param {integer} [blue=0] - The amount to fade the blue channel towards. A value between 0 and 255. * @param {boolean} [force=false] - Force the effect to start immediately, even if already running. * @param {function} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ fade: function (duration, red, green, blue, force, callback, context) { return this.fadeEffect.start(true, duration, red, green, blue, force, callback, context); }, /** * Flashes the Camera by setting it to the given color immediately and then fading it away again quickly over the duration specified. * * @method Phaser.Cameras.Scene2D.Camera#flash * @since 3.0.0 * * @param {integer} [duration=250] - The duration of the effect in milliseconds. * @param {integer} [red=255] - The amount to fade the red channel towards. A value between 0 and 255. * @param {integer} [green=255] - The amount to fade the green channel towards. A value between 0 and 255. * @param {integer} [blue=255] - The amount to fade the blue channel towards. A value between 0 and 255. * @param {boolean} [force=false] - Force the effect to start immediately, even if already running. * @param {function} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ flash: function (duration, red, green, blue, force, callback, context) { return this.flashEffect.start(duration, red, green, blue, force, callback, context); }, /** * Shakes the Camera by the given intensity over the duration specified. * * @method Phaser.Cameras.Scene2D.Camera#shake * @since 3.0.0 * * @param {integer} [duration=100] - The duration of the effect in milliseconds. * @param {number} [intensity=0.05] - The intensity of the shake. * @param {boolean} [force=false] - Force the shake effect to start immediately, even if already running. * @param {function} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ shake: function (duration, intensity, force, callback, context) { return this.shakeEffect.start(duration, intensity, force, callback, context); }, /** * Converts the given `x` and `y` coordinates into World space, based on this Cameras transform. * You can optionally provide a Vector2, or similar object, to store the results in. * * @method Phaser.Cameras.Scene2D.Camera#getWorldPoint * @since 3.0.0 * * @generic {Phaser.Math.Vector2} O - [output,$return] * * @param {number} x - The x position to convert to world space. * @param {number} y - The y position to convert to world space. * @param {(object|Phaser.Math.Vector2)} [output] - An optional object to store the results in. If not provided a new Vector2 will be created. * * @return {Phaser.Math.Vector2} An object holding the converted values in its `x` and `y` properties. */ getWorldPoint: function (x, y, output) { if (output === undefined) { output = new Vector2(); } var cameraMatrix = this.matrix.matrix; var mva = cameraMatrix[0]; var mvb = cameraMatrix[1]; var mvc = cameraMatrix[2]; var mvd = cameraMatrix[3]; var mve = cameraMatrix[4]; var mvf = cameraMatrix[5]; /* First Invert Matrix */ var determinant = (mva * mvd) - (mvb * mvc); if (!determinant) { output.x = x; output.y = y; return output; } determinant = 1 / determinant; var ima = mvd * determinant; var imb = -mvb * determinant; var imc = -mvc * determinant; var imd = mva * determinant; var ime = (mvc * mvf - mvd * mve) * determinant; var imf = (mvb * mve - mva * mvf) * determinant; var c = Math.cos(this.rotation); var s = Math.sin(this.rotation); var zoom = this.zoom; var scrollX = this.scrollX; var scrollY = this.scrollY; var sx = x + ((scrollX * c - scrollY * s) * zoom); var sy = y + ((scrollX * s + scrollY * c) * zoom); /* Apply transform to point */ output.x = (sx * ima + sy * imc + ime); output.y = (sx * imb + sy * imd + imf); return output; }, /** * Given a Game Object, or an array of Game Objects, it will update all of their camera filter settings * so that they are ignored by this Camera. This means they will not be rendered by this Camera. * * @method Phaser.Cameras.Scene2D.Camera#ignore * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObject - The Game Object, or array of Game Objects, to be ignored by this Camera. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ ignore: function (gameObject) { var id = this._id; if (Array.isArray(gameObject)) { for (var i = 0; i < gameObject.length; i++) { gameObject[i].cameraFilter |= id; } } else { gameObject.cameraFilter |= id; } return this; }, /** * Internal preRender step. * * @method Phaser.Cameras.Scene2D.Camera#preRender * @protected * @since 3.0.0 * * @param {number} baseScale - The base scale, as set in the Camera Manager. * @param {number} resolution - The game resolution. */ preRender: function (baseScale, resolution) { var width = this.width; var height = this.height; var zoom = this.zoom * baseScale; var matrix = this.matrix; var originX = width / 2; var originY = height / 2; var follow = this._follow; if (follow) { this.scrollX = Linear(this.scrollX, (follow.x - this.followOffset.x) - originX, this.lerp.x) / zoom; this.scrollY = Linear(this.scrollY, (follow.y - this.followOffset.y) - originY, this.lerp.y) / zoom; } if (this.useBounds) { var bounds = this._bounds; var bw = Math.max(0, bounds.right - width); var bh = Math.max(0, bounds.bottom - height); if (this.scrollX < bounds.x) { this.scrollX = bounds.x; } else if (this.scrollX > bw) { this.scrollX = bw; } if (this.scrollY < bounds.y) { this.scrollY = bounds.y; } else if (this.scrollY > bh) { this.scrollY = bh; } } if (this.roundPixels) { this.scrollX = Math.round(this.scrollX); this.scrollY = Math.round(this.scrollY); } matrix.loadIdentity(); matrix.scale(resolution, resolution); matrix.translate(this.x + originX, this.y + originY); matrix.rotate(this.rotation); matrix.scale(zoom, zoom); matrix.translate(-originX, -originY); this.shakeEffect.preRender(); }, /** * If this Camera has previously had movement bounds set on it, this will remove them. * * @method Phaser.Cameras.Scene2D.Camera#removeBounds * @since 3.0.0 * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ removeBounds: function () { this.useBounds = false; this._bounds.setEmpty(); return this; }, /** * Set the rotation of this Camera. This causes everything it renders to appear rotated. * * Rotating a camera does not rotate the viewport itself, it is applied during rendering. * * @method Phaser.Cameras.Scene2D.Camera#setAngle * @since 3.0.0 * * @param {number} [value=0] - The cameras angle of rotation, given in degrees. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setAngle: function (value) { if (value === undefined) { value = 0; } this.rotation = DegToRad(value); return this; }, /** * Sets the linear interpolation value to use when following a target. * * The default values of 1 means the camera will instantly snap to the target coordinates. * A lower value, such as 0.1 means the camera will more slowly track the target, giving * a smooth transition. You can set the horizontal and vertical values independently, and also * adjust this value in real-time during your game. * * Be sure to keep the value between 0 and 1. A value of zero will disable tracking on that axis. * * @method Phaser.Cameras.Scene2D.Camera#setLerp * @since 3.9.0 * * @param {number} [x=1] - The amount added to the horizontal linear interpolation of the follow target. * @param {number} [y=1] - The amount added to the vertical linear interpolation of the follow target. * * @return {this} This Camera instance. */ setLerp: function (x, y) { if (x === undefined) { x = 1; } if (y === undefined) { y = x; } this.lerp.set(x, y); return this; }, /** * Sets the horizontal and vertical offset of the camera from its follow target. * The values are subtracted from the targets position during the Cameras update step. * * @method Phaser.Cameras.Scene2D.Camera#setFollowOffset * @since 3.9.0 * * @param {number} [x=0] - The horizontal offset from the camera follow target.x position. * @param {number} [y=0] - The vertical offset from the camera follow target.y position. * * @return {this} This Camera instance. */ setFollowOffset: function (x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } this.followOffset.set(x, y); return this; }, /** * Sets the background color for this Camera. * * By default a Camera has a transparent background but it can be given a solid color, with any level * of transparency, via this method. * * The color value can be specified using CSS color notation, hex or numbers. * * @method Phaser.Cameras.Scene2D.Camera#setBackgroundColor * @since 3.0.0 * * @param {(string|number|InputColorObject)} [color='rgba(0,0,0,0)'] - The color value. In CSS, hex or numeric color notation. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setBackgroundColor: function (color) { if (color === undefined) { color = 'rgba(0,0,0,0)'; } this.backgroundColor = ValueToColor(color); this.transparent = (this.backgroundColor.alpha === 0); return this; }, /** * Set the world bounds for this Camera. * * A Camera bounds controls where the camera can scroll to within the world. It does not limit * rendering of the camera, or placement of the viewport within your game. * * @method Phaser.Cameras.Scene2D.Camera#setBounds * @since 3.0.0 * * @param {integer} x - The top-left x coordinate of the bounds. * @param {integer} y - The top-left y coordinate of the bounds. * @param {integer} width - The width of the bounds, in pixels. * @param {integer} height - The height of the bounds, in pixels. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setBounds: function (x, y, width, height) { this._bounds.setTo(x, y, width, height); this.useBounds = true; return this; }, /** * Sets the name of this Camera. * This value is for your own use and isn't used internally. * * @method Phaser.Cameras.Scene2D.Camera#setName * @since 3.0.0 * * @param {string} [value=''] - The name of the Camera. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setName: function (value) { if (value === undefined) { value = ''; } this.name = value; return this; }, /** * Set the position of the Camera viewport within the game. * * This does not change where the camera is 'looking'. See `setScroll` to control that. * * @method Phaser.Cameras.Scene2D.Camera#setPosition * @since 3.0.0 * * @param {number} x - The top-left x coordinate of the Camera viewport. * @param {number} [y=x] - The top-left y coordinate of the Camera viewport. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setPosition: function (x, y) { if (y === undefined) { y = x; } this.x = x; this.y = y; return this; }, /** * Set the rotation of this Camera. This causes everything it renders to appear rotated. * * Rotating a camera does not rotate the viewport itself, it is applied during rendering. * * @method Phaser.Cameras.Scene2D.Camera#setRotation * @since 3.0.0 * * @param {number} [value=0] - The rotation of the Camera, in radians. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setRotation: function (value) { if (value === undefined) { value = 0; } this.rotation = value; return this; }, /** * Should the Camera round pixel values to whole integers when scrolling? * In some types of game this is required to prevent sub-pixel aliasing. * * @method Phaser.Cameras.Scene2D.Camera#setRoundPixels * @since 3.0.0 * * @param {boolean} value - `true` to round Camera pixels, `false` to not. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setRoundPixels: function (value) { this.roundPixels = value; return this; }, /** * Sets the Scene the Camera is bound to. * * @method Phaser.Cameras.Scene2D.Camera#setScene * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene the camera is bound to. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setScene: function (scene) { this.scene = scene; return this; }, /** * Set the position of where the Camera is looking within the game. * You can also modify the properties `Camera.scrollX` and `Camera.scrollY` directly. * Use this method, or the scroll properties, to move your camera around the game world. * * This does not change where the camera viewport is placed. See `setPosition` to control that. * * @method Phaser.Cameras.Scene2D.Camera#setScroll * @since 3.0.0 * * @param {number} x - The x coordinate of the Camera in the game world. * @param {number} [y=x] - The y coordinate of the Camera in the game world. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setScroll: function (x, y) { if (y === undefined) { y = x; } this.scrollX = x; this.scrollY = y; return this; }, /** * Set the size of the Camera viewport. * * By default a Camera is the same size as the game, but can be made smaller via this method, * allowing you to create mini-cam style effects by creating and positioning a smaller Camera * viewport within your game. * * @method Phaser.Cameras.Scene2D.Camera#setSize * @since 3.0.0 * * @param {integer} width - The width of the Camera viewport. * @param {integer} [height=width] - The height of the Camera viewport. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setSize: function (width, height) { if (height === undefined) { height = width; } this.width = width; this.height = height; return this; }, /** * This method sets the position and size of the Camera viewport in a single call. * * If you're trying to change where the Camera is looking at in your game, then see * the method `Camera.setScroll` instead. This method is for changing the viewport * itself, not what the camera can see. * * By default a Camera is the same size as the game, but can be made smaller via this method, * allowing you to create mini-cam style effects by creating and positioning a smaller Camera * viewport within your game. * * @method Phaser.Cameras.Scene2D.Camera#setViewport * @since 3.0.0 * * @param {number} x - The top-left x coordinate of the Camera viewport. * @param {number} y - The top-left y coordinate of the Camera viewport. * @param {integer} width - The width of the Camera viewport. * @param {integer} [height=width] - The height of the Camera viewport. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setViewport: function (x, y, width, height) { this.x = x; this.y = y; this.width = width; this.height = height; return this; }, /** * Set the zoom value of the Camera. * * Changing to a smaller value, such as 0.5, will cause the camera to 'zoom out'. * Changing to a larger value, such as 2, will cause the camera to 'zoom in'. * * A value of 1 means 'no zoom' and is the default. * * Changing the zoom does not impact the Camera viewport in any way, it is only applied during rendering. * * @method Phaser.Cameras.Scene2D.Camera#setZoom * @since 3.0.0 * * @param {float} [value=1] - The zoom value of the Camera. * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ setZoom: function (value) { if (value === undefined) { value = 1; } this.zoom = value; return this; }, /** * Sets the visibility of this Camera. * * An invisible Camera will skip rendering and input tests of everything it can see. * * @method Phaser.Cameras.Scene2D.Camera#setVisible * @since 3.10.0 * * @param {boolean} value - The visible state of the Camera. * * @return {this} This Camera instance. */ setVisible: function (value) { this.visible = value; return this; }, /** * Sets the Camera to follow a Game Object. * * When enabled the Camera will automatically adjust its scroll position to keep the target Game Object * in its center. * * You can set the linear interpolation value used in the follow code. * Use low lerp values (such as 0.1) to automatically smooth the camera motion. * * If you find you're getting a slight "jitter" effect when following an object it's probably to do with sub-pixel * rendering of the targets position. This can be rounded by setting the `roundPixels` argument to `true` to * force full pixel rounding rendering. Note that this can still be broken if you have specified a non-integer zoom * value on the camera. So be sure to keep the camera zoom to integers. * * @method Phaser.Cameras.Scene2D.Camera#startFollow * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|object)} target - The target for the Camera to follow. * @param {boolean} [roundPixels=false] - Round the camera position to whole integers to avoid sub-pixel rendering? * @param {float} [lerpX=1] - A value between 0 and 1. This value specifies the amount of linear interpolation to use when horizontally tracking the target. The closer the value to 1, the faster the camera will track. * @param {float} [lerpY=1] - A value between 0 and 1. This value specifies the amount of linear interpolation to use when vertically tracking the target. The closer the value to 1, the faster the camera will track. * @param {number} [offsetX=0] - The horizontal offset from the camera follow target.x position. * @param {number} [offsetY=0] - The vertical offset from the camera follow target.y position. * * @return {this} This Camera instance. */ startFollow: function (target, roundPixels, lerpX, lerpY, offsetX, offsetY) { if (roundPixels === undefined) { roundPixels = false; } if (lerpX === undefined) { lerpX = 1; } if (lerpY === undefined) { lerpY = lerpX; } if (offsetX === undefined) { offsetX = 0; } if (offsetY === undefined) { offsetY = offsetX; } this._follow = target; this.roundPixels = roundPixels; lerpX = Clamp(lerpX, 0, 1); lerpY = Clamp(lerpY, 0, 1); this.lerp.set(lerpX, lerpY); this.followOffset.set(offsetX, offsetY); // Move the camera there immediately, to avoid a large lerp during preUpdate var zoom = this.zoom; var originX = this.width / 2; var originY = this.height / 2; this.scrollX = (target.x - offsetX - originX) / zoom; this.scrollY = (target.y - offsetY - originY) / zoom; return this; }, /** * Stops a Camera from following a Game Object, if previously set via `Camera.startFollow`. * * @method Phaser.Cameras.Scene2D.Camera#stopFollow * @since 3.0.0 * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ stopFollow: function () { this._follow = null; return this; }, /** * Returns an Object suitable for JSON storage containing all of the Camera viewport and rendering properties. * * @method Phaser.Cameras.Scene2D.Camera#toJSON * @since 3.0.0 * * @return {JSONCamera} A well-formed object suitable for conversion to JSON. */ toJSON: function () { var output = { name: this.name, x: this.x, y: this.y, width: this.width, height: this.height, zoom: this.zoom, rotation: this.rotation, roundPixels: this.roundPixels, scrollX: this.scrollX, scrollY: this.scrollY, backgroundColor: this.backgroundColor.rgba }; if (this.useBounds) { output['bounds'] = { x: this._bounds.x, y: this._bounds.y, width: this._bounds.width, height: this._bounds.height }; } return output; }, /** * Resets any active FX, such as a fade, flash or shake. Useful to call after a fade in order to * remove the fade. * * @method Phaser.Cameras.Scene2D.Camera#resetFX * @since 3.0.0 * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ resetFX: function () { this.shakeEffect.reset(); this.flashEffect.reset(); this.fadeEffect.reset(); return this; }, /** * Internal method called automatically by the Camera Manager. * * @method Phaser.Cameras.Scene2D.Camera#update * @protected * @since 3.0.0 * * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ update: function (time, delta) { if (this.visible) { this.shakeEffect.update(time, delta); this.flashEffect.update(time, delta); this.fadeEffect.update(time, delta); } }, /** * This event is fired when a camera is destroyed by the Camera Manager. * * @event CameraDestroyEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that was destroyed. */ /** * Destroys this Camera instance. You rarely need to call this directly. * * Called by the Camera Manager. If you wish to destroy a Camera please use `CameraManager.remove` as * cameras are stored in a pool, ready for recycling later, and calling this directly will prevent that. * * @method Phaser.Cameras.Scene2D.Camera#destroy * @fires CameraDestroyEvent * @since 3.0.0 */ destroy: function () { this.emit('cameradestroy', this); this.removeAllListeners(); this.resetFX(); this.matrix.destroy(); this.culledObjects = []; this._follow = null; this._bounds = null; this.scene = null; }, /** * The x position of the center of the Camera's viewport, relative to the top-left of the game canvas. * * @name Phaser.Cameras.Scene2D.Camera#centerX * @type {number} * @readOnly * @since 3.10.0 */ centerX: { get: function () { return this.x + (0.5 * this.width); } }, /** * The y position of the center of the Camera's viewport, relative to the top-left of the game canvas. * * @name Phaser.Cameras.Scene2D.Camera#centerY * @type {number} * @readOnly * @since 3.10.0 */ centerY: { get: function () { return this.y + (0.5 * this.height); } } }); module.exports = Camera; /***/ }), /* 124 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @callback EachMapCallback * @generic E - [entry] * * @param {string} key - [description] * @param {*} entry - [description] * * @return {?boolean} [description] */ /** * @classdesc * The keys of a Map can be arbitrary values. * var map = new Map([ * [ 1, 'one' ], * [ 2, 'two' ], * [ 3, 'three' ] * ]); * * @class Map * @memberOf Phaser.Structs * @constructor * @since 3.0.0 * * @generic K * @generic V * @genericUse {V[]} - [elements] * * @param {Array.<*>} elements - [description] */ var Map = new Class({ initialize: function Map (elements) { /** * [description] * * @genericUse {Object.} - [$type] * * @name Phaser.Structs.Map#entries * @type {Object.} * @default {} * @since 3.0.0 */ this.entries = {}; /** * [description] * * @name Phaser.Structs.Map#size * @type {number} * @default 0 * @since 3.0.0 */ this.size = 0; if (Array.isArray(elements)) { for (var i = 0; i < elements.length; i++) { this.set(elements[i][0], elements[i][1]); } } }, /** * [description] * * @method Phaser.Structs.Map#set * @since 3.0.0 * * @genericUse {K} - [key] * @genericUse {V} - [value] * @genericUse {Phaser.Structs.Map.} - [$return] * * @param {string} key - [description] * @param {*} value - [description] * * @return {Phaser.Structs.Map} This Map object. */ set: function (key, value) { if (!this.has(key)) { this.entries[key] = value; this.size++; } return this; }, /** * [description] * * @method Phaser.Structs.Map#get * @since 3.0.0 * * @genericUse {K} - [key] * @genericUse {V} - [$return] * * @param {string} key - [description] * * @return {*} [description] */ get: function (key) { if (this.has(key)) { return this.entries[key]; } }, /** * [description] * * @method Phaser.Structs.Map#getArray * @since 3.0.0 * * @genericUse {V[]} - [$return] * * @return {Array.<*>} [description] */ getArray: function () { var output = []; var entries = this.entries; for (var key in entries) { output.push(entries[key]); } return output; }, /** * [description] * * @method Phaser.Structs.Map#has * @since 3.0.0 * * @genericUse {K} - [key] * * @param {string} key - [description] * * @return {boolean} [description] */ has: function (key) { return (this.entries.hasOwnProperty(key)); }, /** * [description] * * @method Phaser.Structs.Map#delete * @since 3.0.0 * * @genericUse {K} - [key] * @genericUse {Phaser.Structs.Map.} - [$return] * * @param {string} key - [description] * * @return {Phaser.Structs.Map} This Map object. */ delete: function (key) { if (this.has(key)) { delete this.entries[key]; this.size--; } return this; }, /** * [description] * * @method Phaser.Structs.Map#clear * @since 3.0.0 * * @genericUse {Phaser.Structs.Map.} - [$return] * * @return {Phaser.Structs.Map} This Map object. */ clear: function () { Object.keys(this.entries).forEach(function (prop) { delete this.entries[prop]; }, this); this.size = 0; return this; }, /** * [description] * * @method Phaser.Structs.Map#keys * @since 3.0.0 * * @genericUse {K[]} - [$return] * * @return {string[]} [description] */ keys: function () { return Object.keys(this.entries); }, /** * [description] * * @method Phaser.Structs.Map#values * @since 3.0.0 * * @genericUse {V[]} - [$return] * * @return {Array.<*>} [description] */ values: function () { var output = []; var entries = this.entries; for (var key in entries) { output.push(entries[key]); } return output; }, /** * [description] * * @method Phaser.Structs.Map#dump * @since 3.0.0 */ dump: function () { var entries = this.entries; // eslint-disable-next-line no-console console.group('Map'); for (var key in entries) { console.log(key, entries[key]); } // eslint-disable-next-line no-console console.groupEnd(); }, /** * [description] * * @method Phaser.Structs.Map#each * @since 3.0.0 * * @genericUse {EachMapCallback.} - [callback] * @genericUse {Phaser.Structs.Map.} - [$return] * * @param {EachMapCallback} callback - [description] * * @return {Phaser.Structs.Map} This Map object. */ each: function (callback) { var entries = this.entries; for (var key in entries) { if (callback(key, entries[key]) === false) { break; } } return this; }, /** * [description] * * @method Phaser.Structs.Map#contains * @since 3.0.0 * * @genericUse {V} - [value] * * @param {*} value - [description] * * @return {boolean} [description] */ contains: function (value) { var entries = this.entries; for (var key in entries) { if (entries[key] === value) { return true; } } return false; }, /** * Merges all new keys from the given Map into this one * If it encounters a key that already exists it will be skipped * unless override = true. * * @method Phaser.Structs.Map#merge * @since 3.0.0 * * @genericUse {Phaser.Structs.Map.} - [map,$return] * * @param {Phaser.Structs.Map} map - [description] * @param {boolean} [override=false] - [description] * * @return {Phaser.Structs.Map} This Map object. */ merge: function (map, override) { if (override === undefined) { override = false; } var local = this.entries; var source = map.entries; for (var key in source) { if (local.hasOwnProperty(key) && override) { local[key] = source[key]; } else { this.set(key, source[key]); } } return this; } }); module.exports = Map; /***/ }), /* 125 */, /* 126 */, /* 127 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetAdvancedValue = __webpack_require__(10); /** * Adds an Animation component to a Sprite and populates it based on the given config. * * @function Phaser.GameObjects.BuildGameObjectAnimation * @since 3.0.0 * * @param {Phaser.GameObjects.Sprite} sprite - The sprite to add an Animation component to. * @param {object} config - The animation config. * * @return {Phaser.GameObjects.Sprite} The updated Sprite. */ var BuildGameObjectAnimation = function (sprite, config) { var animConfig = GetAdvancedValue(config, 'anims', null); if (animConfig === null) { return sprite; } if (typeof animConfig === 'string') { // { anims: 'key' } sprite.anims.play(animConfig); } else if (typeof animConfig === 'object') { // { anims: { // key: string // startFrame: [string|integer] // delay: [float] // repeat: [integer] // repeatDelay: [float] // yoyo: [boolean] // play: [boolean] // delayedPlay: [boolean] // } // } var anims = sprite.anims; var key = GetAdvancedValue(animConfig, 'key', undefined); var startFrame = GetAdvancedValue(animConfig, 'startFrame', undefined); var delay = GetAdvancedValue(animConfig, 'delay', 0); var repeat = GetAdvancedValue(animConfig, 'repeat', 0); var repeatDelay = GetAdvancedValue(animConfig, 'repeatDelay', 0); var yoyo = GetAdvancedValue(animConfig, 'yoyo', false); var play = GetAdvancedValue(animConfig, 'play', false); var delayedPlay = GetAdvancedValue(animConfig, 'delayedPlay', 0); anims.delay(delay); anims.repeat(repeat); anims.repeatDelay(repeatDelay); anims.yoyo(yoyo); if (play) { anims.play(key, startFrame); } else if (delayedPlay > 0) { anims.delayedPlay(delayedPlay, key, startFrame); } else { anims.load(key); } } return sprite; }; module.exports = BuildGameObjectAnimation; /***/ }), /* 128 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Extend = __webpack_require__(17); /** * @classdesc * A Frame is a section of a Texture. * * @class Frame * @memberOf Phaser.Textures * @constructor * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture this Frame is a part of. * @param {(integer|string)} name - The name of this Frame. The name is unique within the Texture. * @param {integer} sourceIndex - The index of the TextureSource that this Frame is a part of. * @param {number} x - The x coordinate of the top-left of this Frame. * @param {number} y - The y coordinate of the top-left of this Frame. * @param {number} width - The width of this Frame. * @param {number} height - The height of this Frame. */ var Frame = new Class({ initialize: function Frame (texture, name, sourceIndex, x, y, width, height) { /** * The Texture this Frame is a part of. * * @name Phaser.Textures.Frame#texture * @type {Phaser.Textures.Texture} * @since 3.0.0 */ this.texture = texture; /** * The name of this Frame. * The name is unique within the Texture. * * @name Phaser.Textures.Frame#name * @type {string} * @since 3.0.0 */ this.name = name; /** * The TextureSource this Frame is part of. * * @name Phaser.Textures.Frame#source * @type {Phaser.Textures.TextureSource} * @since 3.0.0 */ this.source = texture.source[sourceIndex]; /** * The index of the TextureSource in the Texture sources array. * * @name Phaser.Textures.Frame#sourceIndex * @type {integer} * @since 3.0.0 */ this.sourceIndex = sourceIndex; /** * X position within the source image to cut from. * * @name Phaser.Textures.Frame#cutX * @type {integer} * @since 3.0.0 */ this.cutX; /** * Y position within the source image to cut from. * * @name Phaser.Textures.Frame#cutY * @type {integer} * @since 3.0.0 */ this.cutY; /** * The width of the area in the source image to cut. * * @name Phaser.Textures.Frame#cutWidth * @type {integer} * @since 3.0.0 */ this.cutWidth; /** * The height of the area in the source image to cut. * * @name Phaser.Textures.Frame#cutHeight * @type {integer} * @since 3.0.0 */ this.cutHeight; /** * The X rendering offset of this Frame, taking trim into account. * * @name Phaser.Textures.Frame#x * @type {integer} * @default 0 * @since 3.0.0 */ this.x = 0; /** * The Y rendering offset of this Frame, taking trim into account. * * @name Phaser.Textures.Frame#y * @type {integer} * @default 0 * @since 3.0.0 */ this.y = 0; /** * The rendering width of this Frame, taking trim into account. * * @name Phaser.Textures.Frame#width * @type {integer} * @since 3.0.0 */ this.width; /** * The rendering height of this Frame, taking trim into account. * * @name Phaser.Textures.Frame#height * @type {integer} * @since 3.0.0 */ this.height; /** * Half the width, floored. * Precalculated for the renderer. * * @name Phaser.Textures.Frame#halfWidth * @type {integer} * @since 3.0.0 */ this.halfWidth; /** * Half the height, floored. * Precalculated for the renderer. * * @name Phaser.Textures.Frame#halfHeight * @type {integer} * @since 3.0.0 */ this.halfHeight; /** * The x center of this frame, floored. * * @name Phaser.Textures.Frame#centerX * @type {integer} * @since 3.0.0 */ this.centerX; /** * The y center of this frame, floored. * * @name Phaser.Textures.Frame#centerY * @type {integer} * @since 3.0.0 */ this.centerY; /** * The horizontal pivot point of this Frame. * * @name Phaser.Textures.Frame#pivotX * @type {number} * @default 0 * @since 3.0.0 */ this.pivotX = 0; /** * The vertical pivot point of this Frame. * * @name Phaser.Textures.Frame#pivotY * @type {number} * @default 0 * @since 3.0.0 */ this.pivotY = 0; /** * Does this Frame have a custom pivot point? * * @name Phaser.Textures.Frame#customPivot * @type {boolean} * @default false * @since 3.0.0 */ this.customPivot = false; /** * **CURRENTLY UNSUPPORTED** * * Is this frame is rotated or not in the Texture? * Rotation allows you to use rotated frames in texture atlas packing. * It has nothing to do with Sprite rotation. * * @name Phaser.Textures.Frame#rotated * @type {boolean} * @default false * @since 3.0.0 */ this.rotated = false; /** * Over-rides the Renderer setting. * -1 = use Renderer Setting * 0 = No rounding * 1 = Round * * @name Phaser.Textures.Frame#autoRound * @type {integer} * @default -1 * @since 3.0.0 */ this.autoRound = -1; /** * Any Frame specific custom data can be stored here. * * @name Phaser.Textures.Frame#customData * @type {object} * @since 3.0.0 */ this.customData = {}; /** * The un-modified source frame, trim and UV data. * * @name Phaser.Textures.Frame#data * @type {object} * @private * @since 3.0.0 */ this.data = { cut: { x: 0, y: 0, w: 0, h: 0, r: 0, b: 0 }, trim: false, sourceSize: { w: 0, h: 0 }, spriteSourceSize: { x: 0, y: 0, w: 0, h: 0 }, uvs: { x0: 0, y0: 0, x1: 0, y1: 0, x2: 0, y2: 0, x3: 0, y3: 0 }, radius: 0, drawImage: { sx: 0, sy: 0, sWidth: 0, sHeight: 0, dWidth: 0, dHeight: 0 } }; this.setSize(width, height, x, y); }, /** * Sets the width, height, x and y of this Frame. * * This is called automatically by the constructor * and should rarely be changed on-the-fly. * * @method Phaser.Textures.Frame#setSize * @since 3.7.0 * * @param {integer} width - The width of the frame before being trimmed. * @param {integer} height - The height of the frame before being trimmed. * @param {integer} [x=0] - The x coordinate of the top-left of this Frame. * @param {integer} [y=0] - The y coordinate of the top-left of this Frame. * * @return {Phaser.Textures.Frame} This Frame object. */ setSize: function (width, height, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } this.cutX = x; this.cutY = y; this.cutWidth = width; this.cutHeight = height; this.width = width; this.height = height; this.halfWidth = Math.floor(width * 0.5); this.halfHeight = Math.floor(height * 0.5); this.centerX = Math.floor(width / 2); this.centerY = Math.floor(height / 2); var data = this.data; var cut = data.cut; cut.x = x; cut.y = y; cut.w = width; cut.h = height; cut.r = x + width; cut.b = y + height; data.sourceSize.w = width; data.sourceSize.h = height; data.spriteSourceSize.w = width; data.spriteSourceSize.h = height; data.radius = 0.5 * Math.sqrt(width * width + height * height); var drawImage = data.drawImage; drawImage.sx = x; drawImage.sy = y; drawImage.sWidth = width; drawImage.sHeight = height; drawImage.dWidth = width; drawImage.dHeight = height; return this.updateUVs(); }, /** * If the frame was trimmed when added to the Texture Atlas, this records the trim and source data. * * @method Phaser.Textures.Frame#setTrim * @since 3.0.0 * * @param {number} actualWidth - The width of the frame before being trimmed. * @param {number} actualHeight - The height of the frame before being trimmed. * @param {number} destX - The destination X position of the trimmed frame for display. * @param {number} destY - The destination Y position of the trimmed frame for display. * @param {number} destWidth - The destination width of the trimmed frame for display. * @param {number} destHeight - The destination height of the trimmed frame for display. * * @return {Phaser.Textures.Frame} This Frame object. */ setTrim: function (actualWidth, actualHeight, destX, destY, destWidth, destHeight) { var data = this.data; var ss = data.spriteSourceSize; // Store actual values data.trim = true; data.sourceSize.w = actualWidth; data.sourceSize.h = actualHeight; ss.x = destX; ss.y = destY; ss.w = destWidth; ss.h = destHeight; // Adjust properties this.x = destX; this.y = destY; this.width = destWidth; this.height = destHeight; this.halfWidth = destWidth * 0.5; this.halfHeight = destHeight * 0.5; this.centerX = Math.floor(destWidth / 2); this.centerY = Math.floor(destHeight / 2); return this.updateUVs(); }, /** * Updates the internal WebGL UV cache and the drawImage cache. * * @method Phaser.Textures.Frame#updateUVs * @since 3.0.0 * * @return {Phaser.Textures.Frame} This Frame object. */ updateUVs: function () { var cx = this.cutX; var cy = this.cutY; var cw = this.cutWidth; var ch = this.cutHeight; // Canvas data var cd = this.data.drawImage; cd.sWidth = cw; cd.sHeight = ch; cd.dWidth = cw; cd.dHeight = ch; // WebGL data var tw = this.source.width; var th = this.source.height; var uvs = this.data.uvs; uvs.x0 = cx / tw; uvs.y0 = cy / th; uvs.x1 = cx / tw; uvs.y1 = (cy + ch) / th; uvs.x2 = (cx + cw) / tw; uvs.y2 = (cy + ch) / th; uvs.x3 = (cx + cw) / tw; uvs.y3 = cy / th; return this; }, /** * Updates the internal WebGL UV cache. * * @method Phaser.Textures.Frame#updateUVsInverted * @since 3.0.0 * * @return {Phaser.Textures.Frame} This Frame object. */ updateUVsInverted: function () { var tw = this.source.width; var th = this.source.height; var uvs = this.data.uvs; uvs.x3 = (this.cutX + this.cutHeight) / tw; uvs.y3 = (this.cutY + this.cutWidth) / th; uvs.x2 = this.cutX / tw; uvs.y2 = (this.cutY + this.cutWidth) / th; uvs.x1 = this.cutX / tw; uvs.y1 = this.cutY / th; uvs.x0 = (this.cutX + this.cutHeight) / tw; uvs.y0 = this.cutY / th; return this; }, /** * Clones this Frame into a new Frame object. * * @method Phaser.Textures.Frame#clone * @since 3.0.0 * * @return {Phaser.Textures.Frame} A clone of this Frame. */ clone: function () { var clone = new Frame(this.texture, this.name, this.sourceIndex); clone.cutX = this.cutX; clone.cutY = this.cutY; clone.cutWidth = this.cutWidth; clone.cutHeight = this.cutHeight; clone.x = this.x; clone.y = this.y; clone.width = this.width; clone.height = this.height; clone.halfWidth = this.halfWidth; clone.halfHeight = this.halfHeight; clone.centerX = this.centerX; clone.centerY = this.centerY; clone.rotated = this.rotated; clone.data = Extend(true, clone.data, this.data); clone.updateUVs(); return clone; }, /** * Destroys this Frames references. * * @method Phaser.Textures.Frame#destroy * @since 3.0.0 */ destroy: function () { this.texture = null; this.source = null; }, /** * The width of the Frame in its un-trimmed, un-padded state, as prepared in the art package, * before being packed. * * @name Phaser.Textures.Frame#realWidth * @type {number} * @readOnly * @since 3.0.0 */ realWidth: { get: function () { return this.data.sourceSize.w; } }, /** * The height of the Frame in its un-trimmed, un-padded state, as prepared in the art package, * before being packed. * * @name Phaser.Textures.Frame#realHeight * @type {number} * @readOnly * @since 3.0.0 */ realHeight: { get: function () { return this.data.sourceSize.h; } }, /** * The UV data for this Frame. * * @name Phaser.Textures.Frame#uvs * @type {object} * @readOnly * @since 3.0.0 */ uvs: { get: function () { return this.data.uvs; } }, /** * The radius of the Frame (derived from sqrt(w * w + h * h) / 2) * * @name Phaser.Textures.Frame#radius * @type {number} * @readOnly * @since 3.0.0 */ radius: { get: function () { return this.data.radius; } }, /** * Is the Frame trimmed or not? * * @name Phaser.Textures.Frame#trimmed * @type {boolean} * @readOnly * @since 3.0.0 */ trimmed: { get: function () { return this.data.trim; } }, /** * The Canvas drawImage data object. * * @name Phaser.Textures.Frame#canvasData * @type {object} * @readOnly * @since 3.0.0 */ canvasData: { get: function () { return this.data.drawImage; } } }); module.exports = Frame; /***/ }), /* 129 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Felipe Alfonso <@bitnenfer> * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var ModelViewProjection = __webpack_require__(202); var ShaderSourceFS = __webpack_require__(526); var ShaderSourceVS = __webpack_require__(525); var Utils = __webpack_require__(27); var WebGLPipeline = __webpack_require__(84); /** * @classdesc * TextureTintPipeline implements the rendering infrastructure * for displaying textured objects * The config properties are: * - game: Current game instance. * - renderer: Current WebGL renderer. * - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES. * Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants). * - vertShader: Source for vertex shader as a string. * - fragShader: Source for fragment shader as a string. * - vertexCapacity: The amount of vertices that shall be allocated * - vertexSize: The size of a single vertex in bytes. * * @class TextureTintPipeline * @extends Phaser.Renderer.WebGL.WebGLPipeline * @memberOf Phaser.Renderer.WebGL.Pipelines * @constructor * @since 3.0.0 * * @param {object} config - [description] */ var TextureTintPipeline = new Class({ Extends: WebGLPipeline, Mixins: [ ModelViewProjection ], initialize: function TextureTintPipeline (config) { WebGLPipeline.call(this, { game: config.game, renderer: config.renderer, gl: config.renderer.gl, topology: (config.topology ? config.topology : config.renderer.gl.TRIANGLES), vertShader: (config.vertShader ? config.vertShader : ShaderSourceVS), fragShader: (config.fragShader ? config.fragShader : ShaderSourceFS), vertexCapacity: (config.vertexCapacity ? config.vertexCapacity : 6 * 2000), vertexSize: (config.vertexSize ? config.vertexSize : Float32Array.BYTES_PER_ELEMENT * 2 + Float32Array.BYTES_PER_ELEMENT * 2 + Uint8Array.BYTES_PER_ELEMENT * 4), attributes: [ { name: 'inPosition', size: 2, type: config.renderer.gl.FLOAT, normalized: false, offset: 0 }, { name: 'inTexCoord', size: 2, type: config.renderer.gl.FLOAT, normalized: false, offset: Float32Array.BYTES_PER_ELEMENT * 2 }, { name: 'inTint', size: 4, type: config.renderer.gl.UNSIGNED_BYTE, normalized: true, offset: Float32Array.BYTES_PER_ELEMENT * 4 } ] }); /** * Float32 view of the array buffer containing the pipeline's vertices. * * @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#vertexViewF32 * @type {Float32Array} * @since 3.0.0 */ this.vertexViewF32 = new Float32Array(this.vertexData); /** * Uint32 view of the array buffer containing the pipeline's vertices. * * @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#vertexViewU32 * @type {Uint32Array} * @since 3.0.0 */ this.vertexViewU32 = new Uint32Array(this.vertexData); /** * Size of the batch. * * @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#maxQuads * @type {integer} * @default 2000 * @since 3.0.0 */ this.maxQuads = 2000; /** * Collection of batch information * * @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batches * @type {array} * @since 3.1.0 */ this.batches = []; this.mvpInit(); }, /** * Assigns a texture to the current batch. If a texture is already set it creates * a new batch object. * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#setTexture2D * @since 3.1.0 * * @param {WebGLTexture} texture - WebGLTexture that will be assigned to the current batch. * @param {integer} textureUnit - Texture unit to which the texture needs to be bound. * * @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} [description] */ setTexture2D: function (texture, unit) { if (!texture) { return this; } var batches = this.batches; if (batches.length === 0) { this.pushBatch(); } var batch = batches[batches.length - 1]; if (unit > 0) { if (batch.textures[unit - 1] && batch.textures[unit - 1] !== texture) { this.pushBatch(); } batches[batches.length - 1].textures[unit - 1] = texture; } else { if (batch.texture !== null && batch.texture !== texture) { this.pushBatch(); } batches[batches.length - 1].texture = texture; } return this; }, /** * Creates a new batch object and pushes it to a batch array. * The batch object contains information relevant to the current * vertex batch like the offset in the vertex buffer, vertex count and * the textures used by that batch. * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#pushBatch * @since 3.1.0 */ pushBatch: function () { var batch = { first: this.vertexCount, texture: null, textures: [] }; this.batches.push(batch); }, /** * Binds, uploads resources and processes all batches generating draw calls. * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#flush * @since 3.1.0 * * @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} This Pipeline. */ flush: function () { if (this.flushLocked) { return this; } this.flushLocked = true; var gl = this.gl; var renderer = this.renderer; var vertexCount = this.vertexCount; var topology = this.topology; var vertexSize = this.vertexSize; var batches = this.batches; var batchCount = batches.length; var batchVertexCount = 0; var batch = null; var batchNext; var textureIndex; var nTexture; if (batchCount === 0 || vertexCount === 0) { this.flushLocked = false; return this; } gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.bytes.subarray(0, vertexCount * vertexSize)); for (var index = 0; index < batches.length - 1; ++index) { batch = batches[index]; batchNext = batches[index + 1]; if (batch.textures.length > 0) { for (textureIndex = 0; textureIndex < batch.textures.length; ++textureIndex) { nTexture = batch.textures[textureIndex]; if (nTexture) { renderer.setTexture2D(nTexture, 1 + textureIndex); } } gl.activeTexture(gl.TEXTURE0); } batchVertexCount = batchNext.first - batch.first; if (batch.texture === null || batchVertexCount <= 0) { continue; } renderer.setTexture2D(batch.texture, 0); gl.drawArrays(topology, batch.first, batchVertexCount); } // Left over data batch = batches[batches.length - 1]; if (batch.textures.length > 0) { for (textureIndex = 0; textureIndex < batch.textures.length; ++textureIndex) { nTexture = batch.textures[textureIndex]; if (nTexture) { renderer.setTexture2D(nTexture, 1 + textureIndex); } } gl.activeTexture(gl.TEXTURE0); } batchVertexCount = vertexCount - batch.first; if (batch.texture && batchVertexCount > 0) { renderer.setTexture2D(batch.texture, 0); gl.drawArrays(topology, batch.first, batchVertexCount); } this.vertexCount = 0; batches.length = 0; this.pushBatch(); this.flushLocked = false; return this; }, /** * Called every time the pipeline needs to be used. * It binds all necessary resources. * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#onBind * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} [description] */ onBind: function () { WebGLPipeline.prototype.onBind.call(this); this.mvpUpdate(); if (this.batches.length === 0) { this.pushBatch(); } return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#resize * @since 3.0.0 * * @param {number} width - [description] * @param {number} height - [description] * @param {number} resolution - [description] * * @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} [description] */ resize: function (width, height, resolution) { WebGLPipeline.prototype.resize.call(this, width, height, resolution); this.projOrtho(0, this.width, this.height, 0, -1000.0, 1000.0); return this; }, /** * Renders immediately a static tilemap. This function won't use * the batching functionality of the pipeline. * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawStaticTilemapLayer * @since 3.0.0 * * @param {Phaser.Tilemaps.StaticTilemapLayer} tilemap - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ drawStaticTilemapLayer: function (tilemap) { if (tilemap.vertexCount > 0) { var pipelineVertexBuffer = this.vertexBuffer; var gl = this.gl; var renderer = this.renderer; var frame = tilemap.tileset.image.get(); if (renderer.currentPipeline && renderer.currentPipeline.vertexCount > 0) { renderer.flush(); } this.vertexBuffer = tilemap.vertexBuffer; renderer.setPipeline(this); renderer.setTexture2D(frame.source.glTexture, 0); gl.drawArrays(this.topology, 0, tilemap.vertexCount); this.vertexBuffer = pipelineVertexBuffer; } this.viewIdentity(); this.modelIdentity(); }, /** * Renders contents of a ParticleEmitterManager. It'll batch all particles if possible. * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawEmitterManager * @since 3.0.0 * * @param {Phaser.GameObjects.Particles.ParticleEmitterManager} emitterManager - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ drawEmitterManager: function (emitterManager, camera, parentTransformMatrix) { var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } this.renderer.setPipeline(this); var roundPixels = this.renderer.config.roundPixels; var emitters = emitterManager.emitters.list; var emitterCount = emitters.length; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var renderer = this.renderer; var maxQuads = this.maxQuads; var cameraScrollX = camera.scrollX; var cameraScrollY = camera.scrollY; var cameraMatrix = camera.matrix.matrix; var cma = cameraMatrix[0]; var cmb = cameraMatrix[1]; var cmc = cameraMatrix[2]; var cmd = cameraMatrix[3]; var cme = cameraMatrix[4]; var cmf = cameraMatrix[5]; var sin = Math.sin; var cos = Math.cos; var vertexComponentCount = this.vertexComponentCount; var vertexCapacity = this.vertexCapacity; var texture = emitterManager.defaultFrame.source.glTexture; var pca, pcb, pcc, pcd, pce, pcf; var pma, pmb, pmc, pmd, pme, pmf; if (parentMatrix) { pma = parentMatrix[0]; pmb = parentMatrix[1]; pmc = parentMatrix[2]; pmd = parentMatrix[3]; pme = parentMatrix[4]; pmf = parentMatrix[5]; } this.setTexture2D(texture, 0); for (var emitterIndex = 0; emitterIndex < emitterCount; ++emitterIndex) { var emitter = emitters[emitterIndex]; var particles = emitter.alive; var aliveLength = particles.length; var batchCount = Math.ceil(aliveLength / maxQuads); var particleOffset = 0; var scrollX = cameraScrollX * emitter.scrollFactorX; var scrollY = cameraScrollY * emitter.scrollFactorY; if (parentMatrix) { var cse = -scrollX; var csf = -scrollY; var pse = cse * cma + csf * cmc + cme; var psf = cse * cmb + csf * cmd + cmf; pca = pma * cma + pmb * cmc; pcb = pma * cmb + pmb * cmd; pcc = pmc * cma + pmd * cmc; pcd = pmc * cmb + pmd * cmd; pce = pme * cma + pmf * cmc + pse; pcf = pme * cmb + pmf * cmd + psf; cma = pca; cmb = pcb; cmc = pcc; cmd = pcd; cme = pce; cmf = pcf; scrollX = 0.0; scrollY = 0.0; } if (!emitter.visible || aliveLength === 0) { continue; } renderer.setBlendMode(emitter.blendMode); if (this.vertexCount >= vertexCapacity) { this.flush(); this.setTexture2D(texture, 0); } for (var batchIndex = 0; batchIndex < batchCount; ++batchIndex) { var batchSize = Math.min(aliveLength, maxQuads); for (var index = 0; index < batchSize; ++index) { var particle = particles[particleOffset + index]; if (particle.alpha <= 0) { continue; } var frame = particle.frame; var uvs = frame.uvs; var x = -(frame.halfWidth); var y = -(frame.halfHeight); var color = particle.color; var xw = x + frame.width; var yh = y + frame.height; var sr = sin(particle.rotation); var cr = cos(particle.rotation); var sra = cr * particle.scaleX; var srb = sr * particle.scaleX; var src = -sr * particle.scaleY; var srd = cr * particle.scaleY; var sre = particle.x - scrollX; var srf = particle.y - scrollY; var mva = sra * cma + srb * cmc; var mvb = sra * cmb + srb * cmd; var mvc = src * cma + srd * cmc; var mvd = src * cmb + srd * cmd; var mve = sre * cma + srf * cmc + cme; var mvf = sre * cmb + srf * cmd + cmf; var tx0 = x * mva + y * mvc + mve; var ty0 = x * mvb + y * mvd + mvf; var tx1 = x * mva + yh * mvc + mve; var ty1 = x * mvb + yh * mvd + mvf; var tx2 = xw * mva + yh * mvc + mve; var ty2 = xw * mvb + yh * mvd + mvf; var tx3 = xw * mva + y * mvc + mve; var ty3 = xw * mvb + y * mvd + mvf; var vertexOffset = this.vertexCount * vertexComponentCount; if (roundPixels) { tx0 |= 0; ty0 |= 0; tx1 |= 0; ty1 |= 0; tx2 |= 0; ty2 |= 0; tx3 |= 0; ty3 |= 0; } vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewF32[vertexOffset + 2] = uvs.x0; vertexViewF32[vertexOffset + 3] = uvs.y0; vertexViewU32[vertexOffset + 4] = color; vertexViewF32[vertexOffset + 5] = tx1; vertexViewF32[vertexOffset + 6] = ty1; vertexViewF32[vertexOffset + 7] = uvs.x1; vertexViewF32[vertexOffset + 8] = uvs.y1; vertexViewU32[vertexOffset + 9] = color; vertexViewF32[vertexOffset + 10] = tx2; vertexViewF32[vertexOffset + 11] = ty2; vertexViewF32[vertexOffset + 12] = uvs.x2; vertexViewF32[vertexOffset + 13] = uvs.y2; vertexViewU32[vertexOffset + 14] = color; vertexViewF32[vertexOffset + 15] = tx0; vertexViewF32[vertexOffset + 16] = ty0; vertexViewF32[vertexOffset + 17] = uvs.x0; vertexViewF32[vertexOffset + 18] = uvs.y0; vertexViewU32[vertexOffset + 19] = color; vertexViewF32[vertexOffset + 20] = tx2; vertexViewF32[vertexOffset + 21] = ty2; vertexViewF32[vertexOffset + 22] = uvs.x2; vertexViewF32[vertexOffset + 23] = uvs.y2; vertexViewU32[vertexOffset + 24] = color; vertexViewF32[vertexOffset + 25] = tx3; vertexViewF32[vertexOffset + 26] = ty3; vertexViewF32[vertexOffset + 27] = uvs.x3; vertexViewF32[vertexOffset + 28] = uvs.y3; vertexViewU32[vertexOffset + 29] = color; this.vertexCount += 6; if (this.vertexCount >= vertexCapacity) { this.flush(); this.setTexture2D(texture, 0); } } particleOffset += batchSize; aliveLength -= batchSize; if (this.vertexCount >= vertexCapacity) { this.flush(); this.setTexture2D(texture, 0); } } } this.setTexture2D(texture, 0); }, /** * Batches blitter game object * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawBlitter * @since 3.0.0 * * @param {Phaser.GameObjects.Blitter} blitter - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ drawBlitter: function (blitter, camera, parentTransformMatrix) { var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } this.renderer.setPipeline(this); var roundPixels = this.renderer.config.roundPixels; var getTint = Utils.getTintAppendFloatAlpha; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var list = blitter.getRenderList(); var length = list.length; var cameraMatrix = camera.matrix.matrix; var a = cameraMatrix[0]; var b = cameraMatrix[1]; var c = cameraMatrix[2]; var d = cameraMatrix[3]; var e = cameraMatrix[4]; var f = cameraMatrix[5]; var cameraScrollX = camera.scrollX * blitter.scrollFactorX; var cameraScrollY = camera.scrollY * blitter.scrollFactorY; var batchCount = Math.ceil(length / this.maxQuads); var batchOffset = 0; if (parentMatrix) { var pma = parentMatrix[0]; var pmb = parentMatrix[1]; var pmc = parentMatrix[2]; var pmd = parentMatrix[3]; var pme = parentMatrix[4]; var pmf = parentMatrix[5]; var cse = -cameraScrollX; var csf = -cameraScrollY; var pse = cse * a + csf * c + e; var psf = cse * b + csf * d + f; var pca = pma * a + pmb * c; var pcb = pma * b + pmb * d; var pcc = pmc * a + pmd * c; var pcd = pmc * b + pmd * d; var pce = pme * a + pmf * c + pse; var pcf = pme * b + pmf * d + psf; a = pca; b = pcb; c = pcc; d = pcd; e = pce; f = pcf; cameraScrollX = 0.0; cameraScrollY = 0.0; } var blitterX = blitter.x - cameraScrollX; var blitterY = blitter.y - cameraScrollY; var prevTextureSourceIndex; for (var batchIndex = 0; batchIndex < batchCount; ++batchIndex) { var batchSize = Math.min(length, this.maxQuads); for (var index = 0; index < batchSize; ++index) { var bob = list[batchOffset + index]; var frame = bob.frame; var alpha = bob.alpha; if (alpha === 0) { // Nothing to see here, moving on ... continue; } var tint = getTint(0xffffff, alpha); var uvs = frame.uvs; var flipX = bob.flipX; var flipY = bob.flipY; var width = frame.width * (flipX ? -1.0 : 1.0); var height = frame.height * (flipY ? -1.0 : 1.0); var x = blitterX + bob.x + frame.x + (frame.width * ((flipX) ? 1.0 : 0.0)); var y = blitterY + bob.y + frame.y + (frame.height * ((flipY) ? 1.0 : 0.0)); var xw = x + width; var yh = y + height; var tx0 = x * a + y * c + e; var ty0 = x * b + y * d + f; var tx1 = xw * a + yh * c + e; var ty1 = xw * b + yh * d + f; // Bind texture only if the Texture Source is different from before if (frame.sourceIndex !== prevTextureSourceIndex) { this.setTexture2D(frame.texture.source[frame.sourceIndex].glTexture, 0); prevTextureSourceIndex = frame.sourceIndex; } var vertexOffset = this.vertexCount * this.vertexComponentCount; if (roundPixels) { tx0 |= 0; ty0 |= 0; tx1 |= 0; ty1 |= 0; } vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewF32[vertexOffset + 2] = uvs.x0; vertexViewF32[vertexOffset + 3] = uvs.y0; vertexViewU32[vertexOffset + 4] = tint; vertexViewF32[vertexOffset + 5] = tx0; vertexViewF32[vertexOffset + 6] = ty1; vertexViewF32[vertexOffset + 7] = uvs.x1; vertexViewF32[vertexOffset + 8] = uvs.y1; vertexViewU32[vertexOffset + 9] = tint; vertexViewF32[vertexOffset + 10] = tx1; vertexViewF32[vertexOffset + 11] = ty1; vertexViewF32[vertexOffset + 12] = uvs.x2; vertexViewF32[vertexOffset + 13] = uvs.y2; vertexViewU32[vertexOffset + 14] = tint; vertexViewF32[vertexOffset + 15] = tx0; vertexViewF32[vertexOffset + 16] = ty0; vertexViewF32[vertexOffset + 17] = uvs.x0; vertexViewF32[vertexOffset + 18] = uvs.y0; vertexViewU32[vertexOffset + 19] = tint; vertexViewF32[vertexOffset + 20] = tx1; vertexViewF32[vertexOffset + 21] = ty1; vertexViewF32[vertexOffset + 22] = uvs.x2; vertexViewF32[vertexOffset + 23] = uvs.y2; vertexViewU32[vertexOffset + 24] = tint; vertexViewF32[vertexOffset + 25] = tx1; vertexViewF32[vertexOffset + 26] = ty0; vertexViewF32[vertexOffset + 27] = uvs.x3; vertexViewF32[vertexOffset + 28] = uvs.y3; vertexViewU32[vertexOffset + 29] = tint; this.vertexCount += 6; if (this.vertexCount >= this.vertexCapacity) { this.flush(); prevTextureSourceIndex = -1; } } batchOffset += batchSize; length -= batchSize; if (this.vertexCount >= this.vertexCapacity) { this.flush(); } } }, /** * Batches Sprite game object * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchSprite * @since 3.0.0 * * @param {Phaser.GameObjects.Sprite} sprite - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ batchSprite: function (sprite, camera, parentTransformMatrix) { var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } this.renderer.setPipeline(this); if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } var roundPixels = this.renderer.config.roundPixels; var getTint = Utils.getTintAppendFloatAlpha; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var cameraMatrix = camera.matrix.matrix; var frame = sprite.frame; var texture = frame.texture.source[frame.sourceIndex].glTexture; var forceFlipY = (texture.isRenderTexture ? true : false); var flipX = sprite.flipX; var flipY = sprite.flipY ^ forceFlipY; var uvs = frame.uvs; var width = frame.width * (flipX ? -1.0 : 1.0); var height = frame.height * (flipY ? -1.0 : 1.0); var x = -sprite.displayOriginX + frame.x + ((frame.width) * (flipX ? 1.0 : 0.0)); var y = -sprite.displayOriginY + frame.y + ((frame.height) * (flipY ? 1.0 : 0.0)); var xw = (roundPixels ? (x|0) : x) + width; var yh = (roundPixels ? (y|0) : y) + height; var scaleX = sprite.scaleX; var scaleY = sprite.scaleY; var rotation = sprite.rotation; var alphaTL = sprite._alphaTL; var alphaTR = sprite._alphaTR; var alphaBL = sprite._alphaBL; var alphaBR = sprite._alphaBR; var tintTL = sprite._tintTL; var tintTR = sprite._tintTR; var tintBL = sprite._tintBL; var tintBR = sprite._tintBR; var sr = Math.sin(rotation); var cr = Math.cos(rotation); var sra = cr * scaleX; var srb = sr * scaleX; var src = -sr * scaleY; var srd = cr * scaleY; var sre = sprite.x; var srf = sprite.y; var cma = cameraMatrix[0]; var cmb = cameraMatrix[1]; var cmc = cameraMatrix[2]; var cmd = cameraMatrix[3]; var cme = cameraMatrix[4]; var cmf = cameraMatrix[5]; var mva, mvb, mvc, mvd, mve, mvf; if (parentMatrix) { var pma = parentMatrix[0]; var pmb = parentMatrix[1]; var pmc = parentMatrix[2]; var pmd = parentMatrix[3]; var pme = parentMatrix[4]; var pmf = parentMatrix[5]; var cse = -camera.scrollX * sprite.scrollFactorX; var csf = -camera.scrollY * sprite.scrollFactorY; var pse = cse * cma + csf * cmc + cme; var psf = cse * cmb + csf * cmd + cmf; var pca = pma * cma + pmb * cmc; var pcb = pma * cmb + pmb * cmd; var pcc = pmc * cma + pmd * cmc; var pcd = pmc * cmb + pmd * cmd; var pce = pme * cma + pmf * cmc + pse; var pcf = pme * cmb + pmf * cmd + psf; mva = sra * pca + srb * pcc; mvb = sra * pcb + srb * pcd; mvc = src * pca + srd * pcc; mvd = src * pcb + srd * pcd; mve = sre * pca + srf * pcc + pce; mvf = sre * pcb + srf * pcd + pcf; } else { sre -= camera.scrollX * sprite.scrollFactorX; srf -= camera.scrollY * sprite.scrollFactorY; mva = sra * cma + srb * cmc; mvb = sra * cmb + srb * cmd; mvc = src * cma + srd * cmc; mvd = src * cmb + srd * cmd; mve = sre * cma + srf * cmc + cme; mvf = sre * cmb + srf * cmd + cmf; } var tx0 = x * mva + y * mvc + mve; var ty0 = x * mvb + y * mvd + mvf; var tx1 = x * mva + yh * mvc + mve; var ty1 = x * mvb + yh * mvd + mvf; var tx2 = xw * mva + yh * mvc + mve; var ty2 = xw * mvb + yh * mvd + mvf; var tx3 = xw * mva + y * mvc + mve; var ty3 = xw * mvb + y * mvd + mvf; var vTintTL = getTint(tintTL, alphaTL); var vTintTR = getTint(tintTR, alphaTR); var vTintBL = getTint(tintBL, alphaBL); var vTintBR = getTint(tintBR, alphaBR); var vertexOffset = 0; if (roundPixels) { tx0 |= 0; ty0 |= 0; tx1 |= 0; ty1 |= 0; tx2 |= 0; ty2 |= 0; tx3 |= 0; ty3 |= 0; } this.setTexture2D(texture, 0); vertexOffset = this.vertexCount * this.vertexComponentCount; vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewF32[vertexOffset + 2] = uvs.x0; vertexViewF32[vertexOffset + 3] = uvs.y0; vertexViewU32[vertexOffset + 4] = vTintTL; vertexViewF32[vertexOffset + 5] = tx1; vertexViewF32[vertexOffset + 6] = ty1; vertexViewF32[vertexOffset + 7] = uvs.x1; vertexViewF32[vertexOffset + 8] = uvs.y1; vertexViewU32[vertexOffset + 9] = vTintBL; vertexViewF32[vertexOffset + 10] = tx2; vertexViewF32[vertexOffset + 11] = ty2; vertexViewF32[vertexOffset + 12] = uvs.x2; vertexViewF32[vertexOffset + 13] = uvs.y2; vertexViewU32[vertexOffset + 14] = vTintBR; vertexViewF32[vertexOffset + 15] = tx0; vertexViewF32[vertexOffset + 16] = ty0; vertexViewF32[vertexOffset + 17] = uvs.x0; vertexViewF32[vertexOffset + 18] = uvs.y0; vertexViewU32[vertexOffset + 19] = vTintTL; vertexViewF32[vertexOffset + 20] = tx2; vertexViewF32[vertexOffset + 21] = ty2; vertexViewF32[vertexOffset + 22] = uvs.x2; vertexViewF32[vertexOffset + 23] = uvs.y2; vertexViewU32[vertexOffset + 24] = vTintBR; vertexViewF32[vertexOffset + 25] = tx3; vertexViewF32[vertexOffset + 26] = ty3; vertexViewF32[vertexOffset + 27] = uvs.x3; vertexViewF32[vertexOffset + 28] = uvs.y3; vertexViewU32[vertexOffset + 29] = vTintTR; this.vertexCount += 6; }, /** * Batches Mesh game object * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchMesh * @since 3.0.0 * * @param {Phaser.GameObjects.Mesh} mesh - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ batchMesh: function (mesh, camera, parentTransformMatrix) { var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } var vertices = mesh.vertices; var length = vertices.length; var vertexCount = (length / 2)|0; this.renderer.setPipeline(this); if (this.vertexCount + vertexCount > this.vertexCapacity) { this.flush(); } var roundPixels = this.renderer.config.roundPixels; var getTint = Utils.getTintAppendFloatAlpha; var uvs = mesh.uv; var colors = mesh.colors; var alphas = mesh.alphas; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var cameraMatrix = camera.matrix.matrix; var frame = mesh.frame; var texture = mesh.texture.source[frame.sourceIndex].glTexture; var translateX = mesh.x; var translateY = mesh.y; var scaleX = mesh.scaleX; var scaleY = mesh.scaleY; var rotation = mesh.rotation; var sr = Math.sin(rotation); var cr = Math.cos(rotation); var sra = cr * scaleX; var srb = sr * scaleX; var src = -sr * scaleY; var srd = cr * scaleY; var sre = translateX; var srf = translateY; var cma = cameraMatrix[0]; var cmb = cameraMatrix[1]; var cmc = cameraMatrix[2]; var cmd = cameraMatrix[3]; var cme = cameraMatrix[4]; var cmf = cameraMatrix[5]; var vertexOffset = 0; var mva, mvb, mvc, mvd, mve, mvf; if (parentMatrix) { var pma = parentMatrix[0]; var pmb = parentMatrix[1]; var pmc = parentMatrix[2]; var pmd = parentMatrix[3]; var pme = parentMatrix[4]; var pmf = parentMatrix[5]; var cse = -camera.scrollX * mesh.scrollFactorX; var csf = -camera.scrollY * mesh.scrollFactorY; var pse = cse * cma + csf * cmc + cme; var psf = cse * cmb + csf * cmd + cmf; var pca = pma * cma + pmb * cmc; var pcb = pma * cmb + pmb * cmd; var pcc = pmc * cma + pmd * cmc; var pcd = pmc * cmb + pmd * cmd; var pce = pme * cma + pmf * cmc + pse; var pcf = pme * cmb + pmf * cmd + psf; mva = sra * pca + srb * pcc; mvb = sra * pcb + srb * pcd; mvc = src * pca + srd * pcc; mvd = src * pcb + srd * pcd; mve = sre * pca + srf * pcc + pce; mvf = sre * pcb + srf * pcd + pcf; } else { sre -= camera.scrollX * mesh.scrollFactorX; srf -= camera.scrollY * mesh.scrollFactorY; mva = sra * cma + srb * cmc; mvb = sra * cmb + srb * cmd; mvc = src * cma + srd * cmc; mvd = src * cmb + srd * cmd; mve = sre * cma + srf * cmc + cme; mvf = sre * cmb + srf * cmd + cmf; } this.setTexture2D(texture, 0); vertexOffset = this.vertexCount * this.vertexComponentCount; for (var index = 0, index0 = 0; index < length; index += 2) { var x = vertices[index + 0]; var y = vertices[index + 1]; var tx = x * mva + y * mvc + mve; var ty = x * mvb + y * mvd + mvf; if (roundPixels) { tx |= 0; ty |= 0; } vertexViewF32[vertexOffset + 0] = tx; vertexViewF32[vertexOffset + 1] = ty; vertexViewF32[vertexOffset + 2] = uvs[index + 0]; vertexViewF32[vertexOffset + 3] = uvs[index + 1]; vertexViewU32[vertexOffset + 4] = getTint(colors[index0], alphas[index0]); vertexOffset += 5; index0 += 1; } this.vertexCount += vertexCount; }, /** * Batches BitmapText game object * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchBitmapText * @since 3.0.0 * * @param {Phaser.GameObjects.BitmapText} bitmapText - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ batchBitmapText: function (bitmapText, camera, parentTransformMatrix) { var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } this.renderer.setPipeline(this); if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } var roundPixels = this.renderer.config.roundPixels; var text = bitmapText.text; var textLength = text.length; var getTint = Utils.getTintAppendFloatAlpha; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var cameraMatrix = camera.matrix.matrix; var cameraWidth = camera.width + 50; var cameraHeight = camera.height + 50; var cameraX = -50; var cameraY = -50; var frame = bitmapText.frame; var textureSource = bitmapText.texture.source[frame.sourceIndex]; var cameraScrollX = camera.scrollX * bitmapText.scrollFactorX; var cameraScrollY = camera.scrollY * bitmapText.scrollFactorY; var fontData = bitmapText.fontData; var lineHeight = fontData.lineHeight; var scale = (bitmapText.fontSize / fontData.size); var chars = fontData.chars; var alpha = bitmapText.alpha; var vTintTL = getTint(bitmapText._tintTL, alpha); var vTintTR = getTint(bitmapText._tintTR, alpha); var vTintBL = getTint(bitmapText._tintBL, alpha); var vTintBR = getTint(bitmapText._tintBR, alpha); var srcX = bitmapText.x; var srcY = bitmapText.y; var textureX = frame.cutX; var textureY = frame.cutY; var textureWidth = textureSource.width; var textureHeight = textureSource.height; var texture = textureSource.glTexture; var xAdvance = 0; var yAdvance = 0; var indexCount = 0; var charCode = 0; var glyph = null; var glyphX = 0; var glyphY = 0; var glyphW = 0; var glyphH = 0; var x = 0; var y = 0; var xw = 0; var yh = 0; var tx0; var ty0; var tx1; var ty1; var tx2; var ty2; var tx3; var ty3; var umin = 0; var umax = 0; var vmin = 0; var vmax = 0; var lastGlyph = null; var lastCharCode = 0; var translateX = srcX + frame.x; var translateY = srcY + frame.y; var rotation = bitmapText.rotation; var scaleX = bitmapText.scaleX; var scaleY = bitmapText.scaleY; var letterSpacing = bitmapText.letterSpacing; var sr = Math.sin(rotation); var cr = Math.cos(rotation); var sra = cr * scaleX; var srb = sr * scaleX; var src = -sr * scaleY; var srd = cr * scaleY; var sre = translateX; var srf = translateY; var cma = cameraMatrix[0]; var cmb = cameraMatrix[1]; var cmc = cameraMatrix[2]; var cmd = cameraMatrix[3]; var cme = cameraMatrix[4]; var cmf = cameraMatrix[5]; var vertexOffset = 0; var mva, mvb, mvc, mvd, mve, mvf; if (parentMatrix) { var pma = parentMatrix[0]; var pmb = parentMatrix[1]; var pmc = parentMatrix[2]; var pmd = parentMatrix[3]; var pme = parentMatrix[4]; var pmf = parentMatrix[5]; var cse = -cameraScrollX; var csf = -cameraScrollY; var pse = cse * cma + csf * cmc + cme; var psf = cse * cmb + csf * cmd + cmf; var pca = pma * cma + pmb * cmc; var pcb = pma * cmb + pmb * cmd; var pcc = pmc * cma + pmd * cmc; var pcd = pmc * cmb + pmd * cmd; var pce = pme * cma + pmf * cmc + pse; var pcf = pme * cmb + pmf * cmd + psf; mva = sra * pca + srb * pcc; mvb = sra * pcb + srb * pcd; mvc = src * pca + srd * pcc; mvd = src * pcb + srd * pcd; mve = sre * pca + srf * pcc + pce; mvf = sre * pcb + srf * pcd + pcf; } else { sre -= cameraScrollX; srf -= cameraScrollY; mva = sra * cma + srb * cmc; mvb = sra * cmb + srb * cmd; mvc = src * cma + srd * cmc; mvd = src * cmb + srd * cmd; mve = sre * cma + srf * cmc + cme; mvf = sre * cmb + srf * cmd + cmf; } this.setTexture2D(texture, 0); for (var index = 0; index < textLength; ++index) { charCode = text.charCodeAt(index); if (charCode === 10) { xAdvance = 0; indexCount = 0; yAdvance += lineHeight; lastGlyph = null; continue; } glyph = chars[charCode]; if (!glyph) { continue; } glyphX = textureX + glyph.x; glyphY = textureY + glyph.y; glyphW = glyph.width; glyphH = glyph.height; x = (indexCount + glyph.xOffset + xAdvance) * scale; y = (glyph.yOffset + yAdvance) * scale; if (lastGlyph !== null) { var kerningOffset = glyph.kerning[lastCharCode]; x += (kerningOffset !== undefined) ? kerningOffset : 0; } xAdvance += glyph.xAdvance + letterSpacing; indexCount += 1; lastGlyph = glyph; lastCharCode = charCode; // Nothing to render or a space? Then skip to the next glyph if (glyphW === 0 || glyphH === 0 || charCode === 32) { continue; } x -= bitmapText.displayOriginX; y -= bitmapText.displayOriginY; xw = x + glyphW * scale; yh = y + glyphH * scale; tx0 = x * mva + y * mvc + mve; ty0 = x * mvb + y * mvd + mvf; tx1 = x * mva + yh * mvc + mve; ty1 = x * mvb + yh * mvd + mvf; tx2 = xw * mva + yh * mvc + mve; ty2 = xw * mvb + yh * mvd + mvf; tx3 = xw * mva + y * mvc + mve; ty3 = xw * mvb + y * mvd + mvf; umin = glyphX / textureWidth; umax = (glyphX + glyphW) / textureWidth; vmin = glyphY / textureHeight; vmax = (glyphY + glyphH) / textureHeight; if ((tx0 < cameraX || tx0 > cameraWidth || ty0 < cameraY || ty0 > cameraHeight) && (tx1 < cameraX || tx1 > cameraWidth || ty1 < cameraY || ty1 > cameraHeight) && (tx2 < cameraX || tx2 > cameraWidth || ty2 < cameraY || ty2 > cameraHeight) && (tx3 < cameraX || tx3 > cameraWidth || ty3 < cameraY || ty3 > cameraHeight)) { continue; } if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } vertexOffset = this.vertexCount * this.vertexComponentCount; if (roundPixels) { tx0 |= 0; ty0 |= 0; tx1 |= 0; ty1 |= 0; tx2 |= 0; ty2 |= 0; tx3 |= 0; ty3 |= 0; } vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewF32[vertexOffset + 2] = umin; vertexViewF32[vertexOffset + 3] = vmin; vertexViewU32[vertexOffset + 4] = vTintTL; vertexViewF32[vertexOffset + 5] = tx1; vertexViewF32[vertexOffset + 6] = ty1; vertexViewF32[vertexOffset + 7] = umin; vertexViewF32[vertexOffset + 8] = vmax; vertexViewU32[vertexOffset + 9] = vTintBL; vertexViewF32[vertexOffset + 10] = tx2; vertexViewF32[vertexOffset + 11] = ty2; vertexViewF32[vertexOffset + 12] = umax; vertexViewF32[vertexOffset + 13] = vmax; vertexViewU32[vertexOffset + 14] = vTintBR; vertexViewF32[vertexOffset + 15] = tx0; vertexViewF32[vertexOffset + 16] = ty0; vertexViewF32[vertexOffset + 17] = umin; vertexViewF32[vertexOffset + 18] = vmin; vertexViewU32[vertexOffset + 19] = vTintTL; vertexViewF32[vertexOffset + 20] = tx2; vertexViewF32[vertexOffset + 21] = ty2; vertexViewF32[vertexOffset + 22] = umax; vertexViewF32[vertexOffset + 23] = vmax; vertexViewU32[vertexOffset + 24] = vTintBR; vertexViewF32[vertexOffset + 25] = tx3; vertexViewF32[vertexOffset + 26] = ty3; vertexViewF32[vertexOffset + 27] = umax; vertexViewF32[vertexOffset + 28] = vmin; vertexViewU32[vertexOffset + 29] = vTintTR; this.vertexCount += 6; } }, /** * Batches DynamicBitmapText game object * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchDynamicBitmapText * @since 3.0.0 * * @param {Phaser.GameObjects.DynamicBitmapText} bitmapText - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ batchDynamicBitmapText: function (bitmapText, camera, parentTransformMatrix) { var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } this.renderer.setPipeline(this); if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } var roundPixels = this.renderer.config.roundPixels; var displayCallback = bitmapText.displayCallback; var text = bitmapText.text; var textLength = text.length; var getTint = Utils.getTintAppendFloatAlpha; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var renderer = this.renderer; var cameraMatrix = camera.matrix.matrix; var frame = bitmapText.frame; var textureSource = bitmapText.texture.source[frame.sourceIndex]; var cameraScrollX = camera.scrollX * bitmapText.scrollFactorX; var cameraScrollY = camera.scrollY * bitmapText.scrollFactorY; var scrollX = bitmapText.scrollX; var scrollY = bitmapText.scrollY; var fontData = bitmapText.fontData; var lineHeight = fontData.lineHeight; var scale = (bitmapText.fontSize / fontData.size); var chars = fontData.chars; var alpha = bitmapText.alpha; var vTintTL = getTint(bitmapText._tintTL, alpha); var vTintTR = getTint(bitmapText._tintTR, alpha); var vTintBL = getTint(bitmapText._tintBL, alpha); var vTintBR = getTint(bitmapText._tintBR, alpha); var srcX = bitmapText.x; var srcY = bitmapText.y; var textureX = frame.cutX; var textureY = frame.cutY; var textureWidth = textureSource.width; var textureHeight = textureSource.height; var texture = textureSource.glTexture; var xAdvance = 0; var yAdvance = 0; var indexCount = 0; var charCode = 0; var glyph = null; var glyphX = 0; var glyphY = 0; var glyphW = 0; var glyphH = 0; var x = 0; var y = 0; var xw = 0; var tx0; var ty0; var tx1; var ty1; var tx2; var ty2; var tx3; var ty3; var yh = 0; var umin = 0; var umax = 0; var vmin = 0; var vmax = 0; var lastGlyph = null; var lastCharCode = 0; var translateX = srcX + frame.x; var translateY = srcY + frame.y; var rotation = bitmapText.rotation; var scaleX = bitmapText.scaleX; var scaleY = bitmapText.scaleY; var letterSpacing = bitmapText.letterSpacing; var sr = Math.sin(rotation); var cr = Math.cos(rotation); var sra = cr * scaleX; var srb = sr * scaleX; var src = -sr * scaleY; var srd = cr * scaleY; var sre = translateX; var srf = translateY; var cma = cameraMatrix[0]; var cmb = cameraMatrix[1]; var cmc = cameraMatrix[2]; var cmd = cameraMatrix[3]; var cme = cameraMatrix[4]; var cmf = cameraMatrix[5]; var crop = (bitmapText.cropWidth > 0 || bitmapText.cropHeight > 0); var uta, utb, utc, utd, ute, utf; var vertexOffset = 0; var mva, mvb, mvc, mvd, mve, mvf; if (parentMatrix) { var pma = parentMatrix[0]; var pmb = parentMatrix[1]; var pmc = parentMatrix[2]; var pmd = parentMatrix[3]; var pme = parentMatrix[4]; var pmf = parentMatrix[5]; var cse = -cameraScrollX; var csf = -cameraScrollY; var pse = cse * cma + csf * cmc + cme; var psf = cse * cmb + csf * cmd + cmf; var pca = pma * cma + pmb * cmc; var pcb = pma * cmb + pmb * cmd; var pcc = pmc * cma + pmd * cmc; var pcd = pmc * cmb + pmd * cmd; var pce = pme * cma + pmf * cmc + pse; var pcf = pme * cmb + pmf * cmd + psf; mva = sra * pca + srb * pcc; mvb = sra * pcb + srb * pcd; mvc = src * pca + srd * pcc; mvd = src * pcb + srd * pcd; mve = sre * pca + srf * pcc + pce; mvf = sre * pcb + srf * pcd + pcf; } else { sre -= cameraScrollX; srf -= cameraScrollY; mva = sra * cma + srb * cmc; mvb = sra * cmb + srb * cmd; mvc = src * cma + srd * cmc; mvd = src * cmb + srd * cmd; mve = sre * cma + srf * cmc + cme; mvf = sre * cmb + srf * cmd + cmf; } this.setTexture2D(texture, 0); if (crop) { renderer.pushScissor( bitmapText.x, bitmapText.y, bitmapText.cropWidth * bitmapText.scaleX, bitmapText.cropHeight * bitmapText.scaleY ); } for (var index = 0; index < textLength; ++index) { scale = (bitmapText.fontSize / bitmapText.fontData.size); rotation = 0; charCode = text.charCodeAt(index); if (charCode === 10) { xAdvance = 0; indexCount = 0; yAdvance += lineHeight; lastGlyph = null; continue; } glyph = chars[charCode]; if (!glyph) { continue; } glyphX = textureX + glyph.x; glyphY = textureY + glyph.y; glyphW = glyph.width; glyphH = glyph.height; x = (indexCount + glyph.xOffset + xAdvance) - scrollX; y = (glyph.yOffset + yAdvance) - scrollY; if (lastGlyph !== null) { var kerningOffset = glyph.kerning[lastCharCode]; x += (kerningOffset !== undefined) ? kerningOffset : 0; } xAdvance += glyph.xAdvance + letterSpacing; indexCount += 1; lastGlyph = glyph; lastCharCode = charCode; // Nothing to render or a space? Then skip to the next glyph if (glyphW === 0 || glyphH === 0 || charCode === 32) { continue; } if (displayCallback) { var output = displayCallback({ color: 0, tint: { topLeft: vTintTL, topRight: vTintTR, bottomLeft: vTintBL, bottomRight: vTintBR }, index: index, charCode: charCode, x: x, y: y, scale: scale, rotation: 0, data: glyph.data }); x = output.x; y = output.y; scale = output.scale; rotation = output.rotation; if (output.color) { vTintTL = output.color; vTintTR = output.color; vTintBL = output.color; vTintBR = output.color; } else { vTintTL = output.tint.topLeft; vTintTR = output.tint.topRight; vTintBL = output.tint.bottomLeft; vTintBR = output.tint.bottomRight; } vTintTL = getTint(vTintTL, alpha); vTintTR = getTint(vTintTR, alpha); vTintBL = getTint(vTintBL, alpha); vTintBR = getTint(vTintBR, alpha); } x -= bitmapText.displayOriginX; y -= bitmapText.displayOriginY; x *= scale; y *= scale; sr = Math.sin(rotation); cr = Math.cos(rotation); uta = cr * scale; utb = sr * scale; utc = -sr * scale; utd = cr * scale; ute = x; utf = y; sra = uta * mva + utb * mvc; srb = uta * mvb + utb * mvd; src = utc * mva + utd * mvc; srd = utc * mvb + utd * mvd; sre = ute * mva + utf * mvc + mve; srf = ute * mvb + utf * mvd + mvf; xw = glyphW; yh = glyphH; tx0 = sre; ty0 = srf; tx1 = yh * src + sre; ty1 = yh * srd + srf; tx2 = xw * sra + yh * src + sre; ty2 = xw * srb + yh * srd + srf; tx3 = xw * sra + sre; ty3 = xw * srb + srf; umin = glyphX / textureWidth; umax = (glyphX + glyphW) / textureWidth; vmin = glyphY / textureHeight; vmax = (glyphY + glyphH) / textureHeight; if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } vertexOffset = this.vertexCount * this.vertexComponentCount; if (roundPixels) { tx0 |= 0; ty0 |= 0; tx1 |= 0; ty1 |= 0; tx2 |= 0; ty2 |= 0; tx3 |= 0; ty3 |= 0; } vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewF32[vertexOffset + 2] = umin; vertexViewF32[vertexOffset + 3] = vmin; vertexViewU32[vertexOffset + 4] = vTintTL; vertexViewF32[vertexOffset + 5] = tx1; vertexViewF32[vertexOffset + 6] = ty1; vertexViewF32[vertexOffset + 7] = umin; vertexViewF32[vertexOffset + 8] = vmax; vertexViewU32[vertexOffset + 9] = vTintBL; vertexViewF32[vertexOffset + 10] = tx2; vertexViewF32[vertexOffset + 11] = ty2; vertexViewF32[vertexOffset + 12] = umax; vertexViewF32[vertexOffset + 13] = vmax; vertexViewU32[vertexOffset + 14] = vTintBR; vertexViewF32[vertexOffset + 15] = tx0; vertexViewF32[vertexOffset + 16] = ty0; vertexViewF32[vertexOffset + 17] = umin; vertexViewF32[vertexOffset + 18] = vmin; vertexViewU32[vertexOffset + 19] = vTintTL; vertexViewF32[vertexOffset + 20] = tx2; vertexViewF32[vertexOffset + 21] = ty2; vertexViewF32[vertexOffset + 22] = umax; vertexViewF32[vertexOffset + 23] = vmax; vertexViewU32[vertexOffset + 24] = vTintBR; vertexViewF32[vertexOffset + 25] = tx3; vertexViewF32[vertexOffset + 26] = ty3; vertexViewF32[vertexOffset + 27] = umax; vertexViewF32[vertexOffset + 28] = vmin; vertexViewU32[vertexOffset + 29] = vTintTR; this.vertexCount += 6; } if (crop) { renderer.popScissor(); } }, /** * Batches Text game object * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchText * @since 3.0.0 * * @param {Phaser.GameObjects.Text} text - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ batchText: function (text, camera, parentTransformMatrix) { var getTint = Utils.getTintAppendFloatAlpha; this.batchTexture( text, text.canvasTexture, text.canvasTexture.width, text.canvasTexture.height, text.x, text.y, text.canvasTexture.width, text.canvasTexture.height, text.scaleX, text.scaleY, text.rotation, text.flipX, text.flipY, text.scrollFactorX, text.scrollFactorY, text.displayOriginX, text.displayOriginY, 0, 0, text.canvasTexture.width, text.canvasTexture.height, getTint(text._tintTL, text._alphaTL), getTint(text._tintTR, text._alphaTR), getTint(text._tintBL, text._alphaBL), getTint(text._tintBR, text._alphaBR), 0, 0, camera, parentTransformMatrix ); }, /** * Batches DynamicTilemapLayer game object * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchDynamicTilemapLayer * @since 3.0.0 * * @param {Phaser.Tilemaps.DynamicTilemapLayer} tilemapLayer - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ batchDynamicTilemapLayer: function (tilemapLayer, camera, parentTransformMatrix) { var renderTiles = tilemapLayer.culledTiles; var length = renderTiles.length; var texture = tilemapLayer.tileset.image.get().source.glTexture; var tileset = tilemapLayer.tileset; var scrollFactorX = tilemapLayer.scrollFactorX; var scrollFactorY = tilemapLayer.scrollFactorY; var alpha = tilemapLayer.alpha; var x = tilemapLayer.x; var y = tilemapLayer.y; var sx = tilemapLayer.scaleX; var sy = tilemapLayer.scaleY; var getTint = Utils.getTintAppendFloatAlpha; for (var index = 0; index < length; ++index) { var tile = renderTiles[index]; var tileTexCoords = tileset.getTileTextureCoordinates(tile.index); if (tileTexCoords === null) { continue; } var frameWidth = tile.width; var frameHeight = tile.height; var frameX = tileTexCoords.x; var frameY = tileTexCoords.y; var tint = getTint(tile.tint, alpha * tile.alpha); this.batchTexture( tilemapLayer, texture, texture.width, texture.height, (tile.width / 2) + x + tile.pixelX * sx, (tile.height / 2) + y + tile.pixelY * sy, tile.width * sx, tile.height * sy, 1, 1, tile.rotation, tile.flipX, tile.flipY, scrollFactorX, scrollFactorY, (tile.width / 2), (tile.height / 2), frameX, frameY, frameWidth, frameHeight, tint, tint, tint, tint, 0, 0, camera, parentTransformMatrix ); } }, /** * Batches TileSprite game object * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchTileSprite * @since 3.0.0 * * @param {Phaser.GameObjects.TileSprite} tileSprite - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ batchTileSprite: function (tileSprite, camera, parentTransformMatrix) { var getTint = Utils.getTintAppendFloatAlpha; this.batchTexture( tileSprite, tileSprite.tileTexture, tileSprite.frame.width, tileSprite.frame.height, tileSprite.x, tileSprite.y, tileSprite.width, tileSprite.height, tileSprite.scaleX, tileSprite.scaleY, tileSprite.rotation, tileSprite.flipX, tileSprite.flipY, tileSprite.scrollFactorX, tileSprite.scrollFactorY, tileSprite.originX * tileSprite.width, tileSprite.originY * tileSprite.height, 0, 0, tileSprite.width, tileSprite.height, getTint(tileSprite._tintTL, tileSprite._alphaTL), getTint(tileSprite._tintTR, tileSprite._alphaTR), getTint(tileSprite._tintBL, tileSprite._alphaBL), getTint(tileSprite._tintBR, tileSprite._alphaBR), (tileSprite.tilePositionX % tileSprite.frame.width) / tileSprite.frame.width, (tileSprite.tilePositionY % tileSprite.frame.height) / tileSprite.frame.height, camera, parentTransformMatrix ); }, /** * Generic function for batching a textured quad * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchTexture * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - Source GameObject * @param {WebGLTexture} texture - Raw WebGLTexture associated with the quad * @param {integer} textureWidth - Real texture width * @param {integer} textureHeight - Real texture height * @param {float} srcX - X coordinate of the quad * @param {float} srcY - Y coordinate of the quad * @param {float} srcWidth - Width of the quad * @param {float} srcHeight - Height of the quad * @param {float} scaleX - X component of scale * @param {float} scaleY - Y component of scale * @param {float} rotation - Rotation of the quad * @param {boolean} flipX - Indicates if the quad is horizontally flipped * @param {boolean} flipY - Indicates if the quad is vertically flipped * @param {float} scrollFactorX - By which factor is the quad affected by the camera horizontal scroll * @param {float} scrollFactorY - By which factor is the quad effected by the camera vertical scroll * @param {float} displayOriginX - Horizontal origin in pixels * @param {float} displayOriginY - Vertical origin in pixels * @param {float} frameX - X coordinate of the texture frame * @param {float} frameY - Y coordinate of the texture frame * @param {float} frameWidth - Width of the texture frame * @param {float} frameHeight - Height of the texture frame * @param {integer} tintTL - Tint for top left * @param {integer} tintTR - Tint for top right * @param {integer} tintBL - Tint for bottom left * @param {integer} tintBR - Tint for bottom right * @param {float} uOffset - Horizontal offset on texture coordinate * @param {float} vOffset - Vertical offset on texture coordinate * @param {Phaser.Cameras.Scene2D.Camera} camera - Current used camera * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - Parent container */ batchTexture: function ( gameObject, texture, textureWidth, textureHeight, srcX, srcY, srcWidth, srcHeight, scaleX, scaleY, rotation, flipX, flipY, scrollFactorX, scrollFactorY, displayOriginX, displayOriginY, frameX, frameY, frameWidth, frameHeight, tintTL, tintTR, tintBL, tintBR, uOffset, vOffset, camera, parentTransformMatrix) { var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } this.renderer.setPipeline(this); if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } flipY = flipY ^ (texture.isRenderTexture ? 1 : 0); var roundPixels = this.renderer.config.roundPixels; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var cameraMatrix = camera.matrix.matrix; var width = srcWidth * (flipX ? -1.0 : 1.0); var height = srcHeight * (flipY ? -1.0 : 1.0); var x = -displayOriginX + ((srcWidth) * (flipX ? 1.0 : 0.0)); var y = -displayOriginY + ((srcHeight) * (flipY ? 1.0 : 0.0)); var xw = x + width; var yh = y + height; var translateX = srcX; var translateY = srcY; var sr = Math.sin(rotation); var cr = Math.cos(rotation); var sra = cr * scaleX; var srb = sr * scaleX; var src = -sr * scaleY; var srd = cr * scaleY; var sre = translateX; var srf = translateY; var cma = cameraMatrix[0]; var cmb = cameraMatrix[1]; var cmc = cameraMatrix[2]; var cmd = cameraMatrix[3]; var cme = cameraMatrix[4]; var cmf = cameraMatrix[5]; var mva, mvb, mvc, mvd, mve, mvf; if (parentMatrix) { var pma = parentMatrix[0]; var pmb = parentMatrix[1]; var pmc = parentMatrix[2]; var pmd = parentMatrix[3]; var pme = parentMatrix[4]; var pmf = parentMatrix[5]; var cse = -camera.scrollX * scrollFactorX; var csf = -camera.scrollY * scrollFactorY; var pse = cse * cma + csf * cmc + cme; var psf = cse * cmb + csf * cmd + cmf; var pca = pma * cma + pmb * cmc; var pcb = pma * cmb + pmb * cmd; var pcc = pmc * cma + pmd * cmc; var pcd = pmc * cmb + pmd * cmd; var pce = pme * cma + pmf * cmc + pse; var pcf = pme * cmb + pmf * cmd + psf; mva = sra * pca + srb * pcc; mvb = sra * pcb + srb * pcd; mvc = src * pca + srd * pcc; mvd = src * pcb + srd * pcd; mve = sre * pca + srf * pcc + pce; mvf = sre * pcb + srf * pcd + pcf; } else { sre -= camera.scrollX * scrollFactorX; srf -= camera.scrollY * scrollFactorY; mva = sra * cma + srb * cmc; mvb = sra * cmb + srb * cmd; mvc = src * cma + srd * cmc; mvd = src * cmb + srd * cmd; mve = sre * cma + srf * cmc + cme; mvf = sre * cmb + srf * cmd + cmf; } var tx0 = x * mva + y * mvc + mve; var ty0 = x * mvb + y * mvd + mvf; var tx1 = x * mva + yh * mvc + mve; var ty1 = x * mvb + yh * mvd + mvf; var tx2 = xw * mva + yh * mvc + mve; var ty2 = xw * mvb + yh * mvd + mvf; var tx3 = xw * mva + y * mvc + mve; var ty3 = xw * mvb + y * mvd + mvf; var vertexOffset = 0; var u0 = (frameX / textureWidth) + uOffset; var v0 = (frameY / textureHeight) + vOffset; var u1 = (frameX + frameWidth) / textureWidth + uOffset; var v1 = (frameY + frameHeight) / textureHeight + vOffset; this.setTexture2D(texture, 0); vertexOffset = this.vertexCount * this.vertexComponentCount; if (roundPixels) { tx0 |= 0; ty0 |= 0; tx1 |= 0; ty1 |= 0; tx2 |= 0; ty2 |= 0; tx3 |= 0; ty3 |= 0; } vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewF32[vertexOffset + 2] = u0; vertexViewF32[vertexOffset + 3] = v0; vertexViewU32[vertexOffset + 4] = tintTL; vertexViewF32[vertexOffset + 5] = tx1; vertexViewF32[vertexOffset + 6] = ty1; vertexViewF32[vertexOffset + 7] = u0; vertexViewF32[vertexOffset + 8] = v1; vertexViewU32[vertexOffset + 9] = tintTR; vertexViewF32[vertexOffset + 10] = tx2; vertexViewF32[vertexOffset + 11] = ty2; vertexViewF32[vertexOffset + 12] = u1; vertexViewF32[vertexOffset + 13] = v1; vertexViewU32[vertexOffset + 14] = tintBL; vertexViewF32[vertexOffset + 15] = tx0; vertexViewF32[vertexOffset + 16] = ty0; vertexViewF32[vertexOffset + 17] = u0; vertexViewF32[vertexOffset + 18] = v0; vertexViewU32[vertexOffset + 19] = tintTL; vertexViewF32[vertexOffset + 20] = tx2; vertexViewF32[vertexOffset + 21] = ty2; vertexViewF32[vertexOffset + 22] = u1; vertexViewF32[vertexOffset + 23] = v1; vertexViewU32[vertexOffset + 24] = tintBL; vertexViewF32[vertexOffset + 25] = tx3; vertexViewF32[vertexOffset + 26] = ty3; vertexViewF32[vertexOffset + 27] = u1; vertexViewF32[vertexOffset + 28] = v0; vertexViewU32[vertexOffset + 29] = tintBR; this.vertexCount += 6; }, /** * Immediately draws a texture with no batching. * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawTexture * @since 3.2.0 * * @param {WebGLTexture} texture [description] * @param {number} srcX - [description] * @param {number} srcY - [description] * @param {number} tint - [description] * @param {number} alpha - [description] * @param {number} frameX - [description] * @param {number} frameY - [description] * @param {number} frameWidth - [description] * @param {number} frameHeight - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} transformMatrix - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * * @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} This Pipeline. */ drawTexture: function ( texture, srcX, srcY, tint, alpha, frameX, frameY, frameWidth, frameHeight, transformMatrix, parentTransformMatrix ) { var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } this.renderer.setPipeline(this); if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } var roundPixels = this.renderer.config.roundPixels; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var width = frameWidth; var height = frameHeight; var x = srcX; var y = srcY; var xw = x + width; var yh = y + height; var mva = transformMatrix[0]; var mvb = transformMatrix[1]; var mvc = transformMatrix[2]; var mvd = transformMatrix[3]; var mve = transformMatrix[4]; var mvf = transformMatrix[5]; if (parentMatrix) { var pma = parentMatrix[0]; var pmb = parentMatrix[1]; var pmc = parentMatrix[2]; var pmd = parentMatrix[3]; var pme = parentMatrix[4]; var pmf = parentMatrix[5]; var pca = mva * pma + mvb * pmc; var pcb = mva * pmb + mvb * pmd; var pcc = mvc * pma + mvd * pmc; var pcd = mvc * pmb + mvd * pmd; var pce = mve * pma + mvf * pmc + pme; var pcf = mve * pmb + mvf * pmd + pmf; mva = pca; mvb = pcb; mvc = pcc; mvd = pcd; mve = pce; mvf = pcf; } var tx0 = x * mva + y * mvc + mve; var ty0 = x * mvb + y * mvd + mvf; var tx1 = x * mva + yh * mvc + mve; var ty1 = x * mvb + yh * mvd + mvf; var tx2 = xw * mva + yh * mvc + mve; var ty2 = xw * mvb + yh * mvd + mvf; var tx3 = xw * mva + y * mvc + mve; var ty3 = xw * mvb + y * mvd + mvf; var vertexOffset = 0; var textureWidth = texture.width; var textureHeight = texture.height; var u0 = (frameX / textureWidth); var v0 = (frameY / textureHeight); var u1 = (frameX + frameWidth) / textureWidth; var v1 = (frameY + frameHeight) / textureHeight; tint = Utils.getTintAppendFloatAlpha(tint, alpha); this.setTexture2D(texture, 0); vertexOffset = this.vertexCount * this.vertexComponentCount; if (roundPixels) { tx0 |= 0; ty0 |= 0; tx1 |= 0; ty1 |= 0; tx2 |= 0; ty2 |= 0; tx3 |= 0; ty3 |= 0; } vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewF32[vertexOffset + 2] = u0; vertexViewF32[vertexOffset + 3] = v0; vertexViewU32[vertexOffset + 4] = tint; vertexViewF32[vertexOffset + 5] = tx1; vertexViewF32[vertexOffset + 6] = ty1; vertexViewF32[vertexOffset + 7] = u0; vertexViewF32[vertexOffset + 8] = v1; vertexViewU32[vertexOffset + 9] = tint; vertexViewF32[vertexOffset + 10] = tx2; vertexViewF32[vertexOffset + 11] = ty2; vertexViewF32[vertexOffset + 12] = u1; vertexViewF32[vertexOffset + 13] = v1; vertexViewU32[vertexOffset + 14] = tint; vertexViewF32[vertexOffset + 15] = tx0; vertexViewF32[vertexOffset + 16] = ty0; vertexViewF32[vertexOffset + 17] = u0; vertexViewF32[vertexOffset + 18] = v0; vertexViewU32[vertexOffset + 19] = tint; vertexViewF32[vertexOffset + 20] = tx2; vertexViewF32[vertexOffset + 21] = ty2; vertexViewF32[vertexOffset + 22] = u1; vertexViewF32[vertexOffset + 23] = v1; vertexViewU32[vertexOffset + 24] = tint; vertexViewF32[vertexOffset + 25] = tx3; vertexViewF32[vertexOffset + 26] = ty3; vertexViewF32[vertexOffset + 27] = u1; vertexViewF32[vertexOffset + 28] = v0; vertexViewU32[vertexOffset + 29] = tint; this.vertexCount += 6; // Force an immediate draw this.flush(); }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchGraphics * @since 3.0.0 * * @param {Phaser.GameObjects.Graphics} graphics - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ batchGraphics: function () { // Stub } }); module.exports = TextureTintPipeline; /***/ }), /* 130 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Adds the given element to the DOM. If a parent is provided the element is added as a child of the parent, providing it was able to access it. * If no parent was given or falls back to using `document.body`. * * @function Phaser.DOM.AddToDOM * @since 3.0.0 * * @param {HTMLElement} element - The element to be added to the DOM. Usually a Canvas object. * @param {(string|HTMLElement)} [parent] - The parent in which to add the element. Can be a string which is passed to `getElementById` or an actual DOM object. * @param {boolean} [overflowHidden=true] - Whether or not to hide overflowing content inside the parent. * * @return {HTMLElement} The element that was added to the DOM. */ var AddToDOM = function (element, parent, overflowHidden) { if (overflowHidden === undefined) { overflowHidden = true; } var target; if (parent) { if (typeof parent === 'string') { // Hopefully an element ID target = document.getElementById(parent); } else if (typeof parent === 'object' && parent.nodeType === 1) { // Quick test for a HTMLelement target = parent; } } else if (element.parentElement) { return element; } // Fallback, covers an invalid ID and a non HTMLelement object if (!target) { target = document.body; } if (overflowHidden && target.style) { target.style.overflow = 'hidden'; } target.appendChild(element); return element; }; module.exports = AddToDOM; /***/ }), /* 131 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // Browser specific prefix, so not going to change between contexts, only between browsers var prefix = ''; /** * @namespace Phaser.Display.Canvas.Smoothing * @since 3.0.0 */ var Smoothing = function () { /** * Gets the Smoothing Enabled vendor prefix being used on the given context, or null if not set. * * @function Phaser.Display.Canvas.Smoothing.getPrefix * @since 3.0.0 * * @param {(CanvasRenderingContext2D|WebGLRenderingContext)} context - [description] * * @return {string} [description] */ var getPrefix = function (context) { var vendors = [ 'i', 'webkitI', 'msI', 'mozI', 'oI' ]; for (var i = 0; i < vendors.length; i++) { var s = vendors[i] + 'mageSmoothingEnabled'; if (s in context) { return s; } } return null; }; /** * Sets the Image Smoothing property on the given context. Set to false to disable image smoothing. * By default browsers have image smoothing enabled, which isn't always what you visually want, especially * when using pixel art in a game. Note that this sets the property on the context itself, so that any image * drawn to the context will be affected. This sets the property across all current browsers but support is * patchy on earlier browsers, especially on mobile. * * @function Phaser.Display.Canvas.Smoothing.enable * @since 3.0.0 * * @param {(CanvasRenderingContext2D|WebGLRenderingContext)} context - [description] * * @return {(CanvasRenderingContext2D|WebGLRenderingContext)} [description] */ var enable = function (context) { if (prefix === '') { prefix = getPrefix(context); } if (prefix) { context[prefix] = true; } return context; }; /** * Sets the Image Smoothing property on the given context. Set to false to disable image smoothing. * By default browsers have image smoothing enabled, which isn't always what you visually want, especially * when using pixel art in a game. Note that this sets the property on the context itself, so that any image * drawn to the context will be affected. This sets the property across all current browsers but support is * patchy on earlier browsers, especially on mobile. * * @function Phaser.Display.Canvas.Smoothing.disable * @since 3.0.0 * * @param {(CanvasRenderingContext2D|WebGLRenderingContext)} context - [description] * * @return {(CanvasRenderingContext2D|WebGLRenderingContext)} [description] */ var disable = function (context) { if (prefix === '') { prefix = getPrefix(context); } if (prefix) { context[prefix] = false; } return context; }; /** * Returns `true` if the given context has image smoothing enabled, otherwise returns `false`. * Returns null if no smoothing prefix is available. * * @function Phaser.Display.Canvas.Smoothing.isEnabled * @since 3.0.0 * * @param {(CanvasRenderingContext2D|WebGLRenderingContext)} context - [description] * * @return {?boolean} [description] */ var isEnabled = function (context) { return (prefix !== null) ? context[prefix] : null; }; return { disable: disable, enable: enable, getPrefix: getPrefix, isEnabled: isEnabled }; }; module.exports = Smoothing(); /***/ }), /* 132 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var HexStringToColor = __webpack_require__(285); var IntegerToColor = __webpack_require__(283); var ObjectToColor = __webpack_require__(281); var RGBStringToColor = __webpack_require__(280); /** * Converts the given source color value into an instance of a Color class. * The value can be either a string, prefixed with `rgb` or a hex string, a number or an Object. * * @function Phaser.Display.Color.ValueToColor * @since 3.0.0 * * @param {(string|number|InputColorObject)} input - The source color value to convert. * * @return {Phaser.Display.Color} A Color object. */ var ValueToColor = function (input) { var t = typeof input; switch (t) { case 'string': if (input.substr(0, 3).toLowerCase() === 'rgb') { return RGBStringToColor(input); } else { return HexStringToColor(input); } case 'number': return IntegerToColor(input); case 'object': return ObjectToColor(input); } }; module.exports = ValueToColor; /***/ }), /* 133 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Takes the given string and pads it out, to the length required, using the character * specified. For example if you need a string to be 6 characters long, you can call: * * `pad('bob', 6, '-', 2)` * * This would return: `bob---` as it has padded it out to 6 characters, using the `-` on the right. * * You can also use it to pad numbers (they are always returned as strings): * * `pad(512, 6, '0', 1)` * * Would return: `000512` with the string padded to the left. * * If you don't specify a direction it'll pad to both sides: * * `pad('c64', 7, '*')` * * Would return: `**c64**` * * @function Phaser.Utils.String.Pad * @since 3.0.0 * * @param {string} str - The target string. `toString()` will be called on the string, which means you can also pass in common data types like numbers. * @param {integer} [len=0] - The number of characters to be added. * @param {string} [pad=" "] - The string to pad it out with (defaults to a space). * @param {integer} [dir=3] - The direction dir = 1 (left), 2 (right), 3 (both). * * @return {string} The padded string. */ var Pad = function (str, len, pad, dir) { if (len === undefined) { len = 0; } if (pad === undefined) { pad = ' '; } if (dir === undefined) { dir = 3; } str = str.toString(); var padlen = 0; if (len + 1 >= str.length) { switch (dir) { case 1: str = new Array(len + 1 - str.length).join(pad) + str; break; case 3: var right = Math.ceil((padlen = len - str.length) / 2); var left = padlen - right; str = new Array(left + 1).join(pad) + str + new Array(right + 1).join(pad); break; default: str = str + new Array(len + 1 - str.length).join(pad); break; } } return str; }; module.exports = Pad; /***/ }), /* 134 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); /** * Returns a uniformly distributed random point from anywhere within the given Ellipse. * * @function Phaser.Geom.Ellipse.Random * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to get a random point from. * @param {(Phaser.Geom.Point|object)} [out] - A Point or point-like object to set the random `x` and `y` values in. * * @return {(Phaser.Geom.Point|object)} A Point object with the random values set in the `x` and `y` properties. */ var Random = function (ellipse, out) { if (out === undefined) { out = new Point(); } var p = Math.random() * Math.PI * 2; var s = Math.sqrt(Math.random()); out.x = ellipse.x + ((s * Math.cos(p)) * ellipse.width / 2); out.y = ellipse.y + ((s * Math.sin(p)) * ellipse.height / 2); return out; }; module.exports = Random; /***/ }), /* 135 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Perimeter = __webpack_require__(97); var Point = __webpack_require__(5); /** * Position is a value between 0 and 1 where 0 = the top-left of the rectangle and 0.5 = the bottom right. * * @function Phaser.Geom.Rectangle.GetPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Rectangle} rectangle - [description] * @param {float} position - [description] * @param {(Phaser.Geom.Point|object)} [out] - [description] * * @return {Phaser.Geom.Point} [description] */ var GetPoint = function (rectangle, position, out) { if (out === undefined) { out = new Point(); } if (position <= 0 || position >= 1) { out.x = rectangle.x; out.y = rectangle.y; return out; } var p = Perimeter(rectangle) * position; if (position > 0.5) { p -= (rectangle.width + rectangle.height); if (p <= rectangle.width) { // Face 3 out.x = rectangle.right - p; out.y = rectangle.bottom; } else { // Face 4 out.x = rectangle.x; out.y = rectangle.bottom - (p - rectangle.width); } } else if (p <= rectangle.width) { // Face 1 out.x = rectangle.x + p; out.y = rectangle.y; } else { // Face 2 out.x = rectangle.right; out.y = rectangle.y + (p - rectangle.width); } return out; }; module.exports = GetPoint; /***/ }), /* 136 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); /** * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle. * * @function Phaser.Geom.Circle.CircumferencePoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Circle} circle - The Circle to get the circumference point on. * @param {number} angle - The angle from the center of the Circle to the circumference to return the point from. Given in radians. * @param {(Phaser.Geom.Point|object)} [out] - A Point, or point-like object, to store the results in. If not given a Point will be created. * * @return {(Phaser.Geom.Point|object)} A Point object where the `x` and `y` properties are the point on the circumference. */ var CircumferencePoint = function (circle, angle, out) { if (out === undefined) { out = new Point(); } out.x = circle.x + (circle.radius * Math.cos(angle)); out.y = circle.y + (circle.radius * Math.sin(angle)); return out; }; module.exports = CircumferencePoint; /***/ }), /* 137 */, /* 138 */, /* 139 */, /* 140 */, /* 141 */, /* 142 */, /* 143 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(18); var File = __webpack_require__(19); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var IsPlainObject = __webpack_require__(8); var ParseXML = __webpack_require__(270); /** * @typedef {object} Phaser.Loader.FileTypes.XMLFileConfig * * @property {string} key - The key of the file. Must be unique within both the Loader and the Text Cache. * @property {string} [url] - The absolute or relative URL to load the file from. * @property {string} [extension='xml'] - The default file extension to use if no url is provided. * @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ /** * @classdesc * A single XML File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#xml method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#xml. * * @class XMLFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.XMLFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ var XMLFile = new Class({ Extends: File, initialize: function XMLFile (loader, key, url, xhrSettings) { var extension = 'xml'; if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); url = GetFastValue(config, 'url'); xhrSettings = GetFastValue(config, 'xhrSettings'); extension = GetFastValue(config, 'extension', extension); } var fileConfig = { type: 'xml', cache: loader.cacheManager.xml, extension: extension, responseType: 'text', key: key, url: url, xhrSettings: xhrSettings }; File.call(this, loader, fileConfig); }, /** * Called automatically by Loader.nextFile. * This method controls what extra work this File does with its loaded data. * * @method Phaser.Loader.FileTypes.XMLFile#onProcess * @since 3.7.0 */ onProcess: function () { this.state = CONST.FILE_PROCESSING; this.data = ParseXML(this.xhrLoader.responseText); if (this.data) { this.onProcessComplete(); } else { console.warn('Invalid XMLFile: ' + this.key); this.onProcessError(); } } }); /** * Adds an XML file, or array of XML files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.xml('wavedata', 'files/AlienWaveData.xml'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * The key must be a unique String. It is used to add the file to the global XML Cache upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the XML Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the XML Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.xml({ * key: 'wavedata', * url: 'files/AlienWaveData.xml' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.XMLFileConfig` for more details. * * Once the file has finished loading you can access it from its Cache using its key: * * ```javascript * this.load.xml('wavedata', 'files/AlienWaveData.xml'); * // and later in your game ... * var data = this.cache.xml.get('wavedata'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and * this is what you would use to retrieve the text from the XML Cache. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" * and no URL is given then the Loader will set the URL to be "data.xml". It will always add `.xml` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * Note: The ability to load this type of file will only be available if the XML File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#xml * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.XMLFileConfig|Phaser.Loader.FileTypes.XMLFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('xml', function (key, url, xhrSettings) { if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object this.addFile(new XMLFile(this, key[i])); } } else { this.addFile(new XMLFile(this, key, url, xhrSettings)); } return this; }); module.exports = XMLFile; /***/ }), /* 144 */, /* 145 */, /* 146 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Returns a Random element from the array. * * @function Phaser.Utils.Array.GetRandom * @since 3.0.0 * * @param {array} array - The array to select the random entry from. * @param {integer} [startIndex=0] - An optional start index. * @param {integer} [length=array.length] - An optional length, the total number of elements (from the startIndex) to choose from. * * @return {object} A random element from the array, or `null` if no element could be found in the range given. */ var GetRandom = function (array, startIndex, length) { if (startIndex === undefined) { startIndex = 0; } if (length === undefined) { length = array.length; } var randomIndex = startIndex + Math.floor(Math.random() * length); return (array[randomIndex] === undefined) ? null : array[randomIndex]; }; module.exports = GetRandom; /***/ }), /* 147 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Utils.Array */ module.exports = { Matrix: __webpack_require__(503), Add: __webpack_require__(496), AddAt: __webpack_require__(495), BringToTop: __webpack_require__(494), CountAllMatching: __webpack_require__(493), Each: __webpack_require__(492), EachInRange: __webpack_require__(491), FindClosestInSorted: __webpack_require__(209), GetAll: __webpack_require__(490), GetFirst: __webpack_require__(489), GetRandom: __webpack_require__(146), MoveDown: __webpack_require__(488), MoveTo: __webpack_require__(487), MoveUp: __webpack_require__(486), NumberArray: __webpack_require__(485), NumberArrayStep: __webpack_require__(484), QuickSelect: __webpack_require__(180), Range: __webpack_require__(254), Remove: __webpack_require__(195), RemoveAt: __webpack_require__(483), RemoveBetween: __webpack_require__(482), RemoveRandomElement: __webpack_require__(481), Replace: __webpack_require__(480), RotateLeft: __webpack_require__(290), RotateRight: __webpack_require__(289), SafeRange: __webpack_require__(29), SendToBack: __webpack_require__(479), SetAll: __webpack_require__(478), Shuffle: __webpack_require__(95), SpliceOne: __webpack_require__(56), StableSort: __webpack_require__(83), Swap: __webpack_require__(477) }; /***/ }), /* 148 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Felipe Alfonso <@bitnenfer> * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var ShaderSourceFS = __webpack_require__(527); var TextureTintPipeline = __webpack_require__(129); var LIGHT_COUNT = 10; /** * @classdesc * ForwardDiffuseLightPipeline implements a forward rendering approach for 2D lights. * This pipeline extends TextureTintPipeline so it implements all it's rendering functions * and batching system. * * @class ForwardDiffuseLightPipeline * @extends Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline * @memberOf Phaser.Renderer.WebGL.Pipelines * @constructor * @since 3.0.0 * * @param {object} config - [description] */ var ForwardDiffuseLightPipeline = new Class({ Extends: TextureTintPipeline, initialize: function ForwardDiffuseLightPipeline (config) { config.fragShader = ShaderSourceFS.replace('%LIGHT_COUNT%', LIGHT_COUNT.toString()); TextureTintPipeline.call(this, config); }, /** * This function binds it's base class resources and this lights 2D resources. * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#onBind * @override * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline} [description] */ onBind: function () { TextureTintPipeline.prototype.onBind.call(this); var renderer = this.renderer; var program = this.program; this.mvpUpdate(); renderer.setInt1(program, 'uNormSampler', 1); renderer.setFloat2(program, 'uResolution', this.width, this.height); return this; }, /** * This function sets all the needed resources for each camera pass. * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#onRender * @since 3.0.0 * * @param {Phaser.Scene} scene - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * * @return {Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline} [description] */ onRender: function (scene, camera) { this.active = false; var lightManager = scene.sys.lights; if (!lightManager || lightManager.lights.length <= 0 || !lightManager.active) { // Passthru return this; } var lights = lightManager.cull(camera); var lightCount = Math.min(lights.length, LIGHT_COUNT); if (lightCount === 0) { return this; } this.active = true; var renderer = this.renderer; var program = this.program; var cameraMatrix = camera.matrix; var point = {x: 0, y: 0}; var height = renderer.height; var index; for (index = 0; index < LIGHT_COUNT; ++index) { // Reset lights renderer.setFloat1(program, 'uLights[' + index + '].radius', 0); } renderer.setFloat4(program, 'uCamera', camera.x, camera.y, camera.rotation, camera.zoom); renderer.setFloat3(program, 'uAmbientLightColor', lightManager.ambientColor.r, lightManager.ambientColor.g, lightManager.ambientColor.b); for (index = 0; index < lightCount; ++index) { var light = lights[index]; var lightName = 'uLights[' + index + '].'; cameraMatrix.transformPoint(light.x, light.y, point); renderer.setFloat2(program, lightName + 'position', point.x - (camera.scrollX * light.scrollFactorX * camera.zoom), height - (point.y - (camera.scrollY * light.scrollFactorY) * camera.zoom)); renderer.setFloat3(program, lightName + 'color', light.r, light.g, light.b); renderer.setFloat1(program, lightName + 'intensity', light.intensity); renderer.setFloat1(program, lightName + 'radius', light.radius); } return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#drawStaticTilemapLayer * @override * @since 3.0.0 * * @param {Phaser.Tilemaps.StaticTilemapLayer} tilemap - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ drawStaticTilemapLayer: function (tilemap, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = tilemap.tileset.image.dataSource[0]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.drawStaticTilemapLayer.call(this, tilemap, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. StaticTilemapLayer rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.drawStaticTilemapLayer(tilemap, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#drawEmitterManager * @since 3.0.0 * * @param {Phaser.GameObjects.Particles.ParticleEmitterManager} emitterManager - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ drawEmitterManager: function (emitterManager, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = emitterManager.texture.dataSource[emitterManager.frame.sourceIndex]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.drawEmitterManager.call(this, emitterManager, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. EmitterManager rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.drawEmitterManager(emitterManager, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#drawBlitter * @since 3.0.0 * * @param {Phaser.GameObjects.Blitter} blitter - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ drawBlitter: function (blitter, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = blitter.texture.dataSource[blitter.frame.sourceIndex]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.drawBlitter.call(this, blitter, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. Blitter rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.drawBlitter(blitter, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#batchSprite * @since 3.0.0 * * @param {Phaser.GameObjects.Sprite} sprite - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ batchSprite: function (sprite, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = sprite.texture.dataSource[sprite.frame.sourceIndex]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.batchSprite.call(this, sprite, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. Sprite rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.batchSprite(sprite, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#batchMesh * @since 3.0.0 * * @param {Phaser.GameObjects.Mesh} mesh - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ batchMesh: function (mesh, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = mesh.texture.dataSource[mesh.frame.sourceIndex]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.batchMesh.call(this, mesh, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. Mesh rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.batchMesh(mesh, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#batchBitmapText * @since 3.0.0 * * @param {Phaser.GameObjects.BitmapText} bitmapText - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ batchBitmapText: function (bitmapText, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = bitmapText.texture.dataSource[bitmapText.frame.sourceIndex]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.batchBitmapText.call(this, bitmapText, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. BitmapText rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.batchBitmapText(bitmapText, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#batchDynamicBitmapText * @since 3.0.0 * * @param {Phaser.GameObjects.DynamicBitmapText} bitmapText - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ batchDynamicBitmapText: function (bitmapText, camera, parentTransformMatrix) { var normalTexture = bitmapText.texture.dataSource[bitmapText.frame.sourceIndex]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.batchDynamicBitmapText.call(this, bitmapText, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. DynamicBitmapText rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.batchDynamicBitmapText(bitmapText, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#batchText * @since 3.0.0 * * @param {Phaser.GameObjects.Text} text - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ batchText: function (text, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = text.texture.dataSource[text.frame.sourceIndex]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.batchText.call(this, text, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. Text rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.batchText(text, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#batchDynamicTilemapLayer * @since 3.0.0 * * @param {Phaser.Tilemaps.DynamicTilemapLayer} tilemapLayer - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ batchDynamicTilemapLayer: function (tilemapLayer, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = tilemapLayer.tileset.image.dataSource[0]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.batchDynamicTilemapLayer.call(this, tilemapLayer, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. DynamicTilemapLayer rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.batchDynamicTilemapLayer(tilemapLayer, camera, parentTransformMatrix); } }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#batchTileSprite * @since 3.0.0 * * @param {Phaser.GameObjects.TileSprite} tileSprite - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] * */ batchTileSprite: function (tileSprite, camera, parentTransformMatrix) { if (!this.active) { return; } var normalTexture = tileSprite.texture.dataSource[tileSprite.frame.sourceIndex]; if (normalTexture) { this.renderer.setPipeline(this); this.setTexture2D(normalTexture.glTexture, 1); TextureTintPipeline.prototype.batchTileSprite.call(this, tileSprite, camera, parentTransformMatrix); } else { console.warn('Normal map texture missing for using Light2D pipeline. TileSprite rendered with default pipeline.'); this.renderer.pipelines.TextureTintPipeline.batchTileSprite(tileSprite, camera, parentTransformMatrix); } } }); ForwardDiffuseLightPipeline.LIGHT_COUNT = LIGHT_COUNT; module.exports = ForwardDiffuseLightPipeline; /***/ }), /* 149 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Compute a random integer between the `min` and `max` values, inclusive. * * @function Phaser.Math.Between * @since 3.0.0 * * @param {integer} min - The minimum value. * @param {integer} max - The maximum value. * * @return {integer} The random integer. */ var Between = function (min, max) { return Math.floor(Math.random() * (max - min + 1) + min); }; module.exports = Between; /***/ }), /* 150 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CONST = __webpack_require__(16); /** * Convert the given angle in radians, to the equivalent angle in degrees. * * @function Phaser.Math.RadToDeg * @since 3.0.0 * * @param {float} radians - The angle in radians to convert ot degrees. * * @return {integer} The given angle converted to degrees. */ var RadToDeg = function (radians) { return radians * CONST.RAD_TO_DEG; }; module.exports = RadToDeg; /***/ }), /* 151 */, /* 152 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Given 3 separate color values this will return an integer representation of it. * * @function Phaser.Display.Color.GetColor * @since 3.0.0 * * @param {integer} red - The red color value. A number between 0 and 255. * @param {integer} green - The green color value. A number between 0 and 255. * @param {integer} blue - The blue color value. A number between 0 and 255. * * @return {number} The combined color value. */ var GetColor = function (red, green, blue) { return red << 16 | green << 8 | blue; }; module.exports = GetColor; /***/ }), /* 153 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); /** * [description] * * @function Phaser.Geom.Triangle.Random * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Triangle} triangle - [description] * @param {Phaser.Geom.Point} [out] - [description] * * @return {Phaser.Geom.Point} [description] */ var Random = function (triangle, out) { if (out === undefined) { out = new Point(); } // Basis vectors var ux = triangle.x2 - triangle.x1; var uy = triangle.y2 - triangle.y1; var vx = triangle.x3 - triangle.x1; var vy = triangle.y3 - triangle.y1; // Random point within the unit square var r = Math.random(); var s = Math.random(); // Point outside the triangle? Remap it. if (r + s >= 1) { r = 1 - r; s = 1 - s; } out.x = triangle.x1 + ((ux * r) + (vx * s)); out.y = triangle.y1 + ((uy * r) + (vy * s)); return out; }; module.exports = Random; /***/ }), /* 154 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); /** * [description] * * @function Phaser.Geom.Rectangle.Random * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Rectangle} rect - [description] * @param {Phaser.Geom.Point} out - [description] * * @return {Phaser.Geom.Point} [description] */ var Random = function (rect, out) { if (out === undefined) { out = new Point(); } out.x = rect.x + (Math.random() * rect.width); out.y = rect.y + (Math.random() * rect.height); return out; }; module.exports = Random; /***/ }), /* 155 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); /** * Returns a random point on a given Line. * * @function Phaser.Geom.Line.Random * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Line} line - The Line to calculate the random Point on. * @param {(Phaser.Geom.Point|object)} [out] - An instance of a Point to be modified. * * @return {(Phaser.Geom.Point|object)} A random Point on the Line. */ var Random = function (line, out) { if (out === undefined) { out = new Point(); } var t = Math.random(); out.x = line.x1 + t * (line.x2 - line.x1); out.y = line.y1 + t * (line.y2 - line.y1); return out; }; module.exports = Random; /***/ }), /* 156 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Length = __webpack_require__(71); var Point = __webpack_require__(5); /** * [description] * * @function Phaser.Geom.Line.GetPoints * @since 3.0.0 * * @generic {Phaser.Geom.Point[]} O - [out,$return] * * @param {Phaser.Geom.Line} line - [description] * @param {integer} quantity - [description] * @param {integer} [stepRate] - [description] * @param {(array|Phaser.Geom.Point[])} [out] - [description] * * @return {(array|Phaser.Geom.Point[])} [description] */ var GetPoints = function (line, quantity, stepRate, out) { if (out === undefined) { out = []; } // If quantity is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead. if (!quantity) { quantity = Length(line) / stepRate; } var x1 = line.x1; var y1 = line.y1; var x2 = line.x2; var y2 = line.y2; for (var i = 0; i < quantity; i++) { var position = i / quantity; var x = x1 + (x2 - x1) * position; var y = y1 + (y2 - y1) * position; out.push(new Point(x, y)); } return out; }; module.exports = GetPoints; /***/ }), /* 157 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); /** * Returns a uniformly distributed random point from anywhere within the given Circle. * * @function Phaser.Geom.Circle.Random * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Circle} circle - The Circle to get a random point from. * @param {(Phaser.Geom.Point|object)} [out] - A Point or point-like object to set the random `x` and `y` values in. * * @return {(Phaser.Geom.Point|object)} A Point object with the random values set in the `x` and `y` properties. */ var Random = function (circle, out) { if (out === undefined) { out = new Point(); } var t = 2 * Math.PI * Math.random(); var u = Math.random() + Math.random(); var r = (u > 1) ? 2 - u : u; var x = r * Math.cos(t); var y = r * Math.sin(t); out.x = circle.x + (x * circle.radius); out.y = circle.y + (y * circle.radius); return out; }; module.exports = Random; /***/ }), /* 158 */, /* 159 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var EventEmitter = __webpack_require__(9); var TweenBuilder = __webpack_require__(72); var TWEEN_CONST = __webpack_require__(61); /** * @classdesc * [description] * * @class Timeline * @memberOf Phaser.Tweens * @extends Phaser.Events.EventEmitter * @constructor * @since 3.0.0 * * @param {Phaser.Tweens.TweenManager} manager - [description] */ var Timeline = new Class({ Extends: EventEmitter, initialize: function Timeline (manager) { EventEmitter.call(this); /** * [description] * * @name Phaser.Tweens.Timeline#manager * @type {Phaser.Tweens.TweenManager} * @since 3.0.0 */ this.manager = manager; /** * [description] * * @name Phaser.Tweens.Timeline#isTimeline * @type {boolean} * @default true * @since 3.0.0 */ this.isTimeline = true; /** * An array of Tween objects, each containing a unique property and target being tweened. * * @name Phaser.Tweens.Timeline#data * @type {array} * @default [] * @since 3.0.0 */ this.data = []; /** * data array doesn't usually change, so we can cache the length * * @name Phaser.Tweens.Timeline#totalData * @type {number} * @default 0 * @since 3.0.0 */ this.totalData = 0; /** * If true then duration, delay, etc values are all frame totals. * * @name Phaser.Tweens.Timeline#useFrames * @type {boolean} * @default false * @since 3.0.0 */ this.useFrames = false; /** * Scales the time applied to this Tween. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on. * Value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only. * * @name Phaser.Tweens.Timeline#timeScale * @type {number} * @default 1 * @since 3.0.0 */ this.timeScale = 1; /** * Loop this tween? Can be -1 for an infinite loop, or an integer. * When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD) * * @name Phaser.Tweens.Timeline#loop * @type {number} * @default 0 * @since 3.0.0 */ this.loop = 0; /** * Time in ms/frames before the tween loops. * * @name Phaser.Tweens.Timeline#loopDelay * @type {number} * @default 0 * @since 3.0.0 */ this.loopDelay = 0; /** * How many loops are left to run? * * @name Phaser.Tweens.Timeline#loopCounter * @type {number} * @default 0 * @since 3.0.0 */ this.loopCounter = 0; /** * Time in ms/frames before the 'onComplete' event fires. This never fires if loop = true (as it never completes) * * @name Phaser.Tweens.Timeline#completeDelay * @type {number} * @default 0 * @since 3.0.0 */ this.completeDelay = 0; /** * Countdown timer (used by loopDelay and completeDelay) * * @name Phaser.Tweens.Timeline#countdown * @type {number} * @default 0 * @since 3.0.0 */ this.countdown = 0; /** * The current state of the tween * * @name Phaser.Tweens.Timeline#state * @type {integer} * @since 3.0.0 */ this.state = TWEEN_CONST.PENDING_ADD; /** * The state of the tween when it was paused (used by Resume) * * @name Phaser.Tweens.Timeline#_pausedState * @type {integer} * @private * @since 3.0.0 */ this._pausedState = TWEEN_CONST.PENDING_ADD; /** * Does the Tween start off paused? (if so it needs to be started with Tween.play) * * @name Phaser.Tweens.Timeline#paused * @type {boolean} * @default false * @since 3.0.0 */ this.paused = false; /** * Elapsed time in ms/frames of this run through the Tween. * * @name Phaser.Tweens.Timeline#elapsed * @type {number} * @default 0 * @since 3.0.0 */ this.elapsed = 0; /** * Total elapsed time in ms/frames of the entire Tween, including looping. * * @name Phaser.Tweens.Timeline#totalElapsed * @type {number} * @default 0 * @since 3.0.0 */ this.totalElapsed = 0; /** * Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays. * * @name Phaser.Tweens.Timeline#duration * @type {number} * @default 0 * @since 3.0.0 */ this.duration = 0; /** * Value between 0 and 1. The amount through the Tween, excluding loops. * * @name Phaser.Tweens.Timeline#progress * @type {number} * @default 0 * @since 3.0.0 */ this.progress = 0; /** * Time in ms/frames for all Tweens to complete (including looping) * * @name Phaser.Tweens.Timeline#totalDuration * @type {number} * @default 0 * @since 3.0.0 */ this.totalDuration = 0; /** * Value between 0 and 1. The amount through the entire Tween, including looping. * * @name Phaser.Tweens.Timeline#totalProgress * @type {number} * @default 0 * @since 3.0.0 */ this.totalProgress = 0; this.callbacks = { onComplete: null, onLoop: null, onStart: null, onUpdate: null, onYoyo: null }; this.callbackScope; }, /** * [description] * * @method Phaser.Tweens.Timeline#setTimeScale * @since 3.0.0 * * @param {number} value - [description] * * @return {Phaser.Tweens.Timeline} This Timeline object. */ setTimeScale: function (value) { this.timeScale = value; return this; }, /** * [description] * * @method Phaser.Tweens.Timeline#getTimeScale * @since 3.0.0 * * @return {number} [description] */ getTimeScale: function () { return this.timeScale; }, /** * [description] * * @method Phaser.Tweens.Timeline#isPlaying * @since 3.0.0 * * @return {boolean} [description] */ isPlaying: function () { return (this.state === TWEEN_CONST.ACTIVE); }, /** * [description] * * @method Phaser.Tweens.Timeline#add * @since 3.0.0 * * @param {object} config - [description] * * @return {Phaser.Tweens.Timeline} This Timeline object. */ add: function (config) { return this.queue(TweenBuilder(this, config)); }, /** * [description] * * @method Phaser.Tweens.Timeline#queue * @since 3.0.0 * * @param {Phaser.Tweens.Tween} tween - [description] * * @return {Phaser.Tweens.Timeline} This Timeline object. */ queue: function (tween) { if (!this.isPlaying()) { tween.parent = this; tween.parentIsTimeline = true; this.data.push(tween); this.totalData = this.data.length; } return this; }, /** * [description] * * @method Phaser.Tweens.Timeline#hasOffset * @since 3.0.0 * * @param {Phaser.Tweens.Tween} tween - [description] * * @return {boolean} [description] */ hasOffset: function (tween) { return (tween.offset !== null); }, /** * [description] * * @method Phaser.Tweens.Timeline#isOffsetAbsolute * @since 3.0.0 * * @param {number} value - [description] * * @return {boolean} [description] */ isOffsetAbsolute: function (value) { return (typeof(value) === 'number'); }, /** * [description] * * @method Phaser.Tweens.Timeline#isOffsetRelative * @since 3.0.0 * * @param {string} value - [description] * * @return {boolean} [description] */ isOffsetRelative: function (value) { var t = typeof(value); if (t === 'string') { var op = value[0]; if (op === '-' || op === '+') { return true; } } return false; }, /** * [description] * * @method Phaser.Tweens.Timeline#getRelativeOffset * @since 3.0.0 * * @param {string} value - [description] * @param {number} base - [description] * * @return {number} [description] */ getRelativeOffset: function (value, base) { var op = value[0]; var num = parseFloat(value.substr(2)); var result = base; switch (op) { case '+': result += num; break; case '-': result -= num; break; } // Cannot ever be < 0 return Math.max(0, result); }, /** * [description] * * @method Phaser.Tweens.Timeline#calcDuration * @since 3.0.0 */ calcDuration: function () { var prevEnd = 0; var totalDuration = 0; var offsetDuration = 0; for (var i = 0; i < this.totalData; i++) { var tween = this.data[i]; tween.init(); if (this.hasOffset(tween)) { if (this.isOffsetAbsolute(tween.offset)) { // An actual number, so it defines the start point from the beginning of the timeline tween.calculatedOffset = tween.offset; if (tween.offset === 0) { offsetDuration = 0; } } else if (this.isOffsetRelative(tween.offset)) { // A relative offset (i.e. '-=1000', so starts at 'offset' ms relative to the PREVIOUS Tweens ending time) tween.calculatedOffset = this.getRelativeOffset(tween.offset, prevEnd); } } else { // Sequential tween.calculatedOffset = offsetDuration; } prevEnd = tween.totalDuration + tween.calculatedOffset; totalDuration += tween.totalDuration; offsetDuration += tween.totalDuration; } // Excludes loop values this.duration = totalDuration; this.loopCounter = (this.loop === -1) ? 999999999999 : this.loop; if (this.loopCounter > 0) { this.totalDuration = this.duration + this.completeDelay + ((this.duration + this.loopDelay) * this.loopCounter); } else { this.totalDuration = this.duration + this.completeDelay; } }, /** * [description] * * @method Phaser.Tweens.Timeline#init * @since 3.0.0 * * @return {boolean} [description] */ init: function () { this.calcDuration(); this.progress = 0; this.totalProgress = 0; if (this.paused) { this.state = TWEEN_CONST.PAUSED; return false; } else { return true; } }, /** * [description] * * @method Phaser.Tweens.Timeline#resetTweens * @since 3.0.0 * * @param {boolean} resetFromLoop - [description] */ resetTweens: function (resetFromLoop) { for (var i = 0; i < this.totalData; i++) { var tween = this.data[i]; tween.play(resetFromLoop); } }, /** * [description] * * @method Phaser.Tweens.Timeline#setCallback * @since 3.0.0 * * @param {string} type - [description] * @param {function} callback - [description] * @param {array} [params] - [description] * @param {object} [scope] - [description] * * @return {Phaser.Tweens.Timeline} This Timeline object. */ setCallback: function (type, callback, params, scope) { if (Timeline.TYPES.indexOf(type) !== -1) { this.callbacks[type] = { func: callback, scope: scope, params: params }; } return this; }, /** * Delegates #makeActive to the Tween manager. * * @method Phaser.Tweens.Timeline#makeActive * @since 3.3.0 * * @param {Phaser.Tweens.Tween} tween - The tween object to make active. * * @return {Phaser.Tweens.TweenManager} The Timeline's Tween Manager object. */ makeActive: function (tween) { return this.manager.makeActive(tween); }, /** * [description] * * @method Phaser.Tweens.Timeline#play * @since 3.0.0 */ play: function () { if (this.state === TWEEN_CONST.ACTIVE) { return; } if (this.paused) { this.paused = false; this.manager.makeActive(this); return; } else { this.resetTweens(false); this.state = TWEEN_CONST.ACTIVE; } var onStart = this.callbacks.onStart; if (onStart) { onStart.func.apply(onStart.scope, onStart.params); } this.emit('start', this); }, /** * [description] * * @method Phaser.Tweens.Timeline#nextState * @since 3.0.0 */ nextState: function () { if (this.loopCounter > 0) { // Reset the elapsed time // TODO: Probably ought to be set to the remainder from elapsed - duration // as the tweens nearly always over-run by a few ms due to rAf this.elapsed = 0; this.progress = 0; this.loopCounter--; var onLoop = this.callbacks.onLoop; if (onLoop) { onLoop.func.apply(onLoop.scope, onLoop.params); } this.emit('loop', this, this.loopCounter); this.resetTweens(true); if (this.loopDelay > 0) { this.countdown = this.loopDelay; this.state = TWEEN_CONST.LOOP_DELAY; } else { this.state = TWEEN_CONST.ACTIVE; } } else if (this.completeDelay > 0) { this.countdown = this.completeDelay; this.state = TWEEN_CONST.COMPLETE_DELAY; } else { var onComplete = this.callbacks.onComplete; if (onComplete) { onComplete.func.apply(onComplete.scope, onComplete.params); } this.emit('complete', this); this.state = TWEEN_CONST.PENDING_REMOVE; } }, /** * Returns 'true' if this Timeline has finished and should be removed from the Tween Manager. * Otherwise, returns false. * * @method Phaser.Tweens.Timeline#update * @since 3.0.0 * * @param {number} timestamp - [description] * @param {number} delta - [description] * * @return {boolean} Returns `true` if this Timeline has finished and should be removed from the Tween Manager. */ update: function (timestamp, delta) { if (this.state === TWEEN_CONST.PAUSED) { return; } var rawDelta = delta; if (this.useFrames) { delta = 1 * this.manager.timeScale; } delta *= this.timeScale; this.elapsed += delta; this.progress = Math.min(this.elapsed / this.duration, 1); this.totalElapsed += delta; this.totalProgress = Math.min(this.totalElapsed / this.totalDuration, 1); switch (this.state) { case TWEEN_CONST.ACTIVE: var stillRunning = this.totalData; for (var i = 0; i < this.totalData; i++) { var tween = this.data[i]; if (tween.update(timestamp, rawDelta)) { stillRunning--; } } var onUpdate = this.callbacks.onUpdate; if (onUpdate) { onUpdate.func.apply(onUpdate.scope, onUpdate.params); } this.emit('update', this); // Anything still running? If not, we're done if (stillRunning === 0) { this.nextState(); } break; case TWEEN_CONST.LOOP_DELAY: this.countdown -= delta; if (this.countdown <= 0) { this.state = TWEEN_CONST.ACTIVE; } break; case TWEEN_CONST.COMPLETE_DELAY: this.countdown -= delta; if (this.countdown <= 0) { var onComplete = this.callbacks.onComplete; if (onComplete) { onComplete.func.apply(onComplete.scope, onComplete.params); } this.emit('complete', this); this.state = TWEEN_CONST.PENDING_REMOVE; } break; } return (this.state === TWEEN_CONST.PENDING_REMOVE); }, /** * Stops the Tween immediately, whatever stage of progress it is at and flags it for removal by the TweenManager. * * @method Phaser.Tweens.Timeline#stop * @since 3.0.0 */ stop: function () { this.state = TWEEN_CONST.PENDING_REMOVE; }, /** * [description] * * @method Phaser.Tweens.Timeline#pause * @since 3.0.0 * * @return {Phaser.Tweens.Timeline} This Timeline object. */ pause: function () { if (this.state === TWEEN_CONST.PAUSED) { return; } this.paused = true; this._pausedState = this.state; this.state = TWEEN_CONST.PAUSED; this.emit('pause', this); return this; }, /** * [description] * * @method Phaser.Tweens.Timeline#resume * @since 3.0.0 * * @return {Phaser.Tweens.Timeline} This Timeline object. */ resume: function () { if (this.state === TWEEN_CONST.PAUSED) { this.paused = false; this.state = this._pausedState; } this.emit('resume', this); return this; }, /** * [description] * * @method Phaser.Tweens.Timeline#hasTarget * @since 3.0.0 * * @param {object} target - [description] * * @return {boolean} [description] */ hasTarget: function (target) { for (var i = 0; i < this.data.length; i++) { if (this.data[i].hasTarget(target)) { return true; } } return false; }, /** * [description] * * @method Phaser.Tweens.Timeline#destroy * @since 3.0.0 */ destroy: function () { for (var i = 0; i < this.data.length; i++) { this.data[i].stop(); } } }); Timeline.TYPES = [ 'onStart', 'onUpdate', 'onLoop', 'onComplete', 'onYoyo' ]; module.exports = Timeline; /***/ }), /* 160 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clone = __webpack_require__(33); var Defaults = __webpack_require__(100); var GetAdvancedValue = __webpack_require__(10); var GetBoolean = __webpack_require__(62); var GetEaseFunction = __webpack_require__(63); var GetNewValue = __webpack_require__(73); var GetTargets = __webpack_require__(102); var GetTweens = __webpack_require__(162); var GetValue = __webpack_require__(4); var Timeline = __webpack_require__(159); var TweenBuilder = __webpack_require__(72); /** * [description] * * @function Phaser.Tweens.Builders.TimelineBuilder * @since 3.0.0 * * @param {Phaser.Tweens.TweenManager} manager - [description] * @param {object} config - [description] * * @return {Phaser.Tweens.Timeline} [description] */ var TimelineBuilder = function (manager, config) { var timeline = new Timeline(manager); var tweens = GetTweens(config); if (tweens.length === 0) { timeline.paused = true; return timeline; } var defaults = Clone(Defaults); defaults.targets = GetTargets(config); // totalDuration: If specified each tween in the Timeline is given an equal portion of the totalDuration var totalDuration = GetAdvancedValue(config, 'totalDuration', 0); if (totalDuration > 0) { defaults.duration = Math.floor(totalDuration / tweens.length); } else { defaults.duration = GetNewValue(config, 'duration', defaults.duration); } defaults.delay = GetNewValue(config, 'delay', defaults.delay); defaults.easeParams = GetValue(config, 'easeParams', defaults.easeParams); defaults.ease = GetEaseFunction(GetValue(config, 'ease', defaults.ease), defaults.easeParams); defaults.hold = GetNewValue(config, 'hold', defaults.hold); defaults.repeat = GetNewValue(config, 'repeat', defaults.repeat); defaults.repeatDelay = GetNewValue(config, 'repeatDelay', defaults.repeatDelay); defaults.yoyo = GetBoolean(config, 'yoyo', defaults.yoyo); defaults.flipX = GetBoolean(config, 'flipX', defaults.flipX); defaults.flipY = GetBoolean(config, 'flipY', defaults.flipY); // Create the Tweens for (var i = 0; i < tweens.length; i++) { timeline.queue(TweenBuilder(timeline, tweens[i], defaults)); } timeline.completeDelay = GetAdvancedValue(config, 'completeDelay', 0); timeline.loop = Math.round(GetAdvancedValue(config, 'loop', 0)); timeline.loopDelay = Math.round(GetAdvancedValue(config, 'loopDelay', 0)); timeline.paused = GetBoolean(config, 'paused', false); timeline.useFrames = GetBoolean(config, 'useFrames', false); // Callbacks var scope = GetValue(config, 'callbackScope', timeline); var timelineArray = [ timeline ]; var onStart = GetValue(config, 'onStart', false); // The Start of the Timeline if (onStart) { var onStartScope = GetValue(config, 'onStartScope', scope); var onStartParams = GetValue(config, 'onStartParams', []); timeline.setCallback('onStart', onStart, timelineArray.concat(onStartParams), onStartScope); } var onUpdate = GetValue(config, 'onUpdate', false); // Every time the Timeline updates (regardless which Tweens are running) if (onUpdate) { var onUpdateScope = GetValue(config, 'onUpdateScope', scope); var onUpdateParams = GetValue(config, 'onUpdateParams', []); timeline.setCallback('onUpdate', onUpdate, timelineArray.concat(onUpdateParams), onUpdateScope); } var onLoop = GetValue(config, 'onLoop', false); // Called when the whole Timeline loops if (onLoop) { var onLoopScope = GetValue(config, 'onLoopScope', scope); var onLoopParams = GetValue(config, 'onLoopParams', []); timeline.setCallback('onLoop', onLoop, timelineArray.concat(onLoopParams), onLoopScope); } var onYoyo = GetValue(config, 'onYoyo', false); // Called when a Timeline yoyos if (onYoyo) { var onYoyoScope = GetValue(config, 'onYoyoScope', scope); var onYoyoParams = GetValue(config, 'onYoyoParams', []); timeline.setCallback('onYoyo', onYoyo, timelineArray.concat(null, onYoyoParams), onYoyoScope); } var onComplete = GetValue(config, 'onComplete', false); // Called when the Timeline completes, after the completeDelay, etc. if (onComplete) { var onCompleteScope = GetValue(config, 'onCompleteScope', scope); var onCompleteParams = GetValue(config, 'onCompleteParams', []); timeline.setCallback('onComplete', onComplete, timelineArray.concat(onCompleteParams), onCompleteScope); } return timeline; }; module.exports = TimelineBuilder; /***/ }), /* 161 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Defaults = __webpack_require__(100); var GetAdvancedValue = __webpack_require__(10); var GetBoolean = __webpack_require__(62); var GetEaseFunction = __webpack_require__(63); var GetNewValue = __webpack_require__(73); var GetValue = __webpack_require__(4); var GetValueOp = __webpack_require__(101); var Tween = __webpack_require__(99); var TweenData = __webpack_require__(98); /** * [description] * * @function Phaser.Tweens.Builders.NumberTweenBuilder * @since 3.0.0 * * @param {(Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline)} parent - [description] * @param {object} config - [description] * @param {Phaser.Tweens.TweenConfigDefaults} defaults - [description] * * @return {Phaser.Tweens.Tween} [description] */ var NumberTweenBuilder = function (parent, config, defaults) { if (defaults === undefined) { defaults = Defaults; } // var tween = this.tweens.addCounter({ // from: 100, // to: 200, // ... (normal tween properties) // }) // // Then use it in your game via: // // tween.getValue() var from = GetValue(config, 'from', 0); var to = GetValue(config, 'to', 1); var targets = [ { value: from } ]; var delay = GetNewValue(config, 'delay', defaults.delay); var duration = GetNewValue(config, 'duration', defaults.duration); var easeParams = GetValue(config, 'easeParams', defaults.easeParams); var ease = GetEaseFunction(GetValue(config, 'ease', defaults.ease), easeParams); var hold = GetNewValue(config, 'hold', defaults.hold); var repeat = GetNewValue(config, 'repeat', defaults.repeat); var repeatDelay = GetNewValue(config, 'repeatDelay', defaults.repeatDelay); var yoyo = GetBoolean(config, 'yoyo', defaults.yoyo); var data = []; var ops = GetValueOp('value', to); var tweenData = TweenData( targets[0], 'value', ops.getEnd, ops.getStart, ease, delay, duration, yoyo, hold, repeat, repeatDelay, false, false ); tweenData.start = from; tweenData.current = from; tweenData.to = to; data.push(tweenData); var tween = new Tween(parent, data, targets); tween.offset = GetAdvancedValue(config, 'offset', null); tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0); tween.loop = Math.round(GetAdvancedValue(config, 'loop', 0)); tween.loopDelay = Math.round(GetAdvancedValue(config, 'loopDelay', 0)); tween.paused = GetBoolean(config, 'paused', false); tween.useFrames = GetBoolean(config, 'useFrames', false); // Set the Callbacks var scope = GetValue(config, 'callbackScope', tween); // Callback parameters: 0 = a reference to the Tween itself, 1 = the target/s of the Tween, ... your own params var tweenArray = [ tween, null ]; var callbacks = Tween.TYPES; for (var i = 0; i < callbacks.length; i++) { var type = callbacks[i]; var callback = GetValue(config, type, false); if (callback) { var callbackScope = GetValue(config, type + 'Scope', scope); var callbackParams = GetValue(config, type + 'Params', []); // The null is reset to be the Tween target tween.setCallback(type, callback, tweenArray.concat(callbackParams), callbackScope); } } return tween; }; module.exports = NumberTweenBuilder; /***/ }), /* 162 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetValue = __webpack_require__(4); /** * [description] * * @function Phaser.Tweens.Builders.GetTweens * @since 3.0.0 * * @param {object} config - [description] * * @return {array} [description] */ var GetTweens = function (config) { var tweens = GetValue(config, 'tweens', null); if (tweens === null) { return []; } else if (typeof tweens === 'function') { tweens = tweens.call(); } if (!Array.isArray(tweens)) { tweens = [ tweens ]; } return tweens; }; module.exports = GetTweens; /***/ }), /* 163 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var RESERVED = __webpack_require__(304); /** * [description] * * @function Phaser.Tweens.Builders.GetProps * @since 3.0.0 * * @param {object} config - [description] * * @return {array} [description] */ var GetProps = function (config) { var key; var keys = []; // First see if we have a props object if (config.hasOwnProperty('props')) { for (key in config.props) { // Skip any property that starts with an underscore if (key.substr(0, 1) !== '_') { keys.push({ key: key, value: config.props[key] }); } } } else { for (key in config) { // Skip any property that is in the ReservedProps list or that starts with an underscore if (RESERVED.indexOf(key) === -1 && key.substr(0, 1) !== '_') { keys.push({ key: key, value: config[key] }); } } } return keys; }; module.exports = GetProps; /***/ }), /* 164 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var GetFastValue = __webpack_require__(1); /** * @typedef {object} TimerEventConfig * * @property {number} [delay=0] - [description] * @property {number} [repeat=0] - [description] * @property {boolean} [loop=false] - [description] * @property {function} [callback] - [description] * @property {*} [callbackScope] - [description] * @property {Array.<*>} [args] - [description] * @property {number} [timeScale=1] - [description] * @property {number} [startAt=1] - [description] * @property {boolean} [paused=false] - [description] */ /** * @classdesc * [description] * * @class TimerEvent * @memberOf Phaser.Time * @constructor * @since 3.0.0 * * @param {TimerEventConfig} config - [description] */ var TimerEvent = new Class({ initialize: function TimerEvent (config) { /** * The delay in ms at which this TimerEvent fires. * * @name Phaser.Time.TimerEvent#delay * @type {number} * @default 0 * @readOnly * @since 3.0.0 */ this.delay = 0; /** * The total number of times this TimerEvent will repeat before finishing. * * @name Phaser.Time.TimerEvent#repeat * @type {number} * @default 0 * @readOnly * @since 3.0.0 */ this.repeat = 0; /** * If repeating this contains the current repeat count. * * @name Phaser.Time.TimerEvent#repeatCount * @type {number} * @default 0 * @since 3.0.0 */ this.repeatCount = 0; /** * True if this TimerEvent loops, otherwise false. * * @name Phaser.Time.TimerEvent#loop * @type {boolean} * @default false * @readOnly * @since 3.0.0 */ this.loop = false; /** * The callback that will be called when the TimerEvent occurs. * * @name Phaser.Time.TimerEvent#callback * @type {function} * @since 3.0.0 */ this.callback; /** * The scope in which the callback will be called. * * @name Phaser.Time.TimerEvent#callbackScope * @type {object} * @since 3.0.0 */ this.callbackScope; /** * Additional arguments to be passed to the callback. * * @name Phaser.Time.TimerEvent#args * @type {array} * @since 3.0.0 */ this.args; /** * Scale the time causing this TimerEvent to update. * * @name Phaser.Time.TimerEvent#timeScale * @type {number} * @default 1 * @since 3.0.0 */ this.timeScale = 1; /** * Start this many MS into the elapsed (useful if you want a long duration with repeat, but for the first loop to fire quickly) * * @name Phaser.Time.TimerEvent#startAt * @type {number} * @default 0 * @since 3.0.0 */ this.startAt = 0; /** * [description] * * @name Phaser.Time.TimerEvent#elapsed * @type {number} * @default 0 * @since 3.0.0 */ this.elapsed = 0; /** * [description] * * @name Phaser.Time.TimerEvent#paused * @type {boolean} * @default false * @since 3.0.0 */ this.paused = false; /** * [description] * * @name Phaser.Time.TimerEvent#hasDispatched * @type {boolean} * @default false * @since 3.0.0 */ this.hasDispatched = false; this.reset(config); }, /** * [description] * * @method Phaser.Time.TimerEvent#reset * @since 3.0.0 * * @param {TimerEventConfig} config - [description] * * @return {Phaser.Time.TimerEvent} This TimerEvent object. */ reset: function (config) { this.delay = GetFastValue(config, 'delay', 0); // Can also be set to -1 for an infinite loop (same as setting loop: true) this.repeat = GetFastValue(config, 'repeat', 0); this.loop = GetFastValue(config, 'loop', false); this.callback = GetFastValue(config, 'callback', undefined); this.callbackScope = GetFastValue(config, 'callbackScope', this.callback); this.args = GetFastValue(config, 'args', []); this.timeScale = GetFastValue(config, 'timeScale', 1); this.startAt = GetFastValue(config, 'startAt', 0); this.paused = GetFastValue(config, 'paused', false); this.elapsed = this.startAt; this.hasDispatched = false; this.repeatCount = (this.repeat === -1 || this.loop) ? 999999999999 : this.repeat; return this; }, /** * Gets the progress of the current iteration, not factoring in repeats. * * @method Phaser.Time.TimerEvent#getProgress * @since 3.0.0 * * @return {number} [description] */ getProgress: function () { return (this.elapsed / this.delay); }, /** * Gets the progress of the timer overall, factoring in repeats. * * @method Phaser.Time.TimerEvent#getOverallProgress * @since 3.0.0 * * @return {number} [description] */ getOverallProgress: function () { if (this.repeat > 0) { var totalDuration = this.delay + (this.delay * this.repeat); var totalElapsed = this.elapsed + (this.delay * (this.repeat - this.repeatCount)); return (totalElapsed / totalDuration); } else { return this.getProgress(); } }, /** * [description] * * @method Phaser.Time.TimerEvent#getRepeatCount * @since 3.0.0 * * @return {number} [description] */ getRepeatCount: function () { return this.repeatCount; }, /** * [description] * * @method Phaser.Time.TimerEvent#getElapsed * @since 3.0.0 * * @return {number} [description] */ getElapsed: function () { return this.elapsed; }, /** * [description] * * @method Phaser.Time.TimerEvent#getElapsedSeconds * @since 3.0.0 * * @return {number} [description] */ getElapsedSeconds: function () { return this.elapsed * 0.001; }, /** * [description] * * @method Phaser.Time.TimerEvent#remove * @since 3.0.0 * * @param {function} dispatchCallback - [description] */ remove: function (dispatchCallback) { if (dispatchCallback === undefined) { dispatchCallback = false; } this.elapsed = this.delay; this.hasDispatched = !dispatchCallback; this.repeatCount = 0; }, /** * [description] * * @method Phaser.Time.TimerEvent#destroy * @since 3.0.0 */ destroy: function () { this.callback = undefined; this.callbackScope = undefined; this.args = []; } }); module.exports = TimerEvent; /***/ }), /* 165 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser3-plugin-template/blob/master/LICENSE|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * A Global Plugin is installed just once into the Game owned Plugin Manager. * It can listen for Game events and respond to them. * * @class BasePlugin * @memberOf Phaser.Plugins * @constructor * @since 3.8.0 * * @param {Phaser.Plugins.PluginManager} pluginManager - A reference to the Plugin Manager. */ var BasePlugin = new Class({ initialize: function BasePlugin (pluginManager) { /** * A handy reference to the Plugin Manager that is responsible for this plugin. * Can be used as a route to gain access to game systems and events. * * @name Phaser.Plugins.BasePlugin#pluginManager * @type {Phaser.Plugins.PluginManager} * @protected * @since 3.8.0 */ this.pluginManager = pluginManager; /** * A reference to the Game instance this plugin is running under. * * @name Phaser.Plugins.BasePlugin#game * @type {Phaser.Game} * @protected * @since 3.8.0 */ this.game = pluginManager.game; /** * A reference to the Scene that has installed this plugin. * Only set if it's a Scene Plugin, otherwise `null`. * This property is only set when the plugin is instantiated and added to the Scene, not before. * You cannot use it during the `init` method, but you can during the `boot` method. * * @name Phaser.Plugins.BasePlugin#scene * @type {?Phaser.Scene} * @protected * @since 3.8.0 */ this.scene; /** * A reference to the Scene Systems of the Scene that has installed this plugin. * Only set if it's a Scene Plugin, otherwise `null`. * This property is only set when the plugin is instantiated and added to the Scene, not before. * You cannot use it during the `init` method, but you can during the `boot` method. * * @name Phaser.Plugins.BasePlugin#systems * @type {?Phaser.Scenes.Systems} * @protected * @since 3.8.0 */ this.systems; }, /** * Called by the PluginManager when this plugin is first instantiated. * It will never be called again on this instance. * In here you can set-up whatever you need for this plugin to run. * If a plugin is set to automatically start then `BasePlugin.start` will be called immediately after this. * * @method Phaser.Plugins.BasePlugin#init * @since 3.8.0 */ init: function () { }, /** * Called by the PluginManager when this plugin is started. * If a plugin is stopped, and then started again, this will get called again. * Typically called immediately after `BasePlugin.init`. * * @method Phaser.Plugins.BasePlugin#start * @since 3.8.0 */ start: function () { // Here are the game-level events you can listen to. // At the very least you should offer a destroy handler for when the game closes down. // var eventEmitter = this.game.events; // eventEmitter.once('destroy', this.gameDestroy, this); // eventEmitter.on('pause', this.gamePause, this); // eventEmitter.on('resume', this.gameResume, this); // eventEmitter.on('resize', this.gameResize, this); // eventEmitter.on('prestep', this.gamePreStep, this); // eventEmitter.on('step', this.gameStep, this); // eventEmitter.on('poststep', this.gamePostStep, this); // eventEmitter.on('prerender', this.gamePreRender, this); // eventEmitter.on('postrender', this.gamePostRender, this); }, /** * Called by the PluginManager when this plugin is stopped. * The game code has requested that your plugin stop doing whatever it does. * It is now considered as 'inactive' by the PluginManager. * Handle that process here (i.e. stop listening for events, etc) * If the plugin is started again then `BasePlugin.start` will be called again. * * @method Phaser.Plugins.BasePlugin#stop * @since 3.8.0 */ stop: function () { }, /** * If this is a Scene Plugin (i.e. installed into a Scene) then this method is called when the Scene boots. * By this point the plugin properties `scene` and `systems` will have already been set. * In here you can listen for Scene events and set-up whatever you need for this plugin to run. * * @method Phaser.Plugins.BasePlugin#boot * @since 3.8.0 */ boot: function () { // Here are the Scene events you can listen to. // At the very least you should offer a destroy handler for when the Scene closes down. // var eventEmitter = this.systems.events; // eventEmitter.once('destroy', this.sceneDestroy, this); // eventEmitter.on('start', this.sceneStart, this); // eventEmitter.on('preupdate', this.scenePreUpdate, this); // eventEmitter.on('update', this.sceneUpdate, this); // eventEmitter.on('postupdate', this.scenePostUpdate, this); // eventEmitter.on('pause', this.scenePause, this); // eventEmitter.on('resume', this.sceneResume, this); // eventEmitter.on('sleep', this.sceneSleep, this); // eventEmitter.on('wake', this.sceneWake, this); // eventEmitter.on('shutdown', this.sceneShutdown, this); // eventEmitter.on('destroy', this.sceneDestroy, this); }, /** * Game instance has been destroyed. * You must release everything in here, all references, all objects, free it all up. * * @method Phaser.Plugins.BasePlugin#destroy * @since 3.8.0 */ destroy: function () { this.pluginManager = null; this.game = null; this.scene = null; this.systems = null; } }); module.exports = BasePlugin; /***/ }), /* 166 */, /* 167 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var File = __webpack_require__(19); var GetFastValue = __webpack_require__(1); var GetURL = __webpack_require__(108); var IsPlainObject = __webpack_require__(8); /** * @classdesc * A single Audio File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#audio method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audio. * * @class HTML5AudioFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.AudioFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string} [urlConfig] - The absolute or relative URL to load this file from. * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ var HTML5AudioFile = new Class({ Extends: File, initialize: function HTML5AudioFile (loader, key, urlConfig, audioConfig) { if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); audioConfig = GetFastValue(config, 'config', audioConfig); } var fileConfig = { type: 'audio', cache: loader.cacheManager.audio, extension: urlConfig.type, key: key, url: urlConfig.url, config: audioConfig }; File.call(this, loader, fileConfig); // New properties specific to this class this.locked = 'ontouchstart' in window; this.loaded = false; this.filesLoaded = 0; this.filesTotal = 0; }, /** * Called when the file finishes loading. * * @method Phaser.Loader.FileTypes.HTML5AudioFile#onLoad * @since 3.0.0 */ onLoad: function () { if (this.loaded) { return; } this.loaded = true; this.loader.nextFile(this, true); }, /** * Called if the file errors while loading. * * @method Phaser.Loader.FileTypes.HTML5AudioFile#onError * @since 3.0.0 */ onError: function () { for (var i = 0; i < this.data.length; i++) { var audio = this.data[i]; audio.oncanplaythrough = null; audio.onerror = null; } this.loader.nextFile(this, false); }, /** * Called during the file load progress. Is sent a DOM ProgressEvent. * * @method Phaser.Loader.FileTypes.HTML5AudioFile#onProgress * @since 3.0.0 */ onProgress: function (event) { var audio = event.target; audio.oncanplaythrough = null; audio.onerror = null; this.filesLoaded++; this.percentComplete = Math.min((this.filesLoaded / this.filesTotal), 1); this.loader.emit('fileprogress', this, this.percentComplete); if (this.filesLoaded === this.filesTotal) { this.onLoad(); } }, /** * Called by the Loader, starts the actual file downloading. * During the load the methods onLoad, onError and onProgress are called, based on the XHR events. * You shouldn't normally call this method directly, it's meant to be invoked by the Loader. * * @method Phaser.Loader.FileTypes.HTML5AudioFile#load * @since 3.0.0 */ load: function () { this.data = []; var instances = (this.config && this.config.instances) || 1; this.filesTotal = instances; this.filesLoaded = 0; this.percentComplete = 0; for (var i = 0; i < instances; i++) { var audio = new Audio(); audio.dataset.name = this.key + ('0' + i).slice(-2); audio.dataset.used = 'false'; if (this.locked) { audio.dataset.locked = 'true'; } else { audio.dataset.locked = 'false'; audio.preload = 'auto'; audio.oncanplaythrough = this.onProgress.bind(this); audio.onerror = this.onError.bind(this); } this.data.push(audio); } for (i = 0; i < this.data.length; i++) { audio = this.data[i]; audio.src = GetURL(this, this.loader.baseURL); if (!this.locked) { audio.load(); } } if (this.locked) { // This is super-dangerous but works. Race condition potential high. // Is there another way? setTimeout(this.onLoad.bind(this)); } } }); module.exports = HTML5AudioFile; /***/ }), /* 168 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(20); var File = __webpack_require__(19); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var HTML5AudioFile = __webpack_require__(167); var IsPlainObject = __webpack_require__(8); /** * @typedef {object} Phaser.Loader.FileTypes.AudioFileConfig * * @property {string} key - The key of the file. Must be unique within the Loader and Audio Cache. * @property {string} [urlConfig] - The absolute or relative URL to load the file from. * @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. * @property {AudioContext} [audioContext] - The AudioContext this file will use to process itself. */ /** * @classdesc * A single Audio File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#audio method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audio. * * @class AudioFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.AudioFileConfig)} key - The key to use for this file, or a file configuration object. * @param {any} [urlConfig] - The absolute or relative URL to load this file from in a config object. * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. * @param {AudioContext} [audioContext] - The AudioContext this file will use to process itself. */ var AudioFile = new Class({ Extends: File, initialize: // URL is an object created by AudioFile.findAudioURL function AudioFile (loader, key, urlConfig, xhrSettings, audioContext) { if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); xhrSettings = GetFastValue(config, 'xhrSettings'); audioContext = GetFastValue(config, 'context', audioContext); } var fileConfig = { type: 'audio', cache: loader.cacheManager.audio, extension: urlConfig.type, responseType: 'arraybuffer', key: key, url: urlConfig.url, xhrSettings: xhrSettings, config: { context: audioContext } }; File.call(this, loader, fileConfig); }, /** * Called automatically by Loader.nextFile. * This method controls what extra work this File does with its loaded data. * * @method Phaser.Loader.FileTypes.AudioFile#onProcess * @since 3.0.0 */ onProcess: function () { this.state = CONST.FILE_PROCESSING; var _this = this; // interesting read https://github.com/WebAudio/web-audio-api/issues/1305 this.config.context.decodeAudioData(this.xhrLoader.response, function (audioBuffer) { _this.data = audioBuffer; _this.onProcessComplete(); }, function (e) { // eslint-disable-next-line no-console console.error('Error decoding audio: ' + this.key + ' - ', e.message); _this.onProcessError(); } ); this.config.context = null; } }); AudioFile.create = function (loader, key, urls, config, xhrSettings) { var game = loader.systems.game; var audioConfig = game.config.audio; var deviceAudio = game.device.audio; // url may be inside key, which may be an object if (IsPlainObject(key)) { urls = GetFastValue(key, 'url', []); config = GetFastValue(key, 'config', {}); } var urlConfig = AudioFile.getAudioURL(game, urls); if (!urlConfig) { return null; } // https://developers.google.com/web/updates/2012/02/HTML5-audio-and-the-Web-Audio-API-are-BFFs // var stream = GetFastValue(config, 'stream', false); if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio)) { return new AudioFile(loader, key, urlConfig, xhrSettings, game.sound.context); } else { return new HTML5AudioFile(loader, key, urlConfig, config); } }; AudioFile.getAudioURL = function (game, urls) { if (!Array.isArray(urls)) { urls = [ urls ]; } for (var i = 0; i < urls.length; i++) { var url = GetFastValue(urls[i], 'url', urls[i]); if (url.indexOf('blob:') === 0 || url.indexOf('data:') === 0) { return url; } var audioType = url.match(/\.([a-zA-Z0-9]+)($|\?)/); audioType = GetFastValue(urls[i], 'type', (audioType) ? audioType[1] : '').toLowerCase(); if (game.device.audio[audioType]) { return { url: url, type: audioType }; } } return null; }; /** * Adds an Audio or HTML5Audio file, or array of audio files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.audio('title', [ 'music/Title.ogg', 'music/Title.mp3', 'music/Title.m4a' ]); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * The key must be a unique String. It is used to add the file to the global Audio Cache upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the Audio Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the Audio Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.audio({ * key: 'title', * url: [ 'music/Title.ogg', 'music/Title.mp3', 'music/Title.m4a' ] * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.AudioFileConfig` for more details. * * The URLs can be relative or absolute. If the URLs are relative the `Loader.baseURL` and `Loader.path` values will be prepended to them. * * Due to different browsers supporting different audio file types you should usually provide your audio files in a variety of formats. * ogg, mp3 and m4a are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on * browser support. * * If audio has been disabled in your game, either via the game config, or lack of support from the device, then no audio will be loaded. * * Note: The ability to load this type of file will only be available if the Audio File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#audio * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.AudioFileConfig|Phaser.Loader.FileTypes.AudioFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {(string|string[])} [urls] - The absolute or relative URL to load the audio files from. * @param {any} [config] - An object containing an `instances` property for HTML5Audio. Defaults to 1. * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('audio', function (key, urls, config, xhrSettings) { var game = this.systems.game; var audioConfig = game.config.audio; var deviceAudio = game.device.audio; if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData)) { // Sounds are disabled, so skip loading audio return this; } var audioFile; if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object audioFile = AudioFile.create(this, key[i]); if (audioFile) { this.addFile(audioFile); } } } else { audioFile = AudioFile.create(this, key, urls, config, xhrSettings); if (audioFile) { this.addFile(audioFile); } } return this; }); module.exports = AudioFile; /***/ }), /* 169 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var MergeXHRSettings = __webpack_require__(107); /** * Creates a new XMLHttpRequest (xhr) object based on the given File and XHRSettings * and starts the download of it. It uses the Files own XHRSettings and merges them * with the global XHRSettings object to set the xhr values before download. * * @function Phaser.Loader.XHRLoader * @since 3.0.0 * * @param {Phaser.Loader.File} file - The File to download. * @param {XHRSettingsObject} globalXHRSettings - The global XHRSettings object. * * @return {XMLHttpRequest} The XHR object. */ var XHRLoader = function (file, globalXHRSettings) { var config = MergeXHRSettings(globalXHRSettings, file.xhrSettings); var xhr = new XMLHttpRequest(); xhr.open('GET', file.src, config.async, config.user, config.password); xhr.responseType = file.xhrSettings.responseType; xhr.timeout = config.timeout; if (config.header && config.headerValue) { xhr.setRequestHeader(config.header, config.headerValue); } if (config.requestedWith) { xhr.setRequestHeader('X-Requested-With', config.requestedWith); } if (config.overrideMimeType) { xhr.overrideMimeType(config.overrideMimeType); } // After a successful request, the xhr.response property will contain the requested data as a DOMString, ArrayBuffer, Blob, or Document (depending on what was set for responseType.) xhr.onload = file.onLoad.bind(file, xhr); xhr.onerror = file.onError.bind(file); xhr.onprogress = file.onProgress.bind(file); // This is the only standard method, the ones above are browser additions (maybe not universal?) // xhr.onreadystatechange xhr.send(); return xhr; }; module.exports = XHRLoader; /***/ }), /* 170 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var GetFastValue = __webpack_require__(1); var ProcessKeyCombo = __webpack_require__(372); var ResetKeyCombo = __webpack_require__(370); /** * @callback KeyboardKeydownCallback * * @param {KeyboardEvent} event - The Keyboard Event. */ /** * @typedef {object} KeyComboConfig * * @property {boolean} [resetOnWrongKey=true] - If they press the wrong key do we reset the combo? * @property {number} [maxKeyDelay=0] - The max delay in ms between each key press. Above this the combo is reset. 0 means disabled. * @property {boolean} [resetOnMatch=false] - If previously matched and they press the first key of the combo again, will it reset? * @property {boolean} [deleteOnMatch=false] - If the combo matches, will it delete itself? */ /** * @classdesc * A KeyCombo will listen for a specific string of keys from the Keyboard, and when it receives them * it will emit a `keycombomatch` event from the Keyboard Manager. * * The keys to be listened for can be defined as: * * A string (i.e. 'ATARI') * An array of either integers (key codes) or strings, or a mixture of both * An array of objects (such as Key objects) with a public 'keyCode' property * * For example, to listen for the Konami code (up, up, up, down, down, down, left, left, left, right, right, right) * you could pass the following array of key codes: * * ```javascript * this.input.keyboard.createCombo([ 38, 38, 38, 40, 40, 40, 37, 37, 37, 39, 39, 39 ], { resetOnMatch: true }); * * this.input.keyboard.on('keycombomatch', function (event) { * console.log('Konami Code entered!'); * }); * ``` * * Or, to listen for the user entering the word PHASER: * * ```javascript * this.input.keyboard.createCombo('PHASER'); * ``` * * @class KeyCombo * @memberOf Phaser.Input.Keyboard * @constructor * @since 3.0.0 * * @param {Phaser.Input.Keyboard.KeyboardPlugin} keyboardPlugin - A reference to the Keyboard Plugin. * @param {(string|integer[]|object[])} keys - The keys that comprise this combo. * @param {KeyComboConfig} [config] - A Key Combo configuration object. */ var KeyCombo = new Class({ initialize: function KeyCombo (keyboardPlugin, keys, config) { if (config === undefined) { config = {}; } // Can't have a zero or single length combo (string or array based) if (keys.length < 2) { return false; } /** * A reference to the Keyboard Manager * * @name Phaser.Input.Keyboard.KeyCombo#manager * @type {Phaser.Input.Keyboard.KeyboardPlugin} * @since 3.0.0 */ this.manager = keyboardPlugin; /** * A flag that controls if this Key Combo is actively processing keys or not. * * @name Phaser.Input.Keyboard.KeyCombo#enabled * @type {boolean} * @default true * @since 3.0.0 */ this.enabled = true; /** * An array of the keycodes that comprise this combo. * * @name Phaser.Input.Keyboard.KeyCombo#keyCodes * @type {array} * @default [] * @since 3.0.0 */ this.keyCodes = []; // if 'keys' is a string we need to get the keycode of each character in it for (var i = 0; i < keys.length; i++) { var char = keys[i]; if (typeof char === 'string') { this.keyCodes.push(char.toUpperCase().charCodeAt(0)); } else if (typeof char === 'number') { this.keyCodes.push(char); } else if (char.hasOwnProperty('keyCode')) { this.keyCodes.push(char.keyCode); } } /** * The current keyCode the combo is waiting for. * * @name Phaser.Input.Keyboard.KeyCombo#current * @type {integer} * @since 3.0.0 */ this.current = this.keyCodes[0]; /** * The current index of the key being waited for in the 'keys' string. * * @name Phaser.Input.Keyboard.KeyCombo#index * @type {integer} * @default 0 * @since 3.0.0 */ this.index = 0; /** * The length of this combo (in keycodes) * * @name Phaser.Input.Keyboard.KeyCombo#size * @type {number} * @since 3.0.0 */ this.size = this.keyCodes.length; /** * The time the previous key in the combo was matched. * * @name Phaser.Input.Keyboard.KeyCombo#timeLastMatched * @type {number} * @default 0 * @since 3.0.0 */ this.timeLastMatched = 0; /** * Has this Key Combo been matched yet? * * @name Phaser.Input.Keyboard.KeyCombo#matched * @type {boolean} * @default false * @since 3.0.0 */ this.matched = false; /** * The time the entire combo was matched. * * @name Phaser.Input.Keyboard.KeyCombo#timeMatched * @type {number} * @default 0 * @since 3.0.0 */ this.timeMatched = 0; /** * If they press the wrong key do we reset the combo? * * @name Phaser.Input.Keyboard.KeyCombo#resetOnWrongKey * @type {boolean} * @default 0 * @since 3.0.0 */ this.resetOnWrongKey = GetFastValue(config, 'resetOnWrongKey', true); /** * The max delay in ms between each key press. Above this the combo is reset. 0 means disabled. * * @name Phaser.Input.Keyboard.KeyCombo#maxKeyDelay * @type {integer} * @default 0 * @since 3.0.0 */ this.maxKeyDelay = GetFastValue(config, 'maxKeyDelay', 0); /** * If previously matched and they press the first key of the combo again, will it reset? * * @name Phaser.Input.Keyboard.KeyCombo#resetOnMatch * @type {boolean} * @default false * @since 3.0.0 */ this.resetOnMatch = GetFastValue(config, 'resetOnMatch', false); /** * If the combo matches, will it delete itself? * * @name Phaser.Input.Keyboard.KeyCombo#deleteOnMatch * @type {boolean} * @default false * @since 3.0.0 */ this.deleteOnMatch = GetFastValue(config, 'deleteOnMatch', false); var _this = this; var onKeyDownHandler = function (event) { if (_this.matched || !_this.enabled) { return; } var matched = ProcessKeyCombo(event, _this); if (matched) { _this.manager.emit('keycombomatch', _this, event); if (_this.resetOnMatch) { ResetKeyCombo(_this); } else if (_this.deleteOnMatch) { _this.destroy(); } } }; /** * The internal Key Down handler. * * @name Phaser.Input.Keyboard.KeyCombo#onKeyDown * @private * @type {KeyboardKeydownCallback} * @since 3.0.0 */ this.onKeyDown = onKeyDownHandler; this.manager.on('keydown', onKeyDownHandler); }, /** * How far complete is this combo? A value between 0 and 1. * * @name Phaser.Input.Keyboard.KeyCombo#progress * @type {number} * @readOnly * @since 3.0.0 */ progress: { get: function () { return this.index / this.size; } }, /** * Destroys this Key Combo and all of its references. * * @method Phaser.Input.Keyboard.KeyCombo#destroy * @since 3.0.0 */ destroy: function () { this.enabled = false; this.keyCodes = []; this.manager.off('keydown', this.onKeyDown); this.manager = null; } }); module.exports = KeyCombo; /***/ }), /* 171 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * A generic Key object which can be passed to the Process functions (and so on) * keycode must be an integer * * @class Key * @memberOf Phaser.Input.Keyboard * @constructor * @since 3.0.0 * * @param {integer} keyCode - The keycode of this key. */ var Key = new Class({ initialize: function Key (keyCode) { /** * The keycode of this key. * * @name Phaser.Input.Keyboard.Key#keyCode * @type {integer} * @since 3.0.0 */ this.keyCode = keyCode; /** * The original DOM event. * * @name Phaser.Input.Keyboard.Key#originalEvent * @type {KeyboardEvent} * @since 3.0.0 */ this.originalEvent = undefined; /** * Should this Key prevent event propagation? * * @name Phaser.Input.Keyboard.Key#preventDefault * @type {boolean} * @default true * @since 3.0.0 */ this.preventDefault = true; /** * Can this Key be processed? * * @name Phaser.Input.Keyboard.Key#enabled * @type {boolean} * @default true * @since 3.0.0 */ this.enabled = true; /** * The "down" state of the key. This will remain `true` for as long as the keyboard thinks this key is held down. * * @name Phaser.Input.Keyboard.Key#isDown * @type {boolean} * @default false * @since 3.0.0 */ this.isDown = false; /** * The "up" state of the key. This will remain `true` for as long as the keyboard thinks this key is up. * * @name Phaser.Input.Keyboard.Key#isUp * @type {boolean} * @default true * @since 3.0.0 */ this.isUp = true; /** * The down state of the ALT key, if pressed at the same time as this key. * * @name Phaser.Input.Keyboard.Key#altKey * @type {boolean} * @default false * @since 3.0.0 */ this.altKey = false; /** * The down state of the CTRL key, if pressed at the same time as this key. * * @name Phaser.Input.Keyboard.Key#ctrlKey * @type {boolean} * @default false * @since 3.0.0 */ this.ctrlKey = false; /** * The down state of the SHIFT key, if pressed at the same time as this key. * * @name Phaser.Input.Keyboard.Key#shiftKey * @type {boolean} * @default false * @since 3.0.0 */ this.shiftKey = false; /** * The location of the modifier key. 0 for standard (or unknown), 1 for left, 2 for right, 3 for numpad. * * @name Phaser.Input.Keyboard.Key#location * @type {number} * @default 0 * @since 3.0.0 */ this.location = 0; /** * The timestamp when the key was last pressed down. * * @name Phaser.Input.Keyboard.Key#timeDown * @type {number} * @default 0 * @since 3.0.0 */ this.timeDown = 0; /** * The number of milliseconds this key has been held down for. * If the key is down this value holds the duration of that key press and is constantly updated. * If the key is up it holds the duration of the previous down session. * * @name Phaser.Input.Keyboard.Key#duration * @type {number} * @default 0 * @since 3.0.0 */ this.duration = 0; /** * The timestamp when the key was last released. * * @name Phaser.Input.Keyboard.Key#timeUp * @type {number} * @default 0 * @since 3.0.0 */ this.timeUp = 0; /** * If a key is held down this holds down the number of times the key has 'repeated'. * * @name Phaser.Input.Keyboard.Key#repeats * @type {number} * @default 0 * @since 3.0.0 */ this.repeats = 0; /** * True if the key has just been pressed (NOTE: requires to be reset, see justDown getter) * * @name Phaser.Input.Keyboard.Key#_justDown * @type {boolean} * @private * @default false * @since 3.0.0 */ this._justDown = false; /** * True if the key has just been pressed (NOTE: requires to be reset, see justDown getter) * * @name Phaser.Input.Keyboard.Key#_justUp * @type {boolean} * @private * @default false * @since 3.0.0 */ this._justUp = false; }, /** * Resets this Key object back to its default un-pressed state. * * @method Phaser.Input.Keyboard.Key.reset * @since 3.6.0 * * @return {Phaser.Input.Keyboard.Key} This Key instance. */ reset: function () { this.preventDefault = true; this.enabled = true; this.isDown = false; this.isUp = true; this.altKey = false; this.ctrlKey = false; this.shiftKey = false; this.timeDown = 0; this.duration = 0; this.timeUp = 0; this.repeats = 0; this._justDown = false; this._justUp = false; return this; } }); module.exports = Key; /***/ }), /* 172 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Axis = __webpack_require__(174); var Button = __webpack_require__(173); var Class = __webpack_require__(0); var EventEmitter = __webpack_require__(9); var Vector2 = __webpack_require__(6); /** * @classdesc * A single Gamepad. * * These are created, updated and managed by the Gamepad Plugin. * * @class Gamepad * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Input.Gamepad * @constructor * @since 3.0.0 * * @param {Phaser.Input.Gamepad.GamepadPlugin} manager - A reference to the Gamepad Plugin. * @param {Pad} pad - The Gamepad object, as extracted from GamepadEvent. */ var Gamepad = new Class({ Extends: EventEmitter, initialize: function Gamepad (manager, pad) { EventEmitter.call(this); /** * A reference to the Gamepad Plugin. * * @name Phaser.Input.Gamepad.Gamepad#manager * @type {Phaser.Input.Gamepad.GamepadPlugin} * @since 3.0.0 */ this.manager = manager; /** * A reference to the native Gamepad object that is connected to the browser. * * @name Phaser.Input.Gamepad.Gamepad#pad * @type {any} * @since 3.10.0 */ this.pad = pad; /** * A string containing some information about the controller. * * This is not strictly specified, but in Firefox it will contain three pieces of information * separated by dashes (-): two 4-digit hexadecimal strings containing the USB vendor and * product id of the controller, and the name of the controller as provided by the driver. * In Chrome it will contain the name of the controller as provided by the driver, * followed by vendor and product 4-digit hexadecimal strings. * * @name Phaser.Input.Gamepad.Gamepad#id * @type {string} * @since 3.0.0 */ this.id = pad.id; /** * An integer that is unique for each Gamepad currently connected to the system. * This can be used to distinguish multiple controllers. * Note that disconnecting a device and then connecting a new device may reuse the previous index. * * @name Phaser.Input.Gamepad.Gamepad#index * @type {number} * @since 3.0.0 */ this.index = pad.index; var buttons = []; for (var i = 0; i < pad.buttons.length; i++) { buttons.push(new Button(this, i)); } /** * An array of Gamepad Button objects, corresponding to the different buttons available on the Gamepad. * * @name Phaser.Input.Gamepad.Gamepad#buttons * @type {Phaser.Input.Gamepad.Button[]} * @since 3.0.0 */ this.buttons = buttons; var axes = []; for (i = 0; i < pad.axes.length; i++) { axes.push(new Axis(this, i)); } /** * An array of Gamepad Axis objects, corresponding to the different axes available on the Gamepad, if any. * * @name Phaser.Input.Gamepad.Gamepad#axes * @type {Phaser.Input.Gamepad.Axis[]} * @since 3.0.0 */ this.axes = axes; /** * The Gamepad's Haptic Actuator (Vibration / Rumble support). * This is highly experimental and only set if both present on the device, * and exposed by both the hardware and browser. * * @name Phaser.Input.Gamepad.Gamepad#vibration * @type {GamepadHapticActuator} * @since 3.10.0 */ this.vibration = pad.vibrationActuator; // https://w3c.github.io/gamepad/#remapping var _noButton = { value: 0, pressed: false }; /** * A reference to the Left Button in the Left Cluster. * * @name Phaser.Input.Gamepad.Gamepad#_LCLeft * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._LCLeft = (buttons[14]) ? buttons[14] : _noButton; /** * A reference to the Right Button in the Left Cluster. * * @name Phaser.Input.Gamepad.Gamepad#_LCRight * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._LCRight = (buttons[15]) ? buttons[15] : _noButton; /** * A reference to the Top Button in the Left Cluster. * * @name Phaser.Input.Gamepad.Gamepad#_LCTop * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._LCTop = (buttons[12]) ? buttons[12] : _noButton; /** * A reference to the Bottom Button in the Left Cluster. * * @name Phaser.Input.Gamepad.Gamepad#_LCBottom * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._LCBottom = (buttons[13]) ? buttons[13] : _noButton; /** * A reference to the Left Button in the Right Cluster. * * @name Phaser.Input.Gamepad.Gamepad#_RCLeft * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._RCLeft = (buttons[2]) ? buttons[2] : _noButton; /** * A reference to the Right Button in the Right Cluster. * * @name Phaser.Input.Gamepad.Gamepad#_RCRight * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._RCRight = (buttons[1]) ? buttons[1] : _noButton; /** * A reference to the Top Button in the Right Cluster. * * @name Phaser.Input.Gamepad.Gamepad#_RCTop * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._RCTop = (buttons[3]) ? buttons[3] : _noButton; /** * A reference to the Bottom Button in the Right Cluster. * * @name Phaser.Input.Gamepad.Gamepad#_RCBottom * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._RCBottom = (buttons[0]) ? buttons[0] : _noButton; /** * A reference to the Top Left Front Button (L1 Shoulder Button) * * @name Phaser.Input.Gamepad.Gamepad#_FBLeftTop * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._FBLeftTop = (buttons[4]) ? buttons[4] : _noButton; /** * A reference to the Bottom Left Front Button (L2 Shoulder Button) * * @name Phaser.Input.Gamepad.Gamepad#_FBLeftBottom * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._FBLeftBottom = (buttons[6]) ? buttons[6] : _noButton; /** * A reference to the Top Right Front Button (R1 Shoulder Button) * * @name Phaser.Input.Gamepad.Gamepad#_FBRightTop * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._FBRightTop = (buttons[5]) ? buttons[5] : _noButton; /** * A reference to the Bottom Right Front Button (R2 Shoulder Button) * * @name Phaser.Input.Gamepad.Gamepad#_FBRightBottom * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._FBRightBottom = (buttons[7]) ? buttons[7] : _noButton; var _noAxis = { value: 0 }; /** * A reference to the Horizontal Axis for the Left Stick. * * @name Phaser.Input.Gamepad.Gamepad#_HAxisLeft * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._HAxisLeft = (axes[0]) ? axes[0] : _noAxis; /** * A reference to the Vertical Axis for the Left Stick. * * @name Phaser.Input.Gamepad.Gamepad#_VAxisLeft * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._VAxisLeft = (axes[1]) ? axes[1] : _noAxis; /** * A reference to the Horizontal Axis for the Right Stick. * * @name Phaser.Input.Gamepad.Gamepad#_HAxisRight * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._HAxisRight = (axes[2]) ? axes[2] : _noAxis; /** * A reference to the Vertical Axis for the Right Stick. * * @name Phaser.Input.Gamepad.Gamepad#_VAxisRight * @type {Phaser.Input.Gamepad.Button} * @private * @since 3.10.0 */ this._VAxisRight = (axes[3]) ? axes[3] : _noAxis; /** * A Vector2 containing the most recent values from the Gamepad's left axis stick. * This is updated automatically as part of the Gamepad.update cycle. * The H Axis is mapped to the `Vector2.x` property, and the V Axis to the `Vector2.y` property. * The values are based on the Axis thresholds. * If the Gamepad does not have a left axis stick, the values will always be zero. * * @name Phaser.Input.Gamepad.Gamepad#leftStick * @type {Phaser.Math.Vector2} * @since 3.10.0 */ this.leftStick = new Vector2(); /** * A Vector2 containing the most recent values from the Gamepad's right axis stick. * This is updated automatically as part of the Gamepad.update cycle. * The H Axis is mapped to the `Vector2.x` property, and the V Axis to the `Vector2.y` property. * The values are based on the Axis thresholds. * If the Gamepad does not have a right axis stick, the values will always be zero. * * @name Phaser.Input.Gamepad.Gamepad#rightStick * @type {Phaser.Math.Vector2} * @since 3.10.0 */ this.rightStick = new Vector2(); }, /** * Gets the total number of axis this Gamepad claims to support. * * @method Phaser.Input.Gamepad.Gamepad#getAxisTotal * @since 3.10.0 * * @return {integer} The total number of axes this Gamepad claims to support. */ getAxisTotal: function () { return this.axes.length; }, /** * Gets the value of an axis based on the given index. * The index must be valid within the range of axes supported by this Gamepad. * The return value will be a float between 0 and 1. * * @method Phaser.Input.Gamepad.Gamepad#getAxisValue * @since 3.10.0 * * @param {integer} index - The index of the axes to get the value for. * * @return {number} The value of the axis, between 0 and 1. */ getAxisValue: function (index) { return this.axes[index].getValue(); }, /** * Sets the threshold value of all axis on this Gamepad. * The value is a float between 0 and 1 and is the amount below which the axis is considered as not having been moved. * * @method Phaser.Input.Gamepad.Gamepad#setAxisThreshold * @since 3.10.0 * * @param {number} value - A value between 0 and 1. */ setAxisThreshold: function (value) { for (var i = 0; i < this.axes.length; i++) { this.axes[i].threshold = value; } }, /** * Gets the total number of buttons this Gamepad claims to have. * * @method Phaser.Input.Gamepad.Gamepad#getButtonTotal * @since 3.10.0 * * @return {integer} The total number of buttons this Gamepad claims to have. */ getButtonTotal: function () { return this.buttons.length; }, /** * Gets the value of a button based on the given index. * The index must be valid within the range of buttons supported by this Gamepad. * * The return value will be either 0 or 1 for an analogue button, or a float between 0 and 1 * for a pressure-sensitive digital button, such as the shoulder buttons on a Dual Shock. * * @method Phaser.Input.Gamepad.Gamepad#getButtonValue * @since 3.10.0 * * @param {integer} index - The index of the button to get the value for. * * @return {number} The value of the button, between 0 and 1. */ getButtonValue: function (index) { return this.buttons[index].value; }, /** * Returns if the button is pressed down or not. * The index must be valid within the range of buttons supported by this Gamepad. * * @method Phaser.Input.Gamepad.Gamepad#isButtonDown * @since 3.10.0 * * @param {integer} index - The index of the button to get the value for. * * @return {boolean} `true` if the button is considered as being pressed down, otherwise `false`. */ isButtonDown: function (index) { return this.buttons[index].pressed; }, /** * Internal update handler for this Gamepad. * Called automatically by the Gamepad Manager as part of its update. * * @method Phaser.Input.Gamepad.Gamepad#update * @private * @since 3.0.0 */ update: function (pad) { var i; // Sync the button values var localButtons = this.buttons; var gamepadButtons = pad.buttons; var len = localButtons.length; for (i = 0; i < len; i++) { localButtons[i].update(gamepadButtons[i].value); } // Sync the axis values var localAxes = this.axes; var gamepadAxes = pad.axes; len = localAxes.length; for (i = 0; i < len; i++) { localAxes[i].update(gamepadAxes[i]); } if (len >= 2) { this.leftStick.set(localAxes[0].getValue(), localAxes[1].getValue()); if (len >= 4) { this.rightStick.set(localAxes[2].getValue(), localAxes[3].getValue()); } } }, /** * Destroys this Gamepad instance, its buttons and axes, and releases external references it holds. * * @method Phaser.Input.Gamepad.Gamepad#destroy * @since 3.10.0 */ destroy: function () { this.removeAllListeners(); this.manager = null; this.pad = null; var i; for (i = 0; i < this.buttons.length; i++) { this.buttons[i].destroy(); } for (i = 0; i < this.axes.length; i++) { this.axes[i].destroy(); } this.buttons = []; this.axes = []; }, /** * Is this Gamepad currently connected or not? * * @name Phaser.Input.Gamepad.Gamepad#connected * @type {boolean} * @default true * @since 3.0.0 */ connected: { get: function () { return this.pad.connected; } }, /** * A timestamp containing the most recent time this Gamepad was updated. * * @name Phaser.Input.Gamepad.Gamepad#timestamp * @type {number} * @since 3.0.0 */ timestamp: { get: function () { return this.pad.timestamp; } }, /** * Is the Gamepad's Left button being pressed? * If the Gamepad doesn't have this button it will always return false. * This is the d-pad left button under standard Gamepad mapping. * * @name Phaser.Input.Gamepad.Gamepad#left * @type {boolean} * @since 3.10.0 */ left: { get: function () { return this._LCLeft.pressed; } }, /** * Is the Gamepad's Right button being pressed? * If the Gamepad doesn't have this button it will always return false. * This is the d-pad right button under standard Gamepad mapping. * * @name Phaser.Input.Gamepad.Gamepad#right * @type {boolean} * @since 3.10.0 */ right: { get: function () { return this._LCRight.pressed; } }, /** * Is the Gamepad's Up button being pressed? * If the Gamepad doesn't have this button it will always return false. * This is the d-pad up button under standard Gamepad mapping. * * @name Phaser.Input.Gamepad.Gamepad#up * @type {boolean} * @since 3.10.0 */ up: { get: function () { return this._LCTop.pressed; } }, /** * Is the Gamepad's Down button being pressed? * If the Gamepad doesn't have this button it will always return false. * This is the d-pad down button under standard Gamepad mapping. * * @name Phaser.Input.Gamepad.Gamepad#down * @type {boolean} * @since 3.10.0 */ down: { get: function () { return this._LCBottom.pressed; } }, /** * Is the Gamepad's bottom button in the right button cluster being pressed? * If the Gamepad doesn't have this button it will always return false. * On a Dual Shock controller it's the X button. * On an XBox controller it's the A button. * * @name Phaser.Input.Gamepad.Gamepad#A * @type {boolean} * @since 3.10.0 */ A: { get: function () { return this._RCBottom.pressed; } }, /** * Is the Gamepad's top button in the right button cluster being pressed? * If the Gamepad doesn't have this button it will always return false. * On a Dual Shock controller it's the Triangle button. * On an XBox controller it's the Y button. * * @name Phaser.Input.Gamepad.Gamepad#Y * @type {boolean} * @since 3.10.0 */ Y: { get: function () { return this._RCTop.pressed; } }, /** * Is the Gamepad's left button in the right button cluster being pressed? * If the Gamepad doesn't have this button it will always return false. * On a Dual Shock controller it's the Square button. * On an XBox controller it's the X button. * * @name Phaser.Input.Gamepad.Gamepad#X * @type {boolean} * @since 3.10.0 */ X: { get: function () { return this._RCLeft.pressed; } }, /** * Is the Gamepad's right button in the right button cluster being pressed? * If the Gamepad doesn't have this button it will always return false. * On a Dual Shock controller it's the Circle button. * On an XBox controller it's the B button. * * @name Phaser.Input.Gamepad.Gamepad#B * @type {boolean} * @since 3.10.0 */ B: { get: function () { return this._RCRight.pressed; } }, /** * Returns the value of the Gamepad's top left shoulder button. * If the Gamepad doesn't have this button it will always return zero. * The value is a float between 0 and 1, corresponding to how depressed the button is. * On a Dual Shock controller it's the L1 button. * On an XBox controller it's the LB button. * * @name Phaser.Input.Gamepad.Gamepad#L1 * @type {number} * @since 3.10.0 */ L1: { get: function () { return this._FBLeftTop.value; } }, /** * Returns the value of the Gamepad's bottom left shoulder button. * If the Gamepad doesn't have this button it will always return zero. * The value is a float between 0 and 1, corresponding to how depressed the button is. * On a Dual Shock controller it's the L2 button. * On an XBox controller it's the LT button. * * @name Phaser.Input.Gamepad.Gamepad#L2 * @type {number} * @since 3.10.0 */ L2: { get: function () { return this._FBLeftBottom.value; } }, /** * Returns the value of the Gamepad's top right shoulder button. * If the Gamepad doesn't have this button it will always return zero. * The value is a float between 0 and 1, corresponding to how depressed the button is. * On a Dual Shock controller it's the R1 button. * On an XBox controller it's the RB button. * * @name Phaser.Input.Gamepad.Gamepad#R1 * @type {number} * @since 3.10.0 */ R1: { get: function () { return this._FBRightTop.value; } }, /** * Returns the value of the Gamepad's bottom right shoulder button. * If the Gamepad doesn't have this button it will always return zero. * The value is a float between 0 and 1, corresponding to how depressed the button is. * On a Dual Shock controller it's the R2 button. * On an XBox controller it's the RT button. * * @name Phaser.Input.Gamepad.Gamepad#R2 * @type {number} * @since 3.10.0 */ R2: { get: function () { return this._FBRightBottom.value; } } }); module.exports = Gamepad; /***/ }), /* 173 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * Contains information about a specific button on a Gamepad. * Button objects are created automatically by the Gamepad as they are needed. * * @class Button * @memberOf Phaser.Input.Gamepad * @constructor * @since 3.0.0 * * @param {Phaser.Input.Gamepad.Gamepad} pad - A reference to the Gamepad that this Button belongs to. * @param {integer} index - The index of this Button. */ var Button = new Class({ initialize: function Button (pad, index) { /** * A reference to the Gamepad that this Button belongs to. * * @name Phaser.Input.Gamepad.Button#pad * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.0.0 */ this.pad = pad; /** * An event emitter to use to emit the button events. * * @name Phaser.Input.Gamepad.Button#events * @type {Phaser.Events.EventEmitter} * @since 3.0.0 */ this.events = pad.manager; /** * The index of this Button. * * @name Phaser.Input.Gamepad.Button#index * @type {integer} * @since 3.0.0 */ this.index = index; /** * Between 0 and 1. * * @name Phaser.Input.Gamepad.Button#value * @type {float} * @default 0 * @since 3.0.0 */ this.value = 0; /** * Can be set for analogue buttons to enable a 'pressure' threshold, * before a button is considered as being 'pressed'. * * @name Phaser.Input.Gamepad.Button#threshold * @type {float} * @default 1 * @since 3.0.0 */ this.threshold = 1; /** * Is the Button being pressed down or not? * * @name Phaser.Input.Gamepad.Button#pressed * @type {boolean} * @default false * @since 3.0.0 */ this.pressed = false; }, /** * Internal update handler for this Button. * Called automatically by the Gamepad as part of its update. * * @method Phaser.Input.Gamepad.Button#update * @private * @since 3.0.0 * * @param {number} value - The GamepadButton value. */ update: function (value) { this.value = value; var pad = this.pad; var index = this.index; if (value >= this.threshold) { if (!this.pressed) { this.pressed = true; this.events.emit('down', pad, this, value); this.pad.emit('down', index, value, this); } } else if (this.pressed) { this.pressed = false; this.events.emit('up', pad, this, value); this.pad.emit('up', index, value, this); } }, /** * Destroys this Button instance and releases external references it holds. * * @method Phaser.Input.Gamepad.Button#destroy * @since 3.10.0 */ destroy: function () { this.pad = null; this.events = null; } }); module.exports = Button; /***/ }), /* 174 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * Contains information about a specific Gamepad Axis. * Axis objects are created automatically by the Gamepad as they are needed. * * @class Axis * @memberOf Phaser.Input.Gamepad * @constructor * @since 3.0.0 * * @param {Phaser.Input.Gamepad.Gamepad} pad - A reference to the Gamepad that this Axis belongs to. * @param {integer} index - The index of this Axis. */ var Axis = new Class({ initialize: function Axis (pad, index) { /** * A reference to the Gamepad that this Axis belongs to. * * @name Phaser.Input.Gamepad.Axis#pad * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.0.0 */ this.pad = pad; /** * An event emitter to use to emit the axis events. * * @name Phaser.Input.Gamepad.Axis#events * @type {Phaser.Events.EventEmitter} * @since 3.0.0 */ this.events = pad.events; /** * The index of this Axis. * * @name Phaser.Input.Gamepad.Axis#index * @type {integer} * @since 3.0.0 */ this.index = index; /** * The raw axis value, between -1 and 1 with 0 being dead center. * Use the method `getValue` to get a normalized value with the threshold applied. * * @name Phaser.Input.Gamepad.Axis#value * @type {float} * @default 0 * @since 3.0.0 */ this.value = 0; /** * Movement tolerance threshold below which axis values are ignored in `getValue`. * * @name Phaser.Input.Gamepad.Axis#threshold * @type {float} * @default 0.1 * @since 3.0.0 */ this.threshold = 0.1; }, /** * Internal update handler for this Axis. * Called automatically by the Gamepad as part of its update. * * @method Phaser.Input.Gamepad.Axis#update * @private * @since 3.0.0 * * @param {float} value - The value of the axis movement. */ update: function (value) { this.value = value; }, /** * Applies the `threshold` value to the axis and returns it. * * @method Phaser.Input.Gamepad.Axis#getValue * @since 3.0.0 * * @return {float} The axis value, adjusted for the movement threshold. */ getValue: function () { return (Math.abs(this.value) < this.threshold) ? 0 : this.value; }, /** * Destroys this Axis instance and releases external references it holds. * * @method Phaser.Input.Gamepad.Axis#destroy * @since 3.10.0 */ destroy: function () { this.pad = null; this.events = null; } }); module.exports = Axis; /***/ }), /* 175 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @callback HitAreaCallback * * @param {any} hitArea - The hit area object. * @param {number} x - The translated x coordinate of the hit test event. * @param {number} y - The translated y coordinate of the hit test event. * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that invoked the hit test. * * @return {boolean} `true` if the coordinates fall within the space of the hitArea, otherwise `false`. */ /** * @typedef {object} Phaser.Input.InteractiveObject * * @property {Phaser.GameObjects.GameObject} gameObject - The Game Object to which this Interactive Object is bound. * @property {boolean} enabled - Is this Interactive Object currently enabled for input events? * @property {boolean} draggable - Is this Interactive Object draggable? Enable with `InputPlugin.setDraggable`. * @property {boolean} dropZone - Is this Interactive Object a drag-targets drop zone? Set when the object is created. * @property {(boolean|string)} cursor - Should this Interactive Object change the cursor (via css) when over? (desktop only) * @property {?Phaser.GameObjects.GameObject} target - An optional drop target for a draggable Interactive Object. * @property {Phaser.Cameras.Scene2D.Camera} camera - The most recent Camera to be tested against this Interactive Object. * @property {any} hitArea - The hit area for this Interactive Object. Typically a geometry shape, like a Rectangle or Circle. * @property {HitAreaCallback} hitAreaCallback - The 'contains' check callback that the hit area shape will use for all hit tests. * @property {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. * @property {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. * @property {(0|1|2)} dragState - The current drag state of this Interactive Object. 0 = Not being dragged, 1 = being checked for drag, or 2 = being actively dragged. * @property {number} dragStartX - The x coordinate that the Pointer started dragging this Interactive Object from. * @property {number} dragStartY - The y coordinate that the Pointer started dragging this Interactive Object from. * @property {number} dragX - The x coordinate that this Interactive Object is currently being dragged to. * @property {number} dragY - The y coordinate that this Interactive Object is currently being dragged to. */ /** * Creates a new Interactive Object. * * This is called automatically by the Input Manager when you enable a Game Object for input. * * The resulting Interactive Object is mapped to the Game Object's `input` property. * * @function Phaser.Input.CreateInteractiveObject * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to which this Interactive Object is bound. * @param {any} hitArea - The hit area for this Interactive Object. Typically a geometry shape, like a Rectangle or Circle. * @param {HitAreaCallback} hitAreaCallback - The 'contains' check callback that the hit area shape will use for all hit tests. * * @return {Phaser.Input.InteractiveObject} The new Interactive Object. */ var CreateInteractiveObject = function (gameObject, hitArea, hitAreaCallback) { return { gameObject: gameObject, enabled: true, draggable: false, dropZone: false, cursor: false, target: null, camera: null, hitArea: hitArea, hitAreaCallback: hitAreaCallback, localX: 0, localY: 0, // 0 = Not being dragged // 1 = Being checked for dragging // 2 = Being dragged dragState: 0, dragStartX: 0, dragStartY: 0, dragX: 0, dragY: 0 }; }; module.exports = CreateInteractiveObject; /***/ }), /* 176 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Commands = __webpack_require__(119); var GameObject = __webpack_require__(2); /** * Renders this Game Object with the Canvas Renderer to the given Camera. * The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera. * This method should not be called directly. It is a utility function of the Render module. * * @method Phaser.GameObjects.Graphics#renderCanvas * @since 3.0.0 * @private * * @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer. * @param {Phaser.GameObjects.Graphics} src - The Game Object being rendered in this call. * @param {number} interpolationPercentage - Reserved for future use and custom pipelines. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object. * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested * @param {CanvasRenderingContext2D} [renderTargetCtx] - The target rendering context. * @param {boolean} allowClip - [description] */ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix, renderTargetCtx, allowClip) { if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id))) { return; } var cameraScrollX = camera.scrollX * src.scrollFactorX; var cameraScrollY = camera.scrollY * src.scrollFactorY; var srcX = src.x; var srcY = src.y; var srcScaleX = src.scaleX; var srcScaleY = src.scaleY; var srcRotation = src.rotation; var commandBuffer = src.commandBuffer; var ctx = renderTargetCtx || renderer.currentContext; var lineAlpha = 1.0; var fillAlpha = 1.0; var lineColor = 0; var fillColor = 0; var lineWidth = 1.0; var red = 0; var green = 0; var blue = 0; // Blend Mode if (renderer.currentBlendMode !== src.blendMode) { renderer.currentBlendMode = src.blendMode; ctx.globalCompositeOperation = renderer.blendModes[src.blendMode]; } // Alpha if (renderer.currentAlpha !== src.alpha) { renderer.currentAlpha = src.alpha; ctx.globalAlpha = src.alpha; } // Smoothing if (renderer.currentScaleMode !== src.scaleMode) { renderer.currentScaleMode = src.scaleMode; } ctx.save(); if (parentMatrix) { var matrix = parentMatrix.matrix; ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); } ctx.translate(srcX - cameraScrollX, srcY - cameraScrollY); ctx.rotate(srcRotation); ctx.scale(srcScaleX, srcScaleY); ctx.fillStyle = '#fff'; ctx.globalAlpha = src.alpha; for (var index = 0, length = commandBuffer.length; index < length; ++index) { var commandID = commandBuffer[index]; switch (commandID) { case Commands.ARC: ctx.arc( commandBuffer[index + 1], commandBuffer[index + 2], commandBuffer[index + 3], commandBuffer[index + 4], commandBuffer[index + 5], commandBuffer[index + 6] ); index += 6; break; case Commands.LINE_STYLE: lineWidth = commandBuffer[index + 1]; lineColor = commandBuffer[index + 2]; lineAlpha = commandBuffer[index + 3]; red = ((lineColor & 0xFF0000) >>> 16); green = ((lineColor & 0xFF00) >>> 8); blue = (lineColor & 0xFF); ctx.strokeStyle = 'rgba(' + red + ',' + green + ',' + blue + ',' + lineAlpha + ')'; ctx.lineWidth = lineWidth; index += 3; break; case Commands.FILL_STYLE: fillColor = commandBuffer[index + 1]; fillAlpha = commandBuffer[index + 2]; red = ((fillColor & 0xFF0000) >>> 16); green = ((fillColor & 0xFF00) >>> 8); blue = (fillColor & 0xFF); ctx.fillStyle = 'rgba(' + red + ',' + green + ',' + blue + ',' + fillAlpha + ')'; index += 2; break; case Commands.BEGIN_PATH: ctx.beginPath(); break; case Commands.CLOSE_PATH: ctx.closePath(); break; case Commands.FILL_PATH: if (!allowClip) { ctx.fill(); } break; case Commands.STROKE_PATH: if (!allowClip) { ctx.stroke(); } break; case Commands.FILL_RECT: if (!allowClip) { ctx.fillRect( commandBuffer[index + 1], commandBuffer[index + 2], commandBuffer[index + 3], commandBuffer[index + 4] ); } else { ctx.rect( commandBuffer[index + 1], commandBuffer[index + 2], commandBuffer[index + 3], commandBuffer[index + 4] ); } index += 4; break; case Commands.FILL_TRIANGLE: ctx.beginPath(); ctx.moveTo(commandBuffer[index + 1], commandBuffer[index + 2]); ctx.lineTo(commandBuffer[index + 3], commandBuffer[index + 4]); ctx.lineTo(commandBuffer[index + 5], commandBuffer[index + 6]); ctx.closePath(); if (!allowClip) { ctx.fill(); } index += 6; break; case Commands.STROKE_TRIANGLE: ctx.beginPath(); ctx.moveTo(commandBuffer[index + 1], commandBuffer[index + 2]); ctx.lineTo(commandBuffer[index + 3], commandBuffer[index + 4]); ctx.lineTo(commandBuffer[index + 5], commandBuffer[index + 6]); ctx.closePath(); if (!allowClip) { ctx.stroke(); } index += 6; break; case Commands.LINE_TO: ctx.lineTo( commandBuffer[index + 1], commandBuffer[index + 2] ); index += 2; break; case Commands.MOVE_TO: ctx.moveTo( commandBuffer[index + 1], commandBuffer[index + 2] ); index += 2; break; case Commands.LINE_FX_TO: ctx.lineTo( commandBuffer[index + 1], commandBuffer[index + 2] ); index += 5; break; case Commands.MOVE_FX_TO: ctx.moveTo( commandBuffer[index + 1], commandBuffer[index + 2] ); index += 5; break; case Commands.SAVE: ctx.save(); break; case Commands.RESTORE: ctx.restore(); break; case Commands.TRANSLATE: ctx.translate( commandBuffer[index + 1], commandBuffer[index + 2] ); index += 2; break; case Commands.SCALE: ctx.scale( commandBuffer[index + 1], commandBuffer[index + 2] ); index += 2; break; case Commands.ROTATE: ctx.rotate( commandBuffer[index + 1] ); index += 1; break; default: // console.error('Phaser: Invalid Graphics Command ID ' + commandID); break; } } ctx.restore(); }; module.exports = GraphicsCanvasRenderer; /***/ }), /* 177 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Returns the circumference of the given Ellipse. * * @function Phaser.Geom.Ellipse.Circumference * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to get the circumference of. * * @return {number} The circumference of th Ellipse. */ var Circumference = function (ellipse) { var rx = ellipse.width / 2; var ry = ellipse.height / 2; var h = Math.pow((rx - ry), 2) / Math.pow((rx + ry), 2); return (Math.PI * (rx + ry)) * (1 + ((3 * h) / (10 + Math.sqrt(4 - (3 * h))))); }; module.exports = Circumference; /***/ }), /* 178 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Circumference = __webpack_require__(177); var CircumferencePoint = __webpack_require__(113); var FromPercent = __webpack_require__(65); var MATH_CONST = __webpack_require__(16); /** * Returns an array of Point objects containing the coordinates of the points around the circumference of the Ellipse, * based on the given quantity or stepRate values. * * @function Phaser.Geom.Ellipse.GetPoints * @since 3.0.0 * * @generic {Phaser.Geom.Point[]} O - [out,$return] * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to get the points from. * @param {integer} quantity - The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. * @param {number} [stepRate] - Sets the quantity by getting the circumference of the ellipse and dividing it by the stepRate. * @param {(array|Phaser.Geom.Point[])} [out] - An array to insert the points in to. If not provided a new array will be created. * * @return {(array|Phaser.Geom.Point[])} An array of Point objects pertaining to the points around the circumference of the ellipse. */ var GetPoints = function (ellipse, quantity, stepRate, out) { if (out === undefined) { out = []; } // If quantity is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead. if (!quantity) { quantity = Circumference(ellipse) / stepRate; } for (var i = 0; i < quantity; i++) { var angle = FromPercent(i / quantity, 0, MATH_CONST.PI2); out.push(CircumferencePoint(ellipse, angle)); } return out; }; module.exports = GetPoints; /***/ }), /* 179 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CircumferencePoint = __webpack_require__(113); var FromPercent = __webpack_require__(65); var MATH_CONST = __webpack_require__(16); var Point = __webpack_require__(5); /** * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point * at 180 degrees around the circle. * * @function Phaser.Geom.Ellipse.GetPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to get the circumference point on. * @param {float} position - A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the ellipse. * @param {(Phaser.Geom.Point|object)} [out] - An object to store the return values in. If not given a Point object will be created. * * @return {(Phaser.Geom.Point|object)} A Point, or point-like object, containing the coordinates of the point around the ellipse. */ var GetPoint = function (ellipse, position, out) { if (out === undefined) { out = new Point(); } var angle = FromPercent(position, 0, MATH_CONST.PI2); return CircumferencePoint(ellipse, angle, out); }; module.exports = GetPoint; /***/ }), /* 180 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // This is from the quickselect npm package: https://www.npmjs.com/package/quickselect // Coded by https://www.npmjs.com/~mourner (Vladimir Agafonkin) // https://en.wikipedia.org/wiki/Floyd%E2%80%93Rivest_algorithm // Floyd-Rivest selection algorithm: // Rearrange items so that all items in the [left, k] range are smaller than all items in (k, right]; // The k-th element will have the (k - left + 1)th smallest value in [left, right] /** * [description] * * @function Phaser.Utils.Array.QuickSelect * @since 3.0.0 * * @param {array} arr - [description] * @param {number} k - [description] * @param {number} left - [description] * @param {number} right - [description] * @param {function} compare - [description] */ var QuickSelect = function (arr, k, left, right, compare) { left = left || 0; right = right || (arr.length - 1); compare = compare || defaultCompare; while (right > left) { if (right - left > 600) { var n = right - left + 1; var m = k - left + 1; var z = Math.log(n); var s = 0.5 * Math.exp(2 * z / 3); var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1); var newLeft = Math.max(left, Math.floor(k - m * s / n + sd)); var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd)); QuickSelect(arr, k, newLeft, newRight, compare); } var t = arr[k]; var i = left; var j = right; swap(arr, left, k); if (compare(arr[right], t) > 0) { swap(arr, left, right); } while (i < j) { swap(arr, i, j); i++; j--; while (compare(arr[i], t) < 0) { i++; } while (compare(arr[j], t) > 0) { j--; } } if (compare(arr[left], t) === 0) { swap(arr, left, j); } else { j++; swap(arr, j, right); } if (j <= k) { left = j + 1; } if (k <= j) { right = j - 1; } } }; function swap (arr, i, j) { var tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } function defaultCompare (a, b) { return a < b ? -1 : a > b ? 1 : 0; } module.exports = QuickSelect; /***/ }), /* 181 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // Transposes the elements of the given matrix (array of arrays). // The transpose of a matrix is a new matrix whose rows are the columns of the original. /** * [description] * * @function Phaser.Utils.Array.Matrix.TransposeMatrix * @since 3.0.0 * * @param {array} array - The array matrix to transpose. * * @return {array} A new array matrix which is a transposed version of the given array. */ var TransposeMatrix = function (array) { var sourceRowCount = array.length; var sourceColCount = array[0].length; var result = new Array(sourceColCount); for (var i = 0; i < sourceColCount; i++) { result[i] = new Array(sourceRowCount); for (var j = sourceRowCount - 1; j > -1; j--) { result[i][j] = array[j][i]; } } return result; }; module.exports = TransposeMatrix; /***/ }), /* 182 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Textures.Parsers */ module.exports = { AtlasXML: __webpack_require__(514), Canvas: __webpack_require__(513), Image: __webpack_require__(512), JSONArray: __webpack_require__(511), JSONHash: __webpack_require__(510), SpriteSheet: __webpack_require__(509), SpriteSheetFromAtlas: __webpack_require__(508), UnityYAML: __webpack_require__(507) }; /***/ }), /* 183 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CanvasPool = __webpack_require__(22); var Class = __webpack_require__(0); var IsSizePowerOfTwo = __webpack_require__(85); var ScaleModes = __webpack_require__(59); /** * @classdesc * A Texture Source is the encapsulation of the actual source data for a Texture. * This is typically an Image Element, loaded from the file system or network, or a Canvas Element. * * A Texture can contain multiple Texture Sources, which only happens when a multi-atlas is loaded. * * @class TextureSource * @memberOf Phaser.Textures * @constructor * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture this TextureSource belongs to. * @param {(HTMLImageElement|HTMLCanvasElement)} source - The source image data. * @param {integer} [width] - Optional width of the source image. If not given it's derived from the source itself. * @param {integer} [height] - Optional height of the source image. If not given it's derived from the source itself. */ var TextureSource = new Class({ initialize: function TextureSource (texture, source, width, height) { var game = texture.manager.game; /** * The Texture this TextureSource belongs to. * * @name Phaser.Textures.TextureSource#renderer * @type {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} * @since 3.7.0 */ this.renderer = game.renderer; /** * The Texture this TextureSource belongs to. * * @name Phaser.Textures.TextureSource#texture * @type {string} * @since 3.0.0 */ this.texture = texture; /** * The source image data. This is either an Image Element, or a Canvas Element. * * @name Phaser.Textures.TextureSource#image * @type {(HTMLImageElement|HTMLCanvasElement)} * @since 3.0.0 */ this.image = source; /** * Currently un-used. * * @name Phaser.Textures.TextureSource#compressionAlgorithm * @type {integer} * @default null * @since 3.0.0 */ this.compressionAlgorithm = null; /** * The resolution of the source image. * * @name Phaser.Textures.TextureSource#resolution * @type {number} * @default 1 * @since 3.0.0 */ this.resolution = 1; /** * The width of the source image. If not specified in the constructor it will check * the `naturalWidth` and then `width` properties of the source image. * * @name Phaser.Textures.TextureSource#width * @type {integer} * @since 3.0.0 */ this.width = width || source.naturalWidth || source.width || 0; /** * The height of the source image. If not specified in the constructor it will check * the `naturalHeight` and then `height` properties of the source image. * * @name Phaser.Textures.TextureSource#height * @type {integer} * @since 3.0.0 */ this.height = height || source.naturalHeight || source.height || 0; /** * The Scale Mode the image will use when rendering. * Either Linear or Nearest. * * @name Phaser.Textures.TextureSource#scaleMode * @type {number} * @since 3.0.0 */ this.scaleMode = ScaleModes.DEFAULT; /** * Is the source image a Canvas Element? * * @name Phaser.Textures.TextureSource#isCanvas * @type {boolean} * @since 3.0.0 */ this.isCanvas = (source instanceof HTMLCanvasElement); /** * Are the source image dimensions a power of two? * * @name Phaser.Textures.TextureSource#isPowerOf2 * @type {boolean} * @since 3.0.0 */ this.isPowerOf2 = IsSizePowerOfTwo(this.width, this.height); /** * The WebGL Texture of the source image. * * @name Phaser.Textures.TextureSource#glTexture * @type {?WebGLTexture} * @default null * @since 3.0.0 */ this.glTexture = null; this.init(game); }, /** * Creates a WebGL Texture, if required, and sets the Texture filter mode. * * @method Phaser.Textures.TextureSource#init * @since 3.0.0 * * @param {Phaser.Game} game - A reference to the Phaser Game instance. */ init: function (game) { if (this.renderer && this.renderer.gl) { if (this.isCanvas) { this.glTexture = this.renderer.canvasToTexture(this.image); } else { this.glTexture = this.renderer.createTextureFromSource(this.image, this.width, this.height, this.scaleMode); } } if (game.config.pixelArt) { this.setFilter(1); } }, /** * Sets the Filter Mode for this Texture. * * The mode can be either Linear, the default, or Nearest. * * For pixel-art you should use Nearest. * * @method Phaser.Textures.TextureSource#setFilter * @since 3.0.0 * * @param {Phaser.Textures.FilterMode} filterMode - The Filter Mode. */ setFilter: function (filterMode) { if (this.renderer.gl) { this.renderer.setTextureFilter(this.glTexture, filterMode); } }, /** * If this TextureSource is backed by a Canvas and is running under WebGL, * it updates the WebGLTexture using the canvas data. * * @method Phaser.Textures.TextureSource#update * @since 3.7.0 */ update: function () { if (this.renderer.gl && this.isCanvas) { this.renderer.canvasToTexture(this.image, this.glTexture); } }, /** * Destroys this Texture Source and nulls the references. * * @method Phaser.Textures.TextureSource#destroy * @since 3.0.0 */ destroy: function () { if (this.glTexture) { this.renderer.deleteTexture(this.glTexture); } if (this.isCanvas) { CanvasPool.remove(this.image); } this.renderer = null; this.texture = null; this.image = null; } }); module.exports = TextureSource; /***/ }), /* 184 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CanvasPool = __webpack_require__(22); var CanvasTexture = __webpack_require__(515); var Class = __webpack_require__(0); var Color = __webpack_require__(30); var CONST = __webpack_require__(20); var EventEmitter = __webpack_require__(9); var GenerateTexture = __webpack_require__(276); var GetValue = __webpack_require__(4); var Parser = __webpack_require__(182); var Texture = __webpack_require__(117); /** * @callback EachTextureCallback * * @param {Phaser.Textures.Texture} texture - [description] * @param {...*} [args] - Additional arguments that will be passed to the callback, after the child. */ /** * @classdesc * Textures are managed by the global TextureManager. This is a singleton class that is * responsible for creating and delivering Textures and their corresponding Frames to Game Objects. * * Sprites and other Game Objects get the texture data they need from the TextureManager. * * Access it via `scene.textures`. * * @class TextureManager * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Textures * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - [description] */ var TextureManager = new Class({ Extends: EventEmitter, initialize: function TextureManager (game) { EventEmitter.call(this); /** * [description] * * @name Phaser.Textures.TextureManager#game * @type {Phaser.Game} * @since 3.0.0 */ this.game = game; /** * [description] * * @name Phaser.Textures.TextureManager#name * @type {string} * @since 3.0.0 */ this.name = 'TextureManager'; /** * [description] * * @name Phaser.Textures.TextureManager#list * @type {object} * @default {} * @since 3.0.0 */ this.list = {}; /** * [description] * * @name Phaser.Textures.TextureManager#_tempCanvas * @type {HTMLCanvasElement} * @private * @since 3.0.0 */ this._tempCanvas = CanvasPool.create2D(this, 1, 1); /** * [description] * * @name Phaser.Textures.TextureManager#_tempContext * @type {CanvasRenderingContext2D} * @private * @since 3.0.0 */ this._tempContext = this._tempCanvas.getContext('2d'); /** * [description] * * @name Phaser.Textures.TextureManager#_pending * @type {integer} * @private * @default 0 * @since 3.0.0 */ this._pending = 0; game.events.once('boot', this.boot, this); }, /** * [description] * * @method Phaser.Textures.TextureManager#boot * @since 3.0.0 */ boot: function () { this._pending = 2; this.on('onload', this.updatePending, this); this.on('onerror', this.updatePending, this); this.addBase64('__DEFAULT', this.game.config.defaultImage); this.addBase64('__MISSING', this.game.config.missingImage); this.game.events.once('destroy', this.destroy, this); }, /** * [description] * * @method Phaser.Textures.TextureManager#updatePending * @since 3.0.0 */ updatePending: function () { this._pending--; if (this._pending === 0) { this.off('onload'); this.off('onerror'); this.game.events.emit('ready'); } }, /** * Checks the given texture key and throws a console.warn if the key is already in use, then returns false. * If you wish to avoid the console.warn then use `TextureManager.exists` instead. * * @method Phaser.Textures.TextureManager#checkKey * @since 3.7.0 * * @param {string} key - The texture key to check. * * @return {boolean} `true` if it's safe to use the texture key, otherwise `false`. */ checkKey: function (key) { if (this.exists(key)) { // eslint-disable-next-line no-console console.error('Texture key already in use: ' + key); return false; } return true; }, /** * Removes a Texture from the Texture Manager and destroys it. This will immediately * clear all references to it from the Texture Manager, and if it has one, destroy its * WebGLTexture. This will emit a `removetexture` event. * * Note: If you have any Game Objects still using this texture they will start throwing * errors the next time they try to render. Make sure that removing the texture is the final * step when clearing down to avoid this. * * @method Phaser.Textures.TextureManager#remove * @since 3.7.0 * * @param {(string|Phaser.Textures.Texture)} key - The key of the Texture to remove, or a reference to it. * * @return {Phaser.Textures.TextureManager} The Texture Manager. */ remove: function (key) { if (typeof key === 'string') { if (this.exists(key)) { key = this.get(key); } else { console.warn('No texture found matching key: ' + key); return this; } } // By this point key should be a Texture, if not, the following fails anyway if (this.list.hasOwnProperty(key.key)) { delete this.list[key.key]; key.destroy(); this.emit('removetexture', key.key); } return this; }, /** * Adds a new Texture to the Texture Manager created from the given Base64 encoded data. * * @method Phaser.Textures.TextureManager#addBase64 * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {*} data - The Base64 encoded data. */ addBase64: function (key, data) { if (this.checkKey(key)) { var _this = this; var image = new Image(); image.onerror = function () { _this.emit('onerror', key); }; image.onload = function () { var texture = _this.create(key, image); Parser.Image(texture, 0); _this.emit('addtexture', key, texture); _this.emit('onload', key, texture); }; image.src = data; } }, /** * Adds a new Texture to the Texture Manager created from the given Image element. * * @method Phaser.Textures.TextureManager#addImage * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {HTMLImageElement} source - The source Image element. * @param {HTMLImageElement} [dataSource] - An optional data Image element. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ addImage: function (key, source, dataSource) { var texture = null; if (this.checkKey(key)) { texture = this.create(key, source); Parser.Image(texture, 0); if (dataSource) { texture.setDataSource(dataSource); } this.emit('addtexture', key, texture); } return texture; }, /** * Creates a new Texture using the given config values. * Generated textures consist of a Canvas element to which the texture data is drawn. * See the Phaser.Create function for the more direct way to create textures. * * @method Phaser.Textures.TextureManager#generate * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {object} config - [description] * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ generate: function (key, config) { if (this.checkKey(key)) { var canvas = CanvasPool.create(this, 1, 1); config.canvas = canvas; GenerateTexture(config); return this.addCanvas(key, canvas); } else { return null; } }, /** * Creates a new Texture using a blank Canvas element of the size given. * * Canvas elements are automatically pooled and calling this method will * extract a free canvas from the CanvasPool, or create one if none are available. * * @method Phaser.Textures.TextureManager#createCanvas * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {integer} [width=256]- The width of the Canvas element. * @param {integer} [height=256] - The height of the Canvas element. * * @return {?Phaser.Textures.CanvasTexture} The Canvas Texture that was created, or `null` if the key is already in use. */ createCanvas: function (key, width, height) { if (width === undefined) { width = 256; } if (height === undefined) { height = 256; } if (this.checkKey(key)) { var canvas = CanvasPool.create(this, width, height, CONST.CANVAS, true); return this.addCanvas(key, canvas); } return null; }, /** * Creates a new Canvas Texture object from an existing Canvas element and adds * it to this Texture Manager. * * @method Phaser.Textures.TextureManager#addCanvas * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {HTMLCanvasElement} source - The Canvas element to form the base of the new Texture. * * @return {?Phaser.Textures.CanvasTexture} The Canvas Texture that was created, or `null` if the key is already in use. */ addCanvas: function (key, source) { var texture = null; if (this.checkKey(key)) { texture = new CanvasTexture(this, key, source, source.width, source.height); this.list[key] = texture; this.emit('addtexture', key, texture); } return texture; }, /** * Adds a new Texture Atlas to this Texture Manager. * It can accept either JSON Array or JSON Hash formats, as exported by Texture Packer and similar software. * * @method Phaser.Textures.TextureManager#addAtlas * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {HTMLImageElement} source - The source Image element. * @param {object} data - The Texture Atlas data. * @param {HTMLImageElement} [dataSource] - An optional data Image element. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ addAtlas: function (key, source, data, dataSource) { // New Texture Packer format? if (Array.isArray(data.textures) || Array.isArray(data.frames)) { return this.addAtlasJSONArray(key, source, data, dataSource); } else { return this.addAtlasJSONHash(key, source, data, dataSource); } }, /** * Adds a Texture Atlas to this Texture Manager. * The frame data of the atlas must be stored in an Array within the JSON. * This is known as a JSON Array in software such as Texture Packer. * * @method Phaser.Textures.TextureManager#addAtlasJSONArray * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {(HTMLImageElement|HTMLImageElement[])} source - The source Image element/s. * @param {(object|object[])} data - The Texture Atlas data/s. * @param {HTMLImageElement} [dataSource] - An optional data Image element. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ addAtlasJSONArray: function (key, source, data, dataSource) { var texture = null; if (this.checkKey(key)) { texture = this.create(key, source); // Multi-Atlas? if (Array.isArray(data)) { var singleAtlasFile = (data.length === 1); // multi-pack with one atlas file for all images // !! Assumes the textures are in the same order in the source array as in the json data !! for (var i = 0; i < texture.source.length; i++) { var atlasData = singleAtlasFile ? data[0] : data[i]; Parser.JSONArray(texture, i, atlasData); } } else { Parser.JSONArray(texture, 0, data); } if (dataSource) { texture.setDataSource(dataSource); } this.emit('addtexture', key, texture); } return texture; }, /** * Adds a Texture Atlas to this Texture Manager. * The frame data of the atlas must be stored in an Object within the JSON. * This is known as a JSON Hash in software such as Texture Packer. * * @method Phaser.Textures.TextureManager#addAtlasJSONHash * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {HTMLImageElement} source - The source Image element. * @param {object} data - The Texture Atlas data. * @param {HTMLImageElement} [dataSource] - An optional data Image element. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ addAtlasJSONHash: function (key, source, data, dataSource) { var texture = null; if (this.checkKey(key)) { texture = this.create(key, source); if (Array.isArray(data)) { for (var i = 0; i < data.length; i++) { Parser.JSONHash(texture, i, data[i]); } } else { Parser.JSONHash(texture, 0, data); } if (dataSource) { texture.setDataSource(dataSource); } this.emit('addtexture', key, texture); } return texture; }, /** * Adds a Texture Atlas to this Texture Manager, where the atlas data is given * in the XML format. * * @method Phaser.Textures.TextureManager#addAtlasXML * @since 3.7.0 * * @param {string} key - The unique string-based key of the Texture. * @param {HTMLImageElement} source - The source Image element. * @param {object} data - The Texture Atlas XML data. * @param {HTMLImageElement} [dataSource] - An optional data Image element. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ addAtlasXML: function (key, source, data, dataSource) { var texture = null; if (this.checkKey(key)) { texture = this.create(key, source); Parser.AtlasXML(texture, 0, data); if (dataSource) { texture.setDataSource(dataSource); } this.emit('addtexture', key, texture); } return texture; }, /** * Adds a Unity Texture Atlas to this Texture Manager. * The data must be in the form of a Unity YAML file. * * @method Phaser.Textures.TextureManager#addUnityAtlas * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {HTMLImageElement} source - The source Image element. * @param {object} data - The Texture Atlas data. * @param {HTMLImageElement} [dataSource] - An optional data Image element. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ addUnityAtlas: function (key, source, data, dataSource) { var texture = null; if (this.checkKey(key)) { texture = this.create(key, source); Parser.UnityYAML(texture, 0, data); if (dataSource) { texture.setDataSource(dataSource); } this.emit('addtexture', key, texture); } return texture; }, /** * @typedef {object} SpriteSheetConfig * * @property {integer} frameWidth - The fixed width of each frame. * @property {integer} [frameHeight] - The fixed height of each frame. If not set it will use the frameWidth as the height. * @property {integer} [startFrame=0] - Skip a number of frames. Useful when there are multiple sprite sheets in one Texture. * @property {integer} [endFrame=-1] - The total number of frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames". * @property {integer} [margin=0] - If the frames have been drawn with a margin, specify the amount here. * @property {integer} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. */ /** * Adds a Sprite Sheet to this Texture Manager. * * In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact * same size and cannot be trimmed or rotated. * * @method Phaser.Textures.TextureManager#addSpriteSheet * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {HTMLImageElement} source - The source Image element. * @param {SpriteSheetConfig} config - The configuration object for this Sprite Sheet. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ addSpriteSheet: function (key, source, config) { var texture = null; if (this.checkKey(key)) { texture = this.create(key, source); var width = texture.source[0].width; var height = texture.source[0].height; Parser.SpriteSheet(texture, 0, 0, 0, width, height, config); this.emit('addtexture', key, texture); } return texture; }, /** * @typedef {object} SpriteSheetFromAtlasConfig * * @property {string} atlas - The key of the Texture Atlas in which this Sprite Sheet can be found. * @property {string} frame - The key of the Texture Atlas Frame in which this Sprite Sheet can be found. * @property {integer} frameWidth - The fixed width of each frame. * @property {integer} [frameHeight] - The fixed height of each frame. If not set it will use the frameWidth as the height. * @property {integer} [startFrame=0] - Skip a number of frames. Useful when there are multiple sprite sheets in one Texture. * @property {integer} [endFrame=-1] - The total number of frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames". * @property {integer} [margin=0] - If the frames have been drawn with a margin, specify the amount here. * @property {integer} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. */ /** * Adds a Sprite Sheet to this Texture Manager, where the Sprite Sheet exists as a Frame within a Texture Atlas. * * In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact * same size and cannot be trimmed or rotated. * * @method Phaser.Textures.TextureManager#addSpriteSheetFromAtlas * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {SpriteSheetFromAtlasConfig} config - The configuration object for this Sprite Sheet. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ addSpriteSheetFromAtlas: function (key, config) { if (!this.checkKey(key)) { return null; } var atlasKey = GetValue(config, 'atlas', null); var atlasFrame = GetValue(config, 'frame', null); if (!atlasKey || !atlasFrame) { return; } var atlas = this.get(atlasKey); var sheet = atlas.get(atlasFrame); if (sheet) { var texture = this.create(key, sheet.source.image); if (sheet.trimmed) { // If trimmed we need to help the parser adjust Parser.SpriteSheetFromAtlas(texture, sheet, config); } else { Parser.SpriteSheet(texture, 0, sheet.cutX, sheet.cutY, sheet.cutWidth, sheet.cutHeight, config); } this.emit('addtexture', key, texture); return texture; } }, /** * Creates a new Texture using the given source and dimensions. * * @method Phaser.Textures.TextureManager#create * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {HTMLImageElement} source - The source Image element. * @param {integer} width - The width of the Texture. * @param {integer} height - The height of the Texture. * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ create: function (key, source, width, height) { var texture = null; if (this.checkKey(key)) { texture = new Texture(this, key, source, width, height); this.list[key] = texture; } return texture; }, /** * Checks the given key to see if a Texture using it exists within this Texture Manager. * * @method Phaser.Textures.TextureManager#exists * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * * @return {boolean} Returns `true` if a Texture matching the given key exists in this Texture Manager. */ exists: function (key) { return (this.list.hasOwnProperty(key)); }, /** * Returns a Texture from the Texture Manager that matches the given key. * If the key is undefined it will return the `__DEFAULT` Texture. * If the key is given, but not found, it will return the `__MISSING` Texture. * * @method Phaser.Textures.TextureManager#get * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * * @return {Phaser.Textures.Texture} The Texture that was created. */ get: function (key) { if (key === undefined) { key = '__DEFAULT'; } if (this.list[key]) { return this.list[key]; } else { return this.list['__MISSING']; } }, /** * Takes a Texture key and Frame name and returns a clone of that Frame if found. * * @method Phaser.Textures.TextureManager#cloneFrame * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {(string|integer)} frame - The string or index of the Frame to be cloned. * * @return {Phaser.Textures.Frame} A Clone of the given Frame. */ cloneFrame: function (key, frame) { if (this.list[key]) { return this.list[key].get(frame).clone(); } }, /** * Takes a Texture key and Frame name and returns a reference to that Frame, if found. * * @method Phaser.Textures.TextureManager#getFrame * @since 3.0.0 * * @param {string} key - The unique string-based key of the Texture. * @param {(string|integer)} frame - The string or index of the Frame. * * @return {Phaser.Textures.Frame} A Texture Frame object. */ getFrame: function (key, frame) { if (this.list[key]) { return this.list[key].get(frame); } }, /** * Returns an array with all of the keys of all Textures in this Texture Manager. * The output array will exclude the `__DEFAULT` and `__MISSING` keys. * * @method Phaser.Textures.TextureManager#getTextureKeys * @since 3.0.0 * * @return {string[]} An array containing all of the Texture keys stored in this Texture Manager. */ getTextureKeys: function () { var output = []; for (var key in this.list) { if (key !== '__DEFAULT' && key !== '__MISSING') { output.push(key); } } return output; }, /** * Given a Texture and an `x` and `y` coordinate this method will return a new * Color object that has been populated with the color and alpha values of the pixel * at that location in the Texture. * * @method Phaser.Textures.TextureManager#getPixel * @since 3.0.0 * * @param {integer} x - The x coordinate of the pixel within the Texture. * @param {integer} y - The y coordinate of the pixel within the Texture. * @param {string} key - The unique string-based key of the Texture. * @param {(string|integer)} frame - The string or index of the Frame. * * @return {?Phaser.Display.Color} A Color object populated with the color values of the requested pixel, * or `null` if the coordinates were out of bounds. */ getPixel: function (x, y, key, frame) { var textureFrame = this.getFrame(key, frame); if (textureFrame) { var source = textureFrame.source.image; if (x >= 0 && x <= source.width && y >= 0 && y <= source.height) { x += textureFrame.cutX; y += textureFrame.cutY; // if (textureFrame.trimmed) // { // x -= this.sprite.texture.trim.x; // y -= this.sprite.texture.trim.y; // } var context = this._tempContext; context.clearRect(0, 0, 1, 1); context.drawImage(source, x, y, 1, 1, 0, 0, 1, 1); var rgb = context.getImageData(0, 0, 1, 1); return new Color(rgb.data[0], rgb.data[1], rgb.data[2], rgb.data[3]); } } return null; }, /** * Given a Texture and an `x` and `y` coordinate this method will return a value between 0 and 255 * corresponding to the alpha value of the pixel at that location in the Texture. If the coordinate * is out of bounds it will return null. * * @method Phaser.Textures.TextureManager#getPixelAlpha * @since 3.10.0 * * @param {integer} x - The x coordinate of the pixel within the Texture. * @param {integer} y - The y coordinate of the pixel within the Texture. * @param {string} key - The unique string-based key of the Texture. * @param {(string|integer)} frame - The string or index of the Frame. * * @return {integer} A value between 0 and 255, or `null` if the coordinates were out of bounds. */ getPixelAlpha: function (x, y, key, frame) { var textureFrame = this.getFrame(key, frame); if (textureFrame) { var source = textureFrame.source.image; if (x >= 0 && x <= source.width && y >= 0 && y <= source.height) { x += textureFrame.cutX; y += textureFrame.cutY; var context = this._tempContext; context.clearRect(0, 0, 1, 1); context.drawImage(source, x, y, 1, 1, 0, 0, 1, 1); var rgb = context.getImageData(0, 0, 1, 1); return rgb.data[3]; } } return null; }, /** * Sets the given Game Objects `texture` and `frame` properties so that it uses * the Texture and Frame specified in the `key` and `frame` arguments to this method. * * @method Phaser.Textures.TextureManager#setTexture * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - [description] * @param {string} key - The unique string-based key of the Texture. * @param {(string|integer)} frame - The string or index of the Frame. * * @return {Phaser.GameObjects.GameObject} The Game Object the texture was set on. */ setTexture: function (gameObject, key, frame) { if (this.list[key]) { gameObject.texture = this.list[key]; gameObject.frame = gameObject.texture.get(frame); } return gameObject; }, /** * Passes all Textures to the given callback. * * @method Phaser.Textures.TextureManager#each * @since 3.0.0 * * @param {EachTextureCallback} callback - The callback function to be sent the Textures. * @param {object} scope - The value to use as `this` when executing the callback. * @param {...*} [args] - Additional arguments that will be passed to the callback, after the child. */ each: function (callback, scope) { var args = [ null ]; for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); } for (var texture in this.list) { args[0] = this.list[texture]; callback.apply(scope, args); } }, /** * Destroys the Texture Manager and all Textures stored within it. * * @method Phaser.Textures.TextureManager#destroy * @since 3.0.0 */ destroy: function () { for (var texture in this.list) { this.list[texture].destroy(); } this.list = {}; this.game = null; CanvasPool.remove(this._tempCanvas); } }); module.exports = TextureManager; /***/ }), /* 185 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BaseSound = __webpack_require__(78); var Class = __webpack_require__(0); /** * @classdesc * Web Audio API implementation of the sound. * * @class WebAudioSound * @extends Phaser.Sound.BaseSound * @memberOf Phaser.Sound * @constructor * @since 3.0.0 * * @param {Phaser.Sound.WebAudioSoundManager} manager - Reference to the current sound manager instance. * @param {string} key - Asset key for the sound. * @param {SoundConfig} [config={}] - An optional config object containing default sound settings. */ var WebAudioSound = new Class({ Extends: BaseSound, initialize: function WebAudioSound (manager, key, config) { if (config === undefined) { config = {}; } /** * Audio buffer containing decoded data of the audio asset to be played. * * @name Phaser.Sound.WebAudioSound#audioBuffer * @type {AudioBuffer} * @private * @since 3.0.0 */ this.audioBuffer = manager.game.cache.audio.get(key); if (!this.audioBuffer) { // eslint-disable-next-line no-console console.warn('Audio cache entry missing: ' + key); return; } /** * A reference to an audio source node used for playing back audio from * audio data stored in Phaser.Sound.WebAudioSound#audioBuffer. * * @name Phaser.Sound.WebAudioSound#source * @type {AudioBufferSourceNode} * @private * @default null * @since 3.0.0 */ this.source = null; /** * A reference to a second audio source used for gapless looped playback. * * @name Phaser.Sound.WebAudioSound#loopSource * @type {AudioBufferSourceNode} * @private * @default null * @since 3.0.0 */ this.loopSource = null; /** * Gain node responsible for controlling this sound's muting. * * @name Phaser.Sound.WebAudioSound#muteNode * @type {GainNode} * @private * @since 3.0.0 */ this.muteNode = manager.context.createGain(); /** * Gain node responsible for controlling this sound's volume. * * @name Phaser.Sound.WebAudioSound#volumeNode * @type {GainNode} * @private * @since 3.0.0 */ this.volumeNode = manager.context.createGain(); /** * The time at which the sound should have started playback from the beginning. * Based on BaseAudioContext.currentTime value. * * @name Phaser.Sound.WebAudioSound#playTime * @type {number} * @private * @default 0 * @since 3.0.0 */ this.playTime = 0; /** * The time at which the sound source should have actually started playback. * Based on BaseAudioContext.currentTime value. * * @name Phaser.Sound.WebAudioSound#startTime * @type {number} * @private * @default 0 * @since 3.0.0 */ this.startTime = 0; /** * The time at which the sound loop source should actually start playback. * Based on BaseAudioContext.currentTime value. * * @name Phaser.Sound.WebAudioSound#loopTime * @type {number} * @private * @default 0 * @since 3.0.0 */ this.loopTime = 0; /** * An array where we keep track of all rate updates during playback. * Array of object types: { time: number, rate: number } * * @name Phaser.Sound.WebAudioSound#rateUpdates * @type {array} * @private * @default [] * @since 3.0.0 */ this.rateUpdates = []; /** * Used for keeping track when sound source playback has ended * so its state can be updated accordingly. * * @name Phaser.Sound.WebAudioSound#hasEnded * @type {boolean} * @private * @default false * @since 3.0.0 */ this.hasEnded = false; /** * Used for keeping track when sound source has looped * so its state can be updated accordingly. * * @name Phaser.Sound.WebAudioSound#hasLooped * @type {boolean} * @private * @default false * @since 3.0.0 */ this.hasLooped = false; this.muteNode.connect(this.volumeNode); this.volumeNode.connect(manager.destination); this.duration = this.audioBuffer.duration; this.totalDuration = this.audioBuffer.duration; BaseSound.call(this, manager, key, config); }, /** * @event Phaser.Sound.WebAudioSound#playEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the Sound that emitted event. */ /** * Play this sound, or a marked section of it. * * It always plays the sound from the start. If you want to start playback from a specific time * you can set 'seek' setting of the config object, provided to this call, to that value. * * @method Phaser.Sound.WebAudioSound#play * @fires Phaser.Sound.WebAudioSound#playEvent * @since 3.0.0 * * @param {string} [markerName=''] - If you want to play a marker then provide the marker name here, otherwise omit it to play the full sound. * @param {SoundConfig} [config] - Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound. * * @return {boolean} Whether the sound started playing successfully. */ play: function (markerName, config) { if (!BaseSound.prototype.play.call(this, markerName, config)) { return false; } // \/\/\/ isPlaying = true, isPaused = false \/\/\/ this.stopAndRemoveBufferSource(); this.createAndStartBufferSource(); this.emit('play', this); return true; }, /** * @event Phaser.Sound.WebAudioSound#pauseEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the Sound that emitted event. */ /** * Pauses the sound. * * @method Phaser.Sound.WebAudioSound#pause * @fires Phaser.Sound.WebAudioSound#pauseEvent * @since 3.0.0 * * @return {boolean} Whether the sound was paused successfully. */ pause: function () { if (this.manager.context.currentTime < this.startTime) { return false; } if (!BaseSound.prototype.pause.call(this)) { return false; } // \/\/\/ isPlaying = false, isPaused = true \/\/\/ this.currentConfig.seek = this.getCurrentTime(); // Equivalent to setting paused time this.stopAndRemoveBufferSource(); this.emit('pause', this); return true; }, /** * @event Phaser.Sound.WebAudioSound#resumeEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the Sound that emitted event. */ /** * Resumes the sound. * * @method Phaser.Sound.WebAudioSound#resume * @fires Phaser.Sound.WebAudioSound#resumeEvent * @since 3.0.0 * * @return {boolean} Whether the sound was resumed successfully. */ resume: function () { if (this.manager.context.currentTime < this.startTime) { return false; } if (!BaseSound.prototype.resume.call(this)) { return false; } // \/\/\/ isPlaying = true, isPaused = false \/\/\/ this.createAndStartBufferSource(); this.emit('resume', this); return true; }, /** * @event Phaser.Sound.WebAudioSound#stopEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the Sound that emitted event. */ /** * Stop playing this sound. * * @method Phaser.Sound.WebAudioSound#stop * @fires Phaser.Sound.WebAudioSound#stopEvent * @since 3.0.0 * * @return {boolean} Whether the sound was stopped successfully. */ stop: function () { if (!BaseSound.prototype.stop.call(this)) { return false; } // \/\/\/ isPlaying = false, isPaused = false \/\/\/ this.stopAndRemoveBufferSource(); this.emit('stop', this); return true; }, /** * Used internally. * * @method Phaser.Sound.WebAudioSound#createAndStartBufferSource * @private * @since 3.0.0 */ createAndStartBufferSource: function () { var seek = this.currentConfig.seek; var delay = this.currentConfig.delay; var when = this.manager.context.currentTime + delay; var offset = (this.currentMarker ? this.currentMarker.start : 0) + seek; var duration = this.duration - seek; this.playTime = when - seek; this.startTime = when; this.source = this.createBufferSource(); this.applyConfig(); this.source.start(Math.max(0, when), Math.max(0, offset), Math.max(0, duration)); this.resetConfig(); }, /** * Used internally. * * @method Phaser.Sound.WebAudioSound#createAndStartLoopBufferSource * @private * @since 3.0.0 */ createAndStartLoopBufferSource: function () { var when = this.getLoopTime(); var offset = this.currentMarker ? this.currentMarker.start : 0; var duration = this.duration; this.loopTime = when; this.loopSource = this.createBufferSource(); this.loopSource.playbackRate.setValueAtTime(this.totalRate, 0); this.loopSource.start(Math.max(0, when), Math.max(0, offset), Math.max(0, duration)); }, /** * Used internally. * * @method Phaser.Sound.WebAudioSound#createBufferSource * @private * @since 3.0.0 * * @return {AudioBufferSourceNode} */ createBufferSource: function () { var _this = this; var source = this.manager.context.createBufferSource(); source.buffer = this.audioBuffer; source.connect(this.muteNode); source.onended = function (ev) { if (ev.target === _this.source) { // sound ended if (_this.currentConfig.loop) { _this.hasLooped = true; } else { _this.hasEnded = true; } } // else was stopped }; return source; }, /** * Used internally. * * @method Phaser.Sound.WebAudioSound#stopAndRemoveBufferSource * @private * @since 3.0.0 */ stopAndRemoveBufferSource: function () { if (this.source) { this.source.stop(); this.source.disconnect(); this.source = null; } this.playTime = 0; this.startTime = 0; this.stopAndRemoveLoopBufferSource(); }, /** * Used internally. * * @method Phaser.Sound.WebAudioSound#stopAndRemoveLoopBufferSource * @private * @since 3.0.0 */ stopAndRemoveLoopBufferSource: function () { if (this.loopSource) { this.loopSource.stop(); this.loopSource.disconnect(); this.loopSource = null; } this.loopTime = 0; }, /** * Method used internally for applying config values to some of the sound properties. * * @method Phaser.Sound.WebAudioSound#applyConfig * @protected * @since 3.0.0 */ applyConfig: function () { this.rateUpdates.length = 0; this.rateUpdates.push({ time: 0, rate: 1 }); BaseSound.prototype.applyConfig.call(this); }, /** * @event Phaser.Sound.WebAudioSound#endedEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the sound that emitted event. */ /** * @event Phaser.Sound.WebAudioSound#loopedEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the sound that emitted event. */ /** * Update method called automatically by sound manager on every game step. * * @method Phaser.Sound.WebAudioSound#update * @fires Phaser.Sound.WebAudioSound#endedEvent * @fires Phaser.Sound.WebAudioSound#loopedEvent * @protected * @since 3.0.0 * * @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time elapsed since the last frame. */ // eslint-disable-next-line no-unused-vars update: function (time, delta) { if (this.hasEnded) { this.hasEnded = false; BaseSound.prototype.stop.call(this); this.stopAndRemoveBufferSource(); this.emit('ended', this); } else if (this.hasLooped) { this.hasLooped = false; this.source = this.loopSource; this.loopSource = null; this.playTime = this.startTime = this.loopTime; this.rateUpdates.length = 0; this.rateUpdates.push({ time: 0, rate: this.totalRate }); this.createAndStartLoopBufferSource(); this.emit('looped', this); } }, /** * Calls Phaser.Sound.BaseSound#destroy method * and cleans up all Web Audio API related stuff. * * @method Phaser.Sound.WebAudioSound#destroy * @since 3.0.0 */ destroy: function () { BaseSound.prototype.destroy.call(this); this.audioBuffer = null; this.stopAndRemoveBufferSource(); this.muteNode.disconnect(); this.muteNode = null; this.volumeNode.disconnect(); this.volumeNode = null; this.rateUpdates.length = 0; this.rateUpdates = null; }, /** * Method used internally to calculate total playback rate of the sound. * * @method Phaser.Sound.WebAudioSound#calculateRate * @protected * @since 3.0.0 */ calculateRate: function () { BaseSound.prototype.calculateRate.call(this); var now = this.manager.context.currentTime; if (this.source && typeof this.totalRate === 'number') { this.source.playbackRate.setValueAtTime(this.totalRate, now); } if (this.isPlaying) { this.rateUpdates.push({ time: Math.max(this.startTime, now) - this.playTime, rate: this.totalRate }); if (this.loopSource) { this.stopAndRemoveLoopBufferSource(); this.createAndStartLoopBufferSource(); } } }, /** * Method used internally for calculating current playback time of a playing sound. * * @method Phaser.Sound.WebAudioSound#getCurrentTime * @private * @since 3.0.0 */ getCurrentTime: function () { var currentTime = 0; for (var i = 0; i < this.rateUpdates.length; i++) { var nextTime = 0; if (i < this.rateUpdates.length - 1) { nextTime = this.rateUpdates[i + 1].time; } else { nextTime = this.manager.context.currentTime - this.playTime; } currentTime += (nextTime - this.rateUpdates[i].time) * this.rateUpdates[i].rate; } return currentTime; }, /** * Method used internally for calculating the time * at witch the loop source should start playing. * * @method Phaser.Sound.WebAudioSound#getLoopTime * @private * @since 3.0.0 */ getLoopTime: function () { var lastRateUpdateCurrentTime = 0; for (var i = 0; i < this.rateUpdates.length - 1; i++) { lastRateUpdateCurrentTime += (this.rateUpdates[i + 1].time - this.rateUpdates[i].time) * this.rateUpdates[i].rate; } var lastRateUpdate = this.rateUpdates[this.rateUpdates.length - 1]; return this.playTime + lastRateUpdate.time + (this.duration - lastRateUpdateCurrentTime) / lastRateUpdate.rate; }, /** * @event Phaser.Sound.WebAudioSound#rateEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the sound that emitted the event. * @param {number} value - An updated value of Phaser.Sound.WebAudioSound#rate property. */ /** * Rate at which this Sound will be played. * Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed * and 2.0 doubles the audios playback speed. * * @name Phaser.Sound.WebAudioSound#rate * @type {number} * @default 1 * @since 3.0.0 */ rate: { get: function () { return this.currentConfig.rate; }, set: function (value) { this.currentConfig.rate = value; this.calculateRate(); this.emit('rate', this, value); } }, /** * Sets the playback rate of this Sound. * * For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed * and 2.0 doubles the audios playback speed. * * @method Phaser.Sound.WebAudioSound#setRate * @fires Phaser.Sound.WebAudioSound#rateEvent * @since 3.3.0 * * @param {number} value - The playback rate at of this Sound. * * @return {Phaser.Sound.WebAudioSound} This Sound. */ setRate: function (value) { this.rate = value; return this; }, /** * @event Phaser.Sound.WebAudioSound#detuneEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the Sound that emitted event. * @param {number} value - An updated value of Phaser.Sound.WebAudioSound#detune property. */ /** * The detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @name Phaser.Sound.WebAudioSound#detune * @type {number} * @default 0 * @since 3.0.0 */ detune: { get: function () { return this.currentConfig.detune; }, set: function (value) { this.currentConfig.detune = value; this.calculateRate(); this.emit('detune', this, value); } }, /** * Sets the detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @method Phaser.Sound.WebAudioSound#setDetune * @fires Phaser.Sound.WebAudioSound#detuneEvent * @since 3.3.0 * * @param {number} value - The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @return {Phaser.Sound.WebAudioSound} This Sound. */ setDetune: function (value) { this.detune = value; return this; }, /** * @event Phaser.Sound.WebAudioSound#muteEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the sound that emitted event. * @param {boolean} value - An updated value of Phaser.Sound.WebAudioSound#mute property. */ /** * Boolean indicating whether the sound is muted or not. * Gets or sets the muted state of this sound. * * @name Phaser.Sound.WebAudioSound#mute * @type {boolean} * @default false * @since 3.0.0 */ mute: { get: function () { return (this.muteNode.gain.value === 0); }, set: function (value) { this.currentConfig.mute = value; this.muteNode.gain.setValueAtTime(value ? 0 : 1, 0); this.emit('mute', this, value); } }, /** * Sets the muted state of this Sound. * * @method Phaser.Sound.WebAudioSound#setMute * @fires Phaser.Sound.WebAudioSound#muteEvent * @since 3.4.0 * * @param {boolean} value - `true` to mute this sound, `false` to unmute it. * * @return {Phaser.Sound.WebAudioSound} This Sound instance. */ setMute: function (value) { this.mute = value; return this; }, /** * @event Phaser.Sound.WebAudioSound#volumeEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the sound that emitted event. * @param {number} value - An updated value of Phaser.Sound.WebAudioSound#volume property. */ /** * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). * * @name Phaser.Sound.WebAudioSound#volume * @type {number} * @default 1 * @since 3.0.0 */ volume: { get: function () { return this.volumeNode.gain.value; }, set: function (value) { this.currentConfig.volume = value; this.volumeNode.gain.setValueAtTime(value, 0); this.emit('volume', this, value); } }, /** * Sets the volume of this Sound. * * @method Phaser.Sound.WebAudioSound#setVolume * @fires Phaser.Sound.WebAudioSound#volumeEvent * @since 3.4.0 * * @param {number} value - The volume of the sound. * * @return {Phaser.Sound.WebAudioSound} This Sound instance. */ setVolume: function (value) { this.volume = value; return this; }, /** * @event Phaser.Sound.WebAudioSound#seekEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the sound that emitted event. * @param {number} value - An updated value of Phaser.Sound.WebAudioSound#seek property. */ /** * Property representing the position of playback for this sound, in seconds. * Setting it to a specific value moves current playback to that position. * The value given is clamped to the range 0 to current marker duration. * Setting seek of a stopped sound has no effect. * * @name Phaser.Sound.WebAudioSound#seek * @type {number} * @since 3.0.0 */ seek: { get: function () { if (this.isPlaying) { if (this.manager.context.currentTime < this.startTime) { return this.startTime - this.playTime; } return this.getCurrentTime(); } else if (this.isPaused) { return this.currentConfig.seek; } else { return 0; } }, set: function (value) { if (this.manager.context.currentTime < this.startTime) { return; } if (this.isPlaying || this.isPaused) { value = Math.min(Math.max(0, value), this.duration); this.currentConfig.seek = value; if (this.isPlaying) { this.stopAndRemoveBufferSource(); this.createAndStartBufferSource(); } this.emit('seek', this, value); } } }, /** * Seeks to a specific point in this sound. * * @method Phaser.Sound.WebAudioSound#setSeek * @fires Phaser.Sound.WebAudioSound#seekEvent * @since 3.4.0 * * @param {number} value - The point in the sound to seek to. * * @return {Phaser.Sound.WebAudioSound} This Sound instance. */ setSeek: function (value) { this.seek = value; return this; }, /** * @event Phaser.Sound.WebAudioSound#loopEvent * @param {Phaser.Sound.WebAudioSound} sound - Reference to the sound that emitted event. * @param {boolean} value - An updated value of Phaser.Sound.WebAudioSound#loop property. */ /** * Flag indicating whether or not the sound or current sound marker will loop. * * @name Phaser.Sound.WebAudioSound#loop * @type {boolean} * @default false * @since 3.0.0 */ loop: { get: function () { return this.currentConfig.loop; }, set: function (value) { this.currentConfig.loop = value; if (this.isPlaying) { this.stopAndRemoveLoopBufferSource(); if (value) { this.createAndStartLoopBufferSource(); } } this.emit('loop', this, value); } }, /** * Sets the loop state of this Sound. * * @method Phaser.Sound.WebAudioSound#setLoop * @fires Phaser.Sound.WebAudioSound#loopEvent * @since 3.4.0 * * @param {boolean} value - `true` to loop this sound, `false` to not loop it. * * @return {Phaser.Sound.WebAudioSound} This Sound instance. */ setLoop: function (value) { this.loop = value; return this; } }); module.exports = WebAudioSound; /***/ }), /* 186 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BaseSoundManager = __webpack_require__(79); var Class = __webpack_require__(0); var WebAudioSound = __webpack_require__(185); /** * @classdesc * Web Audio API implementation of the sound manager. * * @class WebAudioSoundManager * @extends Phaser.Sound.BaseSoundManager * @memberOf Phaser.Sound * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - Reference to the current game instance. */ var WebAudioSoundManager = new Class({ Extends: BaseSoundManager, initialize: function WebAudioSoundManager (game) { /** * The AudioContext being used for playback. * * @name Phaser.Sound.WebAudioSoundManager#context * @type {AudioContext} * @private * @since 3.0.0 */ this.context = this.createAudioContext(game); /** * Gain node responsible for controlling global muting. * * @name Phaser.Sound.WebAudioSoundManager#masterMuteNode * @type {GainNode} * @private * @since 3.0.0 */ this.masterMuteNode = this.context.createGain(); /** * Gain node responsible for controlling global volume. * * @name Phaser.Sound.WebAudioSoundManager#masterVolumeNode * @type {GainNode} * @private * @since 3.0.0 */ this.masterVolumeNode = this.context.createGain(); this.masterMuteNode.connect(this.masterVolumeNode); this.masterVolumeNode.connect(this.context.destination); /** * Destination node for connecting individual sounds to. * * @name Phaser.Sound.WebAudioSoundManager#destination * @type {AudioNode} * @private * @since 3.0.0 */ this.destination = this.masterMuteNode; this.locked = this.context.state === 'suspended' && ('ontouchstart' in window || 'onclick' in window); BaseSoundManager.call(this, game); if (this.locked) { this.unlock(); } }, /** * Method responsible for instantiating and returning AudioContext instance. * If an instance of an AudioContext class was provided through the game config, * that instance will be returned instead. This can come in handy if you are reloading * a Phaser game on a page that never properly refreshes (such as in an SPA project) * and you want to reuse already instantiated AudioContext. * * @method Phaser.Sound.WebAudioSoundManager#createAudioContext * @private * @since 3.0.0 * * @param {Phaser.Game} game - Reference to the current game instance. * * @return {AudioContext} The AudioContext instance to be used for playback. */ createAudioContext: function (game) { var audioConfig = game.config.audio; if (audioConfig && audioConfig.context) { audioConfig.context.resume(); return audioConfig.context; } return new AudioContext(); }, /** * Adds a new sound into the sound manager. * * @method Phaser.Sound.WebAudioSoundManager#add * @since 3.0.0 * * @param {string} key - Asset key for the sound. * @param {SoundConfig} [config] - An optional config object containing default sound settings. * * @return {Phaser.Sound.WebAudioSound} The new sound instance. */ add: function (key, config) { var sound = new WebAudioSound(this, key, config); this.sounds.push(sound); return sound; }, /** * Unlocks Web Audio API on the initial input event. * * Read more about how this issue is handled here in [this article](https://medium.com/@pgoloskokovic/unlocking-web-audio-the-smarter-way-8858218c0e09). * * @method Phaser.Sound.WebAudioSoundManager#unlock * @since 3.0.0 */ unlock: function () { var _this = this; var unlock = function () { _this.context.resume().then(function () { document.body.removeEventListener('touchstart', unlock); document.body.removeEventListener('touchend', unlock); document.body.removeEventListener('click', unlock); _this.unlocked = true; }); }; if (document.body) { document.body.addEventListener('touchstart', unlock, false); document.body.addEventListener('touchend', unlock, false); document.body.addEventListener('click', unlock, false); } }, /** * Method used internally for pausing sound manager if * Phaser.Sound.WebAudioSoundManager#pauseOnBlur is set to true. * * @method Phaser.Sound.WebAudioSoundManager#onBlur * @protected * @since 3.0.0 */ onBlur: function () { this.context.suspend(); }, /** * Method used internally for resuming sound manager if * Phaser.Sound.WebAudioSoundManager#pauseOnBlur is set to true. * * @method Phaser.Sound.WebAudioSoundManager#onFocus * @protected * @since 3.0.0 */ onFocus: function () { this.context.resume(); }, /** * Calls Phaser.Sound.BaseSoundManager#destroy method * and cleans up all Web Audio API related stuff. * * @method Phaser.Sound.WebAudioSoundManager#destroy * @since 3.0.0 */ destroy: function () { this.destination = null; this.masterVolumeNode.disconnect(); this.masterVolumeNode = null; this.masterMuteNode.disconnect(); this.masterMuteNode = null; if (this.game.config.audio && this.game.config.audio.context) { this.context.suspend(); } else { var _this = this; this.context.close().then(function () { _this.context = null; }); } BaseSoundManager.prototype.destroy.call(this); }, /** * @event Phaser.Sound.WebAudioSoundManager#muteEvent * @param {Phaser.Sound.WebAudioSoundManager} soundManager - Reference to the sound manager that emitted event. * @param {boolean} value - An updated value of Phaser.Sound.WebAudioSoundManager#mute property. */ /** * Sets the muted state of all this Sound Manager. * * @method Phaser.Sound.WebAudioSoundManager#setMute * @fires Phaser.Sound.WebAudioSoundManager#muteEvent * @since 3.3.0 * * @param {boolean} value - `true` to mute all sounds, `false` to unmute them. * * @return {Phaser.Sound.WebAudioSoundManager} This Sound Manager. */ setMute: function (value) { this.mute = value; return this; }, /** * @name Phaser.Sound.WebAudioSoundManager#mute * @type {boolean} * @fires Phaser.Sound.WebAudioSoundManager#MuteEvent * @since 3.0.0 */ mute: { get: function () { return (this.masterMuteNode.gain.value === 0); }, set: function (value) { this.masterMuteNode.gain.setValueAtTime(value ? 0 : 1, 0); this.emit('mute', this, value); } }, /** * @event Phaser.Sound.WebAudioSoundManager#VolumeEvent * @param {Phaser.Sound.WebAudioSoundManager} soundManager - Reference to the sound manager that emitted event. * @param {number} value - An updated value of Phaser.Sound.WebAudioSoundManager#volume property. */ /** * Sets the volume of this Sound Manager. * * @method Phaser.Sound.WebAudioSoundManager#setVolume * @fires Phaser.Sound.WebAudioSoundManager#VolumeEvent * @since 3.3.0 * * @param {number} value - The global volume of this Sound Manager. * * @return {Phaser.Sound.WebAudioSoundManager} This Sound Manager. */ setVolume: function (value) { this.volume = value; return this; }, /** * @name Phaser.Sound.WebAudioSoundManager#volume * @type {number} * @fires Phaser.Sound.WebAudioSoundManager#VolumeEvent * @since 3.0.0 */ volume: { get: function () { return this.masterVolumeNode.gain.value; }, set: function (value) { this.masterVolumeNode.gain.setValueAtTime(value, 0); this.emit('volume', this, value); } } }); module.exports = WebAudioSoundManager; /***/ }), /* 187 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BaseSound = __webpack_require__(78); var Class = __webpack_require__(0); var EventEmitter = __webpack_require__(9); var Extend = __webpack_require__(17); /** * @classdesc * No audio implementation of the sound. It is used if audio has been * disabled in the game config or the device doesn't support any audio. * * It represents a graceful degradation of sound logic that provides * minimal functionality and prevents Phaser projects that use audio from * breaking on devices that don't support any audio playback technologies. * * @class NoAudioSound * @extends Phaser.Sound.BaseSound * @memberOf Phaser.Sound * @constructor * @since 3.0.0 * * @param {Phaser.Sound.NoAudioSoundManager} manager - Reference to the current sound manager instance. * @param {string} key - Asset key for the sound. * @param {SoundConfig} [config={}] - An optional config object containing default sound settings. */ var NoAudioSound = new Class({ Extends: EventEmitter, initialize: function NoAudioSound (manager, key, config) { if (config === void 0) { config = {}; } EventEmitter.call(this); this.manager = manager; this.key = key; this.isPlaying = false; this.isPaused = false; this.totalRate = 1; this.duration = 0; this.totalDuration = 0; this.config = Extend({ mute: false, volume: 1, rate: 1, detune: 0, seek: 0, loop: false, delay: 0 }, config); this.currentConfig = this.config; this.mute = false; this.volume = 1; this.rate = 1; this.detune = 0; this.seek = 0; this.loop = false; this.markers = {}; this.currentMarker = null; this.pendingRemove = false; }, // eslint-disable-next-line no-unused-vars addMarker: function (marker) { return false; }, // eslint-disable-next-line no-unused-vars updateMarker: function (marker) { return false; }, // eslint-disable-next-line no-unused-vars removeMarker: function (markerName) { return null; }, // eslint-disable-next-line no-unused-vars play: function (markerName, config) { return false; }, pause: function () { return false; }, resume: function () { return false; }, stop: function () { return false; }, destroy: function () { this.manager.remove(this); BaseSound.prototype.destroy.call(this); } }); module.exports = NoAudioSound; /***/ }), /* 188 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BaseSoundManager = __webpack_require__(79); var Class = __webpack_require__(0); var EventEmitter = __webpack_require__(9); var NoAudioSound = __webpack_require__(187); var NOOP = __webpack_require__(3); /** * @classdesc * No audio implementation of the sound manager. It is used if audio has been * disabled in the game config or the device doesn't support any audio. * * It represents a graceful degradation of sound manager logic that provides * minimal functionality and prevents Phaser projects that use audio from * breaking on devices that don't support any audio playback technologies. * * @class NoAudioSoundManager * @extends Phaser.Sound.BaseSoundManager * @memberOf Phaser.Sound * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - Reference to the current game instance. */ var NoAudioSoundManager = new Class({ Extends: EventEmitter, initialize: function NoAudioSoundManager (game) { EventEmitter.call(this); this.game = game; this.sounds = []; this.mute = false; this.volume = 1; this.rate = 1; this.detune = 0; this.pauseOnBlur = true; this.locked = false; }, add: function (key, config) { var sound = new NoAudioSound(this, key, config); this.sounds.push(sound); return sound; }, addAudioSprite: function (key, config) { var sound = this.add(key, config); sound.spritemap = {}; return sound; }, // eslint-disable-next-line no-unused-vars play: function (key, extra) { return false; }, // eslint-disable-next-line no-unused-vars playAudioSprite: function (key, spriteName, config) { return false; }, remove: function (sound) { return BaseSoundManager.prototype.remove.call(this, sound); }, removeByKey: function (key) { return BaseSoundManager.prototype.removeByKey.call(this, key); }, pauseAll: NOOP, resumeAll: NOOP, stopAll: NOOP, update: NOOP, setRate: NOOP, setDetune: NOOP, setMute: NOOP, setVolume: NOOP, forEachActiveSound: function (callbackfn, scope) { BaseSoundManager.prototype.forEachActiveSound.call(this, callbackfn, scope); }, destroy: function () { BaseSoundManager.prototype.destroy.call(this); } }); module.exports = NoAudioSoundManager; /***/ }), /* 189 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BaseSound = __webpack_require__(78); var Class = __webpack_require__(0); /** * @classdesc * HTML5 Audio implementation of the sound. * * @class HTML5AudioSound * @extends Phaser.Sound.BaseSound * @memberOf Phaser.Sound * @constructor * @since 3.0.0 * * @param {Phaser.Sound.HTML5AudioSoundManager} manager - Reference to the current sound manager instance. * @param {string} key - Asset key for the sound. * @param {SoundConfig} [config={}] - An optional config object containing default sound settings. */ var HTML5AudioSound = new Class({ Extends: BaseSound, initialize: function HTML5AudioSound (manager, key, config) { if (config === undefined) { config = {}; } /** * An array containing all HTML5 Audio tags that could be used for individual * sound's playback. Number of instances depends on the config value passed * to the Loader#audio method call, default is 1. * * @name Phaser.Sound.HTML5AudioSound#tags * @type {HTMLAudioElement[]} * @private * @since 3.0.0 */ this.tags = manager.game.cache.audio.get(key); if (!this.tags) { // eslint-disable-next-line no-console console.warn('Audio cache entry missing: ' + key); return; } /** * Reference to an HTML5 Audio tag used for playing sound. * * @name Phaser.Sound.HTML5AudioSound#audio * @type {HTMLAudioElement} * @private * @default null * @since 3.0.0 */ this.audio = null; /** * Timestamp as generated by the Request Animation Frame or SetTimeout * representing the time at which the delayed sound playback should start. * Set to 0 if sound playback is not delayed. * * @name Phaser.Sound.HTML5AudioSound#startTime * @type {number} * @private * @default 0 * @since 3.0.0 */ this.startTime = 0; /** * Audio tag's playback position recorded on previous * update method call. Set to 0 if sound is not playing. * * @name Phaser.Sound.HTML5AudioSound#previousTime * @type {number} * @private * @default 0 * @since 3.0.0 */ this.previousTime = 0; this.duration = this.tags[0].duration; this.totalDuration = this.tags[0].duration; BaseSound.call(this, manager, key, config); }, /** * @event Phaser.Sound.HTML5AudioSound#playEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. */ /** * Play this sound, or a marked section of it. * It always plays the sound from the start. If you want to start playback from a specific time * you can set 'seek' setting of the config object, provided to this call, to that value. * * @method Phaser.Sound.HTML5AudioSound#play * @fires Phaser.Sound.HTML5AudioSound#playEvent * @since 3.0.0 * * @param {string} [markerName=''] - If you want to play a marker then provide the marker name here, otherwise omit it to play the full sound. * @param {SoundConfig} [config] - Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound. * * @return {boolean} Whether the sound started playing successfully. */ play: function (markerName, config) { if (this.manager.isLocked(this, 'play', [ markerName, config ])) { return false; } if (!BaseSound.prototype.play.call(this, markerName, config)) { return false; } // \/\/\/ isPlaying = true, isPaused = false \/\/\/ if (!this.pickAndPlayAudioTag()) { return false; } this.emit('play', this); return true; }, /** * @event Phaser.Sound.HTML5AudioSound#pauseEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. */ /** * Pauses the sound. * * @method Phaser.Sound.HTML5AudioSound#pause * @fires Phaser.Sound.HTML5AudioSound#pauseEvent * @since 3.0.0 * * @return {boolean} Whether the sound was paused successfully. */ pause: function () { if (this.manager.isLocked(this, 'pause')) { return false; } if (this.startTime > 0) { return false; } if (!BaseSound.prototype.pause.call(this)) { return false; } // \/\/\/ isPlaying = false, isPaused = true \/\/\/ this.currentConfig.seek = this.audio.currentTime - (this.currentMarker ? this.currentMarker.start : 0); this.stopAndReleaseAudioTag(); this.emit('pause', this); return true; }, /** * @event Phaser.Sound.HTML5AudioSound#resumeEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. */ /** * Resumes the sound. * * @method Phaser.Sound.HTML5AudioSound#resume * @fires Phaser.Sound.HTML5AudioSound#resumeEvent * @since 3.0.0 * * @return {boolean} Whether the sound was resumed successfully. */ resume: function () { if (this.manager.isLocked(this, 'resume')) { return false; } if (this.startTime > 0) { return false; } if (!BaseSound.prototype.resume.call(this)) { return false; } // \/\/\/ isPlaying = true, isPaused = false \/\/\/ if (!this.pickAndPlayAudioTag()) { return false; } this.emit('resume', this); return true; }, /** * @event Phaser.Sound.HTML5AudioSound#stopEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. */ /** * Stop playing this sound. * * @method Phaser.Sound.HTML5AudioSound#stop * @fires Phaser.Sound.HTML5AudioSound#stopEvent * @since 3.0.0 * * @return {boolean} Whether the sound was stopped successfully. */ stop: function () { if (this.manager.isLocked(this, 'stop')) { return false; } if (!BaseSound.prototype.stop.call(this)) { return false; } // \/\/\/ isPlaying = false, isPaused = false \/\/\/ this.stopAndReleaseAudioTag(); this.emit('stop', this); return true; }, /** * Used internally to do what the name says. * * @method Phaser.Sound.HTML5AudioSound#pickAndPlayAudioTag * @private * @since 3.0.0 * * @return {boolean} Whether the sound was assigned an audio tag successfully. */ pickAndPlayAudioTag: function () { if (!this.pickAudioTag()) { this.reset(); return false; } var seek = this.currentConfig.seek; var delay = this.currentConfig.delay; var offset = (this.currentMarker ? this.currentMarker.start : 0) + seek; this.previousTime = offset; this.audio.currentTime = offset; this.applyConfig(); if (delay === 0) { this.startTime = 0; if (this.audio.paused) { this.playCatchPromise(); } } else { this.startTime = window.performance.now() + delay * 1000; if (!this.audio.paused) { this.audio.pause(); } } this.resetConfig(); return true; }, /** * This method performs the audio tag pooling logic. It first looks for * unused audio tag to assign to this sound object. If there are no unused * audio tags, based on HTML5AudioSoundManager#override property value, it * looks for sound with most advanced playback and hijacks its audio tag or * does nothing. * * @method Phaser.Sound.HTML5AudioSound#pickAudioTag * @private * @since 3.0.0 * * @return {boolean} Whether the sound was assigned an audio tag successfully. */ pickAudioTag: function () { if (this.audio) { return true; } for (var i = 0; i < this.tags.length; i++) { var audio = this.tags[i]; if (audio.dataset.used === 'false') { audio.dataset.used = 'true'; this.audio = audio; return true; } } if (!this.manager.override) { return false; } var otherSounds = []; this.manager.forEachActiveSound(function (sound) { if (sound.key === this.key && sound.audio) { otherSounds.push(sound); } }, this); otherSounds.sort(function (a1, a2) { if (a1.loop === a2.loop) { // sort by progress return (a2.seek / a2.duration) - (a1.seek / a1.duration); } return a1.loop ? 1 : -1; }); var selectedSound = otherSounds[0]; this.audio = selectedSound.audio; selectedSound.reset(); selectedSound.audio = null; selectedSound.startTime = 0; selectedSound.previousTime = 0; return true; }, /** * Method used for playing audio tag and catching possible exceptions * thrown from rejected Promise returned from play method call. * * @method Phaser.Sound.HTML5AudioSound#playCatchPromise * @private * @since 3.0.0 */ playCatchPromise: function () { var playPromise = this.audio.play(); if (playPromise) { // eslint-disable-next-line no-unused-vars playPromise.catch(function (reason) { console.warn(reason); }); } }, /** * Used internally to do what the name says. * * @method Phaser.Sound.HTML5AudioSound#stopAndReleaseAudioTag * @private * @since 3.0.0 */ stopAndReleaseAudioTag: function () { this.audio.pause(); this.audio.dataset.used = 'false'; this.audio = null; this.startTime = 0; this.previousTime = 0; }, /** * Method used internally to reset sound state, usually when stopping sound * or when hijacking audio tag from another sound. * * @method Phaser.Sound.HTML5AudioSound#reset * @private * @since 3.0.0 */ reset: function () { BaseSound.prototype.stop.call(this); }, /** * Method used internally by sound manager for pausing sound if * Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true. * * @method Phaser.Sound.HTML5AudioSoundManager#onBlur * @private * @since 3.0.0 */ onBlur: function () { this.isPlaying = false; this.isPaused = true; this.currentConfig.seek = this.audio.currentTime - (this.currentMarker ? this.currentMarker.start : 0); this.currentConfig.delay = Math.max(0, (this.startTime - window.performance.now()) / 1000); this.stopAndReleaseAudioTag(); }, /** * Method used internally by sound manager for resuming sound if * Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true. * * @method Phaser.Sound.HTML5AudioSound#onFocus * @private * @since 3.0.0 */ onFocus: function () { this.isPlaying = true; this.isPaused = false; this.pickAndPlayAudioTag(); }, /** * @event Phaser.Sound.HTML5AudioSound#loopedEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. */ /** * @event Phaser.Sound.HTML5AudioSound#endedEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. */ /** * Update method called automatically by sound manager on every game step. * * @method Phaser.Sound.HTML5AudioSound#update * @fires Phaser.Sound.HTML5AudioSound#loopedEvent * @fires Phaser.Sound.HTML5AudioSound#endedEvent * @protected * @since 3.0.0 * * @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time elapsed since the last frame. */ // eslint-disable-next-line no-unused-vars update: function (time, delta) { if (!this.isPlaying) { return; } // handling delayed playback if (this.startTime > 0) { if (this.startTime < time - this.manager.audioPlayDelay) { this.audio.currentTime += Math.max(0, time - this.startTime) / 1000; this.startTime = 0; this.previousTime = this.audio.currentTime; this.playCatchPromise(); } return; } // handle looping and ending var startTime = this.currentMarker ? this.currentMarker.start : 0; var endTime = startTime + this.duration; var currentTime = this.audio.currentTime; if (this.currentConfig.loop) { if (currentTime >= endTime - this.manager.loopEndOffset) { this.audio.currentTime = startTime + Math.max(0, currentTime - endTime); currentTime = this.audio.currentTime; } else if (currentTime < startTime) { this.audio.currentTime += startTime; currentTime = this.audio.currentTime; } if (currentTime < this.previousTime) { this.emit('looped', this); } } else if (currentTime >= endTime) { this.reset(); this.stopAndReleaseAudioTag(); this.emit('ended', this); return; } this.previousTime = currentTime; }, /** * Calls Phaser.Sound.BaseSound#destroy method * and cleans up all HTML5 Audio related stuff. * * @method Phaser.Sound.HTML5AudioSound#destroy * @since 3.0.0 */ destroy: function () { BaseSound.prototype.destroy.call(this); this.tags = null; if (this.audio) { this.stopAndReleaseAudioTag(); } }, /** * Method used internally to determine mute setting of the sound. * * @method Phaser.Sound.HTML5AudioSound#updateMute * @private * @since 3.0.0 */ updateMute: function () { if (this.audio) { this.audio.muted = this.currentConfig.mute || this.manager.mute; } }, /** * Method used internally to calculate total volume of the sound. * * @method Phaser.Sound.HTML5AudioSound#updateVolume * @private * @since 3.0.0 */ updateVolume: function () { if (this.audio) { this.audio.volume = this.currentConfig.volume * this.manager.volume; } }, /** * Method used internally to calculate total playback rate of the sound. * * @method Phaser.Sound.HTML5AudioSound#calculateRate * @protected * @since 3.0.0 */ calculateRate: function () { BaseSound.prototype.calculateRate.call(this); if (this.audio) { this.audio.playbackRate = this.totalRate; } }, /** * @event Phaser.Sound.HTML5AudioSound#muteEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. * @param {boolean} value - An updated value of Phaser.Sound.HTML5AudioSound#mute property. */ /** * Boolean indicating whether the sound is muted or not. * Gets or sets the muted state of this sound. * * @name Phaser.Sound.HTML5AudioSound#mute * @type {boolean} * @default false * @since 3.0.0 */ mute: { get: function () { return this.currentConfig.mute; }, set: function (value) { this.currentConfig.mute = value; if (this.manager.isLocked(this, 'mute', value)) { return; } this.emit('mute', this, value); } }, /** * Sets the muted state of this Sound. * * @method Phaser.Sound.HTML5AudioSound#setMute * @fires Phaser.Sound.HTML5AudioSound#muteEvent * @since 3.4.0 * * @param {boolean} value - `true` to mute this sound, `false` to unmute it. * * @return {Phaser.Sound.HTML5AudioSound} This Sound instance. */ setMute: function (value) { this.mute = value; return this; }, /** * @event Phaser.Sound.HTML5AudioSound#volumeEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. * @param {number} value - An updated value of Phaser.Sound.HTML5AudioSound#volume property. */ /** * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). * * @name Phaser.Sound.HTML5AudioSound#volume * @type {number} * @default 1 * @since 3.0.0 */ volume: { get: function () { return this.currentConfig.volume; }, set: function (value) { this.currentConfig.volume = value; if (this.manager.isLocked(this, 'volume', value)) { return; } this.emit('volume', this, value); } }, /** * Sets the volume of this Sound. * * @method Phaser.Sound.HTML5AudioSound#setVolume * @fires Phaser.Sound.HTML5AudioSound#volumeEvent * @since 3.4.0 * * @param {number} value - The volume of the sound. * * @return {Phaser.Sound.HTML5AudioSound} This Sound instance. */ setVolume: function (value) { this.volume = value; return this; }, /** * @event Phaser.Sound.HTML5AudioSound#rateEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted the event. * @param {number} value - An updated value of Phaser.Sound.HTML5AudioSound#rate property. */ /** * Rate at which this Sound will be played. * Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed * and 2.0 doubles the audios playback speed. * * @name Phaser.Sound.HTML5AudioSound#rate * @type {number} * @default 1 * @since 3.0.0 */ rate: { get: function () { return this.currentConfig.rate; }, set: function (value) { this.currentConfig.rate = value; if (this.manager.isLocked(this, 'rate', value)) { return; } else { this.calculateRate(); this.emit('rate', this, value); } } }, /** * Sets the playback rate of this Sound. * * For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed * and 2.0 doubles the audios playback speed. * * @method Phaser.Sound.HTML5AudioSound#setRate * @fires Phaser.Sound.HTML5AudioSound#rateEvent * @since 3.3.0 * * @param {number} value - The playback rate at of this Sound. * * @return {Phaser.Sound.HTML5AudioSound} This Sound. */ setRate: function (value) { this.rate = value; return this; }, /** * @event Phaser.Sound.HTML5AudioSound#detuneEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the Sound that emitted event. * @param {number} value - An updated value of Phaser.Sound.HTML5AudioSound#detune property. */ /** * The detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @name Phaser.Sound.HTML5AudioSound#detune * @type {number} * @default 0 * @since 3.0.0 */ detune: { get: function () { return this.currentConfig.detune; }, set: function (value) { this.currentConfig.detune = value; if (this.manager.isLocked(this, 'detune', value)) { return; } else { this.calculateRate(); this.emit('detune', this, value); } } }, /** * Sets the detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @method Phaser.Sound.HTML5AudioSound#setDetune * @fires Phaser.Sound.HTML5AudioSound#detuneEvent * @since 3.3.0 * * @param {number} value - The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * * @return {Phaser.Sound.HTML5AudioSound} This Sound. */ setDetune: function (value) { this.detune = value; return this; }, /** * @event Phaser.Sound.HTML5AudioSound#seekEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. * @param {number} value - An updated value of Phaser.Sound.HTML5AudioSound#seek property. */ /** * Property representing the position of playback for this sound, in seconds. * Setting it to a specific value moves current playback to that position. * The value given is clamped to the range 0 to current marker duration. * Setting seek of a stopped sound has no effect. * * @name Phaser.Sound.HTML5AudioSound#seek * @type {number} * @since 3.0.0 */ seek: { get: function () { if (this.isPlaying) { return this.audio.currentTime - (this.currentMarker ? this.currentMarker.start : 0); } else if (this.isPaused) { return this.currentConfig.seek; } else { return 0; } }, set: function (value) { if (this.manager.isLocked(this, 'seek', value)) { return; } if (this.startTime > 0) { return; } if (this.isPlaying || this.isPaused) { value = Math.min(Math.max(0, value), this.duration); if (this.isPlaying) { this.previousTime = value; this.audio.currentTime = value; } else if (this.isPaused) { this.currentConfig.seek = value; } this.emit('seek', this, value); } } }, /** * Seeks to a specific point in this sound. * * @method Phaser.Sound.HTML5AudioSound#setSeek * @fires Phaser.Sound.HTML5AudioSound#seekEvent * @since 3.4.0 * * @param {number} value - The point in the sound to seek to. * * @return {Phaser.Sound.HTML5AudioSound} This Sound instance. */ setSeek: function (value) { this.seek = value; return this; }, /** * @event Phaser.Sound.HTML5AudioSound#loopEvent * @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event. * @param {boolean} value - An updated value of Phaser.Sound.HTML5AudioSound#loop property. */ /** * Flag indicating whether or not the sound or current sound marker will loop. * * @name Phaser.Sound.HTML5AudioSound#loop * @type {boolean} * @default false * @since 3.0.0 */ loop: { get: function () { return this.currentConfig.loop; }, set: function (value) { this.currentConfig.loop = value; if (this.manager.isLocked(this, 'loop', value)) { return; } if (this.audio) { this.audio.loop = value; } this.emit('loop', this, value); } }, /** * Sets the loop state of this Sound. * * @method Phaser.Sound.HTML5AudioSound#setLoop * @fires Phaser.Sound.HTML5AudioSound#loopEvent * @since 3.4.0 * * @param {boolean} value - `true` to loop this sound, `false` to not loop it. * * @return {Phaser.Sound.HTML5AudioSound} This Sound instance. */ setLoop: function (value) { this.loop = value; return this; } }); module.exports = HTML5AudioSound; /***/ }), /* 190 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BaseSoundManager = __webpack_require__(79); var Class = __webpack_require__(0); var HTML5AudioSound = __webpack_require__(189); /** * HTML5 Audio implementation of the Sound Manager. * * @class HTML5AudioSoundManager * @extends Phaser.Sound.BaseSoundManager * @memberOf Phaser.Sound * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - Reference to the current game instance. */ var HTML5AudioSoundManager = new Class({ Extends: BaseSoundManager, initialize: function HTML5AudioSoundManager (game) { /** * Flag indicating whether if there are no idle instances of HTML5 Audio tag, * for any particular sound, if one of the used tags should be hijacked and used * for succeeding playback or if succeeding Phaser.Sound.HTML5AudioSound#play * call should be ignored. * * @name Phaser.Sound.HTML5AudioSoundManager#override * @type {boolean} * @default true * @since 3.0.0 */ this.override = true; /** * Value representing time difference, in seconds, between calling * play method on an audio tag and when it actually starts playing. * It is used to achieve more accurate delayed sound playback. * * You might need to tweak this value to get the desired results * since audio play delay varies depending on the browser/platform. * * @name Phaser.Sound.HTML5AudioSoundManager#audioPlayDelay * @type {number} * @default 0.1 * @since 3.0.0 */ this.audioPlayDelay = 0.1; /** * A value by which we should offset the loop end marker of the * looping sound to compensate for lag, caused by changing audio * tag playback position, in order to achieve gapless looping. * * You might need to tweak this value to get the desired results * since loop lag varies depending on the browser/platform. * * @name Phaser.Sound.HTML5AudioSoundManager#loopEndOffset * @type {number} * @default 0.05 * @since 3.0.0 */ this.loopEndOffset = 0.05; /** * An array for keeping track of all the sounds * that were paused when game lost focus. * * @name Phaser.Sound.HTML5AudioSoundManager#onBlurPausedSounds * @type {Phaser.Sound.HTML5AudioSound[]} * @private * @default [] * @since 3.0.0 */ this.onBlurPausedSounds = []; this.locked = 'ontouchstart' in window; /** * A queue of all actions performed on sound objects while audio was locked. * Once the audio gets unlocked, after an explicit user interaction, * all actions will be performed in chronological order. * Array of object types: { sound: Phaser.Sound.HTML5AudioSound, name: string, value?: * } * * @name Phaser.Sound.HTML5AudioSoundManager#lockedActionsQueue * @type {array} * @private * @since 3.0.0 */ this.lockedActionsQueue = this.locked ? [] : null; /** * Property that actually holds the value of global mute * for HTML5 Audio sound manager implementation. * * @name Phaser.Sound.HTML5AudioSoundManager#_mute * @type {boolean} * @private * @default false * @since 3.0.0 */ this._mute = false; /** * Property that actually holds the value of global volume * for HTML5 Audio sound manager implementation. * * @name Phaser.Sound.HTML5AudioSoundManager#_volume * @type {boolean} * @private * @default 1 * @since 3.0.0 */ this._volume = 1; BaseSoundManager.call(this, game); }, /** * Adds a new sound into the sound manager. * * @method Phaser.Sound.HTML5AudioSoundManager#add * @since 3.0.0 * * @param {string} key - Asset key for the sound. * @param {SoundConfig} [config] - An optional config object containing default sound settings. * * @return {Phaser.Sound.HTML5AudioSound} The new sound instance. */ add: function (key, config) { var sound = new HTML5AudioSound(this, key, config); this.sounds.push(sound); return sound; }, /** * Unlocks HTML5 Audio loading and playback on mobile * devices on the initial explicit user interaction. * * @method Phaser.Sound.HTML5AudioSoundManager#unlock * @since 3.0.0 */ unlock: function () { this.locked = false; var _this = this; this.game.cache.audio.entries.each(function (key, tags) { for (var i = 0; i < tags.length; i++) { if (tags[i].dataset.locked === 'true') { _this.locked = true; return false; } } return true; }); if (!this.locked) { return; } var moved = false; var detectMove = function () { moved = true; }; var unlock = function () { if (moved) { moved = false; return; } document.body.removeEventListener('touchmove', detectMove); document.body.removeEventListener('touchend', unlock); var lockedTags = []; _this.game.cache.audio.entries.each(function (key, tags) { for (var i = 0; i < tags.length; i++) { var tag = tags[i]; if (tag.dataset.locked === 'true') { lockedTags.push(tag); } } return true; }); if (lockedTags.length === 0) { return; } var lastTag = lockedTags[lockedTags.length - 1]; lastTag.oncanplaythrough = function () { lastTag.oncanplaythrough = null; lockedTags.forEach(function (tag) { tag.dataset.locked = 'false'; }); _this.unlocked = true; }; lockedTags.forEach(function (tag) { tag.load(); }); }; this.once('unlocked', function () { this.forEachActiveSound(function (sound) { if (sound.currentMarker === null && sound.duration === 0) { sound.duration = sound.tags[0].duration; } sound.totalDuration = sound.tags[0].duration; }); while (this.lockedActionsQueue.length) { var lockedAction = this.lockedActionsQueue.shift(); if (lockedAction.sound[lockedAction.prop].apply) { lockedAction.sound[lockedAction.prop].apply(lockedAction.sound, lockedAction.value || []); } else { lockedAction.sound[lockedAction.prop] = lockedAction.value; } } }, this); document.body.addEventListener('touchmove', detectMove, false); document.body.addEventListener('touchend', unlock, false); }, /** * Method used internally for pausing sound manager if * Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true. * * @method Phaser.Sound.HTML5AudioSoundManager#onBlur * @protected * @since 3.0.0 */ onBlur: function () { this.forEachActiveSound(function (sound) { if (sound.isPlaying) { this.onBlurPausedSounds.push(sound); sound.onBlur(); } }); }, /** * Method used internally for resuming sound manager if * Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true. * * @method Phaser.Sound.HTML5AudioSoundManager#onFocus * @protected * @since 3.0.0 */ onFocus: function () { this.onBlurPausedSounds.forEach(function (sound) { sound.onFocus(); }); this.onBlurPausedSounds.length = 0; }, /** * Calls Phaser.Sound.BaseSoundManager#destroy method * and cleans up all HTML5 Audio related stuff. * * @method Phaser.Sound.HTML5AudioSoundManager#destroy * @since 3.0.0 */ destroy: function () { BaseSoundManager.prototype.destroy.call(this); this.onBlurPausedSounds.length = 0; this.onBlurPausedSounds = null; }, /** * Method used internally by Phaser.Sound.HTML5AudioSound class methods and property setters * to check if sound manager is locked and then either perform action immediately or queue it * to be performed once the sound manager gets unlocked. * * @method Phaser.Sound.HTML5AudioSoundManager#isLocked * @protected * @since 3.0.0 * * @param {Phaser.Sound.HTML5AudioSound} sound - Sound object on which to perform queued action. * @param {string} prop - Name of the method to be called or property to be assigned a value to. * @param {*} [value] - An optional parameter that either holds an array of arguments to be passed to the method call or value to be set to the property. * * @return {boolean} Whether the sound manager is locked. */ isLocked: function (sound, prop, value) { if (sound.tags[0].dataset.locked === 'true') { this.lockedActionsQueue.push({ sound: sound, prop: prop, value: value }); return true; } return false; }, /** * @event Phaser.Sound.HTML5AudioSoundManager#muteEvent * @param {Phaser.Sound.HTML5AudioSoundManager} soundManager - Reference to the sound manager that emitted event. * @param {boolean} value - An updated value of Phaser.Sound.HTML5AudioSoundManager#mute property. */ /** * Sets the muted state of all this Sound Manager. * * @method Phaser.Sound.HTML5AudioSoundManager#setMute * @fires Phaser.Sound.HTML5AudioSoundManager#muteEvent * @since 3.3.0 * * @param {boolean} value - `true` to mute all sounds, `false` to unmute them. * * @return {Phaser.Sound.HTML5AudioSoundManager} This Sound Manager. */ setMute: function (value) { this.mute = value; return this; }, /** * @name Phaser.Sound.HTML5AudioSoundManager#mute * @type {boolean} * @fires Phaser.Sound.HTML5AudioSoundManager#muteEvent * @since 3.0.0 */ mute: { get: function () { return this._mute; }, set: function (value) { this._mute = value; this.forEachActiveSound(function (sound) { sound.updateMute(); }); this.emit('mute', this, value); } }, /** * @event Phaser.Sound.HTML5AudioSoundManager#volumeEvent * @param {Phaser.Sound.HTML5AudioSoundManager} soundManager - Reference to the sound manager that emitted event. * @param {number} value - An updated value of Phaser.Sound.HTML5AudioSoundManager#volume property. */ /** * Sets the volume of this Sound Manager. * * @method Phaser.Sound.HTML5AudioSoundManager#setVolume * @fires Phaser.Sound.HTML5AudioSoundManager#volumeEvent * @since 3.3.0 * * @param {number} value - The global volume of this Sound Manager. * * @return {Phaser.Sound.HTML5AudioSoundManager} This Sound Manager. */ setVolume: function (value) { this.volume = value; return this; }, /** * @name Phaser.Sound.HTML5AudioSoundManager#volume * @type {number} * @fires Phaser.Sound.HTML5AudioSoundManager#volumeEvent * @since 3.0.0 */ volume: { get: function () { return this._volume; }, set: function (value) { this._volume = value; this.forEachActiveSound(function (sound) { sound.updateVolume(); }); this.emit('volume', this, value); } } }); module.exports = HTML5AudioSoundManager; /***/ }), /* 191 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var HTML5AudioSoundManager = __webpack_require__(190); var NoAudioSoundManager = __webpack_require__(188); var WebAudioSoundManager = __webpack_require__(186); /** * Creates a Web Audio, HTML5 Audio or No Audio Sound Manager based on config and device settings. * * Be aware of https://developers.google.com/web/updates/2017/09/autoplay-policy-changes * * @function Phaser.Sound.SoundManagerCreator * @since 3.0.0 * * @param {Phaser.Game} game - Reference to the current game instance. */ var SoundManagerCreator = { create: function (game) { var audioConfig = game.config.audio; var deviceAudio = game.device.audio; if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData)) { return new NoAudioSoundManager(game); } if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio)) { return new WebAudioSoundManager(game); } return new HTML5AudioSoundManager(game); } }; module.exports = SoundManagerCreator; /***/ }), /* 192 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CONST = __webpack_require__(55); var GetValue = __webpack_require__(4); var Merge = __webpack_require__(94); var InjectionMap = __webpack_require__(516); /** * @namespace Phaser.Scenes.Settings */ /** * @typedef {object} Phaser.Scenes.Settings.Config * * @property {string} [key] - [description] * @property {boolean} [active=false] - [description] * @property {boolean} [visible=true] - [description] * @property {(false|Phaser.Loader.FileTypes.PackFileConfig)} [pack=false] - [description] * @property {?(InputJSONCameraObject|InputJSONCameraObject[])} [cameras=null] - [description] * @property {Object.} [map] - Overwrites the default injection map for a scene. * @property {Object.} [mapAdd] - Extends the injection map for a scene. * @property {object} [physics={}] - [description] * @property {object} [loader={}] - [description] * @property {(false|*)} [plugins=false] - [description] */ /** * @typedef {object} Phaser.Scenes.Settings.Object * * @property {number} status - [description] * @property {string} key - [description] * @property {boolean} active - [description] * @property {boolean} visible - [description] * @property {boolean} isBooted - [description] * @property {boolean} isTransition - [description] * @property {?Phaser.Scene} transitionFrom - [description] * @property {integer} transitionDuration - [description] * @property {boolean} transitionAllowInput - [description] * @property {object} data - [description] * @property {(false|Phaser.Loader.FileTypes.PackFileConfig)} pack - [description] * @property {?(InputJSONCameraObject|InputJSONCameraObject[])} cameras - [description] * @property {Object.} map - [description] * @property {object} physics - [description] * @property {object} loader - [description] * @property {(false|*)} plugins - [description] */ var Settings = { /** * Takes a Scene configuration object and returns a fully formed Systems object. * * @function Phaser.Scenes.Settings.create * @since 3.0.0 * * @param {(string|Phaser.Scenes.Settings.Config)} config - [description] * * @return {Phaser.Scenes.Settings.Object} [description] */ create: function (config) { if (typeof config === 'string') { config = { key: config }; } else if (config === undefined) { // Pass the 'hasOwnProperty' checks config = {}; } return { status: CONST.PENDING, key: GetValue(config, 'key', ''), active: GetValue(config, 'active', false), visible: GetValue(config, 'visible', true), isBooted: false, isTransition: false, transitionFrom: null, transitionDuration: 0, transitionAllowInput: true, // Loader payload array data: {}, pack: GetValue(config, 'pack', false), // Cameras cameras: GetValue(config, 'cameras', null), // Scene Property Injection Map map: GetValue(config, 'map', Merge(InjectionMap, GetValue(config, 'mapAdd', {}))), // Physics physics: GetValue(config, 'physics', {}), // Loader loader: GetValue(config, 'loader', {}), // Plugins plugins: GetValue(config, 'plugins', false), // Input input: GetValue(config, 'input', {}) }; } }; module.exports = Settings; /***/ }), /* 193 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Systems = __webpack_require__(118); /** * @classdesc * [description] * * @class Scene * @memberOf Phaser * @constructor * @since 3.0.0 * * @param {(string|Phaser.Scenes.Settings.Config)} config - Scene specific configuration settings. */ var Scene = new Class({ initialize: function Scene (config) { /** * The Scene Systems. You must never overwrite this property, or all hell will break lose. * * @name Phaser.Scene#sys * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.sys = new Systems(this, config); /** * A reference to the Phaser.Game instance. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#game * @type {Phaser.Game} * @since 3.0.0 */ this.game; /** * A reference to the global Animation Manager. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#anims * @type {Phaser.Animations.AnimationManager} * @since 3.0.0 */ this.anims; /** * A reference to the global Cache. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#cache * @type {Phaser.Cache.CacheManager} * @since 3.0.0 */ this.cache; /** * A reference to the game level Data Manager. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#registry * @type {Phaser.Data.DataManager} * @since 3.0.0 */ this.registry; /** * A reference to the Sound Manager. * This property will only be available if defined in the Scene Injection Map and the plugin is installed. * * @name Phaser.Scene#sound * @type {Phaser.Sound.BaseSoundManager} * @since 3.0.0 */ this.sound; /** * A reference to the Texture Manager. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#textures * @type {Phaser.Textures.TextureManager} * @since 3.0.0 */ this.textures; /** * A scene level Event Emitter. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#events * @type {Phaser.Events.EventEmitter} * @since 3.0.0 */ this.events; /** * A scene level Camera System. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#cameras * @type {Phaser.Cameras.Scene2D.CameraManager} * @since 3.0.0 */ this.cameras; /** * A scene level 3D Camera System. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#cameras3d * @type {Phaser.Cameras.Sprite3D.CameraManager} * @since 3.0.0 */ this.cameras3d; /** * A scene level Game Object Factory. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#add * @type {Phaser.GameObjects.GameObjectFactory} * @since 3.0.0 */ this.add; /** * A scene level Game Object Creator. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#make * @type {Phaser.GameObjects.GameObjectCreator} * @since 3.0.0 */ this.make; /** * A reference to the Scene Manager Plugin. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#scene * @type {Phaser.Scenes.ScenePlugin} * @since 3.0.0 */ this.scene; /** * A scene level Game Object Display List. * This property will only be available if defined in the Scene Injection Map. * * @name Phaser.Scene#children * @type {Phaser.GameObjects.DisplayList} * @since 3.0.0 */ this.children; /** * A scene level Lights Manager Plugin. * This property will only be available if defined in the Scene Injection Map and the plugin is installed. * * @name Phaser.Scene#lights * @type {Phaser.GameObjects.LightsManager} * @since 3.0.0 */ this.lights; /** * A scene level Data Manager Plugin. * This property will only be available if defined in the Scene Injection Map and the plugin is installed. * * @name Phaser.Scene#data * @type {Phaser.Data.DataManager} * @since 3.0.0 */ this.data; /** * A scene level Input Manager Plugin. * This property will only be available if defined in the Scene Injection Map and the plugin is installed. * * @name Phaser.Scene#input * @type {Phaser.Input.InputPlugin} * @since 3.0.0 */ this.input; /** * A scene level Loader Plugin. * This property will only be available if defined in the Scene Injection Map and the plugin is installed. * * @name Phaser.Scene#load * @type {Phaser.Loader.LoaderPlugin} * @since 3.0.0 */ this.load; /** * A scene level Time and Clock Plugin. * This property will only be available if defined in the Scene Injection Map and the plugin is installed. * * @name Phaser.Scene#time * @type {Phaser.Time.Clock} * @since 3.0.0 */ this.time; /** * A scene level Tween Manager Plugin. * This property will only be available if defined in the Scene Injection Map and the plugin is installed. * * @name Phaser.Scene#tweens * @type {Phaser.Tweens.TweenManager} * @since 3.0.0 */ this.tweens; /** * A scene level Arcade Physics Plugin. * This property will only be available if defined in the Scene Injection Map, the plugin is installed and configured. * * @name Phaser.Scene#physics * @type {Phaser.Physics.Arcade.ArcadePhysics} * @since 3.0.0 */ this.physics; /** * A scene level Impact Physics Plugin. * This property will only be available if defined in the Scene Injection Map, the plugin is installed and configured. * * @name Phaser.Scene#impact * @type {Phaser.Physics.Impact.ImpactPhysics} * @since 3.0.0 */ this.impact; /** * A scene level Matter Physics Plugin. * This property will only be available if defined in the Scene Injection Map, the plugin is installed and configured. * * @name Phaser.Scene#matter * @type {Phaser.Physics.Matter.MatterPhysics} * @since 3.0.0 */ this.matter; }, /** * Should be overridden by your own Scenes. * * @method Phaser.Scene#update * @override * @since 3.0.0 * * @param {number} time - [description] * @param {number} delta - [description] */ update: function () { } }); module.exports = Scene; /***/ }), /* 194 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(55); var GetValue = __webpack_require__(4); var NOOP = __webpack_require__(3); var Scene = __webpack_require__(193); var Systems = __webpack_require__(118); /** * @classdesc * The Scene Manager. * * The Scene Manager is a Game level system, responsible for creating, processing and updating all of the * Scenes in a Game instance. * * * @class SceneManager * @memberOf Phaser.Scenes * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - The Phaser.Game instance this Scene Manager belongs to. * @param {object} sceneConfig - Scene specific configuration settings. */ var SceneManager = new Class({ initialize: function SceneManager (game, sceneConfig) { /** * The Game that this SceneManager belongs to. * * @name Phaser.Scenes.SceneManager#game * @type {Phaser.Game} * @since 3.0.0 */ this.game = game; /** * An object that maps the keys to the scene so we can quickly get a scene from a key without iteration. * * @name Phaser.Scenes.SceneManager#keys * @type {object} * @since 3.0.0 */ this.keys = {}; /** * The array in which all of the scenes are kept. * * @name Phaser.Scenes.SceneManager#scenes * @type {array} * @since 3.0.0 */ this.scenes = []; /** * Scenes pending to be added are stored in here until the manager has time to add it. * * @name Phaser.Scenes.SceneManager#_pending * @type {array} * @private * @since 3.0.0 */ this._pending = []; /** * An array of scenes waiting to be started once the game has booted. * * @name Phaser.Scenes.SceneManager#_start * @type {array} * @private * @since 3.0.0 */ this._start = []; /** * An operations queue, because we don't manipulate the scenes array during processing. * * @name Phaser.Scenes.SceneManager#_queue * @type {array} * @private * @since 3.0.0 */ this._queue = []; /** * Boot time data to merge. * * @name Phaser.Scenes.SceneManager#_data * @type {object} * @private * @since 3.4.0 */ this._data = {}; /** * Is the Scene Manager actively processing the Scenes list? * * @name Phaser.Scenes.SceneManager#isProcessing * @type {boolean} * @default false * @readOnly * @since 3.0.0 */ this.isProcessing = false; /** * Has the Scene Manager properly started? * * @name Phaser.Scenes.SceneManager#isBooted * @type {boolean} * @default false * @readOnly * @since 3.4.0 */ this.isBooted = false; if (sceneConfig) { if (!Array.isArray(sceneConfig)) { sceneConfig = [ sceneConfig ]; } for (var i = 0; i < sceneConfig.length; i++) { // The i === 0 part just autostarts the first Scene given (unless it says otherwise in its config) this._pending.push({ key: 'default', scene: sceneConfig[i], autoStart: (i === 0), data: {} }); } } game.events.once('ready', this.bootQueue, this); }, /** * Internal first-time Scene boot handler. * * @method Phaser.Scenes.SceneManager#bootQueue * @private * @since 3.2.0 */ bootQueue: function () { if (this.isBooted) { return; } var i; var entry; var key; var sceneConfig; for (i = 0; i < this._pending.length; i++) { entry = this._pending[i]; key = entry.key; sceneConfig = entry.scene; var newScene; if (sceneConfig instanceof Scene) { newScene = this.createSceneFromInstance(key, sceneConfig); } else if (typeof sceneConfig === 'object') { newScene = this.createSceneFromObject(key, sceneConfig); } else if (typeof sceneConfig === 'function') { newScene = this.createSceneFromFunction(key, sceneConfig); } // Replace key in case the scene changed it key = newScene.sys.settings.key; this.keys[key] = newScene; this.scenes.push(newScene); // Any data to inject? if (this._data[key]) { newScene.sys.settings.data = this._data[key].data; if (this._data[key].autoStart) { entry.autoStart = true; } } if (entry.autoStart || newScene.sys.settings.active) { this._start.push(key); } } // Clear the pending lists this._pending.length = 0; this._data = {}; this.isBooted = true; // _start might have been populated by the above for (i = 0; i < this._start.length; i++) { entry = this._start[i]; this.start(entry); } this._start.length = 0; }, /** * Process the Scene operations queue. * * @method Phaser.Scenes.SceneManager#processQueue * @since 3.0.0 */ processQueue: function () { var pendingLength = this._pending.length; var queueLength = this._queue.length; if (pendingLength === 0 && queueLength === 0) { return; } var i; var entry; if (pendingLength) { for (i = 0; i < pendingLength; i++) { entry = this._pending[i]; this.add(entry.key, entry.scene, entry.autoStart, entry.data); } // _start might have been populated by this.add for (i = 0; i < this._start.length; i++) { entry = this._start[i]; this.start(entry); } // Clear the pending lists this._start.length = 0; this._pending.length = 0; return; } for (i = 0; i < this._queue.length; i++) { entry = this._queue[i]; this[entry.op](entry.keyA, entry.keyB); } this._queue.length = 0; }, /** * Adds a new Scene into the SceneManager. * You must give each Scene a unique key by which you'll identify it. * * The `sceneConfig` can be: * * * A `Phaser.Scene` object, or an object that extends it. * * A plain JavaScript object * * A JavaScript ES6 Class that extends `Phaser.Scene` * * A JavaScript ES5 prototype based Class * * A JavaScript function * * If a function is given then a new Scene will be created by calling it. * * @method Phaser.Scenes.SceneManager#add * @since 3.0.0 * * @param {string} key - A unique key used to reference the Scene, i.e. `MainMenu` or `Level1`. * @param {(Phaser.Scene|Phaser.Scenes.Settings.Config|function)} sceneConfig - The config for the Scene * @param {boolean} [autoStart=false] - If `true` the Scene will be started immediately after being added. * @param {object} [data] - Optional data object. This will be set as Scene.settings.data and passed to `Scene.init`. * * @return {?Phaser.Scene} The added Scene, if it was added immediately, otherwise `null`. */ add: function (key, sceneConfig, autoStart, data) { if (autoStart === undefined) { autoStart = false; } if (data === undefined) { data = {}; } // If processing or not booted then put scene into a holding pattern if (this.isProcessing || !this.isBooted) { this._pending.push({ key: key, scene: sceneConfig, autoStart: autoStart, data: data }); if (!this.isBooted) { this._data[key] = { data: data }; } return null; } key = this.getKey(key, sceneConfig); var newScene; if (sceneConfig instanceof Scene) { newScene = this.createSceneFromInstance(key, sceneConfig); } else if (typeof sceneConfig === 'object') { sceneConfig.key = key; newScene = this.createSceneFromObject(key, sceneConfig); } else if (typeof sceneConfig === 'function') { newScene = this.createSceneFromFunction(key, sceneConfig); } // Any data to inject? newScene.sys.settings.data = data; // Replace key in case the scene changed it key = newScene.sys.settings.key; this.keys[key] = newScene; this.scenes.push(newScene); if (autoStart || newScene.sys.settings.active) { if (this._pending.length) { this._start.push(key); } else { this.start(key); } } return newScene; }, /** * Removes a Scene from the SceneManager. * * The Scene is removed from the local scenes array, it's key is cleared from the keys * cache and Scene.Systems.destroy is then called on it. * * If the SceneManager is processing the Scenes when this method is called it wil * queue the operation for the next update sequence. * * @method Phaser.Scenes.SceneManager#remove * @since 3.2.0 * * @param {(string|Phaser.Scene)} scene - The Scene to be removed. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ remove: function (key) { if (this.isProcessing) { this._queue.push({ op: 'remove', keyA: key, keyB: null }); } else { var sceneToRemove = this.getScene(key); if (!sceneToRemove || sceneToRemove.sys.isTransitioning()) { return this; } var index = this.scenes.indexOf(sceneToRemove); var sceneKey = sceneToRemove.sys.settings.key; if (index > -1) { delete this.keys[sceneKey]; this.scenes.splice(index, 1); if (this._start.indexOf(sceneKey) > -1) { index = this._start.indexOf(sceneKey); this._start.splice(index, 1); } sceneToRemove.sys.destroy(); } } return this; }, /** * Boot the given Scene. * * @method Phaser.Scenes.SceneManager#bootScene * @private * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene to boot. */ bootScene: function (scene) { var sys = scene.sys; var settings = sys.settings; if (scene.init) { scene.init.call(scene, settings.data); if (settings.isTransition) { sys.events.emit('transitioninit', settings.transitionFrom, settings.transitionDuration); } } var loader; if (sys.load) { loader = sys.load; loader.reset(); } if (loader && scene.preload) { scene.preload.call(scene); // Is the loader empty? if (loader.list.size === 0) { this.create(scene); } else { settings.status = CONST.LOADING; // Start the loader going as we have something in the queue loader.once('complete', this.loadComplete, this); loader.start(); } } else { // No preload? Then there was nothing to load either this.create(scene); } }, /** * Handles load completion for a Scene's Loader. * * Starts the Scene that the Loader belongs to. * * @method Phaser.Scenes.SceneManager#loadComplete * @private * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - The loader that has completed loading. */ loadComplete: function (loader) { var scene = loader.scene; // Try to unlock HTML5 sounds every time any loader completes if (this.game.sound.onBlurPausedSounds) { this.game.sound.unlock(); } this.create(scene); }, /** * Handle payload completion for a Scene. * * @method Phaser.Scenes.SceneManager#payloadComplete * @private * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - The loader that has completed loading its Scene's payload. */ payloadComplete: function (loader) { this.bootScene(loader.scene); }, /** * Updates the Scenes. * * @method Phaser.Scenes.SceneManager#update * @since 3.0.0 * * @param {number} time - Time elapsed. * @param {number} delta - Delta time from the last update. */ update: function (time, delta) { this.processQueue(); this.isProcessing = true; // Loop through the active scenes in reverse order for (var i = this.scenes.length - 1; i >= 0; i--) { var sys = this.scenes[i].sys; if (sys.settings.status > CONST.START && sys.settings.status <= CONST.RUNNING) { sys.step(time, delta); } } }, /** * Informs the Scenes of the Game being resized. * * @method Phaser.Scenes.SceneManager#resize * @since 3.2.0 * * @param {number} width - The new width of the game. * @param {number} height - The new height of the game. */ resize: function (width, height) { // Loop through the scenes in forward order for (var i = 0; i < this.scenes.length; i++) { var sys = this.scenes[i].sys; sys.resize(width, height); } }, /** * Renders the Scenes. * * @method Phaser.Scenes.SceneManager#render * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The renderer to use. */ render: function (renderer) { // Loop through the scenes in forward order for (var i = 0; i < this.scenes.length; i++) { var sys = this.scenes[i].sys; if (sys.settings.visible && sys.settings.status >= CONST.LOADING && sys.settings.status < CONST.SLEEPING) { sys.render(renderer); } } this.isProcessing = false; }, /** * Calls the given Scene's {@link Phaser.Scene#create} method and updates its status. * * @method Phaser.Scenes.SceneManager#create * @private * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene to create. */ create: function (scene) { var sys = scene.sys; var settings = sys.settings; if (scene.create) { scene.sys.settings.status = CONST.CREATING; scene.create.call(scene, scene.sys.settings.data); if (settings.isTransition) { sys.events.emit('transitionstart', settings.transitionFrom, settings.transitionDuration); } } // If the Scene has an update function we'll set it now, otherwise it'll remain as NOOP if (scene.update) { sys.sceneUpdate = scene.update; } settings.status = CONST.RUNNING; }, /** * Creates and initializes a Scene from a function. * * @method Phaser.Scenes.SceneManager#createSceneFromFunction * @private * @since 3.0.0 * * @param {string} key - The key of the Scene. * @param {function} scene - The function to create the Scene from. * * @return {Phaser.Scene} The created Scene. */ createSceneFromFunction: function (key, scene) { var newScene = new scene(); if (newScene instanceof Scene) { var configKey = newScene.sys.settings.key; if (configKey !== '') { key = configKey; } if (this.keys.hasOwnProperty(key)) { throw new Error('Cannot add a Scene with duplicate key: ' + key); } return this.createSceneFromInstance(key, newScene); } else { newScene.sys = new Systems(newScene); newScene.sys.settings.key = key; newScene.sys.init(this.game); return newScene; } }, /** * Creates and initializes a Scene instance. * * @method Phaser.Scenes.SceneManager#createSceneFromInstance * @private * @since 3.0.0 * * @param {string} key - The key of the Scene. * @param {Phaser.Scene} newScene - The Scene instance. * * @return {Phaser.Scene} The created Scene. */ createSceneFromInstance: function (key, newScene) { var configKey = newScene.sys.settings.key; if (configKey !== '') { key = configKey; } else { newScene.sys.settings.key = key; } newScene.sys.init(this.game); return newScene; }, /** * Creates and initializes a Scene from an Object definition. * * @method Phaser.Scenes.SceneManager#createSceneFromObject * @private * @since 3.0.0 * * @param {string} key - The key of the Scene. * @param {(string|Phaser.Scenes.Settings.Config)} sceneConfig - The Scene config. * * @return {Phaser.Scene} The created Scene. */ createSceneFromObject: function (key, sceneConfig) { var newScene = new Scene(sceneConfig); var configKey = newScene.sys.settings.key; if (configKey !== '') { key = configKey; } else { newScene.sys.settings.key = key; } newScene.sys.init(this.game); // Extract callbacks var defaults = [ 'init', 'preload', 'create', 'update', 'render' ]; for (var i = 0; i < defaults.length; i++) { var sceneCallback = GetValue(sceneConfig, defaults[i], null); if (sceneCallback) { newScene[defaults[i]] = sceneCallback; } } // Now let's move across any other functions or properties that may exist in the extend object: /* scene: { preload: preload, create: create, extend: { hello: 1, test: 'atari', addImage: addImage } } */ if (sceneConfig.hasOwnProperty('extend')) { for (var propertyKey in sceneConfig.extend) { var value = sceneConfig.extend[propertyKey]; if (propertyKey === 'data' && newScene.hasOwnProperty('data') && typeof value === 'object') { // Populate the DataManager newScene.data.merge(value); } else if (propertyKey !== 'sys') { newScene[propertyKey] = value; } } } return newScene; }, /** * Retrieves the key of a Scene from a Scene config. * * @method Phaser.Scenes.SceneManager#getKey * @private * @since 3.0.0 * * @param {string} key - The key to check in the Scene config. * @param {(Phaser.Scene|Phaser.Scenes.Settings.Config|function)} sceneConfig - The Scene config. * * @return {string} The Scene key. */ getKey: function (key, sceneConfig) { if (!key) { key = 'default'; } if (typeof sceneConfig === 'function') { return key; } else if (sceneConfig instanceof Scene) { key = sceneConfig.sys.settings.key; } else if (typeof sceneConfig === 'object' && sceneConfig.hasOwnProperty('key')) { key = sceneConfig.key; } // By this point it's either 'default' or extracted from the Scene if (this.keys.hasOwnProperty(key)) { throw new Error('Cannot add a Scene with duplicate key: ' + key); } else { return key; } }, /** * Retrieves a Scene. * * @method Phaser.Scenes.SceneManager#getScene * @since 3.0.0 * * @param {string|Phaser.Scene} key - The Scene to retrieve. * * @return {?Phaser.Scene} The Scene. */ getScene: function (key) { if (typeof key === 'string') { if (this.keys[key]) { return this.keys[key]; } } else { for (var i = 0; i < this.scenes.length; i++) { if (key === this.scenes[i]) { return key; } } } return null; }, /** * Determines whether a Scene is active. * * @method Phaser.Scenes.SceneManager#isActive * @since 3.0.0 * * @param {string} key - The Scene to check. * * @return {boolean} Whether the Scene is active. */ isActive: function (key) { var scene = this.getScene(key); if (scene) { return scene.sys.isActive(); } return null; }, /** * Determines whether a Scene is visible. * * @method Phaser.Scenes.SceneManager#isVisible * @since 3.0.0 * * @param {string} key - The Scene to check. * * @return {boolean} Whether the Scene is visible. */ isVisible: function (key) { var scene = this.getScene(key); if (scene) { return scene.sys.isVisible(); } return null; }, /** * Determines whether a Scene is sleeping. * * @method Phaser.Scenes.SceneManager#isSleeping * @since 3.0.0 * * @param {string} key - The Scene to check. * * @return {boolean} Whether the Scene is sleeping. */ isSleeping: function (key) { var scene = this.getScene(key); if (scene) { return scene.sys.isSleeping(); } return null; }, /** * Pauses the given Scene. * * @method Phaser.Scenes.SceneManager#pause * @since 3.0.0 * * @param {string} key - The Scene to pause. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ pause: function (key) { var scene = this.getScene(key); if (scene) { scene.sys.pause(); } return this; }, /** * Resumes the given Scene. * * @method Phaser.Scenes.SceneManager#resume * @since 3.0.0 * * @param {string} key - The Scene to resume. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ resume: function (key) { var scene = this.getScene(key); if (scene) { scene.sys.resume(); } return this; }, /** * Puts the given Scene to sleep. * * @method Phaser.Scenes.SceneManager#sleep * @since 3.0.0 * * @param {string} key - The Scene to put to sleep. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ sleep: function (key) { var scene = this.getScene(key); if (scene && !scene.sys.isTransitioning()) { scene.sys.sleep(); } return this; }, /** * Awakens the given Scene. * * @method Phaser.Scenes.SceneManager#wake * @since 3.0.0 * * @param {string} key - The Scene to wake up. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ wake: function (key) { var scene = this.getScene(key); if (scene) { scene.sys.wake(); } return this; }, /** * Runs the given Scene, but does not change the state of this Scene. * * If the given Scene is paused, it will resume it. If sleeping, it will wake it. * If not running at all, it will be started. * * Use this if you wish to open a modal Scene by calling `pause` on the current * Scene, then `run` on the modal Scene. * * @method Phaser.Scenes.SceneManager#run * @since 3.10.0 * * @param {string} key - The Scene to run. * @param {object} [data] - A data object that will be passed to the Scene that is run _only if the Scene isn't asleep or paused_. * * @return {Phaser.Scenes.SceneManager} This Scene Manager. */ run: function (key, data) { var scene = this.getScene(key); if (!scene) { return this; } if (scene.sys.isSleeping()) { // Sleeping? scene.sys.wake(); } else if (scene.sys.isBooted && !scene.sys.isActive()) { // Paused? scene.sys.resume(); } else { // Not actually running? this.start(key, data); } }, /** * Starts the given Scene. * * @method Phaser.Scenes.SceneManager#start * @since 3.0.0 * * @param {string} key - The Scene to start. * @param {object} [data] - Optional data object to pass to Scene.Settings and Scene.init. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ start: function (key, data) { // If the Scene Manager is not running, then put the Scene into a holding pattern if (!this.isBooted) { this._data[key] = { autoStart: true, data: data }; return this; } var scene = this.getScene(key); if (scene) { scene.sys.start(data); var loader; if (scene.sys.load) { loader = scene.sys.load; } // Files payload? if (loader && scene.sys.settings.hasOwnProperty('pack')) { loader.reset(); if (loader.addPack({ payload: scene.sys.settings.pack })) { scene.sys.settings.status = CONST.LOADING; loader.once('complete', this.payloadComplete, this); loader.start(); return this; } } this.bootScene(scene); } return this; }, /** * Stops the given Scene. * * @method Phaser.Scenes.SceneManager#stop * @since 3.0.0 * * @param {string} key - The Scene to stop. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ stop: function (key) { var scene = this.getScene(key); if (scene && !scene.sys.isTransitioning()) { scene.sys.shutdown(); } return this; }, /** * Sleeps one one Scene and starts the other. * * @method Phaser.Scenes.SceneManager#switch * @since 3.0.0 * * @param {string} from - The Scene to sleep. * @param {string} to - The Scene to start. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ switch: function (from, to) { var sceneA = this.getScene(from); var sceneB = this.getScene(to); if (sceneA && sceneB && sceneA !== sceneB) { this.sleep(from); if (this.isSleeping(to)) { this.wake(to); } else { this.start(to); } } return this; }, /** * Retrieves a Scene by numeric index. * * @method Phaser.Scenes.SceneManager#getAt * @since 3.0.0 * * @param {integer} index - The index of the Scene to retrieve. * * @return {(Phaser.Scene|undefined)} The Scene. */ getAt: function (index) { return this.scenes[index]; }, /** * Retrieves the numeric index of a Scene. * * @method Phaser.Scenes.SceneManager#getIndex * @since 3.0.0 * * @param {(string|Phaser.Scene)} key - The key of the Scene. * * @return {integer} The index of the Scene. */ getIndex: function (key) { var scene = this.getScene(key); return this.scenes.indexOf(scene); }, /** * Brings a Scene to the top of the Scenes list. * * This means it will render above all other Scenes. * * @method Phaser.Scenes.SceneManager#bringToTop * @since 3.0.0 * * @param {(string|Phaser.Scene)} key - The Scene to move. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ bringToTop: function (key) { if (this.isProcessing) { this._queue.push({ op: 'bringToTop', keyA: key, keyB: null }); } else { var index = this.getIndex(key); if (index !== -1 && index < this.scenes.length) { var scene = this.getScene(key); this.scenes.splice(index, 1); this.scenes.push(scene); } } return this; }, /** * Sends a Scene to the back of the Scenes list. * * This means it will render below all other Scenes. * * @method Phaser.Scenes.SceneManager#sendToBack * @since 3.0.0 * * @param {(string|Phaser.Scene)} key - The Scene to move. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ sendToBack: function (key) { if (this.isProcessing) { this._queue.push({ op: 'sendToBack', keyA: key, keyB: null }); } else { var index = this.getIndex(key); if (index !== -1 && index > 0) { var scene = this.getScene(key); this.scenes.splice(index, 1); this.scenes.unshift(scene); } } return this; }, /** * Moves a Scene down one position in the Scenes list. * * @method Phaser.Scenes.SceneManager#moveDown * @since 3.0.0 * * @param {(string|Phaser.Scene)} key - The Scene to move. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ moveDown: function (key) { if (this.isProcessing) { this._queue.push({ op: 'moveDown', keyA: key, keyB: null }); } else { var indexA = this.getIndex(key); if (indexA > 0) { var indexB = indexA - 1; var sceneA = this.getScene(key); var sceneB = this.getAt(indexB); this.scenes[indexA] = sceneB; this.scenes[indexB] = sceneA; } } return this; }, /** * Moves a Scene up one position in the Scenes list. * * @method Phaser.Scenes.SceneManager#moveUp * @since 3.0.0 * * @param {(string|Phaser.Scene)} key - The Scene to move. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ moveUp: function (key) { if (this.isProcessing) { this._queue.push({ op: 'moveUp', keyA: key, keyB: null }); } else { var indexA = this.getIndex(key); if (indexA < this.scenes.length - 1) { var indexB = indexA + 1; var sceneA = this.getScene(key); var sceneB = this.getAt(indexB); this.scenes[indexA] = sceneB; this.scenes[indexB] = sceneA; } } return this; }, /** * Moves a Scene so it is immediately above another Scene in the Scenes list. * * This means it will render over the top of the other Scene. * * @method Phaser.Scenes.SceneManager#moveAbove * @since 3.2.0 * * @param {(string|Phaser.Scene)} keyA - The Scene that Scene B will be moved above. * @param {(string|Phaser.Scene)} keyB - The Scene to be moved. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ moveAbove: function (keyA, keyB) { if (keyA === keyB) { return this; } if (this.isProcessing) { this._queue.push({ op: 'moveAbove', keyA: keyA, keyB: keyB }); } else { var indexA = this.getIndex(keyA); var indexB = this.getIndex(keyB); if (indexA !== -1 && indexB !== -1) { var tempScene = this.getAt(indexB); // Remove this.scenes.splice(indexB, 1); // Add in new location this.scenes.splice(indexA + 1, 0, tempScene); } } return this; }, /** * Moves a Scene so it is immediately below another Scene in the Scenes list. * * This means it will render behind the other Scene. * * @method Phaser.Scenes.SceneManager#moveBelow * @since 3.2.0 * * @param {(string|Phaser.Scene)} keyA - The Scene that Scene B will be moved above. * @param {(string|Phaser.Scene)} keyB - The Scene to be moved. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ moveBelow: function (keyA, keyB) { if (keyA === keyB) { return this; } if (this.isProcessing) { this._queue.push({ op: 'moveBelow', keyA: keyA, keyB: keyB }); } else { var indexA = this.getIndex(keyA); var indexB = this.getIndex(keyB); if (indexA !== -1 && indexB !== -1) { var tempScene = this.getAt(indexB); // Remove this.scenes.splice(indexB, 1); if (indexA === 0) { this.scenes.unshift(tempScene); } else { // Add in new location this.scenes.splice(indexA, 0, tempScene); } } } return this; }, /** * Queue a Scene operation for the next update. * * @method Phaser.Scenes.SceneManager#queueOp * @private * @since 3.0.0 * * @param {string} op - The operation to perform. * @param {(string|Phaser.Scene)} keyA - Scene A. * @param {(string|Phaser.Scene)} [keyB] - Scene B. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ queueOp: function (op, keyA, keyB) { this._queue.push({ op: op, keyA: keyA, keyB: keyB }); return this; }, /** * Swaps the positions of two Scenes in the Scenes list. * * @method Phaser.Scenes.SceneManager#swapPosition * @since 3.0.0 * * @param {(string|Phaser.Scene)} keyA - The first Scene to swap. * @param {(string|Phaser.Scene)} keyB - The second Scene to swap. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ swapPosition: function (keyA, keyB) { if (keyA === keyB) { return this; } if (this.isProcessing) { this._queue.push({ op: 'swapPosition', keyA: keyA, keyB: keyB }); } else { var indexA = this.getIndex(keyA); var indexB = this.getIndex(keyB); if (indexA !== indexB && indexA !== -1 && indexB !== -1) { var tempScene = this.getAt(indexA); this.scenes[indexA] = this.scenes[indexB]; this.scenes[indexB] = tempScene; } } return this; }, /** * Dumps debug information about each Scene to the developer console. * * @method Phaser.Scenes.SceneManager#dump * @since 3.2.0 */ dump: function () { var out = []; var map = [ 'pending', 'init', 'start', 'loading', 'creating', 'running', 'paused', 'sleeping', 'shutdown', 'destroyed' ]; for (var i = 0; i < this.scenes.length; i++) { var sys = this.scenes[i].sys; var key = (sys.settings.visible && (sys.settings.status === CONST.RUNNING || sys.settings.status === CONST.PAUSED)) ? '[*] ' : '[-] '; key += sys.settings.key + ' (' + map[sys.settings.status] + ')'; out.push(key); } console.log(out.join('\n')); }, /** * Destroy the SceneManager and all of its Scene's systems. * * @method Phaser.Scenes.SceneManager#destroy * @since 3.0.0 */ destroy: function () { for (var i = this.scenes.length - 1; i >= 0; i--) { var sys = this.scenes[i].sys; sys.destroy(); } this.update = NOOP; this.scenes = []; this._pending = []; this._start = []; this._queue = []; this.game = null; } }); module.exports = SceneManager; /***/ }), /* 195 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SpliceOne = __webpack_require__(56); /** * Removes the given item, or array of items, from the array. * * The array is modified in-place. * * You can optionally specify a callback to be invoked for each item successfully removed from the array. * * @function Phaser.Utils.Array.Remove * @since 3.4.0 * * @param {array} array - The array to be modified. * @param {*|Array.<*>} item - The item, or array of items, to be removed from the array. * @param {function} [callback] - A callback to be invoked for each item successfully removed from the array. * @param {object} [context] - The context in which the callback is invoked. * * @return {*|Array.<*>} The item, or array of items, that were successfully removed from the array. */ var Remove = function (array, item, callback, context) { if (context === undefined) { context = array; } var index; // Fast path to avoid array mutation and iteration if (!Array.isArray(item)) { index = array.indexOf(item); if (index !== -1) { SpliceOne(array, index); if (callback) { callback.call(context, item); } return item; } else { return null; } } // If we got this far, we have an array of items to remove var itemLength = item.length - 1; while (itemLength >= 0) { var entry = item[itemLength]; index = array.indexOf(entry); if (index !== -1) { SpliceOne(array, index); if (callback) { callback.call(context, entry); } } else { // Item wasn't found in the array, so remove it from our return results item.pop(); } itemLength--; } return item; }; module.exports = Remove; /***/ }), /* 196 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var EventEmitter = __webpack_require__(9); var FileTypesManager = __webpack_require__(7); var GameObjectCreator = __webpack_require__(13); var GameObjectFactory = __webpack_require__(11); var GetFastValue = __webpack_require__(1); var PluginCache = __webpack_require__(12); var Remove = __webpack_require__(195); /** * @typedef {object} GlobalPlugin * * @property {string} key - The unique name of this plugin within the plugin cache. * @property {function} plugin - An instance of the plugin. * @property {boolean} [active] - Is the plugin active or not? * @property {string} [mapping] - If this plugin is to be injected into the Scene Systems, this is the property key map used. */ /** * @classdesc * The PluginManager is responsible for installing and adding plugins to Phaser. * * It is a global system and therefore belongs to the Game instance, not a specific Scene. * * It works in conjunction with the PluginCache. Core internal plugins automatically register themselves * with the Cache, but it's the Plugin Manager that is responsible for injecting them into the Scenes. * * There are two types of plugin: * * 1) A Global Plugin * 2) A Scene Plugin * * A Global Plugin is a plugin that lives within the Plugin Manager rather than a Scene. You can get * access to it by calling `PluginManager.get` and providing a key. Any Scene that requests a plugin in * this way will all get access to the same plugin instance, allowing you to use a single plugin across * multiple Scenes. * * A Scene Plugin is a plugin dedicated to running within a Scene. These are different to Global Plugins * in that their instances do not live within the Plugin Manager, but within the Scene Systems class instead. * And that every Scene created is given its own unique instance of a Scene Plugin. Examples of core Scene * Plugins include the Input Plugin, the Tween Plugin and the physics Plugins. * * You can add a plugin to Phaser in three different ways: * * 1) Preload it * 2) Include it in your source code and install it via the Game Config * 3) Include it in your source code and install it within a Scene * * For examples of all of these approaches please see the Phaser 3 Examples Repo `plugins` folder. * * For information on creating your own plugin please see the Phaser 3 Plugin Template. * * @class PluginManager * @memberOf Phaser.Plugins * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - The game instance that owns this Plugin Manager. */ var PluginManager = new Class({ Extends: EventEmitter, initialize: function PluginManager (game) { EventEmitter.call(this); /** * The game instance that owns this Plugin Manager. * * @name Phaser.Plugins.PluginManager#game * @type {Phaser.Game} * @since 3.0.0 */ this.game = game; /** * The global plugins currently running and managed by this Plugin Manager. * A plugin must have been started at least once in order to appear in this list. * * @name Phaser.Plugins.PluginManager#plugins * @type {GlobalPlugin[]} * @since 3.8.0 */ this.plugins = []; /** * A list of plugin keys that should be installed into Scenes as well as the Core Plugins. * * @name Phaser.Plugins.PluginManager#scenePlugins * @type {string[]} * @since 3.8.0 */ this.scenePlugins = []; /** * A temporary list of plugins to install when the game has booted. * * @name Phaser.Plugins.PluginManager#_pendingGlobal * @private * @type {array} * @since 3.8.0 */ this._pendingGlobal = []; /** * A temporary list of scene plugins to install when the game has booted. * * @name Phaser.Plugins.PluginManager#_pendingScene * @private * @type {array} * @since 3.8.0 */ this._pendingScene = []; if (game.isBooted) { this.boot(); } else { game.events.once('boot', this.boot, this); } }, /** * Run once the game has booted and installs all of the plugins configured in the Game Config. * * @method Phaser.Plugins.PluginManager#boot * @protected * @since 3.0.0 */ boot: function () { var i; var entry; var key; var plugin; var start; var mapping; var config = this.game.config; // Any plugins to install? var list = config.installGlobalPlugins; // Any plugins added outside of the game config, but before the game booted? list = list.concat(this._pendingGlobal); for (i = 0; i < list.length; i++) { entry = list[i]; // { key: 'TestPlugin', plugin: TestPlugin, start: true, mapping: 'test' } key = GetFastValue(entry, 'key', null); plugin = GetFastValue(entry, 'plugin', null); start = GetFastValue(entry, 'start', false); mapping = GetFastValue(entry, 'mapping', null); if (key && plugin) { this.install(key, plugin, start, mapping); } } // Any scene plugins to install? list = config.installScenePlugins; // Any plugins added outside of the game config, but before the game booted? list = list.concat(this._pendingScene); for (i = 0; i < list.length; i++) { entry = list[i]; // { key: 'moveSpritePlugin', plugin: MoveSpritePlugin, , mapping: 'move' } key = GetFastValue(entry, 'key', null); plugin = GetFastValue(entry, 'plugin', null); mapping = GetFastValue(entry, 'mapping', null); if (key && plugin) { this.installScenePlugin(key, plugin, mapping); } } this._pendingGlobal = []; this._pendingScene = []; this.game.events.once('destroy', this.destroy, this); }, /** * Called by the Scene Systems class. Tells the plugin manager to install all Scene plugins into it. * * First it will install global references, i.e. references from the Game systems into the Scene Systems (and Scene if mapped.) * Then it will install Core Scene Plugins followed by Scene Plugins registered with the PluginManager. * Finally it will install any references to Global Plugins that have a Scene mapping property into the Scene itself. * * @method Phaser.Plugins.PluginManager#addToScene * @protected * @since 3.8.0 * * @param {Phaser.Scenes.Systems} sys - The Scene Systems class to install all the plugins in to. * @param {array} globalPlugins - An array of global plugins to install. * @param {array} scenePlugins - An array of scene plugins to install. */ addToScene: function (sys, globalPlugins, scenePlugins) { var i; var pluginKey; var pluginList; var game = this.game; var scene = sys.scene; var map = sys.settings.map; var isBooted = sys.settings.isBooted; // Reference the GlobalPlugins from Game into Scene.Systems for (i = 0; i < globalPlugins.length; i++) { pluginKey = globalPlugins[i]; if (game[pluginKey]) { sys[pluginKey] = game[pluginKey]; // Scene level injection if (map.hasOwnProperty(pluginKey)) { scene[map[pluginKey]] = sys[pluginKey]; } } } for (var s = 0; s < scenePlugins.length; s++) { pluginList = scenePlugins[s]; for (i = 0; i < pluginList.length; i++) { pluginKey = pluginList[i]; if (!PluginCache.hasCore(pluginKey)) { continue; } var source = PluginCache.getCore(pluginKey); var plugin = new source.plugin(scene, this); sys[source.mapping] = plugin; // Scene level injection if (source.custom) { scene[source.mapping] = plugin; } else if (map.hasOwnProperty(source.mapping)) { scene[map[source.mapping]] = plugin; } // Scene is already booted, usually because this method is being called at run-time, so boot the plugin if (isBooted) { plugin.boot(); } } } // And finally, inject any 'global scene plugins' pluginList = this.plugins; for (i = 0; i < pluginList.length; i++) { var entry = pluginList[i]; if (entry.mapping) { scene[entry.mapping] = entry.plugin; } } }, /** * Called by the Scene Systems class. Returns a list of plugins to be installed. * * @method Phaser.Plugins.PluginManager#getDefaultScenePlugins * @protected * @since 3.8.0 * * @return {string[]} A list keys of all the Scene Plugins to install. */ getDefaultScenePlugins: function () { var list = this.game.config.defaultPlugins; // Merge in custom Scene plugins list = list.concat(this.scenePlugins); return list; }, /** * Installs a new Scene Plugin into the Plugin Manager and optionally adds it * to the given Scene as well. A Scene Plugin added to the manager in this way * will be automatically installed into all new Scenes using the key and mapping given. * * The `key` property is what the plugin is injected into Scene.Systems as. * The `mapping` property is optional, and if specified is what the plugin is installed into * the Scene as. For example: * * ```javascript * this.plugins.installScenePlugin('powerupsPlugin', pluginCode, 'powerups'); * * // and from within the scene: * this.sys.powerupsPlugin; // key value * this.powerups; // mapping value * ``` * * This method is called automatically by Phaser if you install your plugins using either the * Game Configuration object, or by preloading them via the Loader. * * @method Phaser.Plugins.PluginManager#installScenePlugin * @since 3.8.0 * * @param {string} key - The property key that will be used to add this plugin to Scene.Systems. * @param {function} plugin - The plugin code. This should be the non-instantiated version. * @param {string} [mapping] - If this plugin is injected into the Phaser.Scene class, this is the property key to use. * @param {Phaser.Scene} [addToScene] - Optionally automatically add this plugin to the given Scene. */ installScenePlugin: function (key, plugin, mapping, addToScene) { if (typeof plugin !== 'function') { console.warn('Invalid Scene Plugin: ' + key); return; } if (PluginCache.hasCore(key)) { console.warn('Scene Plugin key in use: ' + key); return; } PluginCache.register(key, plugin, mapping, true); this.scenePlugins.push(key); if (addToScene) { var instance = new plugin(addToScene, this); addToScene.sys[key] = instance; if (mapping && mapping !== '') { addToScene[mapping] = instance; } instance.boot(); } }, /** * Installs a new Global Plugin into the Plugin Manager and optionally starts it running. * A global plugin belongs to the Plugin Manager, rather than a specific Scene, and can be accessed * and used by all Scenes in your game. * * The `key` property is what you use to access this plugin from the Plugin Manager. * * ```javascript * this.plugins.install('powerupsPlugin', pluginCode); * * // and from within the scene: * this.plugins.get('powerupsPlugin'); * ``` * * This method is called automatically by Phaser if you install your plugins using either the * Game Configuration object, or by preloading them via the Loader. * * The same plugin can be installed multiple times into the Plugin Manager by simply giving each * instance its own unique key. * * @method Phaser.Plugins.PluginManager#install * @since 3.8.0 * * @param {string} key - The unique handle given to this plugin within the Plugin Manager. * @param {function} plugin - The plugin code. This should be the non-instantiated version. * @param {boolean} [start=false] - Automatically start the plugin running? This is always `true` if you provide a mapping value. * @param {string} [mapping] - If this plugin is injected into the Phaser.Scene class, this is the property key to use. */ install: function (key, plugin, start, mapping) { if (start === undefined) { start = false; } if (mapping === undefined) { mapping = null; } if (typeof plugin !== 'function') { console.warn('Invalid Plugin: ' + key); return; } if (PluginCache.hasCustom(key)) { console.warn('Plugin key in use: ' + key); return; } if (mapping !== null) { start = true; } if (!this.game.isBooted) { this._pendingGlobal.push({ key: key, plugin: plugin, start: start, mapping: mapping }); } else { // Add it to the plugin store PluginCache.registerCustom(key, plugin, mapping); if (start) { return this.start(key); } } }, /** * Gets an index of a global plugin based on the given key. * * @method Phaser.Plugins.PluginManager#getIndex * @protected * @since 3.8.0 * * @param {string} key - The unique plugin key. * * @return {integer} The index of the plugin within the plugins array. */ getIndex: function (key) { var list = this.plugins; for (var i = 0; i < list.length; i++) { var entry = list[i]; if (entry.key === key) { return i; } } return -1; }, /** * Gets a global plugin based on the given key. * * @method Phaser.Plugins.PluginManager#getEntry * @protected * @since 3.8.0 * * @param {string} key - The unique plugin key. * * @return {GlobalPlugin} The plugin entry. */ getEntry: function (key) { var idx = this.getIndex(key); if (idx !== -1) { return this.plugins[idx]; } }, /** * Checks if the given global plugin, based on its key, is active or not. * * @method Phaser.Plugins.PluginManager#isActive * @since 3.8.0 * * @param {string} key - The unique plugin key. * * @return {boolean} `true` if the plugin is active, otherwise `false`. */ isActive: function (key) { var entry = this.getEntry(key); return (entry && entry.active); }, /** * Starts a global plugin running. * * If the plugin was previously active then calling `start` will reset it to an active state and then * call its `start` method. * * If the plugin has never been run before a new instance of it will be created within the Plugin Manager, * its active state set and then both of its `init` and `start` methods called, in that order. * * If the plugin is already running under the given key then nothing happens. * * @method Phaser.Plugins.PluginManager#start * @since 3.8.0 * * @param {string} key - The key of the plugin to start. * @param {string} [runAs] - Run the plugin under a new key. This allows you to run one plugin multiple times. * * @return {?Phaser.Plugins.BasePlugin} The plugin that was started, or `null` if invalid key given or plugin is already stopped. */ start: function (key, runAs) { if (runAs === undefined) { runAs = key; } var entry = this.getEntry(runAs); // Plugin already running under this key? if (entry && !entry.active) { // It exists, we just need to start it up again entry.active = true; entry.plugin.start(); } else if (!entry) { entry = this.createEntry(key, runAs); } return (entry) ? entry.plugin : null; }, /** * Creates a new instance of a global plugin, adds an entry into the plugins array and returns it. * * @method Phaser.Plugins.PluginManager#createEntry * @private * @since 3.9.0 * * @param {string} key - The key of the plugin to create an instance of. * @param {string} [runAs] - Run the plugin under a new key. This allows you to run one plugin multiple times. * * @return {?Phaser.Plugins.BasePlugin} The plugin that was started, or `null` if invalid key given. */ createEntry: function (key, runAs) { var entry = PluginCache.getCustom(key); if (entry) { var instance = new entry.plugin(this); entry = { key: runAs, plugin: instance, active: true, mapping: entry.mapping }; this.plugins.push(entry); instance.init(); instance.start(); } return entry; }, /** * Stops a global plugin from running. * * If the plugin is active then its active state will be set to false and the plugins `stop` method * will be called. * * If the plugin is not already running, nothing will happen. * * @method Phaser.Plugins.PluginManager#stop * @since 3.8.0 * * @param {string} key - The key of the plugin to stop. * * @return {Phaser.Plugins.PluginManager} The Plugin Manager. */ stop: function (key) { var entry = this.getEntry(key); if (entry && entry.active) { entry.active = false; entry.plugin.stop(); } return this; }, /** * Gets a global plugin from the Plugin Manager based on the given key and returns it. * * If it cannot find an active plugin based on the key, but there is one in the Plugin Cache with the same key, * then it will create a new instance of the cached plugin and return that. * * @method Phaser.Plugins.PluginManager#get * @since 3.8.0 * * @param {string} key - The key of the plugin to get. * @param {boolean} [autoStart=true] - Automatically start a new instance of the plugin if found in the cache, but not actively running. * * @return {?(Phaser.Plugins.BasePlugin|function)} The plugin, or `null` if no plugin was found matching the key. */ get: function (key, autoStart) { if (autoStart === undefined) { autoStart = true; } var entry = this.getEntry(key); if (entry) { return entry.plugin; } else { var plugin = this.getClass(key); if (plugin && autoStart) { entry = this.createEntry(key, key); return (entry) ? entry.plugin : null; } else if (plugin) { return plugin; } } return null; }, /** * Returns the plugin class from the cache. * Used internally by the Plugin Manager. * * @method Phaser.Plugins.PluginManager#getClass * @since 3.8.0 * * @param {string} key - The key of the plugin to get. * * @return {Phaser.Plugins.BasePlugin} A Plugin object */ getClass: function (key) { return PluginCache.getCustomClass(key); }, /** * Removes a global plugin from the Plugin Manager and Plugin Cache. * * It is up to you to remove all references to this plugin that you may hold within your game code. * * @method Phaser.Plugins.PluginManager#removeGlobalPlugin * @since 3.8.0 * * @param {string} key - The key of the plugin to remove. */ removeGlobalPlugin: function (key) { var entry = this.getEntry(key); if (entry) { Remove(this.plugins, entry); } PluginCache.removeCustom(key); }, /** * Removes a scene plugin from the Plugin Manager and Plugin Cache. * * This will not remove the plugin from any active Scenes that are already using it. * * It is up to you to remove all references to this plugin that you may hold within your game code. * * @method Phaser.Plugins.PluginManager#removeScenePlugin * @since 3.8.0 * * @param {string} key - The key of the plugin to remove. */ removeScenePlugin: function (key) { Remove(this.scenePlugins, key); PluginCache.remove(key); }, /** * Registers a new type of Game Object with the global Game Object Factory and / or Creator. * This is usually called from within your Plugin code and is a helpful short-cut for creating * new Game Objects. * * The key is the property that will be injected into the factories and used to create the * Game Object. For example: * * ```javascript * this.plugins.registerGameObject('clown', clownFactoryCallback, clownCreatorCallback); * // later in your game code: * this.add.clown(); * this.make.clown(); * ``` * * The callbacks are what are called when the factories try to create a Game Object * matching the given key. It's important to understand that the callbacks are invoked within * the context of the GameObjectFactory. In this context there are several properties available * to use: * * this.scene - A reference to the Scene that owns the GameObjectFactory. * this.displayList - A reference to the Display List the Scene owns. * this.updateList - A reference to the Update List the Scene owns. * * See the GameObjectFactory and GameObjectCreator classes for more details. * Any public property or method listed is available from your callbacks under `this`. * * @method Phaser.Plugins.PluginManager#registerGameObject * @since 3.8.0 * * @param {string} key - The key of the Game Object that the given callbacks will create, i.e. `image`, `sprite`. * @param {function} [factoryCallback] - The callback to invoke when the Game Object Factory is called. * @param {function} [creatorCallback] - The callback to invoke when the Game Object Creator is called. */ registerGameObject: function (key, factoryCallback, creatorCallback) { if (factoryCallback) { GameObjectFactory.register(key, factoryCallback); } if (creatorCallback) { GameObjectCreator.register(key, creatorCallback); } return this; }, /** * Registers a new file type with the global File Types Manager, making it available to all Loader * Plugins created after this. * * This is usually called from within your Plugin code and is a helpful short-cut for creating * new loader file types. * * The key is the property that will be injected into the Loader Plugin and used to load the * files. For example: * * ```javascript * this.plugins.registerFileType('wad', doomWadLoaderCallback); * // later in your preload code: * this.load.wad(); * ``` * * The callback is what is called when the loader tries to load a file matching the given key. * It's important to understand that the callback is invoked within * the context of the LoaderPlugin. In this context there are several properties / methods available * to use: * * this.addFile - A method to add the new file to the load queue. * this.scene - The Scene that owns the Loader Plugin instance. * * See the LoaderPlugin class for more details. Any public property or method listed is available from * your callback under `this`. * * @method Phaser.Plugins.PluginManager#registerFileType * @since 3.8.0 * * @param {string} key - The key of the Game Object that the given callbacks will create, i.e. `image`, `sprite`. * @param {function} callback - The callback to invoke when the Game Object Factory is called. * @param {Phaser.Scene} [addToScene] - Optionally add this file type into the Loader Plugin owned by the given Scene. */ registerFileType: function (key, callback, addToScene) { FileTypesManager.register(key, callback); if (addToScene && addToScene.sys.load) { addToScene.sys.load[key] = callback; } }, /** * Destroys this Plugin Manager and all associated plugins. * It will iterate all plugins found and call their `destroy` methods. * Note that the PluginCache is NOT cleared by this as it doesn't hold any plugin instances. * * @method Phaser.Plugins.PluginManager#destroy * @since 3.8.0 */ destroy: function () { for (var i = 0; i < this.plugins.length; i++) { this.plugins[i].plugin.destroy(); } this.game = null; this.plugins = []; this.scenePlugins = []; } }); /* * "Sometimes, the elegant implementation is just a function. * Not a method. Not a class. Not a framework. Just a function." * -- John Carmack */ module.exports = PluginManager; /***/ }), /* 197 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); // https://developer.mozilla.org/en-US/docs/Web/API/Touch_events // https://patrickhlauke.github.io/touch/tests/results/ // https://www.html5rocks.com/en/mobile/touch/ /** * @classdesc * The Touch Manager is a helper class that belongs to the Input Manager. * * Its role is to listen for native DOM Touch Events and then pass them onto the Input Manager for further processing. * * You do not need to create this class directly, the Input Manager will create an instance of it automatically. * * @class TouchManager * @memberOf Phaser.Input.Touch * @constructor * @since 3.0.0 * * @param {Phaser.Input.InputManager} inputManager - A reference to the Input Manager. */ var TouchManager = new Class({ initialize: function TouchManager (inputManager) { /** * A reference to the Input Manager. * * @name Phaser.Input.Touch.TouchManager#manager * @type {Phaser.Input.InputManager} * @since 3.0.0 */ this.manager = inputManager; /** * If true the DOM events will have event.preventDefault applied to them, if false they will propagate fully. * * @name Phaser.Input.Touch.TouchManager#capture * @type {boolean} * @default true * @since 3.0.0 */ this.capture = true; /** * A boolean that controls if the Touch Manager is enabled or not. * Can be toggled on the fly. * * @name Phaser.Input.Touch.TouchManager#enabled * @type {boolean} * @default false * @since 3.0.0 */ this.enabled = false; /** * The Touch Event target, as defined in the Game Config. * Typically the canvas to which the game is rendering, but can be any interactive DOM element. * * @name Phaser.Input.Touch.TouchManager#target * @type {any} * @since 3.0.0 */ this.target; inputManager.events.once('boot', this.boot, this); }, /** * The Touch Manager boot process. * * @method Phaser.Input.Touch.TouchManager#boot * @private * @since 3.0.0 */ boot: function () { var config = this.manager.config; this.enabled = config.inputTouch; this.target = config.inputTouchEventTarget; this.capture = config.inputTouchCapture; if (!this.target) { this.target = this.manager.game.canvas; } if (this.enabled) { this.startListeners(); } }, /** * The Touch Start Event Handler. * * @method Phaser.Input.Touch.TouchManager#onTouchStart * @since 3.10.0 * * @param {TouchEvent} event - The native DOM Touch Start Event. */ onTouchStart: function (event) { if (event.defaultPrevented || !this.enabled) { // Do nothing if event already handled return; } this.manager.queueTouchStart(event); if (this.capture) { event.preventDefault(); } }, /** * The Touch Move Event Handler. * * @method Phaser.Input.Touch.TouchManager#onTouchMove * @since 3.10.0 * * @param {TouchEvent} event - The native DOM Touch Move Event. */ onTouchMove: function (event) { if (event.defaultPrevented || !this.enabled) { // Do nothing if event already handled return; } this.manager.queueTouchMove(event); if (this.capture) { event.preventDefault(); } }, /** * The Touch End Event Handler. * * @method Phaser.Input.Touch.TouchManager#onTouchEnd * @since 3.10.0 * * @param {TouchEvent} event - The native DOM Touch End Event. */ onTouchEnd: function (event) { if (event.defaultPrevented || !this.enabled) { // Do nothing if event already handled return; } this.manager.queueTouchEnd(event); if (this.capture) { event.preventDefault(); } }, /** * Starts the Touch Event listeners running. * This is called automatically and does not need to be manually invoked. * * @method Phaser.Input.Touch.TouchManager#startListeners * @since 3.0.0 */ startListeners: function () { var target = this.target; var passive = { passive: true }; var nonPassive = { passive: false }; if (this.capture) { target.addEventListener('touchstart', this.onTouchStart.bind(this), nonPassive); target.addEventListener('touchmove', this.onTouchMove.bind(this), nonPassive); target.addEventListener('touchend', this.onTouchEnd.bind(this), nonPassive); } else { target.addEventListener('touchstart', this.onTouchStart.bind(this), passive); target.addEventListener('touchmove', this.onTouchMove.bind(this), passive); target.addEventListener('touchend', this.onTouchEnd.bind(this), passive); } }, /** * Stops the Touch Event listeners. * This is called automatically and does not need to be manually invoked. * * @method Phaser.Input.Touch.TouchManager#stopListeners * @since 3.0.0 */ stopListeners: function () { var target = this.target; target.removeEventListener('touchstart', this.onTouchStart); target.removeEventListener('touchmove', this.onTouchMove); target.removeEventListener('touchend', this.onTouchEnd); }, /** * Destroys this Touch Manager instance. * * @method Phaser.Input.Touch.TouchManager#destroy * @since 3.0.0 */ destroy: function () { this.stopListeners(); this.target = null; this.manager = null; } }); module.exports = TouchManager; /***/ }), /* 198 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Vector2 = __webpack_require__(6); /** * @classdesc * A Pointer object encapsulates both mouse and touch input within Phaser. * * By default, Phaser will create 2 pointers for your game to use. If you require more, i.e. for a multi-touch * game, then use the `InputPlugin.addPointer` method to do so, rather than instantiating this class directly, * otherwise it won't be managed by the input system. * * You can reference the current active pointer via `InputPlugin.activePointer`. You can also use the properties * `InputPlugin.pointer1` through to `pointer10`, for each pointer you have enabled in your game. * * The properties of this object are set by the Input Plugin during processing. This object is then sent in all * input related events that the Input Plugin emits, so you can reference properties from it directly in your * callbacks. * * @class Pointer * @memberOf Phaser.Input * @constructor * @since 3.0.0 * * @param {Phaser.Input.InputManager} manager - A reference to the Input Manager. * @param {integer} id - The internal ID of this Pointer. */ var Pointer = new Class({ initialize: function Pointer (manager, id) { /** * A reference to the Input Manager. * * @name Phaser.Input.Pointer#manager * @type {Phaser.Input.InputManager} * @since 3.0.0 */ this.manager = manager; /** * The internal ID of this Pointer. * * @name Phaser.Input.Pointer#id * @type {integer} * @readOnly * @since 3.0.0 */ this.id = id; /** * The most recent native DOM Event this Pointer has processed. * * @name Phaser.Input.Pointer#event * @type {(TouchEvent|MouseEvent)} * @since 3.0.0 */ this.event; /** * The camera the Pointer interacted with during its last update. * * A Pointer can only ever interact with one camera at once, which will be the top-most camera * in the list should multiple cameras be positioned on-top of each other. * * @name Phaser.Input.Pointer#camera * @type {Phaser.Cameras.Scene2D.Camera} * @default null * @since 3.0.0 */ this.camera = null; /** * 0: No button or un-initialized * 1: Left button * 2: Right button * 4: Wheel button or middle button * 8: 4th button (typically the "Browser Back" button) * 16: 5th button (typically the "Browser Forward" button) * * For a mouse configured for left-handed use, the button actions are reversed. * In this case, the values are read from right to left. * * @name Phaser.Input.Pointer#buttons * @type {integer} * @default 0 * @since 3.0.0 */ this.buttons = 0; /** * The position of the Pointer in screen space. * * @name Phaser.Input.Pointer#position * @type {Phaser.Math.Vector2} * @since 3.0.0 */ this.position = new Vector2(); /** * The x position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with. * * @name Phaser.Input.Pointer#worldX * @type {number} * @default 0 * @since 3.10.0 */ this.worldX = 0; /** * The y position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with. * * @name Phaser.Input.Pointer#worldY * @type {number} * @default 0 * @since 3.10.0 */ this.worldY = 0; /** * X coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects. * * @name Phaser.Input.Pointer#downX * @type {number} * @default 0 * @since 3.0.0 */ this.downX = 0; /** * Y coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects. * * @name Phaser.Input.Pointer#downY * @type {number} * @default 0 * @since 3.0.0 */ this.downY = 0; /** * Time when Button 1 (left button), or Touch, was pressed, used for dragging objects. * * @name Phaser.Input.Pointer#downTime * @type {number} * @default 0 * @since 3.0.0 */ this.downTime = 0; /** * X coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects. * * @name Phaser.Input.Pointer#upX * @type {number} * @default 0 * @since 3.0.0 */ this.upX = 0; /** * Y coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects. * * @name Phaser.Input.Pointer#upY * @type {number} * @default 0 * @since 3.0.0 */ this.upY = 0; /** * Time when Button 1 (left button), or Touch, was released, used for dragging objects. * * @name Phaser.Input.Pointer#upTime * @type {number} * @default 0 * @since 3.0.0 */ this.upTime = 0; /** * Is the primary button down? (usually button 0, the left mouse button) * * @name Phaser.Input.Pointer#primaryDown * @type {boolean} * @default false * @since 3.0.0 */ this.primaryDown = false; /** * The Drag State of the Pointer: * * 0 = Not dragging anything * 1 = Being checked if dragging * 2 = Dragging something * * @name Phaser.Input.Pointer#dragState * @type {number} * @default 0 * @since 3.0.0 */ this.dragState = 0; /** * Is _any_ button on this pointer considered as being down? * * @name Phaser.Input.Pointer#isDown * @type {boolean} * @default false * @since 3.0.0 */ this.isDown = false; /** * A dirty flag for this Pointer, used internally by the Input Plugin. * * @name Phaser.Input.Pointer#dirty * @type {boolean} * @default false * @since 3.0.0 */ this.dirty = false; /** * Is this Pointer considered as being "just down" or not? * * @name Phaser.Input.Pointer#justDown * @type {boolean} * @default false * @since 3.0.0 */ this.justDown = false; /** * Is this Pointer considered as being "just up" or not? * * @name Phaser.Input.Pointer#justUp * @type {boolean} * @default false * @since 3.0.0 */ this.justUp = false; /** * Is this Pointer considered as being "just moved" or not? * * @name Phaser.Input.Pointer#justMoved * @type {boolean} * @default false * @since 3.0.0 */ this.justMoved = false; /** * Did the previous input event come from a Touch input (true) or Mouse? (false) * * @name Phaser.Input.Pointer#wasTouch * @type {boolean} * @default false * @since 3.0.0 */ this.wasTouch = false; /** * If the mouse is locked, the horizontal relative movement of the Pointer in pixels since last frame. * * @name Phaser.Input.Pointer#movementX * @type {number} * @default 0 * @since 3.0.0 */ this.movementX = 0; /** * If the mouse is locked, the vertical relative movement of the Pointer in pixels since last frame. * * @name Phaser.Input.Pointer#movementY * @type {number} * @default 0 * @since 3.0.0 */ this.movementY = 0; /** * The identifier property of the Pointer as set by the DOM event when this Pointer is started. * * @name Phaser.Input.Pointer#identifier * @type {number} * @since 3.10.0 */ this.identifier = 0; /** * The pointerId property of the Pointer as set by the DOM event when this Pointer is started. * The browser can and will recycle this value. * * @name Phaser.Input.Pointer#pointerId * @type {number} * @since 3.10.0 */ this.pointerId = null; /** * An active Pointer is one that is currently pressed down on the display. * A Mouse is always considered as active. * * @name Phaser.Input.Pointer#active * @type {boolean} * @since 3.10.0 */ this.active = (id === 0) ? true : false; }, /** * Takes a Camera and returns a Vector2 containing the translated position of this Pointer * within that Camera. This can be used to convert this Pointers position into camera space. * * @method Phaser.Input.Pointer#positionToCamera * @since 3.0.0 * * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to use for the translation. * @param {(Phaser.Math.Vector2|object)} [output] - A Vector2-like object in which to store the translated position. * * @return {(Phaser.Math.Vector2|object)} A Vector2 containing the translated coordinates of this Pointer, based on the given camera. */ positionToCamera: function (camera, output) { return camera.getWorldPoint(this.x, this.y, output); }, /** * Resets the temporal properties of this Pointer. * Called automatically by the Input Plugin each update. * * @method Phaser.Input.Pointer#reset * @private * @since 3.0.0 */ reset: function () { this.dirty = false; this.justDown = false; this.justUp = false; this.justMoved = false; this.movementX = 0; this.movementY = 0; }, /** * Internal method to handle a Mouse Up Event. * * @method Phaser.Input.Pointer#up * @private * @since 3.0.0 * * @param {MouseEvent} event - The Mouse Event to process. * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. */ up: function (event, time) { if (event.buttons) { this.buttons = event.buttons; } this.event = event; // Sets the local x/y properties this.manager.transformPointer(this, event.pageX, event.pageY); // 0: Main button pressed, usually the left button or the un-initialized state if (event.button === 0) { this.primaryDown = false; this.upX = this.x; this.upY = this.y; this.upTime = time; } this.justUp = true; this.isDown = false; this.dirty = true; this.wasTouch = false; }, /** * Internal method to handle a Mouse Down Event. * * @method Phaser.Input.Pointer#down * @private * @since 3.0.0 * * @param {MouseEvent} event - The Mouse Event to process. * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. */ down: function (event, time) { if (event.buttons) { this.buttons = event.buttons; } this.event = event; // Sets the local x/y properties this.manager.transformPointer(this, event.pageX, event.pageY); // 0: Main button pressed, usually the left button or the un-initialized state if (event.button === 0) { this.primaryDown = true; this.downX = this.x; this.downY = this.y; this.downTime = time; } this.justDown = true; this.isDown = true; this.dirty = true; this.wasTouch = false; }, /** * Internal method to handle a Mouse Move Event. * * @method Phaser.Input.Pointer#move * @private * @since 3.0.0 * * @param {MouseEvent} event - The Mouse Event to process. * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. */ move: function (event) { if (event.buttons) { this.buttons = event.buttons; } this.event = event; // Sets the local x/y properties this.manager.transformPointer(this, event.pageX, event.pageY); if (this.manager.mouse.locked) { // Multiple DOM events may occur within one frame, but only one Phaser event will fire this.movementX += event.movementX || event.mozMovementX || event.webkitMovementX || 0; this.movementY += event.movementY || event.mozMovementY || event.webkitMovementY || 0; } this.justMoved = true; this.dirty = true; this.wasTouch = false; }, /** * Internal method to handle a Touch Start Event. * * @method Phaser.Input.Pointer#touchstart * @private * @since 3.0.0 * * @param {TouchEvent} event - The Touch Event to process. * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. */ touchstart: function (event, time) { if (event['pointerId']) { this.pointerId = event.pointerId; } this.identifier = event.identifier; this.target = event.target; this.active = true; this.buttons = 1; this.event = event; // Sets the local x/y properties this.manager.transformPointer(this, event.pageX, event.pageY); this.primaryDown = true; this.downX = this.x; this.downY = this.y; this.downTime = time; this.justDown = true; this.isDown = true; this.dirty = true; this.wasTouch = true; }, /** * Internal method to handle a Touch Move Event. * * @method Phaser.Input.Pointer#touchmove * @private * @since 3.0.0 * * @param {TouchEvent} event - The Touch Event to process. * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. */ touchmove: function (event) { this.event = event; // Sets the local x/y properties this.manager.transformPointer(this, event.pageX, event.pageY); this.justMoved = true; this.dirty = true; this.wasTouch = true; }, /** * Internal method to handle a Touch End Event. * * @method Phaser.Input.Pointer#touchend * @private * @since 3.0.0 * * @param {TouchEvent} event - The Touch Event to process. * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. */ touchend: function (event, time) { this.buttons = 0; this.event = event; // Sets the local x/y properties this.manager.transformPointer(this, event.pageX, event.pageY); this.primaryDown = false; this.upX = this.x; this.upY = this.y; this.upTime = time; this.justUp = true; this.isDown = false; this.dirty = true; this.wasTouch = true; this.active = false; }, /** * Checks to see if any buttons are being held down on this Pointer. * * @method Phaser.Input.Pointer#noButtonDown * @since 3.0.0 * * @return {boolean} `true` if no buttons are being held down. */ noButtonDown: function () { return (this.buttons === 0); }, /** * Checks to see if the left button is being held down on this Pointer. * * @method Phaser.Input.Pointer#leftButtonDown * @since 3.0.0 * * @return {boolean} `true` if the left button is being held down. */ leftButtonDown: function () { return (this.buttons & 1); }, /** * Checks to see if the right button is being held down on this Pointer. * * @method Phaser.Input.Pointer#rightButtonDown * @since 3.0.0 * * @return {boolean} `true` if the right button is being held down. */ rightButtonDown: function () { return (this.buttons & 2); }, /** * Checks to see if the middle button is being held down on this Pointer. * * @method Phaser.Input.Pointer#middleButtonDown * @since 3.0.0 * * @return {boolean} `true` if the middle button is being held down. */ middleButtonDown: function () { return (this.buttons & 4); }, /** * Checks to see if the back button is being held down on this Pointer. * * @method Phaser.Input.Pointer#backButtonDown * @since 3.0.0 * * @return {boolean} `true` if the back button is being held down. */ backButtonDown: function () { return (this.buttons & 8); }, /** * Checks to see if the forward button is being held down on this Pointer. * * @method Phaser.Input.Pointer#forwardButtonDown * @since 3.0.0 * * @return {boolean} `true` if the forward button is being held down. */ forwardButtonDown: function () { return (this.buttons & 16); }, /** * Destroys this Pointer instance and resets its external references. * * @method Phaser.Input.Pointer#destroy * @since 3.0.0 */ destroy: function () { this.camera = null; this.manager = null; this.position = null; }, /** * The x position of this Pointer. * The value is in screen space. * See `worldX` to get a camera converted position. * * @name Phaser.Input.Pointer#x * @type {number} * @since 3.0.0 */ x: { get: function () { return this.position.x; }, set: function (value) { this.position.x = value; } }, /** * The y position of this Pointer. * The value is in screen space. * See `worldY` to get a camera converted position. * * @name Phaser.Input.Pointer#y * @type {number} * @since 3.0.0 */ y: { get: function () { return this.position.y; }, set: function (value) { this.position.y = value; } } }); module.exports = Pointer; /***/ }), /* 199 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Features = __webpack_require__(120); // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md /** * @classdesc * The Mouse Manager is a helper class that belongs to the Input Manager. * * Its role is to listen for native DOM Mouse Events and then pass them onto the Input Manager for further processing. * * You do not need to create this class directly, the Input Manager will create an instance of it automatically. * * @class MouseManager * @memberOf Phaser.Input.Mouse * @constructor * @since 3.0.0 * * @param {Phaser.Input.InputManager} inputManager - A reference to the Input Manager. */ var MouseManager = new Class({ initialize: function MouseManager (inputManager) { /** * A reference to the Input Manager. * * @name Phaser.Input.Mouse.MouseManager#manager * @type {Phaser.Input.InputManager} * @since 3.0.0 */ this.manager = inputManager; /** * If true the DOM mouse events will have event.preventDefault applied to them, if false they will propagate fully. * * @name Phaser.Input.Mouse.MouseManager#capture * @type {boolean} * @default true * @since 3.0.0 */ this.capture = true; /** * A boolean that controls if the Mouse Manager is enabled or not. * Can be toggled on the fly. * * @name Phaser.Input.Mouse.MouseManager#enabled * @type {boolean} * @default false * @since 3.0.0 */ this.enabled = false; /** * The Touch Event target, as defined in the Game Config. * Typically the canvas to which the game is rendering, but can be any interactive DOM element. * * @name Phaser.Input.Mouse.MouseManager#target * @type {any} * @since 3.0.0 */ this.target; /** * If the mouse has been pointer locked successfully this will be set to true. * * @name Phaser.Input.Mouse.MouseManager#locked * @type {boolean} * @default false * @since 3.0.0 */ this.locked = false; inputManager.events.once('boot', this.boot, this); }, /** * The Touch Manager boot process. * * @method Phaser.Input.Mouse.MouseManager#boot * @private * @since 3.0.0 */ boot: function () { var config = this.manager.config; this.enabled = config.inputMouse; this.target = config.inputMouseEventTarget; this.capture = config.inputMouseCapture; if (!this.target) { this.target = this.manager.game.canvas; } if (config.disableContextMenu) { this.disableContextMenu(); } if (this.enabled) { this.startListeners(); } }, /** * Attempts to disable the context menu from appearing if you right-click on the browser. * * Works by listening for the `contextmenu` event and prevent defaulting it. * * Use this if you need to enable right-button mouse support in your game, and the browser * menu keeps getting in the way. * * @method Phaser.Input.Mouse.MouseManager#disableContextMenu * @since 3.0.0 * * @return {Phaser.Input.Mouse.MouseManager} This Mouse Manager instance. */ disableContextMenu: function () { document.body.addEventListener('contextmenu', function (event) { event.preventDefault(); return false; }); return this; }, /** * If the browser supports it, you can request that the pointer be locked to the browser window. * * This is classically known as 'FPS controls', where the pointer can't leave the browser until * the user presses an exit key. * * If the browser successfully enters a locked state, a `POINTER_LOCK_CHANGE_EVENT` will be dispatched, * from the games Input Manager, with an `isPointerLocked` property. * * It is important to note that pointer lock can only be enabled after an 'engagement gesture', * see: https://w3c.github.io/pointerlock/#dfn-engagement-gesture. * * @method Phaser.Input.Mouse.MouseManager#requestPointerLock * @since 3.0.0 */ requestPointerLock: function () { if (Features.pointerLock) { var element = this.target; element.requestPointerLock = element.requestPointerLock || element.mozRequestPointerLock || element.webkitRequestPointerLock; element.requestPointerLock(); } }, /** * Internal pointerLockChange handler. * * @method Phaser.Input.Mouse.MouseManager#pointerLockChange * @since 3.0.0 * * @param {MouseEvent} event - The native event from the browser. */ pointerLockChange: function (event) { var element = this.target; this.locked = (document.pointerLockElement === element || document.mozPointerLockElement === element || document.webkitPointerLockElement === element) ? true : false; this.manager.queue.push(event); }, /** * If the browser supports pointer lock, this will request that the pointer lock is released. If * the browser successfully enters a locked state, a 'POINTER_LOCK_CHANGE_EVENT' will be * dispatched - from the game's input manager - with an `isPointerLocked` property. * * @method Phaser.Input.Mouse.MouseManager#releasePointerLock * @since 3.0.0 */ releasePointerLock: function () { if (Features.pointerLock) { document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock; document.exitPointerLock(); } }, /** * The Mouse Move Event Handler. * * @method Phaser.Input.Mouse.MouseManager#onMouseMove * @since 3.10.0 * * @param {MouseEvent} event - The native DOM Mouse Move Event. */ onMouseMove: function (event) { if (event.defaultPrevented || !this.enabled) { // Do nothing if event already handled return; } this.manager.queueMouseMove(event); if (this.capture) { event.preventDefault(); } }, /** * The Mouse Down Event Handler. * * @method Phaser.Input.Mouse.MouseManager#onMouseDown * @since 3.10.0 * * @param {MouseEvent} event - The native DOM Mouse Down Event. */ onMouseDown: function (event) { if (event.defaultPrevented || !this.enabled) { // Do nothing if event already handled return; } this.manager.queueMouseDown(event); if (this.capture) { event.preventDefault(); } }, /** * The Mouse Up Event Handler. * * @method Phaser.Input.Mouse.MouseManager#onMouseUp * @since 3.10.0 * * @param {MouseEvent} event - The native DOM Mouse Up Event. */ onMouseUp: function (event) { if (event.defaultPrevented || !this.enabled) { // Do nothing if event already handled return; } this.manager.queueMouseUp(event); if (this.capture) { event.preventDefault(); } }, /** * Starts the Mouse Event listeners running. * This is called automatically and does not need to be manually invoked. * * @method Phaser.Input.Mouse.MouseManager#startListeners * @since 3.0.0 */ startListeners: function () { var target = this.target; var passive = { passive: true }; var nonPassive = { passive: false }; if (this.capture) { target.addEventListener('mousemove', this.onMouseMove.bind(this), nonPassive); target.addEventListener('mousedown', this.onMouseDown.bind(this), nonPassive); target.addEventListener('mouseup', this.onMouseUp.bind(this), nonPassive); } else { target.addEventListener('mousemove', this.onMouseMove.bind(this), passive); target.addEventListener('mousedown', this.onMouseDown.bind(this), passive); target.addEventListener('mouseup', this.onMouseUp.bind(this), passive); } if (Features.pointerLock) { this.pointerLockChange = this.pointerLockChange.bind(this); document.addEventListener('pointerlockchange', this.pointerLockChange, true); document.addEventListener('mozpointerlockchange', this.pointerLockChange, true); document.addEventListener('webkitpointerlockchange', this.pointerLockChange, true); } }, /** * Stops the Mouse Event listeners. * This is called automatically and does not need to be manually invoked. * * @method Phaser.Input.Mouse.MouseManager#stopListeners * @since 3.0.0 */ stopListeners: function () { var target = this.target; target.removeEventListener('mousemove', this.onMouseMove); target.removeEventListener('mousedown', this.onMouseDown); target.removeEventListener('mouseup', this.onMouseUp); if (Features.pointerLock) { document.removeEventListener('pointerlockchange', this.pointerLockChange, true); document.removeEventListener('mozpointerlockchange', this.pointerLockChange, true); document.removeEventListener('webkitpointerlockchange', this.pointerLockChange, true); } }, /** * Destroys this Mouse Manager instance. * * @method Phaser.Input.Mouse.MouseManager#destroy * @since 3.0.0 */ destroy: function () { this.stopListeners(); this.target = null; this.manager = null; } }); module.exports = MouseManager; /***/ }), /* 200 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var INPUT_CONST = { /** * The mouse pointer is being held down. * * @name Phaser.Input.MOUSE_DOWN * @type {integer} * @since 3.10.0 */ MOUSE_DOWN: 0, /** * The mouse pointer is being moved. * * @name Phaser.Input.MOUSE_MOVE * @type {integer} * @since 3.10.0 */ MOUSE_MOVE: 1, /** * The mouse pointer is released. * * @name Phaser.Input.MOUSE_UP * @type {integer} * @since 3.10.0 */ MOUSE_UP: 2, /** * A touch pointer has been started. * * @name Phaser.Input.TOUCH_START * @type {integer} * @since 3.10.0 */ TOUCH_START: 3, /** * A touch pointer has been started. * * @name Phaser.Input.TOUCH_MOVE * @type {integer} * @since 3.10.0 */ TOUCH_MOVE: 4, /** * A touch pointer has been started. * * @name Phaser.Input.TOUCH_END * @type {integer} * @since 3.10.0 */ TOUCH_END: 5, /** * The pointer lock has changed. * * @name Phaser.Input.POINTER_LOCK_CHANGE * @type {integer} * @since 3.10.0 */ POINTER_LOCK_CHANGE: 6 }; module.exports = INPUT_CONST; /***/ }), /* 201 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(200); var EventEmitter = __webpack_require__(9); var Mouse = __webpack_require__(199); var Pointer = __webpack_require__(198); var Rectangle = __webpack_require__(14); var Touch = __webpack_require__(197); var TransformMatrix = __webpack_require__(64); var TransformXY = __webpack_require__(257); /** * @classdesc * The Input Manager is responsible for handling the pointer related systems in a single Phaser Game instance. * * Based on the Game Config it will create handlers for mouse and touch support. * * Keyboard and Gamepad are plugins, handled directly by the InputPlugin class. * * It then manages the event queue, pointer creation and general hit test related operations. * * You rarely need to interact with the Input Manager directly, and as such, all of its properties and methods * should be considered private. Instead, you should use the Input Plugin, which is a Scene level system, responsible * for dealing with all input events for a Scene. * * @class InputManager * @memberOf Phaser.Input * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - The Game instance that owns the Input Manager. * @param {object} config - The Input Configuration object, as set in the Game Config. */ var InputManager = new Class({ initialize: function InputManager (game, config) { /** * The Game instance that owns the Input Manager. * A Game only maintains on instance of the Input Manager at any time. * * @name Phaser.Input.InputManager#game * @type {Phaser.Game} * @readOnly * @since 3.0.0 */ this.game = game; /** * The Canvas that is used for all DOM event input listeners. * * @name Phaser.Input.InputManager#canvas * @type {HTMLCanvasElement} * @since 3.0.0 */ this.canvas; /** * The Input Configuration object, as set in the Game Config. * * @name Phaser.Input.InputManager#config * @type {object} * @since 3.0.0 */ this.config = config; /** * If set, the Input Manager will run its update loop every frame. * * @name Phaser.Input.InputManager#enabled * @type {boolean} * @default true * @since 3.0.0 */ this.enabled = true; /** * The Event Emitter instance that the Input Manager uses to emit events from. * * @name Phaser.Input.InputManager#events * @type {Phaser.Events.EventEmitter} * @since 3.0.0 */ this.events = new EventEmitter(); /** * A standard FIFO queue for the native DOM events waiting to be handled by the Input Manager. * * @name Phaser.Input.InputManager#queue * @type {array} * @default [] * @since 3.0.0 */ this.queue = []; /** * DOM Callbacks container. * * @name Phaser.Input.InputManager#domCallbacks * @private * @type {object} * @since 3.10.0 */ this.domCallbacks = { up: [], down: [], move: [], upOnce: [], downOnce: [], moveOnce: [] }; /** * Are there any up callbacks defined? * * @name Phaser.Input.InputManager#_hasUpCallback * @private * @type {boolean} * @since 3.10.0 */ this._hasUpCallback = false; /** * Are there any down callbacks defined? * * @name Phaser.Input.InputManager#_hasDownCallback * @private * @type {boolean} * @since 3.10.0 */ this._hasDownCallback = false; /** * Are there any move callbacks defined? * * @name Phaser.Input.InputManager#_hasMoveCallback * @private * @type {boolean} * @since 3.10.0 */ this._hasMoveCallback = false; /** * Is a custom cursor currently set? (desktop only) * * @name Phaser.Input.InputManager#_customCursor * @private * @type {string} * @since 3.10.0 */ this._customCursor = ''; /** * Custom cursor tracking value. * * 0 - No change. * 1 - Set new cursor. * 2 - Reset cursor. * * @name Phaser.Input.InputManager#_setCursor * @private * @type {integer} * @since 3.10.0 */ this._setCursor = 0; /** * The default CSS cursor to be used when interacting with your game. * * See the `setDefaultCursor` method for more details. * * @name Phaser.Input.InputManager#defaultCursor * @type {string} * @since 3.10.0 */ this.defaultCursor = ''; /** * A reference to the Mouse Manager class, if enabled via the `input.mouse` Game Config property. * * @name Phaser.Input.InputManager#mouse * @type {?Phaser.Input.Mouse.MouseManager} * @since 3.0.0 */ this.mouse = (config.inputMouse) ? new Mouse(this) : null; /** * A reference to the Touch Manager class, if enabled via the `input.touch` Game Config property. * * @name Phaser.Input.InputManager#touch * @type {Phaser.Input.Touch.TouchManager} * @since 3.0.0 */ this.touch = (config.inputTouch) ? new Touch(this) : null; /** * An array of Pointers that have been added to the game. * The first entry is reserved for the Mouse Pointer, the rest are Touch Pointers. * * By default there is 1 touch pointer enabled. If you need more use the `addPointer` method to start them, * or set the `input.activePointers` property in the Game Config. * * @name Phaser.Input.InputManager#pointers * @type {Phaser.Input.Pointer[]} * @since 3.10.0 */ this.pointers = []; /** * The number of touch objects activated and being processed each update. * * You can change this by either calling `addPointer` at run-time, or by * setting the `input.activePointers` property in the Game Config. * * @name Phaser.Input.InputManager#pointersTotal * @type {integer} * @readOnly * @since 3.10.0 */ this.pointersTotal = config.inputActivePointers; if (config.inputTouch && this.pointersTotal === 1) { this.pointersTotal = 2; } for (var i = 0; i <= this.pointersTotal; i++) { this.pointers.push(new Pointer(this, i)); } /** * The mouse has its own unique Pointer object, which you can reference directly if making a _desktop specific game_. * If you are supporting both desktop and touch devices then do not use this property, instead use `activePointer` * which will always map to the most recently interacted pointer. * * @name Phaser.Input.InputManager#mousePointer * @type {?Phaser.Input.Pointer} * @since 3.10.0 */ this.mousePointer = (config.inputMouse) ? this.pointers[0] : null; /** * The most recently active Pointer object. * * If you've only 1 Pointer in your game then this will accurately be either the first finger touched, or the mouse. * * If your game doesn't need to support multi-touch then you can safely use this property in all of your game * code and it will adapt to be either the mouse or the touch, based on device. * * @name Phaser.Input.InputManager#activePointer * @type {Phaser.Input.Pointer} * @since 3.0.0 */ this.activePointer = this.pointers[0]; /** * Reset every frame. Set to `true` if any of the Pointers are dirty this frame. * * @name Phaser.Input.InputManager#dirty * @type {boolean} * @since 3.10.0 */ this.dirty = false; /** * The Scale factor being applied to input coordinates. * * @name Phaser.Input.InputManager#scale * @type { { x:number, y:number } } * @since 3.0.0 */ this.scale = { x: 1, y: 1 }; /** * If the top-most Scene in the Scene List receives an input it will stop input from * propagating any lower down the scene list, i.e. if you have a UI Scene at the top * and click something on it, that click will not then be passed down to any other * Scene below. Disable this to have input events passed through all Scenes, all the time. * * @name Phaser.Input.InputManager#globalTopOnly * @type {boolean} * @default true * @since 3.0.0 */ this.globalTopOnly = true; /** * An internal flag that controls if the Input Manager will ignore or process native DOM events this frame. * Set via the InputPlugin.stopPropagation method. * * @name Phaser.Input.InputManager#ignoreEvents * @type {boolean} * @default false * @since 3.0.0 */ this.ignoreEvents = false; /** * The bounds of the Input Manager, used for pointer hit test calculations. * * @name Phaser.Input.InputManager#bounds * @type {Phaser.Geom.Rectangle} * @since 3.0.0 */ this.bounds = new Rectangle(); /** * A re-cycled point-like object to store hit test values in. * * @name Phaser.Input.InputManager#_tempPoint * @type {{x:number,y:number}} * @private * @since 3.0.0 */ this._tempPoint = { x: 0, y: 0 }; /** * A re-cycled array to store hit results in. * * @name Phaser.Input.InputManager#_tempHitTest * @type {array} * @private * @default [] * @since 3.0.0 */ this._tempHitTest = []; /** * A re-cycled matrix used in hit test calculations. * * @name Phaser.Input.InputManager#_tempMatrix * @type {Phaser.GameObjects.Components.TransformMatrix} * @private * @since 3.4.0 */ this._tempMatrix = new TransformMatrix(); game.events.once('boot', this.boot, this); }, /** * The Boot handler is called by Phaser.Game when it first starts up. * The renderer is available by now. * * @method Phaser.Input.InputManager#boot * @protected * @since 3.0.0 */ boot: function () { this.canvas = this.game.canvas; this.updateBounds(); this.events.emit('boot'); this.game.events.on('prestep', this.update, this); this.game.events.on('poststep', this.postUpdate, this); this.game.events.once('destroy', this.destroy, this); }, /** * Updates the Input Manager bounds rectangle to match the bounding client rectangle of the * canvas element being used to track input events. * * @method Phaser.Input.InputManager#updateBounds * @since 3.0.0 */ updateBounds: function () { var bounds = this.bounds; var clientRect = this.canvas.getBoundingClientRect(); bounds.x = clientRect.left + window.pageXOffset - document.documentElement.clientLeft; bounds.y = clientRect.top + window.pageYOffset - document.documentElement.clientTop; bounds.width = clientRect.width; bounds.height = clientRect.height; }, /** * Resizes the Input Manager internal values, including the bounds and scale factor. * * @method Phaser.Input.InputManager#resize * @since 3.2.0 */ resize: function () { this.updateBounds(); // Game config size var gw = this.game.config.width; var gh = this.game.config.height; // Actual canvas size var bw = this.bounds.width; var bh = this.bounds.height; // Scale factor this.scale.x = gw / bw; this.scale.y = gh / bh; }, /** * Internal update loop, called automatically by the Game Step. * * @method Phaser.Input.InputManager#update * @private * @since 3.0.0 * * @param {number} time - The time stamp value of this game step. */ update: function (time) { var i; this._setCursor = 0; this.events.emit('update'); this.ignoreEvents = false; this.dirty = false; var len = this.queue.length; var pointers = this.pointers; for (i = 0; i < this.pointersTotal; i++) { pointers[i].reset(); } if (!this.enabled || len === 0) { return; } this.dirty = true; this.updateBounds(); this.scale.x = this.game.config.width / this.bounds.width; this.scale.y = this.game.config.height / this.bounds.height; // Clears the queue array, and also means we don't work on array data that could potentially // be modified during the processing phase var queue = this.queue.splice(0, len); var mouse = this.mousePointer; // Process the event queue, dispatching all of the events that have stored up for (i = 0; i < len; i += 2) { var type = queue[i]; var event = queue[i + 1]; switch (type) { case CONST.MOUSE_DOWN: mouse.down(event, time); break; case CONST.MOUSE_MOVE: mouse.move(event, time); break; case CONST.MOUSE_UP: mouse.up(event, time); break; case CONST.TOUCH_START: this.startPointer(event, time); break; case CONST.TOUCH_MOVE: this.updatePointer(event, time); break; case CONST.TOUCH_END: this.stopPointer(event, time); break; case CONST.POINTER_LOCK_CHANGE: this.events.emit('pointerlockchange', event, this.mouse.locked); break; } } }, /** * Internal post-update, called automatically by the Game step. * * @method Phaser.Input.InputManager#postUpdate * @private * @since 3.10.0 */ postUpdate: function () { if (this._setCursor === 1) { this.canvas.style.cursor = this._customCursor; } else if (this._setCursor === 2) { this.canvas.style.cursor = this.defaultCursor; } }, /** * Tells the Input system to set a custom cursor. * * This cursor will be the default cursor used when interacting with the game canvas. * * If an Interactive Object also sets a custom cursor, this is the cursor that is reset after its use. * * Any valid CSS cursor value is allowed, including paths to image files, i.e.: * * ```javascript * this.input.setDefaultCursor('url(assets/cursors/sword.cur), pointer'); * ``` * * Please read about the differences between browsers when it comes to the file formats and sizes they support: * * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_User_Interface/Using_URL_values_for_the_cursor_property * * It's up to you to pick a suitable cursor format that works across the range of browsers you need to support. * * @method Phaser.Input.InputManager#setDefaultCursor * @since 3.10.0 * * @param {string} cursor - The CSS to be used when setting the default cursor. */ setDefaultCursor: function (cursor) { this.defaultCursor = cursor; if (this.canvas.style.cursor !== cursor) { this.canvas.style.cursor = cursor; } }, /** * Called by the InputPlugin when processing over and out events. * * Tells the Input Manager to set a custom cursor during its postUpdate step. * * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor * * @method Phaser.Input.InputManager#setCursor * @private * @since 3.10.0 * * @param {Phaser.Input.InteractiveObject} interactiveObject - The Interactive Object that called this method. */ setCursor: function (interactiveObject) { if (interactiveObject.cursor) { this._setCursor = 1; this._customCursor = interactiveObject.cursor; } }, /** * Called by the InputPlugin when processing over and out events. * * Tells the Input Manager to clear the hand cursor, if set, during its postUpdate step. * * @method Phaser.Input.InputManager#resetCursor * @private * @since 3.10.0 * * @param {Phaser.Input.InteractiveObject} interactiveObject - The Interactive Object that called this method. */ resetCursor: function (interactiveObject) { if (interactiveObject.cursor) { this._setCursor = 2; } }, // event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element) // event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element // event.changedTouches = the touches that CHANGED in this event, not the total number of them /** * Called by the main update loop when a Touch Start Event is received. * * @method Phaser.Input.InputManager#startPointer * @private * @since 3.10.0 * * @param {TouchEvent} event - The native DOM event to be processed. * @param {number} time - The time stamp value of this game step. */ startPointer: function (event, time) { var pointers = this.pointers; for (var c = 0; c < event.changedTouches.length; c++) { var changedTouch = event.changedTouches[c]; for (var i = 1; i < this.pointersTotal; i++) { var pointer = pointers[i]; if (!pointer.active) { pointer.touchstart(changedTouch, time); this.activePointer = pointer; break; } } } }, /** * Called by the main update loop when a Touch Move Event is received. * * @method Phaser.Input.InputManager#updatePointer * @private * @since 3.10.0 * * @param {TouchEvent} event - The native DOM event to be processed. * @param {number} time - The time stamp value of this game step. */ updatePointer: function (event, time) { var pointers = this.pointers; for (var c = 0; c < event.changedTouches.length; c++) { var changedTouch = event.changedTouches[c]; for (var i = 1; i < this.pointersTotal; i++) { var pointer = pointers[i]; if (pointer.active && pointer.identifier === changedTouch.identifier) { pointer.touchmove(changedTouch, time); this.activePointer = pointer; break; } } } }, // For touch end its a list of the touch points that have been removed from the surface // https://developer.mozilla.org/en-US/docs/DOM/TouchList // event.changedTouches = the touches that CHANGED in this event, not the total number of them /** * Called by the main update loop when a Touch End Event is received. * * @method Phaser.Input.InputManager#stopPointer * @private * @since 3.10.0 * * @param {TouchEvent} event - The native DOM event to be processed. * @param {number} time - The time stamp value of this game step. */ stopPointer: function (event, time) { var pointers = this.pointers; for (var c = 0; c < event.changedTouches.length; c++) { var changedTouch = event.changedTouches[c]; for (var i = 1; i < this.pointersTotal; i++) { var pointer = pointers[i]; if (pointer.active && pointer.identifier === changedTouch.identifier) { pointer.touchend(changedTouch, time); break; } } } }, /** * Adds new Pointer objects to the Input Manager. * * By default Phaser creates 2 pointer objects: `mousePointer` and `pointer1`. * * You can create more either by calling this method, or by setting the `input.activePointers` property * in the Game Config, up to a maximum of 10 pointers. * * The first 10 pointers are available via the `InputPlugin.pointerX` properties, once they have been added * via this method. * * @method Phaser.Input.InputManager#addPointer * @since 3.10.0 * * @param {integer} [quantity=1] The number of new Pointers to create. A maximum of 10 is allowed in total. * * @return {Phaser.Input.Pointer[]} An array containing all of the new Pointer objects that were created. */ addPointer: function (quantity) { if (quantity === undefined) { quantity = 1; } var output = []; if (this.pointersTotal + quantity > 10) { quantity = 10 - this.pointersTotal; } for (var i = 0; i < quantity; i++) { var id = this.pointers.length; var pointer = new Pointer(this, id); this.pointers.push(pointer); this.pointersTotal++; output.push(pointer); } return output; }, /** * Process any pending DOM callbacks. * * @method Phaser.Input.InputManager#processDomCallbacks * @private * @since 3.10.0 * * @param {array} once - The isOnce callbacks to invoke. * @param {array} every - The every frame callbacks to invoke. * @param {any} event - The native DOM event that is passed to the callbacks. * * @return {boolean} `true` if there are callbacks still in the list, otherwise `false`. */ processDomCallbacks: function (once, every, event) { var i = 0; for (i = 0; i < once.length; i++) { once[i](event); } for (i = 0; i < every.length; i++) { every[i](event); } once = []; return (every.length > 0); }, /** * Queues a touch start event, as passed in by the TouchManager. * Also dispatches any DOM callbacks for this event. * * @method Phaser.Input.InputManager#queueTouchStart * @private * @since 3.10.0 * * @param {TouchEvent} event - The native DOM Touch event. */ queueTouchStart: function (event) { this.queue.push(CONST.TOUCH_START, event); if (this._hasDownCallback) { var callbacks = this.domCallbacks; this._hasDownCallback = this.processDomCallbacks(callbacks.downOnce, callbacks.down, event); } }, /** * Queues a touch move event, as passed in by the TouchManager. * Also dispatches any DOM callbacks for this event. * * @method Phaser.Input.InputManager#queueTouchMove * @private * @since 3.10.0 * * @param {TouchEvent} event - The native DOM Touch event. */ queueTouchMove: function (event) { this.queue.push(CONST.TOUCH_MOVE, event); if (this._hasMoveCallback) { var callbacks = this.domCallbacks; this._hasMoveCallback = this.processDomCallbacks(callbacks.moveOnce, callbacks.move, event); } }, /** * Queues a touch end event, as passed in by the TouchManager. * Also dispatches any DOM callbacks for this event. * * @method Phaser.Input.InputManager#queueTouchEnd * @private * @since 3.10.0 * * @param {TouchEvent} event - The native DOM Touch event. */ queueTouchEnd: function (event) { this.queue.push(CONST.TOUCH_END, event); if (this._hasUpCallback) { var callbacks = this.domCallbacks; this._hasUpCallback = this.processDomCallbacks(callbacks.upOnce, callbacks.up, event); } }, /** * Queues a mouse down event, as passed in by the MouseManager. * Also dispatches any DOM callbacks for this event. * * @method Phaser.Input.InputManager#queueMouseDown * @private * @since 3.10.0 * * @param {MouseEvent} event - The native DOM Mouse event. */ queueMouseDown: function (event) { this.queue.push(CONST.MOUSE_DOWN, event); if (this._hasDownCallback) { var callbacks = this.domCallbacks; this._hasDownCallback = this.processDomCallbacks(callbacks.downOnce, callbacks.down, event); } }, /** * Queues a mouse move event, as passed in by the MouseManager. * Also dispatches any DOM callbacks for this event. * * @method Phaser.Input.InputManager#queueMouseMove * @private * @since 3.10.0 * * @param {MouseEvent} event - The native DOM Mouse event. */ queueMouseMove: function (event) { this.queue.push(CONST.MOUSE_MOVE, event); if (this._hasMoveCallback) { var callbacks = this.domCallbacks; this._hasMoveCallback = this.processDomCallbacks(callbacks.moveOnce, callbacks.move, event); } }, /** * Queues a mouse up event, as passed in by the MouseManager. * Also dispatches any DOM callbacks for this event. * * @method Phaser.Input.InputManager#queueMouseUp * @private * @since 3.10.0 * * @param {MouseEvent} event - The native DOM Mouse event. */ queueMouseUp: function (event) { this.queue.push(CONST.MOUSE_UP, event); if (this._hasUpCallback) { var callbacks = this.domCallbacks; this._hasUpCallback = this.processDomCallbacks(callbacks.upOnce, callbacks.up, event); } }, /** * Adds a callback to be invoked whenever the native DOM `mouseup` or `touchend` events are received. * By setting the `isOnce` argument you can control if the callback is called once, * or every time the DOM event occurs. * * Callbacks passed to this method are invoked _immediately_ when the DOM event happens, * within the scope of the DOM event handler. Therefore, they are considered as 'native' * from the perspective of the browser. This means they can be used for tasks such as * opening new browser windows, or anything which explicitly requires user input to activate. * However, as a result of this, they come with their own risks, and as such should not be used * for general game input, but instead be reserved for special circumstances. * * If all you're trying to do is execute a callback when a pointer is released, then * please use the internal Input event system instead. * * Please understand that these callbacks are invoked when the browser feels like doing so, * which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep * Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects, * change Scenes or manipulate internal systems, otherwise you run a very real risk of creating * heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind * solve. * * @method Phaser.Input.InputManager#addUpCallback * @since 3.10.0 * * @param {function} callback - The callback to be invoked on this dom event. * @param {boolean} [isOnce=true] - `true` if the callback will only be invoked once, `false` to call every time this event happens. * * @return {this} The Input Manager. */ addUpCallback: function (callback, isOnce) { if (isOnce === undefined) { isOnce = true; } if (isOnce) { this.domCallbacks.upOnce.push(callback); } else { this.domCallbacks.up.push(callback); } this._hasUpCallback = true; return this; }, /** * Adds a callback to be invoked whenever the native DOM `mousedown` or `touchstart` events are received. * By setting the `isOnce` argument you can control if the callback is called once, * or every time the DOM event occurs. * * Callbacks passed to this method are invoked _immediately_ when the DOM event happens, * within the scope of the DOM event handler. Therefore, they are considered as 'native' * from the perspective of the browser. This means they can be used for tasks such as * opening new browser windows, or anything which explicitly requires user input to activate. * However, as a result of this, they come with their own risks, and as such should not be used * for general game input, but instead be reserved for special circumstances. * * If all you're trying to do is execute a callback when a pointer is down, then * please use the internal Input event system instead. * * Please understand that these callbacks are invoked when the browser feels like doing so, * which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep * Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects, * change Scenes or manipulate internal systems, otherwise you run a very real risk of creating * heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind * solve. * * @method Phaser.Input.InputManager#addDownCallback * @since 3.10.0 * * @param {function} callback - The callback to be invoked on this dom event. * @param {boolean} [isOnce=true] - `true` if the callback will only be invoked once, `false` to call every time this event happens. * * @return {this} The Input Manager. */ addDownCallback: function (callback, isOnce) { if (isOnce === undefined) { isOnce = true; } if (isOnce) { this.domCallbacks.downOnce.push(callback); } else { this.domCallbacks.down.push(callback); } this._hasDownCallback = true; return this; }, /** * Adds a callback to be invoked whenever the native DOM `mousemove` or `touchmove` events are received. * By setting the `isOnce` argument you can control if the callback is called once, * or every time the DOM event occurs. * * Callbacks passed to this method are invoked _immediately_ when the DOM event happens, * within the scope of the DOM event handler. Therefore, they are considered as 'native' * from the perspective of the browser. This means they can be used for tasks such as * opening new browser windows, or anything which explicitly requires user input to activate. * However, as a result of this, they come with their own risks, and as such should not be used * for general game input, but instead be reserved for special circumstances. * * If all you're trying to do is execute a callback when a pointer is moved, then * please use the internal Input event system instead. * * Please understand that these callbacks are invoked when the browser feels like doing so, * which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep * Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects, * change Scenes or manipulate internal systems, otherwise you run a very real risk of creating * heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind * solve. * * @method Phaser.Input.InputManager#addMoveCallback * @since 3.10.0 * * @param {function} callback - The callback to be invoked on this dom event. * @param {boolean} [isOnce=false] - `true` if the callback will only be invoked once, `false` to call every time this event happens. * * @return {this} The Input Manager. */ addMoveCallback: function (callback, isOnce) { if (isOnce === undefined) { isOnce = false; } if (isOnce) { this.domCallbacks.moveOnce.push(callback); } else { this.domCallbacks.move.push(callback); } this._hasMoveCallback = true; return this; }, /** * Checks if the given Game Object should be considered as a candidate for input or not. * * Checks if the Game Object has an input component that is enabled, that it will render, * and finally, if it has a parent, that the parent parent, or any ancestor, is visible or not. * * @method Phaser.Input.InputManager#inputCandidate * @private * @since 3.10.0 * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to test. * * @return {boolean} `true` if the Game Object should be considered for input, otherwise `false`. */ inputCandidate: function (gameObject) { var input = gameObject.input; if (!input || !input.enabled || !gameObject.willRender()) { return false; } var visible = true; var parent = gameObject.parentContainer; if (parent) { do { if (!parent.visible) { visible = false; break; } parent = parent.parentContainer; } while (parent); } return visible; }, /** * Performs a hit test using the given Pointer and camera, against an array of interactive Game Objects. * * The Game Objects are culled against the camera, and then the coordinates are translated into the local camera space * and used to determine if they fall within the remaining Game Objects hit areas or not. * * If nothing is matched an empty array is returned. * * This method is called automatically by InputPlugin.hitTestPointer and doesn't usually need to be invoked directly. * * @method Phaser.Input.InputManager#hitTest * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The Pointer to test against. * @param {array} gameObjects - An array of interactive Game Objects to check. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera which is being tested against. * @param {array} [output] - An array to store the results in. If not given, a new empty array is created. * * @return {array} An array of the Game Objects that were hit during this hit test. */ hitTest: function (pointer, gameObjects, camera, output) { if (output === undefined) { output = this._tempHitTest; } var tempPoint = this._tempPoint; var cameraW = camera.width; var cameraH = camera.height; output.length = 0; var x = pointer.x; var y = pointer.y; if (!(x >= camera.x && y >= camera.y && x <= camera.x + cameraW && y <= camera.y + cameraH)) { return output; } // Stores the world point inside of tempPoint camera.getWorldPoint(x, y, tempPoint); pointer.worldX = tempPoint.x; pointer.worldY = tempPoint.y; // Disable until fixed. // var culledGameObjects = camera.cull(gameObjects); var point = { x: 0, y: 0 }; var res = this.game.config.resolution; var matrix = this._tempMatrix; for (var i = 0; i < gameObjects.length; i++) { var gameObject = gameObjects[i]; if (!this.inputCandidate(gameObject)) { continue; } var px = tempPoint.x * res + (camera.scrollX * gameObject.scrollFactorX) - camera.scrollX; var py = tempPoint.y * res + (camera.scrollY * gameObject.scrollFactorY) - camera.scrollY; if (gameObject.parentContainer) { gameObject.getWorldTransformMatrix(matrix); TransformXY(px, py, matrix.tx, matrix.ty, matrix.rotation, matrix.scaleX, matrix.scaleY, point); } else { TransformXY(px, py, gameObject.x, gameObject.y, gameObject.rotation, gameObject.scaleX, gameObject.scaleY, point); } if (this.pointWithinHitArea(gameObject, point.x, point.y)) { output.push(gameObject); } } return output; }, /** * Checks if the given x and y coordinate are within the hit area of the Game Object. * * This method assumes that the coordinate values have already been translated into the space of the Game Object. * * If the coordinates are within the hit area they are set into the Game Objects Input `localX` and `localY` properties. * * @method Phaser.Input.InputManager#pointWithinHitArea * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - The interactive Game Object to check against. * @param {number} x - The translated x coordinate for the hit test. * @param {number} y - The translated y coordinate for the hit test. * * @return {boolean} `true` if the coordinates were inside the Game Objects hit area, otherwise `false`. */ pointWithinHitArea: function (gameObject, x, y) { // Normalize the origin x += gameObject.displayOriginX; y += gameObject.displayOriginY; var input = gameObject.input; if (input && input.hitAreaCallback(input.hitArea, x, y, gameObject)) { input.localX = x; input.localY = y; return true; } else { return false; } }, /** * Checks if the given x and y coordinate are within the hit area of the Interactive Object. * * This method assumes that the coordinate values have already been translated into the space of the Interactive Object. * * If the coordinates are within the hit area they are set into the Interactive Objects Input `localX` and `localY` properties. * * @method Phaser.Input.InputManager#pointWithinInteractiveObject * @since 3.0.0 * * @param {Phaser.Input.InteractiveObject} object - The Interactive Object to check against. * @param {number} x - The translated x coordinate for the hit test. * @param {number} y - The translated y coordinate for the hit test. * * @return {boolean} `true` if the coordinates were inside the Game Objects hit area, otherwise `false`. */ pointWithinInteractiveObject: function (object, x, y) { if (!object.hitArea) { return false; } // Normalize the origin x += object.gameObject.displayOriginX; y += object.gameObject.displayOriginY; object.localX = x; object.localY = y; return object.hitAreaCallback(object.hitArea, x, y, object); }, /** * Transforms the pageX and pageY values of a Pointer into the scaled coordinate space of the Input Manager. * * @method Phaser.Input.InputManager#transformPointer * @since 3.10.0 * * @param {Phaser.Input.Pointer} pointer - The Pointer to transform the values for. * * @return {number} The translated value. */ transformPointer: function (pointer, pageX, pageY) { pointer.x = (pageX - this.bounds.left) * this.scale.x; pointer.y = (pageY - this.bounds.top) * this.scale.y; }, /** * Transforms the pageX value into the scaled coordinate space of the Input Manager. * * @method Phaser.Input.InputManager#transformX * @since 3.0.0 * * @param {number} pageX - The DOM pageX value. * * @return {number} The translated value. */ transformX: function (pageX) { return (pageX - this.bounds.left) * this.scale.x; }, /** * Transforms the pageY value into the scaled coordinate space of the Input Manager. * * @method Phaser.Input.InputManager#transformY * @since 3.0.0 * * @param {number} pageY - The DOM pageY value. * * @return {number} The translated value. */ transformY: function (pageY) { return (pageY - this.bounds.top) * this.scale.y; }, /** * Returns the left offset of the Input bounds. * * @method Phaser.Input.InputManager#getOffsetX * @since 3.0.0 * * @return {number} The left bounds value. */ getOffsetX: function () { return this.bounds.left; }, /** * Returns the top offset of the Input bounds. * * @method Phaser.Input.InputManager#getOffsetY * @since 3.0.0 * * @return {number} The top bounds value. */ getOffsetY: function () { return this.bounds.top; }, /** * Returns the horizontal Input Scale value. * * @method Phaser.Input.InputManager#getScaleX * @since 3.0.0 * * @return {number} The horizontal scale factor of the input. */ getScaleX: function () { return this.game.config.width / this.bounds.width; }, /** * Returns the vertical Input Scale value. * * @method Phaser.Input.InputManager#getScaleY * @since 3.0.0 * * @return {number} The vertical scale factor of the input. */ getScaleY: function () { return this.game.config.height / this.bounds.height; }, /** * Destroys the Input Manager and all of its systems. * * There is no way to recover from doing this. * * @method Phaser.Input.InputManager#destroy * @since 3.0.0 */ destroy: function () { this.events.removeAllListeners(); if (this.mouse) { this.mouse.destroy(); } if (this.touch) { this.touch.destroy(); } for (var i = 0; i < this.pointers.length; i++) { this.pointers[i].destroy(); } this.domCallbacks = {}; this.pointers = []; this.queue = []; this._tempHitTest = []; this._tempMatrix.destroy(); this.canvas = null; this.game = null; } }); module.exports = InputManager; /***/ }), /* 202 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Implements a model view projection matrices. * Pipelines can implement this for doing 2D and 3D rendering. */ var ModelViewProjection = { /** * Dirty flag for checking if model matrix needs to be updated on GPU. */ modelMatrixDirty: false, /** * Dirty flag for checking if view matrix needs to be updated on GPU. */ viewMatrixDirty: false, /** * Dirty flag for checking if projection matrix needs to be updated on GPU. */ projectionMatrixDirty: false, /** * Model matrix */ modelMatrix: null, /** * View matrix */ viewMatrix: null, /** * Projection matrix */ projectionMatrix: null, /** * Initializes MVP matrices with an identity matrix */ mvpInit: function () { this.modelMatrixDirty = true; this.viewMatrixDirty = true; this.projectionMatrixDirty = true; this.modelMatrix = new Float32Array([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]); this.viewMatrix = new Float32Array([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]); this.projectionMatrix = new Float32Array([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]); return this; }, /** * If dirty flags are set then the matrices are uploaded to the GPU. */ mvpUpdate: function () { var program = this.program; if (this.modelMatrixDirty) { this.renderer.setMatrix4(program, 'uModelMatrix', false, this.modelMatrix); this.modelMatrixDirty = false; } if (this.viewMatrixDirty) { this.renderer.setMatrix4(program, 'uViewMatrix', false, this.viewMatrix); this.viewMatrixDirty = false; } if (this.projectionMatrixDirty) { this.renderer.setMatrix4(program, 'uProjectionMatrix', false, this.projectionMatrix); this.projectionMatrixDirty = false; } return this; }, /** * Loads an identity matrix to the model matrix */ modelIdentity: function () { var modelMatrix = this.modelMatrix; modelMatrix[0] = 1; modelMatrix[1] = 0; modelMatrix[2] = 0; modelMatrix[3] = 0; modelMatrix[4] = 0; modelMatrix[5] = 1; modelMatrix[6] = 0; modelMatrix[7] = 0; modelMatrix[8] = 0; modelMatrix[9] = 0; modelMatrix[10] = 1; modelMatrix[11] = 0; modelMatrix[12] = 0; modelMatrix[13] = 0; modelMatrix[14] = 0; modelMatrix[15] = 1; this.modelMatrixDirty = true; return this; }, /** * Scale model matrix */ modelScale: function (x, y, z) { var modelMatrix = this.modelMatrix; modelMatrix[0] = modelMatrix[0] * x; modelMatrix[1] = modelMatrix[1] * x; modelMatrix[2] = modelMatrix[2] * x; modelMatrix[3] = modelMatrix[3] * x; modelMatrix[4] = modelMatrix[4] * y; modelMatrix[5] = modelMatrix[5] * y; modelMatrix[6] = modelMatrix[6] * y; modelMatrix[7] = modelMatrix[7] * y; modelMatrix[8] = modelMatrix[8] * z; modelMatrix[9] = modelMatrix[9] * z; modelMatrix[10] = modelMatrix[10] * z; modelMatrix[11] = modelMatrix[11] * z; this.modelMatrixDirty = true; return this; }, /** * Translate model matrix */ modelTranslate: function (x, y, z) { var modelMatrix = this.modelMatrix; modelMatrix[12] = modelMatrix[0] * x + modelMatrix[4] * y + modelMatrix[8] * z + modelMatrix[12]; modelMatrix[13] = modelMatrix[1] * x + modelMatrix[5] * y + modelMatrix[9] * z + modelMatrix[13]; modelMatrix[14] = modelMatrix[2] * x + modelMatrix[6] * y + modelMatrix[10] * z + modelMatrix[14]; modelMatrix[15] = modelMatrix[3] * x + modelMatrix[7] * y + modelMatrix[11] * z + modelMatrix[15]; this.modelMatrixDirty = true; return this; }, /** * Rotates the model matrix in the X axis. */ modelRotateX: function (radians) { var modelMatrix = this.modelMatrix; var s = Math.sin(radians); var c = Math.cos(radians); var a10 = modelMatrix[4]; var a11 = modelMatrix[5]; var a12 = modelMatrix[6]; var a13 = modelMatrix[7]; var a20 = modelMatrix[8]; var a21 = modelMatrix[9]; var a22 = modelMatrix[10]; var a23 = modelMatrix[11]; modelMatrix[4] = a10 * c + a20 * s; modelMatrix[5] = a11 * c + a21 * s; modelMatrix[6] = a12 * c + a22 * s; modelMatrix[7] = a13 * c + a23 * s; modelMatrix[8] = a20 * c - a10 * s; modelMatrix[9] = a21 * c - a11 * s; modelMatrix[10] = a22 * c - a12 * s; modelMatrix[11] = a23 * c - a13 * s; this.modelMatrixDirty = true; return this; }, /** * Rotates the model matrix in the Y axis. */ modelRotateY: function (radians) { var modelMatrix = this.modelMatrix; var s = Math.sin(radians); var c = Math.cos(radians); var a00 = modelMatrix[0]; var a01 = modelMatrix[1]; var a02 = modelMatrix[2]; var a03 = modelMatrix[3]; var a20 = modelMatrix[8]; var a21 = modelMatrix[9]; var a22 = modelMatrix[10]; var a23 = modelMatrix[11]; modelMatrix[0] = a00 * c - a20 * s; modelMatrix[1] = a01 * c - a21 * s; modelMatrix[2] = a02 * c - a22 * s; modelMatrix[3] = a03 * c - a23 * s; modelMatrix[8] = a00 * s + a20 * c; modelMatrix[9] = a01 * s + a21 * c; modelMatrix[10] = a02 * s + a22 * c; modelMatrix[11] = a03 * s + a23 * c; this.modelMatrixDirty = true; return this; }, /** * Rotates the model matrix in the Z axis. */ modelRotateZ: function (radians) { var modelMatrix = this.modelMatrix; var s = Math.sin(radians); var c = Math.cos(radians); var a00 = modelMatrix[0]; var a01 = modelMatrix[1]; var a02 = modelMatrix[2]; var a03 = modelMatrix[3]; var a10 = modelMatrix[4]; var a11 = modelMatrix[5]; var a12 = modelMatrix[6]; var a13 = modelMatrix[7]; modelMatrix[0] = a00 * c + a10 * s; modelMatrix[1] = a01 * c + a11 * s; modelMatrix[2] = a02 * c + a12 * s; modelMatrix[3] = a03 * c + a13 * s; modelMatrix[4] = a10 * c - a00 * s; modelMatrix[5] = a11 * c - a01 * s; modelMatrix[6] = a12 * c - a02 * s; modelMatrix[7] = a13 * c - a03 * s; this.modelMatrixDirty = true; return this; }, /** * Loads identity matrix into the view matrix */ viewIdentity: function () { var viewMatrix = this.viewMatrix; viewMatrix[0] = 1; viewMatrix[1] = 0; viewMatrix[2] = 0; viewMatrix[3] = 0; viewMatrix[4] = 0; viewMatrix[5] = 1; viewMatrix[6] = 0; viewMatrix[7] = 0; viewMatrix[8] = 0; viewMatrix[9] = 0; viewMatrix[10] = 1; viewMatrix[11] = 0; viewMatrix[12] = 0; viewMatrix[13] = 0; viewMatrix[14] = 0; viewMatrix[15] = 1; this.viewMatrixDirty = true; return this; }, /** * Scales view matrix */ viewScale: function (x, y, z) { var viewMatrix = this.viewMatrix; viewMatrix[0] = viewMatrix[0] * x; viewMatrix[1] = viewMatrix[1] * x; viewMatrix[2] = viewMatrix[2] * x; viewMatrix[3] = viewMatrix[3] * x; viewMatrix[4] = viewMatrix[4] * y; viewMatrix[5] = viewMatrix[5] * y; viewMatrix[6] = viewMatrix[6] * y; viewMatrix[7] = viewMatrix[7] * y; viewMatrix[8] = viewMatrix[8] * z; viewMatrix[9] = viewMatrix[9] * z; viewMatrix[10] = viewMatrix[10] * z; viewMatrix[11] = viewMatrix[11] * z; this.viewMatrixDirty = true; return this; }, /** * Translates view matrix */ viewTranslate: function (x, y, z) { var viewMatrix = this.viewMatrix; viewMatrix[12] = viewMatrix[0] * x + viewMatrix[4] * y + viewMatrix[8] * z + viewMatrix[12]; viewMatrix[13] = viewMatrix[1] * x + viewMatrix[5] * y + viewMatrix[9] * z + viewMatrix[13]; viewMatrix[14] = viewMatrix[2] * x + viewMatrix[6] * y + viewMatrix[10] * z + viewMatrix[14]; viewMatrix[15] = viewMatrix[3] * x + viewMatrix[7] * y + viewMatrix[11] * z + viewMatrix[15]; this.viewMatrixDirty = true; return this; }, /** * Rotates view matrix in the X axis. */ viewRotateX: function (radians) { var viewMatrix = this.viewMatrix; var s = Math.sin(radians); var c = Math.cos(radians); var a10 = viewMatrix[4]; var a11 = viewMatrix[5]; var a12 = viewMatrix[6]; var a13 = viewMatrix[7]; var a20 = viewMatrix[8]; var a21 = viewMatrix[9]; var a22 = viewMatrix[10]; var a23 = viewMatrix[11]; viewMatrix[4] = a10 * c + a20 * s; viewMatrix[5] = a11 * c + a21 * s; viewMatrix[6] = a12 * c + a22 * s; viewMatrix[7] = a13 * c + a23 * s; viewMatrix[8] = a20 * c - a10 * s; viewMatrix[9] = a21 * c - a11 * s; viewMatrix[10] = a22 * c - a12 * s; viewMatrix[11] = a23 * c - a13 * s; this.viewMatrixDirty = true; return this; }, /** * Rotates view matrix in the Y axis. */ viewRotateY: function (radians) { var viewMatrix = this.viewMatrix; var s = Math.sin(radians); var c = Math.cos(radians); var a00 = viewMatrix[0]; var a01 = viewMatrix[1]; var a02 = viewMatrix[2]; var a03 = viewMatrix[3]; var a20 = viewMatrix[8]; var a21 = viewMatrix[9]; var a22 = viewMatrix[10]; var a23 = viewMatrix[11]; viewMatrix[0] = a00 * c - a20 * s; viewMatrix[1] = a01 * c - a21 * s; viewMatrix[2] = a02 * c - a22 * s; viewMatrix[3] = a03 * c - a23 * s; viewMatrix[8] = a00 * s + a20 * c; viewMatrix[9] = a01 * s + a21 * c; viewMatrix[10] = a02 * s + a22 * c; viewMatrix[11] = a03 * s + a23 * c; this.viewMatrixDirty = true; return this; }, /** * Rotates view matrix in the Z axis. */ viewRotateZ: function (radians) { var viewMatrix = this.viewMatrix; var s = Math.sin(radians); var c = Math.cos(radians); var a00 = viewMatrix[0]; var a01 = viewMatrix[1]; var a02 = viewMatrix[2]; var a03 = viewMatrix[3]; var a10 = viewMatrix[4]; var a11 = viewMatrix[5]; var a12 = viewMatrix[6]; var a13 = viewMatrix[7]; viewMatrix[0] = a00 * c + a10 * s; viewMatrix[1] = a01 * c + a11 * s; viewMatrix[2] = a02 * c + a12 * s; viewMatrix[3] = a03 * c + a13 * s; viewMatrix[4] = a10 * c - a00 * s; viewMatrix[5] = a11 * c - a01 * s; viewMatrix[6] = a12 * c - a02 * s; viewMatrix[7] = a13 * c - a03 * s; this.viewMatrixDirty = true; return this; }, /** * Loads a 2D view matrix (3x2 matrix) into a 4x4 view matrix */ viewLoad2D: function (matrix2D) { var vm = this.viewMatrix; vm[0] = matrix2D[0]; vm[1] = matrix2D[1]; vm[2] = 0.0; vm[3] = 0.0; vm[4] = matrix2D[2]; vm[5] = matrix2D[3]; vm[6] = 0.0; vm[7] = 0.0; vm[8] = matrix2D[4]; vm[9] = matrix2D[5]; vm[10] = 1.0; vm[11] = 0.0; vm[12] = 0.0; vm[13] = 0.0; vm[14] = 0.0; vm[15] = 1.0; this.viewMatrixDirty = true; return this; }, /** * Copies a 4x4 matrix into the view matrix */ viewLoad: function (matrix) { var vm = this.viewMatrix; vm[0] = matrix[0]; vm[1] = matrix[1]; vm[2] = matrix[2]; vm[3] = matrix[3]; vm[4] = matrix[4]; vm[5] = matrix[5]; vm[6] = matrix[6]; vm[7] = matrix[7]; vm[8] = matrix[8]; vm[9] = matrix[9]; vm[10] = matrix[10]; vm[11] = matrix[11]; vm[12] = matrix[12]; vm[13] = matrix[13]; vm[14] = matrix[14]; vm[15] = matrix[15]; this.viewMatrixDirty = true; return this; }, /** * Loads identity matrix into the projection matrix. */ projIdentity: function () { var projectionMatrix = this.projectionMatrix; projectionMatrix[0] = 1; projectionMatrix[1] = 0; projectionMatrix[2] = 0; projectionMatrix[3] = 0; projectionMatrix[4] = 0; projectionMatrix[5] = 1; projectionMatrix[6] = 0; projectionMatrix[7] = 0; projectionMatrix[8] = 0; projectionMatrix[9] = 0; projectionMatrix[10] = 1; projectionMatrix[11] = 0; projectionMatrix[12] = 0; projectionMatrix[13] = 0; projectionMatrix[14] = 0; projectionMatrix[15] = 1; this.projectionMatrixDirty = true; return this; }, /** * Sets up an orthographics projection matrix */ projOrtho: function (left, right, bottom, top, near, far) { var projectionMatrix = this.projectionMatrix; var leftRight = 1.0 / (left - right); var bottomTop = 1.0 / (bottom - top); var nearFar = 1.0 / (near - far); projectionMatrix[0] = -2.0 * leftRight; projectionMatrix[1] = 0.0; projectionMatrix[2] = 0.0; projectionMatrix[3] = 0.0; projectionMatrix[4] = 0.0; projectionMatrix[5] = -2.0 * bottomTop; projectionMatrix[6] = 0.0; projectionMatrix[7] = 0.0; projectionMatrix[8] = 0.0; projectionMatrix[9] = 0.0; projectionMatrix[10] = 2.0 * nearFar; projectionMatrix[11] = 0.0; projectionMatrix[12] = (left + right) * leftRight; projectionMatrix[13] = (top + bottom) * bottomTop; projectionMatrix[14] = (far + near) * nearFar; projectionMatrix[15] = 1.0; this.projectionMatrixDirty = true; return this; }, /** * Sets up a perspective projection matrix */ projPersp: function (fovy, aspectRatio, near, far) { var projectionMatrix = this.projectionMatrix; var fov = 1.0 / Math.tan(fovy / 2.0); var nearFar = 1.0 / (near - far); projectionMatrix[0] = fov / aspectRatio; projectionMatrix[1] = 0.0; projectionMatrix[2] = 0.0; projectionMatrix[3] = 0.0; projectionMatrix[4] = 0.0; projectionMatrix[5] = fov; projectionMatrix[6] = 0.0; projectionMatrix[7] = 0.0; projectionMatrix[8] = 0.0; projectionMatrix[9] = 0.0; projectionMatrix[10] = (far + near) * nearFar; projectionMatrix[11] = -1.0; projectionMatrix[12] = 0.0; projectionMatrix[13] = 0.0; projectionMatrix[14] = (2.0 * far * near) * nearFar; projectionMatrix[15] = 0.0; this.projectionMatrixDirty = true; return this; } }; module.exports = ModelViewProjection; /***/ }), /* 203 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CanvasPool = __webpack_require__(22); /** * Determines the canvas features of the browser running this Phaser Game instance. * These values are read-only and populated during the boot sequence of the game. * They are then referenced by internal game systems and are available for you to access * via `this.sys.game.device.canvasFeatures` from within any Scene. * * @typedef {object} Phaser.Device.CanvasFeatures * @since 3.0.0 * * @property {boolean} supportInverseAlpha - Set to true if the browser supports inversed alpha. * @property {boolean} supportNewBlendModes - Set to true if the browser supports new canvas blend modes. */ var CanvasFeatures = { supportInverseAlpha: false, supportNewBlendModes: false }; function checkBlendMode () { var pngHead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABAQMAAADD8p2OAAAAA1BMVEX/'; var pngEnd = 'AAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg=='; var magenta = new Image(); magenta.onload = function () { var yellow = new Image(); yellow.onload = function () { var canvas = CanvasPool.create(yellow, 6, 1); var context = canvas.getContext('2d'); context.globalCompositeOperation = 'multiply'; context.drawImage(magenta, 0, 0); context.drawImage(yellow, 2, 0); if (!context.getImageData(2, 0, 1, 1)) { return false; } var data = context.getImageData(2, 0, 1, 1).data; CanvasPool.remove(yellow); CanvasFeatures.supportNewBlendModes = (data[0] === 255 && data[1] === 0 && data[2] === 0); }; yellow.src = pngHead + '/wCKxvRF' + pngEnd; }; magenta.src = pngHead + 'AP804Oa6' + pngEnd; return false; } function checkInverseAlpha () { var canvas = CanvasPool.create(this, 2, 1); var context = canvas.getContext('2d'); context.fillStyle = 'rgba(10, 20, 30, 0.5)'; // Draw a single pixel context.fillRect(0, 0, 1, 1); // Get the color values var s1 = context.getImageData(0, 0, 1, 1); if (s1 === null) { return false; } // Plot them to x2 context.putImageData(s1, 1, 0); // Get those values var s2 = context.getImageData(1, 0, 1, 1); // Compare and return return (s2.data[0] === s1.data[0] && s2.data[1] === s1.data[1] && s2.data[2] === s1.data[2] && s2.data[3] === s1.data[3]); } function init () { if (document !== undefined) { CanvasFeatures.supportNewBlendModes = checkBlendMode(); CanvasFeatures.supportInverseAlpha = checkInverseAlpha(); } return CanvasFeatures; } module.exports = init(); /***/ }), /* 204 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Cameras.Scene2D.Effects */ module.exports = { Fade: __webpack_require__(565), Flash: __webpack_require__(564), Shake: __webpack_require__(563) }; /***/ }), /* 205 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BaseCache = __webpack_require__(206); var Class = __webpack_require__(0); /** * @classdesc * The Cache Manager is the global cache owned and maintained by the Game instance. * * Various systems, such as the file Loader, rely on this cache in order to store the files * it has loaded. The manager itself doesn't store any files, but instead owns multiple BaseCache * instances, one per type of file. You can also add your own custom caches. * * @class CacheManager * @memberOf Phaser.Cache * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - A reference to the Phaser.Game instance that owns this CacheManager. */ var CacheManager = new Class({ initialize: function CacheManager (game) { /** * A reference to the Phaser.Game instance that owns this CacheManager. * * @name Phaser.Cache.CacheManager#game * @type {Phaser.Game} * @protected * @since 3.0.0 */ this.game = game; /** * A Cache storing all binary files, typically added via the Loader. * * @name Phaser.Cache.CacheManager#binary * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.binary = new BaseCache(); /** * A Cache storing all bitmap font data files, typically added via the Loader. * Only the font data is stored in this cache, the textures are part of the Texture Manager. * * @name Phaser.Cache.CacheManager#bitmapFont * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.bitmapFont = new BaseCache(); /** * A Cache storing all JSON data files, typically added via the Loader. * * @name Phaser.Cache.CacheManager#json * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.json = new BaseCache(); /** * A Cache storing all physics data files, typically added via the Loader. * * @name Phaser.Cache.CacheManager#physics * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.physics = new BaseCache(); /** * A Cache storing all shader source files, typically added via the Loader. * * @name Phaser.Cache.CacheManager#shader * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.shader = new BaseCache(); /** * A Cache storing all non-streaming audio files, typically added via the Loader. * * @name Phaser.Cache.CacheManager#audio * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.audio = new BaseCache(); /** * A Cache storing all text files, typically added via the Loader. * * @name Phaser.Cache.CacheManager#text * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.text = new BaseCache(); /** * A Cache storing all WaveFront OBJ files, typically added via the Loader. * * @name Phaser.Cache.CacheManager#obj * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.obj = new BaseCache(); /** * A Cache storing all tilemap data files, typically added via the Loader. * Only the data is stored in this cache, the textures are part of the Texture Manager. * * @name Phaser.Cache.CacheManager#tilemap * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.tilemap = new BaseCache(); /** * A Cache storing all xml data files, typically added via the Loader. * * @name Phaser.Cache.CacheManager#xml * @type {Phaser.Cache.BaseCache} * @since 3.0.0 */ this.xml = new BaseCache(); /** * An object that contains your own custom BaseCache entries. * Add to this via the `addCustom` method. * * @name Phaser.Cache.CacheManager#custom * @type {Object.} * @since 3.0.0 */ this.custom = {}; this.game.events.once('destroy', this.destroy, this); }, /** * Add your own custom Cache for storing your own files. * The cache will be available under `Cache.custom.key`. * The cache will only be created if the key is not already in use. * * @method Phaser.Cache.CacheManager#addCustom * @since 3.0.0 * * @param {string} key - The unique key of your custom cache. * * @return {Phaser.Cache.BaseCache} A reference to the BaseCache that was created. If the key was already in use, a reference to the existing cache is returned instead. */ addCustom: function (key) { if (!this.custom.hasOwnProperty(key)) { this.custom[key] = new BaseCache(); } return this.custom[key]; }, /** * Removes all entries from all BaseCaches and destroys all custom caches. * * @method Phaser.Cache.CacheManager#destroy * @since 3.0.0 */ destroy: function () { var keys = [ 'binary', 'bitmapFont', 'json', 'physics', 'shader', 'audio', 'text', 'obj', 'tilemap', 'xml' ]; for (var i = 0; i < keys.length; i++) { this[keys[i]].destroy(); this[keys[i]] = null; } for (var key in this.custom) { this.custom[key].destroy(); } this.custom = null; this.game = null; } }); module.exports = CacheManager; /***/ }), /* 206 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CustomMap = __webpack_require__(124); var EventEmitter = __webpack_require__(9); /** * @classdesc * The BaseCache is a base Cache class that can be used for storing references to any kind of data. * * Data can be added, retrieved and removed based on the given keys. * * Keys are string-based. * * @class BaseCache * @memberOf Phaser.Cache * @constructor * @since 3.0.0 */ var BaseCache = new Class({ initialize: function BaseCache () { /** * The Map in which the cache objects are stored. * * You can query the Map directly or use the BaseCache methods. * * @name Phaser.Cache.BaseCache#entries * @type {Phaser.Structs.Map.} * @since 3.0.0 */ this.entries = new CustomMap(); /** * An instance of EventEmitter used by the cache to emit related events. * * @name Phaser.Cache.BaseCache#events * @type {Phaser.Events.EventEmitter} * @since 3.0.0 */ this.events = new EventEmitter(); }, /** * Cache add event. * * This event is fired by the Cache each time a new object is added to it. * * @event Phaser.Cache.BaseCache#addEvent * @param {Phaser.Cache.BaseCache} cache - The BaseCache to which the object was added. * @param {string} key - The key of the object added to the cache. * @param {*} object - A reference to the object added to the cache. */ /** * Adds an item to this cache. The item is referenced by a unique string, which you are responsible * for setting and keeping track of. The item can only be retrieved by using this string. * * @method Phaser.Cache.BaseCache#add * @fires Phaser.Cache.BaseCache#addEvent * @since 3.0.0 * * @param {string} key - The unique key by which the data added to the cache will be referenced. * @param {*} data - The data to be stored in the cache. * * @return {Phaser.Cache.BaseCache} This BaseCache object. */ add: function (key, data) { this.entries.set(key, data); this.events.emit('add', this, key, data); return this; }, /** * Checks if this cache contains an item matching the given key. * This performs the same action as `BaseCache.exists`. * * @method Phaser.Cache.BaseCache#has * @since 3.0.0 * * @param {string} key - The unique key of the item to be checked in this cache. * * @return {boolean} Returns `true` if the cache contains an item matching the given key, otherwise `false`. */ has: function (key) { return this.entries.has(key); }, /** * Checks if this cache contains an item matching the given key. * This performs the same action as `BaseCache.has` and is called directly by the Loader. * * @method Phaser.Cache.BaseCache#exists * @since 3.7.0 * * @param {string} key - The unique key of the item to be checked in this cache. * * @return {boolean} Returns `true` if the cache contains an item matching the given key, otherwise `false`. */ exists: function (key) { return this.entries.has(key); }, /** * Gets an item from this cache based on the given key. * * @method Phaser.Cache.BaseCache#get * @since 3.0.0 * * @param {string} key - The unique key of the item to be retrieved from this cache. * * @return {*} The item in the cache, or `null` if no item matching the given key was found. */ get: function (key) { return this.entries.get(key); }, /** * Cache remove event. * * This event is fired by the Cache each time an object is removed from it. * * @event Phaser.Cache.BaseCache#removeEvent * @param {Phaser.Cache.BaseCache} cache - The BaseCache from which the object was removed. * @param {string} key - The key of the object removed from the cache. * @param {*} object - The object that was removed from the cache. */ /** * Removes and item from this cache based on the given key. * * If an entry matching the key is found it is removed from the cache and a `remove` event emitted. * No additional checks are done on the item removed. If other systems or parts of your game code * are relying on this item, it is up to you to sever those relationships prior to removing the item. * * @method Phaser.Cache.BaseCache#remove * @fires Phaser.Cache.BaseCache#removeEvent * @since 3.0.0 * * @param {string} key - The unique key of the item to remove from the cache. * * @return {Phaser.Cache.BaseCache} This BaseCache object. */ remove: function (key) { var entry = this.get(key); if (entry) { this.entries.delete(key); this.events.emit('remove', this, key, entry.data); } return this; }, /** * Destroys this cache and all items within it. * * @method Phaser.Cache.BaseCache#destroy * @since 3.0.0 */ destroy: function () { this.entries.clear(); this.events.removeAllListeners(); this.entries = null; this.events = null; } }); module.exports = BaseCache; /***/ }), /* 207 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Animation = __webpack_require__(210); var Class = __webpack_require__(0); var CustomMap = __webpack_require__(124); var EventEmitter = __webpack_require__(9); var GetValue = __webpack_require__(4); var Pad = __webpack_require__(133); /** * @typedef {object} JSONAnimationManager * * @property {JSONAnimation[]} anims - [description] * @property {number} globalTimeScale - [description] */ /** * @classdesc * The Animation Manager. * * Animations are managed by the global Animation Manager. This is a singleton class that is * responsible for creating and delivering animations and their corresponding data to all Game Objects. * Unlike plugins it is owned by the Game instance, not the Scene. * * Sprites and other Game Objects get the data they need from the AnimationManager. * * @class AnimationManager * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Animations * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - [description] */ var AnimationManager = new Class({ Extends: EventEmitter, initialize: function AnimationManager (game) { EventEmitter.call(this); /** * [description] * * @name Phaser.Animations.AnimationManager#game * @type {Phaser.Game} * @protected * @since 3.0.0 */ this.game = game; /** * [description] * * @name Phaser.Animations.AnimationManager#textureManager * @type {Phaser.Textures.TextureManager} * @protected * @since 3.0.0 */ this.textureManager = null; /** * [description] * * @name Phaser.Animations.AnimationManager#globalTimeScale * @type {number} * @default 1 * @since 3.0.0 */ this.globalTimeScale = 1; /** * [description] * * @name Phaser.Animations.AnimationManager#anims * @type {Phaser.Structs.Map.} * @protected * @since 3.0.0 */ this.anims = new CustomMap(); /** * [description] * * @name Phaser.Animations.AnimationManager#paused * @type {boolean} * @default false * @since 3.0.0 */ this.paused = false; /** * [description] * * @name Phaser.Animations.AnimationManager#name * @type {string} * @since 3.0.0 */ this.name = 'AnimationManager'; game.events.once('boot', this.boot, this); }, /** * [description] * * @method Phaser.Animations.AnimationManager#boot * @since 3.0.0 */ boot: function () { this.textureManager = this.game.textures; this.game.events.once('destroy', this.destroy, this); }, /** * [description] * * @method Phaser.Animations.AnimationManager#add * @fires AddAnimationEvent * @since 3.0.0 * * @param {string} key - [description] * @param {Phaser.Animations.Animation} animation - [description] * * @return {Phaser.Animations.AnimationManager} This Animation Manager. */ add: function (key, animation) { if (this.anims.has(key)) { console.warn('Animation with key', key, 'already exists'); return; } animation.key = key; this.anims.set(key, animation); this.emit('add', key, animation); return this; }, /** * [description] * * @method Phaser.Animations.AnimationManager#create * @fires AddAnimationEvent * @since 3.0.0 * * @param {AnimationConfig} config - [description] * * @return {Phaser.Animations.Animation} The Animation that was created. */ create: function (config) { var key = config.key; if (!key || this.anims.has(key)) { console.warn('Invalid Animation Key, or Key already in use: ' + key); return; } var anim = new Animation(this, key, config); this.anims.set(key, anim); this.emit('add', key, anim); return anim; }, /** * [description] * * @method Phaser.Animations.AnimationManager#fromJSON * @since 3.0.0 * * @param {(string|JSONAnimationManager|JSONAnimation)} data - [description] * @param {boolean} [clearCurrentAnimations=false] - [description] * * @return {Phaser.Animations.Animation[]} An array containing all of the Animation objects that were created as a result of this call. */ fromJSON: function (data, clearCurrentAnimations) { if (clearCurrentAnimations === undefined) { clearCurrentAnimations = false; } if (clearCurrentAnimations) { this.anims.clear(); } // Do we have a String (i.e. from JSON, or an Object?) if (typeof data === 'string') { data = JSON.parse(data); } var output = []; // Array of animations, or a single animation? if (data.hasOwnProperty('anims') && Array.isArray(data.anims)) { for (var i = 0; i < data.anims.length; i++) { output.push(this.create(data.anims[i])); } if (data.hasOwnProperty('globalTimeScale')) { this.globalTimeScale = data.globalTimeScale; } } else if (data.hasOwnProperty('key') && data.type === 'frame') { output.push(this.create(data)); } return output; }, /** * @typedef {object} GenerateFrameNamesConfig * * @property {string} [prefix=''] - [description] * @property {integer} [start=0] - [description] * @property {integer} [end=0] - [description] * @property {string} [suffix=''] - [description] * @property {integer} [zeroPad=0] - [description] * @property {AnimationFrameConfig[]} [outputArray=[]] - [description] * @property {boolean} [frames=false] - [description] */ /** * [description] * * @method Phaser.Animations.AnimationManager#generateFrameNames * @since 3.0.0 * * @param {string} key - [description] * @param {GenerateFrameNamesConfig} [config] - [description] * * @return {AnimationFrameConfig[]} [description] */ generateFrameNames: function (key, config) { var prefix = GetValue(config, 'prefix', ''); var start = GetValue(config, 'start', 0); var end = GetValue(config, 'end', 0); var suffix = GetValue(config, 'suffix', ''); var zeroPad = GetValue(config, 'zeroPad', 0); var out = GetValue(config, 'outputArray', []); var frames = GetValue(config, 'frames', false); var texture = this.textureManager.get(key); if (!texture) { return out; } var diff = (start < end) ? 1 : -1; // Adjust because we use i !== end in the for loop end += diff; var i; var frame; if (!config) { // Use every frame in the atlas? frames = texture.getFrameNames(); for (i = 0; i < frames.length; i++) { out.push({ key: key, frame: frames[i] }); } } else if (Array.isArray(frames)) { // Have they provided their own custom frame sequence array? for (i = 0; i < frames.length; i++) { frame = prefix + Pad(frames[i], zeroPad, '0', 1) + suffix; if (texture.has(frame)) { out.push({ key: key, frame: frame }); } } } else { for (i = start; i !== end; i += diff) { frame = prefix + Pad(i, zeroPad, '0', 1) + suffix; if (texture.has(frame)) { out.push({ key: key, frame: frame }); } } } return out; }, /** * @typedef {object} GenerateFrameNumbersConfig * * @property {integer} [start=0] - [description] * @property {integer} [end=-1] - [description] * @property {boolean} [first=false] - [description] * @property {AnimationFrameConfig[]} [outputArray=[]] - [description] * @property {boolean} [frames=false] - [description] */ /** * [description] * * @method Phaser.Animations.AnimationManager#generateFrameNumbers * @since 3.0.0 * * @param {string} key - [description] * @param {GenerateFrameNumbersConfig} config - [description] * * @return {AnimationFrameConfig[]} [description] */ generateFrameNumbers: function (key, config) { var startFrame = GetValue(config, 'start', 0); var endFrame = GetValue(config, 'end', -1); var firstFrame = GetValue(config, 'first', false); var out = GetValue(config, 'outputArray', []); var frames = GetValue(config, 'frames', false); var texture = this.textureManager.get(key); if (!texture) { return out; } if (firstFrame && texture.has(firstFrame)) { out.push({ key: key, frame: firstFrame }); } var i; // Have they provided their own custom frame sequence array? if (Array.isArray(frames)) { for (i = 0; i < frames.length; i++) { if (texture.has(frames[i])) { out.push({ key: key, frame: frames[i] }); } } } else { // No endFrame then see if we can get it if (endFrame === -1) { endFrame = texture.frameTotal; } for (i = startFrame; i <= endFrame; i++) { if (texture.has(i)) { out.push({ key: key, frame: i }); } } } return out; }, /** * [description] * * @method Phaser.Animations.AnimationManager#get * @since 3.0.0 * * @param {string} key - [description] * * @return {Phaser.Animations.Animation} [description] */ get: function (key) { return this.anims.get(key); }, /** * Load an Animation into a Game Objects Animation Component. * * @method Phaser.Animations.AnimationManager#load * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} child - [description] * @param {string} key - [description] * @param {(string|integer)} [startFrame] - [description] * * @return {Phaser.GameObjects.GameObject} [description] */ load: function (child, key, startFrame) { var anim = this.get(key); if (anim) { anim.load(child, startFrame); } return child; }, /** * [description] * * @method Phaser.Animations.AnimationManager#pauseAll * @fires PauseAllAnimationEvent * @since 3.0.0 * * @return {Phaser.Animations.AnimationManager} This Animation Manager. */ pauseAll: function () { if (!this.paused) { this.paused = true; this.emit('pauseall'); } return this; }, /** * [description] * * @method Phaser.Animations.AnimationManager#play * @since 3.0.0 * * @param {string} key - [description] * @param {Phaser.GameObjects.GameObject} child - [description] * * @return {Phaser.Animations.AnimationManager} This Animation Manager. */ play: function (key, child) { if (!Array.isArray(child)) { child = [ child ]; } var anim = this.get(key); if (!anim) { return; } for (var i = 0; i < child.length; i++) { child[i].anims.play(key); } return this; }, /** * [description] * * @method Phaser.Animations.AnimationManager#remove * @fires RemoveAnimationEvent * @since 3.0.0 * * @param {string} key - [description] * * @return {Phaser.Animations.Animation} [description] */ remove: function (key) { var anim = this.get(key); if (anim) { this.emit('remove', key, anim); this.anims.delete(key); } return anim; }, /** * [description] * * @method Phaser.Animations.AnimationManager#resumeAll * @fires ResumeAllAnimationEvent * @since 3.0.0 * * @return {Phaser.Animations.AnimationManager} This Animation Manager. */ resumeAll: function () { if (this.paused) { this.paused = false; this.emit('resumeall'); } return this; }, /** * Takes an array of Game Objects that have the Animation Component and then * starts the given animation playing on them, each one offset by the * `stagger` amount given to this method. * * @method Phaser.Animations.AnimationManager#staggerPlay * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {string} key - The key of the animation to play on the Game Objects. * @param {Phaser.GameObjects.GameObject[]} children - An array of Game Objects to play the animation on. They must have the Animation Component. * @param {number} [stagger=0] - The amount of time, in milliseconds, to offset each play time by. * * @return {Phaser.Animations.AnimationManager} This Animation Manager. */ staggerPlay: function (key, children, stagger) { if (stagger === undefined) { stagger = 0; } if (!Array.isArray(children)) { children = [ children ]; } var anim = this.get(key); if (!anim) { return; } for (var i = 0; i < children.length; i++) { children[i].anims.delayedPlay(stagger * i, key); } return this; }, /** * [description] * * @method Phaser.Animations.AnimationManager#toJSON * @since 3.0.0 * * @param {string} key - [description] * * @return {JSONAnimationManager} [description] */ toJSON: function (key) { if (key !== undefined && key !== '') { return this.anims.get(key).toJSON(); } else { var output = { anims: [], globalTimeScale: this.globalTimeScale }; this.anims.each(function (animationKey, animation) { output.anims.push(animation.toJSON()); }); return output; } }, /** * [description] * * @method Phaser.Animations.AnimationManager#destroy * @since 3.0.0 */ destroy: function () { this.anims.clear(); this.textureManager = null; this.game = null; } }); module.exports = AnimationManager; /***/ }), /* 208 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @typedef {object} JSONAnimationFrame * * @property {string} key - The key of the Texture this AnimationFrame uses. * @property {(string|integer)} frame - The key of the Frame within the Texture that this AnimationFrame uses. * @property {number} duration - Additional time (in ms) that this frame should appear for during playback. */ /** * @classdesc * A single frame in an Animation sequence. * * An AnimationFrame consists of a reference to the Texture it uses for rendering, references to other * frames in the animation, and index data. It also has the ability to fire its own `onUpdate` callback * and modify the animation timing. * * AnimationFrames are generated automatically by the Animation class. * * @class AnimationFrame * @memberOf Phaser.Animations * @constructor * @since 3.0.0 * * @param {string} textureKey - The key of the Texture this AnimationFrame uses. * @param {(string|integer)} textureFrame - The key of the Frame within the Texture that this AnimationFrame uses. * @param {integer} index - The index of this AnimationFrame within the Animation sequence. * @param {Phaser.Textures.Frame} frame - A reference to the Texture Frame this AnimationFrame uses for rendering. */ var AnimationFrame = new Class({ initialize: function AnimationFrame (textureKey, textureFrame, index, frame) { /** * The key of the Texture this AnimationFrame uses. * * @name Phaser.Animations.AnimationFrame#textureKey * @type {string} * @since 3.0.0 */ this.textureKey = textureKey; /** * The key of the Frame within the Texture that this AnimationFrame uses. * * @name Phaser.Animations.AnimationFrame#textureFrame * @type {(string|integer)} * @since 3.0.0 */ this.textureFrame = textureFrame; /** * The index of this AnimationFrame within the Animation sequence. * * @name Phaser.Animations.AnimationFrame#index * @type {integer} * @since 3.0.0 */ this.index = index; /** * A reference to the Texture Frame this AnimationFrame uses for rendering. * * @name Phaser.Animations.AnimationFrame#frame * @type {Phaser.Textures.Frame} * @since 3.0.0 */ this.frame = frame; /** * Is this the first frame in an animation sequence? * * @name Phaser.Animations.AnimationFrame#isFirst * @type {boolean} * @default false * @readOnly * @since 3.0.0 */ this.isFirst = false; /** * Is this the last frame in an animation sequence? * * @name Phaser.Animations.AnimationFrame#isLast * @type {boolean} * @default false * @readOnly * @since 3.0.0 */ this.isLast = false; /** * A reference to the AnimationFrame that comes before this one in the animation, if any. * * @name Phaser.Animations.AnimationFrame#prevFrame * @type {?Phaser.Animations.AnimationFrame} * @default null * @readOnly * @since 3.0.0 */ this.prevFrame = null; /** * A reference to the AnimationFrame that comes after this one in the animation, if any. * * @name Phaser.Animations.AnimationFrame#nextFrame * @type {?Phaser.Animations.AnimationFrame} * @default null * @readOnly * @since 3.0.0 */ this.nextFrame = null; /** * Additional time (in ms) that this frame should appear for during playback. * The value is added onto the msPerFrame set by the animation. * * @name Phaser.Animations.AnimationFrame#duration * @type {number} * @default 0 * @since 3.0.0 */ this.duration = 0; /** * What % through the animation does this frame come? * This value is generated when the animation is created and cached here. * * @name Phaser.Animations.AnimationFrame#progress * @type {number} * @default 0 * @readOnly * @since 3.0.0 */ this.progress = 0; }, /** * Generates a JavaScript object suitable for converting to JSON. * * @method Phaser.Animations.AnimationFrame#toJSON * @since 3.0.0 * * @return {JSONAnimationFrame} The AnimationFrame data. */ toJSON: function () { return { key: this.textureKey, frame: this.textureFrame, duration: this.duration }; }, /** * Destroys this object by removing references to external resources and callbacks. * * @method Phaser.Animations.AnimationFrame#destroy * @since 3.0.0 */ destroy: function () { this.frame = undefined; } }); module.exports = AnimationFrame; /***/ }), /* 209 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Utils.Array.FindClosestInSorted * @since 3.0.0 * * @param {number} value - The value to search for in the array. * @param {array} array - The array to search, which must be sorted. * @param {string} [key] - An optional property key. If specified the array elements property will be checked against value. * * @return {number|object} The nearest value found in the array, or if a `key` was given, the nearest object with the matching property value. */ var FindClosestInSorted = function (value, array, key) { if (!array.length) { return NaN; } else if (array.length === 1) { return array[0]; } var i = 1; var low; var high; if (key) { if (value < array[0][key]) { return array[0]; } while (array[i][key] < value) { i++; } } else { while (array[i] < value) { i++; } } if (i > array.length) { i = array.length; } if (key) { low = array[i - 1][key]; high = array[i][key]; return ((high - value) <= (value - low)) ? array[i] : array[i - 1]; } else { low = array[i - 1]; high = array[i]; return ((high - value) <= (value - low)) ? high : low; } }; module.exports = FindClosestInSorted; /***/ }), /* 210 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clamp = __webpack_require__(23); var Class = __webpack_require__(0); var FindClosestInSorted = __webpack_require__(209); var Frame = __webpack_require__(208); var GetValue = __webpack_require__(4); /** * @typedef {object} JSONAnimation * * @property {string} key - The key that the animation will be associated with. i.e. sprite.animations.play(key) * @property {string} type - A frame based animation (as opposed to a bone based animation) * @property {JSONAnimationFrame[]} frames - [description] * @property {integer} frameRate - The frame rate of playback in frames per second (default 24 if duration is null) * @property {integer} duration - How long the animation should play for in milliseconds. If not given its derived from frameRate. * @property {boolean} skipMissedFrames - Skip frames if the time lags, or always advanced anyway? * @property {integer} delay - Delay before starting playback. Value given in milliseconds. * @property {integer} repeat - Number of times to repeat the animation (-1 for infinity) * @property {integer} repeatDelay - Delay before the animation repeats. Value given in milliseconds. * @property {boolean} yoyo - Should the animation yoyo? (reverse back down to the start) before repeating? * @property {boolean} showOnStart - Should sprite.visible = true when the animation starts to play? * @property {boolean} hideOnComplete - Should sprite.visible = false when the animation finishes? */ /** * @typedef {object} AnimationFrameConfig * * @property {string} key - The key that the animation will be associated with. i.e. sprite.animations.play(key) * @property {(string|number)} frame - [description] * @property {float} [duration=0] - [description] * @property {boolean} [visible] - [description] */ /** * @typedef {object} AnimationConfig * * @property {string} [key] - The key that the animation will be associated with. i.e. sprite.animations.play(key) * @property {AnimationFrameConfig[]} [frames] - An object containing data used to generate the frames for the animation * @property {string} [defaultTextureKey=null] - The key of the texture all frames of the animation will use. Can be overridden on a per frame basis. * @property {integer} [frameRate] - The frame rate of playback in frames per second (default 24 if duration is null) * @property {integer} [duration] - How long the animation should play for in milliseconds. If not given its derived from frameRate. * @property {boolean} [skipMissedFrames=true] - Skip frames if the time lags, or always advanced anyway? * @property {integer} [delay=0] - Delay before starting playback. Value given in milliseconds. * @property {integer} [repeat=0] - Number of times to repeat the animation (-1 for infinity) * @property {integer} [repeatDelay=0] - Delay before the animation repeats. Value given in milliseconds. * @property {boolean} [yoyo=false] - Should the animation yoyo? (reverse back down to the start) before repeating? * @property {boolean} [showOnStart=false] - Should sprite.visible = true when the animation starts to play? * @property {boolean} [hideOnComplete=false] - Should sprite.visible = false when the animation finishes? */ /** * @classdesc * A Frame based Animation. * * This consists of a key, some default values (like the frame rate) and a bunch of Frame objects. * * The Animation Manager creates these. Game Objects don't own an instance of these directly. * Game Objects have the Animation Component, which are like playheads to global Animations (these objects) * So multiple Game Objects can have playheads all pointing to this one Animation instance. * * @class Animation * @memberOf Phaser.Animations * @constructor * @since 3.0.0 * * @param {Phaser.Animations.AnimationManager} manager - [description] * @param {string} key - [description] * @param {AnimationConfig} config - [description] */ var Animation = new Class({ initialize: function Animation (manager, key, config) { /** * A reference to the global Animation Manager * * @name Phaser.Animations.Animation#manager * @type {Phaser.Animations.AnimationManager} * @since 3.0.0 */ this.manager = manager; /** * The unique identifying string for this animation * * @name Phaser.Animations.Animation#key * @type {string} * @since 3.0.0 */ this.key = key; /** * A frame based animation (as opposed to a bone based animation) * * @name Phaser.Animations.Animation#type * @type {string} * @default frame * @since 3.0.0 */ this.type = 'frame'; /** * Extract all the frame data into the frames array * * @name Phaser.Animations.Animation#frames * @type {Phaser.Animations.AnimationFrame[]} * @since 3.0.0 */ this.frames = this.getFrames( manager.textureManager, GetValue(config, 'frames', []), GetValue(config, 'defaultTextureKey', null) ); /** * The frame rate of playback in frames per second (default 24 if duration is null) * * @name Phaser.Animations.Animation#frameRate * @type {integer} * @default 24 * @since 3.0.0 */ this.frameRate = GetValue(config, 'frameRate', null); /** * How long the animation should play for, in milliseconds. * If the `frameRate` property has been set then it overrides this value, * otherwise the `frameRate` is derived from `duration`. * * @name Phaser.Animations.Animation#duration * @type {integer} * @since 3.0.0 */ this.duration = GetValue(config, 'duration', null); if (this.duration === null && this.frameRate === null) { // No duration or frameRate given, use default frameRate of 24fps this.frameRate = 24; this.duration = (this.frameRate / this.frames.length) * 1000; } else if (this.duration && this.frameRate === null) { // Duration given but no frameRate, so set the frameRate based on duration // I.e. 12 frames in the animation, duration = 4000 ms // So frameRate is 12 / (4000 / 1000) = 3 fps this.frameRate = this.frames.length / (this.duration / 1000); } else { // frameRate given, derive duration from it (even if duration also specified) // I.e. 15 frames in the animation, frameRate = 30 fps // So duration is 15 / 30 = 0.5 * 1000 (half a second, or 500ms) this.duration = (this.frames.length / this.frameRate) * 1000; } /** * How many ms per frame, not including frame specific modifiers. * * @name Phaser.Animations.Animation#msPerFrame * @type {integer} * @since 3.0.0 */ this.msPerFrame = 1000 / this.frameRate; /** * Skip frames if the time lags, or always advanced anyway? * * @name Phaser.Animations.Animation#skipMissedFrames * @type {boolean} * @default false * @since 3.0.0 */ this.skipMissedFrames = GetValue(config, 'skipMissedFrames', true); /** * The delay in ms before the playback will begin. * * @name Phaser.Animations.Animation#delay * @type {integer} * @default 0 * @since 3.0.0 */ this.delay = GetValue(config, 'delay', 0); /** * Number of times to repeat the animation. Set to -1 to repeat forever. * * @name Phaser.Animations.Animation#repeat * @type {integer} * @default 0 * @since 3.0.0 */ this.repeat = GetValue(config, 'repeat', 0); /** * The delay in ms before the a repeat playthrough starts. * * @name Phaser.Animations.Animation#repeatDelay * @type {integer} * @default 0 * @since 3.0.0 */ this.repeatDelay = GetValue(config, 'repeatDelay', 0); /** * Should the animation yoyo? (reverse back down to the start) before repeating? * * @name Phaser.Animations.Animation#yoyo * @type {boolean} * @default false * @since 3.0.0 */ this.yoyo = GetValue(config, 'yoyo', false); /** * Should sprite.visible = true when the animation starts to play? * * @name Phaser.Animations.Animation#showOnStart * @type {boolean} * @default false * @since 3.0.0 */ this.showOnStart = GetValue(config, 'showOnStart', false); /** * Should sprite.visible = false when the animation finishes? * * @name Phaser.Animations.Animation#hideOnComplete * @type {boolean} * @default false * @since 3.0.0 */ this.hideOnComplete = GetValue(config, 'hideOnComplete', false); /** * Global pause. All Game Objects using this Animation instance are impacted by this property. * * @name Phaser.Animations.Animation#paused * @type {boolean} * @default false * @since 3.0.0 */ this.paused = false; this.manager.on('pauseall', this.pause, this); this.manager.on('resumeall', this.resume, this); }, /** * Add frames to the end of the animation. * * @method Phaser.Animations.Animation#addFrame * @since 3.0.0 * * @param {(string|AnimationFrameConfig[])} config - [description] * * @return {Phaser.Animations.Animation} This Animation object. */ addFrame: function (config) { return this.addFrameAt(this.frames.length, config); }, /** * Add frame/s into the animation. * * @method Phaser.Animations.Animation#addFrameAt * @since 3.0.0 * * @param {integer} index - [description] * @param {(string|AnimationFrameConfig[])} config - [description] * * @return {Phaser.Animations.Animation} This Animation object. */ addFrameAt: function (index, config) { var newFrames = this.getFrames(this.manager.textureManager, config); if (newFrames.length > 0) { if (index === 0) { this.frames = newFrames.concat(this.frames); } else if (index === this.frames.length) { this.frames = this.frames.concat(newFrames); } else { var pre = this.frames.slice(0, index); var post = this.frames.slice(index); this.frames = pre.concat(newFrames, post); } this.updateFrameSequence(); } return this; }, /** * Check if the given frame index is valid. * * @method Phaser.Animations.Animation#checkFrame * @since 3.0.0 * * @param {integer} index - The index to be checked. * * @return {boolean} `true` if the index is valid, otherwise `false`. */ checkFrame: function (index) { return (index >= 0 && index < this.frames.length); }, /** * [description] * * @method Phaser.Animations.Animation#completeAnimation * @protected * @since 3.0.0 * * @param {Phaser.GameObjects.Components.Animation} component - [description] */ completeAnimation: function (component) { if (this.hideOnComplete) { component.parent.visible = false; } component.stop(); }, /** * [description] * * @method Phaser.Animations.Animation#getFirstTick * @protected * @since 3.0.0 * * @param {Phaser.GameObjects.Components.Animation} component - [description] * @param {boolean} [includeDelay=true] - [description] */ getFirstTick: function (component, includeDelay) { if (includeDelay === undefined) { includeDelay = true; } // When is the first update due? component.accumulator = 0; component.nextTick = component.msPerFrame + component.currentFrame.duration; if (includeDelay) { component.nextTick += component._delay; } }, /** * Returns the AnimationFrame at the provided index * * @method Phaser.Animations.Animation#getFrameAt * @protected * @since 3.0.0 * * @param {integer} index - The index in the AnimationFrame array * * @return {Phaser.Animations.AnimationFrame} The frame at the index provided from the animation sequence */ getFrameAt: function (index) { return this.frames[index]; }, /** * [description] * * @method Phaser.Animations.Animation#getFrames * @since 3.0.0 * * @param {Phaser.Textures.TextureManager} textureManager - [description] * @param {(string|AnimationFrameConfig[])} frames - [description] * @param {string} [defaultTextureKey] - [description] * * @return {Phaser.Animations.AnimationFrame[]} [description] */ getFrames: function (textureManager, frames, defaultTextureKey) { var out = []; var prev; var animationFrame; var index = 1; var i; var textureKey; // if frames is a string, we'll get all the frames from the texture manager as if it's a sprite sheet if (typeof frames === 'string') { textureKey = frames; var texture = textureManager.get(textureKey); var frameKeys = texture.getFrameNames(); frames = []; frameKeys.forEach(function (idx, value) { frames.push({ key: textureKey, frame: value }); }); } if (!Array.isArray(frames) || frames.length === 0) { return out; } for (i = 0; i < frames.length; i++) { var item = frames[i]; var key = GetValue(item, 'key', defaultTextureKey); if (!key) { continue; } // Could be an integer or a string var frame = GetValue(item, 'frame', 0); // The actual texture frame var textureFrame = textureManager.getFrame(key, frame); animationFrame = new Frame(key, frame, index, textureFrame); animationFrame.duration = GetValue(item, 'duration', 0); animationFrame.isFirst = (!prev); // The previously created animationFrame if (prev) { prev.nextFrame = animationFrame; animationFrame.prevFrame = prev; } out.push(animationFrame); prev = animationFrame; index++; } if (out.length > 0) { animationFrame.isLast = true; // Link them end-to-end, so they loop animationFrame.nextFrame = out[0]; out[0].prevFrame = animationFrame; // Generate the progress data var slice = 1 / (out.length - 1); for (i = 0; i < out.length; i++) { out[i].progress = i * slice; } } return out; }, /** * [description] * * @method Phaser.Animations.Animation#getNextTick * @since 3.0.0 * * @param {Phaser.GameObjects.Components.Animation} component - [description] */ getNextTick: function (component) { // accumulator += delta * _timeScale // after a large delta surge (perf issue for example) we need to adjust for it here // When is the next update due? component.accumulator -= component.nextTick; component.nextTick = component.msPerFrame + component.currentFrame.duration; }, /** * Loads the Animation values into the Animation Component. * * @method Phaser.Animations.Animation#load * @private * @since 3.0.0 * * @param {Phaser.GameObjects.Components.Animation} component - The Animation Component to load values into. * @param {integer} startFrame - The start frame of the animation to load. */ load: function (component, startFrame) { if (startFrame >= this.frames.length) { startFrame = 0; } if (component.currentAnim !== this) { component.currentAnim = this; component.frameRate = this.frameRate; component.duration = this.duration; component.msPerFrame = this.msPerFrame; component.skipMissedFrames = this.skipMissedFrames; component._timeScale = 1; component._delay = this.delay; component._repeat = this.repeat; component._repeatDelay = this.repeatDelay; component._yoyo = this.yoyo; } component.updateFrame(this.frames[startFrame]); }, /** * Returns the frame closest to the given progress value between 0 and 1. * * @method Phaser.Animations.Animation#getFrameByProgress * @since 3.4.0 * * @param {float} value - A value between 0 and 1. * * @return {Phaser.Animations.AnimationFrame} The frame closest to the given progress value. */ getFrameByProgress: function (value) { value = Clamp(value, 0, 1); return FindClosestInSorted(value, this.frames, 'progress'); }, /** * Advance the animation frame. * * @method Phaser.Animations.Animation#nextFrame * @since 3.0.0 * * @param {Phaser.GameObjects.Components.Animation} component - The Animation Component to advance. */ nextFrame: function (component) { var frame = component.currentFrame; // TODO: Add frame skip support if (frame.isLast) { // We're at the end of the animation // Yoyo? (happens before repeat) if (component._yoyo) { component.forward = false; component.updateFrame(frame.prevFrame); // Delay for the current frame this.getNextTick(component); } else if (component.repeatCounter > 0) { // Repeat (happens before complete) this.repeatAnimation(component); } else { this.completeAnimation(component); } } else { component.updateFrame(frame.nextFrame); this.getNextTick(component); } }, /** * [description] * * @method Phaser.Animations.Animation#previousFrame * @since 3.0.0 * * @param {Phaser.GameObjects.Components.Animation} component - [description] */ previousFrame: function (component) { var frame = component.currentFrame; // TODO: Add frame skip support if (frame.isFirst) { // We're at the start of the animation if (component.repeatCounter > 0) { // Repeat (happens before complete) this.repeatAnimation(component); } else { this.completeAnimation(component); } } else { component.updateFrame(frame.prevFrame); this.getNextTick(component); } }, /** * [description] * * @method Phaser.Animations.Animation#removeFrame * @since 3.0.0 * * @param {Phaser.Animations.AnimationFrame} frame - [description] * * @return {Phaser.Animations.Animation} This Animation object. */ removeFrame: function (frame) { var index = this.frames.indexOf(frame); if (index !== -1) { this.removeFrameAt(index); } return this; }, /** * Removes a frame from the AnimationFrame array at the provided index * and updates the animation accordingly. * * @method Phaser.Animations.Animation#removeFrameAt * @since 3.0.0 * * @param {integer} index - The index in the AnimationFrame array * * @return {Phaser.Animations.Animation} This Animation object. */ removeFrameAt: function (index) { this.frames.splice(index, 1); this.updateFrameSequence(); return this; }, /** * [description] * * @method Phaser.Animations.Animation#repeatAnimation * @since 3.0.0 * * @param {Phaser.GameObjects.Components.Animation} component - [description] */ repeatAnimation: function (component) { if (component._pendingStop === 2) { return this.completeAnimation(component); } if (component._repeatDelay > 0 && component.pendingRepeat === false) { component.pendingRepeat = true; component.accumulator -= component.nextTick; component.nextTick += component._repeatDelay; } else { component.repeatCounter--; component.forward = true; component.updateFrame(component.currentFrame.nextFrame); if (component.isPlaying) { this.getNextTick(component); component.pendingRepeat = false; component.parent.emit('animationrepeat', this, component.currentFrame, component.repeatCounter); } } }, /** * [description] * * @method Phaser.Animations.Animation#setFrame * @since 3.0.0 * * @param {Phaser.GameObjects.Components.Animation} component - [description] */ setFrame: function (component) { // Work out which frame should be set next on the child, and set it if (component.forward) { this.nextFrame(component); } else { this.previousFrame(component); } }, /** * [description] * * @method Phaser.Animations.Animation#toJSON * @since 3.0.0 * * @return {JSONAnimation} [description] */ toJSON: function () { var output = { key: this.key, type: this.type, frames: [], frameRate: this.frameRate, duration: this.duration, skipMissedFrames: this.skipMissedFrames, delay: this.delay, repeat: this.repeat, repeatDelay: this.repeatDelay, yoyo: this.yoyo, showOnStart: this.showOnStart, hideOnComplete: this.hideOnComplete }; this.frames.forEach(function (frame) { output.frames.push(frame.toJSON()); }); return output; }, /** * [description] * * @method Phaser.Animations.Animation#updateFrameSequence * @since 3.0.0 * * @return {Phaser.Animations.Animation} This Animation object. */ updateFrameSequence: function () { var len = this.frames.length; var slice = 1 / (len - 1); for (var i = 0; i < len; i++) { var frame = this.frames[i]; frame.index = i + 1; frame.isFirst = false; frame.isLast = false; frame.progress = i * slice; if (i === 0) { frame.isFirst = true; frame.isLast = (len === 1); frame.prevFrame = this.frames[len - 1]; frame.nextFrame = this.frames[i + 1]; } else if (i === len - 1) { frame.isLast = true; frame.prevFrame = this.frames[len - 2]; frame.nextFrame = this.frames[0]; } else if (len > 1) { frame.prevFrame = this.frames[i - 1]; frame.nextFrame = this.frames[i + 1]; } } return this; }, /** * [description] * * @method Phaser.Animations.Animation#pause * @since 3.0.0 * * @return {Phaser.Animations.Animation} This Animation object. */ pause: function () { this.paused = true; return this; }, /** * [description] * * @method Phaser.Animations.Animation#resume * @since 3.0.0 * * @return {Phaser.Animations.Animation} This Animation object. */ resume: function () { this.paused = false; return this; }, /** * [description] * * @method Phaser.Animations.Animation#destroy * @since 3.0.0 */ destroy: function () { this.manager.off('pauseall', this.pause, this); this.manager.off('resumeall', this.resume, this); this.manager.remove(this.key); for (var i = 0; i < this.frames.length; i++) { this.frames[i].destroy(); } this.frames = []; this.manager = null; } }); module.exports = Animation; /***/ }), /* 211 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Wrap = __webpack_require__(39); /** * Wrap an angle in degrees. * * Wraps the angle to a value in the range of -180 to 180. * * @function Phaser.Math.Angle.WrapDegrees * @since 3.0.0 * * @param {number} angle - The angle to wrap, in degrees. * * @return {number} The wrapped angle, in degrees. */ var WrapDegrees = function (angle) { return Wrap(angle, -180, 180); }; module.exports = WrapDegrees; /***/ }), /* 212 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var MathWrap = __webpack_require__(39); /** * Wrap an angle. * * Wraps the angle to a value in the range of -PI to PI. * * @function Phaser.Math.Angle.Wrap * @since 3.0.0 * * @param {number} angle - The angle to wrap, in radians. * * @return {number} The wrapped angle, in radians. */ var Wrap = function (angle) { return MathWrap(angle, -Math.PI, Math.PI); }; module.exports = Wrap; /***/ }), /* 213 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * [description] * * @class GeometryMask * @memberOf Phaser.Display.Masks * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - [description] * @param {Phaser.GameObjects.Graphics} graphicsGeometry - [description] */ var GeometryMask = new Class({ initialize: function GeometryMask (scene, graphicsGeometry) { /** * [description] * * @name Phaser.Display.Masks.GeometryMask#geometryMask * @type {Phaser.GameObjects.Graphics} * @since 3.0.0 */ this.geometryMask = graphicsGeometry; }, /** * [description] * * @method Phaser.Display.Masks.GeometryMask#setShape * @since 3.0.0 * * @param {Phaser.GameObjects.Graphics} graphicsGeometry - [description] */ setShape: function (graphicsGeometry) { this.geometryMask = graphicsGeometry; }, /** * [description] * * @method Phaser.Display.Masks.GeometryMask#preRenderWebGL * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] * @param {Phaser.GameObjects.GameObject} mask - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ preRenderWebGL: function (renderer, mask, camera) { var gl = renderer.gl; var geometryMask = this.geometryMask; // Force flushing before drawing to stencil buffer renderer.flush(); // Enable and setup GL state to write to stencil buffer gl.enable(gl.STENCIL_TEST); gl.clear(gl.STENCIL_BUFFER_BIT); gl.colorMask(false, false, false, false); gl.stencilFunc(gl.NOTEQUAL, 1, 1); gl.stencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE); // Write stencil buffer geometryMask.renderWebGL(renderer, geometryMask, 0.0, camera); renderer.flush(); // Use stencil buffer to affect next rendering object gl.colorMask(true, true, true, true); gl.stencilFunc(gl.EQUAL, 1, 1); gl.stencilOp(gl.INVERT, gl.INVERT, gl.INVERT); }, /** * [description] * * @method Phaser.Display.Masks.GeometryMask#postRenderWebGL * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] */ postRenderWebGL: function (renderer) { var gl = renderer.gl; // Force flush before disabling stencil test renderer.flush(); gl.disable(gl.STENCIL_TEST); }, /** * [description] * * @method Phaser.Display.Masks.GeometryMask#preRenderCanvas * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] * @param {Phaser.GameObjects.GameObject} mask - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ preRenderCanvas: function (renderer, mask, camera) { var geometryMask = this.geometryMask; renderer.currentContext.save(); geometryMask.renderCanvas(renderer, geometryMask, 0.0, camera, undefined, null, true); renderer.currentContext.clip(); }, /** * [description] * * @method Phaser.Display.Masks.GeometryMask#postRenderCanvas * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] */ postRenderCanvas: function (renderer) { renderer.currentContext.restore(); }, /** * Destroys this GeometryMask and nulls any references it holds. * * Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it, * so be sure to call `clearMask` on any Game Object using it, before destroying it. * * @method Phaser.Display.Masks.GeometryMask#destroy * @since 3.7.0 */ destroy: function () { this.geometryMask = null; } }); module.exports = GeometryMask; /***/ }), /* 214 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * [description] * * @class BitmapMask * @memberOf Phaser.Display.Masks * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - [description] * @param {Phaser.GameObjects.GameObject} renderable - A renderable Game Object that uses a texture, such as a Sprite. */ var BitmapMask = new Class({ initialize: function BitmapMask (scene, renderable) { var renderer = scene.sys.game.renderer; /** * A renderable Game Object that uses a texture, such as a Sprite. * * @name Phaser.Display.Masks.BitmapMask#bitmapMask * @type {Phaser.GameObjects.GameObject} * @since 3.0.0 */ this.bitmapMask = renderable; /** * [description] * * @name Phaser.Display.Masks.BitmapMask#maskTexture * @type {WebGLTexture} * @default null * @since 3.0.0 */ this.maskTexture = null; /** * [description] * * @name Phaser.Display.Masks.BitmapMask#mainTexture * @type {WebGLTexture} * @default null * @since 3.0.0 */ this.mainTexture = null; /** * [description] * * @name Phaser.Display.Masks.BitmapMask#dirty * @type {boolean} * @default true * @since 3.0.0 */ this.dirty = true; /** * [description] * * @name Phaser.Display.Masks.BitmapMask#mainFramebuffer * @type {WebGLFramebuffer} * @since 3.0.0 */ this.mainFramebuffer = null; /** * [description] * * @name Phaser.Display.Masks.BitmapMask#maskFramebuffer * @type {WebGLFramebuffer} * @since 3.0.0 */ this.maskFramebuffer = null; /** * [description] * * @name Phaser.Display.Masks.BitmapMask#invertAlpha * @type {boolean} * @since 3.1.2 */ this.invertAlpha = false; if (renderer && renderer.gl) { var width = renderer.width; var height = renderer.height; var pot = ((width & (width - 1)) === 0 && (height & (height - 1)) === 0); var gl = renderer.gl; var wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE; var filter = gl.LINEAR; this.mainTexture = renderer.createTexture2D(0, filter, filter, wrap, wrap, gl.RGBA, null, width, height); this.maskTexture = renderer.createTexture2D(0, filter, filter, wrap, wrap, gl.RGBA, null, width, height); this.mainFramebuffer = renderer.createFramebuffer(width, height, this.mainTexture, false); this.maskFramebuffer = renderer.createFramebuffer(width, height, this.maskTexture, false); renderer.onContextRestored(function (renderer) { var width = renderer.width; var height = renderer.height; var pot = ((width & (width - 1)) === 0 && (height & (height - 1)) === 0); var gl = renderer.gl; var wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE; var filter = gl.LINEAR; this.mainTexture = renderer.createTexture2D(0, filter, filter, wrap, wrap, gl.RGBA, null, width, height); this.maskTexture = renderer.createTexture2D(0, filter, filter, wrap, wrap, gl.RGBA, null, width, height); this.mainFramebuffer = renderer.createFramebuffer(width, height, this.mainTexture, false); this.maskFramebuffer = renderer.createFramebuffer(width, height, this.maskTexture, false); }, this); } }, /** * [description] * * @method Phaser.Display.Masks.BitmapMask#setBitmap * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} renderable - A renderable Game Object that uses a texture, such as a Sprite. */ setBitmap: function (renderable) { this.bitmapMask = renderable; }, /** * [description] * * @method Phaser.Display.Masks.BitmapMask#preRenderWebGL * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] * @param {Phaser.GameObjects.GameObject} maskedObject - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to render to. */ preRenderWebGL: function (renderer, maskedObject, camera) { renderer.pipelines.BitmapMaskPipeline.beginMask(this, maskedObject, camera); }, /** * [description] * * @method Phaser.Display.Masks.BitmapMask#postRenderWebGL * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] */ postRenderWebGL: function (renderer) { renderer.pipelines.BitmapMaskPipeline.endMask(this); }, /** * [description] * * @method Phaser.Display.Masks.BitmapMask#preRenderCanvas * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] * @param {Phaser.GameObjects.GameObject} mask - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to render to. */ preRenderCanvas: function () { // NOOP }, /** * [description] * * @method Phaser.Display.Masks.BitmapMask#postRenderCanvas * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - [description] */ postRenderCanvas: function () { // NOOP }, /** * Destroys this BitmapMask and nulls any references it holds. * * Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it, * so be sure to call `clearMask` on any Game Object using it, before destroying it. * * @method Phaser.Display.Masks.BitmapMask#destroy * @since 3.7.0 */ destroy: function () { this.bitmapMask = null; this.mainTexture = null; this.maskTexture = null; this.mainFramebuffer = null; this.maskFramebuffer = null; } }); module.exports = BitmapMask; /***/ }), /* 215 */ /***/ (function(module, exports) { var g; // This works in non-strict mode g = (function() { return this; })(); try { // This works if eval is allowed (see CSP) g = g || Function("return this")() || (1, eval)("this"); } catch (e) { // This works if the window reference is available if (typeof window === "object") g = window; } // g can still be undefined, but nothing to do about it... // We return undefined, instead of nothing here, so it's // easier to handle this case. if(!global) { ...} module.exports = g; /***/ }), /* 216 */, /* 217 */, /* 218 */, /* 219 */, /* 220 */, /* 221 */, /* 222 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var quickselect = __webpack_require__(180); /** * @classdesc * RBush is a high-performance JavaScript library for 2D spatial indexing of points and rectangles. * It's based on an optimized R-tree data structure with bulk insertion support. * * Spatial index is a special data structure for points and rectangles that allows you to perform queries like * "all items within this bounding box" very efficiently (e.g. hundreds of times faster than looping over all items). * * This version of RBush uses a fixed min/max accessor structure of `[ '.left', '.top', '.right', '.bottom' ]`. * This is to avoid the eval like function creation that the original library used, which caused CSP policy violations. * * @class RTree * @memberOf Phaser.Structs * @constructor * @since 3.0.0 */ function rbush (maxEntries) { var format = [ '.left', '.top', '.right', '.bottom' ]; if (!(this instanceof rbush)) return new rbush(maxEntries, format); // max entries in a node is 9 by default; min node fill is 40% for best performance this._maxEntries = Math.max(4, maxEntries || 9); this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)); this.clear(); } rbush.prototype = { all: function () { return this._all(this.data, []); }, search: function (bbox) { var node = this.data, result = [], toBBox = this.toBBox; if (!intersects(bbox, node)) return result; var nodesToSearch = [], i, len, child, childBBox; while (node) { for (i = 0, len = node.children.length; i < len; i++) { child = node.children[i]; childBBox = node.leaf ? toBBox(child) : child; if (intersects(bbox, childBBox)) { if (node.leaf) result.push(child); else if (contains(bbox, childBBox)) this._all(child, result); else nodesToSearch.push(child); } } node = nodesToSearch.pop(); } return result; }, collides: function (bbox) { var node = this.data, toBBox = this.toBBox; if (!intersects(bbox, node)) return false; var nodesToSearch = [], i, len, child, childBBox; while (node) { for (i = 0, len = node.children.length; i < len; i++) { child = node.children[i]; childBBox = node.leaf ? toBBox(child) : child; if (intersects(bbox, childBBox)) { if (node.leaf || contains(bbox, childBBox)) return true; nodesToSearch.push(child); } } node = nodesToSearch.pop(); } return false; }, load: function (data) { if (!(data && data.length)) return this; if (data.length < this._minEntries) { for (var i = 0, len = data.length; i < len; i++) { this.insert(data[i]); } return this; } // recursively build the tree with the given data from scratch using OMT algorithm var node = this._build(data.slice(), 0, data.length - 1, 0); if (!this.data.children.length) { // save as is if tree is empty this.data = node; } else if (this.data.height === node.height) { // split root if trees have the same height this._splitRoot(this.data, node); } else { if (this.data.height < node.height) { // swap trees if inserted one is bigger var tmpNode = this.data; this.data = node; node = tmpNode; } // insert the small tree into the large tree at appropriate level this._insert(node, this.data.height - node.height - 1, true); } return this; }, insert: function (item) { if (item) this._insert(item, this.data.height - 1); return this; }, clear: function () { this.data = createNode([]); return this; }, remove: function (item, equalsFn) { if (!item) return this; var node = this.data, bbox = this.toBBox(item), path = [], indexes = [], i, parent, index, goingUp; // depth-first iterative tree traversal while (node || path.length) { if (!node) { // go up node = path.pop(); parent = path[path.length - 1]; i = indexes.pop(); goingUp = true; } if (node.leaf) { // check current node index = findItem(item, node.children, equalsFn); if (index !== -1) { // item found, remove the item and condense tree upwards node.children.splice(index, 1); path.push(node); this._condense(path); return this; } } if (!goingUp && !node.leaf && contains(node, bbox)) { // go down path.push(node); indexes.push(i); i = 0; parent = node; node = node.children[0]; } else if (parent) { // go right i++; node = parent.children[i]; goingUp = false; } else node = null; // nothing found } return this; }, toBBox: function (item) { return item; }, compareMinX: compareNodeMinX, compareMinY: compareNodeMinY, toJSON: function () { return this.data; }, fromJSON: function (data) { this.data = data; return this; }, _all: function (node, result) { var nodesToSearch = []; while (node) { if (node.leaf) result.push.apply(result, node.children); else nodesToSearch.push.apply(nodesToSearch, node.children); node = nodesToSearch.pop(); } return result; }, _build: function (items, left, right, height) { var N = right - left + 1, M = this._maxEntries, node; if (N <= M) { // reached leaf level; return leaf node = createNode(items.slice(left, right + 1)); calcBBox(node, this.toBBox); return node; } if (!height) { // target height of the bulk-loaded tree height = Math.ceil(Math.log(N) / Math.log(M)); // target number of root entries to maximize storage utilization M = Math.ceil(N / Math.pow(M, height - 1)); } node = createNode([]); node.leaf = false; node.height = height; // split the items into M mostly square tiles var N2 = Math.ceil(N / M), N1 = N2 * Math.ceil(Math.sqrt(M)), i, j, right2, right3; multiSelect(items, left, right, N1, this.compareMinX); for (i = left; i <= right; i += N1) { right2 = Math.min(i + N1 - 1, right); multiSelect(items, i, right2, N2, this.compareMinY); for (j = i; j <= right2; j += N2) { right3 = Math.min(j + N2 - 1, right2); // pack each entry recursively node.children.push(this._build(items, j, right3, height - 1)); } } calcBBox(node, this.toBBox); return node; }, _chooseSubtree: function (bbox, node, level, path) { var i, len, child, targetNode, area, enlargement, minArea, minEnlargement; while (true) { path.push(node); if (node.leaf || path.length - 1 === level) break; minArea = minEnlargement = Infinity; for (i = 0, len = node.children.length; i < len; i++) { child = node.children[i]; area = bboxArea(child); enlargement = enlargedArea(bbox, child) - area; // choose entry with the least area enlargement if (enlargement < minEnlargement) { minEnlargement = enlargement; minArea = area < minArea ? area : minArea; targetNode = child; } else if (enlargement === minEnlargement) { // otherwise choose one with the smallest area if (area < minArea) { minArea = area; targetNode = child; } } } node = targetNode || node.children[0]; } return node; }, _insert: function (item, level, isNode) { var toBBox = this.toBBox, bbox = isNode ? item : toBBox(item), insertPath = []; // find the best node for accommodating the item, saving all nodes along the path too var node = this._chooseSubtree(bbox, this.data, level, insertPath); // put the item into the node node.children.push(item); extend(node, bbox); // split on node overflow; propagate upwards if necessary while (level >= 0) { if (insertPath[level].children.length > this._maxEntries) { this._split(insertPath, level); level--; } else break; } // adjust bboxes along the insertion path this._adjustParentBBoxes(bbox, insertPath, level); }, // split overflowed node into two _split: function (insertPath, level) { var node = insertPath[level], M = node.children.length, m = this._minEntries; this._chooseSplitAxis(node, m, M); var splitIndex = this._chooseSplitIndex(node, m, M); var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex)); newNode.height = node.height; newNode.leaf = node.leaf; calcBBox(node, this.toBBox); calcBBox(newNode, this.toBBox); if (level) insertPath[level - 1].children.push(newNode); else this._splitRoot(node, newNode); }, _splitRoot: function (node, newNode) { // split root node this.data = createNode([node, newNode]); this.data.height = node.height + 1; this.data.leaf = false; calcBBox(this.data, this.toBBox); }, _chooseSplitIndex: function (node, m, M) { var i, bbox1, bbox2, overlap, area, minOverlap, minArea, index; minOverlap = minArea = Infinity; for (i = m; i <= M - m; i++) { bbox1 = distBBox(node, 0, i, this.toBBox); bbox2 = distBBox(node, i, M, this.toBBox); overlap = intersectionArea(bbox1, bbox2); area = bboxArea(bbox1) + bboxArea(bbox2); // choose distribution with minimum overlap if (overlap < minOverlap) { minOverlap = overlap; index = i; minArea = area < minArea ? area : minArea; } else if (overlap === minOverlap) { // otherwise choose distribution with minimum area if (area < minArea) { minArea = area; index = i; } } } return index; }, // sorts node children by the best axis for split _chooseSplitAxis: function (node, m, M) { var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX, compareMinY = node.leaf ? this.compareMinY : compareNodeMinY, xMargin = this._allDistMargin(node, m, M, compareMinX), yMargin = this._allDistMargin(node, m, M, compareMinY); // if total distributions margin value is minimal for x, sort by minX, // otherwise it's already sorted by minY if (xMargin < yMargin) node.children.sort(compareMinX); }, // total margin of all possible split distributions where each node is at least m full _allDistMargin: function (node, m, M, compare) { node.children.sort(compare); var toBBox = this.toBBox, leftBBox = distBBox(node, 0, m, toBBox), rightBBox = distBBox(node, M - m, M, toBBox), margin = bboxMargin(leftBBox) + bboxMargin(rightBBox), i, child; for (i = m; i < M - m; i++) { child = node.children[i]; extend(leftBBox, node.leaf ? toBBox(child) : child); margin += bboxMargin(leftBBox); } for (i = M - m - 1; i >= m; i--) { child = node.children[i]; extend(rightBBox, node.leaf ? toBBox(child) : child); margin += bboxMargin(rightBBox); } return margin; }, _adjustParentBBoxes: function (bbox, path, level) { // adjust bboxes along the given tree path for (var i = level; i >= 0; i--) { extend(path[i], bbox); } }, _condense: function (path) { // go through the path, removing empty nodes and updating bboxes for (var i = path.length - 1, siblings; i >= 0; i--) { if (path[i].children.length === 0) { if (i > 0) { siblings = path[i - 1].children; siblings.splice(siblings.indexOf(path[i]), 1); } else this.clear(); } else calcBBox(path[i], this.toBBox); } }, compareMinX: function (a, b) { return a.left - b.left; }, compareMinY: function (a, b) { return a.top - b.top; }, toBBox: function (a) { return { minX: a.left, minY: a.top, maxX: a.right, maxY: a.bottom }; } }; function findItem (item, items, equalsFn) { if (!equalsFn) return items.indexOf(item); for (var i = 0; i < items.length; i++) { if (equalsFn(item, items[i])) return i; } return -1; } // calculate node's bbox from bboxes of its children function calcBBox (node, toBBox) { distBBox(node, 0, node.children.length, toBBox, node); } // min bounding rectangle of node children from k to p-1 function distBBox (node, k, p, toBBox, destNode) { if (!destNode) destNode = createNode(null); destNode.minX = Infinity; destNode.minY = Infinity; destNode.maxX = -Infinity; destNode.maxY = -Infinity; for (var i = k, child; i < p; i++) { child = node.children[i]; extend(destNode, node.leaf ? toBBox(child) : child); } return destNode; } function extend (a, b) { a.minX = Math.min(a.minX, b.minX); a.minY = Math.min(a.minY, b.minY); a.maxX = Math.max(a.maxX, b.maxX); a.maxY = Math.max(a.maxY, b.maxY); return a; } function compareNodeMinX (a, b) { return a.minX - b.minX; } function compareNodeMinY (a, b) { return a.minY - b.minY; } function bboxArea (a) { return (a.maxX - a.minX) * (a.maxY - a.minY); } function bboxMargin (a) { return (a.maxX - a.minX) + (a.maxY - a.minY); } function enlargedArea (a, b) { return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) * (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY)); } function intersectionArea (a, b) { var minX = Math.max(a.minX, b.minX), minY = Math.max(a.minY, b.minY), maxX = Math.min(a.maxX, b.maxX), maxY = Math.min(a.maxY, b.maxY); return Math.max(0, maxX - minX) * Math.max(0, maxY - minY); } function contains (a, b) { return a.minX <= b.minX && a.minY <= b.minY && b.maxX <= a.maxX && b.maxY <= a.maxY; } function intersects (a, b) { return b.minX <= a.maxX && b.minY <= a.maxY && b.maxX >= a.minX && b.maxY >= a.minY; } function createNode (children) { return { children: children, height: 1, leaf: true, minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }; } // sort an array so that items come in groups of n unsorted items, with groups sorted between each other; // combines selection algorithm with binary divide & conquer approach function multiSelect (arr, left, right, n, compare) { var stack = [left, right], mid; while (stack.length) { right = stack.pop(); left = stack.pop(); if (right - left <= n) continue; mid = left + Math.ceil((right - left) / n / 2) * n; quickselect(arr, mid, left, right, compare); stack.push(left, mid, mid, right); } } module.exports = rbush; /***/ }), /* 223 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * [description] * * @class ProcessQueue * @memberOf Phaser.Structs * @constructor * @since 3.0.0 * * @generic T */ var ProcessQueue = new Class({ initialize: function ProcessQueue () { /** * [description] * * @genericUse {T[]} - [$type] * * @name Phaser.Structs.ProcessQueue#_pending * @type {Array.<*>} * @private * @default [] * @since 3.0.0 */ this._pending = []; /** * [description] * * @genericUse {T[]} - [$type] * * @name Phaser.Structs.ProcessQueue#_active * @type {Array.<*>} * @private * @default [] * @since 3.0.0 */ this._active = []; /** * [description] * * @genericUse {T[]} - [$type] * * @name Phaser.Structs.ProcessQueue#_destroy * @type {Array.<*>} * @private * @default [] * @since 3.0.0 */ this._destroy = []; /** * [description] * * @name Phaser.Structs.ProcessQueue#_toProcess * @type {integer} * @private * @default 0 * @since 3.0.0 */ this._toProcess = 0; }, /** * [description] * * @method Phaser.Structs.ProcessQueue#add * @since 3.0.0 * * @genericUse {T} - [item] * @genericUse {Phaser.Structs.ProcessQueue.} - [$return] * * @param {*} item - [description] * * @return {Phaser.Structs.ProcessQueue} This Process Queue object. */ add: function (item) { this._pending.push(item); this._toProcess++; return this; }, /** * [description] * * @method Phaser.Structs.ProcessQueue#remove * @since 3.0.0 * * @genericUse {T} - [item] * @genericUse {Phaser.Structs.ProcessQueue.} - [$return] * * @param {*} item - [description] * * @return {Phaser.Structs.ProcessQueue} This Process Queue object. */ remove: function (item) { this._destroy.push(item); this._toProcess++; return this; }, /** * [description] * * @method Phaser.Structs.ProcessQueue#update * @since 3.0.0 * * @genericUse {T[]} - [$return] * * @return {Array.<*>} [description] */ update: function () { if (this._toProcess === 0) { // Quick bail return this._active; } var list = this._destroy; var active = this._active; var i; var item; // Clear the 'destroy' list for (i = 0; i < list.length; i++) { item = list[i]; // Remove from the 'active' array var idx = active.indexOf(item); if (idx !== -1) { active.splice(idx, 1); } } list.length = 0; // Process the pending addition list // This stops callbacks and out of sync events from populating the active array mid-way during an update list = this._pending; for (i = 0; i < list.length; i++) { item = list[i]; this._active.push(item); } list.length = 0; this._toProcess = 0; // The owner of this queue can now safely do whatever it needs to with the active list return this._active; }, /** * [description] * * @method Phaser.Structs.ProcessQueue#getActive * @since 3.0.0 * * @genericUse {T[]} - [$return] * * @return {Array.<*>} [description] */ getActive: function () { return this._active; }, /** * [description] * * @method Phaser.Structs.ProcessQueue#destroy * @since 3.0.0 */ destroy: function () { this._pending = []; this._active = []; this._destroy = []; } }); module.exports = ProcessQueue; /***/ }), /* 224 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(18); var File = __webpack_require__(19); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var IsPlainObject = __webpack_require__(8); /** * @typedef {object} Phaser.Loader.FileTypes.TextFileConfig * * @property {string} key - The key of the file. Must be unique within both the Loader and the Text Cache. * @property {string} [url] - The absolute or relative URL to load the file from. * @property {string} [extension='txt'] - The default file extension to use if no url is provided. * @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ /** * @classdesc * A single Text File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#text method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#text. * * @class TextFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.TextFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ var TextFile = new Class({ Extends: File, initialize: function TextFile (loader, key, url, xhrSettings) { var extension = 'txt'; if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); url = GetFastValue(config, 'url'); xhrSettings = GetFastValue(config, 'xhrSettings'); extension = GetFastValue(config, 'extension', extension); } var fileConfig = { type: 'text', cache: loader.cacheManager.text, extension: extension, responseType: 'text', key: key, url: url, xhrSettings: xhrSettings }; File.call(this, loader, fileConfig); }, /** * Called automatically by Loader.nextFile. * This method controls what extra work this File does with its loaded data. * * @method Phaser.Loader.FileTypes.TextFile#onProcess * @since 3.7.0 */ onProcess: function () { this.state = CONST.FILE_PROCESSING; this.data = this.xhrLoader.responseText; this.onProcessComplete(); } }); /** * Adds a Text file, or array of Text files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.text('story', files/IntroStory.txt'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * The key must be a unique String. It is used to add the file to the global Text Cache upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the Text Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the Text Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.text({ * key: 'story', * url: 'files/IntroStory.txt' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.TextFileConfig` for more details. * * Once the file has finished loading you can access it from its Cache using its key: * * ```javascript * this.load.image('story', 'files/IntroStory.txt'); * // and later in your game ... * var data = this.cache.text.get('story'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and * this is what you would use to retrieve the text from the Text Cache. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story" * and no URL is given then the Loader will set the URL to be "story.txt". It will always add `.txt` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * Note: The ability to load this type of file will only be available if the Text File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#text * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.TextFileConfig|Phaser.Loader.FileTypes.TextFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('text', function (key, url, xhrSettings) { if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object this.addFile(new TextFile(this, key[i])); } } else { this.addFile(new TextFile(this, key, url, xhrSettings)); } return this; }); module.exports = TextFile; /***/ }), /* 225 */, /* 226 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Length = __webpack_require__(71); var Point = __webpack_require__(5); /** * [description] * * @function Phaser.Geom.Triangle.GetPoints * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Triangle} triangle - [description] * @param {integer} quantity - [description] * @param {number} stepRate - [description] * @param {(array|Phaser.Geom.Point[])} [out] - [description] * * @return {(array|Phaser.Geom.Point[])} [description] */ var GetPoints = function (triangle, quantity, stepRate, out) { if (out === undefined) { out = []; } var line1 = triangle.getLineA(); var line2 = triangle.getLineB(); var line3 = triangle.getLineC(); var length1 = Length(line1); var length2 = Length(line2); var length3 = Length(line3); var perimeter = length1 + length2 + length3; // If quantity is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead. if (!quantity) { quantity = perimeter / stepRate; } for (var i = 0; i < quantity; i++) { var p = perimeter * (i / quantity); var localPosition = 0; var point = new Point(); // Which line is it on? if (p < length1) { // Line 1 localPosition = p / length1; point.x = line1.x1 + (line1.x2 - line1.x1) * localPosition; point.y = line1.y1 + (line1.y2 - line1.y1) * localPosition; } else if (p > length1 + length2) { // Line 3 p -= length1 + length2; localPosition = p / length3; point.x = line3.x1 + (line3.x2 - line3.x1) * localPosition; point.y = line3.y1 + (line3.y2 - line3.y1) * localPosition; } else { // Line 2 p -= length1; localPosition = p / length2; point.x = line2.x1 + (line2.x2 - line2.x1) * localPosition; point.y = line2.y1 + (line2.y2 - line2.y1) * localPosition; } out.push(point); } return out; }; module.exports = GetPoints; /***/ }), /* 227 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); var Length = __webpack_require__(71); // Position is a value between 0 and 1 /** * [description] * * @function Phaser.Geom.Triangle.GetPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Triangle} triangle - [description] * @param {float} position - [description] * @param {(Phaser.Geom.Point|object)} [out] - [description] * * @return {(Phaser.Geom.Point|object)} [description] */ var GetPoint = function (triangle, position, out) { if (out === undefined) { out = new Point(); } var line1 = triangle.getLineA(); var line2 = triangle.getLineB(); var line3 = triangle.getLineC(); if (position <= 0 || position >= 1) { out.x = line1.x1; out.y = line1.y1; return out; } var length1 = Length(line1); var length2 = Length(line2); var length3 = Length(line3); var perimeter = length1 + length2 + length3; var p = perimeter * position; var localPosition = 0; // Which line is it on? if (p < length1) { // Line 1 localPosition = p / length1; out.x = line1.x1 + (line1.x2 - line1.x1) * localPosition; out.y = line1.y1 + (line1.y2 - line1.y1) * localPosition; } else if (p > length1 + length2) { // Line 3 p -= length1 + length2; localPosition = p / length3; out.x = line3.x1 + (line3.x2 - line3.x1) * localPosition; out.y = line3.y1 + (line3.y2 - line3.y1) * localPosition; } else { // Line 2 p -= length1; localPosition = p / length2; out.x = line2.x1 + (line2.x2 - line2.x1) * localPosition; out.y = line2.y1 + (line2.y2 - line2.y1) * localPosition; } return out; }; module.exports = GetPoint; /***/ }), /* 228 */, /* 229 */, /* 230 */, /* 231 */, /* 232 */, /* 233 */, /* 234 */, /* 235 */, /* 236 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Stepped */ module.exports = __webpack_require__(421); /***/ }), /* 237 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Sine */ module.exports = { In: __webpack_require__(424), Out: __webpack_require__(423), InOut: __webpack_require__(422) }; /***/ }), /* 238 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Quintic */ module.exports = { In: __webpack_require__(427), Out: __webpack_require__(426), InOut: __webpack_require__(425) }; /***/ }), /* 239 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Quartic */ module.exports = { In: __webpack_require__(430), Out: __webpack_require__(429), InOut: __webpack_require__(428) }; /***/ }), /* 240 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Quadratic */ module.exports = { In: __webpack_require__(433), Out: __webpack_require__(432), InOut: __webpack_require__(431) }; /***/ }), /* 241 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Linear */ module.exports = __webpack_require__(434); /***/ }), /* 242 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Expo */ module.exports = { In: __webpack_require__(437), Out: __webpack_require__(436), InOut: __webpack_require__(435) }; /***/ }), /* 243 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Elastic */ module.exports = { In: __webpack_require__(440), Out: __webpack_require__(439), InOut: __webpack_require__(438) }; /***/ }), /* 244 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Cubic */ module.exports = { In: __webpack_require__(443), Out: __webpack_require__(442), InOut: __webpack_require__(441) }; /***/ }), /* 245 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Circular */ module.exports = { In: __webpack_require__(446), Out: __webpack_require__(445), InOut: __webpack_require__(444) }; /***/ }), /* 246 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Bounce */ module.exports = { In: __webpack_require__(449), Out: __webpack_require__(448), InOut: __webpack_require__(447) }; /***/ }), /* 247 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Math.Easing.Back */ module.exports = { In: __webpack_require__(452), Out: __webpack_require__(451), InOut: __webpack_require__(450) }; /***/ }), /* 248 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Generate a random floating point number between the two given bounds, minimum inclusive, maximum exclusive. * * @function Phaser.Math.FloatBetween * @since 3.0.0 * * @param {float} min - The lower bound for the float, inclusive. * @param {float} max - The upper bound for the float exclusive. * * @return {float} A random float within the given range. */ var FloatBetween = function (min, max) { return Math.random() * (max - min) + min; }; module.exports = FloatBetween; /***/ }), /* 249 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Ellipse = __webpack_require__(114); Ellipse.Area = __webpack_require__(472); Ellipse.Circumference = __webpack_require__(177); Ellipse.CircumferencePoint = __webpack_require__(113); Ellipse.Clone = __webpack_require__(471); Ellipse.Contains = __webpack_require__(54); Ellipse.ContainsPoint = __webpack_require__(470); Ellipse.ContainsRect = __webpack_require__(469); Ellipse.CopyFrom = __webpack_require__(468); Ellipse.Equals = __webpack_require__(467); Ellipse.GetBounds = __webpack_require__(466); Ellipse.GetPoint = __webpack_require__(179); Ellipse.GetPoints = __webpack_require__(178); Ellipse.Offset = __webpack_require__(465); Ellipse.OffsetPoint = __webpack_require__(464); Ellipse.Random = __webpack_require__(134); module.exports = Ellipse; /***/ }), /* 250 */, /* 251 */, /* 252 */, /* 253 */, /* 254 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetValue = __webpack_require__(4); var Shuffle = __webpack_require__(95); var BuildChunk = function (a, b, qty) { var out = []; for (var aIndex = 0; aIndex < a.length; aIndex++) { for (var bIndex = 0; bIndex < b.length; bIndex++) { for (var i = 0; i < qty; i++) { out.push({ a: a[aIndex], b: b[bIndex] }); } } } return out; }; // options = repeat, random, randomB, yoyo, max, qty // Range ([a,b,c], [1,2,3]) = // a1, a2, a3, b1, b2, b3, c1, c2, c3 // Range ([a,b], [1,2,3], qty = 3) = // a1, a1, a1, a2, a2, a2, a3, a3, a3, b1, b1, b1, b2, b2, b2, b3, b3, b3 // Range ([a,b,c], [1,2,3], repeat x1) = // a1, a2, a3, b1, b2, b3, c1, c2, c3, a1, a2, a3, b1, b2, b3, c1, c2, c3 // Range ([a,b], [1,2], repeat -1 = endless, max = 14) = // Maybe if max is set then repeat goes to -1 automatically? // a1, a2, b1, b2, a1, a2, b1, b2, a1, a2, b1, b2, a1, a2 (capped at 14 elements) // Range ([a], [1,2,3,4,5], random = true) = // a4, a1, a5, a2, a3 // Range ([a, b], [1,2,3], random = true) = // b3, a2, a1, b1, a3, b2 // Range ([a, b, c], [1,2,3], randomB = true) = // a3, a1, a2, b2, b3, b1, c1, c3, c2 // Range ([a], [1,2,3,4,5], yoyo = true) = // a1, a2, a3, a4, a5, a5, a4, a3, a2, a1 // Range ([a, b], [1,2,3], yoyo = true) = // a1, a2, a3, b1, b2, b3, b3, b2, b1, a3, a2, a1 /** * [description] * * @function Phaser.Utils.Array.Range * @since 3.0.0 * * @param {array} a - [description] * @param {array} b - [description] * @param {object} options - [description] * * @return {array} [description] */ var Range = function (a, b, options) { var max = GetValue(options, 'max', 0); var qty = GetValue(options, 'qty', 1); var random = GetValue(options, 'random', false); var randomB = GetValue(options, 'randomB', false); var repeat = GetValue(options, 'repeat', 0); var yoyo = GetValue(options, 'yoyo', false); var out = []; if (randomB) { Shuffle(b); } // Endless repeat, so limit by max if (repeat === -1) { if (max === 0) { repeat = 0; } else { // Work out how many repeats we need var total = (a.length * b.length) * qty; if (yoyo) { total *= 2; } repeat = Math.ceil(max / total); } } for (var i = 0; i <= repeat; i++) { var chunk = BuildChunk(a, b, qty); if (random) { Shuffle(chunk); } out = out.concat(chunk); if (yoyo) { chunk.reverse(); out = out.concat(chunk); } } if (max) { out.splice(max); } return out; }; module.exports = Range; /***/ }), /* 255 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Round a given number so it is further away from zero. That is, positive numbers are rounded up, and negative numbers are rounded down. * * @function Phaser.Math.RoundAwayFromZero * @since 3.0.0 * * @param {number} value - The number to round. * * @return {number} The rounded number, rounded away from zero. */ var RoundAwayFromZero = function (value) { // "Opposite" of truncate. return (value > 0) ? Math.ceil(value) : Math.floor(value); }; module.exports = RoundAwayFromZero; /***/ }), /* 256 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Capitalizes the first letter of a string if there is one. * @example * UppercaseFirst('abc'); * // returns 'Abc' * @example * UppercaseFirst('the happy family'); * // returns 'The happy family' * @example * UppercaseFirst(''); * // returns '' * * @function Phaser.Utils.String.UppercaseFirst * @since 3.0.0 * * @param {string} str - The string to capitalize. * * @return {string} A new string, same as the first, but with the first letter capitalized. */ var UppercaseFirst = function (str) { return str && str[0].toUpperCase() + str.slice(1); }; module.exports = UppercaseFirst; /***/ }), /* 257 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Vector2 = __webpack_require__(6); /** * Takes the `x` and `y` coordinates and transforms them into the same space as * defined by the position, rotation and scale values. * * @function Phaser.Math.TransformXY * @since 3.0.0 * * @param {number} x - The x coordinate to be transformed. * @param {number} y - The y coordinate to be transformed. * @param {number} positionX - Horizontal position of the transform point. * @param {number} positionY - Vertical position of the transform point. * @param {number} rotation - Rotation of the transform point, in radians. * @param {number} scaleX - Horizontal scale of the transform point. * @param {number} scaleY - Vertical scale of the transform point. * @param {(Phaser.Math.Vector2|Phaser.Geom.Point|object)} [output] - The output vector, point or object for the translated coordinates. * * @return {(Phaser.Math.Vector2|Phaser.Geom.Point|object)} The translated point. */ var TransformXY = function (x, y, positionX, positionY, rotation, scaleX, scaleY, output) { if (output === undefined) { output = new Vector2(); } // ITRS var sr = Math.sin(-rotation); var cr = Math.cos(-rotation); var a = cr * scaleX; var b = -sr * scaleX; var c = sr * scaleY; var d = cr * scaleY; // Invert var n = a * d - b * c; var m0 = d / n; var m1 = -b / n; var m2 = -c / n; var m3 = a / n; var m4 = (c * positionY - d * positionX) / n; var m5 = -(a * positionY - b * positionX) / n; // Transform output.x = x * m0 + y * m2 + m4; output.y = x * m1 + y * m3 + m5; return output; }; module.exports = TransformXY; /***/ }), /* 258 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // 2.1.1 (Mar 17, 2016) /* ISC License Copyright (c) 2016, Mapbox Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ module.exports = earcut; /* vertices is a flat array of vertice coordinates like [x0,y0, x1,y1, x2,y2, ...]. holes is an array of hole indices if any (e.g. [5, 8] for a 12-vertice input would mean one hole with vertices 5–7 and another with 8–11). dimensions is the number of coordinates per vertice in the input array (2 by default). Each group of three vertice indices in the resulting array forms a triangle. */ function earcut(data, holeIndices, dim) { dim = dim || 2; var hasHoles = holeIndices && holeIndices.length, outerLen = hasHoles ? holeIndices[0] * dim : data.length, outerNode = linkedList(data, 0, outerLen, dim, true), triangles = []; if (!outerNode) return triangles; var minX, minY, maxX, maxY, x, y, size; if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim); // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox if (data.length > 80 * dim) { minX = maxX = data[0]; minY = maxY = data[1]; for (var i = dim; i < outerLen; i += dim) { x = data[i]; y = data[i + 1]; if (x < minX) minX = x; if (y < minY) minY = y; if (x > maxX) maxX = x; if (y > maxY) maxY = y; } // minX, minY and size are later used to transform coords into integers for z-order calculation size = Math.max(maxX - minX, maxY - minY); } earcutLinked(outerNode, triangles, dim, minX, minY, size); return triangles; } // create a circular doubly linked list from polygon points in the specified winding order function linkedList(data, start, end, dim, clockwise) { var i, last; if (clockwise === (signedArea(data, start, end, dim) > 0)) { for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last); } else { for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last); } if (last && equals(last, last.next)) { removeNode(last); last = last.next; } return last; } // eliminate colinear or duplicate points function filterPoints(start, end) { if (!start) return start; if (!end) end = start; var p = start, again; do { again = false; if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) { removeNode(p); p = end = p.prev; if (p === p.next) return null; again = true; } else { p = p.next; } } while (again || p !== end); return end; } // main ear slicing loop which triangulates a polygon (given as a linked list) function earcutLinked(ear, triangles, dim, minX, minY, size, pass) { if (!ear) return; // interlink polygon nodes in z-order if (!pass && size) indexCurve(ear, minX, minY, size); var stop = ear, prev, next; // iterate through ears, slicing them one by one while (ear.prev !== ear.next) { prev = ear.prev; next = ear.next; if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) { // cut off the triangle triangles.push(prev.i / dim); triangles.push(ear.i / dim); triangles.push(next.i / dim); removeNode(ear); // skipping the next vertice leads to less sliver triangles ear = next.next; stop = next.next; continue; } ear = next; // if we looped through the whole remaining polygon and can't find any more ears if (ear === stop) { // try filtering points and slicing again if (!pass) { earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1); // if this didn't work, try curing all small self-intersections locally } else if (pass === 1) { ear = cureLocalIntersections(ear, triangles, dim); earcutLinked(ear, triangles, dim, minX, minY, size, 2); // as a last resort, try splitting the remaining polygon into two } else if (pass === 2) { splitEarcut(ear, triangles, dim, minX, minY, size); } break; } } } // check whether a polygon node forms a valid ear with adjacent nodes function isEar(ear) { var a = ear.prev, b = ear, c = ear.next; if (area(a, b, c) >= 0) return false; // reflex, can't be an ear // now make sure we don't have other points inside the potential ear var p = ear.next.next; while (p !== ear.prev) { if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false; p = p.next; } return true; } function isEarHashed(ear, minX, minY, size) { var a = ear.prev, b = ear, c = ear.next; if (area(a, b, c) >= 0) return false; // reflex, can't be an ear // triangle bbox; min & max are calculated like this for speed var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x), minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y), maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x), maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y); // z-order range for the current triangle bbox; var minZ = zOrder(minTX, minTY, minX, minY, size), maxZ = zOrder(maxTX, maxTY, minX, minY, size); // first look for points inside the triangle in increasing z-order var p = ear.nextZ; while (p && p.z <= maxZ) { if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false; p = p.nextZ; } // then look for points in decreasing z-order p = ear.prevZ; while (p && p.z >= minZ) { if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false; p = p.prevZ; } return true; } // go through all polygon nodes and cure small local self-intersections function cureLocalIntersections(start, triangles, dim) { var p = start; do { var a = p.prev, b = p.next.next; if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) { triangles.push(a.i / dim); triangles.push(p.i / dim); triangles.push(b.i / dim); // remove two nodes involved removeNode(p); removeNode(p.next); p = start = b; } p = p.next; } while (p !== start); return p; } // try splitting polygon into two and triangulate them independently function splitEarcut(start, triangles, dim, minX, minY, size) { // look for a valid diagonal that divides the polygon into two var a = start; do { var b = a.next.next; while (b !== a.prev) { if (a.i !== b.i && isValidDiagonal(a, b)) { // split the polygon in two by the diagonal var c = splitPolygon(a, b); // filter colinear points around the cuts a = filterPoints(a, a.next); c = filterPoints(c, c.next); // run earcut on each half earcutLinked(a, triangles, dim, minX, minY, size); earcutLinked(c, triangles, dim, minX, minY, size); return; } b = b.next; } a = a.next; } while (a !== start); } // link every hole into the outer loop, producing a single-ring polygon without holes function eliminateHoles(data, holeIndices, outerNode, dim) { var queue = [], i, len, start, end, list; for (i = 0, len = holeIndices.length; i < len; i++) { start = holeIndices[i] * dim; end = i < len - 1 ? holeIndices[i + 1] * dim : data.length; list = linkedList(data, start, end, dim, false); if (list === list.next) list.steiner = true; queue.push(getLeftmost(list)); } queue.sort(compareX); // process holes from left to right for (i = 0; i < queue.length; i++) { eliminateHole(queue[i], outerNode); outerNode = filterPoints(outerNode, outerNode.next); } return outerNode; } function compareX(a, b) { return a.x - b.x; } // find a bridge between vertices that connects hole with an outer ring and and link it function eliminateHole(hole, outerNode) { outerNode = findHoleBridge(hole, outerNode); if (outerNode) { var b = splitPolygon(outerNode, hole); filterPoints(b, b.next); } } // David Eberly's algorithm for finding a bridge between hole and outer polygon function findHoleBridge(hole, outerNode) { var p = outerNode, hx = hole.x, hy = hole.y, qx = -Infinity, m; // find a segment intersected by a ray from the hole's leftmost point to the left; // segment's endpoint with lesser x will be potential connection point do { if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) { var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y); if (x <= hx && x > qx) { qx = x; if (x === hx) { if (hy === p.y) return p; if (hy === p.next.y) return p.next; } m = p.x < p.next.x ? p : p.next; } } p = p.next; } while (p !== outerNode); if (!m) return null; if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint // look for points inside the triangle of hole point, segment intersection and endpoint; // if there are no points found, we have a valid connection; // otherwise choose the point of the minimum angle with the ray as connection point var stop = m, mx = m.x, my = m.y, tanMin = Infinity, tan; p = m.next; while (p !== stop) { if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) { tan = Math.abs(hy - p.y) / (hx - p.x); // tangential if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) { m = p; tanMin = tan; } } p = p.next; } return m; } // interlink polygon nodes in z-order function indexCurve(start, minX, minY, size) { var p = start; do { if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, size); p.prevZ = p.prev; p.nextZ = p.next; p = p.next; } while (p !== start); p.prevZ.nextZ = null; p.prevZ = null; sortLinked(p); } // Simon Tatham's linked list merge sort algorithm // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html function sortLinked(list) { var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1; do { p = list; list = null; tail = null; numMerges = 0; while (p) { numMerges++; q = p; pSize = 0; for (i = 0; i < inSize; i++) { pSize++; q = q.nextZ; if (!q) break; } qSize = inSize; while (pSize > 0 || (qSize > 0 && q)) { if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) { e = p; p = p.nextZ; pSize--; } else { e = q; q = q.nextZ; qSize--; } if (tail) tail.nextZ = e; else list = e; e.prevZ = tail; tail = e; } p = q; } tail.nextZ = null; inSize *= 2; } while (numMerges > 1); return list; } // z-order of a point given coords and size of the data bounding box function zOrder(x, y, minX, minY, size) { // coords are transformed into non-negative 15-bit integer range x = 32767 * (x - minX) / size; y = 32767 * (y - minY) / size; x = (x | (x << 8)) & 0x00FF00FF; x = (x | (x << 4)) & 0x0F0F0F0F; x = (x | (x << 2)) & 0x33333333; x = (x | (x << 1)) & 0x55555555; y = (y | (y << 8)) & 0x00FF00FF; y = (y | (y << 4)) & 0x0F0F0F0F; y = (y | (y << 2)) & 0x33333333; y = (y | (y << 1)) & 0x55555555; return x | (y << 1); } // find the leftmost node of a polygon ring function getLeftmost(start) { var p = start, leftmost = start; do { if (p.x < leftmost.x) leftmost = p; p = p.next; } while (p !== start); return leftmost; } // check if a point lies within a convex triangle function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) { return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0; } // check if a diagonal between two polygon nodes is valid (lies in polygon interior) function isValidDiagonal(a, b) { return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b); } // signed area of a triangle function area(p, q, r) { return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y); } // check if two points are equal function equals(p1, p2) { return p1.x === p2.x && p1.y === p2.y; } // check if two segments intersect function intersects(p1, q1, p2, q2) { if ((equals(p1, q1) && equals(p2, q2)) || (equals(p1, q2) && equals(p2, q1))) return true; return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 && area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0; } // check if a polygon diagonal intersects any polygon segments function intersectsPolygon(a, b) { var p = a; do { if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b)) return true; p = p.next; } while (p !== a); return false; } // check if a polygon diagonal is locally inside the polygon function locallyInside(a, b) { return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0; } // check if the middle point of a polygon diagonal is inside the polygon function middleInside(a, b) { var p = a, inside = false, px = (a.x + b.x) / 2, py = (a.y + b.y) / 2; do { if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y && (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)) inside = !inside; p = p.next; } while (p !== a); return inside; } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two; // if one belongs to the outer ring and another to a hole, it merges it into a single ring function splitPolygon(a, b) { var a2 = new Node(a.i, a.x, a.y), b2 = new Node(b.i, b.x, b.y), an = a.next, bp = b.prev; a.next = b; b.prev = a; a2.next = an; an.prev = a2; b2.next = a2; a2.prev = b2; bp.next = b2; b2.prev = bp; return b2; } // create a node and optionally link it with previous one (in a circular doubly linked list) function insertNode(i, x, y, last) { var p = new Node(i, x, y); if (!last) { p.prev = p; p.next = p; } else { p.next = last.next; p.prev = last; last.next.prev = p; last.next = p; } return p; } function removeNode(p) { p.next.prev = p.prev; p.prev.next = p.next; if (p.prevZ) p.prevZ.nextZ = p.nextZ; if (p.nextZ) p.nextZ.prevZ = p.prevZ; } function Node(i, x, y) { // vertice index in coordinates array this.i = i; // vertex coordinates this.x = x; this.y = y; // previous and next vertice nodes in a polygon ring this.prev = null; this.next = null; // z-order curve value this.z = null; // previous and next nodes in z-order this.prevZ = null; this.nextZ = null; // indicates whether this is a steiner point this.steiner = false; } // return a percentage difference between the polygon area and its triangulation area; // used to verify correctness of triangulation earcut.deviation = function (data, holeIndices, dim, triangles) { var hasHoles = holeIndices && holeIndices.length; var outerLen = hasHoles ? holeIndices[0] * dim : data.length; var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim)); if (hasHoles) { for (var i = 0, len = holeIndices.length; i < len; i++) { var start = holeIndices[i] * dim; var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length; polygonArea -= Math.abs(signedArea(data, start, end, dim)); } } var trianglesArea = 0; for (i = 0; i < triangles.length; i += 3) { var a = triangles[i] * dim; var b = triangles[i + 1] * dim; var c = triangles[i + 2] * dim; trianglesArea += Math.abs( (data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1])); } return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea); }; function signedArea(data, start, end, dim) { var sum = 0; for (var i = start, j = end - dim; i < end; i += dim) { sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]); j = i; } return sum; } // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts earcut.flatten = function (data) { var dim = data[0][0].length, result = {vertices: [], holes: [], dimensions: dim}, holeIndex = 0; for (var i = 0; i < data.length; i++) { for (var j = 0; j < data[i].length; j++) { for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]); } if (i > 0) { holeIndex += data[i - 1].length; result.holes.push(holeIndex); } } return result; }; /***/ }), /* 259 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Felipe Alfonso <@bitnenfer> * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var Commands = __webpack_require__(119); var Earcut = __webpack_require__(258); var ModelViewProjection = __webpack_require__(202); var ShaderSourceFS = __webpack_require__(529); var ShaderSourceVS = __webpack_require__(528); var Utils = __webpack_require__(27); var WebGLPipeline = __webpack_require__(84); var Point = function (x, y, width, rgb, alpha) { this.x = x; this.y = y; this.width = width; this.rgb = rgb; this.alpha = alpha; }; var Path = function (x, y, width, rgb, alpha) { this.points = []; this.pointsLength = 1; this.points[0] = new Point(x, y, width, rgb, alpha); }; var currentMatrix = new Float32Array([ 1, 0, 0, 1, 0, 0 ]); var matrixStack = new Float32Array(6 * 1000); var matrixStackLength = 0; var pathArray = []; /** * @classdesc * The FlatTintPipeline is used for rendering flat colored shapes. * Mostly used by the Graphics game object. * The config properties are: * - game: Current game instance. * - renderer: Current WebGL renderer. * - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES. * Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants). * - vertShader: Source for vertex shader as a string. * - fragShader: Source for fragment shader as a string. * - vertexCapacity: The amount of vertices that shall be allocated * - vertexSize: The size of a single vertex in bytes. * * @class FlatTintPipeline * @extends Phaser.Renderer.WebGL.WebGLPipeline * @memberOf Phaser.Renderer.WebGL.Pipelines * @constructor * @since 3.0.0 * * @param {object} config - Used for overriding shader an pipeline properties if extending this pipeline. */ var FlatTintPipeline = new Class({ Extends: WebGLPipeline, Mixins: [ ModelViewProjection ], initialize: function FlatTintPipeline (config) { WebGLPipeline.call(this, { game: config.game, renderer: config.renderer, gl: config.renderer.gl, topology: (config.topology ? config.topology : config.renderer.gl.TRIANGLES), vertShader: (config.vertShader ? config.vertShader : ShaderSourceVS), fragShader: (config.fragShader ? config.fragShader : ShaderSourceFS), vertexCapacity: (config.vertexCapcity ? config.vertexCapacity : 12000), vertexSize: (config.vertexSize ? config.vertexSize : Float32Array.BYTES_PER_ELEMENT * 2 + Uint8Array.BYTES_PER_ELEMENT * 4), attributes: [ { name: 'inPosition', size: 2, type: config.renderer.gl.FLOAT, normalized: false, offset: 0 }, { name: 'inTint', size: 4, type: config.renderer.gl.UNSIGNED_BYTE, normalized: true, offset: Float32Array.BYTES_PER_ELEMENT * 2 } ] }); /** * Float32 view of the array buffer containing the pipeline's vertices. * * @name Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#vertexViewF32 * @type {Float32Array} * @since 3.0.0 */ this.vertexViewF32 = new Float32Array(this.vertexData); /** * Uint32 view of the array buffer containing the pipeline's vertices. * * @name Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#vertexViewU32 * @type {Uint32Array} * @since 3.0.0 */ this.vertexViewU32 = new Uint32Array(this.vertexData); /** * Used internally to draw triangles * * @name Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#tempTriangle * @type {array} * @since 3.0.0 */ this.tempTriangle = [ {x: 0, y: 0, width: 0, rgb: 0xFFFFFF, alpha: 1.0}, {x: 0, y: 0, width: 0, rgb: 0xFFFFFF, alpha: 1.0}, {x: 0, y: 0, width: 0, rgb: 0xFFFFFF, alpha: 1.0}, {x: 0, y: 0, width: 0, rgb: 0xFFFFFF, alpha: 1.0} ]; /** * Used internally by for triangulating a polyong * * @name Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#polygonCache * @type {array} * @default [] * @since 3.0.0 */ this.polygonCache = []; this.mvpInit(); }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#onBind * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline} [description] */ onBind: function () { WebGLPipeline.prototype.onBind.call(this); this.mvpUpdate(); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#resize * @since 3.0.0 * * @param {number} width - [description] * @param {number} height - [description] * @param {number} resolution - [description] * * @return {Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline} [description] */ resize: function (width, height, resolution) { WebGLPipeline.prototype.resize.call(this, width, height, resolution); this.projOrtho(0, this.width, this.height, 0, -1000.0, 1000.0); return this; }, /** * Pushes a rectangle into the vertex batch * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchFillRect * @since 3.0.0 * * @param {float} srcX - Graphics horizontal component for translation * @param {float} srcY - Graphics vertical component for translation * @param {float} srcScaleX - Graphics horizontal component for scale * @param {float} srcScaleY - Graphics vertical component for scale * @param {float} srcRotation - Graphics rotation * @param {float} x - Horiztonal top left coordinate of the rectangle * @param {float} y - Vertical top left coordinate of the rectangle * @param {float} width - Width of the rectangle * @param {float} height - Height of the rectangle * @param {integer} fillColor - RGB color packed as a uint * @param {float} fillAlpha - Alpha represented as float * @param {float} a1 - Matrix stack top a component * @param {float} b1 - Matrix stack top b component * @param {float} c1 - Matrix stack top c component * @param {float} d1 - Matrix stack top d component * @param {float} e1 - Matrix stack top e component * @param {float} f1 - Matrix stack top f component * @param {Float32Array} currentMatrix - Parent matrix, generally used by containers */ batchFillRect: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x, y, width, height, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix) { this.renderer.setPipeline(this); if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var vertexOffset = this.vertexCount * this.vertexComponentCount; var xw = x + width; var yh = y + height; var a0 = currentMatrix[0]; var b0 = currentMatrix[1]; var c0 = currentMatrix[2]; var d0 = currentMatrix[3]; var e0 = currentMatrix[4]; var f0 = currentMatrix[5]; var a = a1 * a0 + b1 * c0; var b = a1 * b0 + b1 * d0; var c = c1 * a0 + d1 * c0; var d = c1 * b0 + d1 * d0; var e = e1 * a0 + f1 * c0 + e0; var f = e1 * b0 + f1 * d0 + f0; var tx0 = x * a + y * c + e; var ty0 = x * b + y * d + f; var tx1 = x * a + yh * c + e; var ty1 = x * b + yh * d + f; var tx2 = xw * a + yh * c + e; var ty2 = xw * b + yh * d + f; var tx3 = xw * a + y * c + e; var ty3 = xw * b + y * d + f; var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha); vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewU32[vertexOffset + 2] = tint; vertexViewF32[vertexOffset + 3] = tx1; vertexViewF32[vertexOffset + 4] = ty1; vertexViewU32[vertexOffset + 5] = tint; vertexViewF32[vertexOffset + 6] = tx2; vertexViewF32[vertexOffset + 7] = ty2; vertexViewU32[vertexOffset + 8] = tint; vertexViewF32[vertexOffset + 9] = tx0; vertexViewF32[vertexOffset + 10] = ty0; vertexViewU32[vertexOffset + 11] = tint; vertexViewF32[vertexOffset + 12] = tx2; vertexViewF32[vertexOffset + 13] = ty2; vertexViewU32[vertexOffset + 14] = tint; vertexViewF32[vertexOffset + 15] = tx3; vertexViewF32[vertexOffset + 16] = ty3; vertexViewU32[vertexOffset + 17] = tint; this.vertexCount += 6; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchFillTriangle * @since 3.0.0 * * @param {float} srcX - Graphics horizontal component for translation * @param {float} srcY - Graphics vertical component for translation * @param {float} srcScaleX - Graphics horizontal component for scale * @param {float} srcScaleY - Graphics vertical component for scale * @param {float} srcRotation - Graphics rotation * @param {float} x0 - Point 0 x coordinate * @param {float} y0 - Point 0 y coordinate * @param {float} x1 - Point 1 x coordinate * @param {float} y1 - Point 1 y coordinate * @param {float} x2 - Point 2 x coordinate * @param {float} y2 - Point 2 y coordinate * @param {integer} fillColor - RGB color packed as a uint * @param {float} fillAlpha - Alpha represented as float * @param {float} a1 - Matrix stack top a component * @param {float} b1 - Matrix stack top b component * @param {float} c1 - Matrix stack top c component * @param {float} d1 - Matrix stack top d component * @param {float} e1 - Matrix stack top e component * @param {float} f1 - Matrix stack top f component * @param {Float32Array} currentMatrix - Parent matrix, generally used by containers */ batchFillTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix) { this.renderer.setPipeline(this); if (this.vertexCount + 3 > this.vertexCapacity) { this.flush(); } var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var vertexOffset = this.vertexCount * this.vertexComponentCount; var a0 = currentMatrix[0]; var b0 = currentMatrix[1]; var c0 = currentMatrix[2]; var d0 = currentMatrix[3]; var e0 = currentMatrix[4]; var f0 = currentMatrix[5]; var a = a1 * a0 + b1 * c0; var b = a1 * b0 + b1 * d0; var c = c1 * a0 + d1 * c0; var d = c1 * b0 + d1 * d0; var e = e1 * a0 + f1 * c0 + e0; var f = e1 * b0 + f1 * d0 + f0; var tx0 = x0 * a + y0 * c + e; var ty0 = x0 * b + y0 * d + f; var tx1 = x1 * a + y1 * c + e; var ty1 = x1 * b + y1 * d + f; var tx2 = x2 * a + y2 * c + e; var ty2 = x2 * b + y2 * d + f; var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha); vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewU32[vertexOffset + 2] = tint; vertexViewF32[vertexOffset + 3] = tx1; vertexViewF32[vertexOffset + 4] = ty1; vertexViewU32[vertexOffset + 5] = tint; vertexViewF32[vertexOffset + 6] = tx2; vertexViewF32[vertexOffset + 7] = ty2; vertexViewU32[vertexOffset + 8] = tint; this.vertexCount += 3; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchStrokeTriangle * @since 3.0.0 * * @param {float} srcX - Graphics horizontal component for translation * @param {float} srcY - Graphics vertical component for translation * @param {float} srcScaleX - Graphics horizontal component for scale * @param {float} srcScaleY - Graphics vertical component for scale * @param {float} srcRotation - Graphics rotation * @param {float} x0 - [description] * @param {float} y0 - [description] * @param {float} x1 - [description] * @param {float} y1 - [description] * @param {float} x2 - [description] * @param {float} y2 - [description] * @param {float} lineWidth - Size of the line as a float value * @param {integer} lineColor - RGB color packed as a uint * @param {float} lineAlpha - Alpha represented as float * @param {float} a - Matrix stack top a component * @param {float} b - Matrix stack top b component * @param {float} c - Matrix stack top c component * @param {float} d - Matrix stack top d component * @param {float} e - Matrix stack top e component * @param {float} f - Matrix stack top f component * @param {Float32Array} currentMatrix - Parent matrix, generally used by containers */ batchStrokeTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, currentMatrix) { var tempTriangle = this.tempTriangle; tempTriangle[0].x = x0; tempTriangle[0].y = y0; tempTriangle[0].width = lineWidth; tempTriangle[0].rgb = lineColor; tempTriangle[0].alpha = lineAlpha; tempTriangle[1].x = x1; tempTriangle[1].y = y1; tempTriangle[1].width = lineWidth; tempTriangle[1].rgb = lineColor; tempTriangle[1].alpha = lineAlpha; tempTriangle[2].x = x2; tempTriangle[2].y = y2; tempTriangle[2].width = lineWidth; tempTriangle[2].rgb = lineColor; tempTriangle[2].alpha = lineAlpha; tempTriangle[3].x = x0; tempTriangle[3].y = y0; tempTriangle[3].width = lineWidth; tempTriangle[3].rgb = lineColor; tempTriangle[3].alpha = lineAlpha; this.batchStrokePath( srcX, srcY, srcScaleX, srcScaleY, srcRotation, tempTriangle, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, false, currentMatrix ); }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchFillPath * @since 3.0.0 * * @param {float} srcX - Graphics horizontal component for translation * @param {float} srcY - Graphics vertical component for translation * @param {float} srcScaleX - Graphics horizontal component for scale * @param {float} srcScaleY - Graphics vertical component for scale * @param {float} srcRotation - Graphics rotation * @param {float} path - Collection of points that represent the path * @param {integer} fillColor - RGB color packed as a uint * @param {float} fillAlpha - Alpha represented as float * @param {float} a1 - Matrix stack top a component * @param {float} b1 - Matrix stack top b component * @param {float} c1 - Matrix stack top c component * @param {float} d1 - Matrix stack top d component * @param {float} e1 - Matrix stack top e component * @param {float} f1 - Matrix stack top f component * @param {Float32Array} currentMatrix - Parent matrix, generally used by containers */ batchFillPath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix) { this.renderer.setPipeline(this); var length = path.length; var polygonCache = this.polygonCache; var polygonIndexArray; var point; var v0, v1, v2; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var vertexOffset = 0; var x0, y0, x1, y1, x2, y2; var tx0, ty0, tx1, ty1, tx2, ty2; var a0 = currentMatrix[0]; var b0 = currentMatrix[1]; var c0 = currentMatrix[2]; var d0 = currentMatrix[3]; var e0 = currentMatrix[4]; var f0 = currentMatrix[5]; var a = a1 * a0 + b1 * c0; var b = a1 * b0 + b1 * d0; var c = c1 * a0 + d1 * c0; var d = c1 * b0 + d1 * d0; var e = e1 * a0 + f1 * c0 + e0; var f = e1 * b0 + f1 * d0 + f0; var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha); for (var pathIndex = 0; pathIndex < length; ++pathIndex) { point = path[pathIndex]; polygonCache.push(point.x, point.y); } polygonIndexArray = Earcut(polygonCache); length = polygonIndexArray.length; for (var index = 0; index < length; index += 3) { v0 = polygonIndexArray[index + 0] * 2; v1 = polygonIndexArray[index + 1] * 2; v2 = polygonIndexArray[index + 2] * 2; if (this.vertexCount + 3 > this.vertexCapacity) { this.flush(); } vertexOffset = this.vertexCount * this.vertexComponentCount; x0 = polygonCache[v0 + 0]; y0 = polygonCache[v0 + 1]; x1 = polygonCache[v1 + 0]; y1 = polygonCache[v1 + 1]; x2 = polygonCache[v2 + 0]; y2 = polygonCache[v2 + 1]; tx0 = x0 * a + y0 * c + e; ty0 = x0 * b + y0 * d + f; tx1 = x1 * a + y1 * c + e; ty1 = x1 * b + y1 * d + f; tx2 = x2 * a + y2 * c + e; ty2 = x2 * b + y2 * d + f; vertexViewF32[vertexOffset + 0] = tx0; vertexViewF32[vertexOffset + 1] = ty0; vertexViewU32[vertexOffset + 2] = tint; vertexViewF32[vertexOffset + 3] = tx1; vertexViewF32[vertexOffset + 4] = ty1; vertexViewU32[vertexOffset + 5] = tint; vertexViewF32[vertexOffset + 6] = tx2; vertexViewF32[vertexOffset + 7] = ty2; vertexViewU32[vertexOffset + 8] = tint; this.vertexCount += 3; } polygonCache.length = 0; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchStrokePath * @since 3.0.0 * * @param {float} srcX - Graphics horizontal component for translation * @param {float} srcY - Graphics vertical component for translation * @param {float} srcScaleX - Graphics horizontal component for scale * @param {float} srcScaleY - Graphics vertical component for scale * @param {float} srcRotation - Graphics rotation * @param {array} path - [description] * @param {float} lineWidth - [description] * @param {integer} lineColor - RGB color packed as a uint * @param {float} lineAlpha - Alpha represented as float * @param {float} a - Matrix stack top a component * @param {float} b - Matrix stack top b component * @param {float} c - Matrix stack top c component * @param {float} d - Matrix stack top d component * @param {float} e - Matrix stack top e component * @param {float} f - Matrix stack top f component * @param {boolean} isLastPath - Indicates if the path should be closed * @param {Float32Array} currentMatrix - Parent matrix, generally used by containers */ batchStrokePath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, isLastPath, currentMatrix) { this.renderer.setPipeline(this); var point0, point1; var pathLength = path.length; var polylines = this.polygonCache; var last, curr; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var vertexOffset; var line; var getTint = Utils.getTintAppendFloatAlphaAndSwap; for (var pathIndex = 0; pathIndex + 1 < pathLength; pathIndex += 1) { point0 = path[pathIndex]; point1 = path[pathIndex + 1]; line = this.batchLine( srcX, srcY, srcScaleX, srcScaleY, srcRotation, point0.x, point0.y, point1.x, point1.y, point0.width / 2, point1.width / 2, point0.rgb, point1.rgb, lineAlpha, a, b, c, d, e, f, currentMatrix ); polylines.push(line); } /* Render joints */ for (var index = 1, polylinesLength = polylines.length; index < polylinesLength; ++index) { if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } last = polylines[index - 1] || polylines[polylinesLength - 1]; curr = polylines[index]; vertexOffset = this.vertexCount * this.vertexComponentCount; vertexViewF32[vertexOffset + 0] = last[3 * 2 + 0]; vertexViewF32[vertexOffset + 1] = last[3 * 2 + 1]; vertexViewU32[vertexOffset + 2] = getTint(last[3 * 2 + 2], lineAlpha); vertexViewF32[vertexOffset + 3] = last[3 * 0 + 0]; vertexViewF32[vertexOffset + 4] = last[3 * 0 + 1]; vertexViewU32[vertexOffset + 5] = getTint(last[3 * 0 + 2], lineAlpha); vertexViewF32[vertexOffset + 6] = curr[3 * 3 + 0]; vertexViewF32[vertexOffset + 7] = curr[3 * 3 + 1]; vertexViewU32[vertexOffset + 8] = getTint(curr[3 * 3 + 2], lineAlpha); vertexViewF32[vertexOffset + 9] = last[3 * 0 + 0]; vertexViewF32[vertexOffset + 10] = last[3 * 0 + 1]; vertexViewU32[vertexOffset + 11] = getTint(last[3 * 0 + 2], lineAlpha); vertexViewF32[vertexOffset + 12] = last[3 * 2 + 0]; vertexViewF32[vertexOffset + 13] = last[3 * 2 + 1]; vertexViewU32[vertexOffset + 14] = getTint(last[3 * 2 + 2], lineAlpha); vertexViewF32[vertexOffset + 15] = curr[3 * 1 + 0]; vertexViewF32[vertexOffset + 16] = curr[3 * 1 + 1]; vertexViewU32[vertexOffset + 17] = getTint(curr[3 * 1 + 2], lineAlpha); this.vertexCount += 6; } polylines.length = 0; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchLine * @since 3.0.0 * * @param {float} srcX - Graphics horizontal component for translation * @param {float} srcY - Graphics vertical component for translation * @param {float} srcScaleX - Graphics horizontal component for scale * @param {float} srcScaleY - Graphics vertical component for scale * @param {float} srcRotation - Graphics rotation * @param {float} ax - X coordinate to the start of the line * @param {float} ay - Y coordinate to the start of the line * @param {float} bx - X coordinate to the end of the line * @param {float} by - Y coordinate to the end of the line * @param {float} aLineWidth - Width of the start of the line * @param {float} bLineWidth - Width of the end of the line * @param {integer} aLineColor - RGB color packed as a uint * @param {integer} bLineColor - RGB color packed as a uint * @param {float} lineAlpha - Alpha represented as float * @param {float} a1 - Matrix stack top a component * @param {float} b1 - Matrix stack top b component * @param {float} c1 - Matrix stack top c component * @param {float} d1 - Matrix stack top d component * @param {float} e1 - Matrix stack top e component * @param {float} f1 - Matrix stack top f component * @param {Float32Array} currentMatrix - Parent matrix, generally used by containers */ batchLine: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha, a1, b1, c1, d1, e1, f1, currentMatrix) { this.renderer.setPipeline(this); if (this.vertexCount + 6 > this.vertexCapacity) { this.flush(); } var a0 = currentMatrix[0]; var b0 = currentMatrix[1]; var c0 = currentMatrix[2]; var d0 = currentMatrix[3]; var e0 = currentMatrix[4]; var f0 = currentMatrix[5]; var a = a1 * a0 + b1 * c0; var b = a1 * b0 + b1 * d0; var c = c1 * a0 + d1 * c0; var d = c1 * b0 + d1 * d0; var e = e1 * a0 + f1 * c0 + e0; var f = e1 * b0 + f1 * d0 + f0; var vertexViewF32 = this.vertexViewF32; var vertexViewU32 = this.vertexViewU32; var dx = bx - ax; var dy = by - ay; var len = Math.sqrt(dx * dx + dy * dy); var al0 = aLineWidth * (by - ay) / len; var al1 = aLineWidth * (ax - bx) / len; var bl0 = bLineWidth * (by - ay) / len; var bl1 = bLineWidth * (ax - bx) / len; var lx0 = bx - bl0; var ly0 = by - bl1; var lx1 = ax - al0; var ly1 = ay - al1; var lx2 = bx + bl0; var ly2 = by + bl1; var lx3 = ax + al0; var ly3 = ay + al1; var x0 = lx0 * a + ly0 * c + e; var y0 = lx0 * b + ly0 * d + f; var x1 = lx1 * a + ly1 * c + e; var y1 = lx1 * b + ly1 * d + f; var x2 = lx2 * a + ly2 * c + e; var y2 = lx2 * b + ly2 * d + f; var x3 = lx3 * a + ly3 * c + e; var y3 = lx3 * b + ly3 * d + f; var getTint = Utils.getTintAppendFloatAlphaAndSwap; var aTint = getTint(aLineColor, lineAlpha); var bTint = getTint(bLineColor, lineAlpha); var vertexOffset = this.vertexCount * this.vertexComponentCount; vertexViewF32[vertexOffset + 0] = x0; vertexViewF32[vertexOffset + 1] = y0; vertexViewU32[vertexOffset + 2] = bTint; vertexViewF32[vertexOffset + 3] = x1; vertexViewF32[vertexOffset + 4] = y1; vertexViewU32[vertexOffset + 5] = aTint; vertexViewF32[vertexOffset + 6] = x2; vertexViewF32[vertexOffset + 7] = y2; vertexViewU32[vertexOffset + 8] = bTint; vertexViewF32[vertexOffset + 9] = x1; vertexViewF32[vertexOffset + 10] = y1; vertexViewU32[vertexOffset + 11] = aTint; vertexViewF32[vertexOffset + 12] = x3; vertexViewF32[vertexOffset + 13] = y3; vertexViewU32[vertexOffset + 14] = aTint; vertexViewF32[vertexOffset + 15] = x2; vertexViewF32[vertexOffset + 16] = y2; vertexViewU32[vertexOffset + 17] = bTint; this.vertexCount += 6; return [ x0, y0, bLineColor, x1, y1, aLineColor, x2, y2, bLineColor, x3, y3, aLineColor ]; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchGraphics * @since 3.0.0 * * @param {Phaser.GameObjects.Graphics} graphics - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description] */ batchGraphics: function (graphics, camera, parentTransformMatrix) { if (graphics.commandBuffer.length <= 0) { return; } var parentMatrix = null; if (parentTransformMatrix) { parentMatrix = parentTransformMatrix.matrix; } this.renderer.setPipeline(this); var cameraScrollX = camera.scrollX * graphics.scrollFactorX; var cameraScrollY = camera.scrollY * graphics.scrollFactorY; var srcX = graphics.x; var srcY = graphics.y; var srcScaleX = graphics.scaleX; var srcScaleY = graphics.scaleY; var srcRotation = graphics.rotation; var commands = graphics.commandBuffer; var alpha = graphics.alpha; var lineAlpha = 1.0; var fillAlpha = 1.0; var lineColor = 0; var fillColor = 0; var lineWidth = 1.0; var cameraMatrix = camera.matrix.matrix; var lastPath = null; var iteration = 0; var iterStep = 0.01; var tx = 0; var ty = 0; var ta = 0; var x = 0; var y = 0; var radius = 0; var startAngle = 0; var endAngle = 0; var anticlockwise = 0; var path = null; var sin = Math.sin; var cos = Math.cos; var PI2 = Math.PI * 2; var sr = sin(srcRotation); var cr = cos(srcRotation); var sra = cr * srcScaleX; var srb = sr * srcScaleX; var src = -sr * srcScaleY; var srd = cr * srcScaleY; var sre = srcX; var srf = srcY; var cma = cameraMatrix[0]; var cmb = cameraMatrix[1]; var cmc = cameraMatrix[2]; var cmd = cameraMatrix[3]; var cme = cameraMatrix[4]; var cmf = cameraMatrix[5]; var mva, mvb, mvc, mvd, mve, mvf; if (parentMatrix) { var pma = parentMatrix[0]; var pmb = parentMatrix[1]; var pmc = parentMatrix[2]; var pmd = parentMatrix[3]; var pme = parentMatrix[4]; var pmf = parentMatrix[5]; var cse = -cameraScrollX; var csf = -cameraScrollY; var pse = cse * cma + csf * cmc + cme; var psf = cse * cmb + csf * cmd + cmf; var pca = pma * cma + pmb * cmc; var pcb = pma * cmb + pmb * cmd; var pcc = pmc * cma + pmd * cmc; var pcd = pmc * cmb + pmd * cmd; var pce = pme * cma + pmf * cmc + pse; var pcf = pme * cmb + pmf * cmd + psf; mva = sra * pca + srb * pcc; mvb = sra * pcb + srb * pcd; mvc = src * pca + srd * pcc; mvd = src * pcb + srd * pcd; mve = sre * pca + srf * pcc + pce; mvf = sre * pcb + srf * pcd + pcf; } else { sre -= cameraScrollX; srf -= cameraScrollY; mva = sra * cma + srb * cmc; mvb = sra * cmb + srb * cmd; mvc = src * cma + srd * cmc; mvd = src * cmb + srd * cmd; mve = sre * cma + srf * cmc + cme; mvf = sre * cmb + srf * cmd + cmf; } var pathArrayIndex; var pathArrayLength; pathArray.length = 0; for (var cmdIndex = 0, cmdLength = commands.length; cmdIndex < cmdLength; ++cmdIndex) { cmd = commands[cmdIndex]; switch (cmd) { case Commands.ARC: iteration = 0; x = commands[cmdIndex + 1]; y = commands[cmdIndex + 2]; radius = commands[cmdIndex + 3]; startAngle = commands[cmdIndex + 4]; endAngle = commands[cmdIndex + 5]; anticlockwise = commands[cmdIndex + 6]; if (lastPath === null) { lastPath = new Path(x + cos(startAngle) * radius, y + sin(startAngle) * radius, lineWidth, lineColor, lineAlpha * alpha); pathArray.push(lastPath); iteration += iterStep; } endAngle -= startAngle; if (anticlockwise) { if (endAngle < -PI2) { endAngle = -PI2; } else if (endAngle > 0) { endAngle = -PI2 + endAngle % PI2; } } else if (endAngle > PI2) { endAngle = PI2; } else if (endAngle < 0) { endAngle = PI2 + endAngle % PI2; } while (iteration < 1) { ta = endAngle * iteration + startAngle; tx = x + cos(ta) * radius; ty = y + sin(ta) * radius; lastPath.points.push(new Point(tx, ty, lineWidth, lineColor, lineAlpha * alpha)); iteration += iterStep; } ta = endAngle + startAngle; tx = x + cos(ta) * radius; ty = y + sin(ta) * radius; lastPath.points.push(new Point(tx, ty, lineWidth, lineColor, lineAlpha * alpha)); cmdIndex += 6; break; case Commands.LINE_STYLE: lineWidth = commands[cmdIndex + 1]; lineColor = commands[cmdIndex + 2]; lineAlpha = commands[cmdIndex + 3]; cmdIndex += 3; break; case Commands.FILL_STYLE: fillColor = commands[cmdIndex + 1]; fillAlpha = commands[cmdIndex + 2]; cmdIndex += 2; break; case Commands.BEGIN_PATH: pathArray.length = 0; lastPath = null; break; case Commands.CLOSE_PATH: if (lastPath && lastPath.points.length) { lastPath.points.push(lastPath.points[0]); } break; case Commands.FILL_PATH: for (pathArrayIndex = 0, pathArrayLength = pathArray.length; pathArrayIndex < pathArrayLength; ++pathArrayIndex) { this.batchFillPath( /* Graphics Game Object Properties */ srcX, srcY, srcScaleX, srcScaleY, srcRotation, /* Rectangle properties */ pathArray[pathArrayIndex].points, fillColor, fillAlpha * alpha, /* Transform */ mva, mvb, mvc, mvd, mve, mvf, currentMatrix ); } break; case Commands.STROKE_PATH: for (pathArrayIndex = 0, pathArrayLength = pathArray.length; pathArrayIndex < pathArrayLength; ++pathArrayIndex) { path = pathArray[pathArrayIndex]; this.batchStrokePath( /* Graphics Game Object Properties */ srcX, srcY, srcScaleX, srcScaleY, srcRotation, /* Rectangle properties */ path.points, lineWidth, lineColor, lineAlpha * alpha, /* Transform */ mva, mvb, mvc, mvd, mve, mvf, path === this._lastPath, currentMatrix ); } break; case Commands.FILL_RECT: this.batchFillRect( /* Graphics Game Object Properties */ srcX, srcY, srcScaleX, srcScaleY, srcRotation, /* Rectangle properties */ commands[cmdIndex + 1], commands[cmdIndex + 2], commands[cmdIndex + 3], commands[cmdIndex + 4], fillColor, fillAlpha * alpha, /* Transform */ mva, mvb, mvc, mvd, mve, mvf, currentMatrix ); cmdIndex += 4; break; case Commands.FILL_TRIANGLE: this.batchFillTriangle( /* Graphics Game Object Properties */ srcX, srcY, srcScaleX, srcScaleY, srcRotation, /* Triangle properties */ commands[cmdIndex + 1], commands[cmdIndex + 2], commands[cmdIndex + 3], commands[cmdIndex + 4], commands[cmdIndex + 5], commands[cmdIndex + 6], fillColor, fillAlpha * alpha, /* Transform */ mva, mvb, mvc, mvd, mve, mvf, currentMatrix ); cmdIndex += 6; break; case Commands.STROKE_TRIANGLE: this.batchStrokeTriangle( /* Graphics Game Object Properties */ srcX, srcY, srcScaleX, srcScaleY, srcRotation, /* Triangle properties */ commands[cmdIndex + 1], commands[cmdIndex + 2], commands[cmdIndex + 3], commands[cmdIndex + 4], commands[cmdIndex + 5], commands[cmdIndex + 6], lineWidth, lineColor, lineAlpha * alpha, /* Transform */ mva, mvb, mvc, mvd, mve, mvf, currentMatrix ); cmdIndex += 6; break; case Commands.LINE_TO: if (lastPath !== null) { lastPath.points.push(new Point(commands[cmdIndex + 1], commands[cmdIndex + 2], lineWidth, lineColor, lineAlpha * alpha)); } else { lastPath = new Path(commands[cmdIndex + 1], commands[cmdIndex + 2], lineWidth, lineColor, lineAlpha * alpha); pathArray.push(lastPath); } cmdIndex += 2; break; case Commands.MOVE_TO: lastPath = new Path(commands[cmdIndex + 1], commands[cmdIndex + 2], lineWidth, lineColor, lineAlpha * alpha); pathArray.push(lastPath); cmdIndex += 2; break; case Commands.LINE_FX_TO: if (lastPath !== null) { lastPath.points.push(new Point( commands[cmdIndex + 1], commands[cmdIndex + 2], commands[cmdIndex + 3], commands[cmdIndex + 4], commands[cmdIndex + 5] * alpha )); } else { lastPath = new Path( commands[cmdIndex + 1], commands[cmdIndex + 2], commands[cmdIndex + 3], commands[cmdIndex + 4], commands[cmdIndex + 5] * alpha ); pathArray.push(lastPath); } cmdIndex += 5; break; case Commands.MOVE_FX_TO: lastPath = new Path( commands[cmdIndex + 1], commands[cmdIndex + 2], commands[cmdIndex + 3], commands[cmdIndex + 4], commands[cmdIndex + 5] * alpha ); pathArray.push(lastPath); cmdIndex += 5; break; case Commands.SAVE: matrixStack[matrixStackLength + 0] = currentMatrix[0]; matrixStack[matrixStackLength + 1] = currentMatrix[1]; matrixStack[matrixStackLength + 2] = currentMatrix[2]; matrixStack[matrixStackLength + 3] = currentMatrix[3]; matrixStack[matrixStackLength + 4] = currentMatrix[4]; matrixStack[matrixStackLength + 5] = currentMatrix[5]; matrixStackLength += 6; break; case Commands.RESTORE: matrixStackLength -= 6; currentMatrix[0] = matrixStack[matrixStackLength + 0]; currentMatrix[1] = matrixStack[matrixStackLength + 1]; currentMatrix[2] = matrixStack[matrixStackLength + 2]; currentMatrix[3] = matrixStack[matrixStackLength + 3]; currentMatrix[4] = matrixStack[matrixStackLength + 4]; currentMatrix[5] = matrixStack[matrixStackLength + 5]; break; case Commands.TRANSLATE: x = commands[cmdIndex + 1]; y = commands[cmdIndex + 2]; currentMatrix[4] = currentMatrix[0] * x + currentMatrix[2] * y + currentMatrix[4]; currentMatrix[5] = currentMatrix[1] * x + currentMatrix[3] * y + currentMatrix[5]; cmdIndex += 2; break; case Commands.SCALE: x = commands[cmdIndex + 1]; y = commands[cmdIndex + 2]; currentMatrix[0] *= x; currentMatrix[1] *= x; currentMatrix[2] *= y; currentMatrix[3] *= y; cmdIndex += 2; break; case Commands.ROTATE: y = commands[cmdIndex + 1]; x = sin(y); y = cos(y); sra = currentMatrix[0]; srb = currentMatrix[1]; src = currentMatrix[2]; srd = currentMatrix[3]; currentMatrix[0] = y * sra + x * src; currentMatrix[1] = y * srb + x * srd; currentMatrix[2] = -x * sra + y * src; currentMatrix[3] = -x * srb + y * srd; cmdIndex += 1; break; default: // eslint-disable-next-line no-console console.error('Phaser: Invalid Graphics Command ID ' + cmd); break; } } }, // Stubs /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#drawStaticTilemapLayer * @since 3.0.0 * * @param {Phaser.Tilemaps.StaticTilemapLayer} tilemap - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ drawStaticTilemapLayer: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#drawEmitterManager * @since 3.0.0 * * @param {Phaser.GameObjects.Particles.ParticleEmitterManager} emitterManager - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ drawEmitterManager: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#drawBlitter * @since 3.0.0 * * @param {Phaser.GameObjects.Blitter} blitter - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ drawBlitter: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchSprite * @since 3.0.0 * * @param {Phaser.GameObjects.Sprite} sprite - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ batchSprite: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchMesh * @since 3.0.0 * * @param {Phaser.GameObjects.Mesh} mesh - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ batchMesh: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchBitmapText * @since 3.0.0 * * @param {Phaser.GameObjects.BitmapText} bitmapText - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ batchBitmapText: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchDynamicBitmapText * @since 3.0.0 * * @param {Phaser.GameObjects.DynamicBitmapText} bitmapText - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ batchDynamicBitmapText: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchText * @since 3.0.0 * * @param {Phaser.GameObjects.Text} text - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ batchText: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchDynamicTilemapLayer * @since 3.0.0 * * @param {Phaser.Tilemaps.DynamicTilemapLayer} tilemapLayer - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ batchDynamicTilemapLayer: function () { }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchTileSprite * @since 3.0.0 * * @param {Phaser.GameObjects.TileSprite} tileSprite - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ batchTileSprite: function () { } }); module.exports = FlatTintPipeline; /***/ }), /* 260 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Felipe Alfonso <@bitnenfer> * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var ShaderSourceFS = __webpack_require__(531); var ShaderSourceVS = __webpack_require__(530); var WebGLPipeline = __webpack_require__(84); /** * @classdesc * BitmapMaskPipeline handles all bitmap masking rendering in WebGL. It works by using * sampling two texture on the fragment shader and using the fragment's alpha to clip the region. * The config properties are: * - game: Current game instance. * - renderer: Current WebGL renderer. * - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES. * Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants). * - vertShader: Source for vertex shader as a string. * - fragShader: Source for fragment shader as a string. * - vertexCapacity: The amount of vertices that shall be allocated * - vertexSize: The size of a single vertex in bytes. * * @class BitmapMaskPipeline * @extends Phaser.Renderer.WebGL.WebGLPipeline * @memberOf Phaser.Renderer.WebGL.Pipelines * @constructor * @since 3.0.0 * * @param {object} config - Used for overriding shader an pipeline properties if extending this pipeline. */ var BitmapMaskPipeline = new Class({ Extends: WebGLPipeline, initialize: function BitmapMaskPipeline (config) { WebGLPipeline.call(this, { game: config.game, renderer: config.renderer, gl: config.renderer.gl, topology: (config.topology ? config.topology : config.renderer.gl.TRIANGLES), vertShader: (config.vertShader ? config.vertShader : ShaderSourceVS), fragShader: (config.fragShader ? config.fragShader : ShaderSourceFS), vertexCapacity: (config.vertexCapacity ? config.vertexCapacity : 3), vertexSize: (config.vertexSize ? config.vertexSize : Float32Array.BYTES_PER_ELEMENT * 2), vertices: new Float32Array([ -1, +1, -1, -7, +7, +1 ]).buffer, attributes: [ { name: 'inPosition', size: 2, type: config.renderer.gl.FLOAT, normalized: false, offset: 0 } ] }); /** * Float32 view of the array buffer containing the pipeline's vertices. * * @name Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#vertexViewF32 * @type {Float32Array} * @since 3.0.0 */ this.vertexViewF32 = new Float32Array(this.vertexData); /** * Size of the batch. * * @name Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#maxQuads * @type {number} * @default 1 * @since 3.0.0 */ this.maxQuads = 1; /** * Dirty flag to check if resolution properties need to be updated on the * masking shader. * * @name Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#resolutionDirty * @type {boolean} * @default true * @since 3.0.0 */ this.resolutionDirty = true; }, /** * Called every time the pipeline needs to be used. * It binds all necessary resources. * * @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#onBind * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline} [description] */ onBind: function () { WebGLPipeline.prototype.onBind.call(this); var renderer = this.renderer; var program = this.program; if (this.resolutionDirty) { renderer.setFloat2(program, 'uResolution', this.width, this.height); renderer.setInt1(program, 'uMainSampler', 0); renderer.setInt1(program, 'uMaskSampler', 1); this.resolutionDirty = false; } return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#resize * @since 3.0.0 * * @param {number} width - [description] * @param {number} height - [description] * @param {number} resolution - [description] * * @return {Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline} [description] */ resize: function (width, height, resolution) { WebGLPipeline.prototype.resize.call(this, width, height, resolution); this.resolutionDirty = true; return this; }, /** * Binds necessary resources and renders the mask to a separated framebuffer. * The framebuffer for the masked object is also bound for further use. * * @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#beginMask * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} mask - GameObject used as mask. * @param {Phaser.GameObjects.GameObject} maskedObject - GameObject masked by the mask GameObject. * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ beginMask: function (mask, maskedObject, camera) { var bitmapMask = mask.bitmapMask; var renderer = this.renderer; var gl = this.gl; var visible = bitmapMask.visible; if (bitmapMask && gl) { // First we clear the mask framebuffer renderer.setFramebuffer(mask.maskFramebuffer); gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT); // We render out mask source bitmapMask.visible = true; bitmapMask.renderWebGL(renderer, bitmapMask, 0.0, camera); bitmapMask.visible = visible; renderer.flush(); // Bind and clear our main source (masked object) renderer.setFramebuffer(mask.mainFramebuffer); gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT); } }, /** * The masked game object's framebuffer is unbound and it's texture * is bound together with the mask texture and the mask shader and * a draw call with a single quad is processed. Here is where the * masking effect is applied. * * @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#endMask * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} mask - GameObject used as a mask. */ endMask: function (mask) { var bitmapMask = mask.bitmapMask; var renderer = this.renderer; var gl = this.gl; if (bitmapMask) { // Return to default framebuffer renderer.setFramebuffer(null); // Bind bitmap mask pipeline and draw renderer.setPipeline(this); renderer.setTexture2D(mask.maskTexture, 1); renderer.setTexture2D(mask.mainTexture, 0); renderer.setInt1(this.program, 'uInvertMaskAlpha', mask.invertAlpha); // Finally draw a triangle filling the whole screen gl.drawArrays(this.topology, 0, 3); } } }); module.exports = BitmapMaskPipeline; /***/ }), /* 261 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Renderer.Snapshot.WebGL * @since 3.0.0 * * @param {HTMLCanvasElement} sourceCanvas - [description] * @param {string} [type='image/png'] - [description] * @param {float} [encoderOptions=0.92] - [description] * * @return {HTMLImageElement} [description] */ var WebGLSnapshot = function (sourceCanvas, type, encoderOptions) { if (!type) { type = 'image/png'; } if (!encoderOptions) { encoderOptions = 0.92; } var gl = sourceCanvas.getContext('experimental-webgl'); var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4); gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels); // CanvasPool? var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); var imageData; canvas.width = gl.drawingBufferWidth; canvas.height = gl.drawingBufferHeight; imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); var data = imageData.data; for (var y = 0; y < canvas.height; y += 1) { for (var x = 0; x < canvas.width; x += 1) { var si = ((canvas.height - y) * canvas.width + x) * 4; var di = (y * canvas.width + x) * 4; data[di + 0] = pixels[si + 0]; data[di + 1] = pixels[si + 1]; data[di + 2] = pixels[si + 2]; data[di + 3] = pixels[si + 3]; } } ctx.putImageData(imageData, 0, 0); var src = canvas.toDataURL(type, encoderOptions); var image = new Image(); image.src = src; return image; }; module.exports = WebGLSnapshot; /***/ }), /* 262 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Felipe Alfonso <@bitnenfer> * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(20); var IsSizePowerOfTwo = __webpack_require__(85); var SpliceOne = __webpack_require__(56); var Utils = __webpack_require__(27); var WebGLSnapshot = __webpack_require__(261); // Default Pipelines var BitmapMaskPipeline = __webpack_require__(260); var FlatTintPipeline = __webpack_require__(259); var ForwardDiffuseLightPipeline = __webpack_require__(148); var TextureTintPipeline = __webpack_require__(129); /** * @callback WebGLContextCallback * * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - [description] */ /** * @typedef {object} SnapshotState * * @property {SnapshotCallback} callback - [description] * @property {string} type - [description] * @property {float} encoder - [description] */ /** * @classdesc * WebGLRenderer is a class that contains the needed functionality to keep the * WebGLRenderingContext state clean. The main idea of the WebGLRenderer is to keep track of * any context change that happens for WebGL rendering inside of Phaser. This means * if raw webgl functions are called outside the WebGLRenderer of the Phaser WebGL * rendering ecosystem they might pollute the current WebGLRenderingContext state producing * unexpected behaviour. It's recommended that WebGL interaction is done through * WebGLRenderer and/or WebGLPipeline. * * @class WebGLRenderer * @memberOf Phaser.Renderer.WebGL * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - [description] */ var WebGLRenderer = new Class({ initialize: function WebGLRenderer (game) { // eslint-disable-next-line consistent-this var renderer = this; var gameConfig = game.config; var contextCreationConfig = { alpha: gameConfig.transparent, depth: false, // enable when 3D is added in the future antialias: gameConfig.antialias, premultipliedAlpha: gameConfig.premultipliedAlpha, stencil: true, preserveDrawingBuffer: gameConfig.preserveDrawingBuffer, failIfMajorPerformanceCaveat: gameConfig.failIfMajorPerformanceCaveat, powerPreference: gameConfig.powerPreference }; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#config * @type {RendererConfig} * @since 3.0.0 */ this.config = { clearBeforeRender: gameConfig.clearBeforeRender, pixelArt: gameConfig.pixelArt, backgroundColor: gameConfig.backgroundColor, contextCreation: contextCreationConfig, resolution: gameConfig.resolution, autoResize: gameConfig.autoResize, roundPixels: gameConfig.roundPixels, maxTextures: gameConfig.maxTextures, maxTextureSize: gameConfig.maxTextureSize }; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#game * @type {Phaser.Game} * @since 3.0.0 */ this.game = game; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#type * @type {integer} * @since 3.0.0 */ this.type = CONST.WEBGL; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#width * @type {number} * @since 3.0.0 */ this.width = game.config.width; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#height * @type {number} * @since 3.0.0 */ this.height = game.config.height; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#canvas * @type {HTMLCanvasElement} * @since 3.0.0 */ this.canvas = game.canvas; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#lostContextCallbacks * @type {WebGLContextCallback[]} * @since 3.0.0 */ this.lostContextCallbacks = []; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#restoredContextCallbacks * @type {WebGLContextCallback[]} * @since 3.0.0 */ this.restoredContextCallbacks = []; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#blendModes * @type {array} * @default [] * @since 3.0.0 */ this.blendModes = []; /** * Keeps track of any WebGLTexture created with the current WebGLRenderingContext * * @name Phaser.Renderer.WebGL.WebGLRenderer#nativeTextures * @type {array} * @default [] * @since 3.0.0 */ this.nativeTextures = []; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#contextLost * @type {boolean} * @default false * @since 3.0.0 */ this.contextLost = false; /** * This object will store all pipelines created through addPipeline * * @name Phaser.Renderer.WebGL.WebGLRenderer#pipelines * @type {object} * @default null * @since 3.0.0 */ this.pipelines = null; /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#snapshotState * @type {SnapshotState} * @since 3.0.0 */ this.snapshotState = { callback: null, type: null, encoder: null }; // Internal Renderer State (Textures, Framebuffers, Pipelines, Buffers, etc) /** * Cached value for the last texture unit that was used * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentActiveTextureUnit * @type {integer} * @since 3.1.0 */ this.currentActiveTextureUnit = 0; /** * An array of the last texture handles that were bound to the WebGLRenderingContext * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentTextures * @type {array} * @since 3.0.0 */ this.currentTextures = new Array(16); /** * Current framebuffer in use * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentFramebuffer * @type {WebGLFramebuffer} * @default null * @since 3.0.0 */ this.currentFramebuffer = null; /** * Current WebGLPipeline in use * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentPipeline * @type {Phaser.Renderer.WebGL.WebGLPipeline} * @default null * @since 3.0.0 */ this.currentPipeline = null; /** * Current WebGLProgram in use * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentProgram * @type {WebGLProgram} * @default null * @since 3.0.0 */ this.currentProgram = null; /** * Current WebGLBuffer (Vertex buffer) in use * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentVertexBuffer * @type {WebGLBuffer} * @default null * @since 3.0.0 */ this.currentVertexBuffer = null; /** * Current WebGLBuffer (Index buffer) in use * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentIndexBuffer * @type {WebGLBuffer} * @default null * @since 3.0.0 */ this.currentIndexBuffer = null; /** * Current blend mode in use * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentBlendMode * @type {integer} * @since 3.0.0 */ this.currentBlendMode = Infinity; /** * Indicates if the the scissor state is enabled in WebGLRenderingContext * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissorEnabled * @type {boolean} * @default false * @since 3.0.0 */ this.currentScissorEnabled = false; /** * Stores the current scissor data * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissor * @type {Uint32Array} * @since 3.0.0 */ this.currentScissor = new Uint32Array([ 0, 0, this.width, this.height ]); /** * Index to the scissor stack top * * @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissorIdx * @type {number} * @default 0 * @since 3.0.0 */ this.currentScissorIdx = 0; /** * Stack of scissor data * * @name Phaser.Renderer.WebGL.WebGLRenderer#scissorStack * @type {Uint32Array} * @since 3.0.0 */ this.scissorStack = new Uint32Array(4 * 1000); // Setup context lost and restore event listeners this.canvas.addEventListener('webglcontextlost', function (event) { renderer.contextLost = true; event.preventDefault(); for (var index = 0; index < renderer.lostContextCallbacks.length; ++index) { var callback = renderer.lostContextCallbacks[index]; callback[0].call(callback[1], renderer); } }, false); this.canvas.addEventListener('webglcontextrestored', function () { renderer.contextLost = false; renderer.init(renderer.config); for (var index = 0; index < renderer.restoredContextCallbacks.length; ++index) { var callback = renderer.restoredContextCallbacks[index]; callback[0].call(callback[1], renderer); } }, false); // These are initialized post context creation /** * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#gl * @type {WebGLRenderingContext} * @default null * @since 3.0.0 */ this.gl = null; /** * Array of strings that indicate which WebGL extensions are supported by the browser * * @name Phaser.Renderer.WebGL.WebGLRenderer#supportedExtensions * @type {object} * @default null * @since 3.0.0 */ this.supportedExtensions = null; /** * Extensions loaded into the current context * * @name Phaser.Renderer.WebGL.WebGLRenderer#extensions * @type {object} * @default {} * @since 3.0.0 */ this.extensions = {}; /** * Stores the current WebGL component formats for further use * * @name Phaser.Renderer.WebGL.WebGLRenderer#glFormats * @type {array} * @default [] * @since 3.2.0 */ this.glFormats = []; /** * Stores the supported WebGL texture compression formats. * * @name Phaser.Renderer.WebGL.WebGLRenderer#compression * @type {array} * @since 3.8.0 */ this.compression = { ETC1: false, PVRTC: false, S3TC: false }; this.init(this.config); }, /** * Creates a new WebGLRenderingContext and initializes all internal * state. * * @method Phaser.Renderer.WebGL.WebGLRenderer#init * @since 3.0.0 * * @param {object} config - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ init: function (config) { var gl; var canvas = this.canvas; var clearColor = config.backgroundColor; // Did they provide their own context? if (this.game.config.context) { gl = this.game.config.context; } else { gl = canvas.getContext('webgl', config.contextCreation) || canvas.getContext('experimental-webgl', config.contextCreation); } if (!gl || gl.isContextLost()) { this.contextLost = true; throw new Error('This browser does not support WebGL. Try using the Canvas pipeline.'); } this.gl = gl; // Set it back into the Game, so devs can access it from there too this.game.context = gl; for (var i = 0; i <= 16; i++) { this.blendModes.push({ func: [ gl.ONE, gl.ONE_MINUS_SRC_ALPHA ], equation: gl.FUNC_ADD }); } this.blendModes[1].func = [ gl.ONE, gl.DST_ALPHA ]; this.blendModes[2].func = [ gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA ]; this.blendModes[3].func = [ gl.ONE, gl.ONE_MINUS_SRC_COLOR ]; this.glFormats[0] = gl.BYTE; this.glFormats[1] = gl.SHORT; this.glFormats[2] = gl.UNSIGNED_BYTE; this.glFormats[3] = gl.UNSIGNED_SHORT; this.glFormats[4] = gl.FLOAT; // Load supported extensions var exts = gl.getSupportedExtensions(); if (!config.maxTextures) { config.maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); } if (!config.maxTextureSize) { config.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); } var extString = 'WEBGL_compressed_texture_'; var wkExtString = 'WEBKIT_' + extString; this.compression.ETC1 = gl.getExtension(extString + 'etc1') || gl.getExtension(wkExtString + 'etc1'); this.compression.PVRTC = gl.getExtension(extString + 'pvrtc') || gl.getExtension(wkExtString + 'pvrtc'); this.compression.S3TC = gl.getExtension(extString + 's3tc') || gl.getExtension(wkExtString + 's3tc'); this.supportedExtensions = exts; // Setup initial WebGL state gl.disable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); gl.disable(gl.SCISSOR_TEST); gl.enable(gl.BLEND); gl.clearColor(clearColor.redGL, clearColor.greenGL, clearColor.blueGL, 1.0); // Initialize all textures to null for (var index = 0; index < this.currentTextures.length; ++index) { this.currentTextures[index] = null; } // Clear previous pipelines and reload default ones this.pipelines = {}; this.addPipeline('TextureTintPipeline', new TextureTintPipeline({ game: this.game, renderer: this })); this.addPipeline('FlatTintPipeline', new FlatTintPipeline({ game: this.game, renderer: this })); this.addPipeline('BitmapMaskPipeline', new BitmapMaskPipeline({ game: this.game, renderer: this })); this.addPipeline('Light2D', new ForwardDiffuseLightPipeline({ game: this.game, renderer: this })); this.setBlendMode(CONST.BlendModes.NORMAL); this.resize(this.width, this.height); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#resize * @since 3.0.0 * * @param {number} width - [description] * @param {number} height - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ resize: function (width, height) { var gl = this.gl; var pipelines = this.pipelines; var resolution = this.config.resolution; this.width = Math.floor(width * resolution); this.height = Math.floor(height * resolution); this.canvas.width = this.width; this.canvas.height = this.height; if (this.config.autoResize) { this.canvas.style.width = (this.width / resolution) + 'px'; this.canvas.style.height = (this.height / resolution) + 'px'; } gl.viewport(0, 0, this.width, this.height); // Update all registered pipelines for (var pipelineName in pipelines) { pipelines[pipelineName].resize(width, height, resolution); } this.currentScissor.set([ 0, 0, this.width, this.height ]); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#onContextRestored * @since 3.0.0 * * @param {WebGLContextCallback} callback - [description] * @param {object} target - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ onContextRestored: function (callback, target) { this.restoredContextCallbacks.push([ callback, target ]); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#onContextLost * @since 3.0.0 * * @param {WebGLContextCallback} callback - [description] * @param {object} target - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ onContextLost: function (callback, target) { this.lostContextCallbacks.push([ callback, target ]); return this; }, /** * Checks if a WebGL extension is supported * * @method Phaser.Renderer.WebGL.WebGLRenderer#hasExtension * @since 3.0.0 * * @param {string} extensionName - Name of the WebGL extension * * @return {boolean} [description] */ hasExtension: function (extensionName) { return this.supportedExtensions ? this.supportedExtensions.indexOf(extensionName) : false; }, /** * Loads a WebGL extension * * @method Phaser.Renderer.WebGL.WebGLRenderer#getExtension * @since 3.0.0 * * @param {string} extensionName - [description] * * @return {object} WebGL extension if the extension is supported */ getExtension: function (extensionName) { if (!this.hasExtension(extensionName)) { return null; } if (!(extensionName in this.extensions)) { this.extensions[extensionName] = this.gl.getExtension(extensionName); } return this.extensions[extensionName]; }, /** * Flushes the current pipeline if the pipeline is bound * * @method Phaser.Renderer.WebGL.WebGLRenderer#flush * @since 3.0.0 */ flush: function () { if (this.currentPipeline) { this.currentPipeline.flush(); } }, /* Renderer State Manipulation Functions */ /** * Checks if a pipeline is present in the current WebGLRenderer * * @method Phaser.Renderer.WebGL.WebGLRenderer#hasPipeline * @since 3.0.0 * * @param {string} pipelineName - Name of the pipeline * * @return {boolean} [description] */ hasPipeline: function (pipelineName) { return (pipelineName in this.pipelines); }, /** * Returns the pipeline by name if the pipeline exists * * @method Phaser.Renderer.WebGL.WebGLRenderer#getPipeline * @since 3.0.0 * * @param {string} pipelineName - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ getPipeline: function (pipelineName) { return (this.hasPipeline(pipelineName)) ? this.pipelines[pipelineName] : null; }, /** * Removes a pipeline by name * * @method Phaser.Renderer.WebGL.WebGLRenderer#removePipeline * @since 3.0.0 * * @param {string} pipelineName - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ removePipeline: function (pipelineName) { delete this.pipelines[pipelineName]; return this; }, /** * Adds a pipeline instance into the collection of pipelines * * @method Phaser.Renderer.WebGL.WebGLRenderer#addPipeline * @since 3.0.0 * * @param {string} pipelineName - [description] * @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - Pipeline instance must extend WebGLPipeline * * @return {Phaser.Renderer.WebGL.WebGLPipeline} The instance that was passed. */ addPipeline: function (pipelineName, pipelineInstance) { if (!this.hasPipeline(pipelineName)) { this.pipelines[pipelineName] = pipelineInstance; } else { console.warn('Pipeline', pipelineName, ' already exists.'); } pipelineInstance.name = pipelineName; this.pipelines[pipelineName].resize(this.width, this.height, this.config.resolution); return pipelineInstance; }, /** * Sets the current scissor state * * @method Phaser.Renderer.WebGL.WebGLRenderer#setScissor * @since 3.0.0 * * @param {integer} x - [description] * @param {integer} y - [description] * @param {integer} w - [description] * @param {integer} h - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setScissor: function (x, y, w, h) { var gl = this.gl; var currentScissor = this.currentScissor; var enabled = (x === 0 && y === 0 && w === gl.canvas.width && h === gl.canvas.height && w >= 0 && h >= 0); if (currentScissor[0] !== x || currentScissor[1] !== y || currentScissor[2] !== w || currentScissor[3] !== h) { this.flush(); } currentScissor[0] = x; currentScissor[1] = y; currentScissor[2] = w; currentScissor[3] = h; this.currentScissorEnabled = enabled; if (enabled) { gl.disable(gl.SCISSOR_TEST); return this; } gl.enable(gl.SCISSOR_TEST); gl.scissor(x, (gl.drawingBufferHeight - y - h), w, h); return this; }, /** * Pushes a new scissor state. This is used to set nested scissor states. * * @method Phaser.Renderer.WebGL.WebGLRenderer#pushScissor * @since 3.0.0 * * @param {integer} x - [description] * @param {integer} y - [description] * @param {integer} w - [description] * @param {integer} h - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ pushScissor: function (x, y, w, h) { var scissorStack = this.scissorStack; var stackIndex = this.currentScissorIdx; var currentScissor = this.currentScissor; scissorStack[stackIndex + 0] = currentScissor[0]; scissorStack[stackIndex + 1] = currentScissor[1]; scissorStack[stackIndex + 2] = currentScissor[2]; scissorStack[stackIndex + 3] = currentScissor[3]; this.currentScissorIdx += 4; this.setScissor(x, y, w, h); return this; }, /** * Pops the last scissor state and sets it. * * @method Phaser.Renderer.WebGL.WebGLRenderer#popScissor * @since 3.0.0 * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ popScissor: function () { var scissorStack = this.scissorStack; var stackIndex = this.currentScissorIdx - 4; var x = scissorStack[stackIndex + 0]; var y = scissorStack[stackIndex + 1]; var w = scissorStack[stackIndex + 2]; var h = scissorStack[stackIndex + 3]; this.currentScissorIdx = stackIndex; this.setScissor(x, y, w, h); return this; }, /** * Binds a WebGLPipeline and sets it as the current pipeline to be used. * * @method Phaser.Renderer.WebGL.WebGLRenderer#setPipeline * @since 3.0.0 * * @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - [description] * * @return {Phaser.Renderer.WebGL.WebGLPipeline} [description] */ setPipeline: function (pipelineInstance) { if (this.currentPipeline !== pipelineInstance || this.currentPipeline.vertexBuffer !== this.currentVertexBuffer || this.currentPipeline.program !== this.currentProgram) { this.flush(); this.currentPipeline = pipelineInstance; this.currentPipeline.bind(); } this.currentPipeline.onBind(); return this.currentPipeline; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setBlendMode * @since 3.0.0 * * @param {integer} blendModeId - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setBlendMode: function (blendModeId) { var gl = this.gl; var blendMode = this.blendModes[blendModeId]; if (blendModeId !== CONST.BlendModes.SKIP_CHECK && this.currentBlendMode !== blendModeId) { this.flush(); gl.enable(gl.BLEND); gl.blendEquation(blendMode.equation); if (blendMode.func.length > 2) { gl.blendFuncSeparate(blendMode.func[0], blendMode.func[1], blendMode.func[2], blendMode.func[3]); } else { gl.blendFunc(blendMode.func[0], blendMode.func[1]); } this.currentBlendMode = blendModeId; } return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#addBlendMode * @since 3.0.0 * * @param {function} func - [description] * @param {function} equation - [description] * * @return {integer} [description] */ addBlendMode: function (func, equation) { var index = this.blendModes.push({ func: func, equation: equation }); return index - 1; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#updateBlendMode * @since 3.0.0 * * @param {integer} index - [description] * @param {function} func - [description] * @param {function} equation - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ updateBlendMode: function (index, func, equation) { if (this.blendModes[index]) { this.blendModes[index].func = func; if (equation) { this.blendModes[index].equation = equation; } } return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#removeBlendMode * @since 3.0.0 * * @param {integer} index - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ removeBlendMode: function (index) { if (index > 16 && this.blendModes[index]) { this.blendModes.splice(index, 1); } return this; }, /** * Binds a texture at a texture unit. If a texture is already * bound to that unit it will force a flush on the current pipeline. * * @method Phaser.Renderer.WebGL.WebGLRenderer#setTexture2D * @since 3.0.0 * * @param {WebGLTexture} texture - The WebGL texture that needs to be bound * @param {integer} textureUnit - The texture unit to which the texture will be bound * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ setTexture2D: function (texture, textureUnit) { var gl = this.gl; if (texture !== this.currentTextures[textureUnit]) { this.flush(); if (this.currentActiveTextureUnit !== textureUnit) { gl.activeTexture(gl.TEXTURE0 + textureUnit); this.currentActiveTextureUnit = textureUnit; } gl.bindTexture(gl.TEXTURE_2D, texture); this.currentTextures[textureUnit] = texture; } return this; }, /** * Binds a framebuffer. If there was another framebuffer already bound * it will force a pipeline flush. * * @method Phaser.Renderer.WebGL.WebGLRenderer#setFramebuffer * @since 3.0.0 * * @param {WebGLFramebuffer} framebuffer - The framebuffer that needs to be bound * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ setFramebuffer: function (framebuffer) { var gl = this.gl; if (framebuffer !== this.currentFramebuffer) { this.flush(); gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); this.currentFramebuffer = framebuffer; } return this; }, /** * Binds a program. If there was another program already bound * it will force a pipeline flush * * @method Phaser.Renderer.WebGL.WebGLRenderer#setProgram * @since 3.0.0 * * @param {WebGLProgram} program - The program that needs to be bound * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ setProgram: function (program) { var gl = this.gl; if (program !== this.currentProgram) { this.flush(); gl.useProgram(program); this.currentProgram = program; } return this; }, /** * Bounds a vertex buffer. If there is a vertex buffer already bound * it'll force a pipeline flush. * * @method Phaser.Renderer.WebGL.WebGLRenderer#setVertexBuffer * @since 3.0.0 * * @param {WebGLBuffer} vertexBuffer - The buffer that needs to be bound * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ setVertexBuffer: function (vertexBuffer) { var gl = this.gl; if (vertexBuffer !== this.currentVertexBuffer) { this.flush(); gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); this.currentVertexBuffer = vertexBuffer; } return this; }, /** * Bounds a index buffer. If there is a index buffer already bound * it'll force a pipeline flush. * * @method Phaser.Renderer.WebGL.WebGLRenderer#setIndexBuffer * @since 3.0.0 * * @param {WebGLBuffer} indexBuffer - The buffer the needs to be bound * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ setIndexBuffer: function (indexBuffer) { var gl = this.gl; if (indexBuffer !== this.currentIndexBuffer) { this.flush(); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); this.currentIndexBuffer = indexBuffer; } return this; }, /* Renderer Resource Creation Functions */ /** * Creates a texture from an image source. If the source is not valid * it creates an empty texture * * @method Phaser.Renderer.WebGL.WebGLRenderer#createTextureFromSource * @since 3.0.0 * * @param {object} source - [description] * @param {integer} width - [description] * @param {integer} height - [description] * @param {integer} scaleMode - [description] * * @return {WebGLTexture} [description] */ createTextureFromSource: function (source, width, height, scaleMode) { var gl = this.gl; var filter = gl.NEAREST; var wrap = gl.CLAMP_TO_EDGE; var texture = null; width = source ? source.width : width; height = source ? source.height : height; if (IsSizePowerOfTwo(width, height)) { wrap = gl.REPEAT; } if (scaleMode === CONST.ScaleModes.LINEAR) { filter = gl.LINEAR; } else if (scaleMode === CONST.ScaleModes.NEAREST || this.config.pixelArt) { filter = gl.NEAREST; } if (!source && typeof width === 'number' && typeof height === 'number') { texture = this.createTexture2D(0, filter, filter, wrap, wrap, gl.RGBA, null, width, height); } else { texture = this.createTexture2D(0, filter, filter, wrap, wrap, gl.RGBA, source); } return texture; }, /** * A wrapper for creating a WebGLTexture. If not pixel data is passed * it will create an empty texture. * * @method Phaser.Renderer.WebGL.WebGLRenderer#createTexture2D * @since 3.0.0 * * @param {integer} mipLevel - Mip level of the texture * @param {integer} minFilter - Filtering of the texture * @param {integer} magFilter - Filtering of the texture * @param {integer} wrapT - Wrapping mode of the texture * @param {integer} wrapS - Wrapping mode of the texture * @param {integer} format - Which format does the texture use * @param {object} pixels - pixel data * @param {integer} width - Width of the texture in pixels * @param {integer} height - Height of the texture in pixels * @param {boolean} pma - Does the texture hace premultiplied alpha. * * @return {WebGLTexture} Raw WebGLTexture */ createTexture2D: function (mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma) { var gl = this.gl; var texture = gl.createTexture(); pma = (pma === undefined || pma === null) ? true : pma; this.setTexture2D(texture, 0); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT); gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, pma); if (pixels === null || pixels === undefined) { gl.texImage2D(gl.TEXTURE_2D, mipLevel, format, width, height, 0, format, gl.UNSIGNED_BYTE, null); } else { gl.texImage2D(gl.TEXTURE_2D, mipLevel, format, format, gl.UNSIGNED_BYTE, pixels); width = pixels.width; height = pixels.height; } this.setTexture2D(null, 0); texture.isAlphaPremultiplied = pma; texture.isRenderTexture = false; texture.width = width; texture.height = height; this.nativeTextures.push(texture); return texture; }, /** * Wrapper for creating WebGLFramebuffer. * * @method Phaser.Renderer.WebGL.WebGLRenderer#createFramebuffer * @since 3.0.0 * * @param {integer} width - Width in pixels of the framebuffer * @param {integer} height - Height in pixels of the framebuffer * @param {WebGLTexture} renderTexture - The color texture to where the color pixels are written * @param {boolean} addDepthStencilBuffer - Indicates if the current framebuffer support depth and stencil buffers * * @return {WebGLFramebuffer} Raw WebGLFramebuffer */ createFramebuffer: function (width, height, renderTexture, addDepthStencilBuffer) { var gl = this.gl; var framebuffer = gl.createFramebuffer(); var complete = 0; this.setFramebuffer(framebuffer); if (addDepthStencilBuffer) { var depthStencilBuffer = gl.createRenderbuffer(); gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer); gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height); gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer); } renderTexture.isRenderTexture = true; renderTexture.isAlphaPremultiplied = false; gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, renderTexture, 0); complete = gl.checkFramebufferStatus(gl.FRAMEBUFFER); if (complete !== gl.FRAMEBUFFER_COMPLETE) { var errors = { 36054: 'Incomplete Attachment', 36055: 'Missing Attachment', 36057: 'Incomplete Dimensions', 36061: 'Framebuffer Unsupported' }; throw new Error('Framebuffer incomplete. Framebuffer status: ' + errors[complete]); } framebuffer.renderTexture = renderTexture; this.setFramebuffer(null); return framebuffer; }, /** * Wrapper for creating a WebGLProgram * * @method Phaser.Renderer.WebGL.WebGLRenderer#createProgram * @since 3.0.0 * * @param {string} vertexShader - Source to the vertex shader * @param {string} fragmentShader - Source to the fragment shader * * @return {WebGLProgram} Raw WebGLProgram */ createProgram: function (vertexShader, fragmentShader) { var gl = this.gl; var program = gl.createProgram(); var vs = gl.createShader(gl.VERTEX_SHADER); var fs = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(vs, vertexShader); gl.shaderSource(fs, fragmentShader); gl.compileShader(vs); gl.compileShader(fs); if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS)) { throw new Error('Failed to compile Vertex Shader:\n' + gl.getShaderInfoLog(vs)); } if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS)) { throw new Error('Failed to compile Fragment Shader:\n' + gl.getShaderInfoLog(fs)); } gl.attachShader(program, vs); gl.attachShader(program, fs); gl.linkProgram(program); if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { throw new Error('Failed to link program:\n' + gl.getProgramInfoLog(program)); } return program; }, /** * Wrapper for creating a vertex buffer. * * @method Phaser.Renderer.WebGL.WebGLRenderer#createVertexBuffer * @since 3.0.0 * * @param {ArrayBuffer} initialDataOrSize - It's either ArrayBuffer or an integer indicating the size of the vbo * @param {integer} bufferUsage - How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW * * @return {WebGLBuffer} Raw vertex buffer */ createVertexBuffer: function (initialDataOrSize, bufferUsage) { var gl = this.gl; var vertexBuffer = gl.createBuffer(); this.setVertexBuffer(vertexBuffer); gl.bufferData(gl.ARRAY_BUFFER, initialDataOrSize, bufferUsage); this.setVertexBuffer(null); return vertexBuffer; }, /** * Wrapper for creating a vertex buffer. * * @method Phaser.Renderer.WebGL.WebGLRenderer#createIndexBuffer * @since 3.0.0 * * @param {ArrayBuffer} initialDataOrSize - It's either ArrayBuffer or an integer indicating the size of the vbo * @param {integer} bufferUsage - How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW * * @return {WebGLBuffer} Raw index buffer */ createIndexBuffer: function (initialDataOrSize, bufferUsage) { var gl = this.gl; var indexBuffer = gl.createBuffer(); this.setIndexBuffer(indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, initialDataOrSize, bufferUsage); this.setIndexBuffer(null); return indexBuffer; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#deleteTexture * @since 3.0.0 * * @param {WebGLTexture} texture - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ deleteTexture: function (texture) { var index = this.nativeTextures.indexOf(texture); if (index !== -1) { SpliceOne(this.nativeTextures, index); } this.gl.deleteTexture(texture); return this; }, /** * Wrapper for deleting a raw WebGLFramebuffer * * @method Phaser.Renderer.WebGL.WebGLRenderer#deleteFramebuffer * @since 3.0.0 * * @param {WebGLFramebuffer} framebuffer - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ deleteFramebuffer: function (framebuffer) { this.gl.deleteFramebuffer(framebuffer); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#deleteProgram * @since 3.0.0 * * @param {WebGLProgram} program - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ deleteProgram: function (program) { this.gl.deleteProgram(program); return this; }, /** * Wrapper for deleting a vertex or index buffer * * @method Phaser.Renderer.WebGL.WebGLRenderer#deleteBuffer * @since 3.0.0 * * @param {WebGLBuffer} vertexBuffer - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer. */ deleteBuffer: function (buffer) { this.gl.deleteBuffer(buffer); return this; }, /* Rendering Functions */ /** * Handles any clipping needed by the camera and renders the background * color if a color is visible. * * @method Phaser.Renderer.WebGL.WebGLRenderer#preRenderCamera * @since 3.0.0 * * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ preRenderCamera: function (camera) { var resolution = this.config.resolution; var cx = Math.floor(camera.x * resolution); var cy = Math.floor(camera.y * resolution); var cw = Math.floor(camera.width * resolution); var ch = Math.floor(camera.height * resolution); this.pushScissor(cx, cy, cw, ch); if (camera.backgroundColor.alphaGL > 0) { var color = camera.backgroundColor; var FlatTintPipeline = this.pipelines.FlatTintPipeline; FlatTintPipeline.batchFillRect( 0, 0, 1, 1, 0, camera.x, camera.y, camera.width, camera.height, Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1.0), color.alphaGL, 1, 0, 0, 1, 0, 0, [ 1, 0, 0, 1, 0, 0 ] ); FlatTintPipeline.flush(); } }, /** * Renders the foreground camera effects like flash and fading. * It resets the current scissor state. * * @method Phaser.Renderer.WebGL.WebGLRenderer#postRenderCamera * @since 3.0.0 * * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ postRenderCamera: function (camera) { var FlatTintPipeline = this.pipelines.FlatTintPipeline; var isFlashing = camera.flashEffect.postRenderWebGL(FlatTintPipeline, Utils.getTintFromFloats); var isFading = camera.fadeEffect.postRenderWebGL(FlatTintPipeline, Utils.getTintFromFloats); if (isFading || isFlashing) { FlatTintPipeline.flush(); } this.popScissor(); }, /** * Clears the current vertex buffer and updates pipelines. * * @method Phaser.Renderer.WebGL.WebGLRenderer#preRender * @since 3.0.0 */ preRender: function () { if (this.contextLost) { return; } var gl = this.gl; var color = this.config.backgroundColor; var pipelines = this.pipelines; // Bind custom framebuffer here gl.clearColor(color.redGL, color.greenGL, color.blueGL, color.alphaGL); if (this.config.clearBeforeRender) { gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT); } for (var key in pipelines) { pipelines[key].onPreRender(); } }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#render * @since 3.0.0 * * @param {Phaser.Scene} scene - [description] * @param {Phaser.GameObjects.GameObject} children - [description] * @param {number} interpolationPercentage - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ render: function (scene, children, interpolationPercentage, camera) { if (this.contextLost) { return; } var list = children.list; var childCount = list.length; var pipelines = this.pipelines; for (var key in pipelines) { pipelines[key].onRender(scene, camera); } this.preRenderCamera(camera); for (var index = 0; index < childCount; ++index) { var child = list[index]; if (!child.willRender()) { continue; } if (child.blendMode !== this.currentBlendMode) { this.setBlendMode(child.blendMode); } if (child.mask) { child.mask.preRenderWebGL(this, child, camera); } child.renderWebGL(this, child, interpolationPercentage, camera); if (child.mask) { child.mask.postRenderWebGL(this, child); } } this.flush(); this.setBlendMode(CONST.BlendModes.NORMAL); this.postRenderCamera(camera); }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#postRender * @since 3.0.0 */ postRender: function () { if (this.contextLost) { return; } // Unbind custom framebuffer here if (this.snapshotState.callback) { this.snapshotState.callback(WebGLSnapshot(this.canvas, this.snapshotState.type, this.snapshotState.encoder)); this.snapshotState.callback = null; } var pipelines = this.pipelines; for (var key in pipelines) { pipelines[key].onPostRender(); } }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#snapshot * @since 3.0.0 * * @param {SnapshotCallback} callback - [description] * @param {string} type - [description] * @param {float} encoderOptions - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ snapshot: function (callback, type, encoderOptions) { this.snapshotState.callback = callback; this.snapshotState.type = type; this.snapshotState.encoder = encoderOptions; return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#canvasToTexture * @since 3.0.0 * * @param {HTMLCanvasElement} srcCanvas - [description] * @param {WebGLTexture} [dstTexture] - [description] * * @return {WebGLTexture} [description] */ canvasToTexture: function (srcCanvas, dstTexture) { var gl = this.gl; if (!dstTexture) { var wrapping = gl.CLAMP_TO_EDGE; if (IsSizePowerOfTwo(srcCanvas.width, srcCanvas.height)) { wrapping = gl.REPEAT; } dstTexture = this.createTexture2D(0, gl.NEAREST, gl.NEAREST, wrapping, wrapping, gl.RGBA, srcCanvas, srcCanvas.width, srcCanvas.height, true); } else { this.setTexture2D(dstTexture, 0); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas); dstTexture.width = srcCanvas.width; dstTexture.height = srcCanvas.height; this.setTexture2D(null, 0); } return dstTexture; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setTextureFilter * @since 3.0.0 * * @param {integer} texture - [description] * @param {integer} filter - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setTextureFilter: function (texture, filter) { var gl = this.gl; var glFilter = [ gl.LINEAR, gl.NEAREST ][filter]; this.setTexture2D(texture, 0); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, glFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, glFilter); this.setTexture2D(null, 0); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat1 * @since 3.0.0 * * @param {WebGLProgram} program - [description] * @param {string} name - [description] * @param {float} x - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setFloat1: function (program, name, x) { this.setProgram(program); this.gl.uniform1f(this.gl.getUniformLocation(program, name), x); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat2 * @since 3.0.0 * * @param {WebGLProgram} program - [description] * @param {string} name - [description] * @param {float} x - [description] * @param {float} y - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setFloat2: function (program, name, x, y) { this.setProgram(program); this.gl.uniform2f(this.gl.getUniformLocation(program, name), x, y); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat3 * @since 3.0.0 * * @param {WebGLProgram} program - [description] * @param {string} name - [description] * @param {float} x - [description] * @param {float} y - [description] * @param {float} z - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setFloat3: function (program, name, x, y, z) { this.setProgram(program); this.gl.uniform3f(this.gl.getUniformLocation(program, name), x, y, z); return this; }, /** * Sets uniform of a WebGLProgram * * @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat4 * @since 3.0.0 * * @param {WebGLProgram} program - Target program * @param {string} name - Name of the uniform * @param {float} x - X component * @param {float} y - Y component * @param {float} z - Z component * @param {float} w - W component * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setFloat4: function (program, name, x, y, z, w) { this.setProgram(program); this.gl.uniform4f(this.gl.getUniformLocation(program, name), x, y, z, w); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setInt1 * @since 3.0.0 * * @param {WebGLProgram} program - [description] * @param {string} name - [description] * @param {integer} x - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setInt1: function (program, name, x) { this.setProgram(program); this.gl.uniform1i(this.gl.getUniformLocation(program, name), x); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setInt2 * @since 3.0.0 * * @param {WebGLProgram} program - [description] * @param {string} name - [description] * @param {integer} x - [description] * @param {integer} y - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setInt2: function (program, name, x, y) { this.setProgram(program); this.gl.uniform2i(this.gl.getUniformLocation(program, name), x, y); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setInt3 * @since 3.0.0 * * @param {WebGLProgram} program - [description] * @param {string} name - [description] * @param {integer} x - [description] * @param {integer} y - [description] * @param {integer} z - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setInt3: function (program, name, x, y, z) { this.setProgram(program); this.gl.uniform3i(this.gl.getUniformLocation(program, name), x, y, z); return this; }, /** * Sets uniform of a WebGLProgram * * @method Phaser.Renderer.WebGL.WebGLRenderer#setInt4 * @since 3.0.0 * * @param {WebGLProgram} program - Target Program * @param {string} name - Name of the uniform * @param {integer} x - X component * @param {integer} y - Y component * @param {integer} z - Z component * @param {integer} w - W component * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setInt4: function (program, name, x, y, z, w) { this.setProgram(program); this.gl.uniform4i(this.gl.getUniformLocation(program, name), x, y, z, w); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setMatrix2 * @since 3.0.0 * * @param {WebGLProgram} program - [description] * @param {string} name - [description] * @param {boolean} transpose - [description] * @param {Float32Array} matrix - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setMatrix2: function (program, name, transpose, matrix) { this.setProgram(program); this.gl.uniformMatrix2fv(this.gl.getUniformLocation(program, name), transpose, matrix); return this; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#setMatrix3 * @since 3.0.0 * * @param {WebGLProgram} program - [description] * @param {string} name - [description] * @param {boolean} transpose - [description] * @param {Float32Array} matrix - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setMatrix3: function (program, name, transpose, matrix) { this.setProgram(program); this.gl.uniformMatrix3fv(this.gl.getUniformLocation(program, name), transpose, matrix); return this; }, /** * Sets uniform of a WebGLProgram * * @method Phaser.Renderer.WebGL.WebGLRenderer#setMatrix4 * @since 3.0.0 * * @param {WebGLProgram} program - Target program * @param {string} name - Name of the uniform * @param {boolean} transpose - Is the matrix transposed * @param {Float32Array} matrix - Matrix data * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] */ setMatrix4: function (program, name, transpose, matrix) { this.setProgram(program); this.gl.uniformMatrix4fv(this.gl.getUniformLocation(program, name), transpose, matrix); return this; }, /** * Returns the maximum number of texture units that can be used in a fragment shader. * * @method Phaser.Renderer.WebGL.WebGLRenderer#getMaxTextures * @since 3.8.0 * * @return {integer} The maximum number of textures WebGL supports. */ getMaxTextures: function () { return this.config.maxTextures; }, /** * Returns the largest texture size (either width or height) that can be created. * Note that VRAM may not allow a texture of any given size, it just expresses * hardware / driver support for a given size. * * @method Phaser.Renderer.WebGL.WebGLRenderer#getMaxTextureSize * @since 3.8.0 * * @return {integer} ... */ getMaxTextureSize: function () { return this.config.maxTextureSize; }, /** * [description] * * @method Phaser.Renderer.WebGL.WebGLRenderer#destroy * @since 3.0.0 */ destroy: function () { // Clear-up anything that should be cleared :) for (var key in this.pipelines) { this.pipelines[key].destroy(); delete this.pipelines[key]; } for (var index = 0; index < this.nativeTextures.length; ++index) { this.deleteTexture(this.nativeTextures[index]); delete this.nativeTextures[index]; } delete this.gl; delete this.game; this.contextLost = true; this.extensions = {}; this.nativeTextures.length = 0; } }); module.exports = WebGLRenderer; /***/ }), /* 263 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var modes = __webpack_require__(51); var CanvasFeatures = __webpack_require__(203); /** * [description] * * @function Phaser.Renderer.Canvas.GetBlendModes * @since 3.0.0 * * @return {array} [description] */ var GetBlendModes = function () { var output = []; var useNew = CanvasFeatures.supportNewBlendModes; output[modes.NORMAL] = 'source-over'; output[modes.ADD] = 'lighter'; output[modes.MULTIPLY] = (useNew) ? 'multiply' : 'source-over'; output[modes.SCREEN] = (useNew) ? 'screen' : 'source-over'; output[modes.OVERLAY] = (useNew) ? 'overlay' : 'source-over'; output[modes.DARKEN] = (useNew) ? 'darken' : 'source-over'; output[modes.LIGHTEN] = (useNew) ? 'lighten' : 'source-over'; output[modes.COLOR_DODGE] = (useNew) ? 'color-dodge' : 'source-over'; output[modes.COLOR_BURN] = (useNew) ? 'color-burn' : 'source-over'; output[modes.HARD_LIGHT] = (useNew) ? 'hard-light' : 'source-over'; output[modes.SOFT_LIGHT] = (useNew) ? 'soft-light' : 'source-over'; output[modes.DIFFERENCE] = (useNew) ? 'difference' : 'source-over'; output[modes.EXCLUSION] = (useNew) ? 'exclusion' : 'source-over'; output[modes.HUE] = (useNew) ? 'hue' : 'source-over'; output[modes.SATURATION] = (useNew) ? 'saturation' : 'source-over'; output[modes.COLOR] = (useNew) ? 'color' : 'source-over'; output[modes.LUMINOSITY] = (useNew) ? 'luminosity' : 'source-over'; return output; }; module.exports = GetBlendModes; /***/ }), /* 264 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var roundPixels = false; /** * [description] * * @function Phaser.Renderer.Canvas.DrawImage * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} src - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - [description] */ var DrawImage = function (src, camera, parentMatrix) { var ctx = this.currentContext; var frame = src.frame; var cd = frame.canvasData; // Blend Mode if (this.currentBlendMode !== src.blendMode) { this.currentBlendMode = src.blendMode; ctx.globalCompositeOperation = this.blendModes[src.blendMode]; } // Alpha if (this.currentAlpha !== src.alpha) { this.currentAlpha = src.alpha; ctx.globalAlpha = src.alpha; } // Smoothing if (this.currentScaleMode !== src.scaleMode) { this.currentScaleMode = src.scaleMode; // ctx[this.smoothProperty] = (source.scaleMode === ScaleModes.LINEAR); } var dx = frame.x; var dy = frame.y; var fx = 1; var fy = 1; if (src.flipX) { fx = -1; dx -= cd.dWidth - src.displayOriginX; } else { dx -= src.displayOriginX; } if (src.flipY) { fy = -1; dy -= cd.dHeight - src.displayOriginY; } else { dy -= src.displayOriginY; } var tx = src.x - camera.scrollX * src.scrollFactorX; var ty = src.y - camera.scrollY * src.scrollFactorY; if (roundPixels) { tx |= 0; ty |= 0; dx |= 0; dy |= 0; } // Perform Matrix ITRS ctx.save(); if (parentMatrix) { var matrix = parentMatrix.matrix; ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); } ctx.translate(tx, ty); ctx.rotate(src.rotation); ctx.scale(src.scaleX, src.scaleY); ctx.scale(fx, fy); ctx.drawImage(frame.source.image, cd.sx, cd.sy, cd.sWidth, cd.sHeight, dx, dy, cd.dWidth, cd.dHeight); ctx.restore(); }; // Special return so we can store the config value locally module.exports = function (configRoundPixels) { roundPixels = configRoundPixels; return DrawImage; }; /***/ }), /* 265 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Renderer.Snapshot.Canvas * @since 3.0.0 * * @param {HTMLCanvasElement} canvas - [description] * @param {string} [type='image/png'] - [description] * @param {float} [encoderOptions=0.92] - [description] * * @return {HTMLImageElement} [description] */ var CanvasSnapshot = function (canvas, type, encoderOptions) { if (type === undefined) { type = 'image/png'; } if (encoderOptions === undefined) { encoderOptions = 0.92; } var src = canvas.toDataURL(type, encoderOptions); var image = new Image(); image.src = src; return image; }; module.exports = CanvasSnapshot; /***/ }), /* 266 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var roundPixels = false; /** * No scaling, anchor, rotation or effects, literally draws the frame directly to the canvas. * * @function Phaser.Renderer.Canvas.BlitImage * @since 3.0.0 * * @param {number} dx - The x coordinate to render the Frame to. * @param {number} dy - The y coordinate to render the Frame to. * @param {Phaser.Textures.Frame} frame - The Frame to render. */ var BlitImage = function (dx, dy, frame) { var ctx = this.currentContext; var cd = frame.canvasData; if (roundPixels) { dx |= 0; dy |= 0; } ctx.drawImage( frame.source.image, cd.sx, cd.sy, cd.sWidth, cd.sHeight, dx, dy, cd.dWidth, cd.dHeight ); }; // Special return so we can store the config value locally module.exports = function (configRoundPixels) { roundPixels = configRoundPixels; return BlitImage; }; /***/ }), /* 267 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Felipe Alfonso <@bitnenfer> * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BlitImage = __webpack_require__(266); var CanvasSnapshot = __webpack_require__(265); var Class = __webpack_require__(0); var CONST = __webpack_require__(20); var DrawImage = __webpack_require__(264); var GetBlendModes = __webpack_require__(263); var ScaleModes = __webpack_require__(59); var Smoothing = __webpack_require__(131); /** * @classdesc * [description] * * @class CanvasRenderer * @memberOf Phaser.Renderer.Canvas * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - The Phaser Game instance that owns this renderer. */ var CanvasRenderer = new Class({ initialize: function CanvasRenderer (game) { /** * The Phaser Game instance that owns this renderer. * * @name Phaser.Renderer.Canvas.CanvasRenderer#game * @type {Phaser.Game} * @since 3.0.0 */ this.game = game; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#type * @type {integer} * @since 3.0.0 */ this.type = CONST.CANVAS; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#drawCount * @type {number} * @default 0 * @since 3.0.0 */ this.drawCount = 0; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#width * @type {number} * @since 3.0.0 */ this.width = game.config.width; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#height * @type {number} * @since 3.0.0 */ this.height = game.config.height; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#config * @type {RendererConfig} * @since 3.0.0 */ this.config = { clearBeforeRender: game.config.clearBeforeRender, pixelArt: game.config.pixelArt, backgroundColor: game.config.backgroundColor, resolution: game.config.resolution, autoResize: game.config.autoResize, roundPixels: game.config.roundPixels }; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#scaleMode * @type {integer} * @since 3.0.0 */ this.scaleMode = (game.config.pixelArt) ? ScaleModes.NEAREST : ScaleModes.LINEAR; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#gameCanvas * @type {HTMLCanvasElement} * @since 3.0.0 */ this.gameCanvas = game.canvas; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#gameContext * @type {CanvasRenderingContext2D} * @since 3.0.0 */ this.gameContext = (this.game.config.context) ? this.game.config.context : this.gameCanvas.getContext('2d'); /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#currentContext * @type {CanvasRenderingContext2D} * @since 3.0.0 */ this.currentContext = this.gameContext; /** * Map to the required function. * * @name Phaser.Renderer.Canvas.CanvasRenderer#drawImage * @type {function} * @since 3.0.0 */ this.drawImage = DrawImage(this.config.roundPixels); /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#blitImage * @type {function} * @since 3.0.0 */ this.blitImage = BlitImage(this.config.roundPixels); /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#blendModes * @type {array} * @since 3.0.0 */ this.blendModes = GetBlendModes(); /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#currentAlpha * @type {number} * @default 1 * @since 3.0.0 */ this.currentAlpha = 1; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#currentBlendMode * @type {number} * @default 0 * @since 3.0.0 */ this.currentBlendMode = 0; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#currentScaleMode * @type {number} * @default 0 * @since 3.0.0 */ this.currentScaleMode = 0; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#snapshotCallback * @type {?SnapshotCallback} * @default null * @since 3.0.0 */ this.snapshotCallback = null; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#snapshotType * @type {?string} * @default null * @since 3.0.0 */ this.snapshotType = null; /** * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#snapshotEncoder * @type {?number} * @default null * @since 3.0.0 */ this.snapshotEncoder = null; this.init(); }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#init * @since 3.0.0 */ init: function () { this.resize(this.width, this.height); }, /** * Resize the main game canvas. * * @method Phaser.Renderer.Canvas.CanvasRenderer#resize * @since 3.0.0 * * @param {integer} width - [description] * @param {integer} height - [description] */ resize: function (width, height) { var resolution = this.config.resolution; this.width = width * resolution; this.height = height * resolution; this.gameCanvas.width = this.width; this.gameCanvas.height = this.height; if (this.config.autoResize) { this.gameCanvas.style.width = (this.width / resolution) + 'px'; this.gameCanvas.style.height = (this.height / resolution) + 'px'; } // Resizing a canvas will reset imageSmoothingEnabled (and probably other properties) if (this.scaleMode === ScaleModes.NEAREST) { Smoothing.disable(this.gameContext); } }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#onContextLost * @since 3.0.0 * * @param {function} callback - [description] */ onContextLost: function () { }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#onContextRestored * @since 3.0.0 * * @param {function} callback - [description] */ onContextRestored: function () { }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#resetTransform * @since 3.0.0 */ resetTransform: function () { this.currentContext.setTransform(1, 0, 0, 1, 0, 0); }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#setBlendMode * @since 3.0.0 * * @param {number} blendMode - [description] * * @return {number} [description] */ setBlendMode: function (blendMode) { if (this.currentBlendMode !== blendMode) { this.currentContext.globalCompositeOperation = blendMode; this.currentBlendMode = blendMode; } return this.currentBlendMode; }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#setAlpha * @since 3.0.0 * * @param {float} alpha - [description] * * @return {float} [description] */ setAlpha: function (alpha) { if (this.currentAlpha !== alpha) { this.currentContext.globalAlpha = alpha; this.currentAlpha = alpha; } return this.currentAlpha; }, /** * Called at the start of the render loop. * * @method Phaser.Renderer.Canvas.CanvasRenderer#preRender * @since 3.0.0 */ preRender: function () { var ctx = this.gameContext; var config = this.config; var width = this.width; var height = this.height; if (config.clearBeforeRender) { ctx.clearRect(0, 0, width, height); } if (!config.transparent) { ctx.fillStyle = config.backgroundColor.rgba; ctx.fillRect(0, 0, width, height); } this.drawCount = 0; }, /** * Renders the Scene to the given Camera. * * @method Phaser.Renderer.Canvas.CanvasRenderer#render * @since 3.0.0 * * @param {Phaser.Scene} scene - [description] * @param {Phaser.GameObjects.DisplayList} children - [description] * @param {float} interpolationPercentage - [description] * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ render: function (scene, children, interpolationPercentage, camera) { var ctx = scene.sys.context; var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height); var list = children.list; var resolution = this.config.resolution; this.currentContext = ctx; // If the alpha or blend mode didn't change since the last render, then don't set them again (saves 2 ops) if (!camera.transparent) { ctx.fillStyle = camera.backgroundColor.rgba; ctx.fillRect(camera.x, camera.y, camera.width, camera.height); } if (this.currentAlpha !== 1) { ctx.globalAlpha = 1; this.currentAlpha = 1; } if (this.currentBlendMode !== 0) { ctx.globalCompositeOperation = 'source-over'; this.currentBlendMode = 0; } this.currentScaleMode = 0; this.drawCount += list.length; if (scissor) { ctx.save(); ctx.beginPath(); ctx.rect(camera.x * resolution, camera.y * resolution, camera.width * resolution, camera.height * resolution); ctx.clip(); } var matrix = camera.matrix.matrix; ctx.setTransform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); for (var c = 0; c < list.length; c++) { var child = list[c]; if (child.mask) { child.mask.preRenderCanvas(this, child, camera); } child.renderCanvas(this, child, interpolationPercentage, camera); if (child.mask) { child.mask.postRenderCanvas(this, child, camera); } } ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalCompositeOperation = 'source-over'; camera.flashEffect.postRenderCanvas(ctx); camera.fadeEffect.postRenderCanvas(ctx); // Reset the camera scissor if (scissor) { ctx.restore(); } }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#postRender * @since 3.0.0 */ postRender: function () { var ctx = this.gameContext; ctx.globalAlpha = 1; ctx.globalCompositeOperation = 'source-over'; this.currentAlpha = 1; this.currentBlendMode = 0; if (this.snapshotCallback) { this.snapshotCallback(CanvasSnapshot(this.gameCanvas, this.snapshotType, this.snapshotEncoder)); this.snapshotCallback = null; } }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#snapshot * @since 3.0.0 * * @param {SnapshotCallback} callback - [description] * @param {string} type - [description] * @param {number} encoderOptions - [description] */ snapshot: function (callback, type, encoderOptions) { this.snapshotCallback = callback; this.snapshotType = type; this.snapshotEncoder = encoderOptions; }, /** * [description] * * @method Phaser.Renderer.Canvas.CanvasRenderer#destroy * @since 3.0.0 */ destroy: function () { this.gameCanvas = null; this.gameContext = null; this.game = null; } }); module.exports = CanvasRenderer; /***/ }), /* 268 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var NOOP = __webpack_require__(3); /** * @classdesc * Abstracts away the use of RAF or setTimeOut for the core game update loop. * This is invoked automatically by the Phaser.Game instance. * * @class RequestAnimationFrame * @memberOf Phaser.DOM * @constructor * @since 3.0.0 */ var RequestAnimationFrame = new Class({ initialize: function RequestAnimationFrame () { /** * True if RequestAnimationFrame is running, otherwise false. * * @name Phaser.DOM.RequestAnimationFrame#isRunning * @type {boolean} * @default false * @since 3.0.0 */ this.isRunning = false; /** * The callback to be invoked each step. * * @name Phaser.DOM.RequestAnimationFrame#callback * @type {FrameRequestCallback} * @since 3.0.0 */ this.callback = NOOP; /** * The most recent timestamp. Either a DOMHighResTimeStamp under RAF or `Date.now` under SetTimeout. * * @name Phaser.DOM.RequestAnimationFrame#tick * @type {number} * @default 0 * @since 3.0.0 */ this.tick = 0; /** * True if the step is using setTimeout instead of RAF. * * @name Phaser.DOM.RequestAnimationFrame#isSetTimeOut * @type {boolean} * @default false * @since 3.0.0 */ this.isSetTimeOut = false; /** * The setTimeout or RAF callback ID used when canceling them. * * @name Phaser.DOM.RequestAnimationFrame#timeOutID * @type {?number} * @default null * @since 3.0.0 */ this.timeOutID = null; /** * The previous time the step was called. * * @name Phaser.DOM.RequestAnimationFrame#lastTime * @type {number} * @default 0 * @since 3.0.0 */ this.lastTime = 0; var _this = this; /** * The RAF step function. * Updates the local tick value, invokes the callback and schedules another call to requestAnimationFrame. * * @name Phaser.DOM.RequestAnimationFrame#step * @type {FrameRequestCallback} * @since 3.0.0 */ this.step = function step (timestamp) { // DOMHighResTimeStamp _this.lastTime = _this.tick; _this.tick = timestamp; _this.callback(timestamp); _this.timeOutID = window.requestAnimationFrame(step); }; /** * The SetTimeout step function. * Updates the local tick value, invokes the callback and schedules another call to setTimeout. * * @name Phaser.DOM.RequestAnimationFrame#stepTimeout * @type {function} * @since 3.0.0 */ this.stepTimeout = function stepTimeout () { var d = Date.now(); var delay = Math.max(16 + _this.lastTime - d, 0); _this.lastTime = _this.tick; _this.tick = d; _this.callback(d); _this.timeOutID = window.setTimeout(stepTimeout, delay); }; }, /** * Starts the requestAnimationFrame or setTimeout process running. * * @method Phaser.DOM.RequestAnimationFrame#start * @since 3.0.0 * * @param {FrameRequestCallback} callback - The callback to invoke each step. * @param {boolean} forceSetTimeOut - Should it use SetTimeout, even if RAF is available? */ start: function (callback, forceSetTimeOut) { if (this.isRunning) { return; } this.callback = callback; this.isSetTimeOut = forceSetTimeOut; this.isRunning = true; this.timeOutID = (forceSetTimeOut) ? window.setTimeout(this.stepTimeout, 0) : window.requestAnimationFrame(this.step); }, /** * Stops the requestAnimationFrame or setTimeout from running. * * @method Phaser.DOM.RequestAnimationFrame#stop * @since 3.0.0 */ stop: function () { this.isRunning = false; if (this.isSetTimeOut) { clearTimeout(this.timeOutID); } else { window.cancelAnimationFrame(this.timeOutID); } }, /** * Stops the step from running and clears the callback reference. * * @method Phaser.DOM.RequestAnimationFrame#destroy * @since 3.0.0 */ destroy: function () { this.stop(); this.callback = NOOP; } }); module.exports = RequestAnimationFrame; /***/ }), /* 269 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Attempts to remove the element from its parentNode in the DOM. * * @function Phaser.DOM.RemoveFromDOM * @since 3.0.0 * * @param {HTMLElement} element - The DOM element to remove from its parent node. */ var RemoveFromDOM = function (element) { if (element.parentNode) { element.parentNode.removeChild(element); } }; module.exports = RemoveFromDOM; /***/ }), /* 270 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Takes the given data string and parses it as XML. * First tries to use the window.DOMParser and reverts to the Microsoft.XMLDOM if that fails. * The parsed XML object is returned, or `null` if there was an error while parsing the data. * * @function Phaser.DOM.ParseXML * @since 3.0.0 * * @param {string} data - The XML source stored in a string. * * @return {?(DOMParser|ActiveXObject)} The parsed XML data, or `null` if the data could not be parsed. */ var ParseXML = function (data) { var xml = ''; try { if (window['DOMParser']) { var domparser = new DOMParser(); xml = domparser.parseFromString(data, 'text/xml'); } else { xml = new ActiveXObject('Microsoft.XMLDOM'); xml.loadXML(data); } } catch (e) { xml = null; } if (!xml || !xml.documentElement || xml.getElementsByTagName('parsererror').length) { return null; } else { return xml; } }; module.exports = ParseXML; /***/ }), /* 271 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var OS = __webpack_require__(57); /** * @callback ContentLoadedCallback */ /** * Inspects the readyState of the document. If the document is already complete then it invokes the given callback. * If not complete it sets up several event listeners such as `deviceready`, and once those fire, it invokes the callback. * Called automatically by the Phaser.Game instance. Should not usually be accessed directly. * * @function Phaser.DOM.DOMContentLoaded * @since 3.0.0 * * @param {ContentLoadedCallback} callback - The callback to be invoked when the device is ready and the DOM content is loaded. */ var DOMContentLoaded = function (callback) { if (document.readyState === 'complete' || document.readyState === 'interactive') { callback(); return; } var check = function () { document.removeEventListener('deviceready', check, true); document.removeEventListener('DOMContentLoaded', check, true); window.removeEventListener('load', check, true); callback(); }; if (!document.body) { window.setTimeout(check, 20); } else if (OS.cordova && !OS.cocoonJS) { // Ref. http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html#deviceready document.addEventListener('deviceready', check, false); } else { document.addEventListener('DOMContentLoaded', check, true); window.addEventListener('load', check, true); } }; module.exports = DOMContentLoaded; /***/ }), /* 272 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Display.Canvas.CanvasInterpolation * @since 3.0.0 */ var CanvasInterpolation = { /** * Sets the CSS image-rendering property on the given canvas to be 'crisp' (aka 'optimize contrast' on webkit). * * @function Phaser.Display.Canvas.CanvasInterpolation.setCrisp * @since 3.0.0 * * @param {HTMLCanvasElement} canvas - The canvas object to have the style set on. * * @return {HTMLCanvasElement} The canvas. */ setCrisp: function (canvas) { var types = [ 'optimizeSpeed', 'crisp-edges', '-moz-crisp-edges', '-webkit-optimize-contrast', 'optimize-contrast', 'pixelated' ]; types.forEach(function (type) { canvas.style['image-rendering'] = type; }); canvas.style.msInterpolationMode = 'nearest-neighbor'; return canvas; }, /** * Sets the CSS image-rendering property on the given canvas to be 'bicubic' (aka 'auto'). * * @function Phaser.Display.Canvas.CanvasInterpolation.setBicubic * @since 3.0.0 * * @param {HTMLCanvasElement} canvas - The canvas object to have the style set on. * * @return {HTMLCanvasElement} The canvas. */ setBicubic: function (canvas) { canvas.style['image-rendering'] = 'auto'; canvas.style.msInterpolationMode = 'bicubic'; return canvas; } }; module.exports = CanvasInterpolation; /***/ }), /* 273 */, /* 274 */, /* 275 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * A 16 color palette by [Arne](http://androidarts.com/palette/16pal.htm) * * @name Phaser.Create.Palettes.ARNE16 * @since 3.0.0 * * @type {Palette} */ module.exports = { 0: '#000', 1: '#9D9D9D', 2: '#FFF', 3: '#BE2633', 4: '#E06F8B', 5: '#493C2B', 6: '#A46422', 7: '#EB8931', 8: '#F7E26B', 9: '#2F484E', A: '#44891A', B: '#A3CE27', C: '#1B2632', D: '#005784', E: '#31A2F2', F: '#B2DCEF' }; /***/ }), /* 276 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Arne16 = __webpack_require__(275); var CanvasPool = __webpack_require__(22); var GetValue = __webpack_require__(4); /** * @callback GenerateTextureRendererCallback * * @param {HTMLCanvasElement} canvas - [description] * @param {CanvasRenderingContext2D} context - [description] */ /** * @typedef {object} GenerateTextureConfig * * @property {array} [data=[]] - [description] * @property {HTMLCanvasElement} [canvas=null] - [description] * @property {Palette} [palette=Arne16] - [description] * @property {number} [pixelWidth=1] - [description] * @property {number} [pixelHeight=1] - [description] * @property {boolean} [resizeCanvas=true] - [description] * @property {boolean} [clearCanvas=true] - [description] * @property {GenerateTextureRendererCallback} [preRender] - [description] * @property {GenerateTextureRendererCallback} [postRender] - [description] */ /** * [description] * * @function Phaser.Create.GenerateTexture * @since 3.0.0 * * @param {GenerateTextureConfig} config - [description] * * @return {HTMLCanvasElement} [description] */ var GenerateTexture = function (config) { var data = GetValue(config, 'data', []); var canvas = GetValue(config, 'canvas', null); var palette = GetValue(config, 'palette', Arne16); var pixelWidth = GetValue(config, 'pixelWidth', 1); var pixelHeight = GetValue(config, 'pixelHeight', pixelWidth); var resizeCanvas = GetValue(config, 'resizeCanvas', true); var clearCanvas = GetValue(config, 'clearCanvas', true); var preRender = GetValue(config, 'preRender', null); var postRender = GetValue(config, 'postRender', null); var width = Math.floor(Math.abs(data[0].length * pixelWidth)); var height = Math.floor(Math.abs(data.length * pixelHeight)); if (!canvas) { canvas = CanvasPool.create2D(this, width, height); resizeCanvas = false; clearCanvas = false; } if (resizeCanvas) { canvas.width = width; canvas.height = height; } var ctx = canvas.getContext('2d'); if (clearCanvas) { ctx.clearRect(0, 0, width, height); } // preRender Callback? if (preRender) { preRender(canvas, ctx); } // Draw it for (var y = 0; y < data.length; y++) { var row = data[y]; for (var x = 0; x < row.length; x++) { var d = row[x]; if (d !== '.' && d !== ' ') { ctx.fillStyle = palette[d]; ctx.fillRect(x * pixelWidth, y * pixelHeight, pixelWidth, pixelHeight); } } } // postRender Callback? if (postRender) { postRender(canvas, ctx); } return canvas; }; module.exports = GenerateTexture; /***/ }), /* 277 */, /* 278 */, /* 279 */, /* 280 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Color = __webpack_require__(30); /** * Converts a CSS 'web' string into a Phaser Color object. * * The web string can be in the format `'rgb(r,g,b)'` or `'rgba(r,g,b,a)'` where r/g/b are in the range [0..255] and a is in the range [0..1]. * * @function Phaser.Display.Color.RGBStringToColor * @since 3.0.0 * * @param {string} rgb - The CSS format color string, using the `rgb` or `rgba` format. * * @return {Phaser.Display.Color} A Color object. */ var RGBStringToColor = function (rgb) { var color = new Color(); var result = (/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+(?:\.\d+)?))?\s*\)$/).exec(rgb.toLowerCase()); if (result) { var r = parseInt(result[1], 10); var g = parseInt(result[2], 10); var b = parseInt(result[3], 10); var a = (result[4] !== undefined) ? parseFloat(result[4]) : 1; color.setTo(r, g, b, a * 255); } return color; }; module.exports = RGBStringToColor; /***/ }), /* 281 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Color = __webpack_require__(30); /** * Converts an object containing `r`, `g`, `b` and `a` properties into a Color class instance. * * @function Phaser.Display.Color.ObjectToColor * @since 3.0.0 * * @param {InputColorObject} input - An object containing `r`, `g`, `b` and `a` properties in the range 0 to 255. * * @return {Phaser.Display.Color} A Color object. */ var ObjectToColor = function (input) { return new Color(input.r, input.g, input.b, input.a); }; module.exports = ObjectToColor; /***/ }), /* 282 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Return the component parts of a color as an Object with the properties alpha, red, green, blue. * * Alpha will only be set if it exists in the given color (0xAARRGGBB) * * @function Phaser.Display.Color.IntegerToRGB * @since 3.0.0 * * @param {integer} input - The color value to convert into a Color object. * * @return {ColorObject} An object with the red, green and blue values set in the r, g and b properties. */ var IntegerToRGB = function (color) { if (color > 16777215) { // The color value has an alpha component return { a: color >>> 24, r: color >> 16 & 0xFF, g: color >> 8 & 0xFF, b: color & 0xFF }; } else { return { a: 255, r: color >> 16 & 0xFF, g: color >> 8 & 0xFF, b: color & 0xFF }; } }; module.exports = IntegerToRGB; /***/ }), /* 283 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Color = __webpack_require__(30); var IntegerToRGB = __webpack_require__(282); /** * Converts the given color value into an instance of a Color object. * * @function Phaser.Display.Color.IntegerToColor * @since 3.0.0 * * @param {integer} input - The color value to convert into a Color object. * * @return {Phaser.Display.Color} A Color object. */ var IntegerToColor = function (input) { var rgb = IntegerToRGB(input); return new Color(rgb.r, rgb.g, rgb.b, rgb.a); }; module.exports = IntegerToColor; /***/ }), /* 284 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Given an alpha and 3 color values this will return an integer representation of it. * * @function Phaser.Display.Color.GetColor32 * @since 3.0.0 * * @param {integer} red - The red color value. A number between 0 and 255. * @param {integer} green - The green color value. A number between 0 and 255. * @param {integer} blue - The blue color value. A number between 0 and 255. * @param {integer} alpha - The alpha color value. A number between 0 and 255. * * @return {number} The combined color value. */ var GetColor32 = function (red, green, blue, alpha) { return alpha << 24 | red << 16 | green << 8 | blue; }; module.exports = GetColor32; /***/ }), /* 285 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Color = __webpack_require__(30); /** * Converts a hex string into a Phaser Color object. * * The hex string can supplied as `'#0033ff'` or the short-hand format of `'#03f'`; it can begin with an optional "#" or "0x", or be unprefixed. * * An alpha channel is _not_ supported. * * @function Phaser.Display.Color.HexStringToColor * @since 3.0.0 * * @param {string} hex - The hex color value to convert, such as `#0033ff` or the short-hand format: `#03f`. * * @return {Phaser.Display.Color} A Color object populated by the values of the given string. */ var HexStringToColor = function (hex) { var color = new Color(); // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") hex = hex.replace(/^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) { return r + r + g + g + b + b; }); var result = (/^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i).exec(hex); if (result) { var r = parseInt(result[1], 16); var g = parseInt(result[2], 16); var b = parseInt(result[3], 16); color.setTo(r, g, b); } return color; }; module.exports = HexStringToColor; /***/ }), /* 286 */, /* 287 */, /* 288 */, /* 289 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Moves the element at the end of the array to the start, shifting all items in the process. * The "rotation" happens to the right. * * @function Phaser.Utils.Array.RotateRight * @since 3.0.0 * * @param {array} array - The array to shift to the right. This array is modified in place. * @param {integer} [total=1] - The number of times to shift the array. * * @return {*} The most recently shifted element. */ var RotateRight = function (array, total) { if (total === undefined) { total = 1; } var element = null; for (var i = 0; i < total; i++) { element = array.pop(); array.unshift(element); } return element; }; module.exports = RotateRight; /***/ }), /* 290 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Moves the element at the start of the array to the end, shifting all items in the process. * The "rotation" happens to the left. * * @function Phaser.Utils.Array.RotateLeft * @since 3.0.0 * * @param {array} array - The array to shift to the left. This array is modified in place. * @param {integer} [total=1] - The number of times to shift the array. * * @return {*} The most recently shifted element. */ var RotateLeft = function (array, total) { if (total === undefined) { total = 1; } var element = null; for (var i = 0; i < total; i++) { element = array.shift(); array.push(element); } return element; }; module.exports = RotateLeft; /***/ }), /* 291 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Provides methods used for setting the WebGL rendering pipeline of a Game Object. * * @name Phaser.GameObjects.Components.Pipeline * @webglOnly * @since 3.0.0 */ var Pipeline = { /** * The initial WebGL pipeline of this Game Object. * * @name Phaser.GameObjects.Components.Pipeline#defaultPipeline * @type {Phaser.Renderer.WebGL.WebGLPipeline} * @default null * @webglOnly * @since 3.0.0 */ defaultPipeline: null, /** * The current WebGL pipeline of this Game Object. * * @name Phaser.GameObjects.Components.Pipeline#pipeline * @type {Phaser.Renderer.WebGL.WebGLPipeline} * @default null * @webglOnly * @since 3.0.0 */ pipeline: null, /** * Sets the initial WebGL Pipeline of this Game Object. * This should only be called during the instantiation of the Game Object. * * @method Phaser.GameObjects.Components.Pipeline#initPipeline * @webglOnly * @since 3.0.0 * * @param {string} pipelineName - The name of the pipeline to set on this Game Object. * * @return {boolean} `true` if the pipeline was set successfully, otherwise `false`. */ initPipeline: function (pipelineName) { var renderer = this.scene.sys.game.renderer; if (renderer && renderer.gl && renderer.hasPipeline(pipelineName)) { this.defaultPipeline = renderer.getPipeline(pipelineName); this.pipeline = this.defaultPipeline; return true; } return false; }, /** * Sets the active WebGL Pipeline of this Game Object. * * @method Phaser.GameObjects.Components.Pipeline#setPipeline * @webglOnly * @since 3.0.0 * * @param {string} pipelineName - The name of the pipeline to set on this Game Object. * * @return {boolean} `true` if the pipeline was set successfully, otherwise `false`. */ setPipeline: function (pipelineName) { var renderer = this.scene.sys.game.renderer; if (renderer && renderer.gl && renderer.hasPipeline(pipelineName)) { this.pipeline = renderer.getPipeline(pipelineName); return true; } return false; }, /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. * * @method Phaser.GameObjects.Components.Pipeline#resetPipeline * @webglOnly * @since 3.0.0 * * @return {boolean} `true` if the pipeline was set successfully, otherwise `false`. */ resetPipeline: function () { this.pipeline = this.defaultPipeline; return (this.pipeline !== null); }, /** * Gets the name of the WebGL Pipeline this Game Object is currently using. * * @method Phaser.GameObjects.Components.Pipeline#getPipelineName * @webglOnly * @since 3.0.0 * * @return {string} The string-based name of the pipeline being used by this Game Object. */ getPipelineName: function () { return this.pipeline.name; } }; module.exports = Pipeline; /***/ }), /* 292 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Rotate a `point` around `x` and `y` by the given `angle`. * * @function Phaser.Math.RotateAround * @since 3.0.0 * * @param {(Phaser.Geom.Point|object)} point - The point to be rotated. * @param {number} x - The horizontal coordinate to rotate around. * @param {number} y - The vertical coordinate to rotate around. * @param {number} angle - The angle of rotation in radians. * * @return {Phaser.Geom.Point} The given point, rotated by the given angle around the given coordinates. */ var RotateAround = function (point, x, y, angle) { var c = Math.cos(angle); var s = Math.sin(angle); var tx = point.x - x; var ty = point.y - y; point.x = tx * c - ty * s + x; point.y = tx * s + ty * c + y; return point; }; module.exports = RotateAround; /***/ }), /* 293 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Point = __webpack_require__(5); // Get a point on the given line 'progress' percentage along its length. // progress is a value between 0 and 1. /** * [description] * * @function Phaser.Geom.Line.GetPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Line} line - [description] * @param {float} position - A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle. * @param {(Phaser.Geom.Point|object)} [out] - [description] * * @return {(Phaser.Geom.Point|object)} [description] */ var GetPoint = function (line, position, out) { if (out === undefined) { out = new Point(); } out.x = line.x1 + (line.x2 - line.x1) * position; out.y = line.y1 + (line.y2 - line.y1) * position; return out; }; module.exports = GetPoint; /***/ }), /* 294 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetPoint = __webpack_require__(135); var Perimeter = __webpack_require__(97); // Return an array of points from the perimeter of the rectangle // each spaced out based on the quantity or step required /** * [description] * * @function Phaser.Geom.Rectangle.GetPoints * @since 3.0.0 * * @generic {Phaser.Geom.Point[]} O - [out,$return] * * @param {Phaser.Geom.Rectangle} rectangle - [description] * @param {number} step - [description] * @param {integer} quantity - [description] * @param {(array|Phaser.Geom.Point[])} [out] - [description] * * @return {(array|Phaser.Geom.Point[])} [description] */ var GetPoints = function (rectangle, quantity, stepRate, out) { if (out === undefined) { out = []; } // If quantity is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead. if (!quantity) { quantity = Perimeter(rectangle) / stepRate; } for (var i = 0; i < quantity; i++) { var position = i / quantity; out.push(GetPoint(rectangle, position)); } return out; }; module.exports = GetPoints; /***/ }), /* 295 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Returns the circumference of the given Circle. * * @function Phaser.Geom.Circle.Circumference * @since 3.0.0 * * @param {Phaser.Geom.Circle} circle - The Circle to get the circumference of. * * @return {number} The circumference of the Circle. */ var Circumference = function (circle) { return 2 * (Math.PI * circle.radius); }; module.exports = Circumference; /***/ }), /* 296 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Circumference = __webpack_require__(295); var CircumferencePoint = __webpack_require__(136); var FromPercent = __webpack_require__(65); var MATH_CONST = __webpack_require__(16); /** * Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, * based on the given quantity or stepRate values. * * @function Phaser.Geom.Circle.GetPoints * @since 3.0.0 * * @param {Phaser.Geom.Circle} circle - The Circle to get the points from. * @param {integer} quantity - The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. * @param {number} [stepRate] - Sets the quantity by getting the circumference of the circle and dividing it by the stepRate. * @param {array} [output] - An array to insert the points in to. If not provided a new array will be created. * * @return {Phaser.Geom.Point[]} An array of Point objects pertaining to the points around the circumference of the circle. */ var GetPoints = function (circle, quantity, stepRate, out) { if (out === undefined) { out = []; } // If quantity is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead. if (!quantity) { quantity = Circumference(circle) / stepRate; } for (var i = 0; i < quantity; i++) { var angle = FromPercent(i / quantity, 0, MATH_CONST.PI2); out.push(CircumferencePoint(circle, angle)); } return out; }; module.exports = GetPoints; /***/ }), /* 297 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * @classdesc * A seeded random data generator. * * @class RandomDataGenerator * @memberOf Phaser.Math * @constructor * @since 3.0.0 * * @param {string[]} [seeds] - The seeds. */ var RandomDataGenerator = new Class({ initialize: function RandomDataGenerator (seeds) { /** * Internal var. * * @name Phaser.Math.RandomDataGenerator#c * @type {number} * @default 1 * @private * @since 3.0.0 */ this.c = 1; /** * Internal var. * * @name Phaser.Math.RandomDataGenerator#s0 * @type {number} * @default 0 * @private * @since 3.0.0 */ this.s0 = 0; /** * Internal var. * * @name Phaser.Math.RandomDataGenerator#s1 * @type {number} * @default 0 * @private * @since 3.0.0 */ this.s1 = 0; /** * Internal var. * * @name Phaser.Math.RandomDataGenerator#s2 * @type {number} * @default 0 * @private * @since 3.0.0 */ this.s2 = 0; /** * Internal var. * * @name Phaser.Math.RandomDataGenerator#n * @type {number} * @default 0 * @private * @since 3.2.0 */ this.n = 0; /** * Signs to choose from. * * @name Phaser.Math.RandomDataGenerator#signs * @type {number[]} * @since 3.0.0 */ this.signs = [ -1, 1 ]; if (seeds) { this.init(seeds); } }, /** * Private random helper. * * @method Phaser.Math.RandomDataGenerator#rnd * @since 3.0.0 * @private * * @return {number} A random number. */ rnd: function () { var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32 this.c = t | 0; this.s0 = this.s1; this.s1 = this.s2; this.s2 = t - this.c; return this.s2; }, /** * Internal method that creates a seed hash. * * @method Phaser.Math.RandomDataGenerator#hash * @since 3.0.0 * @private * * @param {string} data - The value to hash. * * @return {number} The hashed value. */ hash: function (data) { var h; var n = this.n; data = data.toString(); for (var i = 0; i < data.length; i++) { n += data.charCodeAt(i); h = 0.02519603282416938 * n; n = h >>> 0; h -= n; h *= n; n = h >>> 0; h -= n; n += h * 0x100000000;// 2^32 } this.n = n; return (n >>> 0) * 2.3283064365386963e-10;// 2^-32 }, /** * Initialize the state of the random data generator. * * @method Phaser.Math.RandomDataGenerator#init * @since 3.0.0 * * @param {(string|string[])} seeds - The seeds to initialize the random data generator with. */ init: function (seeds) { if (typeof seeds === 'string') { this.state(seeds); } else { this.sow(seeds); } }, /** * Reset the seed of the random data generator. * * _Note_: the seed array is only processed up to the first `undefined` (or `null`) value, should such be present. * * @method Phaser.Math.RandomDataGenerator#sow * @since 3.0.0 * * @param {string[]} seeds - The array of seeds: the `toString()` of each value is used. */ sow: function (seeds) { // Always reset to default seed this.n = 0xefc8249d; this.s0 = this.hash(' '); this.s1 = this.hash(' '); this.s2 = this.hash(' '); this.c = 1; if (!seeds) { return; } // Apply any seeds for (var i = 0; i < seeds.length && (seeds[i] != null); i++) { var seed = seeds[i]; this.s0 -= this.hash(seed); this.s0 += ~~(this.s0 < 0); this.s1 -= this.hash(seed); this.s1 += ~~(this.s1 < 0); this.s2 -= this.hash(seed); this.s2 += ~~(this.s2 < 0); } }, /** * Returns a random integer between 0 and 2^32. * * @method Phaser.Math.RandomDataGenerator#integer * @since 3.0.0 * * @return {number} A random integer between 0 and 2^32. */ integer: function () { // 2^32 return this.rnd() * 0x100000000; }, /** * Returns a random real number between 0 and 1. * * @method Phaser.Math.RandomDataGenerator#frac * @since 3.0.0 * * @return {number} A random real number between 0 and 1. */ frac: function () { // 2^-53 return this.rnd() + (this.rnd() * 0x200000 | 0) * 1.1102230246251565e-16; }, /** * Returns a random real number between 0 and 2^32. * * @method Phaser.Math.RandomDataGenerator#real * @since 3.0.0 * * @return {number} A random real number between 0 and 2^32. */ real: function () { return this.integer() + this.frac(); }, /** * Returns a random integer between and including min and max. * * @method Phaser.Math.RandomDataGenerator#integerInRange * @since 3.0.0 * * @param {number} min - The minimum value in the range. * @param {number} max - The maximum value in the range. * * @return {number} A random number between min and max. */ integerInRange: function (min, max) { return Math.floor(this.realInRange(0, max - min + 1) + min); }, /** * Returns a random integer between and including min and max. * This method is an alias for RandomDataGenerator.integerInRange. * * @method Phaser.Math.RandomDataGenerator#between * @since 3.0.0 * * @param {number} min - The minimum value in the range. * @param {number} max - The maximum value in the range. * * @return {number} A random number between min and max. */ between: function (min, max) { return Math.floor(this.realInRange(0, max - min + 1) + min); }, /** * Returns a random real number between min and max. * * @method Phaser.Math.RandomDataGenerator#realInRange * @since 3.0.0 * * @param {number} min - The minimum value in the range. * @param {number} max - The maximum value in the range. * * @return {number} A random number between min and max. */ realInRange: function (min, max) { return this.frac() * (max - min) + min; }, /** * Returns a random real number between -1 and 1. * * @method Phaser.Math.RandomDataGenerator#normal * @since 3.0.0 * * @return {number} A random real number between -1 and 1. */ normal: function () { return 1 - (2 * this.frac()); }, /** * Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368 * * @method Phaser.Math.RandomDataGenerator#uuid * @since 3.0.0 * * @return {string} A valid RFC4122 version4 ID hex string */ uuid: function () { var a = ''; var b = ''; for (b = a = ''; a++ < 36; b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac() * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-') { // eslint-disable-next-line no-empty } return b; }, /** * Returns a random element from within the given array. * * @method Phaser.Math.RandomDataGenerator#pick * @since 3.0.0 * * @param {array} array - The array to pick a random element from. * * @return {*} A random member of the array. */ pick: function (array) { return array[this.integerInRange(0, array.length - 1)]; }, /** * Returns a sign to be used with multiplication operator. * * @method Phaser.Math.RandomDataGenerator#sign * @since 3.0.0 * * @return {number} -1 or +1. */ sign: function () { return this.pick(this.signs); }, /** * Returns a random element from within the given array, favoring the earlier entries. * * @method Phaser.Math.RandomDataGenerator#weightedPick * @since 3.0.0 * * @param {array} array - The array to pick a random element from. * * @return {*} A random member of the array. */ weightedPick: function (array) { return array[~~(Math.pow(this.frac(), 2) * (array.length - 1) + 0.5)]; }, /** * Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified. * * @method Phaser.Math.RandomDataGenerator#timestamp * @since 3.0.0 * * @param {number} min - The minimum value in the range. * @param {number} max - The maximum value in the range. * * @return {number} A random timestamp between min and max. */ timestamp: function (min, max) { return this.realInRange(min || 946684800000, max || 1577862000000); }, /** * Returns a random angle between -180 and 180. * * @method Phaser.Math.RandomDataGenerator#angle * @since 3.0.0 * * @return {number} A random number between -180 and 180. */ angle: function () { return this.integerInRange(-180, 180); }, /** * Returns a random rotation in radians, between -3.141 and 3.141 * * @method Phaser.Math.RandomDataGenerator#rotation * @since 3.0.0 * * @return {number} A random number between -3.141 and 3.141 */ rotation: function () { return this.realInRange(-3.1415926, 3.1415926); }, /** * Gets or Sets the state of the generator. This allows you to retain the values * that the generator is using between games, i.e. in a game save file. * * To seed this generator with a previously saved state you can pass it as the * `seed` value in your game config, or call this method directly after Phaser has booted. * * Call this method with no parameters to return the current state. * * If providing a state it should match the same format that this method * returns, which is a string with a header `!rnd` followed by the `c`, * `s0`, `s1` and `s2` values respectively, each comma-delimited. * * @method Phaser.Math.RandomDataGenerator#state * @since 3.0.0 * * @param {string} [state] - Generator state to be set. * * @return {string} The current state of the generator. */ state: function (state) { if (typeof state === 'string' && state.match(/^!rnd/)) { state = state.split(','); this.c = parseFloat(state[1]); this.s0 = parseFloat(state[2]); this.s1 = parseFloat(state[3]); this.s2 = parseFloat(state[4]); } return [ '!rnd', this.c, this.s0, this.s1, this.s2 ].join(','); }, /** * Shuffles the given array, using the current seed. * * @method Phaser.Math.RandomDataGenerator#shuffle * @since 3.7.0 * * @param {array} [array] - The array to be shuffled. * * @return {array} The shuffled array. */ shuffle: function (array) { var len = array.length - 1; for (var i = len; i > 0; i--) { var randomIndex = Math.floor(this.frac() * (len + 1)); var itemAtIndex = array[randomIndex]; array[randomIndex] = array[i]; array[i] = itemAtIndex; } return array; } }); module.exports = RandomDataGenerator; /***/ }), /* 298 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CircumferencePoint = __webpack_require__(136); var FromPercent = __webpack_require__(65); var MATH_CONST = __webpack_require__(16); var Point = __webpack_require__(5); /** * Returns a Point object containing the coordinates of a point on the circumference of the Circle * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point * at 180 degrees around the circle. * * @function Phaser.Geom.Circle.GetPoint * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Circle} circle - The Circle to get the circumference point on. * @param {float} position - A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle. * @param {(Phaser.Geom.Point|object)} [out] - An object to store the return values in. If not given a Point object will be created. * * @return {(Phaser.Geom.Point|object)} A Point, or point-like object, containing the coordinates of the point around the circle. */ var GetPoint = function (circle, position, out) { if (out === undefined) { out = new Point(); } var angle = FromPercent(position, 0, MATH_CONST.PI2); return CircumferencePoint(circle, angle, out); }; module.exports = GetPoint; /***/ }), /* 299 */, /* 300 */, /* 301 */, /* 302 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); /** * This event is dispatched when an animation starts playing. * * @event Phaser.GameObjects.Components.Animation#onStartEvent * @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation. * @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame. */ /** * This event is dispatched when an animation repeats. * * @event Phaser.GameObjects.Components.Animation#onRepeatEvent * @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation. * @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame. * @param {integer} repeatCount - The number of times this animation has repeated. */ /** * This event is dispatched when an animation updates. This happens when the animation frame changes, * based on the animation frame rate and other factors like timeScale and delay. * * @event Phaser.GameObjects.Components.Animation#onUpdateEvent * @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation. * @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame. */ /** * This event is dispatched when an animation completes playing, either naturally or via Animation.stop. * * @event Phaser.GameObjects.Components.Animation#onCompleteEvent * @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation. * @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame. */ /** * @classdesc * A Game Object Animation Controller. * * This controller lives as an instance within a Game Object, accessible as `sprite.anims`. * * @class Animation * @memberOf Phaser.GameObjects.Components * @constructor * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} parent - The Game Object to which this animation controller belongs. */ var Animation = new Class({ initialize: function Animation (parent) { /** * The Game Object to which this animation controller belongs. * * @name Phaser.GameObjects.Components.Animation#parent * @type {Phaser.GameObjects.GameObject} * @since 3.0.0 */ this.parent = parent; /** * A reference to the global Animation Manager. * * @name Phaser.GameObjects.Components.Animation#animationManager * @type {Phaser.Animations.AnimationManager} * @since 3.0.0 */ this.animationManager = parent.scene.sys.anims; this.animationManager.once('remove', this.remove, this); /** * Is an animation currently playing or not? * * @name Phaser.GameObjects.Components.Animation#isPlaying * @type {boolean} * @default false * @since 3.0.0 */ this.isPlaying = false; /** * The current Animation loaded into this Animation Controller. * * @name Phaser.GameObjects.Components.Animation#currentAnim * @type {?Phaser.Animations.Animation} * @default null * @since 3.0.0 */ this.currentAnim = null; /** * The current AnimationFrame being displayed by this Animation Controller. * * @name Phaser.GameObjects.Components.Animation#currentFrame * @type {?Phaser.Animations.AnimationFrame} * @default null * @since 3.0.0 */ this.currentFrame = null; /** * Time scale factor. * * @name Phaser.GameObjects.Components.Animation#_timeScale * @type {number} * @private * @default 1 * @since 3.0.0 */ this._timeScale = 1; /** * The frame rate of playback in frames per second. * The default is 24 if the `duration` property is `null`. * * @name Phaser.GameObjects.Components.Animation#frameRate * @type {number} * @default 0 * @since 3.0.0 */ this.frameRate = 0; /** * How long the animation should play for, in milliseconds. * If the `frameRate` property has been set then it overrides this value, * otherwise the `frameRate` is derived from `duration`. * * @name Phaser.GameObjects.Components.Animation#duration * @type {number} * @default 0 * @since 3.0.0 */ this.duration = 0; /** * ms per frame, not including frame specific modifiers that may be present in the Animation data. * * @name Phaser.GameObjects.Components.Animation#msPerFrame * @type {number} * @default 0 * @since 3.0.0 */ this.msPerFrame = 0; /** * Skip frames if the time lags, or always advanced anyway? * * @name Phaser.GameObjects.Components.Animation#skipMissedFrames * @type {boolean} * @default true * @since 3.0.0 */ this.skipMissedFrames = true; /** * A delay before starting playback, in milliseconds. * * @name Phaser.GameObjects.Components.Animation#_delay * @type {number} * @private * @default 0 * @since 3.0.0 */ this._delay = 0; /** * Number of times to repeat the animation (-1 for infinity) * * @name Phaser.GameObjects.Components.Animation#_repeat * @type {number} * @private * @default 0 * @since 3.0.0 */ this._repeat = 0; /** * Delay before the repeat starts, in milliseconds. * * @name Phaser.GameObjects.Components.Animation#_repeatDelay * @type {number} * @private * @default 0 * @since 3.0.0 */ this._repeatDelay = 0; /** * Should the animation yoyo? (reverse back down to the start) before repeating? * * @name Phaser.GameObjects.Components.Animation#_yoyo * @type {boolean} * @private * @default false * @since 3.0.0 */ this._yoyo = false; /** * Will the playhead move forwards (`true`) or in reverse (`false`) * * @name Phaser.GameObjects.Components.Animation#forward * @type {boolean} * @default true * @since 3.0.0 */ this.forward = true; /** * Internal time overflow accumulator. * * @name Phaser.GameObjects.Components.Animation#accumulator * @type {number} * @default 0 * @since 3.0.0 */ this.accumulator = 0; /** * The time point at which the next animation frame will change. * * @name Phaser.GameObjects.Components.Animation#nextTick * @type {number} * @default 0 * @since 3.0.0 */ this.nextTick = 0; /** * An internal counter keeping track of how many repeats are left to play. * * @name Phaser.GameObjects.Components.Animation#repeatCounter * @type {number} * @default 0 * @since 3.0.0 */ this.repeatCounter = 0; /** * An internal flag keeping track of pending repeats. * * @name Phaser.GameObjects.Components.Animation#pendingRepeat * @type {boolean} * @default false * @since 3.0.0 */ this.pendingRepeat = false; /** * Is the Animation paused? * * @name Phaser.GameObjects.Components.Animation#_paused * @type {boolean} * @private * @default false * @since 3.0.0 */ this._paused = false; /** * Was the animation previously playing before being paused? * * @name Phaser.GameObjects.Components.Animation#_wasPlaying * @type {boolean} * @private * @default false * @since 3.0.0 */ this._wasPlaying = false; /** * Internal property tracking if this Animation is waiting to stop. * * 0 = No * 1 = Waiting for ms to pass * 2 = Waiting for repeat * 3 = Waiting for specific frame * * @name Phaser.GameObjects.Components.Animation#_pendingStop * @type {integer} * @private * @since 3.4.0 */ this._pendingStop = 0; /** * Internal property used by _pendingStop. * * @name Phaser.GameObjects.Components.Animation#_pendingStopValue * @type {any} * @private * @since 3.4.0 */ this._pendingStopValue; }, /** * Sets the amount of time, in milliseconds, that the animation will be delayed before starting playback. * * @method Phaser.GameObjects.Components.Animation#setDelay * @since 3.4.0 * * @param {integer} [value=0] - The amount of time, in milliseconds, to wait before starting playback. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ setDelay: function (value) { if (value === undefined) { value = 0; } this._delay = value; return this.parent; }, /** * Gets the amount of time, in milliseconds that the animation will be delayed before starting playback. * * @method Phaser.GameObjects.Components.Animation#getDelay * @since 3.4.0 * * @return {integer} The amount of time, in milliseconds, the Animation will wait before starting playback. */ getDelay: function () { return this._delay; }, /** * Waits for the specified delay, in milliseconds, then starts playback of the requested animation. * * @method Phaser.GameObjects.Components.Animation#delayedPlay * @since 3.0.0 * * @param {integer} delay - The delay, in milliseconds, to wait before starting the animation playing. * @param {string} key - The key of the animation to play. * @param {integer} [startFrame=0] - The frame of the animation to start from. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ delayedPlay: function (delay, key, startFrame) { this.play(key, true, startFrame); this.nextTick += delay; return this.parent; }, /** * Returns the key of the animation currently loaded into this component. * * @method Phaser.GameObjects.Components.Animation#getCurrentKey * @since 3.0.0 * * @return {string} The key of the Animation loaded into this component. */ getCurrentKey: function () { if (this.currentAnim) { return this.currentAnim.key; } }, /** * Internal method used to load an animation into this component. * * @method Phaser.GameObjects.Components.Animation#load * @protected * @since 3.0.0 * * @param {string} key - The key of the animation to load. * @param {integer} [startFrame=0] - The start frame of the animation to load. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ load: function (key, startFrame) { if (startFrame === undefined) { startFrame = 0; } if (this.isPlaying) { this.stop(); } // Load the new animation in this.animationManager.load(this, key, startFrame); return this.parent; }, /** * Pause the current animation and set the `isPlaying` property to `false`. * You can optionally pause it at a specific frame. * * @method Phaser.GameObjects.Components.Animation#pause * @since 3.0.0 * * @param {Phaser.Animations.AnimationFrame} [atFrame] - An optional frame to set after pausing the animation. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ pause: function (atFrame) { if (!this._paused) { this._paused = true; this._wasPlaying = this.isPlaying; this.isPlaying = false; } if (atFrame !== undefined) { this.updateFrame(atFrame); } return this.parent; }, /** * Resumes playback of a paused animation and sets the `isPlaying` property to `true`. * You can optionally tell it to start playback from a specific frame. * * @method Phaser.GameObjects.Components.Animation#resume * @since 3.0.0 * * @param {Phaser.Animations.AnimationFrame} [fromFrame] - An optional frame to set before restarting playback. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ resume: function (fromFrame) { if (this._paused) { this._paused = false; this.isPlaying = this._wasPlaying; } if (fromFrame !== undefined) { this.updateFrame(fromFrame); } return this.parent; }, /** * `true` if the current animation is paused, otherwise `false`. * * @name Phaser.GameObjects.Components.Animation#isPaused * @readOnly * @type {boolean} * @since 3.4.0 */ isPaused: { get: function () { return this._paused; } }, /** * Plays an Animation on the Game Object that owns this Animation Component. * * @method Phaser.GameObjects.Components.Animation#play * @fires Phaser.GameObjects.Components.Animation#onStartEvent * @since 3.0.0 * * @param {string} key - The string-based key of the animation to play, as defined previously in the Animation Manager. * @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call. * @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ play: function (key, ignoreIfPlaying, startFrame) { if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; } if (startFrame === undefined) { startFrame = 0; } if (ignoreIfPlaying && this.isPlaying && this.currentAnim.key === key) { return this.parent; } this.load(key, startFrame); var anim = this.currentAnim; var gameObject = this.parent; // Should give us 9,007,199,254,740,991 safe repeats this.repeatCounter = (this._repeat === -1) ? Number.MAX_VALUE : this._repeat; anim.getFirstTick(this); this.forward = true; this.isPlaying = true; this.pendingRepeat = false; if (anim.showOnStart) { gameObject.visible = true; } gameObject.emit('animationstart', this.currentAnim, this.currentFrame); return gameObject; }, /** * Returns a value between 0 and 1 indicating how far this animation is through, ignoring repeats and yoyos. * If the animation has a non-zero repeat defined, `getProgress` and `getTotalProgress` will be different * because `getProgress` doesn't include any repeats or repeat delays, whereas `getTotalProgress` does. * * @method Phaser.GameObjects.Components.Animation#getProgress * @since 3.4.0 * * @return {float} The progress of the current animation, between 0 and 1. */ getProgress: function () { var p = this.currentFrame.progress; if (!this.forward) { p = 1 - p; } return p; }, /** * Takes a value between 0 and 1 and uses it to set how far this animation is through playback. * Does not factor in repeats or yoyos, but does handle playing forwards or backwards. * * @method Phaser.GameObjects.Components.Animation#setProgress * @since 3.4.0 * * @param {float} [value=0] - The progress value, between 0 and 1. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ setProgress: function (value) { if (!this.forward) { value = 1 - value; } this.setCurrentFrame(this.currentAnim.getFrameByProgress(value)); return this.parent; }, /** * Handle the removal of an animation from the Animation Manager. * * @method Phaser.GameObjects.Components.Animation#remove * @since 3.0.0 * * @param {string} [key] - The key of the removed Animation. * @param {Phaser.Animations.Animation} [animation] - The removed Animation. */ remove: function (key, animation) { if (animation === undefined) { animation = this.currentAnim; } if (this.isPlaying && animation.key === this.currentAnim.key) { this.stop(); this.setCurrentFrame(this.currentAnim.frames[0]); } }, /** * Gets the number of times that the animation will repeat * after its first iteration. For example, if returns 1, the animation will * play a total of twice (the initial play plus 1 repeat). * A value of -1 means the animation will repeat indefinitely. * * @method Phaser.GameObjects.Components.Animation#getRepeat * @since 3.4.0 * * @return {integer} The number of times that the animation will repeat. */ getRepeat: function () { return this._repeat; }, /** * Sets the number of times that the animation should repeat * after its first iteration. For example, if repeat is 1, the animation will * play a total of twice (the initial play plus 1 repeat). * To repeat indefinitely, use -1. repeat should always be an integer. * * @method Phaser.GameObjects.Components.Animation#setRepeat * @since 3.4.0 * * @param {integer} value - The number of times that the animation should repeat. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ setRepeat: function (value) { this._repeat = value; this.repeatCounter = 0; return this.parent; }, /** * Gets the amount of delay between repeats, if any. * * @method Phaser.GameObjects.Components.Animation#getRepeatDelay * @since 3.4.0 * * @return {number} The delay between repeats. */ getRepeatDelay: function () { return this._repeatDelay; }, /** * Sets the amount of time in seconds between repeats. * For example, if `repeat` is 2 and `repeatDelay` is 10, the animation will play initially, * then wait for 10 seconds before repeating, then play again, then wait another 10 seconds * before doing its final repeat. * * @method Phaser.GameObjects.Components.Animation#setRepeatDelay * @since 3.4.0 * * @param {number} value - The delay to wait between repeats, in seconds. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ setRepeatDelay: function (value) { this._repeatDelay = value; return this.parent; }, /** * Restarts the current animation from its beginning, optionally including its delay value. * * @method Phaser.GameObjects.Components.Animation#restart * @since 3.0.0 * * @param {boolean} [includeDelay=false] - Whether to include the delay value of the animation when restarting. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ restart: function (includeDelay) { if (includeDelay === undefined) { includeDelay = false; } this.currentAnim.getFirstTick(this, includeDelay); this.forward = true; this.isPlaying = true; this.pendingRepeat = false; this._paused = false; // Set frame this.updateFrame(this.currentAnim.frames[0]); return this.parent; }, /** * Immediately stops the current animation from playing and dispatches the `animationcomplete` event. * * @method Phaser.GameObjects.Components.Animation#stop * @fires Phaser.GameObjects.Components.Animation#onCompleteEvent * @since 3.0.0 * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ stop: function () { this._pendingStop = 0; this.isPlaying = false; var gameObject = this.parent; gameObject.emit('animationcomplete', this.currentAnim, this.currentFrame); return gameObject; }, /** * Stops the current animation from playing after the specified time delay, given in milliseconds. * * @method Phaser.GameObjects.Components.Animation#stopAfterDelay * @fires Phaser.GameObjects.Components.Animation#onCompleteEvent * @since 3.4.0 * * @param {integer} delay - The number of milliseconds to wait before stopping this animation. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ stopAfterDelay: function (delay) { this._pendingStop = 1; this._pendingStopValue = delay; return this.parent; }, /** * Stops the current animation from playing when it next repeats. * * @method Phaser.GameObjects.Components.Animation#stopOnRepeat * @fires Phaser.GameObjects.Components.Animation#onCompleteEvent * @since 3.4.0 * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ stopOnRepeat: function () { this._pendingStop = 2; return this.parent; }, /** * Stops the current animation from playing when it next sets the given frame. * If this frame doesn't exist within the animation it will not stop it from playing. * * @method Phaser.GameObjects.Components.Animation#stopOnFrame * @fires Phaser.GameObjects.Components.Animation#onCompleteEvent * @since 3.4.0 * * @param {Phaser.Animations.AnimationFrame} delay - The frame to check before stopping this animation. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ stopOnFrame: function (frame) { this._pendingStop = 3; this._pendingStopValue = frame; return this.parent; }, /** * Sets the Time Scale factor, allowing you to make the animation go go faster or slower than default. * Where 1 = normal speed (the default), 0.5 = half speed, 2 = double speed, etc. * * @method Phaser.GameObjects.Components.Animation#setTimeScale * @since 3.4.0 * * @param {number} [value=1] - The time scale factor, where 1 is no change, 0.5 is half speed, etc. * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ setTimeScale: function (value) { if (value === undefined) { value = 1; } this._timeScale = value; return this.parent; }, /** * Gets the Time Scale factor. * * @method Phaser.GameObjects.Components.Animation#getTimeScale * @since 3.4.0 * * @return {number} The Time Scale value. */ getTimeScale: function () { return this._timeScale; }, /** * Returns the total number of frames in this animation. * * @method Phaser.GameObjects.Components.Animation#getTotalFrames * @since 3.4.0 * * @return {integer} The total number of frames in this animation. */ getTotalFrames: function () { return this.currentAnim.frames.length; }, /** * The internal update loop for the Animation Component. * * @method Phaser.GameObjects.Components.Animation#update * @since 3.0.0 * * @param {number} time - The current timestamp. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ update: function (time, delta) { if (!this.currentAnim || !this.isPlaying || this.currentAnim.paused) { return; } this.accumulator += delta * this._timeScale; if (this._pendingStop === 1) { this._pendingStopValue -= delta; if (this._pendingStopValue <= 0) { return this.currentAnim.completeAnimation(this); } } if (this.accumulator >= this.nextTick) { this.currentAnim.setFrame(this); } }, /** * Sets the given Animation Frame as being the current frame * and applies it to the parent Game Object, adjusting its size and origin as needed. * * @method Phaser.GameObjects.Components.Animation#setCurrentFrame * @since 3.4.0 * * @param {Phaser.Animations.AnimationFrame} animationFrame - The Animation Frame to set as being current. * * @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to. */ setCurrentFrame: function (animationFrame) { var gameObject = this.parent; this.currentFrame = animationFrame; gameObject.texture = animationFrame.frame.texture; gameObject.frame = animationFrame.frame; gameObject.setSizeToFrame(); if (animationFrame.frame.customPivot) { gameObject.setOrigin(animationFrame.frame.pivotX, animationFrame.frame.pivotY); } else { gameObject.updateDisplayOrigin(); } return gameObject; }, /** * Internal frame change handler. * * @method Phaser.GameObjects.Components.Animation#updateFrame * @fires Phaser.GameObjects.Components.Animation#onUpdateEvent * @private * @since 3.0.0 * * @param {Phaser.Animations.AnimationFrame} animationFrame - The animation frame to change to. */ updateFrame: function (animationFrame) { var gameObject = this.setCurrentFrame(animationFrame); if (this.isPlaying) { if (animationFrame.setAlpha) { gameObject.alpha = animationFrame.alpha; } var anim = this.currentAnim; gameObject.emit('animationupdate', anim, animationFrame); if (this._pendingStop === 3 && this._pendingStopValue === animationFrame) { this.currentAnim.completeAnimation(this); } } }, /** * Sets if the current Animation will yoyo when it reaches the end. * A yoyo'ing animation will play through consecutively, and then reverse-play back to the start again. * * @method Phaser.GameObjects.Components.Animation#setYoyo * @since 3.4.0 * * @param {boolean} [value=false] - `true` if the animation should yoyo, `false` to not. * * @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to. */ setYoyo: function (value) { if (value === undefined) { value = false; } this._yoyo = value; return this.parent; }, /** * Gets if the current Animation will yoyo when it reaches the end. * A yoyo'ing animation will play through consecutively, and then reverse-play back to the start again. * * @method Phaser.GameObjects.Components.Animation#getYoyo * @since 3.4.0 * * @return {boolean} `true` if the animation is set to yoyo, `false` if not. */ getYoyo: function () { return this._yoyo; }, /** * Destroy this Animation component. * * Unregisters event listeners and cleans up its references. * * @method Phaser.GameObjects.Components.Animation#destroy * @since 3.0.0 */ destroy: function () { this.animationManager.off('remove', this.remove, this); this.animationManager = null; this.parent = null; this.currentAnim = null; this.currentFrame = null; } }); module.exports = Animation; /***/ }), /* 303 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var NumberTweenBuilder = __webpack_require__(161); var PluginCache = __webpack_require__(12); var TimelineBuilder = __webpack_require__(160); var TWEEN_CONST = __webpack_require__(61); var TweenBuilder = __webpack_require__(72); /** * @classdesc * [description] * * @class TweenManager * @memberOf Phaser.Tweens * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - [description] */ var TweenManager = new Class({ initialize: function TweenManager (scene) { /** * [description] * * @name Phaser.Tweens.TweenManager#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * [description] * * @name Phaser.Tweens.TweenManager#systems * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.systems = scene.sys; /** * [description] * * @name Phaser.Tweens.TweenManager#timeScale * @type {number} * @default 1 * @since 3.0.0 */ this.timeScale = 1; /** * [description] * * @name Phaser.Tweens.TweenManager#_add * @type {array} * @private * @since 3.0.0 */ this._add = []; /** * [description] * * @name Phaser.Tweens.TweenManager#_pending * @type {array} * @private * @since 3.0.0 */ this._pending = []; /** * [description] * * @name Phaser.Tweens.TweenManager#_active * @type {array} * @private * @since 3.0.0 */ this._active = []; /** * [description] * * @name Phaser.Tweens.TweenManager#_destroy * @type {array} * @private * @since 3.0.0 */ this._destroy = []; /** * [description] * * @name Phaser.Tweens.TweenManager#_toProcess * @type {integer} * @private * @default 0 * @since 3.0.0 */ this._toProcess = 0; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('start', this.start, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Tweens.TweenManager#boot * @private * @since 3.5.1 */ boot: function () { this.systems.events.once('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.Tweens.TweenManager#start * @private * @since 3.5.0 */ start: function () { var eventEmitter = this.systems.events; eventEmitter.on('preupdate', this.preUpdate, this); eventEmitter.on('update', this.update, this); eventEmitter.once('shutdown', this.shutdown, this); this.timeScale = 1; }, /** * Create a Tween Timeline and return it, but do NOT add it to the active or pending Tween lists. * * @method Phaser.Tweens.TweenManager#createTimeline * @since 3.0.0 * * @param {object} config - [description] * * @return {Phaser.Tweens.Timeline} [description] */ createTimeline: function (config) { return TimelineBuilder(this, config); }, /** * Create a Tween Timeline and add it to the active Tween list/ * * @method Phaser.Tweens.TweenManager#timeline * @since 3.0.0 * * @param {object} config - [description] * * @return {Phaser.Tweens.Timeline} [description] */ timeline: function (config) { var timeline = TimelineBuilder(this, config); if (!timeline.paused) { this._add.push(timeline); this._toProcess++; } return timeline; }, /** * Create a Tween and return it, but do NOT add it to the active or pending Tween lists. * * @method Phaser.Tweens.TweenManager#create * @since 3.0.0 * * @param {object} config - [description] * * @return {Phaser.Tweens.Tween} [description] */ create: function (config) { return TweenBuilder(this, config); }, /** * Create a Tween and add it to the active Tween list. * * @method Phaser.Tweens.TweenManager#add * @since 3.0.0 * * @param {object} config - [description] * * @return {Phaser.Tweens.Tween} [description] */ add: function (config) { var tween = TweenBuilder(this, config); this._add.push(tween); this._toProcess++; return tween; }, /** * Add an existing tween into the active Tween list. * * @method Phaser.Tweens.TweenManager#existing * @since 3.0.0 * * @param {Phaser.Tweens.Tween} tween - [description] * * @return {Phaser.Tweens.TweenManager} This Tween Manager object. */ existing: function (tween) { this._add.push(tween); this._toProcess++; return this; }, /** * Create a Tween and add it to the active Tween list. * * @method Phaser.Tweens.TweenManager#addCounter * @since 3.0.0 * * @param {object} config - [description] * * @return {Phaser.Tweens.Tween} [description] */ addCounter: function (config) { var tween = NumberTweenBuilder(this, config); this._add.push(tween); this._toProcess++; return tween; }, /** * [description] * * @method Phaser.Tweens.TweenManager#preUpdate * @since 3.0.0 */ preUpdate: function () { if (this._toProcess === 0) { // Quick bail return; } var list = this._destroy; var active = this._active; var i; var tween; // Clear the 'destroy' list for (i = 0; i < list.length; i++) { tween = list[i]; // Remove from the 'active' array var idx = active.indexOf(tween); if (idx !== -1) { tween.state = TWEEN_CONST.REMOVED; active.splice(idx, 1); } } list.length = 0; // Process the addition list // This stops callbacks and out of sync events from populating the active array mid-way during the update list = this._add; for (i = 0; i < list.length; i++) { tween = list[i]; if (tween.state === TWEEN_CONST.PENDING_ADD) { // Return true if the Tween should be started right away, otherwise false if (tween.init()) { tween.play(); this._active.push(tween); } else { this._pending.push(tween); } } } list.length = 0; this._toProcess = 0; }, /** * [description] * * @method Phaser.Tweens.TweenManager#update * @since 3.0.0 * * @param {number} timestamp - [description] * @param {number} delta - [description] */ update: function (timestamp, delta) { // Process active tweens var list = this._active; var tween; // Scale the delta delta *= this.timeScale; for (var i = 0; i < list.length; i++) { tween = list[i]; // If Tween.update returns 'true' then it means it has completed, // so move it to the destroy list if (tween.update(timestamp, delta)) { this._destroy.push(tween); this._toProcess++; } } }, /** * [description] * * @method Phaser.Tweens.TweenManager#makeActive * @since 3.0.0 * * @param {Phaser.Tweens.Tween} tween - [description] * * @return {Phaser.Tweens.TweenManager} This Tween Manager object. */ makeActive: function (tween) { if (this._add.indexOf(tween) !== -1 || this._active.indexOf(tween) !== -1) { return; } var idx = this._pending.indexOf(tween); if (idx !== -1) { this._pending.splice(idx, 1); } this._add.push(tween); tween.state = TWEEN_CONST.PENDING_ADD; this._toProcess++; return this; }, /** * Passes all Tweens to the given callback. * * @method Phaser.Tweens.TweenManager#each * @since 3.0.0 * * @param {function} callback - [description] * @param {object} [scope] - [description] * @param {...*} [args] - [description] */ each: function (callback, scope) { var args = [ null ]; for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); } for (var texture in this.list) { args[0] = this.list[texture]; callback.apply(scope, args); } }, /** * [description] * * @method Phaser.Tweens.TweenManager#getAllTweens * @since 3.0.0 * * @return {Phaser.Tweens.Tween[]} [description] */ getAllTweens: function () { var list = this._active; var output = []; for (var i = 0; i < list.length; i++) { output.push(list[i]); } return output; }, /** * [description] * * @method Phaser.Tweens.TweenManager#getGlobalTimeScale * @since 3.0.0 * * @return {number} [description] */ getGlobalTimeScale: function () { return this.timeScale; }, /** * [description] * * @method Phaser.Tweens.TweenManager#getTweensOf * @since 3.0.0 * * @param {(object|array)} target - [description] * * @return {Phaser.Tweens.Tween[]} [description] */ getTweensOf: function (target) { var list = this._active; var tween; var output = []; var i; if (Array.isArray(target)) { for (i = 0; i < list.length; i++) { tween = list[i]; for (var t = 0; t < target.length; t++) { if (tween.hasTarget(target[t])) { output.push(tween); } } } } else { for (i = 0; i < list.length; i++) { tween = list[i]; if (tween.hasTarget(target)) { output.push(tween); } } } return output; }, /** * [description] * * @method Phaser.Tweens.TweenManager#isTweening * @since 3.0.0 * * @param {object} target - [description] * * @return {boolean} [description] */ isTweening: function (target) { var list = this._active; var tween; for (var i = 0; i < list.length; i++) { tween = list[i]; if (tween.hasTarget(target) && tween.isPlaying()) { return true; } } return false; }, /** * [description] * * @method Phaser.Tweens.TweenManager#killAll * @since 3.0.0 * * @return {Phaser.Tweens.TweenManager} [description] */ killAll: function () { var tweens = this.getAllTweens(); for (var i = 0; i < tweens.length; i++) { tweens[i].stop(); } return this; }, /** * [description] * * @method Phaser.Tweens.TweenManager#killTweensOf * @since 3.0.0 * * @param {(object|array)} target - [description] * * @return {Phaser.Tweens.TweenManager} [description] */ killTweensOf: function (target) { var tweens = this.getTweensOf(target); for (var i = 0; i < tweens.length; i++) { tweens[i].stop(); } return this; }, /** * [description] * * @method Phaser.Tweens.TweenManager#pauseAll * @since 3.0.0 * * @return {Phaser.Tweens.TweenManager} [description] */ pauseAll: function () { var list = this._active; for (var i = 0; i < list.length; i++) { list[i].pause(); } return this; }, /** * [description] * * @method Phaser.Tweens.TweenManager#resumeAll * @since 3.0.0 * * @return {Phaser.Tweens.TweenManager} [description] */ resumeAll: function () { var list = this._active; for (var i = 0; i < list.length; i++) { list[i].resume(); } return this; }, /** * [description] * * @method Phaser.Tweens.TweenManager#setGlobalTimeScale * @since 3.0.0 * * @param {float} value - [description] * * @return {Phaser.Tweens.TweenManager} [description] */ setGlobalTimeScale: function (value) { this.timeScale = value; return this; }, /** * 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.Tweens.TweenManager#shutdown * @since 3.0.0 */ shutdown: function () { this.killAll(); this._add = []; this._pending = []; this._active = []; this._destroy = []; this._toProcess = 0; var eventEmitter = this.systems.events; eventEmitter.off('preupdate', this.preUpdate, this); eventEmitter.off('update', this.update, this); eventEmitter.off('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.Tweens.TweenManager#destroy * @since 3.0.0 */ destroy: function () { this.shutdown(); this.scene.sys.events.off('start', this.start, this); this.scene = null; this.systems = null; } }); PluginCache.register('TweenManager', TweenManager, 'tweens'); module.exports = TweenManager; /***/ }), /* 304 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // RESERVED properties that a Tween config object uses // completeDelay: The time the tween will wait before the onComplete event is dispatched once it has completed // delay: The time the tween will wait before it first starts // duration: The duration of the tween // ease: The ease function used by the tween // easeParams: The parameters to go with the ease function (if any) // flipX: flip X the GameObject on tween end // flipY: flip Y the GameObject on tween end// hold: The time the tween will pause before running a yoyo // hold: The time the tween will pause before running a yoyo // loop: The time the tween will pause before starting either a yoyo or returning to the start for a repeat // loopDelay: // offset: Used when the Tween is part of a Timeline // paused: Does the tween start in a paused state, or playing? // props: The properties being tweened by the tween // repeat: The number of times the tween will repeat itself (a value of 1 means the tween will play twice, as it repeated once) // repeatDelay: The time the tween will pause for before starting a repeat. The tween holds in the start state. // targets: The targets the tween is updating. // useFrames: Use frames or milliseconds? // yoyo: boolean - Does the tween reverse itself (yoyo) when it reaches the end? module.exports = [ 'callbackScope', 'completeDelay', 'delay', 'duration', 'ease', 'easeParams', 'flipX', 'flipY', 'hold', 'loop', 'loopDelay', 'offset', 'onComplete', 'onCompleteParams', 'onCompleteScope', 'onLoop', 'onLoopParams', 'onLoopScope', 'onRepeat', 'onRepeatParams', 'onRepeatScope', 'onStart', 'onStartParams', 'onStartScope', 'onUpdate', 'onUpdateParams', 'onUpdateScope', 'onYoyo', 'onYoyoParams', 'onYoyoScope', 'paused', 'props', 'repeat', 'repeatDelay', 'targets', 'useFrames', 'yoyo' ]; /***/ }), /* 305 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Tweens.Builders */ module.exports = { GetBoolean: __webpack_require__(62), GetEaseFunction: __webpack_require__(63), GetNewValue: __webpack_require__(73), GetProps: __webpack_require__(163), GetTargets: __webpack_require__(102), GetTweens: __webpack_require__(162), GetValueOp: __webpack_require__(101), NumberTweenBuilder: __webpack_require__(161), TimelineBuilder: __webpack_require__(160), TweenBuilder: __webpack_require__(72) }; /***/ }), /* 306 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CONST = __webpack_require__(61); var Extend = __webpack_require__(17); /** * @namespace Phaser.Tweens */ var Tweens = { Builders: __webpack_require__(305), TweenManager: __webpack_require__(303), Tween: __webpack_require__(99), TweenData: __webpack_require__(98), Timeline: __webpack_require__(159) }; // Merge in the consts Tweens = Extend(false, Tweens, CONST); module.exports = Tweens; /***/ }), /* 307 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var PluginCache = __webpack_require__(12); var TimerEvent = __webpack_require__(164); /** * @classdesc * [description] * * @class Clock * @memberOf Phaser.Time * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - [description] */ var Clock = new Class({ initialize: function Clock (scene) { /** * [description] * * @name Phaser.Time.Clock#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * [description] * * @name Phaser.Time.Clock#systems * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.systems = scene.sys; /** * [description] * * @name Phaser.Time.Clock#now * @type {number} * @since 3.0.0 */ this.now = Date.now(); // Scale the delta time coming into the Clock by this factor // which then influences anything using this Clock for calculations, like TimerEvents /** * [description] * * @name Phaser.Time.Clock#timeScale * @type {float} * @default 1 * @since 3.0.0 */ this.timeScale = 1; /** * [description] * * @name Phaser.Time.Clock#paused * @type {boolean} * @default false * @since 3.0.0 */ this.paused = false; /** * [description] * * @name Phaser.Time.Clock#_active * @type {Phaser.Time.TimerEvent[]} * @private * @default [] * @since 3.0.0 */ this._active = []; /** * [description] * * @name Phaser.Time.Clock#_pendingInsertion * @type {Phaser.Time.TimerEvent[]} * @private * @default [] * @since 3.0.0 */ this._pendingInsertion = []; /** * [description] * * @name Phaser.Time.Clock#_pendingRemoval * @type {Phaser.Time.TimerEvent[]} * @private * @default [] * @since 3.0.0 */ this._pendingRemoval = []; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('start', this.start, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Time.Clock#boot * @private * @since 3.5.1 */ boot: function () { this.systems.events.once('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.Time.Clock#start * @private * @since 3.5.0 */ start: function () { var eventEmitter = this.systems.events; eventEmitter.on('preupdate', this.preUpdate, this); eventEmitter.on('update', this.update, this); eventEmitter.once('shutdown', this.shutdown, this); }, /** * [description] * * @method Phaser.Time.Clock#addEvent * @since 3.0.0 * * @param {TimerEventConfig} config - [description] * * @return {Phaser.Time.TimerEvent} [description] */ addEvent: function (config) { var event = new TimerEvent(config); this._pendingInsertion.push(event); return event; }, /** * [description] * * @method Phaser.Time.Clock#delayedCall * @since 3.0.0 * * @param {number} delay - [description] * @param {function} callback - [description] * @param {Array.<*>} args - [description] * @param {*} callbackScope - [description] * * @return {Phaser.Time.TimerEvent} [description] */ delayedCall: function (delay, callback, args, callbackScope) { return this.addEvent({ delay: delay, callback: callback, args: args, callbackScope: callbackScope }); }, /** * [description] * * @method Phaser.Time.Clock#clearPendingEvents * @since 3.0.0 * * @return {Phaser.Time.Clock} [description] */ clearPendingEvents: function () { this._pendingInsertion = []; return this; }, /** * [description] * * @method Phaser.Time.Clock#removeAllEvents * @since 3.0.0 * * @return {Phaser.Time.Clock} [description] */ removeAllEvents: function () { this._pendingRemoval = this._pendingRemoval.concat(this._active); return this; }, /** * [description] * * @method Phaser.Time.Clock#preUpdate * @since 3.0.0 * * @param {number} time - [description] * @param {number} delta - [description] */ preUpdate: function () { var toRemove = this._pendingRemoval.length; var toInsert = this._pendingInsertion.length; if (toRemove === 0 && toInsert === 0) { // Quick bail return; } var i; var event; // Delete old events for (i = 0; i < toRemove; i++) { event = this._pendingRemoval[i]; var index = this._active.indexOf(event); if (index > -1) { this._active.splice(index, 1); } // Pool them? event.destroy(); } for (i = 0; i < toInsert; i++) { event = this._pendingInsertion[i]; this._active.push(event); } // Clear the lists this._pendingRemoval.length = 0; this._pendingInsertion.length = 0; }, /** * [description] * * @method Phaser.Time.Clock#update * @since 3.0.0 * * @param {number} time - [description] * @param {number} delta - [description] */ update: function (time, delta) { this.now = time; if (this.paused) { return; } delta *= this.timeScale; for (var i = 0; i < this._active.length; i++) { var event = this._active[i]; if (event.paused) { continue; } // Use delta time to increase elapsed. // Avoids needing to adjust for pause / resume. // Automatically smoothed by TimeStep class. // In testing accurate to +- 1ms! event.elapsed += delta * event.timeScale; if (event.elapsed >= event.delay) { var remainder = event.elapsed - event.delay; // Limit it, in case it's checked in the callback event.elapsed = event.delay; // Process the event if (!event.hasDispatched && event.callback) { event.hasDispatched = true; event.callback.apply(event.callbackScope, event.args); } if (event.repeatCount > 0) { event.repeatCount--; event.elapsed = remainder; event.hasDispatched = false; } else { this._pendingRemoval.push(event); } } } }, /** * 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.Time.Clock#shutdown * @private * @since 3.0.0 */ shutdown: function () { var i; for (i = 0; i < this._pendingInsertion.length; i++) { this._pendingInsertion[i].destroy(); } for (i = 0; i < this._active.length; i++) { this._active[i].destroy(); } for (i = 0; i < this._pendingRemoval.length; i++) { this._pendingRemoval[i].destroy(); } this._active.length = 0; this._pendingRemoval.length = 0; this._pendingInsertion.length = 0; var eventEmitter = this.systems.events; eventEmitter.off('preupdate', this.preUpdate, this); eventEmitter.off('update', this.update, this); eventEmitter.off('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.Time.Clock#destroy * @private * @since 3.0.0 */ destroy: function () { this.shutdown(); this.scene.sys.events.off('start', this.start, this); this.scene = null; this.systems = null; } }); PluginCache.register('Clock', Clock, 'time'); module.exports = Clock; /***/ }), /* 308 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Time */ module.exports = { Clock: __webpack_require__(307), TimerEvent: __webpack_require__(164) }; /***/ }), /* 309 */, /* 310 */, /* 311 */, /* 312 */, /* 313 */, /* 314 */, /* 315 */, /* 316 */, /* 317 */, /* 318 */, /* 319 */, /* 320 */, /* 321 */, /* 322 */, /* 323 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Filter Types. * * @name Phaser.Textures.FilterMode * @enum {integer} * @memberOf Phaser.Textures * @readOnly * @since 3.0.0 */ var CONST = { /** * Linear filter type. * * @name Phaser.Textures.FilterMode.LINEAR */ LINEAR: 0, /** * Nearest neighbor filter type. * * @name Phaser.Textures.FilterMode.NEAREST */ NEAREST: 1 }; module.exports = CONST; /***/ }), /* 324 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Extend = __webpack_require__(17); var FilterMode = __webpack_require__(323); /** * @namespace Phaser.Textures */ /** * Linear filter type. * * @name Phaser.Textures.LINEAR * @constant */ /** * Nearest Neighbor filter type. * * @name Phaser.Textures.NEAREST * @constant */ var Textures = { FilterMode: FilterMode, Frame: __webpack_require__(128), Parsers: __webpack_require__(182), Texture: __webpack_require__(117), TextureManager: __webpack_require__(184), TextureSource: __webpack_require__(183) }; Textures = Extend(false, Textures, FilterMode); module.exports = Textures; /***/ }), /* 325 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Structs */ module.exports = { List: __webpack_require__(93), Map: __webpack_require__(124), ProcessQueue: __webpack_require__(223), RTree: __webpack_require__(222), Set: __webpack_require__(70) }; /***/ }), /* 326 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Sound */ /** * Config object containing various sound settings. * * @typedef {object} SoundConfig * * @property {boolean} [mute=false] - Boolean indicating whether the sound should be muted or not. * @property {number} [volume=1] - A value between 0 (silence) and 1 (full volume). * @property {number} [rate=1] - Defines the speed at which the sound should be played. * @property {number} [detune=0] - Represents detuning of sound in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). * @property {number} [seek=0] - Position of playback for this sound, in seconds. * @property {boolean} [loop=false] - Whether or not the sound or current sound marker should loop. * @property {number} [delay=0] - Time, in seconds, that should elapse before the sound actually starts its playback. */ /** * Marked section of a sound represented by name, and optionally start time, duration, and config object. * * @typedef {object} SoundMarker * * @property {string} name - Unique identifier of a sound marker. * @property {number} [start=0] - Sound position offset at witch playback should start. * @property {number} [duration] - Playback duration of this marker. * @property {SoundConfig} [config] - An optional config object containing default marker settings. */ module.exports = { SoundManagerCreator: __webpack_require__(191), BaseSound: __webpack_require__(78), BaseSoundManager: __webpack_require__(79), WebAudioSound: __webpack_require__(185), WebAudioSoundManager: __webpack_require__(186), HTML5AudioSound: __webpack_require__(189), HTML5AudioSoundManager: __webpack_require__(190), NoAudioSound: __webpack_require__(187), NoAudioSoundManager: __webpack_require__(188) }; /***/ }), /* 327 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clamp = __webpack_require__(23); var Class = __webpack_require__(0); var CONST = __webpack_require__(55); var GetFastValue = __webpack_require__(1); var PluginCache = __webpack_require__(12); /** * @classdesc * A proxy class to the Global Scene Manager. * * @class ScenePlugin * @memberOf Phaser.Scenes * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene that this ScenePlugin belongs to. */ var ScenePlugin = new Class({ initialize: function ScenePlugin (scene) { /** * The Scene that this ScenePlugin belongs to. * * @name Phaser.Scenes.ScenePlugin#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * The Scene Systems instance of the Scene that this ScenePlugin belongs to. * * @name Phaser.Scenes.ScenePlugin#systems * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.systems = scene.sys; /** * The settings of the Scene this ScenePlugin belongs to. * * @name Phaser.Scenes.ScenePlugin#settings * @type {Phaser.Scenes.Settings.Object} * @since 3.0.0 */ this.settings = scene.sys.settings; /** * The key of the Scene this ScenePlugin belongs to. * * @name Phaser.Scenes.ScenePlugin#key * @type {string} * @since 3.0.0 */ this.key = scene.sys.settings.key; /** * The Game's SceneManager. * * @name Phaser.Scenes.ScenePlugin#manager * @type {Phaser.Scenes.SceneManager} * @since 3.0.0 */ this.manager = scene.sys.game.scene; /** * If this Scene is currently transitioning to another, this holds * the current percentage of the transition progress, between 0 and 1. * * @name Phaser.Scenes.ScenePlugin#transitionProgress * @type {float} * @since 3.5.0 */ this.transitionProgress = 0; /** * Transition elapsed timer. * * @name Phaser.Scenes.ScenePlugin#_elapsed * @type {integer} * @private * @since 3.5.0 */ this._elapsed = 0; /** * Transition elapsed timer. * * @name Phaser.Scenes.ScenePlugin#_target * @type {?Phaser.Scenes.Scene} * @private * @since 3.5.0 */ this._target = null; /** * Transition duration. * * @name Phaser.Scenes.ScenePlugin#_duration * @type {integer} * @private * @since 3.5.0 */ this._duration = 0; /** * Transition callback. * * @name Phaser.Scenes.ScenePlugin#_onUpdate * @type {function} * @private * @since 3.5.0 */ this._onUpdate; /** * Transition callback scope. * * @name Phaser.Scenes.ScenePlugin#_onUpdateScope * @type {object} * @private * @since 3.5.0 */ this._onUpdateScope; /** * Will this Scene sleep (true) after the transition, or stop (false) * * @name Phaser.Scenes.ScenePlugin#_willSleep * @type {boolean} * @private * @since 3.5.0 */ this._willSleep = false; /** * Will this Scene be removed from the Scene Manager after the transition completes? * * @name Phaser.Scenes.ScenePlugin#_willRemove * @type {boolean} * @private * @since 3.5.0 */ this._willRemove = false; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('start', this.pluginStart, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Scenes.ScenePlugin#boot * @private * @since 3.0.0 */ boot: function () { this.systems.events.once('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.Scenes.ScenePlugin#pluginStart * @private * @since 3.5.0 */ pluginStart: function () { this._target = null; this.systems.events.once('shutdown', this.shutdown, this); }, /** * Shutdown this Scene and run the given one. * * @method Phaser.Scenes.ScenePlugin#start * @since 3.0.0 * * @param {string} key - The Scene to start. * @param {object} [data] - The Scene data. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ start: function (key, data) { if (key === undefined) { key = this.key; } if (this.settings.status !== CONST.RUNNING) { this.manager.queueOp('stop', this.key); this.manager.queueOp('start', key, data); } else { this.manager.stop(this.key); this.manager.start(key, data); } return this; }, /** * Restarts this Scene. * * @method Phaser.Scenes.ScenePlugin#restart * @since 3.4.0 * * @param {object} [data] - The Scene data. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ restart: function (data) { var key = this.key; if (this.settings.status !== CONST.RUNNING) { this.manager.queueOp('stop', key); this.manager.queueOp('start', key, data); } else { this.manager.stop(key); this.manager.start(key, data); } return this; }, /** * @typedef {object} Phaser.Scenes.ScenePlugin.SceneTransitionConfig * * @property {string} target - The Scene key to transition to. * @property {integer} [duration=1000] - The duration, in ms, for the transition to last. * @property {boolean} [sleep=false] - Will the Scene responsible for the transition be sent to sleep on completion (`true`), or stopped? (`false`) * @property {boolean} [allowInput=false] - Will the Scenes Input system be able to process events while it is transitioning in or out? * @property {boolean} [moveAbove] - Move the target Scene to be above this one before the transition starts. * @property {boolean} [moveBelow] - Move the target Scene to be below this one before the transition starts. * @property {function} [onUpdate] - This callback is invoked every frame for the duration of the transition. * @property {any} [onUpdateScope] - The context in which the callback is invoked. * @property {any} [data] - An object containing any data you wish to be passed to the target Scenes init / create methods. */ /** * This will start a transition from the current Scene to the target Scene given. * * The transition will last for the duration specified in milliseconds. * * You can have the target Scene moved above or below this one in the display list. * * You can specify an update callback. This callback will be invoked _every frame_ for the duration * of the transition. * * This Scene can either be sent to sleep at the end of the transition, or stopped. The default is to stop. * * There are also 5 transition related events: This scene will emit the event `transitionto` when * the transition begins, which is typically the frame after calling this method. * * The target Scene will emit the event `transitioninit` when that Scene's `init` method is called. * It will then emit the event `transitionstart` when its `create` method is called. * If the Scene was sleeping and has been woken up, it will emit the event `transitionwake` instead of these two, * as the Scenes `init` and `create` methods are not invoked when a sleep wakes up. * * When the duration of the transition has elapsed it will emit the event `transitioncomplete`. * These events are all cleared of listeners when the Scene shuts down, but not if it is sent to sleep. * * It's important to understand that the duration of the transition begins the moment you call this method. * If the Scene you are transitioning to includes delayed processes, such as waiting for files to load, the * time still counts down even while that is happening. If the game itself pauses, or something else causes * this Scenes update loop to stop, then the transition will also pause for that duration. There are * checks in place to prevent you accidentally stopping a transitioning Scene but if you've got code to * override this understand that until the target Scene completes it might never be unlocked for input events. * * @method Phaser.Scenes.ScenePlugin#transition * @since 3.5.0 * * @param {Phaser.Scenes.ScenePlugin.SceneTransitionConfig} config - The transition configuration object. * * @return {boolean} `true` is the transition was started, otherwise `false`. */ transition: function (config) { if (config === undefined) { config = {}; } var key = GetFastValue(config, 'target', false); var target = this.manager.getScene(key); if (!key || !this.checkValidTransition(target)) { return false; } var duration = GetFastValue(config, 'duration', 1000); this._elapsed = 0; this._target = target; this._duration = duration; this._willSleep = GetFastValue(config, 'sleep', false); this._willRemove = GetFastValue(config, 'remove', false); var callback = GetFastValue(config, 'onUpdate', null); if (callback) { this._onUpdate = callback; this._onUpdateScope = GetFastValue(config, 'onUpdateScope', this.scene); } var allowInput = GetFastValue(config, 'allowInput', false); this.settings.transitionAllowInput = allowInput; var targetSettings = target.sys.settings; targetSettings.isTransition = true; targetSettings.transitionFrom = this.scene; targetSettings.transitionDuration = duration; targetSettings.transitionAllowInput = allowInput; if (GetFastValue(config, 'moveAbove', false)) { this.manager.moveAbove(this.key, key); } else if (GetFastValue(config, 'moveBelow', false)) { this.manager.moveBelow(this.key, key); } if (target.sys.isSleeping()) { target.sys.wake(); } else { this.manager.start(key, GetFastValue(config, 'data')); } this.systems.events.emit('transitionout', target, duration); this.systems.events.on('update', this.step, this); return true; }, /** * Checks to see if this Scene can transition to the target Scene or not. * * @method Phaser.Scenes.ScenePlugin#checkValidTransition * @private * @since 3.5.0 * * @param {Phaser.Scene} target - The Scene to test against. * * @return {boolean} `true` if this Scene can transition, otherwise `false`. */ checkValidTransition: function (target) { // Not a valid target if it doesn't exist, isn't active or is already transitioning in or out if (!target || target.sys.isActive() || target.sys.isTransitioning() || target === this.scene || this.systems.isTransitioning()) { return false; } return true; }, /** * A single game step. This is only called if the parent Scene is transitioning * out to another Scene. * * @method Phaser.Scenes.ScenePlugin#step * @private * @since 3.5.0 * * @param {number} time - [description] * @param {number} delta - [description] */ step: function (time, delta) { this._elapsed += delta; this.transitionProgress = Clamp(this._elapsed / this._duration, 0, 1); if (this._onUpdate) { this._onUpdate.call(this._onUpdateScope, this.transitionProgress); } if (this._elapsed >= this._duration) { this.transitionComplete(); } }, /** * Called by `step` when the transition out of this scene to another is over. * * @method Phaser.Scenes.ScenePlugin#transitionComplete * @private * @since 3.5.0 */ transitionComplete: function () { var targetSys = this._target.sys; var targetSettings = this._target.sys.settings; // Stop the step this.systems.events.off('update', this.step, this); // Notify target scene targetSys.events.emit('transitioncomplete', this.scene); // Clear target scene settings targetSettings.isTransition = false; targetSettings.transitionFrom = null; // Clear local settings this._duration = 0; this._target = null; this._onUpdate = null; this._onUpdateScope = null; // Now everything is clear we can handle what happens to this Scene if (this._willRemove) { this.manager.remove(this.key); } else if (this._willSleep) { this.systems.sleep(); } else { this.manager.stop(this.key); } }, /** * Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set. * * @method Phaser.Scenes.ScenePlugin#add * @since 3.0.0 * * @param {string} key - The Scene key. * @param {(Phaser.Scene|Phaser.Scenes.Settings.Config|function)} sceneConfig - The config for the Scene. * @param {boolean} autoStart - Whether to start the Scene after it's added. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ add: function (key, sceneConfig, autoStart) { this.manager.add(key, sceneConfig, autoStart); return this; }, /** * Launch the given Scene and run it in parallel with this one. * * @method Phaser.Scenes.ScenePlugin#launch * @since 3.0.0 * * @param {string} key - The Scene to launch. * @param {object} [data] - The Scene data. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ launch: function (key, data) { if (key && key !== this.key) { if (this.settings.status !== CONST.RUNNING) { this.manager.queueOp('start', key, data); } else { this.manager.start(key, data); } } return this; }, /** * Runs the given Scene, but does not change the state of this Scene. * * If the given Scene is paused, it will resume it. If sleeping, it will wake it. * If not running at all, it will be started. * * Use this if you wish to open a modal Scene by calling `pause` on the current * Scene, then `run` on the modal Scene. * * @method Phaser.Scenes.ScenePlugin#run * @since 3.10.0 * * @param {string} key - The Scene to run. * @param {object} [data] - A data object that will be passed to the Scene that is run _only if the Scene isn't asleep or paused_. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ run: function (key, data) { if (this.settings.status !== CONST.RUNNING) { this.manager.queueOp('run', key, data); } else { this.manager.run(key, data); } return this; }, /** * Pause the Scene - this stops the update step from happening but it still renders. * * @method Phaser.Scenes.ScenePlugin#pause * @since 3.0.0 * * @param {string} key - The Scene to pause. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ pause: function (key) { if (key === undefined) { key = this.key; } this.manager.pause(key); return this; }, /** * Resume the Scene - starts the update loop again. * * @method Phaser.Scenes.ScenePlugin#resume * @since 3.0.0 * * @param {string} key - The Scene to resume. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ resume: function (key) { if (key === undefined) { key = this.key; } this.manager.resume(key); return this; }, /** * Makes the Scene sleep (no update, no render) but doesn't shutdown. * * @method Phaser.Scenes.ScenePlugin#sleep * @since 3.0.0 * * @param {string} key - The Scene to put to sleep. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ sleep: function (key) { if (key === undefined) { key = this.key; } this.manager.sleep(key); return this; }, /** * Makes the Scene wake-up (starts update and render) * * @method Phaser.Scenes.ScenePlugin#wake * @since 3.0.0 * * @param {string} key - The Scene to wake up. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ wake: function (key) { if (key === undefined) { key = this.key; } this.manager.wake(key); return this; }, /** * Makes this Scene sleep then starts the Scene given. * * @method Phaser.Scenes.ScenePlugin#switch * @since 3.0.0 * * @param {string} key - The Scene to start. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ switch: function (key) { if (key !== this.key) { if (this.settings.status !== CONST.RUNNING) { this.manager.queueOp('switch', this.key, key); } else { this.manager.switch(this.key, key); } } return this; }, /** * Shutdown the Scene, clearing display list, timers, etc. * * @method Phaser.Scenes.ScenePlugin#stop * @since 3.0.0 * * @param {string} key - The Scene to stop. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ stop: function (key) { if (key === undefined) { key = this.key; } this.manager.stop(key); return this; }, /** * Sets the active state of the given Scene. * * @method Phaser.Scenes.ScenePlugin#setActive * @since 3.0.0 * * @param {boolean} value - The active value. * @param {string} [key] - The Scene to set the active state for. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ setActive: function (value, key) { if (key === undefined) { key = this.key; } var scene = this.manager.getScene(key); if (scene) { scene.sys.setActive(value); } return this; }, /** * Sets the visible state of the given Scene. * * @method Phaser.Scenes.ScenePlugin#setVisible * @since 3.0.0 * * @param {boolean} value - The visible value. * @param {string} [key] - The Scene to set the visible state for. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ setVisible: function (value, key) { if (key === undefined) { key = this.key; } var scene = this.manager.getScene(key); if (scene) { scene.sys.setVisible(value); } return this; }, /** * Checks if the given Scene is sleeping or not? * * @method Phaser.Scenes.ScenePlugin#isSleeping * @since 3.0.0 * * @param {string} key - The Scene to check. * * @return {boolean} Whether the Scene is sleeping. */ isSleeping: function (key) { if (key === undefined) { key = this.key; } return this.manager.isSleeping(key); }, /** * Checks if the given Scene is active or not? * * @method Phaser.Scenes.ScenePlugin#isActive * @since 3.0.0 * * @param {string} key - The Scene to check. * * @return {boolean} Whether the Scene is active. */ isActive: function (key) { if (key === undefined) { key = this.key; } return this.manager.isActive(key); }, /** * Checks if the given Scene is visible or not? * * @method Phaser.Scenes.ScenePlugin#isVisible * @since 3.0.0 * * @param {string} key - The Scene to check. * * @return {boolean} Whether the Scene is visible. */ isVisible: function (key) { if (key === undefined) { key = this.key; } return this.manager.isVisible(key); }, /** * Swaps the position of two scenes in the Scenes list. * * This controls the order in which they are rendered and updated. * * @method Phaser.Scenes.ScenePlugin#swapPosition * @since 3.2.0 * * @param {string} keyA - The first Scene to swap. * @param {string} [keyB] - The second Scene to swap. If none is given it defaults to this Scene. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ swapPosition: function (keyA, keyB) { if (keyB === undefined) { keyB = this.key; } if (keyA !== keyB) { this.manager.swapPosition(keyA, keyB); } return this; }, /** * Swaps the position of two scenes in the Scenes list, so that Scene B is directly above Scene A. * * This controls the order in which they are rendered and updated. * * @method Phaser.Scenes.ScenePlugin#moveAbove * @since 3.2.0 * * @param {string} keyA - The Scene that Scene B will be moved to be above. * @param {string} [keyB] - The Scene to be moved. If none is given it defaults to this Scene. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ moveAbove: function (keyA, keyB) { if (keyB === undefined) { keyB = this.key; } if (keyA !== keyB) { this.manager.moveAbove(keyA, keyB); } return this; }, /** * Swaps the position of two scenes in the Scenes list, so that Scene B is directly below Scene A. * * This controls the order in which they are rendered and updated. * * @method Phaser.Scenes.ScenePlugin#moveBelow * @since 3.2.0 * * @param {string} keyA - The Scene that Scene B will be moved to be below. * @param {string} [keyB] - The Scene to be moved. If none is given it defaults to this Scene. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ moveBelow: function (keyA, keyB) { if (keyB === undefined) { keyB = this.key; } if (keyA !== keyB) { this.manager.moveBelow(keyA, keyB); } return this; }, /** * Removes a Scene from the SceneManager. * * The Scene is removed from the local scenes array, it's key is cleared from the keys * cache and Scene.Systems.destroy is then called on it. * * If the SceneManager is processing the Scenes when this method is called it wil * queue the operation for the next update sequence. * * @method Phaser.Scenes.ScenePlugin#remove * @since 3.2.0 * * @param {(string|Phaser.Scene)} key - The Scene to be removed. * * @return {Phaser.Scenes.SceneManager} This SceneManager. */ remove: function (key) { if (key === undefined) { key = this.key; } this.manager.remove(key); return this; }, /** * Moves a Scene up one position in the Scenes list. * * @method Phaser.Scenes.ScenePlugin#moveUp * @since 3.0.0 * * @param {string} key - The Scene to move. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ moveUp: function (key) { if (key === undefined) { key = this.key; } this.manager.moveUp(key); return this; }, /** * Moves a Scene down one position in the Scenes list. * * @method Phaser.Scenes.ScenePlugin#moveDown * @since 3.0.0 * * @param {string} key - The Scene to move. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ moveDown: function (key) { if (key === undefined) { key = this.key; } this.manager.moveDown(key); return this; }, /** * Brings a Scene to the top of the Scenes list. * * This means it will render above all other Scenes. * * @method Phaser.Scenes.ScenePlugin#bringToTop * @since 3.0.0 * * @param {string} key - The Scene to move. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ bringToTop: function (key) { if (key === undefined) { key = this.key; } this.manager.bringToTop(key); return this; }, /** * Sends a Scene to the back of the Scenes list. * * This means it will render below all other Scenes. * * @method Phaser.Scenes.ScenePlugin#sendToBack * @since 3.0.0 * * @param {string} key - The Scene to move. * * @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object. */ sendToBack: function (key) { if (key === undefined) { key = this.key; } this.manager.sendToBack(key); return this; }, /** * Retrieve a Scene. * * @method Phaser.Scenes.ScenePlugin#get * @since 3.0.0 * * @param {string} key - The Scene to retrieve. * * @return {Phaser.Scene} The Scene. */ get: function (key) { return this.manager.getScene(key); }, /** * Retrieves the numeric index of a Scene in the Scenes list. * * @method Phaser.Scenes.ScenePlugin#getIndex * @since 3.7.0 * * @param {(string|Phaser.Scene)} [key] - The Scene to get the index of. * * @return {integer} The index of the Scene. */ getIndex: function (key) { if (key === undefined) { key = this.key; } return this.manager.getIndex(key); }, /** * 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.Scenes.ScenePlugin#shutdown * @private * @since 3.0.0 */ shutdown: function () { var eventEmitter = this.systems.events; eventEmitter.off('shutdown', this.shutdown, this); eventEmitter.off('postupdate', this.step, this); eventEmitter.off('transitionout'); }, /** * The Scene that owns this plugin is being destroyed. * We need to shutdown and then kill off all external references. * * @method Phaser.Scenes.ScenePlugin#destroy * @private * @since 3.0.0 */ destroy: function () { this.shutdown(); this.scene.sys.events.off('start', this.start, this); this.scene = null; this.systems = null; this.settings = null; this.manager = null; } }); PluginCache.register('ScenePlugin', ScenePlugin, 'scenePlugin'); module.exports = ScenePlugin; /***/ }), /* 328 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CONST = __webpack_require__(55); var Extend = __webpack_require__(17); /** * @namespace Phaser.Scenes */ var Scene = { SceneManager: __webpack_require__(194), ScenePlugin: __webpack_require__(327), Settings: __webpack_require__(192), Systems: __webpack_require__(118) }; // Merge in the consts Scene = Extend(false, Scene, CONST); module.exports = Scene; /***/ }), /* 329 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser3-plugin-template/blob/master/LICENSE|MIT License} */ var BasePlugin = __webpack_require__(165); var Class = __webpack_require__(0); /** * @classdesc * A Scene Level Plugin is installed into every Scene and belongs to that Scene. * It can listen for Scene events and respond to them. * It can map itself to a Scene property, or into the Scene Systems, or both. * * @class ScenePlugin * @memberOf Phaser.Plugins * @extends Phaser.Plugins.BasePlugin * @constructor * @since 3.8.0 * * @param {Phaser.Scene} scene - A reference to the Scene that has installed this plugin. * @param {Phaser.Plugins.PluginManager} pluginManager - A reference to the Plugin Manager. */ var ScenePlugin = new Class({ Extends: BasePlugin, initialize: function ScenePlugin (scene, pluginManager) { BasePlugin.call(this, pluginManager); /** * A reference to the Scene that has installed this plugin. * This property is only set when the plugin is instantiated and added to the Scene, not before. * * @name Phaser.Plugins.ScenePlugin#scene * @type {?Phaser.Scene} * @protected * @since 3.8.0 */ this.scene = scene; /** * A reference to the Scene Systems of the Scene that has installed this plugin. * This property is only set when the plugin is instantiated and added to the Scene, not before. * * @name Phaser.Plugins.ScenePlugin#systems * @type {?Phaser.Scenes.Systems} * @protected * @since 3.8.0 */ this.systems = scene.sys; scene.sys.events.once('boot', this.boot, this); }, /** * This method is called when the Scene boots. It is only ever called once. * * By this point the plugin properties `scene` and `systems` will have already been set. * * In here you can listen for Scene events and set-up whatever you need for this plugin to run. * Here are the Scene events you can listen to: * * start * ready * preupdate * update * postupdate * resize * pause * resume * sleep * wake * transitioninit * transitionstart * transitioncomplete * transitionout * shutdown * destroy * * At the very least you should offer a destroy handler for when the Scene closes down, i.e: * * ```javascript * var eventEmitter = this.systems.events; * eventEmitter.once('destroy', this.sceneDestroy, this); * ``` * * @method Phaser.Plugins.ScenePlugin#boot * @since 3.8.0 */ boot: function () { } }); module.exports = ScenePlugin; /***/ }), /* 330 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Plugins */ module.exports = { BasePlugin: __webpack_require__(165), DefaultPlugins: __webpack_require__(121), PluginCache: __webpack_require__(12), PluginManager: __webpack_require__(196), ScenePlugin: __webpack_require__(329) }; /***/ }), /* 331 */, /* 332 */, /* 333 */, /* 334 */, /* 335 */, /* 336 */, /* 337 */, /* 338 */, /* 339 */, /* 340 */, /* 341 */, /* 342 */, /* 343 */, /* 344 */, /* 345 */, /* 346 */, /* 347 */, /* 348 */, /* 349 */, /* 350 */, /* 351 */, /* 352 */, /* 353 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(18); var CustomSet = __webpack_require__(70); var EventEmitter = __webpack_require__(9); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var PluginCache = __webpack_require__(12); var XHRSettings = __webpack_require__(75); /** * @classdesc * The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files. * You typically interact with it via `this.load` in your Scene. Scenes can have a `preload` method, which is always * called before the Scenes `create` method, allowing you to preload assets that the Scene may need. * * If you call any `this.load` methods from outside of `Scene.preload` then you need to start the Loader going * yourself by calling `Loader.start()`. It's only automatically started during the Scene preload. * * The Loader uses a combination of tag loading (eg. Audio elements) and XHR and provides progress and completion events. * Files are loaded in parallel by default. The amount of concurrent connections can be controlled in your Game Configuration. * * Once the Loader has started loading you are still able to add files to it. These can be injected as a result of a loader * event, the type of file being loaded (such as a pack file) or other external events. As long as the Loader hasn't finished * simply adding a new file to it, while running, will ensure it's added into the current queue. * * Every Scene has its own instance of the Loader and they are bound to the Scene in which they are created. However, * assets loaded by the Loader are placed into global game-level caches. For example, loading an XML file will place that * file inside `Game.cache.xml`, which is accessible from every Scene in your game, no matter who was responsible * for loading it. The same is true of Textures. A texture loaded in one Scene is instantly available to all other Scenes * in your game. * * The Loader works by using custom File Types. These are stored in the FileTypesManager, which injects them into the Loader * when it's instantiated. You can create your own custom file types by extending either the File or MultiFile classes. * See those files for more details. * * @class LoaderPlugin * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Loader * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene which owns this Loader instance. */ var LoaderPlugin = new Class({ Extends: EventEmitter, initialize: function LoaderPlugin (scene) { EventEmitter.call(this); var gameConfig = scene.sys.game.config; var sceneConfig = scene.sys.settings.loader; /** * The Scene which owns this Loader instance. * * @name Phaser.Loader.LoaderPlugin#scene * @type {Phaser.Scene} * @protected * @since 3.0.0 */ this.scene = scene; /** * A reference to the Scene Systems. * * @name Phaser.Loader.LoaderPlugin#systems * @type {Phaser.Scenes.Systems} * @protected * @since 3.0.0 */ this.systems = scene.sys; /** * A reference to the global Cache Manager. * * @name Phaser.Loader.LoaderPlugin#cacheManager * @type {Phaser.Cache.CacheManager} * @protected * @since 3.7.0 */ this.cacheManager = scene.sys.cache; /** * A reference to the global Texture Manager. * * @name Phaser.Loader.LoaderPlugin#textureManager * @type {Phaser.Textures.TextureManager} * @protected * @since 3.7.0 */ this.textureManager = scene.sys.textures; // Inject the available filetypes into the Loader FileTypesManager.install(this); /** * An optional prefix that is automatically prepended to the start of every file key. * If prefix was `MENU.` and you load an image with the key 'Background' the resulting key would be `MENU.Background`. * You can set this directly, or call `Loader.setPrefix()`. It will then affect every file added to the Loader * from that point on. It does _not_ change any file already in the load queue. * * @name Phaser.Loader.LoaderPlugin#prefix * @type {string} * @default '' * @since 3.7.0 */ this.prefix = ''; /** * The value of `path`, if set, is placed before any _relative_ file path given. For example: * * ```javascript * this.load.path = "images/sprites/"; * this.load.image("ball", "ball.png"); * this.load.image("tree", "level1/oaktree.png"); * this.load.image("boom", "http://server.com/explode.png"); * ``` * * Would load the `ball` file from `images/sprites/ball.png` and the tree from * `images/sprites/level1/oaktree.png` but the file `boom` would load from the URL * given as it's an absolute URL. * * Please note that the path is added before the filename but *after* the baseURL (if set.) * * If you set this property directly then it _must_ end with a "/". Alternatively, call `setPath()` and it'll do it for you. * * @name Phaser.Loader.LoaderPlugin#path * @type {string} * @default '' * @since 3.0.0 */ this.path = ''; /** * If you want to append a URL before the path of any asset you can set this here. * * Useful if allowing the asset base url to be configured outside of the game code. * * If you set this property directly then it _must_ end with a "/". Alternatively, call `setBaseURL()` and it'll do it for you. * * @name Phaser.Loader.LoaderPlugin#baseURL * @type {string} * @default '' * @since 3.0.0 */ this.baseURL = ''; this.setBaseURL(GetFastValue(sceneConfig, 'baseURL', gameConfig.loaderBaseURL)); this.setPath(GetFastValue(sceneConfig, 'path', gameConfig.loaderPath)); this.setPrefix(GetFastValue(sceneConfig, 'prefix', gameConfig.loaderPrefix)); /** * The number of concurrent / parallel resources to try and fetch at once. * * Old browsers limit 6 requests per domain; modern ones, especially those with HTTP/2 don't limit it at all. * * The default is 32 but you can change this in your Game Config, or by changing this property before the Loader starts. * * @name Phaser.Loader.LoaderPlugin#maxParallelDownloads * @type {integer} * @since 3.0.0 */ this.maxParallelDownloads = GetFastValue(sceneConfig, 'maxParallelDownloads', gameConfig.loaderMaxParallelDownloads); /** * xhr specific global settings (can be overridden on a per-file basis) * * @name Phaser.Loader.LoaderPlugin#xhr * @type {XHRSettingsObject} * @since 3.0.0 */ this.xhr = XHRSettings( GetFastValue(sceneConfig, 'responseType', gameConfig.loaderResponseType), GetFastValue(sceneConfig, 'async', gameConfig.loaderAsync), GetFastValue(sceneConfig, 'user', gameConfig.loaderUser), GetFastValue(sceneConfig, 'password', gameConfig.loaderPassword), GetFastValue(sceneConfig, 'timeout', gameConfig.loaderTimeout) ); /** * The crossOrigin value applied to loaded images. Very often this needs to be set to 'anonymous'. * * @name Phaser.Loader.LoaderPlugin#crossOrigin * @type {string} * @since 3.0.0 */ this.crossOrigin = GetFastValue(sceneConfig, 'crossOrigin', gameConfig.loaderCrossOrigin); /** * The total number of files to load. It may not always be accurate because you may add to the Loader during the process * of loading, especially if you load a Pack File. Therefore this value can change, but in most cases remains static. * * @name Phaser.Loader.LoaderPlugin#totalToLoad * @type {integer} * @default 0 * @since 3.0.0 */ this.totalToLoad = 0; /** * The progress of the current load queue, as a float value between 0 and 1. * This is updated automatically as files complete loading. * Note that it is possible for this value to go down again if you add content to the current load queue during a load. * * @name Phaser.Loader.LoaderPlugin#progress * @type {float} * @default 0 * @since 3.0.0 */ this.progress = 0; /** * Files are placed in this Set when they're added to the Loader via `addFile`. * * They are moved to the `inflight` Set when they start loading, and assuming a successful * load, to the `queue` Set for further processing. * * By the end of the load process this Set will be empty. * * @name Phaser.Loader.LoaderPlugin#list * @type {Phaser.Structs.Set.} * @since 3.0.0 */ this.list = new CustomSet(); /** * Files are stored in this Set while they're in the process of being loaded. * * Upon a successful load they are moved to the `queue` Set. * * By the end of the load process this Set will be empty. * * @name Phaser.Loader.LoaderPlugin#inflight * @type {Phaser.Structs.Set.} * @since 3.0.0 */ this.inflight = new CustomSet(); /** * Files are stored in this Set while they're being processed. * * If the process is successful they are moved to their final destination, which could be * a Cache or the Texture Manager. * * At the end of the load process this Set will be empty. * * @name Phaser.Loader.LoaderPlugin#queue * @type {Phaser.Structs.Set.} * @since 3.0.0 */ this.queue = new CustomSet(); /** * A temporary Set in which files are stored after processing, * awaiting destruction at the end of the load process. * * @name Phaser.Loader.LoaderPlugin#_deleteQueue * @type {Phaser.Structs.Set.} * @private * @since 3.7.0 */ this._deleteQueue = new CustomSet(); /** * The total number of files that failed to load during the most recent load. * This value is reset when you call `Loader.start`. * * @name Phaser.Loader.LoaderPlugin#totalFailed * @type {integer} * @default 0 * @since 3.7.0 */ this.totalFailed = 0; /** * The total number of files that successfully loaded during the most recent load. * This value is reset when you call `Loader.start`. * * @name Phaser.Loader.LoaderPlugin#totalComplete * @type {integer} * @default 0 * @since 3.7.0 */ this.totalComplete = 0; /** * The current state of the Loader. * * @name Phaser.Loader.LoaderPlugin#state * @type {integer} * @readOnly * @since 3.0.0 */ this.state = CONST.LOADER_IDLE; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('start', this.pluginStart, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Loader.LoaderPlugin#boot * @private * @since 3.5.1 */ boot: function () { this.systems.events.once('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.Loader.LoaderPlugin#pluginStart * @private * @since 3.5.1 */ pluginStart: function () { this.systems.events.once('shutdown', this.shutdown, this); }, /** * If you want to append a URL before the path of any asset you can set this here. * * Useful if allowing the asset base url to be configured outside of the game code. * * Once a base URL is set it will affect every file loaded by the Loader from that point on. It does _not_ change any * file _already_ being loaded. To reset it, call this method with no arguments. * * @method Phaser.Loader.LoaderPlugin#setBaseURL * @since 3.0.0 * * @param {string} [url] - The URL to use. Leave empty to reset. * * @return {Phaser.Loader.LoaderPlugin} This Loader object. */ setBaseURL: function (url) { if (url === undefined) { url = ''; } if (url !== '' && url.substr(-1) !== '/') { url = url.concat('/'); } this.baseURL = url; return this; }, /** * The value of `path`, if set, is placed before any _relative_ file path given. For example: * * ```javascript * this.load.setPath("images/sprites/"); * this.load.image("ball", "ball.png"); * this.load.image("tree", "level1/oaktree.png"); * this.load.image("boom", "http://server.com/explode.png"); * ``` * * Would load the `ball` file from `images/sprites/ball.png` and the tree from * `images/sprites/level1/oaktree.png` but the file `boom` would load from the URL * given as it's an absolute URL. * * Please note that the path is added before the filename but *after* the baseURL (if set.) * * Once a path is set it will then affect every file added to the Loader from that point on. It does _not_ change any * file _already_ in the load queue. To reset it, call this method with no arguments. * * @method Phaser.Loader.LoaderPlugin#setPath * @since 3.0.0 * * @param {string} [path] - The path to use. Leave empty to reset. * * @return {Phaser.Loader.LoaderPlugin} This Loader object. */ setPath: function (path) { if (path === undefined) { path = ''; } if (path !== '' && path.substr(-1) !== '/') { path = path.concat('/'); } this.path = path; return this; }, /** * An optional prefix that is automatically prepended to the start of every file key. * * If prefix was `MENU.` and you load an image with the key 'Background' the resulting key would be `MENU.Background`. * * Once a prefix is set it will then affect every file added to the Loader from that point on. It does _not_ change any * file _already_ in the load queue. To reset it, call this method with no arguments. * * @method Phaser.Loader.LoaderPlugin#setPrefix * @since 3.7.0 * * @param {string} [prefix] - The prefix to use. Leave empty to reset. * * @return {Phaser.Loader.LoaderPlugin} This Loader object. */ setPrefix: function (prefix) { if (prefix === undefined) { prefix = ''; } this.prefix = prefix; return this; }, /** * Sets the Cross Origin Resource Sharing value used when loading files. * * Files can override this value on a per-file basis by specifying an alternative `crossOrigin` value in their file config. * * Once CORs is set it will then affect every file loaded by the Loader from that point on, as long as they don't have * their own CORs setting. To reset it, call this method with no arguments. * * For more details about CORs see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS * * @method Phaser.Loader.LoaderPlugin#setCORS * @since 3.0.0 * * @param {string} [crossOrigin] - The value to use for the `crossOrigin` property in the load request. * * @return {Phaser.Loader.LoaderPlugin} This Loader object. */ setCORS: function (crossOrigin) { this.crossOrigin = crossOrigin; return this; }, /** * This event is fired when a Loader successfully begins to load its queue. * * @event Phaser.Loader.LoaderPlugin#addFileEvent * @param {string} key - The key of the file that was added. * @param {string} type - The type of the file that was added. * @param {Phaser.Loader.LoaderPlugin} loader - The Loader that had the file added to it. * @param {Phaser.Loader.File} loader - The File object that was added to the Loader. */ /** * Adds a file, or array of files, into the load queue. * * The file must be an instance of `Phaser.Loader.File`, or a class that extends it. The Loader will check that the key * used by the file won't conflict with any other key either in the loader, the inflight queue or the target cache. * If allowed it will then add the file into the pending list, read for the load to start. Or, if the load has already * started, ready for the next batch of files to be pulled from the list to the inflight queue. * * You should not normally call this method directly, but rather use one of the Loader methods like `image` or `atlas`, * however you can call this as long as the file given to it is well formed. * * @method Phaser.Loader.LoaderPlugin#addFile * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(Phaser.Loader.File|Phaser.Loader.File[])} file - The file, or array of files, to be added to the load queue. */ addFile: function (file) { if (!Array.isArray(file)) { file = [ file ]; } for (var i = 0; i < file.length; i++) { var item = file[i]; // Does the file already exist in the cache or texture manager? // Or will it conflict with a file already in the queue or inflight? if (!this.keyExists(item)) { this.list.set(item); this.emit('addfile', item.key, item.type, this, item); if (this.isLoading()) { this.totalToLoad++; this.updateProgress(); } } } }, /** * Checks the key and type of the given file to see if it will conflict with anything already * in a Cache, the Texture Manager, or the list or inflight queues. * * @method Phaser.Loader.LoaderPlugin#keyExists * @since 3.7.0 * * @param {Phaser.Loader.File} file - The file to check the key of. * * @return {boolean} `true` if adding this file will cause a cache or queue conflict, otherwise `false`. */ keyExists: function (file) { var keyConflict = file.hasCacheConflict(); if (!keyConflict) { this.list.iterate(function (item) { if (item.type === file.type && item.key === file.key) { keyConflict = true; return false; } }); } if (!keyConflict && this.isLoading()) { this.inflight.iterate(function (item) { if (item.type === file.type && item.key === file.key) { keyConflict = true; return false; } }); this.queue.iterate(function (item) { if (item.type === file.type && item.key === file.key) { keyConflict = true; return false; } }); } return keyConflict; }, /** * Takes a well formed, fully parsed pack file object and adds its entries into the load queue. Usually you do not call * this method directly, but instead use `Loader.pack` and supply a path to a JSON file that holds the * pack data. However, if you've got the data prepared you can pass it to this method. * * You can also provide an optional key. If you do then it will only add the entries from that part of the pack into * to the load queue. If not specified it will add all entries it finds. For more details about the pack file format * see the `LoaderPlugin.pack` method. * * @method Phaser.Loader.LoaderPlugin#addPack * @since 3.7.0 * * @param {any} data - The Pack File data to be parsed and each entry of it to added to the load queue. * @param {string} [packKey] - An optional key to use from the pack file data. * * @return {boolean} `true` if any files were added to the queue, otherwise `false`. */ addPack: function (pack, packKey) { // if no packKey provided we'll add everything to the queue if (packKey && pack.hasOwnProperty(packKey)) { pack = { packKey: pack[packKey] }; } var total = 0; // Store the loader settings in case this pack replaces them var currentBaseURL = this.baseURL; var currentPath = this.path; var currentPrefix = this.prefix; // Here we go ... for (var key in pack) { var config = pack[key]; // Any meta data to process? var baseURL = GetFastValue(config, 'baseURL', currentBaseURL); var path = GetFastValue(config, 'path', currentPath); var prefix = GetFastValue(config, 'prefix', currentPrefix); var files = GetFastValue(config, 'files', null); var defaultType = GetFastValue(config, 'defaultType', 'void'); if (Array.isArray(files)) { this.setBaseURL(baseURL); this.setPath(path); this.setPrefix(prefix); for (var i = 0; i < files.length; i++) { var file = files[i]; var type = (file.hasOwnProperty('type')) ? file.type : defaultType; if (this[type]) { this[type](file); total++; } } } } // Reset the loader settings this.setBaseURL(currentBaseURL); this.setPath(currentPath); this.setPrefix(currentPrefix); return (total > 0); }, /** * Is the Loader actively loading, or processing loaded files? * * @method Phaser.Loader.LoaderPlugin#isLoading * @since 3.0.0 * * @return {boolean} `true` if the Loader is busy loading or processing, otherwise `false`. */ isLoading: function () { return (this.state === CONST.LOADER_LOADING || this.state === CONST.LOADER_PROCESSING); }, /** * Is the Loader ready to start a new load? * * @method Phaser.Loader.LoaderPlugin#isReady * @since 3.0.0 * * @return {boolean} `true` if the Loader is ready to start a new load, otherwise `false`. */ isReady: function () { return (this.state === CONST.LOADER_IDLE || this.state === CONST.LOADER_COMPLETE); }, /** * This event is fired when a Loader successfully begins to load its queue. * * @event Phaser.Loader.LoaderPlugin#startEvent * @param {Phaser.Loader.LoaderPlugin} loader - The Loader instance that started. */ /** * Starts the Loader running. This will reset the progress and totals and then emit a `start` event. * If there is nothing in the queue the Loader will immediately complete, otherwise it will start * loading the first batch of files. * * The Loader is started automatically if the queue is populated within your Scenes `preload` method. * * However, outside of this, you need to call this method to start it. * * If the Loader is already running this method will simply return. * * @method Phaser.Loader.LoaderPlugin#start * @fires Phaser.Loader.LoaderPlugin#startEvent * @since 3.0.0 */ start: function () { if (!this.isReady()) { return; } this.progress = 0; this.totalFailed = 0; this.totalComplete = 0; this.totalToLoad = this.list.size; this.emit('start', this); if (this.list.size === 0) { this.loadComplete(); } else { this.state = CONST.LOADER_LOADING; this.inflight.clear(); this.queue.clear(); this.updateProgress(); this.checkLoadQueue(); this.systems.events.on('update', this.update, this); } }, /** * This event is fired when the Loader updates its progress, typically as a result of * a file having completed loading. * * @event Phaser.Loader.LoaderPlugin#progressEvent * @param {float} progress - The current progress of the load. A value between 0 and 1. */ /** * Called automatically during the load process. * It updates the `progress` value and then emits a progress event, which you can use to * display a loading bar in your game. * * @method Phaser.Loader.LoaderPlugin#updateProgress * @fires Phaser.Loader.LoaderPlugin#progressEvent * @since 3.0.0 */ updateProgress: function () { this.progress = 1 - ((this.list.size + this.inflight.size) / this.totalToLoad); this.emit('progress', this.progress); }, /** * Called automatically during the load process. * * @method Phaser.Loader.LoaderPlugin#update * @since 3.10.0 */ update: function () { if (this.state === CONST.LOADER_LOADING && this.list.size > 0 && this.inflight.size < this.maxParallelDownloads) { this.checkLoadQueue(); } }, /** * An internal method called by the Loader. * * It will check to see if there are any more files in the pending list that need loading, and if so it will move * them from the list Set into the inflight Set, set their CORs flag and start them loading. * * It will carrying on doing this for each file in the pending list until it runs out, or hits the max allowed parallel downloads. * * @method Phaser.Loader.LoaderPlugin#checkLoadQueue * @private * @since 3.7.0 */ checkLoadQueue: function () { this.list.each(function (file) { if (file.state === CONST.FILE_POPULATED || (file.state === CONST.FILE_PENDING && this.inflight.size < this.maxParallelDownloads)) { this.inflight.set(file); this.list.delete(file); // If the file doesn't have its own crossOrigin set, we'll use the Loaders (which is undefined by default) if (!file.crossOrigin) { file.crossOrigin = this.crossOrigin; } file.load(); } if (this.inflight.size === this.maxParallelDownloads) { // Tells the Set iterator to abort return false; } }, this); }, /** * This event is fired when the a file successfully completes loading, _before_ it is processed. * * @event Phaser.Loader.LoaderPlugin#loadEvent * @param {Phaser.Loader.File} file - The file that has completed loading. */ /** * This event is fired when the a file errors during load. * * @event Phaser.Loader.LoaderPlugin#loadErrorEvent * @param {Phaser.Loader.File} file - The file that has failed to load. */ /** * An internal method called automatically by the XHRLoader belong to a File. * * This method will remove the given file from the inflight Set and update the load progress. * If the file was successful its `onProcess` method is called, otherwise it is added to the delete queue. * * @method Phaser.Loader.LoaderPlugin#nextFile * @fires Phaser.Loader.LoaderPlugin#loadEvent * @fires Phaser.Loader.LoaderPlugin#loadErrorEvent * @since 3.0.0 * * @param {Phaser.Loader.File} file - The File that just finished loading, or errored during load. * @param {boolean} success - `true` if the file loaded successfully, otherwise `false`. */ nextFile: function (file, success) { this.inflight.delete(file); this.updateProgress(); if (success) { this.totalComplete++; this.queue.set(file); this.emit('load', file); file.onProcess(); } else { this.totalFailed++; this._deleteQueue.set(file); this.emit('loaderror', file); } }, /** * An internal method that is called automatically by the File when it has finished processing. * * If the process was successful, and the File isn't part of a MultiFile, its `addToCache` method is called. * * It this then removed from the queue. If there are no more files to load `loadComplete` is called. * * @method Phaser.Loader.LoaderPlugin#fileProcessComplete * @since 3.7.0 * * @param {Phaser.Loader.File} file - The file that has finished processing. */ fileProcessComplete: function (file) { // This file has failed, so move it to the failed Set if (file.state === CONST.FILE_ERRORED) { if (file.multiFile) { file.multiFile.onFileFailed(file); } } else if (file.state === CONST.FILE_COMPLETE) { if (file.multiFile) { if (file.multiFile.isReadyToProcess()) { // If we got here then all files the link file needs are ready to add to the cache file.multiFile.addToCache(); } } else { // If we got here, then the file processed, so let it add itself to its cache file.addToCache(); } } // Remove it from the queue this.queue.delete(file); // Nothing left to do? if (this.list.size === 0 && this.inflight.size === 0 && this.queue.size === 0) { this.loadComplete(); } }, /** * This event is fired when the Loader has finished loading everything and the queue is empty. * By this point every loaded file will now be in its associated cache and ready for use. * * @event Phaser.Loader.LoaderPlugin#completeEvent * @param {Phaser.Loader.File} file - The file that has failed to load. */ /** * Called at the end when the load queue is exhausted and all files have either loaded or errored. * By this point every loaded file will now be in its associated cache and ready for use. * * Also clears down the Sets, puts progress to 1 and clears the deletion queue. * * @method Phaser.Loader.LoaderPlugin#loadComplete * @fires Phaser.Loader.LoaderPlugin#completeEvent * @since 3.7.0 */ loadComplete: function () { this.emit('loadcomplete', this); this.list.clear(); this.inflight.clear(); this.queue.clear(); this.progress = 1; this.state = CONST.LOADER_COMPLETE; this.systems.events.off('update', this.update, this); // Call 'destroy' on each file ready for deletion this._deleteQueue.iterateLocal('destroy'); this._deleteQueue.clear(); this.emit('complete', this, this.totalComplete, this.totalFailed); }, /** * Adds a File into the pending-deletion queue. * * @method Phaser.Loader.LoaderPlugin#flagForRemoval * @since 3.7.0 * * @param {Phaser.Loader.File} file - The File to be queued for deletion when the Loader completes. */ flagForRemoval: function (file) { this._deleteQueue.set(file); }, /** * Converts the given JSON data into a file that the browser then prompts you to download so you can save it locally. * * The data must be well formed JSON and ready-parsed, not a JavaScript object. * * @method Phaser.Loader.LoaderPlugin#saveJSON * @since 3.0.0 * * @param {*} data - The JSON data, ready parsed. * @param {string} [filename=file.json] - The name to save the JSON file as. * * @return {Phaser.Loader.LoaderPlugin} This Loader plugin. */ saveJSON: function (data, filename) { return this.save(JSON.stringify(data), filename); }, /** * Causes the browser to save the given data as a file to its default Downloads folder. * * Creates a DOM level anchor link, assigns it as being a `download` anchor, sets the href * to be an ObjectURL based on the given data, and then invokes a click event. * * @method Phaser.Loader.LoaderPlugin#save * @since 3.0.0 * * @param {*} data - The data to be saved. Will be passed through URL.createObjectURL. * @param {string} [filename=file.json] - The filename to save the file as. * @param {string} [filetype=application/json] - The file type to use when saving the file. Defaults to JSON. * * @return {Phaser.Loader.LoaderPlugin} This Loader plugin. */ save: function (data, filename, filetype) { if (filename === undefined) { filename = 'file.json'; } if (filetype === undefined) { filetype = 'application/json'; } var blob = new Blob([ data ], { type: filetype }); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.download = filename; a.textContent = 'Download ' + filename; a.href = url; a.click(); return this; }, /** * Resets the Loader. * * This will clear all lists and reset the base URL, path and prefix. * * Warning: If the Loader is currently downloading files, or has files in its queue, they will be aborted. * * @method Phaser.Loader.LoaderPlugin#reset * @since 3.0.0 */ reset: function () { this.list.clear(); this.inflight.clear(); this.queue.clear(); var gameConfig = this.systems.game.config; var sceneConfig = this.systems.settings.loader; this.setBaseURL(GetFastValue(sceneConfig, 'baseURL', gameConfig.loaderBaseURL)); this.setPath(GetFastValue(sceneConfig, 'path', gameConfig.loaderPath)); this.setPrefix(GetFastValue(sceneConfig, 'prefix', gameConfig.loaderPrefix)); this.state = CONST.LOADER_IDLE; }, /** * 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.Loader.LoaderPlugin#shutdown * @private * @since 3.0.0 */ shutdown: function () { this.reset(); this.state = CONST.LOADER_SHUTDOWN; this.systems.events.off('update', this.update, this); this.systems.events.off('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.Loader.LoaderPlugin#destroy * @private * @since 3.0.0 */ destroy: function () { this.shutdown(); this.state = CONST.LOADER_DESTROYED; this.systems.events.off('update', this.update, this); this.systems.events.off('start', this.pluginStart, this); this.list = null; this.inflight = null; this.queue = null; this.scene = null; this.systems = null; this.textureManager = null; this.cacheManager = null; } }); PluginCache.register('Loader', LoaderPlugin, 'load'); module.exports = LoaderPlugin; /***/ }), /* 354 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var FileTypesManager = __webpack_require__(7); var ImageFile = __webpack_require__(37); /** * @typedef {object} Phaser.Loader.FileTypes.SpriteSheetFileConfig * * @property {string} key - The key of the file. Must be unique within both the Loader and the Texture Manager. * @property {string} [url] - The absolute or relative URL to load the file from. * @property {string} [extension='png'] - The default file extension to use if no url is provided. * @property {string} [normalMap] - The filename of an associated normal map. It uses the same path and url to load as the image. * @property {Phaser.Loader.FileTypes.ImageFrameConfig} [frameConfig] - The frame configuration object. * @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ /** * @classdesc * A single Sprite Sheet Image File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#spritesheet method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#spritesheet. * * @class SpriteSheetFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.SpriteSheetFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string|string[]} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param {Phaser.Loader.FileTypes.ImageFrameConfig} [frameConfig] - The frame configuration object. * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ var SpriteSheetFile = new Class({ Extends: ImageFile, initialize: function SpriteSheetFile (loader, key, url, frameConfig, xhrSettings) { ImageFile.call(this, loader, key, url, xhrSettings, frameConfig); this.type = 'spritesheet'; }, /** * Adds this file to its target cache upon successful loading and processing. * * @method Phaser.Loader.FileTypes.SpriteSheetFile#addToCache * @since 3.7.0 */ addToCache: function () { var texture = this.cache.addSpriteSheet(this.key, this.data, this.config); this.pendingDestroy(texture); } }); /** * Adds a Sprite Sheet Image, or array of Sprite Sheet Images, to the current load queue. * * The term 'Sprite Sheet' in Phaser means a fixed-size sheet. Where every frame in the sheet is the exact same size, * and you reference those frames using numbers, not frame names. This is not the same thing as a Texture Atlas, where * the frames are packed in a way where they take up the least amount of space, and are referenced by their names, * not numbers. Some articles and software use the term 'Sprite Sheet' to mean Texture Atlas, so please be aware of * what sort of file you're actually trying to load. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.spritesheet('bot', 'images/robot.png', { frameWidth: 32, frameHeight: 38 }); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. * If you try to load an animated gif only the first frame will be rendered. Browsers do not natively support playback * of animated gifs to Canvas elements. * * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.spritesheet({ * key: 'bot', * url: 'images/robot.png', * frameConfig: { * frameWidth: 32, * frameHeight: 38, * startFrame: 0, * endFrame: 8 * } * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.SpriteSheetFileConfig` for more details. * * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: * * ```javascript * this.load.spritesheet('bot', 'images/robot.png', { frameWidth: 32, frameHeight: 38 }); * // and later in your game ... * this.add.image(x, y, 'bot', 0); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `PLAYER.` and the key was `Running` the final key will be `PLAYER.Running` and * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, * then you can specify it by providing an array as the `url` where the second element is the normal map: * * ```javascript * this.load.spritesheet('logo', [ 'images/AtariLogo.png', 'images/AtariLogo-n.png' ], { frameWidth: 256, frameHeight: 80 }); * ``` * * Or, if you are using a config object use the `normalMap` property: * * ```javascript * this.load.spritesheet({ * key: 'logo', * url: 'images/AtariLogo.png', * normalMap: 'images/AtariLogo-n.png', * frameConfig: { * frameWidth: 256, * frameHeight: 80 * } * }); * ``` * * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. * Normal maps are a WebGL only feature. * * Note: The ability to load this type of file will only be available if the Sprite Sheet File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#spritesheet * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.SpriteSheetFileConfig|Phaser.Loader.FileTypes.SpriteSheetFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param {Phaser.Loader.FileTypes.ImageFrameConfig} [frameConfig] - The frame configuration object. At a minimum it should have a `frameWidth` property. * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('spritesheet', function (key, url, frameConfig, xhrSettings) { if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object this.addFile(new SpriteSheetFile(this, key[i])); } } else { this.addFile(new SpriteSheetFile(this, key, url, frameConfig, xhrSettings)); } return this; }); module.exports = SpriteSheetFile; /***/ }), /* 355 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(18); var File = __webpack_require__(19); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var IsPlainObject = __webpack_require__(8); /** * @typedef {object} Phaser.Loader.FileTypes.ScriptFileConfig * * @property {string} key - The key of the file. Must be unique within the Loader. * @property {string} [url] - The absolute or relative URL to load the file from. * @property {string} [extension='js'] - The default file extension to use if no url is provided. * @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ /** * @classdesc * A single Script File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#script method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#script. * * @class ScriptFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.ScriptFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ var ScriptFile = new Class({ Extends: File, initialize: function ScriptFile (loader, key, url, xhrSettings) { var extension = 'js'; if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); url = GetFastValue(config, 'url'); xhrSettings = GetFastValue(config, 'xhrSettings'); extension = GetFastValue(config, 'extension', extension); } var fileConfig = { type: 'script', cache: false, extension: extension, responseType: 'text', key: key, url: url, xhrSettings: xhrSettings }; File.call(this, loader, fileConfig); }, /** * Called automatically by Loader.nextFile. * This method controls what extra work this File does with its loaded data. * * @method Phaser.Loader.FileTypes.ScriptFile#onProcess * @since 3.7.0 */ onProcess: function () { this.state = CONST.FILE_PROCESSING; this.data = document.createElement('script'); this.data.language = 'javascript'; this.data.type = 'text/javascript'; this.data.defer = false; this.data.text = this.xhrLoader.responseText; document.head.appendChild(this.data); this.onProcessComplete(); } }); /** * Adds a Script file, or array of Script files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.script('aliens', 'lib/aliens.js'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * The key must be a unique String and not already in-use by another file in the Loader. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.script({ * key: 'aliens', * url: 'lib/aliens.js' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.ScriptFileConfig` for more details. * * Once the file has finished loading it will automatically be converted into a script element * via `document.createElement('script')`. It will have its language set to JavaScript, `defer` set to * false and then the resulting element will be appended to `document.head`. Any code then in the * script will be executed. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" * and no URL is given then the Loader will set the URL to be "alien.js". It will always add `.js` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * Note: The ability to load this type of file will only be available if the Script File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#script * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.ScriptFileConfig|Phaser.Loader.FileTypes.ScriptFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('script', function (key, url, xhrSettings) { if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object this.addFile(new ScriptFile(this, key[i])); } } else { this.addFile(new ScriptFile(this, key, url, xhrSettings)); } return this; }); module.exports = ScriptFile; /***/ }), /* 356 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(18); var File = __webpack_require__(19); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var IsPlainObject = __webpack_require__(8); /** * @typedef {object} Phaser.Loader.FileTypes.PluginFileConfig * * @property {string} key - The key of the file. Must be unique within the Loader. * @property {string} [url] - The absolute or relative URL to load the file from. * @property {string} [extension='js'] - The default file extension to use if no url is provided. * @property {boolean} [start=false] - Automatically start the plugin after loading? * @property {string} [mapping] - If this plugin is to be injected into the Scene, this is the property key used. * @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ /** * @classdesc * A single Plugin Script File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#plugin method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#plugin. * * @class PluginFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.PluginFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". * @param {boolean} [start=false] - Automatically start the plugin after loading? * @param {string} [mapping] - If this plugin is to be injected into the Scene, this is the property key used. * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ var PluginFile = new Class({ Extends: File, initialize: function PluginFile (loader, key, url, start, mapping, xhrSettings) { var extension = 'js'; if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); url = GetFastValue(config, 'url'); xhrSettings = GetFastValue(config, 'xhrSettings'); extension = GetFastValue(config, 'extension', extension); start = GetFastValue(config, 'start'); mapping = GetFastValue(config, 'mapping'); } var fileConfig = { type: 'plugin', cache: false, extension: extension, responseType: 'text', key: key, url: url, xhrSettings: xhrSettings, config: { start: start, mapping: mapping } }; File.call(this, loader, fileConfig); // If the url variable refers to a class, add the plugin directly if (typeof url === 'function') { this.data = url; this.state = CONST.FILE_POPULATED; } }, /** * Called automatically by Loader.nextFile. * This method controls what extra work this File does with its loaded data. * * @method Phaser.Loader.FileTypes.PluginFile#onProcess * @since 3.7.0 */ onProcess: function () { var pluginManager = this.loader.systems.plugins; var config = this.config; var start = GetFastValue(config, 'start', false); var mapping = GetFastValue(config, 'mapping', null); if (this.state === CONST.FILE_POPULATED) { pluginManager.install(this.key, this.data, start, mapping); } else { // Plugin added via a js file this.state = CONST.FILE_PROCESSING; this.data = document.createElement('script'); this.data.language = 'javascript'; this.data.type = 'text/javascript'; this.data.defer = false; this.data.text = this.xhrLoader.responseText; document.head.appendChild(this.data); pluginManager.install(this.key, window[this.key], start, mapping); } this.onProcessComplete(); } }); /** * Adds a Plugin Script file, or array of plugin files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.plugin('modplayer', 'plugins/ModPlayer.js'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * The key must be a unique String and not already in-use by another file in the Loader. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.plugin({ * key: 'modplayer', * url: 'plugins/ModPlayer.js' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.PluginFileConfig` for more details. * * Once the file has finished loading it will automatically be converted into a script element * via `document.createElement('script')`. It will have its language set to JavaScript, `defer` set to * false and then the resulting element will be appended to `document.head`. Any code then in the * script will be executed. It will then be passed to the Phaser PluginCache.register method. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" * and no URL is given then the Loader will set the URL to be "alien.js". It will always add `.js` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * Note: The ability to load this type of file will only be available if the Plugin File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#plugin * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.PluginFileConfig|Phaser.Loader.FileTypes.PluginFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {(string|function)} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". Or, a plugin function. * @param {boolean} [start] - The plugin mapping configuration object. * @param {string} [mapping] - If this plugin is to be injected into the Scene, this is the property key used. * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('plugin', function (key, url, start, mapping, xhrSettings) { if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object this.addFile(new PluginFile(this, key[i])); } } else { this.addFile(new PluginFile(this, key, url, start, mapping, xhrSettings)); } return this; }); module.exports = PluginFile; /***/ }), /* 357 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var ImageFile = __webpack_require__(37); var IsPlainObject = __webpack_require__(8); var JSONFile = __webpack_require__(28); var MultiFile = __webpack_require__(36); /** * @typedef {object} Phaser.Loader.FileTypes.MultiAtlasFileConfig * * @property {string} key - The key of the file. Must be unique within both the Loader and the Texture Manager. * @property {string} [atlasURL] - The absolute or relative URL to load the multi atlas json file from. Or, a well formed JSON object. * @property {string} [atlasExtension='json'] - The default file extension to use for the atlas json if no url is provided. * @property {XHRSettingsObject} [atlasXhrSettings] - Extra XHR Settings specifically for the atlas json file. * @property {string} [path] - Optional path to use when loading the textures defined in the atlas data. * @property {string} [baseURL] - Optional Base URL to use when loading the textures defined in the atlas data. * @property {XHRSettingsObject} [textureXhrSettings] - Extra XHR Settings specifically for the texture files. */ /** * @classdesc * A single Multi Texture Atlas File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#multiatlas method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#multiatlas. * * @class MultiAtlasFile * @extends Phaser.Loader.MultiFile * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.7.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {string} key - The key of the file. Must be unique within both the Loader and the Texture Manager. * @param {string} [atlasURL] - The absolute or relative URL to load the multi atlas json file from. * @param {string} [path] - Optional path to use when loading the textures defined in the atlas data. * @param {string} [baseURL] - Optional Base URL to use when loading the textures defined in the atlas data. * @param {XHRSettingsObject} [atlasXhrSettings] - Extra XHR Settings specifically for the atlas json file. * @param {XHRSettingsObject} [textureXhrSettings] - Extra XHR Settings specifically for the texture files. */ var MultiAtlasFile = new Class({ Extends: MultiFile, initialize: function MultiAtlasFile (loader, key, atlasURL, path, baseURL, atlasXhrSettings, textureXhrSettings) { if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); atlasURL = GetFastValue(config, 'url'); atlasXhrSettings = GetFastValue(config, 'xhrSettings'); path = GetFastValue(config, 'path'); baseURL = GetFastValue(config, 'baseURL'); textureXhrSettings = GetFastValue(config, 'textureXhrSettings'); } var data = new JSONFile(loader, key, atlasURL, atlasXhrSettings); MultiFile.call(this, loader, 'multiatlas', key, [ data ]); this.config.path = path; this.config.baseURL = baseURL; this.config.textureXhrSettings = textureXhrSettings; }, /** * Called by each File when it finishes loading. * * @method Phaser.Loader.MultiFile#onFileComplete * @since 3.7.0 * * @param {Phaser.Loader.File} file - The File that has completed processing. */ onFileComplete: function (file) { var index = this.files.indexOf(file); if (index !== -1) { this.pending--; if (file.type === 'json' && file.data.hasOwnProperty('textures')) { // Inspect the data for the files to now load var textures = file.data.textures; var config = this.config; var loader = this.loader; var currentBaseURL = loader.baseURL; var currentPath = loader.path; var currentPrefix = loader.prefix; var baseURL = GetFastValue(config, 'baseURL', currentBaseURL); var path = GetFastValue(config, 'path', currentPath); var prefix = GetFastValue(config, 'prefix', currentPrefix); var textureXhrSettings = GetFastValue(config, 'textureXhrSettings'); loader.setBaseURL(baseURL); loader.setPath(path); loader.setPrefix(prefix); for (var i = 0; i < textures.length; i++) { // "image": "texture-packer-multi-atlas-0.png", var textureURL = textures[i].image; var key = '_MA_' + textureURL; var image = new ImageFile(loader, key, textureURL, textureXhrSettings); this.addToMultiFile(image); loader.addFile(image); // "normalMap": "texture-packer-multi-atlas-0_n.png", if (textures[i].normalMap) { var normalMap = new ImageFile(loader, key, textures[i].normalMap, textureXhrSettings); normalMap.type = 'normalMap'; image.setLink(normalMap); this.addToMultiFile(normalMap); loader.addFile(normalMap); } } // Reset the loader settings loader.setBaseURL(currentBaseURL); loader.setPath(currentPath); loader.setPrefix(currentPrefix); } } }, /** * Adds this file to its target cache upon successful loading and processing. * * @method Phaser.Loader.MultiFile#addToCache * @since 3.7.0 */ addToCache: function () { if (this.isReadyToProcess()) { var fileJSON = this.files[0]; fileJSON.addToCache(); var data = []; var images = []; var normalMaps = []; for (var i = 1; i < this.files.length; i++) { var file = this.files[i]; if (file.type === 'normalMap') { continue; } var key = file.key.substr(4); var image = file.data; // Now we need to find out which json entry this mapped to for (var t = 0; t < fileJSON.data.textures.length; t++) { var item = fileJSON.data.textures[t]; if (item.image === key) { images.push(image); data.push(item); if (file.linkFile) { normalMaps.push(file.linkFile.data); } break; } } } if (normalMaps.length === 0) { normalMaps = undefined; } this.loader.textureManager.addAtlasJSONArray(this.key, images, data, normalMaps); this.complete = true; for (i = 0; i < this.files.length; i++) { this.files[i].pendingDestroy(); } } } }); /** * Adds a Multi Texture Atlas, or array of multi atlases, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.multiatlas('level1', 'images/Level1.json'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. * * Phaser expects the atlas data to be provided in a JSON file as exported from the application Texture Packer, * version 4.6.3 or above, where you have made sure to use the Phaser 3 Export option. * * The way it works internally is that you provide a URL to the JSON file. Phaser then loads this JSON, parses it and * extracts which texture files it also needs to load to complete the process. If the JSON also defines normal maps, * Phaser will load those as well. * * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.multiatlas({ * key: 'level1', * atlasURL: 'images/Level1.json' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.MultiAtlasFileConfig` for more details. * * Instead of passing a URL for the atlas JSON data you can also pass in a well formed JSON object instead. * * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: * * ```javascript * this.load.multiatlas('level1', 'images/Level1.json'); * // and later in your game ... * this.add.image(x, y, 'level1', 'background'); * ``` * * To get a list of all available frames within an atlas please consult your Texture Atlas software. * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * Note: The ability to load this type of file will only be available if the Multi Atlas File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#multiatlas * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.7.0 * * @param {(string|Phaser.Loader.FileTypes.MultiAtlasFileConfig|Phaser.Loader.FileTypes.MultiAtlasFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string} [atlasURL] - The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param {string} [path] - Optional path to use when loading the textures defined in the atlas data. * @param {string} [baseURL] - Optional Base URL to use when loading the textures defined in the atlas data. * @param {XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('multiatlas', function (key, atlasURL, path, baseURL, atlasXhrSettings) { var multifile; // Supports an Object file definition in the key argument // Or an array of objects in the key argument // Or a single entry where all arguments have been defined if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { multifile = new MultiAtlasFile(this, key[i]); this.addFile(multifile.files); } } else { multifile = new MultiAtlasFile(this, key, atlasURL, path, baseURL, atlasXhrSettings); this.addFile(multifile.files); } return this; }); module.exports = MultiAtlasFile; /***/ }), /* 358 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var AudioFile = __webpack_require__(168); var Class = __webpack_require__(0); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var IsPlainObject = __webpack_require__(8); var JSONFile = __webpack_require__(28); var MultiFile = __webpack_require__(36); /** * @typedef {object} Phaser.Loader.FileTypes.AudioSpriteFileConfig * * @property {string} key - The key of the file. Must be unique within both the Loader and the Audio Cache. * @property {string} jsonURL - The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. * @property {XHRSettingsObject} [jsonXhrSettings] - Extra XHR Settings specifically for the json file. * @property {string} [audioURL] - The absolute or relative URL to load the audio file from. * @property {any} [audioConfig] - The audio configuration options. * @property {XHRSettingsObject} [audioXhrSettings] - Extra XHR Settings specifically for the audio file. */ /** * @classdesc * An Audio Sprite File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#audioSprite method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audioSprite. * * @class AudioSpriteFile * @extends Phaser.Loader.MultiFile * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.7.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.AudioSpriteFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string} jsonURL - The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. * @param {string} [audioURL] - The absolute or relative URL to load the audio file from. If empty it will be obtained by parsing the JSON file. * @param {any} [audioConfig] - The audio configuration options. * @param {XHRSettingsObject} [audioXhrSettings] - An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings. * @param {XHRSettingsObject} [jsonXhrSettings] - An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings. */ var AudioSpriteFile = new Class({ Extends: MultiFile, initialize: function AudioSpriteFile (loader, key, jsonURL, audioURL, audioConfig, audioXhrSettings, jsonXhrSettings) { if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); jsonURL = GetFastValue(config, 'jsonURL'); audioURL = GetFastValue(config, 'audioURL'); audioConfig = GetFastValue(config, 'audioConfig'); audioXhrSettings = GetFastValue(config, 'audioXhrSettings'); jsonXhrSettings = GetFastValue(config, 'jsonXhrSettings'); } var data; // No url? then we're going to do a json load and parse it from that if (!audioURL) { data = new JSONFile(loader, key, jsonURL, jsonXhrSettings); MultiFile.call(this, loader, 'audiosprite', key, [ data ]); this.config.resourceLoad = true; this.config.audioConfig = audioConfig; this.config.audioXhrSettings = audioXhrSettings; } else { var audio = AudioFile.create(loader, key, audioURL, audioConfig, audioXhrSettings); if (audio) { data = new JSONFile(loader, key, jsonURL, jsonXhrSettings); MultiFile.call(this, loader, 'audiosprite', key, [ audio, data ]); this.config.resourceLoad = false; } } }, /** * Called by each File when it finishes loading. * * @method Phaser.Loader.AudioSpriteFile#onFileComplete * @since 3.7.0 * * @param {Phaser.Loader.File} file - The File that has completed processing. */ onFileComplete: function (file) { var index = this.files.indexOf(file); if (index !== -1) { this.pending--; if (this.config.resourceLoad && file.type === 'json' && file.data.hasOwnProperty('resources')) { // Inspect the data for the files to now load var urls = file.data.resources; var audioConfig = GetFastValue(this.config, 'audioConfig'); var audioXhrSettings = GetFastValue(this.config, 'audioXhrSettings'); var audio = AudioFile.create(this.loader, file.key, urls, audioConfig, audioXhrSettings); if (audio) { this.addToMultiFile(audio); this.loader.addFile(audio); } } } }, /** * Adds this file to its target cache upon successful loading and processing. * * @method Phaser.Loader.AudioSpriteFile#addToCache * @since 3.7.0 */ addToCache: function () { if (this.isReadyToProcess()) { var fileA = this.files[0]; var fileB = this.files[1]; fileA.addToCache(); fileB.addToCache(); this.complete = true; } } }); /** * Adds a JSON based Audio Sprite, or array of audio sprites, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.audioSprite('kyobi', 'kyobi.json', [ * 'kyobi.ogg', * 'kyobi.mp3', * 'kyobi.m4a' * ]); * } * ``` * * Audio Sprites are a combination of audio files and a JSON configuration. * The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite * * If the JSON file includes a 'resource' object then you can let Phaser parse it and load the audio * files automatically based on its content. To do this exclude the audio URLs from the load: * * ```javascript * function preload () * { * this.load.audioSprite('kyobi', 'kyobi.json'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. * * The key must be a unique String. It is used to add the file to the global Audio Cache upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the Audio Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the Audio Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.audioSprite({ * key: 'kyobi', * jsonURL: 'audio/Kyobi.json', * audioURL: [ * 'audio/Kyobi.ogg', * 'audio/Kyobi.mp3', * 'audio/Kyobi.m4a' * ] * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.AudioSpriteFileConfig` for more details. * * Instead of passing a URL for the audio JSON data you can also pass in a well formed JSON object instead. * * Once the audio has finished loading you can use it create an Audio Sprite by referencing its key: * * ```javascript * this.load.audioSprite('kyobi', 'kyobi.json'); * // and later in your game ... * var music = this.sound.addAudioSprite('kyobi'); * music.play('title'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * Due to different browsers supporting different audio file types you should usually provide your audio files in a variety of formats. * ogg, mp3 and m4a are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on * browser support. * * If audio has been disabled in your game, either via the game config, or lack of support from the device, then no audio will be loaded. * * Note: The ability to load this type of file will only be available if the Audio Sprite File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#audioSprite * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.AudioSpriteFileConfig|Phaser.Loader.FileTypes.AudioSpriteFileConfig[])} key - The key to use for this file, or a file configuration object, or an array of objects. * @param {string} jsonURL - The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. * @param {string} [audioURL] - The absolute or relative URL to load the audio file from. If empty it will be obtained by parsing the JSON file. * @param {any} [audioConfig] - The audio configuration options. * @param {XHRSettingsObject} [audioXhrSettings] - An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings. * @param {XHRSettingsObject} [jsonXhrSettings] - An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader. */ FileTypesManager.register('audioSprite', function (key, jsonURL, audioURL, audioConfig, audioXhrSettings, jsonXhrSettings) { var game = this.systems.game; var gameAudioConfig = game.config.audio; var deviceAudio = game.device.audio; if ((gameAudioConfig && gameAudioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData)) { // Sounds are disabled, so skip loading audio return this; } var multifile; // Supports an Object file definition in the key argument // Or an array of objects in the key argument // Or a single entry where all arguments have been defined if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { multifile = new AudioSpriteFile(this, key[i]); if (multifile.files) { this.addFile(multifile.files); } } } else { multifile = new AudioSpriteFile(this, key, jsonURL, audioURL, audioConfig, audioXhrSettings, jsonXhrSettings); if (multifile.files) { this.addFile(multifile.files); } } return this; }); /***/ }), /* 359 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var FileTypesManager = __webpack_require__(7); var GetFastValue = __webpack_require__(1); var ImageFile = __webpack_require__(37); var IsPlainObject = __webpack_require__(8); var JSONFile = __webpack_require__(28); var MultiFile = __webpack_require__(36); /** * @typedef {object} Phaser.Loader.FileTypes.AtlasJSONFileConfig * * @property {string} key - The key of the file. Must be unique within both the Loader and the Texture Manager. * @property {string} [textureURL] - The absolute or relative URL to load the texture image file from. * @property {string} [textureExtension='png'] - The default file extension to use for the image texture if no url is provided. * @property {XHRSettingsObject} [textureXhrSettings] - Extra XHR Settings specifically for the texture image file. * @property {string} [normalMap] - The filename of an associated normal map. It uses the same path and url to load as the texture image. * @property {string} [atlasURL] - The absolute or relative URL to load the atlas json file from. Or a well formed JSON object to use instead. * @property {string} [atlasExtension='json'] - The default file extension to use for the atlas json if no url is provided. * @property {XHRSettingsObject} [atlasXhrSettings] - Extra XHR Settings specifically for the atlas json file. */ /** * @classdesc * A single JSON based Texture Atlas File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#atlas method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#atlas. * * https://www.codeandweb.com/texturepacker/tutorials/how-to-create-sprite-sheets-for-phaser3?source=photonstorm * * @class AtlasJSONFile * @extends Phaser.Loader.MultiFile * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.AtlasJSONFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string|string[]} [textureURL] - The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param {string} [atlasURL] - The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param {XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. * @param {XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. */ var AtlasJSONFile = new Class({ Extends: MultiFile, initialize: function AtlasJSONFile (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) { var image; var data; if (IsPlainObject(key)) { var config = key; key = GetFastValue(config, 'key'); image = new ImageFile(loader, { key: key, url: GetFastValue(config, 'textureURL'), extension: GetFastValue(config, 'textureExtension', 'png'), normalMap: GetFastValue(config, 'normalMap'), xhrSettings: GetFastValue(config, 'textureXhrSettings') }); data = new JSONFile(loader, { key: key, url: GetFastValue(config, 'atlasURL'), extension: GetFastValue(config, 'atlasExtension', 'json'), xhrSettings: GetFastValue(config, 'atlasXhrSettings') }); } else { image = new ImageFile(loader, key, textureURL, textureXhrSettings); data = new JSONFile(loader, key, atlasURL, atlasXhrSettings); } if (image.linkFile) { // Image has a normal map MultiFile.call(this, loader, 'atlasjson', key, [ image, data, image.linkFile ]); } else { MultiFile.call(this, loader, 'atlasjson', key, [ image, data ]); } }, /** * Adds this file to its target cache upon successful loading and processing. * * @method Phaser.Loader.FileTypes.AtlasJSONFile#addToCache * @since 3.7.0 */ addToCache: function () { if (this.isReadyToProcess()) { var image = this.files[0]; var json = this.files[1]; var normalMap = (this.files[2]) ? this.files[2].data : null; this.loader.textureManager.addAtlas(image.key, image.data, json.data, normalMap); json.addToCache(); this.complete = true; } } }); /** * Adds a JSON based Texture Atlas, or array of atlases, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.atlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. * * Phaser expects the atlas data to be provided in a JSON file, using either the JSON Hash or JSON Array format. * These files are created by software such as Texture Packer, Shoebox and Adobe Flash / Animate. * If you are using Texture Packer and have enabled multi-atlas support, then please use the Phaser Multi Atlas loader * instead of this one. * * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. * * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.atlas({ * key: 'mainmenu', * textureURL: 'images/MainMenu.png', * atlasURL: 'images/MainMenu.json' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.AtlasJSONFileConfig` for more details. * * Instead of passing a URL for the atlas JSON data you can also pass in a well formed JSON object instead. * * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: * * ```javascript * this.load.atlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json'); * // and later in your game ... * this.add.image(x, y, 'mainmenu', 'background'); * ``` * * To get a list of all available frames within an atlas please consult your Texture Atlas software. * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, * then you can specify it by providing an array as the `url` where the second element is the normal map: * * ```javascript * this.load.atlas('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.json'); * ``` * * Or, if you are using a config object use the `normalMap` property: * * ```javascript * this.load.atlas({ * key: 'mainmenu', * textureURL: 'images/MainMenu.png', * normalMap: 'images/MainMenu-n.png', * atlasURL: 'images/MainMenu.json' * }); * ``` * * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. * Normal maps are a WebGL only feature. * * Note: The ability to load this type of file will only be available if the Atlas JSON File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#atlas * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.AtlasJSONFileConfig|Phaser.Loader.FileTypes.AtlasJSONFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string|string[]} [textureURL] - The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param {string} [atlasURL] - The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param {XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. * @param {XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('atlas', function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) { var multifile; // Supports an Object file definition in the key argument // Or an array of objects in the key argument // Or a single entry where all arguments have been defined if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { multifile = new AtlasJSONFile(this, key[i]); this.addFile(multifile.files); } } else { multifile = new AtlasJSONFile(this, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings); this.addFile(multifile.files); } return this; }); module.exports = AtlasJSONFile; /***/ }), /* 360 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var FileTypesManager = __webpack_require__(7); var JSONFile = __webpack_require__(28); /** * @classdesc * A single Animation JSON File suitable for loading by the Loader. * * These are created when you use the Phaser.Loader.LoaderPlugin#animation method and are not typically created directly. * * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#animation. * * @class AnimationJSONFile * @extends Phaser.Loader.File * @memberOf Phaser.Loader.FileTypes * @constructor * @since 3.0.0 * * @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file. * @param {(string|Phaser.Loader.FileTypes.JSONFileConfig)} key - The key to use for this file, or a file configuration object. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. * @param {string} [dataKey] - When the JSON file loads only this property will be stored in the Cache. */ var AnimationJSONFile = new Class({ Extends: JSONFile, initialize: // url can either be a string, in which case it is treated like a proper url, or an object, in which case it is treated as a ready-made JS Object // dataKey allows you to pluck a specific object out of the JSON and put just that into the cache, rather than the whole thing function AnimationJSONFile (loader, key, url, xhrSettings, dataKey) { JSONFile.call(this, loader, key, url, xhrSettings, dataKey); this.type = 'animationJSON'; }, /** * Called automatically by Loader.nextFile. * This method controls what extra work this File does with its loaded data. * * @method Phaser.Loader.FileTypes.AnimationJSONFile#onProcess * @since 3.7.0 */ onProcess: function () { // We need to hook into this event: this.loader.once('loadcomplete', this.onLoadComplete, this); // But the rest is the same as a normal JSON file JSONFile.prototype.onProcess.call(this); }, /** * Called at the end of the load process, after the Loader has finished all files in its queue. * * @method Phaser.Loader.FileTypes.AnimationJSONFile#onLoadComplete * @since 3.7.0 */ onLoadComplete: function () { this.loader.systems.anims.fromJSON(this.data); this.pendingDestroy(); } }); /** * Adds an Animation JSON Data file, or array of Animation JSON files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { * this.load.animation('baddieAnims', 'files/BaddieAnims.json'); * } * ``` * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. * * The key must be a unique String. It is used to add the file to the global JSON Cache upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the JSON Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file * then remove it from the JSON Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript * this.load.animation({ * key: 'baddieAnims', * url: 'files/BaddieAnims.json' * }); * ``` * * See the documentation for `Phaser.Loader.FileTypes.JSONFileConfig` for more details. * * Once the file has finished loading it will automatically be passed to the global Animation Managers `fromJSON` method. * This will parse all of the JSON data and create animation data from it. This process happens at the very end * of the Loader, once every other file in the load queue has finished. The reason for this is to allow you to load * both animation data and the images it relies upon in the same load call. * * Once the animation data has been parsed you will be able to play animations using that data. * Please see the Animation Manager `fromJSON` method for more details about the format and playback. * * You can also access the raw animation data from its Cache using its key: * * ```javascript * this.load.animation('baddieAnims', 'files/BaddieAnims.json'); * // and later in your game ... * var data = this.cache.json.get('baddieAnims'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and * this is what you would use to retrieve the text from the JSON Cache. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" * and no URL is given then the Loader will set the URL to be "data.json". It will always add `.json` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * * You can also optionally provide a `dataKey` to use. This allows you to extract only a part of the JSON and store it in the Cache, * rather than the whole file. For example, if your JSON data had a structure like this: * * ```json * { * "level1": { * "baddies": { * "aliens": {}, * "boss": {} * } * }, * "level2": {}, * "level3": {} * } * ``` * * And if you only wanted to create animations from the `boss` data, then you could pass `level1.baddies.boss`as the `dataKey`. * * Note: The ability to load this type of file will only be available if the JSON File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * * @method Phaser.Loader.LoaderPlugin#animation * @fires Phaser.Loader.LoaderPlugin#addFileEvent * @since 3.0.0 * * @param {(string|Phaser.Loader.FileTypes.JSONFileConfig|Phaser.Loader.FileTypes.JSONFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them. * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param {string} [dataKey] - When the Animation JSON file loads only this property will be stored in the Cache and used to create animation data. * @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. * * @return {Phaser.Loader.LoaderPlugin} The Loader instance. */ FileTypesManager.register('animation', function (key, url, dataKey, xhrSettings) { // Supports an Object file definition in the key argument // Or an array of objects in the key argument // Or a single entry where all arguments have been defined if (Array.isArray(key)) { for (var i = 0; i < key.length; i++) { this.addFile(new AnimationJSONFile(this, key[i])); } } else { this.addFile(new AnimationJSONFile(this, key, url, xhrSettings, dataKey)); } return this; }); module.exports = AnimationJSONFile; /***/ }), /* 361 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Input.Touch */ /* eslint-disable */ module.exports = { TouchManager: __webpack_require__(197) }; /* eslint-enable */ /***/ }), /* 362 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Input.Mouse */ /* eslint-disable */ module.exports = { MouseManager: __webpack_require__(199) }; /* eslint-enable */ /***/ }), /* 363 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Returns `true` if the Key was released within the `duration` value given, or `false` if it either isn't up, * or was released longer ago than then given duration. * * @function Phaser.Input.Keyboard.UpDuration * @since 3.0.0 * * @param {Phaser.Input.Keyboard.Key} key - The Key object to test. * @param {integer} [duration=50] - The duration, in ms, within which the key must have been released. * * @return {boolean} `true` if the Key was released within `duration` ms, otherwise `false`. */ var UpDuration = function (key, duration) { if (duration === undefined) { duration = 50; } return (key.isUp && key.duration < duration); }; module.exports = UpDuration; /***/ }), /* 364 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Returns `true` if the Key was pressed down within the `duration` value given, or `false` if it either isn't down, * or was pressed down longer ago than then given duration. * * @function Phaser.Input.Keyboard.DownDuration * @since 3.0.0 * * @param {Phaser.Input.Keyboard.Key} key - The Key object to test. * @param {integer} [duration=50] - The duration, in ms, within which the key must have been pressed down. * * @return {boolean} `true` if the Key was pressed down within `duration` ms, otherwise `false`. */ var DownDuration = function (key, duration) { if (duration === undefined) { duration = 50; } return (key.isDown && key.duration < duration); }; module.exports = DownDuration; /***/ }), /* 365 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * The justUp value allows you to test if this Key has just been released or not. * * When you check this value it will return `true` if the Key is up, otherwise `false`. * * You can only call JustUp once per key release. It will only return `true` once, until the Key is pressed down and released again. * This allows you to use it in situations where you want to check if this key is up without using an event, such as in a core game loop. * * @function Phaser.Input.Keyboard.JustUp * @since 3.0.0 * * @param {Phaser.Input.Keyboard.Key} key - The Key to check to see if it's just up or not. * * @return {boolean} `true` if the Key was just released, otherwise `false`. */ var JustUp = function (key) { if (key._justUp) { key._justUp = false; return true; } else { return false; } }; module.exports = JustUp; /***/ }), /* 366 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * The justDown value allows you to test if this Key has just been pressed down or not. * * When you check this value it will return `true` if the Key is down, otherwise `false`. * * You can only call justDown once per key press. It will only return `true` once, until the Key is released and pressed down again. * This allows you to use it in situations where you want to check if this key is down without using an event, such as in a core game loop. * * @function Phaser.Input.Keyboard.JustDown * @since 3.0.0 * * @param {Phaser.Input.Keyboard.Key} key - The Key to check to see if it's just down or not. * * @return {boolean} `true` if the Key was just pressed, otherwise `false`. */ var JustDown = function (key) { if (key._justDown) { key._justDown = false; return true; } else { return false; } }; module.exports = JustDown; /***/ }), /* 367 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Used internally by the Keyboard Plugin. * * @function Phaser.Input.Keyboard.ProcessKeyUp * @private * @since 3.0.0 * * @param {Phaser.Input.Keyboard.Key} key - The Key to process the event for. * @param {KeyboardEvent} event - The native Keyboard event. * * @return {Phaser.Input.Keyboard.Key} The Key that was processed. */ var ProcessKeyUp = function (key, event) { key.originalEvent = event; if (key.preventDefault) { event.preventDefault(); } if (!key.enabled) { return; } key.isDown = false; key.isUp = true; key.timeUp = event.timeStamp; key.duration = key.timeUp - key.timeDown; key.repeats = 0; key._justDown = false; key._justUp = true; return key; }; module.exports = ProcessKeyUp; /***/ }), /* 368 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Used internally by the Keyboard Plugin. * * @function Phaser.Input.Keyboard.ProcessKeyDown * @private * @since 3.0.0 * * @param {Phaser.Input.Keyboard.Key} key - The Key to process the event for. * @param {KeyboardEvent} event - The native Keyboard event. * * @return {Phaser.Input.Keyboard.Key} The Key that was processed. */ var ProcessKeyDown = function (key, event) { key.originalEvent = event; if (key.preventDefault) { event.preventDefault(); } if (!key.enabled) { return; } key.altKey = event.altKey; key.ctrlKey = event.ctrlKey; key.shiftKey = event.shiftKey; key.location = event.location; if (key.isDown === false) { key.isDown = true; key.isUp = false; key.timeDown = event.timeStamp; key.duration = 0; key._justDown = true; key._justUp = false; } key.repeats++; return key; }; module.exports = ProcessKeyDown; /***/ }), /* 369 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var KeyCodes = __webpack_require__(109); var KeyMap = {}; for (var key in KeyCodes) { KeyMap[KeyCodes[key]] = key; } module.exports = KeyMap; /***/ }), /* 370 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Used internally by the KeyCombo class. * * @function Phaser.Input.Keyboard.KeyCombo.ResetKeyCombo * @private * @since 3.0.0 * * @param {Phaser.Input.Keyboard.KeyCombo} combo - The KeyCombo to reset. * * @return {Phaser.Input.Keyboard.KeyCombo} The KeyCombo. */ var ResetKeyCombo = function (combo) { combo.current = combo.keyCodes[0]; combo.index = 0; combo.timeLastMatched = 0; combo.matched = false; combo.timeMatched = 0; return combo; }; module.exports = ResetKeyCombo; /***/ }), /* 371 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Used internally by the KeyCombo class. * Return `true` if it reached the end of the combo, `false` if not. * * @function Phaser.Input.Keyboard.KeyCombo.AdvanceKeyCombo * @private * @since 3.0.0 * * @param {KeyboardEvent} event - The native Keyboard Event. * @param {Phaser.Input.Keyboard.KeyCombo} combo - The KeyCombo object to advance. * * @return {boolean} `true` if it reached the end of the combo, `false` if not. */ var AdvanceKeyCombo = function (event, combo) { combo.timeLastMatched = event.timeStamp; combo.index++; if (combo.index === combo.size) { return true; } else { combo.current = combo.keyCodes[combo.index]; return false; } }; module.exports = AdvanceKeyCombo; /***/ }), /* 372 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var AdvanceKeyCombo = __webpack_require__(371); /** * Used internally by the KeyCombo class. * * @function Phaser.Input.Keyboard.KeyCombo.ProcessKeyCombo * @private * @since 3.0.0 * * @param {KeyboardEvent} event - The native Keyboard Event. * @param {Phaser.Input.Keyboard.KeyCombo} combo - The KeyCombo object to be processed. * * @return {boolean} `true` if the combo was matched, otherwise `false`. */ var ProcessKeyCombo = function (event, combo) { if (combo.matched) { return true; } var comboMatched = false; var keyMatched = false; if (event.keyCode === combo.current) { // Key was correct if (combo.index > 0 && combo.maxKeyDelay > 0) { // We have to check to see if the delay between // the new key and the old one was too long (if enabled) var timeLimit = combo.timeLastMatched + combo.maxKeyDelay; // Check if they pressed it in time or not if (event.timeStamp <= timeLimit) { keyMatched = true; comboMatched = AdvanceKeyCombo(event, combo); } } else { keyMatched = true; // We don't check the time for the first key pressed, so just advance it comboMatched = AdvanceKeyCombo(event, combo); } } if (!keyMatched && combo.resetOnWrongKey) { // Wrong key was pressed combo.index = 0; combo.current = combo.keyCodes[0]; } if (comboMatched) { combo.timeLastMatched = event.timeStamp; combo.matched = true; combo.timeMatched = event.timeStamp; } return comboMatched; }; module.exports = ProcessKeyCombo; /***/ }), /* 373 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var EventEmitter = __webpack_require__(9); var GetValue = __webpack_require__(4); var InputPluginCache = __webpack_require__(76); var Key = __webpack_require__(171); var KeyCodes = __webpack_require__(109); var KeyCombo = __webpack_require__(170); var KeyMap = __webpack_require__(369); var ProcessKeyDown = __webpack_require__(368); var ProcessKeyUp = __webpack_require__(367); /** * @classdesc * The Keyboard Plugin is an input plugin that belongs to the Scene-owned Input system. * * Its role is to listen for native DOM Keyboard Events and then process them. * * You do not need to create this class directly, the Input system will create an instance of it automatically. * * You can access it from within a Scene using `this.input.keyboard`. For example, you can do: * * ```javascript * this.input.keyboard.on('keydown', callback, context); * ``` * * Or, to listen for a specific key: * * ```javascript * this.input.keyboard.on('keydown_A', callback, context); * ``` * * You can also create Key objects, which you can then poll in your game loop: * * ```javascript * var spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); * ``` * * _Note_: Many keyboards are unable to process certain combinations of keys due to hardware limitations known as ghosting. * See http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/ for more details. * * Also please be aware that certain browser extensions can disable or override Phaser keyboard handling. * For example the Chrome extension vimium is known to disable Phaser from using the D key, while EverNote disables the backtick key. * And there are others. So, please check your extensions before opening Phaser issues about keys that don't work. * * @class KeyboardPlugin * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Input.Keyboard * @constructor * @since 3.10.0 * * @param {Phaser.Input.InputPlugin} sceneInputPlugin - A reference to the Scene Input Plugin that the KeyboardPlugin belongs to. */ var KeyboardPlugin = new Class({ Extends: EventEmitter, initialize: function KeyboardPlugin (sceneInputPlugin) { EventEmitter.call(this); /** * A reference to the Scene that this Input Plugin is responsible for. * * @name Phaser.Input.Keyboard.KeyboardPlugin#scene * @type {Phaser.Scene} * @since 3.10.0 */ this.scene = sceneInputPlugin.scene; /** * A reference to the Scene Systems Settings. * * @name Phaser.Input.Keyboard.KeyboardPlugin#settings * @type {Phaser.Scenes.Settings.Object} * @since 3.10.0 */ this.settings = this.scene.sys.settings; /** * A reference to the Scene Input Plugin that created this Keyboard Plugin. * * @name Phaser.Input.Keyboard.KeyboardPlugin#sceneInputPlugin * @type {Phaser.Input.InputPlugin} * @since 3.10.0 */ this.sceneInputPlugin = sceneInputPlugin; /** * A boolean that controls if the Keyboard Plugin is enabled or not. * Can be toggled on the fly. * * @name Phaser.Input.Keyboard.KeyboardPlugin#enabled * @type {boolean} * @default true * @since 3.10.0 */ this.enabled = true; /** * The Keyboard Event target, as defined in the Scene or Game Config. * Typically the browser window, but can be any interactive DOM element. * * @name Phaser.Input.Keyboard.KeyboardPlugin#target * @type {any} * @since 3.10.0 */ this.target; /** * An array of Key objects to process. * * @name Phaser.Input.Keyboard.KeyboardPlugin#keys * @type {Phaser.Input.Keyboard.Key[]} * @since 3.10.0 */ this.keys = []; /** * An array of KeyCombo objects to process. * * @name Phaser.Input.Keyboard.KeyboardPlugin#combos * @type {Phaser.Input.Keyboard.KeyCombo[]} * @since 3.10.0 */ this.combos = []; /** * An internal event queue. * * @name Phaser.Input.Keyboard.KeyboardPlugin#queue * @type {KeyboardEvent[]} * @private * @since 3.10.0 */ this.queue = []; /** * Internal event handler. * * @name Phaser.Input.Keyboard.KeyboardPlugin#onKeyHandler * @type {function} * @private * @since 3.10.0 */ this.onKeyHandler; sceneInputPlugin.pluginEvents.once('boot', this.boot, this); sceneInputPlugin.pluginEvents.on('start', this.start, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Input.Keyboard.KeyboardPlugin#boot * @private * @since 3.10.0 */ boot: function () { var settings = this.settings.input; var config = this.scene.sys.game.config; this.enabled = GetValue(settings, 'keyboard', config.inputKeyboard); this.target = GetValue(settings, 'keyboard.target', config.inputKeyboardEventTarget); this.sceneInputPlugin.pluginEvents.once('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.Input.Keyboard.KeyboardPlugin#start * @private * @since 3.10.0 */ start: function () { if (this.enabled) { this.startListeners(); } this.sceneInputPlugin.pluginEvents.once('shutdown', this.shutdown, this); }, /** * Checks to see if both this plugin and the Scene to which it belongs is active. * * @method Phaser.Input.Keyboard.KeyboardPlugin#isActive * @since 3.10.0 * * @return {boolean} `true` if the plugin and the Scene it belongs to is active. */ isActive: function () { return (this.enabled && this.scene.sys.isActive()); }, /** * Starts the Keyboard Event listeners running. * This is called automatically and does not need to be manually invoked. * * @method Phaser.Input.Keyboard.KeyboardPlugin#startListeners * @private * @since 3.10.0 */ startListeners: function () { var _this = this; var handler = function (event) { if (event.defaultPrevented || !_this.isActive()) { // Do nothing if event already handled return; } _this.queue.push(event); var key = _this.keys[event.keyCode]; if (key && key.preventDefault) { event.preventDefault(); } }; this.onKeyHandler = handler; this.target.addEventListener('keydown', handler, false); this.target.addEventListener('keyup', handler, false); // Finally, listen for an update event from the Input Plugin this.sceneInputPlugin.pluginEvents.on('update', this.update, this); }, /** * Stops the Keyboard Event listeners. * This is called automatically and does not need to be manually invoked. * * @method Phaser.Input.Keyboard.KeyboardPlugin#stopListeners * @private * @since 3.10.0 */ stopListeners: function () { this.target.removeEventListener('keydown', this.onKeyHandler); this.target.removeEventListener('keyup', this.onKeyHandler); this.sceneInputPlugin.pluginEvents.off('update', this.update); }, /** * @typedef {object} CursorKeys * * @property {Phaser.Input.Keyboard.Key} [up] - A Key object mapping to the UP arrow key. * @property {Phaser.Input.Keyboard.Key} [down] - A Key object mapping to the DOWN arrow key. * @property {Phaser.Input.Keyboard.Key} [left] - A Key object mapping to the LEFT arrow key. * @property {Phaser.Input.Keyboard.Key} [right] - A Key object mapping to the RIGHT arrow key. * @property {Phaser.Input.Keyboard.Key} [space] - A Key object mapping to the SPACE BAR key. * @property {Phaser.Input.Keyboard.Key} [shift] - A Key object mapping to the SHIFT key. */ /** * Creates and returns an object containing 4 hotkeys for Up, Down, Left and Right, and also Space Bar and shift. * * @method Phaser.Input.Keyboard.KeyboardPlugin#createCursorKeys * @since 3.10.0 * * @return {CursorKeys} An object containing the properties: `up`, `down`, `left`, `right`, `space` and `shift`. */ createCursorKeys: function () { return this.addKeys({ up: KeyCodes.UP, down: KeyCodes.DOWN, left: KeyCodes.LEFT, right: KeyCodes.RIGHT, space: KeyCodes.SPACE, shift: KeyCodes.SHIFT }); }, /** * A practical way to create an object containing user selected hotkeys. * * For example: * * ```javascript * this.input.keyboard.addKeys({ 'up': Phaser.Input.Keyboard.KeyCodes.W, 'down': Phaser.Input.Keyboard.KeyCodes.S }); * ``` * * would return an object containing the properties (`up` and `down`) mapped to W and S {@link Phaser.Input.Keyboard.Key} objects. * * You can also pass in a comma-separated string: * * ```javascript * this.input.keyboard.addKeys('W,S,A,D'); * ``` * * Which will return an object with the properties W, S, A and D mapped to the relevant Key objects. * * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. * * @method Phaser.Input.Keyboard.KeyboardPlugin#addKeys * @since 3.10.0 * * @param {(object|string)} keys - An object containing Key Codes, or a comma-separated string. * * @return {object} An object containing Key objects mapped to the input properties. */ addKeys: function (keys) { var output = {}; if (typeof keys === 'string') { keys = keys.split(','); for (var i = 0; i < keys.length; i++) { output[keys[i]] = this.addKey(keys[i]); } } else { for (var key in keys) { output[key] = this.addKey(keys[key]); } } return output; }, /** * Adds a Key object to this Keyboard Plugin. * * The given argument can be either an existing Key object, a string, such as `A` or `SPACE`, or a key code value. * * If a Key object is given, and one already exists matching the same key code, the existing one is replaced with the new one. * * @method Phaser.Input.Keyboard.KeyboardPlugin#addKey * @since 3.10.0 * * @param {(Phaser.Input.Keyboard.Key|string|integer)} key - Either a Key object, a string, such as `A` or `SPACE`, or a key code value. * * @return {Phaser.Input.Keyboard.Key} The newly created Key object, or a reference to it if it already existed in the keys array. */ addKey: function (key) { var keys = this.keys; if (key instanceof Key) { var idx = keys.indexOf(key); if (idx > -1) { keys[idx] = key; } else { keys[key.keyCode] = key; } return key; } if (typeof key === 'string') { key = KeyCodes[key.toUpperCase()]; } if (!keys[key]) { keys[key] = new Key(key); } return keys[key]; }, /** * Removes a Key object from this Keyboard Plugin. * * The given argument can be either a Key object, a string, such as `A` or `SPACE`, or a key code value. * * @method Phaser.Input.Keyboard.KeyboardPlugin#removeKey * @since 3.10.0 * * @param {(Phaser.Input.Keyboard.Key|string|integer)} key - Either a Key object, a string, such as `A` or `SPACE`, or a key code value. */ removeKey: function (key) { var keys = this.keys; if (key instanceof Key) { var idx = keys.indexOf(key); if (idx > -1) { this.keys[idx] = undefined; } } else if (typeof key === 'string') { key = KeyCodes[key.toUpperCase()]; } if (keys[key]) { keys[key] = undefined; } }, /** * Creates a new KeyCombo. * * A KeyCombo will listen for a specific string of keys from the Keyboard, and when it receives them * it will emit a `keycombomatch` event from this Keyboard Plugin. * * The keys to be listened for can be defined as: * * A string (i.e. 'ATARI') * An array of either integers (key codes) or strings, or a mixture of both * An array of objects (such as Key objects) with a public 'keyCode' property * * For example, to listen for the Konami code (up, up, up, down, down, down, left, left, left, right, right, right) * you could pass the following array of key codes: * * ```javascript * this.input.keyboard.createCombo([ 38, 38, 38, 40, 40, 40, 37, 37, 37, 39, 39, 39 ], { resetOnMatch: true }); * * this.input.keyboard.on('keycombomatch', function (event) { * console.log('Konami Code entered!'); * }); * ``` * * Or, to listen for the user entering the word PHASER: * * ```javascript * this.input.keyboard.createCombo('PHASER'); * ``` * * @method Phaser.Input.Keyboard.KeyboardPlugin#createCombo * @since 3.10.0 * * @param {(string|integer[]|object[])} keys - The keys that comprise this combo. * @param {KeyComboConfig} [config] - A Key Combo configuration object. * * @return {Phaser.Input.Keyboard.KeyCombo} The new KeyCombo object. */ createCombo: function (keys, config) { return new KeyCombo(this, keys, config); }, /** * Internal update handler called by the Input Manager, which is in turn invoked by the Game step. * * @method Phaser.Input.Keyboard.KeyboardPlugin#update * @private * @since 3.10.0 */ update: function () { var len = this.queue.length; if (!this.enabled || len === 0) { return; } // Clears the queue array, and also means we don't work on array data that could potentially // be modified during the processing phase var queue = this.queue.splice(0, len); var keys = this.keys; // Process the event queue, dispatching all of the events that have stored up for (var i = 0; i < len; i++) { var event = queue[i]; var code = event.keyCode; if (event.type === 'keydown') { if (KeyMap[code] && (keys[code] === undefined || keys[code].isDown === false)) { // Will emit a keyboard or keyup event this.emit(event.type, event); this.emit('keydown_' + KeyMap[code], event); } if (keys[code]) { ProcessKeyDown(keys[code], event); } } else { // Will emit a keyboard or keyup event this.emit(event.type, event); this.emit('keyup_' + KeyMap[code], event); if (keys[code]) { ProcessKeyUp(keys[code], event); } } } }, /** * Shuts the Keyboard Plugin down. * All this does is remove any listeners bound to it. * * @method Phaser.Input.Keyboard.KeyboardPlugin#shutdown * @private * @since 3.10.0 */ shutdown: function () { this.stopListeners(); this.removeAllListeners(); }, /** * Destroys this Keyboard Plugin instance and all references it holds, plus clears out local arrays. * * @method Phaser.Input.Keyboard.KeyboardPlugin#destroy * @private * @since 3.10.0 */ destroy: function () { this.shutdown(); this.keys = []; this.combos = []; this.queue = []; this.scene = null; this.settings = null; this.sceneInputPlugin = null; this.target = null; } }); /** * An instance of the Keyboard Plugin class, if enabled via the `input.keyboard` Scene or Game Config property. * Use this to create Key objects and listen for keyboard specific events. * * @name Phaser.Input.InputPlugin#keyboard * @type {?Phaser.Input.Keyboard.KeyboardPlugin} * @since 3.10.0 */ InputPluginCache.register('KeyboardPlugin', KeyboardPlugin, 'keyboard', 'keyboard', 'inputKeyboard'); module.exports = KeyboardPlugin; /***/ }), /* 374 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Input.Keyboard */ module.exports = { KeyboardPlugin: __webpack_require__(373), Key: __webpack_require__(171), KeyCodes: __webpack_require__(109), KeyCombo: __webpack_require__(170), JustDown: __webpack_require__(366), JustUp: __webpack_require__(365), DownDuration: __webpack_require__(364), UpDuration: __webpack_require__(363) }; /***/ }), /* 375 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Creates a new Pixel Perfect Handler function. * * Access via `InputPlugin.makePixelPerfect` rather than calling it directly. * * @function Phaser.Input.CreatePixelPerfectHandler * @since 3.10.0 * * @param {Phaser.Textures.TextureManager} textureManager - A reference to the Texture Manager. * @param {integer} alphaTolerance - The alpha level that the pixel should be above to be included as a successful interaction. * * @return {function} The new Pixel Perfect Handler function. */ var CreatePixelPerfectHandler = function (textureManager, alphaTolerance) { return function (hitArea, x, y, gameObject) { var alpha = textureManager.getPixelAlpha(x, y, gameObject.texture.key, gameObject.frame.key); return (alpha && alpha >= alphaTolerance); }; }; module.exports = CreatePixelPerfectHandler; /***/ }), /* 376 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Circle = __webpack_require__(88); var CircleContains = __webpack_require__(32); var Class = __webpack_require__(0); var CreateInteractiveObject = __webpack_require__(175); var CreatePixelPerfectHandler = __webpack_require__(375); var DistanceBetween = __webpack_require__(58); var Ellipse = __webpack_require__(114); var EllipseContains = __webpack_require__(54); var EventEmitter = __webpack_require__(9); var GetFastValue = __webpack_require__(1); var InputPluginCache = __webpack_require__(76); var IsPlainObject = __webpack_require__(8); var PluginCache = __webpack_require__(12); var Rectangle = __webpack_require__(14); var RectangleContains = __webpack_require__(31); var Triangle = __webpack_require__(68); var TriangleContains = __webpack_require__(60); /** * @classdesc * The Input Plugin belongs to a Scene and handles all input related events and operations for it. * * You can access it from within a Scene using `this.input`. * * It emits events directly. For example, you can do: * * ```javascript * this.input.on('pointerdown', callback, context); * ``` * * To listen for a pointer down event anywhere on the game canvas. * * Game Objects can be enabled for input by calling their `setInteractive` method. After which they * will directly emit input events: * * ```javascript * var sprite = this.add.sprite(x, y, texture); * sprite.setInteractive(); * sprite.on('pointerdown', callback, context); * ``` * * Please see the Input examples and tutorials for more information. * * @class InputPlugin * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Input * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - A reference to the Scene that this Input Plugin is responsible for. */ var InputPlugin = new Class({ Extends: EventEmitter, initialize: function InputPlugin (scene) { EventEmitter.call(this); /** * A reference to the Scene that this Input Plugin is responsible for. * * @name Phaser.Input.InputPlugin#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * A reference to the Scene Systems class. * * @name Phaser.Input.InputPlugin#systems * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.systems = scene.sys; /** * A reference to the Scene Systems Settings. * * @name Phaser.Input.InputPlugin#settings * @type {Phaser.Scenes.Settings.Object} * @since 3.5.0 */ this.settings = scene.sys.settings; /** * A reference to the Game Input Manager. * * @name Phaser.Input.InputPlugin#manager * @type {Phaser.Input.InputManager} * @since 3.0.0 */ this.manager = scene.sys.game.input; /** * Internal event queue used for plugins only. * * @name Phaser.Input.InputPlugin#pluginEvents * @type {Phaser.Events.EventEmitter} * @private * @since 3.10.0 */ this.pluginEvents = new EventEmitter(); /** * If set, the Input Plugin will run its update loop every frame. * * @name Phaser.Input.InputPlugin#enabled * @type {boolean} * @default true * @since 3.5.0 */ this.enabled = true; /** * A reference to the Scene Display List. This property is set during the `boot` method. * * @name Phaser.Input.InputPlugin#displayList * @type {Phaser.GameObjects.DisplayList} * @since 3.0.0 */ this.displayList; /** * A reference to the Scene Cameras Manager. This property is set during the `boot` method. * * @name Phaser.Input.InputPlugin#cameras * @type {Phaser.Cameras.Scene2D.CameraManager} * @since 3.0.0 */ this.cameras; // Inject the available input plugins into this class InputPluginCache.install(this); /** * A reference to the Mouse Manager. * * This property is only set if Mouse support has been enabled in your Game Configuration file. * * If you just wish to get access to the mouse pointer, use the `mousePointer` property instead. * * @name Phaser.Input.InputPlugin#mouse * @type {?Phaser.Input.Mouse.MouseManager} * @since 3.0.0 */ this.mouse = this.manager.mouse; /** * When set to `true` (the default) the Input Plugin will emulate DOM behavior by only emitting events from * the top-most Game Objects in the Display List. * * If set to `false` it will emit events from all Game Objects below a Pointer, not just the top one. * * @name Phaser.Input.InputPlugin#topOnly * @type {boolean} * @default true * @since 3.0.0 */ this.topOnly = true; /** * How often should the Pointers be checked? * * The value is a time, given in ms, and is the time that must have elapsed between game steps before * the Pointers will be polled again. When a pointer is polled it runs a hit test to see which Game * Objects are currently below it, or being interacted with it. * * Pointers will *always* be checked if they have been moved by the user, or press or released. * * This property only controls how often they will be polled if they have not been updated. * You should set this if you want to have Game Objects constantly check against the pointers, even * if the pointer didn't move itself. * * Set to 0 to poll constantly. Set to -1 to only poll on user movement. * * @name Phaser.Input.InputPlugin#pollRate * @type {integer} * @default -1 * @since 3.0.0 */ this.pollRate = -1; /** * Internal poll timer value. * * @name Phaser.Input.InputPlugin#_pollTimer * @type {number} * @private * @default 0 * @since 3.0.0 */ this._pollTimer = 0; /** * The distance, in pixels, a pointer has to move while being held down, before it thinks it is being dragged. * * @name Phaser.Input.InputPlugin#dragDistanceThreshold * @type {number} * @default 0 * @since 3.0.0 */ this.dragDistanceThreshold = 0; /** * The amount of time, in ms, a pointer has to be held down before it thinks it is dragging. * * @name Phaser.Input.InputPlugin#dragTimeThreshold * @type {number} * @default 0 * @since 3.0.0 */ this.dragTimeThreshold = 0; /** * Used to temporarily store the results of the Hit Test * * @name Phaser.Input.InputPlugin#_temp * @type {array} * @private * @default [] * @since 3.0.0 */ this._temp = []; /** * Used to temporarily store the results of the Hit Test dropZones * * @name Phaser.Input.InputPlugin#_tempZones * @type {array} * @private * @default [] * @since 3.0.0 */ this._tempZones = []; /** * A list of all Game Objects that have been set to be interactive in the Scene this Input Plugin is managing. * * @name Phaser.Input.InputPlugin#_list * @type {Phaser.GameObjects.GameObject[]} * @private * @default [] * @since 3.0.0 */ this._list = []; /** * Objects waiting to be inserted to the list on the next call to 'begin'. * * @name Phaser.Input.InputPlugin#_pendingInsertion * @type {Phaser.GameObjects.GameObject[]} * @private * @default [] * @since 3.0.0 */ this._pendingInsertion = []; /** * Objects waiting to be removed from the list on the next call to 'begin'. * * @name Phaser.Input.InputPlugin#_pendingRemoval * @type {Phaser.GameObjects.GameObject[]} * @private * @default [] * @since 3.0.0 */ this._pendingRemoval = []; /** * A list of all Game Objects that have been enabled for dragging. * * @name Phaser.Input.InputPlugin#_draggable * @type {Phaser.GameObjects.GameObject[]} * @private * @default [] * @since 3.0.0 */ this._draggable = []; /** * A list of all Interactive Objects currently considered as being 'draggable' by any pointer, indexed by pointer ID. * * @name Phaser.Input.InputPlugin#_drag * @type {{0:Array,2:Array,3:Array,4:Array,5:Array,6:Array,7:Array,8:Array,9:Array}} * @private * @since 3.0.0 */ this._drag = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [] }; /** * A list of all Interactive Objects currently considered as being 'over' by any pointer, indexed by pointer ID. * * @name Phaser.Input.InputPlugin#_over * @type {{0:Array,2:Array,3:Array,4:Array,5:Array,6:Array,7:Array,8:Array,9:Array}} * @private * @since 3.0.0 */ this._over = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [] }; /** * A list of valid DOM event types. * * @name Phaser.Input.InputPlugin#_validTypes * @type {string[]} * @private * @since 3.0.0 */ this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove', 'onDragStart', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDrop' ]; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('start', this.start, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Input.InputPlugin#boot * @private * @since 3.5.1 */ boot: function () { this.cameras = this.systems.cameras; this.displayList = this.systems.displayList; this.systems.events.once('destroy', this.destroy, this); // Registered input plugins listen for this this.pluginEvents.emit('boot'); }, /** * 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.Input.InputPlugin#start * @private * @since 3.5.0 */ start: function () { var eventEmitter = this.systems.events; eventEmitter.on('transitionstart', this.transitionIn, this); eventEmitter.on('transitionout', this.transitionOut, this); eventEmitter.on('transitioncomplete', this.transitionComplete, this); eventEmitter.on('preupdate', this.preUpdate, this); eventEmitter.on('update', this.update, this); eventEmitter.once('shutdown', this.shutdown, this); this.enabled = true; // Registered input plugins listen for this this.pluginEvents.emit('start'); }, /** * The pre-update handler is responsible for checking the pending removal and insertion lists and * deleting old Game Objects. * * @method Phaser.Input.InputPlugin#preUpdate * @private * @since 3.0.0 */ preUpdate: function () { // Registered input plugins listen for this this.pluginEvents.emit('preUpdate'); var removeList = this._pendingRemoval; var insertList = this._pendingInsertion; var toRemove = removeList.length; var toInsert = insertList.length; if (toRemove === 0 && toInsert === 0) { // Quick bail return; } var current = this._list; // Delete old gameObjects for (var i = 0; i < toRemove; i++) { var gameObject = removeList[i]; var index = current.indexOf(gameObject); if (index > -1) { current.splice(index, 1); this.clear(gameObject); } } // Clear the removal list removeList.length = 0; this._pendingRemoval.length = 0; // Move pendingInsertion to list (also clears pendingInsertion at the same time) this._list = current.concat(insertList.splice(0)); }, /** * Checks to see if both this plugin and the Scene to which it belongs is active. * * @method Phaser.Input.InputPlugin#isActive * @since 3.10.0 * * @return {boolean} `true` if the plugin and the Scene it belongs to is active. */ isActive: function () { return (this.enabled && this.scene.sys.isActive()); }, /** * The internal update loop for the Input Plugin. * Called automatically by the Scene Systems step. * * @method Phaser.Input.InputPlugin#update * @private * @since 3.0.0 * * @param {number} time - The time value from the most recent Game step. Typically a high-resolution timer value, or Date.now(). * @param {number} delta - The delta value since the last frame. This is smoothed to avoid delta spikes by the TimeStep class. */ update: function (time, delta) { if (!this.isActive()) { return; } this.pluginEvents.emit('update', time, delta); var manager = this.manager; // Another Scene above this one has already consumed the input events, or we're in transition if (manager.globalTopOnly && manager.ignoreEvents) { return; } var runUpdate = (manager.dirty || this.pollRate === 0); if (this.pollRate > -1) { this._pollTimer -= delta; if (this._pollTimer < 0) { runUpdate = true; // Discard timer diff this._pollTimer = this.pollRate; } } if (!runUpdate) { return; } var pointers = this.manager.pointers; for (var i = 0; i < this.manager.pointersTotal; i++) { var pointer = pointers[i]; // Always reset this array this._tempZones = []; // _temp contains a hit tested and camera culled list of IO objects this._temp = this.hitTestPointer(pointer); this.sortGameObjects(this._temp); this.sortGameObjects(this._tempZones); if (this.topOnly) { // Only the top-most one counts now, so safely ignore the rest if (this._temp.length) { this._temp.splice(1); } if (this._tempZones.length) { this._tempZones.splice(1); } } var total = this.processDragEvents(pointer, time); // TODO: Enable for touch if (!pointer.wasTouch) { total += this.processOverOutEvents(pointer); } if (pointer.justDown) { total += this.processDownEvents(pointer); } if (pointer.justUp) { total += this.processUpEvents(pointer); } if (pointer.justMoved) { total += this.processMoveEvents(pointer); } if (total > 0 && manager.globalTopOnly) { // We interacted with an event in this Scene, so block any Scenes below us from doing the same this frame manager.ignoreEvents = true; } } }, /** * Clears a Game Object so it no longer has an Interactive Object associated with it. * The Game Object is then queued for removal from the Input Plugin on the next update. * * @method Phaser.Input.InputPlugin#clear * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that will have its Interactive Object removed. * * @return {Phaser.GameObjects.GameObject} The Game Object that had its Interactive Object removed. */ clear: function (gameObject) { var input = gameObject.input; // If GameObject.input already cleared from higher class if (!input) { return; } this.queueForRemoval(gameObject); input.gameObject = undefined; input.target = undefined; input.hitArea = undefined; input.hitAreaCallback = undefined; input.callbackContext = undefined; gameObject.input = null; // Clear from _draggable, _drag and _over var index = this._draggable.indexOf(gameObject); if (index > -1) { this._draggable.splice(index, 1); } index = this._drag[0].indexOf(gameObject); if (index > -1) { this._drag[0].splice(index, 1); } index = this._over[0].indexOf(gameObject); if (index > -1) { this._over[0].splice(index, 1); } return gameObject; }, /** * Disables Input on a single Game Object. * * An input disabled Game Object still retains its Interactive Object component and can be re-enabled * at any time, by passing it to `InputPlugin.enable`. * * @method Phaser.Input.InputPlugin#disable * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to have its input system disabled. */ disable: function (gameObject) { gameObject.input.enabled = false; }, /** * Enable a Game Object for interaction. * * If the Game Object already has an Interactive Object component, it is enabled and returned. * * Otherwise, a new Interactive Object component is created and assigned to the Game Object's `input` property. * * Input works by using hit areas, these are nearly always geometric shapes, such as rectangles or circles, that act as the hit area * for the Game Object. However, you can provide your own hit area shape and callback, should you wish to handle some more advanced * input detection. * * If no arguments are provided it will try and create a rectangle hit area based on the texture frame the Game Object is using. If * this isn't a texture-bound object, such as a Graphics or BitmapText object, this will fail, and you'll need to provide a specific * shape for it to use. * * You can also provide an Input Configuration Object as the only argument to this method. * * @method Phaser.Input.InputPlugin#enable * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to be enabled for input. * @param {(Phaser.Input.InputConfiguration|any)} [shape] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used. * @param {HitAreaCallback} [callback] - The 'contains' function to invoke to check if the pointer is within the hit area. * @param {boolean} [dropZone=false] - Is this Game Object a drop zone or not? * * @return {Phaser.Input.InputPlugin} This Input Plugin. */ enable: function (gameObject, shape, callback, dropZone) { if (dropZone === undefined) { dropZone = false; } if (gameObject.input) { // If it is already has an InteractiveObject then just enable it and return gameObject.input.enabled = true; } else { // Create an InteractiveObject and enable it this.setHitArea(gameObject, shape, callback); } if (gameObject.input && dropZone && !gameObject.input.dropZone) { gameObject.input.dropZone = dropZone; } return this; }, /** * Takes the given Pointer and performs a hit test against it, to see which interactive Game Objects * it is currently above. * * The hit test is performed against which-ever Camera the Pointer is over. If it is over multiple * cameras, it starts checking the camera at the top of the camera list, and if nothing is found, iterates down the list. * * @method Phaser.Input.InputPlugin#hitTestPointer * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The Pointer to check against the Game Objects. * * @return {Phaser.GameObjects.GameObject[]} An array of all the interactive Game Objects the Pointer was above. */ hitTestPointer: function (pointer) { var cameras = this.cameras.getCamerasBelowPointer(pointer); for (var c = 0; c < cameras.length; c++) { var camera = cameras[c]; // Get a list of all objects that can be seen by the camera below the pointer in the scene and store in 'output' array. // All objects in this array are input enabled, as checked by the hitTest method, so we don't need to check later on as well. var over = this.manager.hitTest(pointer, this._list, camera); // Filter out the drop zones for (var i = 0; i < over.length; i++) { var obj = over[i]; if (obj.input.dropZone) { this._tempZones.push(obj); } } if (over.length > 0) { pointer.camera = camera; return over; } } return []; }, /** * An internal method that handles the Pointer down event. * * @method Phaser.Input.InputPlugin#processDownEvents * @private * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The Pointer being tested. * * @return {integer} The total number of objects interacted with. */ processDownEvents: function (pointer) { var currentlyOver = this._temp; // Contains ALL Game Objects currently over in the array this.emit('pointerdown', pointer, currentlyOver); var total = 0; // Go through all objects the pointer was over and fire their events / callbacks for (var i = 0; i < currentlyOver.length; i++) { var gameObject = currentlyOver[i]; if (!gameObject.input) { continue; } total++; gameObject.emit('pointerdown', pointer, gameObject.input.localX, gameObject.input.localY, pointer.camera); this.emit('gameobjectdown', pointer, gameObject); } return total; }, /** * An internal method that handles the Pointer drag events. * * @method Phaser.Input.InputPlugin#processDragEvents * @private * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The Pointer to check against the Game Objects. * @param {number} time - The time stamp of the most recent Game step. * * @return {integer} The total number of objects interacted with. */ processDragEvents: function (pointer, time) { if (this._draggable.length === 0) { // There are no draggable items, so let's not even bother going further return 0; } var i; var gameObject; var list; var input; var currentlyOver = this._temp; // 0 = Not dragging anything // 1 = Primary button down and objects below, so collect a draglist // 2 = Pointer being checked if meets drag criteria // 3 = Pointer meets criteria, notify the draglist // 4 = Pointer actively dragging the draglist and has moved // 5 = Pointer actively dragging but has been released, notify draglist if (pointer.dragState === 0 && pointer.primaryDown && pointer.justDown && currentlyOver.length > 0) { pointer.dragState = 1; } else if (pointer.dragState > 0 && !pointer.primaryDown && pointer.justUp) { pointer.dragState = 5; } // Process the various drag states // 1 = Primary button down and objects below, so collect a draglist if (pointer.dragState === 1) { // Get draggable objects, sort them, pick the top (or all) and store them somewhere var draglist = []; for (i = 0; i < currentlyOver.length; i++) { gameObject = currentlyOver[i]; if (gameObject.input.draggable) { draglist.push(gameObject); } } if (draglist.length === 0) { pointer.dragState = 0; return 0; } else if (draglist.length > 1) { this.sortGameObjects(draglist); if (this.topOnly) { draglist.splice(1); } } // draglist now contains all potential candidates for dragging this._drag[pointer.id] = draglist; if (this.dragDistanceThreshold === 0 && this.dragTimeThreshold === 0) { // No drag criteria, so snap immediately to mode 3 pointer.dragState = 3; } else { // Check the distance / time pointer.dragState = 2; } } // 2 = Pointer being checked if meets drag criteria if (pointer.dragState === 2) { // Has it moved far enough to be considered a drag? if (this.dragDistanceThreshold > 0 && DistanceBetween(pointer.x, pointer.y, pointer.downX, pointer.downY) >= this.dragDistanceThreshold) { // Alrighty, we've got a drag going on ... pointer.dragState = 3; } // Held down long enough to be considered a drag? if (this.dragTimeThreshold > 0 && (time >= pointer.downTime + this.dragTimeThreshold)) { // Alrighty, we've got a drag going on ... pointer.dragState = 3; } } // 3 = Pointer meets criteria and is freshly down, notify the draglist if (pointer.dragState === 3) { list = this._drag[pointer.id]; for (i = 0; i < list.length; i++) { gameObject = list[i]; input = gameObject.input; input.dragState = 2; input.dragX = pointer.x - gameObject.x; input.dragY = pointer.y - gameObject.y; input.dragStartX = gameObject.x; input.dragStartY = gameObject.y; gameObject.emit('dragstart', pointer, input.dragX, input.dragY); this.emit('dragstart', pointer, gameObject); } pointer.dragState = 4; return list.length; } // 4 = Pointer actively dragging the draglist and has moved if (pointer.dragState === 4 && pointer.justMoved && !pointer.justUp) { var dropZones = this._tempZones; list = this._drag[pointer.id]; for (i = 0; i < list.length; i++) { gameObject = list[i]; input = gameObject.input; // If this GO has a target then let's check it if (input.target) { var index = dropZones.indexOf(input.target); // Got a target, are we still over it? if (index === 0) { // We're still over it, and it's still the top of the display list, phew ... gameObject.emit('dragover', pointer, input.target); this.emit('dragover', pointer, gameObject, input.target); } else if (index > 0) { // Still over it but it's no longer top of the display list (targets must always be at the top) gameObject.emit('dragleave', pointer, input.target); this.emit('dragleave', pointer, gameObject, input.target); input.target = dropZones[0]; gameObject.emit('dragenter', pointer, input.target); this.emit('dragenter', pointer, gameObject, input.target); } else { // Nope, we've moved on (or the target has!), leave the old target gameObject.emit('dragleave', pointer, input.target); this.emit('dragleave', pointer, gameObject, input.target); // Anything new to replace it? // Yup! if (dropZones[0]) { input.target = dropZones[0]; gameObject.emit('dragenter', pointer, input.target); this.emit('dragenter', pointer, gameObject, input.target); } else { // Nope input.target = null; } } } else if (!input.target && dropZones[0]) { input.target = dropZones[0]; gameObject.emit('dragenter', pointer, input.target); this.emit('dragenter', pointer, gameObject, input.target); } var dragX = pointer.x - gameObject.input.dragX; var dragY = pointer.y - gameObject.input.dragY; gameObject.emit('drag', pointer, dragX, dragY); this.emit('drag', pointer, gameObject, dragX, dragY); } return list.length; } // 5 = Pointer was actively dragging but has been released, notify draglist if (pointer.dragState === 5) { list = this._drag[pointer.id]; for (i = 0; i < list.length; i++) { gameObject = list[i]; input = gameObject.input; if (input.dragState === 2) { input.dragState = 0; input.dragX = input.localX - gameObject.displayOriginX; input.dragY = input.localY - gameObject.displayOriginY; var dropped = false; if (input.target) { gameObject.emit('drop', pointer, input.target); this.emit('drop', pointer, gameObject, input.target); input.target = null; dropped = true; } // And finally the dragend event gameObject.emit('dragend', pointer, input.dragX, input.dragY, dropped); this.emit('dragend', pointer, gameObject, dropped); } } pointer.dragState = 0; list.splice(0); } return 0; }, /** * An internal method that handles the Pointer movement event. * * @method Phaser.Input.InputPlugin#processMoveEvents * @private * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The pointer to check for events against. * * @return {integer} The total number of objects interacted with. */ processMoveEvents: function (pointer) { var currentlyOver = this._temp; this.emit('pointermove', pointer, currentlyOver); var total = 0; // Go through all objects the pointer was over and fire their events / callbacks for (var i = 0; i < currentlyOver.length; i++) { var gameObject = currentlyOver[i]; if (!gameObject.input) { continue; } total++; gameObject.emit('pointermove', pointer, gameObject.input.localX, gameObject.input.localY); this.emit('gameobjectmove', pointer, gameObject); if (this.topOnly) { break; } } return total; }, /** * An internal method that handles the Pointer over and out events. * * @method Phaser.Input.InputPlugin#processOverOutEvents * @private * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The pointer to check for events against. * * @return {integer} The total number of objects interacted with. */ processOverOutEvents: function (pointer) { var currentlyOver = this._temp; var i; var gameObject; var justOut = []; var justOver = []; var stillOver = []; var previouslyOver = this._over[pointer.id]; var currentlyDragging = this._drag[pointer.id]; var manager = this.manager; // Go through all objects the pointer was previously over, and see if it still is. // Splits the previouslyOver array into two parts: justOut and stillOver for (i = 0; i < previouslyOver.length; i++) { gameObject = previouslyOver[i]; if (currentlyOver.indexOf(gameObject) === -1 && currentlyDragging.indexOf(gameObject) === -1) { // Not in the currentlyOver array, so must be outside of this object now justOut.push(gameObject); } else { // In the currentlyOver array stillOver.push(gameObject); } } // Go through all objects the pointer is currently over (the hit test results) // and if not in the previouslyOver array we know it's a new entry, so add to justOver for (i = 0; i < currentlyOver.length; i++) { gameObject = currentlyOver[i]; // Is this newly over? if (previouslyOver.indexOf(gameObject) === -1) { justOver.push(gameObject); } } // By this point the arrays are filled, so now we can process what happened... // Process the Just Out objects var total = justOut.length; var totalInteracted = 0; if (total > 0) { this.sortGameObjects(justOut); this.emit('pointerout', pointer, justOut); // Call onOut for everything in the justOut array for (i = 0; i < total; i++) { gameObject = justOut[i]; if (!gameObject.input) { continue; } this.emit('gameobjectout', pointer, gameObject); gameObject.emit('pointerout', pointer); manager.resetCursor(gameObject.input); totalInteracted++; } } // Process the Just Over objects total = justOver.length; if (total > 0) { this.sortGameObjects(justOver); this.emit('pointerover', pointer, justOver); // Call onOver for everything in the justOver array for (i = 0; i < total; i++) { gameObject = justOver[i]; if (!gameObject.input) { continue; } this.emit('gameobjectover', pointer, gameObject); gameObject.emit('pointerover', pointer, gameObject.input.localX, gameObject.input.localY); manager.setCursor(gameObject.input); totalInteracted++; } } // Add the contents of justOver to the previously over array previouslyOver = stillOver.concat(justOver); // Then sort it into display list order this._over[pointer.id] = this.sortGameObjects(previouslyOver); return totalInteracted; }, /** * An internal method that handles the Pointer up events. * * @method Phaser.Input.InputPlugin#processUpEvents * @private * @since 3.0.0 * * @param {Phaser.Input.Pointer} pointer - The pointer to check for events against. * * @return {integer} The total number of objects interacted with. */ processUpEvents: function (pointer) { var currentlyOver = this._temp; // Contains ALL Game Objects currently up in the array this.emit('pointerup', pointer, currentlyOver); // Go through all objects the pointer was over and fire their events / callbacks for (var i = 0; i < currentlyOver.length; i++) { var gameObject = currentlyOver[i]; if (!gameObject.input) { continue; } // pointerupoutside gameObject.emit('pointerup', pointer, gameObject.input.localX, gameObject.input.localY); this.emit('gameobjectup', pointer, gameObject); } return currentlyOver.length; }, /** * Queues a Game Object for insertion into this Input Plugin on the next update. * * @method Phaser.Input.InputPlugin#queueForInsertion * @private * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} child - The Game Object to add. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ queueForInsertion: function (child) { if (this._pendingInsertion.indexOf(child) === -1 && this._list.indexOf(child) === -1) { this._pendingInsertion.push(child); } return this; }, /** * Queues a Game Object for removal from this Input Plugin on the next update. * * @method Phaser.Input.InputPlugin#queueForRemoval * @private * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} child - The Game Object to remove. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ queueForRemoval: function (child) { this._pendingRemoval.push(child); return this; }, /** * Sets the draggable state of the given array of Game Objects. * * They can either be set to be draggable, or can have their draggable state removed by passing `false`. * * A Game Object will not fire drag events unless it has been specifically enabled for drag. * * @method Phaser.Input.InputPlugin#setDraggable * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObjects - An array of Game Objects to change the draggable state on. * @param {boolean} [value=true] - Set to `true` if the Game Objects should be made draggable, `false` if they should be unset. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setDraggable: function (gameObjects, value) { if (value === undefined) { value = true; } if (!Array.isArray(gameObjects)) { gameObjects = [ gameObjects ]; } for (var i = 0; i < gameObjects.length; i++) { var gameObject = gameObjects[i]; gameObject.input.draggable = value; var index = this._draggable.indexOf(gameObject); if (value && index === -1) { this._draggable.push(gameObject); } else if (!value && index > -1) { this._draggable.splice(index, 1); } } return this; }, /** * Creates a function that can be passed to `setInteractive`, `enable` or `setHitArea` that will handle * pixel-perfect input detection on an Image or Sprite based Game Object, or any custom class that extends them. * * The following will create a sprite that is clickable on any pixel that has an alpha value >= 1. * * ```javascript * this.add.sprite(x, y, key).setInteractive(this.input.makePixelPerfect()); * ``` * * The following will create a sprite that is clickable on any pixel that has an alpha value >= 150. * * ```javascript * this.add.sprite(x, y, key).setInteractive(this.input.makePixelPerfect(150)); * ``` * * Once you have made an Interactive Object pixel perfect it impacts all input related events for it: down, up, * dragstart, drag, etc. * * As a pointer interacts with the Game Object it will constantly poll the texture, extracting a single pixel from * the given coordinates and checking its color values. This is an expensive process, so should only be enabled on * Game Objects that really need it. * * You cannot make non-texture based Game Objects pixel perfect. So this will not work on Graphics, BitmapText, * Render Textures, Text, Tilemaps, Containers or Particles. * * @method Phaser.Input.InputPlugin#makePixelPerfect * @since 3.10.0 * * @param {integer} [alphaTolerance=1] - The alpha level that the pixel should be above to be included as a successful interaction. * * @return {function} A Pixel Perfect Handler for use as a hitArea shape callback. */ makePixelPerfect: function (alphaTolerance) { if (alphaTolerance === undefined) { alphaTolerance = 1; } var textureManager = this.systems.textures; return CreatePixelPerfectHandler(textureManager, alphaTolerance); }, /** * @typedef {object} Phaser.Input.InputConfiguration * * @property {any} [hitArea] - The object / shape to use as the Hit Area. If not given it will try to create a Rectangle based on the texture frame. * @property {function} [hitAreaCallback] - The callback that determines if the pointer is within the Hit Area shape or not. * @property {boolean} [draggable=false] - If `true` the Interactive Object will be set to be draggable and emit drag events. * @property {boolean} [dropZone=false] - If `true` the Interactive Object will be set to be a drop zone for draggable objects. * @property {boolean} [useHandCursor=false] - If `true` the Interactive Object will set the `pointer` hand cursor when a pointer is over it. This is a short-cut for setting `cursor: 'pointer'`. * @property {string} [cursor] - The CSS string to be used when the cursor is over this Interactive Object. * @property {boolean} [pixelPerfect=false] - If `true` the a pixel perfect function will be set for the hit area callback. Only works with texture based Game Objects. * @property {integer} [alphaTolerance=1] - If `pixelPerfect` is set, this is the alpha tolerance threshold value used in the callback. */ /** * Sets the hit area for the given array of Game Objects. * * A hit area is typically one of the geometric shapes Phaser provides, such as a `Phaser.Geom.Rectangle` * or `Phaser.Geom.Circle`. However, it can be any object as long as it works with the provided callback. * * If no hit area is provided a Rectangle is created based on the size of the Game Object, if possible * to calculate. * * The hit area callback is the function that takes an `x` and `y` coordinate and returns a boolean if * those values fall within the area of the shape or not. All of the Phaser geometry objects provide this, * such as `Phaser.Geom.Rectangle.Contains`. * * @method Phaser.Input.InputPlugin#setHitArea * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObjects - An array of Game Objects to set the hit area on. * @param {(Phaser.Input.InputConfiguration|any)} [shape] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used. * @param {HitAreaCallback} [callback] - The 'contains' function to invoke to check if the pointer is within the hit area. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setHitArea: function (gameObjects, shape, callback) { if (shape === undefined) { return this.setHitAreaFromTexture(gameObjects); } if (!Array.isArray(gameObjects)) { gameObjects = [ gameObjects ]; } var draggable = false; var dropZone = false; var cursor = false; var useHandCursor = false; // Config object? if (IsPlainObject(shape)) { var config = shape; shape = GetFastValue(config, 'hitArea', null); callback = GetFastValue(config, 'hitAreaCallback', null); draggable = GetFastValue(config, 'draggable', false); dropZone = GetFastValue(config, 'dropZone', false); cursor = GetFastValue(config, 'cursor', false); useHandCursor = GetFastValue(config, 'useHandCursor', false); var pixelPerfect = GetFastValue(config, 'pixelPerfect', false); var alphaTolerance = GetFastValue(config, 'alphaTolerance', 1); if (pixelPerfect) { shape = {}; callback = this.makePixelPerfect(alphaTolerance); } // Still no hitArea or callback? if (!shape || !callback) { this.setHitAreaFromTexture(gameObjects); } } else if (typeof shape === 'function' && !callback) { callback = shape; shape = {}; } for (var i = 0; i < gameObjects.length; i++) { var gameObject = gameObjects[i]; var io = (!gameObject.input) ? CreateInteractiveObject(gameObject, shape, callback) : gameObject.input; io.dropZone = dropZone; io.cursor = (useHandCursor) ? 'pointer' : cursor; gameObject.input = io; if (draggable) { this.setDraggable(gameObject); } this.queueForInsertion(gameObject); } return this; }, /** * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Circle` shape, using * the given coordinates and radius to control its position and size. * * @method Phaser.Input.InputPlugin#setHitAreaCircle * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObjects - An array of Game Objects to set as having a circle hit area. * @param {number} x - The center of the circle. * @param {number} y - The center of the circle. * @param {number} radius - The radius of the circle. * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Circle.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setHitAreaCircle: function (gameObjects, x, y, radius, callback) { if (callback === undefined) { callback = CircleContains; } var shape = new Circle(x, y, radius); return this.setHitArea(gameObjects, shape, callback); }, /** * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Ellipse` shape, using * the given coordinates and dimensions to control its position and size. * * @method Phaser.Input.InputPlugin#setHitAreaEllipse * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObjects - An array of Game Objects to set as having an ellipse hit area. * @param {number} x - The center of the ellipse. * @param {number} y - The center of the ellipse. * @param {number} width - The width of the ellipse. * @param {number} height - The height of the ellipse. * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Ellipse.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setHitAreaEllipse: function (gameObjects, x, y, width, height, callback) { if (callback === undefined) { callback = EllipseContains; } var shape = new Ellipse(x, y, width, height); return this.setHitArea(gameObjects, shape, callback); }, /** * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Rectangle` shape, using * the Game Objects texture frame to define the position and size of the hit area. * * @method Phaser.Input.InputPlugin#setHitAreaFromTexture * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObjects - An array of Game Objects to set as having an ellipse hit area. * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Rectangle.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setHitAreaFromTexture: function (gameObjects, callback) { if (callback === undefined) { callback = RectangleContains; } if (!Array.isArray(gameObjects)) { gameObjects = [ gameObjects ]; } for (var i = 0; i < gameObjects.length; i++) { var gameObject = gameObjects[i]; var frame = gameObject.frame; var width = 0; var height = 0; if (frame) { width = frame.realWidth; height = frame.realHeight; } else if (gameObject.width) { width = gameObject.width; height = gameObject.height; } if (gameObject.type === 'Container' && (width === 0 || height === 0)) { console.warn('Container.setInteractive() must specify a Shape or call setSize() first'); continue; } if (width !== 0 && height !== 0) { gameObject.input = CreateInteractiveObject(gameObject, new Rectangle(0, 0, width, height), callback); this.queueForInsertion(gameObject); } } return this; }, /** * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Rectangle` shape, using * the given coordinates and dimensions to control its position and size. * * @method Phaser.Input.InputPlugin#setHitAreaRectangle * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObjects - An array of Game Objects to set as having a rectangular hit area. * @param {number} x - The top-left of the rectangle. * @param {number} y - The top-left of the rectangle. * @param {number} width - The width of the rectangle. * @param {number} height - The height of the rectangle. * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Rectangle.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setHitAreaRectangle: function (gameObjects, x, y, width, height, callback) { if (callback === undefined) { callback = RectangleContains; } var shape = new Rectangle(x, y, width, height); return this.setHitArea(gameObjects, shape, callback); }, /** * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Triangle` shape, using * the given coordinates to control the position of its points. * * @method Phaser.Input.InputPlugin#setHitAreaTriangle * @since 3.0.0 * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObjects - An array of Game Objects to set as having a triangular hit area. * @param {number} x1 - The x coordinate of the first point of the triangle. * @param {number} y1 - The y coordinate of the first point of the triangle. * @param {number} x2 - The x coordinate of the second point of the triangle. * @param {number} y2 - The y coordinate of the second point of the triangle. * @param {number} x3 - The x coordinate of the third point of the triangle. * @param {number} y3 - The y coordinate of the third point of the triangle. * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Triangle.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setHitAreaTriangle: function (gameObjects, x1, y1, x2, y2, x3, y3, callback) { if (callback === undefined) { callback = TriangleContains; } var shape = new Triangle(x1, y1, x2, y2, x3, y3); return this.setHitArea(gameObjects, shape, callback); }, /** * Sets the Pointers to always poll. * * When a pointer is polled it runs a hit test to see which Game Objects are currently below it, * or being interacted with it, regardless if the Pointer has actually moved or not. * * You should enable this if you want objects in your game to fire over / out events, and the objects * are constantly moving, but the pointer may not have. Polling every frame has additional computation * costs, especially if there are a large number of interactive objects in your game. * * @method Phaser.Input.InputPlugin#setPollAlways * @since 3.0.0 * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setPollAlways: function () { this.pollRate = 0; this._pollTimer = 0; return this; }, /** * Sets the Pointers to only poll when they are moved or updated. * * When a pointer is polled it runs a hit test to see which Game Objects are currently below it, * or being interacted with it. * * @method Phaser.Input.InputPlugin#setPollOnMove * @since 3.0.0 * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setPollOnMove: function () { this.pollRate = -1; this._pollTimer = 0; return this; }, /** * Sets the poll rate value. This is the amount of time that should have elapsed before a pointer * will be polled again. See the `setPollAlways` and `setPollOnMove` methods. * * @method Phaser.Input.InputPlugin#setPollRate * @since 3.0.0 * * @param {number} value - The amount of time, in ms, that should elapsed before re-polling the pointers. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setPollRate: function (value) { this.pollRate = value; this._pollTimer = 0; return this; }, /** * When set to `true` the global Input Manager will emulate DOM behavior by only emitting events from * the top-most Game Objects in the Display List. * * If set to `false` it will emit events from all Game Objects below a Pointer, not just the top one. * * @method Phaser.Input.InputPlugin#setGlobalTopOnly * @since 3.0.0 * * @param {boolean} value - `true` to only include the top-most Game Object, or `false` to include all Game Objects in a hit test. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setGlobalTopOnly: function (value) { this.manager.globalTopOnly = value; return this; }, /** * When set to `true` this Input Plugin will emulate DOM behavior by only emitting events from * the top-most Game Objects in the Display List. * * If set to `false` it will emit events from all Game Objects below a Pointer, not just the top one. * * @method Phaser.Input.InputPlugin#setTopOnly * @since 3.0.0 * * @param {boolean} value - `true` to only include the top-most Game Object, or `false` to include all Game Objects in a hit test. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ setTopOnly: function (value) { this.topOnly = value; return this; }, /** * Given an array of Game Objects, sort the array and return it, so that the objects are in depth index order * with the lowest at the bottom. * * @method Phaser.Input.InputPlugin#sortGameObjects * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject[]} gameObjects - An array of Game Objects to be sorted. * * @return {Phaser.GameObjects.GameObject[]} The sorted array of Game Objects. */ sortGameObjects: function (gameObjects) { if (gameObjects.length < 2) { return gameObjects; } this.scene.sys.depthSort(); return gameObjects.sort(this.sortHandlerGO.bind(this)); }, /** * Return the child lowest down the display list (with the smallest index) * Will iterate through all parent containers, if present. * * @method Phaser.Input.InputPlugin#sortHandlerGO * @private * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} childA - The first Game Object to compare. * @param {Phaser.GameObjects.GameObject} childB - The second Game Object to compare. * * @return {integer} Returns either a negative or positive integer, or zero if they match. */ sortHandlerGO: function (childA, childB) { if (!childA.parentContainer && !childB.parentContainer) { // Quick bail out when neither child has a container return this.displayList.getIndex(childB) - this.displayList.getIndex(childA); } else if (childA.parentContainer === childB.parentContainer) { // Quick bail out when both children have the same container return childB.parentContainer.getIndex(childB) - childA.parentContainer.getIndex(childA); } else if (childA.parentContainer === childB) { // Quick bail out when childA is a child of childB return -1; } else if (childB.parentContainer === childA) { // Quick bail out when childA is a child of childB return 1; } else { // Container index check var listA = childA.getIndexList(); var listB = childB.getIndexList(); var len = Math.min(listA.length, listB.length); for (var i = 0; i < len; i++) { var indexA = listA[i]; var indexB = listB[i]; if (indexA === indexB) { // Go to the next level down continue; } else { // Non-matching parents, so return return indexB - indexA; } } } // Technically this shouldn't happen, but ... return 0; }, /** * Causes the Input Manager to stop emitting any events for the remainder of this game step. * * @method Phaser.Input.InputPlugin#stopPropagation * @since 3.0.0 * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ stopPropagation: function () { if (this.manager.globalTopOnly) { this.manager.ignoreEvents = true; } return this; }, /** * Adds a callback to be invoked whenever the native DOM `mouseup` or `touchend` events are received. * By setting the `isOnce` argument you can control if the callback is called once, * or every time the DOM event occurs. * * Callbacks passed to this method are invoked _immediately_ when the DOM event happens, * within the scope of the DOM event handler. Therefore, they are considered as 'native' * from the perspective of the browser. This means they can be used for tasks such as * opening new browser windows, or anything which explicitly requires user input to activate. * However, as a result of this, they come with their own risks, and as such should not be used * for general game input, but instead be reserved for special circumstances. * * If all you're trying to do is execute a callback when a pointer is released, then * please use the internal Input event system instead. * * Please understand that these callbacks are invoked when the browser feels like doing so, * which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep * Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects, * change Scenes or manipulate internal systems, otherwise you run a very real risk of creating * heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind * solve. * * @method Phaser.Input.InputPlugin#addUpCallback * @since 3.10.0 * * @param {function} callback - The callback to be invoked on this DOM event. * @param {boolean} [isOnce=true] - `true` if the callback will only be invoked once, `false` to call every time this event happens. * * @return {this} The Input Plugin. */ addUpCallback: function (callback, isOnce) { this.manager.addUpCallback(callback, isOnce); return this; }, /** * Adds a callback to be invoked whenever the native DOM `mousedown` or `touchstart` events are received. * By setting the `isOnce` argument you can control if the callback is called once, * or every time the DOM event occurs. * * Callbacks passed to this method are invoked _immediately_ when the DOM event happens, * within the scope of the DOM event handler. Therefore, they are considered as 'native' * from the perspective of the browser. This means they can be used for tasks such as * opening new browser windows, or anything which explicitly requires user input to activate. * However, as a result of this, they come with their own risks, and as such should not be used * for general game input, but instead be reserved for special circumstances. * * If all you're trying to do is execute a callback when a pointer is down, then * please use the internal Input event system instead. * * Please understand that these callbacks are invoked when the browser feels like doing so, * which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep * Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects, * change Scenes or manipulate internal systems, otherwise you run a very real risk of creating * heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind * solve. * * @method Phaser.Input.InputPlugin#addDownCallback * @since 3.10.0 * * @param {function} callback - The callback to be invoked on this dom event. * @param {boolean} [isOnce=true] - `true` if the callback will only be invoked once, `false` to call every time this event happens. * * @return {this} The Input Plugin. */ addDownCallback: function (callback, isOnce) { this.manager.addDownCallback(callback, isOnce); return this; }, /** * Adds a callback to be invoked whenever the native DOM `mousemove` or `touchmove` events are received. * By setting the `isOnce` argument you can control if the callback is called once, * or every time the DOM event occurs. * * Callbacks passed to this method are invoked _immediately_ when the DOM event happens, * within the scope of the DOM event handler. Therefore, they are considered as 'native' * from the perspective of the browser. This means they can be used for tasks such as * opening new browser windows, or anything which explicitly requires user input to activate. * However, as a result of this, they come with their own risks, and as such should not be used * for general game input, but instead be reserved for special circumstances. * * If all you're trying to do is execute a callback when a pointer is moved, then * please use the internal Input event system instead. * * Please understand that these callbacks are invoked when the browser feels like doing so, * which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep * Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects, * change Scenes or manipulate internal systems, otherwise you run a very real risk of creating * heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind * solve. * * @method Phaser.Input.InputPlugin#addMoveCallback * @since 3.10.0 * * @param {function} callback - The callback to be invoked on this dom event. * @param {boolean} [isOnce=false] - `true` if the callback will only be invoked once, `false` to call every time this event happens. * * @return {this} The Input Plugin. */ addMoveCallback: function (callback, isOnce) { this.manager.addMoveCallback(callback, isOnce); return this; }, /** * Adds new Pointer objects to the Input Manager. * * By default Phaser creates 2 pointer objects: `mousePointer` and `pointer1`. * * You can create more either by calling this method, or by setting the `input.activePointers` property * in the Game Config, up to a maximum of 10 pointers. * * The first 10 pointers are available via the `InputPlugin.pointerX` properties, once they have been added * via this method. * * @method Phaser.Input.InputPlugin#addPointer * @since 3.10.0 * * @param {integer} [quantity=1] The number of new Pointers to create. A maximum of 10 is allowed in total. * * @return {Phaser.Input.Pointer[]} An array containing all of the new Pointer objects that were created. */ addPointer: function (quantity) { return this.manager.addPointer(quantity); }, /** * Tells the Input system to set a custom cursor. * * This cursor will be the default cursor used when interacting with the game canvas. * * If an Interactive Object also sets a custom cursor, this is the cursor that is reset after its use. * * Any valid CSS cursor value is allowed, including paths to image files, i.e.: * * ```javascript * this.input.setDefaultCursor('url(assets/cursors/sword.cur), pointer'); * ``` * * Please read about the differences between browsers when it comes to the file formats and sizes they support: * * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_User_Interface/Using_URL_values_for_the_cursor_property * * It's up to you to pick a suitable cursor format that works across the range of browsers you need to support. * * @method Phaser.Input.InputPlugin#setDefaultCursor * @since 3.10.0 * * @param {string} cursor - The CSS to be used when setting the default cursor. * * @return {Phaser.Input.InputPlugin} This Input instance. */ setDefaultCursor: function (cursor) { this.manager.setDefaultCursor(cursor); return this; }, /** * The Scene that owns this plugin is transitioning in. * * @method Phaser.Input.InputPlugin#transitionIn * @private * @since 3.5.0 */ transitionIn: function () { this.enabled = this.settings.transitionAllowInput; }, /** * The Scene that owns this plugin has finished transitioning in. * * @method Phaser.Input.InputPlugin#transitionComplete * @private * @since 3.5.0 */ transitionComplete: function () { if (!this.settings.transitionAllowInput) { this.enabled = true; } }, /** * The Scene that owns this plugin is transitioning out. * * @method Phaser.Input.InputPlugin#transitionOut * @private * @since 3.5.0 */ transitionOut: function () { this.enabled = this.settings.transitionAllowInput; }, /** * 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.Input.InputPlugin#shutdown * @private * @since 3.0.0 */ shutdown: function () { // Registered input plugins listen for this this.pluginEvents.emit('shutdown'); this._temp.length = 0; this._list.length = 0; this._draggable.length = 0; this._pendingRemoval.length = 0; this._pendingInsertion.length = 0; for (var i = 0; i < 10; i++) { this._drag[i] = []; this._over[i] = []; } this.removeAllListeners(); var eventEmitter = this.systems.events; eventEmitter.off('transitionstart', this.transitionIn, this); eventEmitter.off('transitionout', this.transitionOut, this); eventEmitter.off('transitioncomplete', this.transitionComplete, this); eventEmitter.off('preupdate', this.preUpdate, this); eventEmitter.off('update', this.update, this); eventEmitter.off('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.Input.InputPlugin#destroy * @private * @since 3.0.0 */ destroy: function () { this.shutdown(); // Registered input plugins listen for this this.pluginEvents.emit('destroy'); this.pluginEvents.removeAllListeners(); this.scene.sys.events.off('start', this.start, this); this.scene = null; this.cameras = null; this.manager = null; this.events = null; this.mouse = null; }, /** * The x coordinates of the ActivePointer based on the first camera in the camera list. * This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch. * * @name Phaser.Input.InputPlugin#x * @type {number} * @readOnly * @since 3.0.0 */ x: { get: function () { return this.manager.activePointer.x; } }, /** * The y coordinates of the ActivePointer based on the first camera in the camera list. * This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch. * * @name Phaser.Input.InputPlugin#y * @type {number} * @readOnly * @since 3.0.0 */ y: { get: function () { return this.manager.activePointer.y; } }, /** * The mouse has its own unique Pointer object, which you can reference directly if making a _desktop specific game_. * If you are supporting both desktop and touch devices then do not use this property, instead use `activePointer` * which will always map to the most recently interacted pointer. * * @name Phaser.Input.InputPlugin#mousePointer * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ mousePointer: { get: function () { return this.manager.mousePointer; } }, /** * The current active input Pointer. * * @name Phaser.Input.InputPlugin#activePointer * @type {Phaser.Input.Pointer} * @readOnly * @since 3.0.0 */ activePointer: { get: function () { return this.manager.activePointer; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer1 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer1: { get: function () { return this.manager.pointers[1]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer2 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer2: { get: function () { return this.manager.pointers[2]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer3 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer3: { get: function () { return this.manager.pointers[3]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer4 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer4: { get: function () { return this.manager.pointers[4]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer5 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer5: { get: function () { return this.manager.pointers[5]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer6 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer6: { get: function () { return this.manager.pointers[6]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer7 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer7: { get: function () { return this.manager.pointers[7]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer8 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer8: { get: function () { return this.manager.pointers[8]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer9 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer9: { get: function () { return this.manager.pointers[9]; } }, /** * A touch-based Pointer object. * This will be `undefined` by default unless you add a new Pointer using `addPointer`. * * @name Phaser.Input.InputPlugin#pointer10 * @type {Phaser.Input.Pointer} * @readOnly * @since 3.10.0 */ pointer10: { get: function () { return this.manager.pointers[10]; } } }); PluginCache.register('InputPlugin', InputPlugin, 'input'); module.exports = InputPlugin; /***/ }), /* 377 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * XBox 360 Gamepad Configuration. * * @name Phaser.Input.Gamepad.Configs.XBOX_360 * @type {object} * @since 3.0.0 */ module.exports = { UP: 12, DOWN: 13, LEFT: 14, RIGHT: 15, MENU: 16, A: 0, B: 1, X: 2, Y: 3, LB: 4, RB: 5, LT: 6, RT: 7, BACK: 8, START: 9, LS: 10, RS: 11, LEFT_STICK_H: 0, LEFT_STICK_V: 1, RIGHT_STICK_H: 2, RIGHT_STICK_V: 3 }; /***/ }), /* 378 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Tatar SNES USB Controller Gamepad Configuration. * USB Gamepad (STANDARD GAMEPAD Vendor: 0079 Product: 0011) * * @name Phaser.Input.Gamepad.Configs.SNES_USB * @type {object} * @since 3.0.0 */ module.exports = { UP: 12, DOWN: 13, LEFT: 14, RIGHT: 15, SELECT: 8, START: 9, B: 0, A: 1, Y: 2, X: 3, LEFT_SHOULDER: 4, RIGHT_SHOULDER: 5 }; /***/ }), /* 379 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * PlayStation DualShock 4 Gamepad Configuration. * Sony PlayStation DualShock 4 (v2) wireless controller * * @name Phaser.Input.Gamepad.Configs.DUALSHOCK_4 * @type {object} * @since 3.0.0 */ module.exports = { UP: 12, DOWN: 13, LEFT: 14, RIGHT: 15, SHARE: 8, OPTIONS: 9, PS: 16, TOUCHBAR: 17, X: 0, CIRCLE: 1, SQUARE: 2, TRIANGLE: 3, L1: 4, R1: 5, L2: 6, R2: 7, L3: 10, R3: 11, LEFT_STICK_H: 0, LEFT_STICK_V: 1, RIGHT_STICK_H: 2, RIGHT_STICK_V: 3 }; /***/ }), /* 380 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Input.Gamepad.Configs */ module.exports = { DUALSHOCK_4: __webpack_require__(379), SNES_USB: __webpack_require__(378), XBOX_360: __webpack_require__(377) }; /***/ }), /* 381 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var EventEmitter = __webpack_require__(9); var Gamepad = __webpack_require__(172); var GetValue = __webpack_require__(4); var InputPluginCache = __webpack_require__(76); /** * @typedef {object} Pad * * @property {string} id - The ID of the Gamepad. * @property {integer} index - The index of the Gamepad. */ /** * @classdesc * The Gamepad Plugin is an input plugin that belongs to the Scene-owned Input system. * * Its role is to listen for native DOM Gamepad Events and then process them. * * You do not need to create this class directly, the Input system will create an instance of it automatically. * * You can access it from within a Scene using `this.input.gamepad`. * * To listen for a gamepad being connected: * * ```javascript * this.input.gamepad.once('connected', function (pad) { * // 'pad' is a reference to the gamepad that was just connected * }); * ``` * * Note that the browser may require you to press a button on a gamepad before it will allow you to access it, * this is for security reasons. However, it may also trust the page already, in which case you won't get the * 'connected' event and instead should check `GamepadPlugin.total` to see if it thinks there are any gamepads * already connected. * * Once you have received the connected event, or polled the gamepads and found them enabled, you can access * them via the built-in properties `GamepadPlugin.pad1` to `pad4`, for up to 4 game pads. With a reference * to the gamepads you can poll its buttons and axis sticks. See the properties and methods available on * the `Gamepad` class for more details. * * For more information about Gamepad support in browsers see the following resources: * * https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API * https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API * https://www.smashingmagazine.com/2015/11/gamepad-api-in-web-games/ * http://html5gamepad.com/ * * @class GamepadPlugin * @extends Phaser.Events.EventEmitter * @memberOf Phaser.Input.Gamepad * @constructor * @since 3.10.0 * * @param {Phaser.Input.InputPlugin} sceneInputPlugin - A reference to the Scene Input Plugin that the KeyboardPlugin belongs to. */ var GamepadPlugin = new Class({ Extends: EventEmitter, initialize: function GamepadPlugin (sceneInputPlugin) { EventEmitter.call(this); /** * A reference to the Scene that this Input Plugin is responsible for. * * @name Phaser.Input.Gamepad.GamepadPlugin#scene * @type {Phaser.Scene} * @since 3.10.0 */ this.scene = sceneInputPlugin.scene; /** * A reference to the Scene Systems Settings. * * @name Phaser.Input.Gamepad.GamepadPlugin#settings * @type {Phaser.Scenes.Settings.Object} * @since 3.10.0 */ this.settings = this.scene.sys.settings; /** * A reference to the Scene Input Plugin that created this Keyboard Plugin. * * @name Phaser.Input.Gamepad.GamepadPlugin#sceneInputPlugin * @type {Phaser.Input.InputPlugin} * @since 3.10.0 */ this.sceneInputPlugin = sceneInputPlugin; /** * A boolean that controls if the Gamepad Manager is enabled or not. * Can be toggled on the fly. * * @name Phaser.Input.Gamepad.GamepadPlugin#enabled * @type {boolean} * @default true * @since 3.10.0 */ this.enabled = true; /** * The Gamepad Event target, as defined in the Game Config. * Typically the browser window, but can be any interactive DOM element. * * @name Phaser.Input.Gamepad.GamepadPlugin#target * @type {any} * @since 3.10.0 */ this.target; /** * An array of the connected Gamepads. * * @name Phaser.Input.Gamepad.GamepadPlugin#gamepads * @type {Phaser.Input.Gamepad.Gamepad[]} * @default [] * @since 3.10.0 */ this.gamepads = []; /** * An internal event queue. * * @name Phaser.Input.Gamepad.GamepadPlugin#queue * @type {GamepadEvent[]} * @private * @since 3.10.0 */ this.queue = []; /** * Internal event handler. * * @name Phaser.Input.Gamepad.GamepadPlugin#onGamepadHandler * @type {function} * @private * @since 3.10.0 */ this.onGamepadHandler; /** * Internal Gamepad reference. * * @name Phaser.Input.Gamepad.GamepadPlugin#_pad1 * @type {Phaser.Input.Gamepad.Gamepad} * @private * @since 3.10.0 */ this._pad1; /** * Internal Gamepad reference. * * @name Phaser.Input.Gamepad.GamepadPlugin#_pad2 * @type {Phaser.Input.Gamepad.Gamepad} * @private * @since 3.10.0 */ this._pad2; /** * Internal Gamepad reference. * * @name Phaser.Input.Gamepad.GamepadPlugin#_pad3 * @type {Phaser.Input.Gamepad.Gamepad} * @private * @since 3.10.0 */ this._pad3; /** * Internal Gamepad reference. * * @name Phaser.Input.Gamepad.GamepadPlugin#_pad4 * @type {Phaser.Input.Gamepad.Gamepad} * @private * @since 3.10.0 */ this._pad4; sceneInputPlugin.pluginEvents.once('boot', this.boot, this); sceneInputPlugin.pluginEvents.on('start', this.start, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Input.Gamepad.GamepadPlugin#boot * @private * @since 3.10.0 */ boot: function () { var game = this.scene.sys.game; var settings = this.settings.input; var config = game.config; this.enabled = GetValue(settings, 'gamepad', config.inputGamepad) && game.device.input.gamepads; this.target = GetValue(settings, 'gamepad.target', config.inputGamepadEventTarget); this.sceneInputPlugin.pluginEvents.once('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.Input.Gamepad.GamepadPlugin#start * @private * @since 3.10.0 */ start: function () { if (this.enabled) { this.startListeners(); } this.sceneInputPlugin.pluginEvents.once('shutdown', this.shutdown, this); }, /** * Checks to see if both this plugin and the Scene to which it belongs is active. * * @method Phaser.Input.Gamepad.GamepadPlugin#isActive * @since 3.10.0 * * @return {boolean} `true` if the plugin and the Scene it belongs to is active. */ isActive: function () { return (this.enabled && this.scene.sys.isActive()); }, /** * Starts the Gamepad Event listeners running. * This is called automatically and does not need to be manually invoked. * * @method Phaser.Input.Gamepad.GamepadPlugin#startListeners * @private * @since 3.10.0 */ startListeners: function () { var _this = this; var target = this.target; var handler = function (event) { // console.log(event); if (event.defaultPrevented || !_this.isActive()) { // Do nothing if event already handled return; } _this.refreshPads(); _this.queue.push(event); }; this.onGamepadHandler = handler; target.addEventListener('gamepadconnected', handler, false); target.addEventListener('gamepaddisconnected', handler, false); // FF also supports gamepadbuttondown, gamepadbuttonup and gamepadaxismove but // nothing else does, and we can get those values via the gamepads anyway, so we will // until more browsers support this // Finally, listen for an update event from the Input Plugin this.sceneInputPlugin.pluginEvents.on('update', this.update, this); }, /** * Stops the Gamepad Event listeners. * This is called automatically and does not need to be manually invoked. * * @method Phaser.Input.Gamepad.GamepadPlugin#stopListeners * @private * @since 3.10.0 */ stopListeners: function () { this.target.removeEventListener('gamepadconnected', this.onGamepadHandler); this.target.removeEventListener('gamepaddisconnected', this.onGamepadHandler); this.sceneInputPlugin.pluginEvents.off('update', this.update); }, /** * Disconnects all current Gamepads. * * @method Phaser.Input.Gamepad.GamepadPlugin#disconnectAll * @since 3.10.0 */ disconnectAll: function () { for (var i = 0; i < this.gamepads.length; i++) { this.gamepads.connected = false; } }, /** * Refreshes the list of connected Gamepads. * * This is called automatically when a gamepad is connected or disconnected, * and during the update loop. * * @method Phaser.Input.Gamepad.GamepadPlugin#refreshPads * @private * @since 3.10.0 */ refreshPads: function () { var connectedPads = navigator.getGamepads(); if (!connectedPads) { this.disconnectAll(); } else { var currentPads = this.gamepads; for (var i = 0; i < connectedPads.length; i++) { var livePad = connectedPads[i]; // Because sometimes they're null (yes, really) if (!livePad) { continue; } var id = livePad.id; var index = livePad.index; var currentPad = currentPads[index]; if (!currentPad) { // A new Gamepad, not currently stored locally var newPad = new Gamepad(this, livePad); currentPads[index] = newPad; if (!this._pad1) { this._pad1 = newPad; } else if (!this._pad2) { this._pad2 = newPad; } else if (!this._pad3) { this._pad3 = newPad; } else if (!this._pad4) { this._pad4 = newPad; } } else if (currentPad.id !== id) { // A new Gamepad with a different vendor string, but it has got the same index as an old one currentPad.destroy(); currentPads[index] = new Gamepad(this, livePad); } else { // If neither of these, it's a pad we've already got, so update it currentPad.update(livePad); } } } }, /** * Returns an array of all currently connected Gamepads. * * @method Phaser.Input.Gamepad.GamepadPlugin#getAll * @since 3.10.0 * * @return {Phaser.Input.Gamepad.Gamepad[]} An array of all currently connected Gamepads. */ getAll: function () { var out = []; var pads = this.gamepads; for (var i = 0; i < pads.length; i++) { if (pads[i]) { out.push(pads[i]); } } return out; }, /** * Looks-up a single Gamepad based on the given index value. * * @method Phaser.Input.Gamepad.GamepadPlugin#getPad * @since 3.10.0 * * @param {number} index - The index of the Gamepad to get. * * @return {Phaser.Input.Gamepad.Gamepad} The Gamepad matching the given index, or undefined if none were found. */ getPad: function (index) { var pads = this.gamepads; for (var i = 0; i < pads.length; i++) { if (pads[i] && pads[i].index === index) { return pads[i]; } } }, /** * The internal update loop. Refreshes all connected gamepads and processes their events. * * Called automatically by the Input Manager, invoked from the Game step. * * @method Phaser.Input.Gamepad.GamepadPlugin#update * @private * @since 3.10.0 */ update: function () { if (!this.enabled) { return; } this.refreshPads(); var len = this.queue.length; if (len === 0) { return; } var queue = this.queue.splice(0, len); // Process the event queue, dispatching all of the events that have stored up for (var i = 0; i < len; i++) { var event = queue[i]; var pad = this.getPad(event.gamepad.index); if (event.type === 'gamepadconnected') { this.emit('connected', pad, event); } else if (event.type === 'gamepaddisconnected') { this.emit('disconnected', pad, event); } } }, /** * Shuts the Gamepad Plugin down. * All this does is remove any listeners bound to it. * * @method Phaser.Input.Gamepad.GamepadPlugin#shutdown * @private * @since 3.10.0 */ shutdown: function () { this.stopListeners(); this.disconnectAll(); this.removeAllListeners(); }, /** * Destroys this Gamepad Plugin, disconnecting all Gamepads and releasing internal references. * * @method Phaser.Input.Gamepad.GamepadPlugin#destroy * @private * @since 3.10.0 */ destroy: function () { this.shutdown(); for (var i = 0; i < this.gamepads.length; i++) { if (this.gamepads[i]) { this.gamepads[i].destroy(); } } this.gamepads = []; this.scene = null; this.settings = null; this.sceneInputPlugin = null; this.target = null; }, /** * The total number of connected game pads. * * @name Phaser.Input.Gamepad.GamepadPlugin#total * @type {integer} * @since 3.10.0 */ total: { get: function () { return this.gamepads.length; } }, /** * A reference to the first connected Gamepad. * * This will be undefined if either no pads are connected, or the browser * has not yet issued a gamepadconnect, which can happen even if a Gamepad * is plugged in, but hasn't yet had any buttons pressed on it. * * @name Phaser.Input.Gamepad.GamepadPlugin#pad1 * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.10.0 */ pad1: { get: function () { return this._pad1; } }, /** * A reference to the second connected Gamepad. * * This will be undefined if either no pads are connected, or the browser * has not yet issued a gamepadconnect, which can happen even if a Gamepad * is plugged in, but hasn't yet had any buttons pressed on it. * * @name Phaser.Input.Gamepad.GamepadPlugin#pad2 * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.10.0 */ pad2: { get: function () { return this._pad2; } }, /** * A reference to the third connected Gamepad. * * This will be undefined if either no pads are connected, or the browser * has not yet issued a gamepadconnect, which can happen even if a Gamepad * is plugged in, but hasn't yet had any buttons pressed on it. * * @name Phaser.Input.Gamepad.GamepadPlugin#pad3 * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.10.0 */ pad3: { get: function () { return this._pad3; } }, /** * A reference to the fourth connected Gamepad. * * This will be undefined if either no pads are connected, or the browser * has not yet issued a gamepadconnect, which can happen even if a Gamepad * is plugged in, but hasn't yet had any buttons pressed on it. * * @name Phaser.Input.Gamepad.GamepadPlugin#pad4 * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.10.0 */ pad4: { get: function () { return this._pad4; } } }); /** * An instance of the Gamepad Plugin class, if enabled via the `input.gamepad` Scene or Game Config property. * Use this to create access Gamepads connected to the browser and respond to gamepad buttons. * * @name Phaser.Input.InputPlugin#gamepad * @type {?Phaser.Input.Gamepad.GamepadPlugin} * @since 3.10.0 */ InputPluginCache.register('GamepadPlugin', GamepadPlugin, 'gamepad', 'gamepad', 'inputGamepad'); module.exports = GamepadPlugin; /***/ }), /* 382 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Input.Gamepad */ module.exports = { Axis: __webpack_require__(174), Button: __webpack_require__(173), Gamepad: __webpack_require__(172), GamepadPlugin: __webpack_require__(381), Configs: __webpack_require__(380) }; /***/ }), /* 383 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CONST = __webpack_require__(200); var Extend = __webpack_require__(17); /** * @namespace Phaser.Input */ var Input = { CreateInteractiveObject: __webpack_require__(175), Gamepad: __webpack_require__(382), InputManager: __webpack_require__(201), InputPlugin: __webpack_require__(376), InputPluginCache: __webpack_require__(76), Keyboard: __webpack_require__(374), Mouse: __webpack_require__(362), Pointer: __webpack_require__(198), Touch: __webpack_require__(361) }; // Merge in the consts Input = Extend(false, Input, CONST); module.exports = Input; /***/ }), /* 384 */, /* 385 */, /* 386 */, /* 387 */, /* 388 */, /* 389 */, /* 390 */, /* 391 */, /* 392 */, /* 393 */, /* 394 */, /* 395 */, /* 396 */, /* 397 */, /* 398 */, /* 399 */, /* 400 */, /* 401 */, /* 402 */, /* 403 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BuildGameObject = __webpack_require__(24); var GameObjectCreator = __webpack_require__(13); var GetAdvancedValue = __webpack_require__(10); var Text = __webpack_require__(110); /** * Creates a new Text Game Object and returns it. * * Note: This method will only be available if the Text Game Object has been built into Phaser. * * @method Phaser.GameObjects.GameObjectCreator#text * @since 3.0.0 * * @param {object} config - The configuration object this Game Object will use to create itself. * @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object. * * @return {Phaser.GameObjects.Text} The Game Object that was created. */ GameObjectCreator.register('text', function (config, addToScene) { if (config === undefined) { config = {}; } // style Object = { // font: [ 'font', '16px Courier' ], // backgroundColor: [ 'backgroundColor', null ], // fill: [ 'fill', '#fff' ], // stroke: [ 'stroke', '#fff' ], // strokeThickness: [ 'strokeThickness', 0 ], // shadowOffsetX: [ 'shadow.offsetX', 0 ], // shadowOffsetY: [ 'shadow.offsetY', 0 ], // shadowColor: [ 'shadow.color', '#000' ], // shadowBlur: [ 'shadow.blur', 0 ], // shadowStroke: [ 'shadow.stroke', false ], // shadowFill: [ 'shadow.fill', false ], // align: [ 'align', 'left' ], // maxLines: [ 'maxLines', 0 ], // fixedWidth: [ 'fixedWidth', false ], // fixedHeight: [ 'fixedHeight', false ], // rtl: [ 'rtl', false ] // } var content = GetAdvancedValue(config, 'text', ''); var style = GetAdvancedValue(config, 'style', null); // Padding // { padding: 2 } // { padding: { x: , y: }} // { padding: { left: , top: }} // { padding: { left: , right: , top: , bottom: }} var padding = GetAdvancedValue(config, 'padding', null); if (padding !== null) { style.padding = padding; } var text = new Text(this.scene, 0, 0, content, style); if (addToScene !== undefined) { config.add = addToScene; } BuildGameObject(this.scene, text, config); // Text specific config options: text.autoRound = GetAdvancedValue(config, 'autoRound', true); text.resolution = GetAdvancedValue(config, 'resolution', 1); return text; }); // When registering a factory function 'this' refers to the GameObjectCreator context. /***/ }), /* 404 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BuildGameObject = __webpack_require__(24); var BuildGameObjectAnimation = __webpack_require__(127); var GameObjectCreator = __webpack_require__(13); var GetAdvancedValue = __webpack_require__(10); var Sprite = __webpack_require__(34); /** * Creates a new Sprite Game Object and returns it. * * Note: This method will only be available if the Sprite Game Object has been built into Phaser. * * @method Phaser.GameObjects.GameObjectCreator#sprite * @since 3.0.0 * * @param {object} config - The configuration object this Game Object will use to create itself. * @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object. * * @return {Phaser.GameObjects.Sprite} The Game Object that was created. */ GameObjectCreator.register('sprite', function (config, addToScene) { if (config === undefined) { config = {}; } var key = GetAdvancedValue(config, 'key', null); var frame = GetAdvancedValue(config, 'frame', null); var sprite = new Sprite(this.scene, 0, 0, key, frame); if (addToScene !== undefined) { config.add = addToScene; } BuildGameObject(this.scene, sprite, config); // Sprite specific config options: BuildGameObjectAnimation(sprite, config); return sprite; }); /***/ }), /* 405 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BuildGameObject = __webpack_require__(24); var GameObjectCreator = __webpack_require__(13); var GetAdvancedValue = __webpack_require__(10); var Image = __webpack_require__(69); /** * Creates a new Image Game Object and returns it. * * Note: This method will only be available if the Image Game Object has been built into Phaser. * * @method Phaser.GameObjects.GameObjectCreator#image * @since 3.0.0 * * @param {object} config - The configuration object this Game Object will use to create itself. * @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object. * * @return {Phaser.GameObjects.Image} The Game Object that was created. */ GameObjectCreator.register('image', function (config, addToScene) { if (config === undefined) { config = {}; } var key = GetAdvancedValue(config, 'key', null); var frame = GetAdvancedValue(config, 'frame', null); var image = new Image(this.scene, 0, 0, key, frame); if (addToScene !== undefined) { config.add = addToScene; } BuildGameObject(this.scene, image, config); return image; }); // When registering a factory function 'this' refers to the GameObjectCreator context. /***/ }), /* 406 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObjectCreator = __webpack_require__(13); var Graphics = __webpack_require__(115); /** * Creates a new Graphics Game Object and returns it. * * Note: This method will only be available if the Graphics Game Object has been built into Phaser. * * @method Phaser.GameObjects.GameObjectCreator#graphics * @since 3.0.0 * * @param {object} config - The configuration object this Game Object will use to create itself. * @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object. * * @return {Phaser.GameObjects.Graphics} The Game Object that was created. */ GameObjectCreator.register('graphics', function (config, addToScene) { if (config === undefined) { config = {}; } if (addToScene !== undefined) { config.add = addToScene; } var graphics = new Graphics(this.scene, config); if (config.add) { this.scene.sys.displayList.add(graphics); } return graphics; }); // When registering a factory function 'this' refers to the GameObjectCreator context. /***/ }), /* 407 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Text = __webpack_require__(110); var GameObjectFactory = __webpack_require__(11); /** * Creates a new Text Game Object and adds it to the Scene. * * Note: This method will only be available if the Text Game Object has been built into Phaser. * * @method Phaser.GameObjects.GameObjectFactory#text * @since 3.0.0 * * @param {number} x - The horizontal position of this Game Object in the world. * @param {number} y - The vertical position of this Game Object in the world. * @param {(string|string[])} text - The text this Text object will display. * @param {object} [style] - The Text style configuration object. * * @return {Phaser.GameObjects.Text} The Game Object that was created. */ GameObjectFactory.register('text', function (x, y, text, style) { return this.displayList.add(new Text(this.scene, x, y, text, style)); }); // When registering a factory function 'this' refers to the GameObjectFactory context. // // There are several properties available to use: // // this.scene - a reference to the Scene that owns the GameObjectFactory // this.displayList - a reference to the Display List the Scene owns // this.updateList - a reference to the Update List the Scene owns /***/ }), /* 408 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObjectFactory = __webpack_require__(11); var Sprite = __webpack_require__(34); /** * Creates a new Sprite Game Object and adds it to the Scene. * * Note: This method will only be available if the Sprite Game Object has been built into Phaser. * * @method Phaser.GameObjects.GameObjectFactory#sprite * @since 3.0.0 * * @param {number} x - The horizontal position of this Game Object in the world. * @param {number} y - The vertical position of this Game Object in the world. * @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with. * * @return {Phaser.GameObjects.Sprite} The Game Object that was created. */ GameObjectFactory.register('sprite', function (x, y, key, frame) { var sprite = new Sprite(this.scene, x, y, key, frame); this.displayList.add(sprite); this.updateList.add(sprite); return sprite; }); // When registering a factory function 'this' refers to the GameObjectFactory context. // // There are several properties available to use: // // this.scene - a reference to the Scene that owns the GameObjectFactory // this.displayList - a reference to the Display List the Scene owns // this.updateList - a reference to the Update List the Scene owns /***/ }), /* 409 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Image = __webpack_require__(69); var GameObjectFactory = __webpack_require__(11); /** * Creates a new Image Game Object and adds it to the Scene. * * Note: This method will only be available if the Image Game Object has been built into Phaser. * * @method Phaser.GameObjects.GameObjectFactory#image * @since 3.0.0 * * @param {number} x - The horizontal position of this Game Object in the world. * @param {number} y - The vertical position of this Game Object in the world. * @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with. * * @return {Phaser.GameObjects.Image} The Game Object that was created. */ GameObjectFactory.register('image', function (x, y, key, frame) { return this.displayList.add(new Image(this.scene, x, y, key, frame)); }); // When registering a factory function 'this' refers to the GameObjectFactory context. // // There are several properties available to use: // // this.scene - a reference to the Scene that owns the GameObjectFactory // this.displayList - a reference to the Display List the Scene owns // this.updateList - a reference to the Update List the Scene owns /***/ }), /* 410 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Graphics = __webpack_require__(115); var GameObjectFactory = __webpack_require__(11); /** * Creates a new Graphics Game Object and adds it to the Scene. * * Note: This method will only be available if the Graphics Game Object has been built into Phaser. * * @method Phaser.GameObjects.GameObjectFactory#graphics * @since 3.0.0 * * @param {GraphicsOptions} [config] - The Graphics configuration. * * @return {Phaser.GameObjects.Graphics} The Game Object that was created. */ GameObjectFactory.register('graphics', function (config) { return this.displayList.add(new Graphics(this.scene, config)); }); // When registering a factory function 'this' refers to the GameObjectFactory context. // // There are several properties available to use: // // this.scene - a reference to the Scene that owns the GameObjectFactory // this.displayList - a reference to the Display List the Scene owns // this.updateList - a reference to the Update List the Scene owns /***/ }), /* 411 */, /* 412 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CanvasPool = __webpack_require__(22); /** * Calculates the ascent, descent and fontSize of a given font style. * * @function Phaser.GameObjects.Text.MeasureText * @since 3.0.0 * * @param {Phaser.GameObjects.Text.TextStyle} textStyle - The TextStyle object to measure. * * @return {object} An object containing the ascent, descent and fontSize of the TextStyle. */ var MeasureText = function (textStyle) { // @property {HTMLCanvasElement} canvas - The canvas element that the text is rendered. var canvas = CanvasPool.create(this); // @property {HTMLCanvasElement} context - The context of the canvas element that the text is rendered to. var context = canvas.getContext('2d'); textStyle.syncFont(canvas, context); var width = Math.ceil(context.measureText(textStyle.testString).width * textStyle.baselineX); var baseline = width; var height = 2 * baseline; baseline = baseline * textStyle.baselineY | 0; canvas.width = width; canvas.height = height; context.fillStyle = '#f00'; context.fillRect(0, 0, width, height); context.font = textStyle._font; context.textBaseline = 'alphabetic'; context.fillStyle = '#000'; context.fillText(textStyle.testString, 0, baseline); var output = { ascent: 0, descent: 0, fontSize: 0 }; if (!context.getImageData(0, 0, width, height)) { output.ascent = baseline; output.descent = baseline + 6; output.fontSize = output.ascent + output.descent; CanvasPool.remove(canvas); return output; } var imagedata = context.getImageData(0, 0, width, height).data; var pixels = imagedata.length; var line = width * 4; var i; var j; var idx = 0; var stop = false; // ascent. scan from top to bottom until we find a non red pixel for (i = 0; i < baseline; i++) { for (j = 0; j < line; j += 4) { if (imagedata[idx + j] !== 255) { stop = true; break; } } if (!stop) { idx += line; } else { break; } } output.ascent = baseline - i; idx = pixels - line; stop = false; // descent. scan from bottom to top until we find a non red pixel for (i = height; i > baseline; i--) { for (j = 0; j < line; j += 4) { if (imagedata[idx + j] !== 255) { stop = true; break; } } if (!stop) { idx -= line; } else { break; } } output.descent = (i - baseline); output.fontSize = output.ascent + output.descent; CanvasPool.remove(canvas); return output; }; module.exports = MeasureText; /***/ }), /* 413 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var GetAdvancedValue = __webpack_require__(10); var GetValue = __webpack_require__(4); var MeasureText = __webpack_require__(412); // Key: [ Object Key, Default Value ] /** * A custom function that will be responsible for wrapping the text. * @callback TextStyleWordWrapCallback * * @param {string} text - The string to wrap. * @param {Phaser.GameObjects.Text} textObject - The Text instance. * * @return {(string|string[])} Should return the wrapped lines either as an array of lines or as a string with * newline characters in place to indicate where breaks should happen. */ var propertyMap = { fontFamily: [ 'fontFamily', 'Courier' ], fontSize: [ 'fontSize', '16px' ], fontStyle: [ 'fontStyle', '' ], backgroundColor: [ 'backgroundColor', null ], color: [ 'color', '#fff' ], stroke: [ 'stroke', '#fff' ], strokeThickness: [ 'strokeThickness', 0 ], shadowOffsetX: [ 'shadow.offsetX', 0 ], shadowOffsetY: [ 'shadow.offsetY', 0 ], shadowColor: [ 'shadow.color', '#000' ], shadowBlur: [ 'shadow.blur', 0 ], shadowStroke: [ 'shadow.stroke', false ], shadowFill: [ 'shadow.fill', false ], align: [ 'align', 'left' ], maxLines: [ 'maxLines', 0 ], fixedWidth: [ 'fixedWidth', 0 ], fixedHeight: [ 'fixedHeight', 0 ], rtl: [ 'rtl', false ], testString: [ 'testString', '|MÉqgy' ], baselineX: [ 'baselineX', 1.2 ], baselineY: [ 'baselineY', 1.4 ], wordWrapWidth: [ 'wordWrap.width', null ], wordWrapCallback: [ 'wordWrap.callback', null ], wordWrapCallbackScope: [ 'wordWrap.callbackScope', null ], wordWrapUseAdvanced: [ 'wordWrap.useAdvancedWrap', false ] }; /** * @classdesc * [description] * * @class TextStyle * @memberOf Phaser.GameObjects.Text * @constructor * @since 3.0.0 * * @param {Phaser.GameObjects.Text} text - The Text object that this TextStyle is styling. * @param {object} style - [description] */ var TextStyle = new Class({ initialize: function TextStyle (text, style) { /** * The Text object that this TextStyle is styling. * * @name Phaser.GameObjects.Text.TextStyle#parent * @type {Phaser.GameObjects.Text} * @since 3.0.0 */ this.parent = text; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#fontFamily * @type {string} * @default 'Courier' * @since 3.0.0 */ this.fontFamily; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#fontSize * @type {string} * @default '16px' * @since 3.0.0 */ this.fontSize; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#fontStyle * @type {string} * @since 3.0.0 */ this.fontStyle; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#backgroundColor * @type {string} * @since 3.0.0 */ this.backgroundColor; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#color * @type {string} * @default '#fff' * @since 3.0.0 */ this.color; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#stroke * @type {string} * @default '#fff' * @since 3.0.0 */ this.stroke; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#strokeThickness * @type {number} * @default 0 * @since 3.0.0 */ this.strokeThickness; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#shadowOffsetX * @type {number} * @default 0 * @since 3.0.0 */ this.shadowOffsetX; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#shadowOffsetY * @type {number} * @default 0 * @since 3.0.0 */ this.shadowOffsetY; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#shadowColor * @type {string} * @default '#000' * @since 3.0.0 */ this.shadowColor; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#shadowBlur * @type {number} * @default 0 * @since 3.0.0 */ this.shadowBlur; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#shadowStroke * @type {boolean} * @default false * @since 3.0.0 */ this.shadowStroke; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#shadowFill * @type {boolean} * @default false * @since 3.0.0 */ this.shadowFill; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#align * @type {string} * @default 'left' * @since 3.0.0 */ this.align; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#maxLines * @type {integer} * @default 0 * @since 3.0.0 */ this.maxLines; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#fixedWidth * @type {number} * @default 0 * @since 3.0.0 */ this.fixedWidth; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#fixedHeight * @type {number} * @default 0 * @since 3.0.0 */ this.fixedHeight; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#rtl * @type {boolean} * @default false * @since 3.0.0 */ this.rtl; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#testString * @type {string} * @default '|MÉqgy' * @since 3.0.0 */ this.testString; /** * The amount of horizontal padding adding to the width of the text when calculating the font metrics. * * @name Phaser.GameObjects.Text.TextStyle#baselineX * @type {number} * @default 1.2 * @since 3.3.0 */ this.baselineX; /** * The amount of vertical padding adding to the width of the text when calculating the font metrics. * * @name Phaser.GameObjects.Text.TextStyle#baselineY * @type {number} * @default 1.4 * @since 3.3.0 */ this.baselineY; /** * [description] * * @name Phaser.GameObjects.Text.TextStyle#_font * @type {string} * @private * @since 3.0.0 */ this._font; // Set to defaults + user style this.setStyle(style, false); var metrics = GetValue(style, 'metrics', false); // Provide optional TextMetrics in the style object to avoid the canvas look-up / scanning // Doing this is reset if you then change the font of this TextStyle after creation if (metrics) { this.metrics = { ascent: GetValue(metrics, 'ascent', 0), descent: GetValue(metrics, 'descent', 0), fontSize: GetValue(metrics, 'fontSize', 0) }; } else { this.metrics = MeasureText(this); } }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setStyle * @since 3.0.0 * * @param {CSSStyleRule} style - [description] * @param {boolean} [updateText=true] - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setStyle: function (style, updateText) { if (updateText === undefined) { updateText = true; } // Avoid type mutation if (style && style.hasOwnProperty('fontSize') && typeof style.fontSize === 'number') { style.fontSize = style.fontSize.toString() + 'px'; } for (var key in propertyMap) { if (key === 'wordWrapCallback' || key === 'wordWrapCallbackScope') { // Callback & scope should be set without processing the values this[key] = GetValue(style, propertyMap[key][0], propertyMap[key][1]); } else { this[key] = GetAdvancedValue(style, propertyMap[key][0], propertyMap[key][1]); } } // Allow for 'font' override var font = GetValue(style, 'font', null); if (font === null) { this._font = [ this.fontStyle, this.fontSize, this.fontFamily ].join(' '); } else { this._font = font; } // Allow for 'fill' to be used in place of 'color' var fill = GetValue(style, 'fill', null); if (fill !== null) { this.color = fill; } if (updateText) { return this.update(true); } else { return this.parent; } }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#syncFont * @since 3.0.0 * * @param {HTMLCanvasElement} canvas - [description] * @param {CanvasRenderingContext2D} context - [description] */ syncFont: function (canvas, context) { context.font = this._font; }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#syncStyle * @since 3.0.0 * * @param {HTMLCanvasElement} canvas - [description] * @param {CanvasRenderingContext2D} context - [description] */ syncStyle: function (canvas, context) { context.textBaseline = 'alphabetic'; context.fillStyle = this.color; context.strokeStyle = this.stroke; context.lineWidth = this.strokeThickness; context.lineCap = 'round'; context.lineJoin = 'round'; }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#syncShadow * @since 3.0.0 * * @param {CanvasRenderingContext2D} context - [description] * @param {boolean} enabled - [description] */ syncShadow: function (context, enabled) { if (enabled) { context.shadowOffsetX = this.shadowOffsetX; context.shadowOffsetY = this.shadowOffsetY; context.shadowColor = this.shadowColor; context.shadowBlur = this.shadowBlur; } else { context.shadowOffsetX = 0; context.shadowOffsetY = 0; context.shadowColor = 0; context.shadowBlur = 0; } }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#update * @since 3.0.0 * * @param {boolean} recalculateMetrics - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ update: function (recalculateMetrics) { if (recalculateMetrics) { this._font = [ this.fontStyle, this.fontSize, this.fontFamily ].join(' '); this.metrics = MeasureText(this); } return this.parent.updateText(); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setFont * @since 3.0.0 * * @param {(string|object)} font - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setFont: function (font) { if (typeof font === 'string') { this.fontFamily = font; this.fontSize = ''; this.fontStyle = ''; } else { this.fontFamily = GetValue(font, 'fontFamily', 'Courier'); this.fontSize = GetValue(font, 'fontSize', '16px'); this.fontStyle = GetValue(font, 'fontStyle', ''); } return this.update(true); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setFontFamily * @since 3.0.0 * * @param {string} family - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setFontFamily: function (family) { this.fontFamily = family; return this.update(true); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setFontStyle * @since 3.0.0 * * @param {string} style - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setFontStyle: function (style) { this.fontStyle = style; return this.update(true); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setFontSize * @since 3.0.0 * * @param {(number|string)} size - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setFontSize: function (size) { if (typeof size === 'number') { size = size.toString() + 'px'; } this.fontSize = size; return this.update(true); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setTestString * @since 3.0.0 * * @param {string} string - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setTestString: function (string) { this.testString = string; return this.update(true); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setFixedSize * @since 3.0.0 * * @param {number} width - [description] * @param {number} height - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setFixedSize: function (width, height) { this.fixedWidth = width; this.fixedHeight = height; if (width) { this.parent.width = width; } if (height) { this.parent.height = height; } return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setBackgroundColor * @since 3.0.0 * * @param {string} color - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setBackgroundColor: function (color) { this.backgroundColor = color; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setFill * @since 3.0.0 * * @param {string} color - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setFill: function (color) { this.color = color; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setColor * @since 3.0.0 * * @param {string} color - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setColor: function (color) { this.color = color; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setStroke * @since 3.0.0 * * @param {string} color - [description] * @param {number} thickness - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setStroke: function (color, thickness) { if (color === undefined) { // Reset the stroke to zero (disabling it) this.strokeThickness = 0; } else { if (thickness === undefined) { thickness = this.strokeThickness; } this.stroke = color; this.strokeThickness = thickness; } return this.update(true); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setShadow * @since 3.0.0 * * @param {number} [x=0] - [description] * @param {number} [y=0] - [description] * @param {string} [color='#000'] - [description] * @param {number} [blur=0] - [description] * @param {boolean} [shadowStroke=false] - [description] * @param {boolean} [shadowFill=true] - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setShadow: function (x, y, color, blur, shadowStroke, shadowFill) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (color === undefined) { color = '#000'; } if (blur === undefined) { blur = 0; } if (shadowStroke === undefined) { shadowStroke = false; } if (shadowFill === undefined) { shadowFill = true; } this.shadowOffsetX = x; this.shadowOffsetY = y; this.shadowColor = color; this.shadowBlur = blur; this.shadowStroke = shadowStroke; this.shadowFill = shadowFill; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setShadowOffset * @since 3.0.0 * * @param {number} [x=0] - [description] * @param {number} [y=0] - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setShadowOffset: function (x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = x; } this.shadowOffsetX = x; this.shadowOffsetY = y; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setShadowColor * @since 3.0.0 * * @param {string} [color='#000'] - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setShadowColor: function (color) { if (color === undefined) { color = '#000'; } this.shadowColor = color; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setShadowBlur * @since 3.0.0 * * @param {number} [blur=0] - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setShadowBlur: function (blur) { if (blur === undefined) { blur = 0; } this.shadowBlur = blur; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setShadowStroke * @since 3.0.0 * * @param {boolean} enabled - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setShadowStroke: function (enabled) { this.shadowStroke = enabled; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setShadowFill * @since 3.0.0 * * @param {boolean} enabled - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setShadowFill: function (enabled) { this.shadowFill = enabled; return this.update(false); }, /** * Set the width (in pixels) to use for wrapping lines. Pass in null to remove wrapping by width. * * @method Phaser.GameObjects.Text.TextStyle#setWordWrapWidth * @since 3.0.0 * * @param {number} width - The maximum width of a line in pixels. Set to null to remove wrapping. * @param {boolean} [useAdvancedWrap=false] - Whether or not to use the advanced wrapping * algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false, * spaces and whitespace are left as is. * * @return {Phaser.GameObjects.Text} The parent Text object. */ setWordWrapWidth: function (width, useAdvancedWrap) { if (useAdvancedWrap === undefined) { useAdvancedWrap = false; } this.wordWrapWidth = width; this.wordWrapUseAdvanced = useAdvancedWrap; return this.update(false); }, /** * Set a custom callback for wrapping lines. Pass in null to remove wrapping by callback. * * @method Phaser.GameObjects.Text.TextStyle#setWordWrapCallback * @since 3.0.0 * * @param {TextStyleWordWrapCallback} callback - A custom function that will be responsible for wrapping the * text. It will receive two arguments: text (the string to wrap), textObject (this Text * instance). It should return the wrapped lines either as an array of lines or as a string with * newline characters in place to indicate where breaks should happen. * @param {object} [scope=null] - The scope that will be applied when the callback is invoked. * * @return {Phaser.GameObjects.Text} The parent Text object. */ setWordWrapCallback: function (callback, scope) { if (scope === undefined) { scope = null; } this.wordWrapCallback = callback; this.wordWrapCallbackScope = scope; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setAlign * @since 3.0.0 * * @param {string} align - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setAlign: function (align) { if (align === undefined) { align = 'left'; } this.align = align; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#setMaxLines * @since 3.0.0 * * @param {integer} [max=0] - [description] * * @return {Phaser.GameObjects.Text} The parent Text object. */ setMaxLines: function (max) { if (max === undefined) { max = 0; } this.maxLines = max; return this.update(false); }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#getTextMetrics * @since 3.0.0 * * @return {object} [description] */ getTextMetrics: function () { var metrics = this.metrics; return { ascent: metrics.ascent, descent: metrics.descent, fontSize: metrics.fontSize }; }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#toJSON * @since 3.0.0 * * @return {object} [description] */ toJSON: function () { var output = {}; for (var key in propertyMap) { output[key] = this[key]; } output.metrics = this.getTextMetrics(); return output; }, /** * [description] * * @method Phaser.GameObjects.Text.TextStyle#destroy * @since 3.0.0 */ destroy: function () { this.parent = undefined; } }); module.exports = TextStyle; /***/ }), /* 414 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObject = __webpack_require__(2); /** * Renders this Game Object with the Canvas Renderer to the given Camera. * The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera. * This method should not be called directly. It is a utility function of the Render module. * * @method Phaser.GameObjects.Text#renderCanvas * @since 3.0.0 * @private * * @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer. * @param {Phaser.GameObjects.Text} src - The Game Object being rendered in this call. * @param {number} interpolationPercentage - Reserved for future use and custom pipelines. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object. * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested */ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix) { if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)) || src.text === '') { return; } var ctx = renderer.currentContext; // var resolution = src.resolution; // Blend Mode if (renderer.currentBlendMode !== src.blendMode) { renderer.currentBlendMode = src.blendMode; ctx.globalCompositeOperation = renderer.blendModes[src.blendMode]; } // Alpha if (renderer.currentAlpha !== src.alpha) { renderer.currentAlpha = src.alpha; ctx.globalAlpha = src.alpha; } // Smoothing if (renderer.currentScaleMode !== src.scaleMode) { renderer.currentScaleMode = src.scaleMode; } var canvas = src.canvas; ctx.save(); if (parentMatrix !== undefined) { var matrix = parentMatrix.matrix; ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); } var tx = src.x - camera.scrollX * src.scrollFactorX; var ty = src.y - camera.scrollY * src.scrollFactorY; if (renderer.config.roundPixels) { tx |= 0; ty |= 0; } ctx.translate(tx, ty); ctx.rotate(src.rotation); ctx.scale(src.scaleX, src.scaleY); ctx.translate(canvas.width * (src.flipX ? 1 : 0), canvas.height * (src.flipY ? 1 : 0)); ctx.scale(src.flipX ? -1 : 1, src.flipY ? -1 : 1); ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, -src.displayOriginX, -src.displayOriginY, canvas.width, canvas.height); ctx.restore(); }; module.exports = TextCanvasRenderer; /***/ }), /* 415 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObject = __webpack_require__(2); /** * Renders this Game Object with the WebGL Renderer to the given Camera. * The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera. * This method should not be called directly. It is a utility function of the Render module. * * @method Phaser.GameObjects.Text#renderWebGL * @since 3.0.0 * @private * * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer. * @param {Phaser.GameObjects.Text} src - The Game Object being rendered in this call. * @param {number} interpolationPercentage - Reserved for future use and custom pipelines. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object. * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested */ var TextWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix) { if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)) || src.text === '') { return; } if (src.dirty) { src.canvasTexture = renderer.canvasToTexture(src.canvas, src.canvasTexture); src.dirty = false; } this.pipeline.batchText(this, camera, parentMatrix); }; module.exports = TextWebGLRenderer; /***/ }), /* 416 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var renderWebGL = __webpack_require__(3); var renderCanvas = __webpack_require__(3); if (true) { renderWebGL = __webpack_require__(415); } if (true) { renderCanvas = __webpack_require__(414); } module.exports = { renderWebGL: renderWebGL, renderCanvas: renderCanvas }; /***/ }), /* 417 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Returns an object containing dimensions of the Text object. * * @function Phaser.GameObjects.Text.GetTextSize * @since 3.0.0 * * @param {Phaser.GameObjects.Text} text - The Text object to get the size from. * @param {number} size - [description] * @param {array} lines - [description] * * @return {object} An object containing dimensions of the Text object. */ var GetTextSize = function (text, size, lines) { var canvas = text.canvas; var context = text.context; var style = text.style; var lineWidths = []; var maxLineWidth = 0; var drawnLines = lines.length; if (style.maxLines > 0 && style.maxLines < lines.length) { drawnLines = style.maxLines; } style.syncFont(canvas, context); // Text Width for (var i = 0; i < drawnLines; i++) { var lineWidth = style.strokeThickness; lineWidth += context.measureText(lines[i]).width; // Adjust for wrapped text if (style.wordWrap) { lineWidth -= context.measureText(' ').width; } lineWidths[i] = Math.ceil(lineWidth); maxLineWidth = Math.max(maxLineWidth, lineWidths[i]); } // Text Height var lineHeight = size.fontSize + style.strokeThickness; var height = lineHeight * drawnLines; var lineSpacing = text._lineSpacing || 0; if (lineSpacing < 0 && Math.abs(lineSpacing) > lineHeight) { lineSpacing = -lineHeight; } // Adjust for line spacing if (lineSpacing !== 0) { height += (lineSpacing > 0) ? lineSpacing * lines.length : lineSpacing * (lines.length - 1); } return { width: maxLineWidth, height: height, lines: drawnLines, lineWidths: lineWidths, lineSpacing: lineSpacing, lineHeight: lineHeight }; }; module.exports = GetTextSize; /***/ }), /* 418 */, /* 419 */, /* 420 */, /* 421 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Stepped easing. * * @function Phaser.Math.Easing.Stepped.Stepped * @since 3.0.0 * * @param {number} v - The value to be tweened. * @param {number} [steps=1] - The number of steps in the ease. * * @return {number} The tweened value. */ var Stepped = function (v, steps) { if (steps === undefined) { steps = 1; } if (v <= 0) { return 0; } else if (v >= 1) { return 1; } else { return (((steps * v) | 0) + 1) * (1 / steps); } }; module.exports = Stepped; /***/ }), /* 422 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Sinusoidal ease-in/out. * * @function Phaser.Math.Easing.Sine.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var InOut = function (v) { if (v === 0) { return 0; } else if (v === 1) { return 1; } else { return 0.5 * (1 - Math.cos(Math.PI * v)); } }; module.exports = InOut; /***/ }), /* 423 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Sinusoidal ease-out. * * @function Phaser.Math.Easing.Sine.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Out = function (v) { if (v === 0) { return 0; } else if (v === 1) { return 1; } else { return Math.sin(v * Math.PI / 2); } }; module.exports = Out; /***/ }), /* 424 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Sinusoidal ease-in. * * @function Phaser.Math.Easing.Sine.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var In = function (v) { if (v === 0) { return 0; } else if (v === 1) { return 1; } else { return 1 - Math.cos(v * Math.PI / 2); } }; module.exports = In; /***/ }), /* 425 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quintic ease-in/out. * * @function Phaser.Math.Easing.Quintic.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var InOut = function (v) { if ((v *= 2) < 1) { return 0.5 * v * v * v * v * v; } else { return 0.5 * ((v -= 2) * v * v * v * v + 2); } }; module.exports = InOut; /***/ }), /* 426 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quintic ease-out. * * @function Phaser.Math.Easing.Quintic.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Out = function (v) { return --v * v * v * v * v + 1; }; module.exports = Out; /***/ }), /* 427 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quintic ease-in. * * @function Phaser.Math.Easing.Quintic.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var In = function (v) { return v * v * v * v * v; }; module.exports = In; /***/ }), /* 428 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quartic ease-in/out. * * @function Phaser.Math.Easing.Quartic.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var InOut = function (v) { if ((v *= 2) < 1) { return 0.5 * v * v * v * v; } else { return -0.5 * ((v -= 2) * v * v * v - 2); } }; module.exports = InOut; /***/ }), /* 429 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quartic ease-out. * * @function Phaser.Math.Easing.Quartic.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Out = function (v) { return 1 - (--v * v * v * v); }; module.exports = Out; /***/ }), /* 430 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quartic ease-in. * * @function Phaser.Math.Easing.Quartic.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var In = function (v) { return v * v * v * v; }; module.exports = In; /***/ }), /* 431 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quadratic ease-in/out. * * @function Phaser.Math.Easing.Quadratic.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var InOut = function (v) { if ((v *= 2) < 1) { return 0.5 * v * v; } else { return -0.5 * (--v * (v - 2) - 1); } }; module.exports = InOut; /***/ }), /* 432 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quadratic ease-out. * * @function Phaser.Math.Easing.Quadratic.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Out = function (v) { return v * (2 - v); }; module.exports = Out; /***/ }), /* 433 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Quadratic ease-in. * * @function Phaser.Math.Easing.Quadratic.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var In = function (v) { return v * v; }; module.exports = In; /***/ }), /* 434 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Linear easing (no variation). * * @function Phaser.Math.Easing.Linear.Linear * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Linear = function (v) { return v; }; module.exports = Linear; /***/ }), /* 435 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Exponential ease-in/out. * * @function Phaser.Math.Easing.Expo.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var InOut = function (v) { if ((v *= 2) < 1) { return 0.5 * Math.pow(2, 10 * (v - 1)); } else { return 0.5 * (2 - Math.pow(2, -10 * (v - 1))); } }; module.exports = InOut; /***/ }), /* 436 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Exponential ease-out. * * @function Phaser.Math.Easing.Expo.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Out = function (v) { return 1 - Math.pow(2, -10 * v); }; module.exports = Out; /***/ }), /* 437 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Exponential ease-in. * * @function Phaser.Math.Easing.Expo.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var In = function (v) { return Math.pow(2, 10 * (v - 1)) - 0.001; }; module.exports = In; /***/ }), /* 438 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Elastic ease-in/out. * * @function Phaser.Math.Easing.Elastic.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * @param {float} [amplitude=0.1] - The amplitude of the elastic ease. * @param {float} [period=0.1] - [description] * * @return {number} The tweened value. */ var InOut = function (v, amplitude, period) { if (amplitude === undefined) { amplitude = 0.1; } if (period === undefined) { period = 0.1; } if (v === 0) { return 0; } else if (v === 1) { return 1; } else { var s = period / 4; if (amplitude < 1) { amplitude = 1; } else { s = period * Math.asin(1 / amplitude) / (2 * Math.PI); } if ((v *= 2) < 1) { return -0.5 * (amplitude * Math.pow(2, 10 * (v -= 1)) * Math.sin((v - s) * (2 * Math.PI) / period)); } else { return amplitude * Math.pow(2, -10 * (v -= 1)) * Math.sin((v - s) * (2 * Math.PI) / period) * 0.5 + 1; } } }; module.exports = InOut; /***/ }), /* 439 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Elastic ease-out. * * @function Phaser.Math.Easing.Elastic.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * @param {float} [amplitude=0.1] - The amplitude of the elastic ease. * @param {float} [period=0.1] - [description] * * @return {number} The tweened value. */ var Out = function (v, amplitude, period) { if (amplitude === undefined) { amplitude = 0.1; } if (period === undefined) { period = 0.1; } if (v === 0) { return 0; } else if (v === 1) { return 1; } else { var s = period / 4; if (amplitude < 1) { amplitude = 1; } else { s = period * Math.asin(1 / amplitude) / (2 * Math.PI); } return (amplitude * Math.pow(2, -10 * v) * Math.sin((v - s) * (2 * Math.PI) / period) + 1); } }; module.exports = Out; /***/ }), /* 440 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Elastic ease-in. * * @function Phaser.Math.Easing.Elastic.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * @param {float} [amplitude=0.1] - The amplitude of the elastic ease. * @param {float} [period=0.1] - [description] * * @return {number} The tweened value. */ var In = function (v, amplitude, period) { if (amplitude === undefined) { amplitude = 0.1; } if (period === undefined) { period = 0.1; } if (v === 0) { return 0; } else if (v === 1) { return 1; } else { var s = period / 4; if (amplitude < 1) { amplitude = 1; } else { s = period * Math.asin(1 / amplitude) / (2 * Math.PI); } return -(amplitude * Math.pow(2, 10 * (v -= 1)) * Math.sin((v - s) * (2 * Math.PI) / period)); } }; module.exports = In; /***/ }), /* 441 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Cubic ease-in/out. * * @function Phaser.Math.Easing.Cubic.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var InOut = function (v) { if ((v *= 2) < 1) { return 0.5 * v * v * v; } else { return 0.5 * ((v -= 2) * v * v + 2); } }; module.exports = InOut; /***/ }), /* 442 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Cubic ease-out. * * @function Phaser.Math.Easing.Cubic.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Out = function (v) { return --v * v * v + 1; }; module.exports = Out; /***/ }), /* 443 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Cubic ease-in. * * @function Phaser.Math.Easing.Cubic.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var In = function (v) { return v * v * v; }; module.exports = In; /***/ }), /* 444 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Circular ease-in/out. * * @function Phaser.Math.Easing.Circular.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var InOut = function (v) { if ((v *= 2) < 1) { return -0.5 * (Math.sqrt(1 - v * v) - 1); } else { return 0.5 * (Math.sqrt(1 - (v -= 2) * v) + 1); } }; module.exports = InOut; /***/ }), /* 445 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Circular ease-out. * * @function Phaser.Math.Easing.Circular.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Out = function (v) { return Math.sqrt(1 - (--v * v)); }; module.exports = Out; /***/ }), /* 446 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Circular ease-in. * * @function Phaser.Math.Easing.Circular.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var In = function (v) { return 1 - Math.sqrt(1 - v * v); }; module.exports = In; /***/ }), /* 447 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Bounce ease-in/out. * * @function Phaser.Math.Easing.Bounce.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var InOut = function (v) { var reverse = false; if (v < 0.5) { v = 1 - (v * 2); reverse = true; } else { v = (v * 2) - 1; } if (v < 1 / 2.75) { v = 7.5625 * v * v; } else if (v < 2 / 2.75) { v = 7.5625 * (v -= 1.5 / 2.75) * v + 0.75; } else if (v < 2.5 / 2.75) { v = 7.5625 * (v -= 2.25 / 2.75) * v + 0.9375; } else { v = 7.5625 * (v -= 2.625 / 2.75) * v + 0.984375; } if (reverse) { return (1 - v) * 0.5; } else { return v * 0.5 + 0.5; } }; module.exports = InOut; /***/ }), /* 448 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Bounce ease-out. * * @function Phaser.Math.Easing.Bounce.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var Out = function (v) { if (v < 1 / 2.75) { return 7.5625 * v * v; } else if (v < 2 / 2.75) { return 7.5625 * (v -= 1.5 / 2.75) * v + 0.75; } else if (v < 2.5 / 2.75) { return 7.5625 * (v -= 2.25 / 2.75) * v + 0.9375; } else { return 7.5625 * (v -= 2.625 / 2.75) * v + 0.984375; } }; module.exports = Out; /***/ }), /* 449 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Bounce ease-in. * * @function Phaser.Math.Easing.Bounce.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * * @return {number} The tweened value. */ var In = function (v) { v = 1 - v; if (v < 1 / 2.75) { return 1 - (7.5625 * v * v); } else if (v < 2 / 2.75) { return 1 - (7.5625 * (v -= 1.5 / 2.75) * v + 0.75); } else if (v < 2.5 / 2.75) { return 1 - (7.5625 * (v -= 2.25 / 2.75) * v + 0.9375); } else { return 1 - (7.5625 * (v -= 2.625 / 2.75) * v + 0.984375); } }; module.exports = In; /***/ }), /* 450 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Back ease-in/out. * * @function Phaser.Math.Easing.Back.InOut * @since 3.0.0 * * @param {number} v - The value to be tweened. * @param {number} [overshoot=1.70158] - The overshoot amount. * * @return {number} The tweened value. */ var InOut = function (v, overshoot) { if (overshoot === undefined) { overshoot = 1.70158; } var s = overshoot * 1.525; if ((v *= 2) < 1) { return 0.5 * (v * v * ((s + 1) * v - s)); } else { return 0.5 * ((v -= 2) * v * ((s + 1) * v + s) + 2); } }; module.exports = InOut; /***/ }), /* 451 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Back ease-out. * * @function Phaser.Math.Easing.Back.Out * @since 3.0.0 * * @param {number} v - The value to be tweened. * @param {number} [overshoot=1.70158] - The overshoot amount. * * @return {number} The tweened value. */ var Out = function (v, overshoot) { if (overshoot === undefined) { overshoot = 1.70158; } return --v * v * ((overshoot + 1) * v + overshoot) + 1; }; module.exports = Out; /***/ }), /* 452 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Back ease-in. * * @function Phaser.Math.Easing.Back.In * @since 3.0.0 * * @param {number} v - The value to be tweened. * @param {number} [overshoot=1.70158] - The overshoot amount. * * @return {number} The tweened value. */ var In = function (v, overshoot) { if (overshoot === undefined) { overshoot = 1.70158; } return v * v * ((overshoot + 1) * v - overshoot); }; module.exports = In; /***/ }), /* 453 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Back = __webpack_require__(247); var Bounce = __webpack_require__(246); var Circular = __webpack_require__(245); var Cubic = __webpack_require__(244); var Elastic = __webpack_require__(243); var Expo = __webpack_require__(242); var Linear = __webpack_require__(241); var Quadratic = __webpack_require__(240); var Quartic = __webpack_require__(239); var Quintic = __webpack_require__(238); var Sine = __webpack_require__(237); var Stepped = __webpack_require__(236); // EaseMap module.exports = { Power0: Linear, Power1: Quadratic.Out, Power2: Cubic.Out, Power3: Quartic.Out, Power4: Quintic.Out, Linear: Linear, Quad: Quadratic.Out, Cubic: Cubic.Out, Quart: Quartic.Out, Quint: Quintic.Out, Sine: Sine.Out, Expo: Expo.Out, Circ: Circular.Out, Elastic: Elastic.Out, Back: Back.Out, Bounce: Bounce.Out, Stepped: Stepped, 'Quad.easeIn': Quadratic.In, 'Cubic.easeIn': Cubic.In, 'Quart.easeIn': Quartic.In, 'Quint.easeIn': Quintic.In, 'Sine.easeIn': Sine.In, 'Expo.easeIn': Expo.In, 'Circ.easeIn': Circular.In, 'Elastic.easeIn': Elastic.In, 'Back.easeIn': Back.In, 'Bounce.easeIn': Bounce.In, 'Quad.easeOut': Quadratic.Out, 'Cubic.easeOut': Cubic.Out, 'Quart.easeOut': Quartic.Out, 'Quint.easeOut': Quintic.Out, 'Sine.easeOut': Sine.Out, 'Expo.easeOut': Expo.Out, 'Circ.easeOut': Circular.Out, 'Elastic.easeOut': Elastic.Out, 'Back.easeOut': Back.Out, 'Bounce.easeOut': Bounce.Out, 'Quad.easeInOut': Quadratic.InOut, 'Cubic.easeInOut': Cubic.InOut, 'Quart.easeInOut': Quartic.InOut, 'Quint.easeInOut': Quintic.InOut, 'Sine.easeInOut': Sine.InOut, 'Expo.easeInOut': Expo.InOut, 'Circ.easeInOut': Circular.InOut, 'Elastic.easeInOut': Elastic.InOut, 'Back.easeInOut': Back.InOut, 'Bounce.easeInOut': Bounce.InOut }; /***/ }), /* 454 */, /* 455 */, /* 456 */, /* 457 */, /* 458 */, /* 459 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObject = __webpack_require__(2); /** * Renders this Game Object with the Canvas Renderer to the given Camera. * The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera. * This method should not be called directly. It is a utility function of the Render module. * * @method Phaser.GameObjects.Image#renderCanvas * @since 3.0.0 * @private * * @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer. * @param {Phaser.GameObjects.Image} src - The Game Object being rendered in this call. * @param {number} interpolationPercentage - Reserved for future use and custom pipelines. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object. * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested */ var ImageCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix) { if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id))) { return; } renderer.drawImage(src, camera, parentMatrix); }; module.exports = ImageCanvasRenderer; /***/ }), /* 460 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObject = __webpack_require__(2); /** * Renders this Game Object with the WebGL Renderer to the given Camera. * The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera. * This method should not be called directly. It is a utility function of the Render module. * * @method Phaser.GameObjects.Image#renderWebGL * @since 3.0.0 * @private * * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer. * @param {Phaser.GameObjects.Image} src - The Game Object being rendered in this call. * @param {number} interpolationPercentage - Reserved for future use and custom pipelines. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object. * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested */ var ImageWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix) { if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id))) { return; } this.pipeline.batchSprite(src, camera, parentMatrix); }; module.exports = ImageWebGLRenderer; /***/ }), /* 461 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var renderWebGL = __webpack_require__(3); var renderCanvas = __webpack_require__(3); if (true) { renderWebGL = __webpack_require__(460); } if (true) { renderCanvas = __webpack_require__(459); } module.exports = { renderWebGL: renderWebGL, renderCanvas: renderCanvas }; /***/ }), /* 462 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObject = __webpack_require__(2); /** * Renders this Game Object with the WebGL Renderer to the given Camera. * The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera. * This method should not be called directly. It is a utility function of the Render module. * * @method Phaser.GameObjects.Graphics#renderWebGL * @since 3.0.0 * @private * * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer. * @param {Phaser.GameObjects.Graphics} graphics - The Game Object being rendered in this call. * @param {number} interpolationPercentage - Reserved for future use and custom pipelines. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object. * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested */ var GraphicsWebGLRenderer = function (renderer, graphics, interpolationPercentage, camera, parentMatrix) { if (GameObject.RENDER_MASK !== graphics.renderFlags || (graphics.cameraFilter > 0 && (graphics.cameraFilter & camera._id))) { return; } this.pipeline.batchGraphics(this, camera, parentMatrix); }; module.exports = GraphicsWebGLRenderer; /***/ }), /* 463 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var renderWebGL = __webpack_require__(3); var renderCanvas = __webpack_require__(3); if (true) { renderWebGL = __webpack_require__(462); // Needed for Graphics.generateTexture renderCanvas = __webpack_require__(176); } if (true) { renderCanvas = __webpack_require__(176); } module.exports = { renderWebGL: renderWebGL, renderCanvas: renderCanvas }; /***/ }), /* 464 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Offsets the Ellipse by the values given in the `x` and `y` properties of the Point object. * * @function Phaser.Geom.Ellipse.OffsetPoint * @since 3.0.0 * * @generic {Phaser.Geom.Ellipse} O - [ellipse,$return] * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to be offset (translated.) * @param {(Phaser.Geom.Point|object)} point - The Point object containing the values to offset the Ellipse by. * * @return {Phaser.Geom.Ellipse} The Ellipse that was offset. */ var OffsetPoint = function (ellipse, point) { ellipse.x += point.x; ellipse.y += point.y; return ellipse; }; module.exports = OffsetPoint; /***/ }), /* 465 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Offsets the Ellipse by the values given. * * @function Phaser.Geom.Ellipse.Offset * @since 3.0.0 * * @generic {Phaser.Geom.Ellipse} O - [ellipse,$return] * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to be offset (translated.) * @param {number} x - The amount to horizontally offset the Ellipse by. * @param {number} y - The amount to vertically offset the Ellipse by. * * @return {Phaser.Geom.Ellipse} The Ellipse that was offset. */ var Offset = function (ellipse, x, y) { ellipse.x += x; ellipse.y += y; return ellipse; }; module.exports = Offset; /***/ }), /* 466 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Rectangle = __webpack_require__(14); /** * Returns the bounds of the Ellipse object. * * @function Phaser.Geom.Ellipse.GetBounds * @since 3.0.0 * * @generic {Phaser.Geom.Rectangle} O - [out,$return] * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to get the bounds from. * @param {(Phaser.Geom.Rectangle|object)} [out] - A Rectangle, or rectangle-like object, to store the ellipse bounds in. If not given a new Rectangle will be created. * * @return {(Phaser.Geom.Rectangle|object)} The Rectangle object containing the Ellipse bounds. */ var GetBounds = function (ellipse, out) { if (out === undefined) { out = new Rectangle(); } out.x = ellipse.left; out.y = ellipse.top; out.width = ellipse.width; out.height = ellipse.height; return out; }; module.exports = GetBounds; /***/ }), /* 467 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Compares the `x`, `y`, `width` and `height` properties of the two given Ellipses. * Returns `true` if they all match, otherwise returns `false`. * * @function Phaser.Geom.Ellipse.Equals * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} ellipse - The first Ellipse to compare. * @param {Phaser.Geom.Ellipse} toCompare - The second Ellipse to compare. * * @return {boolean} `true` if the two Ellipse equal each other, otherwise `false`. */ var Equals = function (ellipse, toCompare) { return ( ellipse.x === toCompare.x && ellipse.y === toCompare.y && ellipse.width === toCompare.width && ellipse.height === toCompare.height ); }; module.exports = Equals; /***/ }), /* 468 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Copies the `x`, `y`, `width` and `height` properties from the `source` Ellipse * into the given `dest` Ellipse, then returns the `dest` Ellipse. * * @function Phaser.Geom.Ellipse.CopyFrom * @since 3.0.0 * * @generic {Phaser.Geom.Ellipse} O - [dest,$return] * * @param {Phaser.Geom.Ellipse} source - The source Ellipse to copy the values from. * @param {Phaser.Geom.Ellipse} dest - The destination Ellipse to copy the values to. * * @return {Phaser.Geom.Ellipse} The dest Ellipse. */ var CopyFrom = function (source, dest) { return dest.setTo(source.x, source.y, source.width, source.height); }; module.exports = CopyFrom; /***/ }), /* 469 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Contains = __webpack_require__(54); /** * Check to see if the Ellipse contains all four points of the given Rectangle object. * * @function Phaser.Geom.Ellipse.ContainsRect * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} ellipse - [description] * @param {(Phaser.Geom.Rectangle|object)} rect - The Rectangle object to check if it's within the Ellipse or not. * * @return {boolean} True if all of the Rectangle coordinates are within the ellipse, otherwise false. */ var ContainsRect = function (ellipse, rect) { return ( Contains(ellipse, rect.x, rect.y) && Contains(ellipse, rect.right, rect.y) && Contains(ellipse, rect.x, rect.bottom) && Contains(ellipse, rect.right, rect.bottom) ); }; module.exports = ContainsRect; /***/ }), /* 470 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Contains = __webpack_require__(54); /** * Check to see if the Ellipse contains the given Point object. * * @function Phaser.Geom.Ellipse.ContainsPoint * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to check. * @param {(Phaser.Geom.Point|object)} point - The Point object to check if it's within the Circle or not. * * @return {boolean} True if the Point coordinates are within the circle, otherwise false. */ var ContainsPoint = function (ellipse, point) { return Contains(ellipse, point.x, point.y); }; module.exports = ContainsPoint; /***/ }), /* 471 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Ellipse = __webpack_require__(114); /** * Creates a new Ellipse instance based on the values contained in the given source. * * @function Phaser.Geom.Ellipse.Clone * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} source - The Ellipse to be cloned. Can be an instance of an Ellipse or a ellipse-like object, with x, y, width and height properties. * * @return {Phaser.Geom.Ellipse} A clone of the source Ellipse. */ var Clone = function (source) { return new Ellipse(source.x, source.y, source.width, source.height); }; module.exports = Clone; /***/ }), /* 472 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Calculates the area of the Ellipse. * * @function Phaser.Geom.Ellipse.Area * @since 3.0.0 * * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to get the area of. * * @return {number} The area of the Ellipse. */ var Area = function (ellipse) { if (ellipse.isEmpty()) { return 0; } // units squared return (ellipse.getMajorRadius() * ellipse.getMinorRadius() * Math.PI); }; module.exports = Area; /***/ }), /* 473 */, /* 474 */, /* 475 */, /* 476 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var PluginCache = __webpack_require__(12); /** * @classdesc * The Update List plugin. * * Update Lists belong to a Scene and maintain the list Game Objects to be updated every frame. * * Some or all of these Game Objects may also be part of the Scene's [Display List]{@link Phaser.GameObjects.DisplayList}, for Rendering. * * @class UpdateList * @memberOf Phaser.GameObjects * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene that the Update List belongs to. */ var UpdateList = new Class({ initialize: function UpdateList (scene) { /** * The Scene that the Update List belongs to. * * @name Phaser.GameObjects.UpdateList#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * The Scene's Systems. * * @name Phaser.GameObjects.UpdateList#systems * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.systems = scene.sys; /** * The list of Game Objects. * * @name Phaser.GameObjects.UpdateList#_list * @type {array} * @private * @default [] * @since 3.0.0 */ this._list = []; /** * Game Objects that are pending insertion into the list. * * @name Phaser.GameObjects.UpdateList#_pendingInsertion * @type {array} * @private * @default [] * @since 3.0.0 */ this._pendingInsertion = []; /** * Game Objects that are pending removal from the list. * * @name Phaser.GameObjects.UpdateList#_pendingRemoval * @type {array} * @private * @default [] * @since 3.0.0 */ this._pendingRemoval = []; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('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.UpdateList#boot * @private * @since 3.5.1 */ boot: function () { this.systems.events.once('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.UpdateList#start * @private * @since 3.5.0 */ start: function () { var eventEmitter = this.systems.events; eventEmitter.on('preupdate', this.preUpdate, this); eventEmitter.on('update', this.update, this); eventEmitter.once('shutdown', this.shutdown, this); }, /** * Add a Game Object to the Update List. * * @method Phaser.GameObjects.UpdateList#add * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} child - The Game Object to add. * * @return {Phaser.GameObjects.GameObject} The added Game Object. */ add: function (child) { // Is child already in this list? if (this._list.indexOf(child) === -1 && this._pendingInsertion.indexOf(child) === -1) { this._pendingInsertion.push(child); } return child; }, /** * The pre-update step. * * Handles Game Objects that are pending insertion to and removal from the list. * * @method Phaser.GameObjects.UpdateList#preUpdate * @since 3.0.0 */ preUpdate: function () { var toRemove = this._pendingRemoval.length; var toInsert = this._pendingInsertion.length; if (toRemove === 0 && toInsert === 0) { // Quick bail return; } var i; var gameObject; // Delete old gameObjects for (i = 0; i < toRemove; i++) { gameObject = this._pendingRemoval[i]; var index = this._list.indexOf(gameObject); if (index > -1) { this._list.splice(index, 1); } } // Move pending to active this._list = this._list.concat(this._pendingInsertion.splice(0)); // Clear the lists this._pendingRemoval.length = 0; this._pendingInsertion.length = 0; }, /** * The update step. * * Pre-updates every active Game Object in the list. * * @method Phaser.GameObjects.UpdateList#update * @since 3.0.0 * * @param {number} time - The current timestamp. * @param {number} delta - The delta time elapsed since the last frame. */ update: function (time, delta) { for (var i = 0; i < this._list.length; i++) { var gameObject = this._list[i]; if (gameObject.active) { gameObject.preUpdate.call(gameObject, time, delta); } } }, /** * Remove a Game Object from the list. * * @method Phaser.GameObjects.UpdateList#remove * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} child - The Game Object to remove from the list. * * @return {Phaser.GameObjects.GameObject} The removed Game Object. */ remove: function (child) { var index = this._list.indexOf(child); if (index !== -1) { this._list.splice(index, 1); } return child; }, /** * Remove all Game Objects from the list. * * @method Phaser.GameObjects.UpdateList#removeAll * @since 3.0.0 * * @return {Phaser.GameObjects.UpdateList} This UpdateList. */ removeAll: function () { var i = this._list.length; while (i--) { this.remove(this._list[i]); } return this; }, /** * 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.UpdateList#shutdown * @since 3.0.0 */ shutdown: function () { this.removeAll(); this._list.length = 0; this._pendingRemoval.length = 0; this._pendingInsertion.length = 0; var eventEmitter = this.systems.events; eventEmitter.off('preupdate', this.preUpdate, this); eventEmitter.off('update', this.update, this); eventEmitter.off('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.UpdateList#destroy * @since 3.0.0 */ destroy: function () { this.shutdown(); this.scene.sys.events.off('start', this.start, this); this.scene = null; this.systems = null; }, /** * The length of the list. * * @name Phaser.GameObjects.UpdateList#length * @type {integer} * @readOnly * @since 3.10.0 */ length: { get: function () { return this._list.length; } } }); PluginCache.register('UpdateList', UpdateList, 'updateList'); module.exports = UpdateList; /***/ }), /* 477 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Swaps the position of two elements in the given array. * The elements must exist in the same array. * The array is modified in-place. * * @function Phaser.Utils.Array.Swap * @since 3.4.0 * * @param {array} array - The input array. * @param {*} item1 - The first element to swap. * @param {*} item2 - The second element to swap. * * @return {array} The input array. */ var Swap = function (array, item1, item2) { if (item1 === item2) { return; } var index1 = array.indexOf(item1); var index2 = array.indexOf(item2); if (index1 < 0 || index2 < 0) { throw new Error('Supplied items must be elements of the same array'); } array[index1] = item2; array[index2] = item1; return array; }; module.exports = Swap; /***/ }), /* 478 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SafeRange = __webpack_require__(29); /** * Scans the array for elements with the given property. If found, the property is set to the `value`. * * For example: `SetAll('visible', true)` would set all elements that have a `visible` property to `false`. * * Optionally you can specify a start and end index. For example if the array had 100 elements, * and you set `startIndex` to 0 and `endIndex` to 50, it would update only the first 50 elements. * * @function Phaser.Utils.Array.SetAll * @since 3.4.0 * * @param {array} array - The array to search. * @param {string} property - The property to test for on each array element. * @param {*} value - The value to set the property to. * @param {integer} [startIndex] - An optional start index to search from. * @param {integer} [endIndex] - An optional end index to search to. * * @return {array} The input array. */ var SetAll = function (array, property, value, startIndex, endIndex) { if (startIndex === undefined) { startIndex = 0; } if (endIndex === undefined) { endIndex = array.length; } if (SafeRange(array, startIndex, endIndex)) { for (var i = startIndex; i < endIndex; i++) { var entry = array[i]; if (entry.hasOwnProperty(property)) { entry[property] = value; } } } return array; }; module.exports = SetAll; /***/ }), /* 479 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Moves the given element to the bottom of the array. * The array is modified in-place. * * @function Phaser.Utils.Array.SendToBack * @since 3.4.0 * * @param {array} array - The array. * @param {*} item - The element to move. * * @return {*} The element that was moved. */ var SendToBack = function (array, item) { var currentIndex = array.indexOf(item); if (currentIndex !== -1 && currentIndex > 0) { array.splice(currentIndex, 1); array.unshift(item); } return item; }; module.exports = SendToBack; /***/ }), /* 480 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Replaces an element of the array with the new element. * The new element cannot already be a member of the array. * The array is modified in-place. * * @function Phaser.Utils.Array.Replace * @since 3.4.0 * * @param {*} oldChild - The element in the array that will be replaced. * @param {*} newChild - The element to be inserted into the array at the position of `oldChild`. * * @return {boolean} Returns true if the oldChild was successfully replaced, otherwise returns false. */ var Replace = function (array, oldChild, newChild) { var index1 = array.indexOf(oldChild); var index2 = array.indexOf(newChild); if (index1 !== -1 && index2 === -1) { array[index1] = newChild; return true; } else { return false; } }; module.exports = Replace; /***/ }), /* 481 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SpliceOne = __webpack_require__(56); /** * Removes a random object from the given array and returns it. * Will return null if there are no array items that fall within the specified range or if there is no item for the randomly chosen index. * * @function Phaser.Utils.Array.RemoveRandomElement * @since 3.0.0 * * @param {array} array - The array to removed a random element from. * @param {integer} [start=0] - The array index to start the search from. * @param {integer} [length=array.length] - Optional restriction on the number of elements to randomly select from. * * @return {object} The random element that was removed, or `null` if there were no array elements that fell within the given range. */ var RemoveRandomElement = function (array, start, length) { if (start === undefined) { start = 0; } if (length === undefined) { length = array.length; } var randomIndex = start + Math.floor(Math.random() * length); return SpliceOne(array, randomIndex); }; module.exports = RemoveRandomElement; /***/ }), /* 482 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SafeRange = __webpack_require__(29); /** * Removes the item within the given range in the array. * * The array is modified in-place. * * You can optionally specify a callback to be invoked for the item/s successfully removed from the array. * * @function Phaser.Utils.Array.RemoveBetween * @since 3.4.0 * * @param {array} array - The array to be modified. * @param {integer} startIndex - The start index to remove from. * @param {integer} endIndex - The end index to remove to. * @param {function} [callback] - A callback to be invoked for the item removed from the array. * @param {object} [context] - The context in which the callback is invoked. * * @return {Array.<*>} An array of items that were removed. */ var RemoveBetween = function (array, startIndex, endIndex, callback, context) { if (startIndex === undefined) { startIndex = 0; } if (endIndex === undefined) { endIndex = array.length; } if (context === undefined) { context = array; } if (SafeRange(array, startIndex, endIndex)) { var size = endIndex - startIndex; var removed = array.splice(startIndex, size); if (callback) { for (var i = 0; i < removed.length; i++) { var entry = removed[i]; callback.call(context, entry); } } return removed; } else { return []; } }; module.exports = RemoveBetween; /***/ }), /* 483 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SpliceOne = __webpack_require__(56); /** * Removes the item from the given position in the array. * * The array is modified in-place. * * You can optionally specify a callback to be invoked for the item if it is successfully removed from the array. * * @function Phaser.Utils.Array.RemoveAt * @since 3.4.0 * * @param {array} array - The array to be modified. * @param {integer} index - The array index to remove the item from. The index must be in bounds or it will throw an error. * @param {function} [callback] - A callback to be invoked for the item removed from the array. * @param {object} [context] - The context in which the callback is invoked. * * @return {*} The item that was removed. */ var RemoveAt = function (array, index, callback, context) { if (context === undefined) { context = array; } if (index < 0 || index > array.length - 1) { throw new Error('Index out of bounds'); } var item = SpliceOne(array, index); if (callback) { callback.call(context, item); } return item; }; module.exports = RemoveAt; /***/ }), /* 484 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var RoundAwayFromZero = __webpack_require__(255); /** * Create an array of numbers (positive and/or negative) progressing from `start` * up to but not including `end` by advancing by `step`. * * If `start` is less than `end` a zero-length range is created unless a negative `step` is specified. * * Certain values for `start` and `end` (eg. NaN/undefined/null) are currently coerced to 0; * for forward compatibility make sure to pass in actual numbers. * * @example * NumberArrayStep(4); * // => [0, 1, 2, 3] * * NumberArrayStep(1, 5); * // => [1, 2, 3, 4] * * NumberArrayStep(0, 20, 5); * // => [0, 5, 10, 15] * * NumberArrayStep(0, -4, -1); * // => [0, -1, -2, -3] * * NumberArrayStep(1, 4, 0); * // => [1, 1, 1] * * NumberArrayStep(0); * // => [] * * @function Phaser.Utils.Array.NumberArrayStep * @since 3.0.0 * * @param {number} [start=0] - The start of the range. * @param {number} [end=null] - The end of the range. * @param {number} [step=1] - The value to increment or decrement by. * * @return {number[]} [description] */ var NumberArrayStep = function (start, end, step) { if (start === undefined) { start = 0; } if (end === undefined) { end = null; } if (step === undefined) { step = 1; } if (end === null) { end = start; start = 0; } var result = []; var total = Math.max(RoundAwayFromZero((end - start) / (step || 1)), 0); for (var i = 0; i < total; i++) { result.push(start); start += step; } return result; }; module.exports = NumberArrayStep; /***/ }), /* 485 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Create an array representing the range of numbers (usually integers), between, and inclusive of, * the given `start` and `end` arguments. For example: * * `var array = numberArray(2, 4); // array = [2, 3, 4]` * `var array = numberArray(0, 9); // array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]` * * This is equivalent to `numberArrayStep(start, end, 1)`. * * You can optionally provide a prefix and / or suffix string. If given the array will contain * strings, not integers. For example: * * `var array = numberArray(1, 4, 'Level '); // array = ["Level 1", "Level 2", "Level 3", "Level 4"]` * `var array = numberArray(5, 7, 'HD-', '.png'); // array = ["HD-5.png", "HD-6.png", "HD-7.png"]` * * @function Phaser.Utils.Array.NumberArray * @since 3.0.0 * * @param {number} start - The minimum value the array starts with. * @param {number} end - The maximum value the array contains. * @param {string} [prefix] - Optional prefix to place before the number. If provided the array will contain strings, not integers. * @param {string} [suffix] - Optional suffix to place after the number. If provided the array will contain strings, not integers. * * @return {(number[]|string[])} The array of number values, or strings if a prefix or suffix was provided. */ var NumberArray = function (start, end, prefix, suffix) { var result = []; for (var i = start; i <= end; i++) { if (prefix || suffix) { var key = (prefix) ? prefix + i.toString() : i.toString(); if (suffix) { key = key.concat(suffix); } result.push(key); } else { result.push(i); } } return result; }; module.exports = NumberArray; /***/ }), /* 486 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Moves the given array element up one place in the array. * The array is modified in-place. * * @function Phaser.Utils.Array.MoveUp * @since 3.4.0 * * @param {array} array - The input array. * @param {*} item - The element to move up the array. * * @return {array} The input array. */ var MoveUp = function (array, item) { var currentIndex = array.indexOf(item); if (currentIndex !== -1 && currentIndex < array.length - 2) { var item2 = array[currentIndex + 1]; var index2 = array.indexOf(item2); array[currentIndex] = item2; array[index2] = item; } return array; }; module.exports = MoveUp; /***/ }), /* 487 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Moves an element in an array to a new position within the same array. * The array is modified in-place. * * @function Phaser.Utils.Array.MoveTo * @since 3.4.0 * * @param {array} array - The array. * @param {*} item - The element to move. * @param {integer} index - The new index that the element will be moved to. * * @return {*} The element that was moved. */ var MoveTo = function (array, item, index) { var currentIndex = array.indexOf(item); if (currentIndex === -1 || index < 0 || index >= array.length) { throw new Error('Supplied index out of bounds'); } if (currentIndex !== index) { // Remove array.splice(currentIndex, 1); // Add in new location array.splice(index, 0, item); } return item; }; module.exports = MoveTo; /***/ }), /* 488 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Moves the given array element down one place in the array. * The array is modified in-place. * * @function Phaser.Utils.Array.MoveDown * @since 3.4.0 * * @param {array} array - The input array. * @param {*} item - The element to move down the array. * * @return {array} The input array. */ var MoveDown = function (array, item) { var currentIndex = array.indexOf(item); if (currentIndex > 0) { var item2 = array[currentIndex - 1]; var index2 = array.indexOf(item2); array[currentIndex] = item2; array[index2] = item; } return array; }; module.exports = MoveDown; /***/ }), /* 489 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SafeRange = __webpack_require__(29); /** * Returns the first element in the array. * * You can optionally specify a matching criteria using the `property` and `value` arguments. * * For example: `getAll('visible', true)` would return the first element that had its `visible` property set. * * Optionally you can specify a start and end index. For example if the array had 100 elements, * and you set `startIndex` to 0 and `endIndex` to 50, it would search only the first 50 elements. * * @function Phaser.Utils.Array.GetFirst * @since 3.4.0 * * @param {array} array - The array to search. * @param {string} [property] - The property to test on each array element. * @param {*} [value] - The value to test the property against. Must pass a strict (`===`) comparison check. * @param {integer} [startIndex=0] - An optional start index to search from. * @param {integer} [endIndex=array.length] - An optional end index to search up to (but not included) * * @return {object} The first matching element from the array, or `null` if no element could be found in the range given. */ var GetFirst = function (array, property, value, startIndex, endIndex) { if (startIndex === undefined) { startIndex = 0; } if (endIndex === undefined) { endIndex = array.length; } if (SafeRange(array, startIndex, endIndex)) { for (var i = startIndex; i < endIndex; i++) { var child = array[i]; if (!property || (property && value === undefined && child.hasOwnProperty(property)) || (property && value !== undefined && child[property] === value)) { return child; } } } return null; }; module.exports = GetFirst; /***/ }), /* 490 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SafeRange = __webpack_require__(29); /** * Returns all elements in the array. * * You can optionally specify a matching criteria using the `property` and `value` arguments. * * For example: `getAll('visible', true)` would return only elements that have their visible property set. * * Optionally you can specify a start and end index. For example if the array had 100 elements, * and you set `startIndex` to 0 and `endIndex` to 50, it would return matches from only * the first 50 elements. * * @function Phaser.Utils.Array.GetAll * @since 3.4.0 * * @param {array} array - The array to search. * @param {string} [property] - The property to test on each array element. * @param {*} [value] - The value to test the property against. Must pass a strict (`===`) comparison check. * @param {integer} [startIndex] - An optional start index to search from. * @param {integer} [endIndex] - An optional end index to search to. * * @return {array} All matching elements from the array. */ var GetAll = function (array, property, value, startIndex, endIndex) { if (startIndex === undefined) { startIndex = 0; } if (endIndex === undefined) { endIndex = array.length; } var output = []; if (SafeRange(array, startIndex, endIndex)) { for (var i = startIndex; i < endIndex; i++) { var child = array[i]; if (!property || (property && value === undefined && child.hasOwnProperty(property)) || (property && value !== undefined && child[property] === value)) { output.push(child); } } } return output; }; module.exports = GetAll; /***/ }), /* 491 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SafeRange = __webpack_require__(29); /** * Passes each element in the array, between the start and end indexes, to the given callback. * * @function Phaser.Utils.Array.EachInRange * @since 3.4.0 * * @param {array} array - The array to search. * @param {function} callback - A callback to be invoked for each item in the array. * @param {object} context - The context in which the callback is invoked. * @param {integer} startIndex - The start index to search from. * @param {integer} endIndex - The end index to search to. * @param {...*} [args] - Additional arguments that will be passed to the callback, after the child. * * @return {array} The input array. */ var EachInRange = function (array, callback, context, startIndex, endIndex) { if (startIndex === undefined) { startIndex = 0; } if (endIndex === undefined) { endIndex = array.length; } if (SafeRange(array, startIndex, endIndex)) { var i; var args = [ null ]; for (i = 5; i < arguments.length; i++) { args.push(arguments[i]); } for (i = startIndex; i < endIndex; i++) { args[0] = array[i]; callback.apply(context, args); } } return array; }; module.exports = EachInRange; /***/ }), /* 492 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Passes each element in the array to the given callback. * * @function Phaser.Utils.Array.Each * @since 3.4.0 * * @param {array} array - The array to search. * @param {function} callback - A callback to be invoked for each item in the array. * @param {object} context - The context in which the callback is invoked. * @param {...*} [args] - Additional arguments that will be passed to the callback, after the child. * * @return {array} The input array. */ var Each = function (array, callback, context) { var i; var args = [ null ]; for (i = 2; i < arguments.length; i++) { args.push(arguments[i]); } for (i = 0; i < array.length; i++) { args[0] = array[i]; callback.apply(context, args); } return array; }; module.exports = Each; /***/ }), /* 493 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var SafeRange = __webpack_require__(29); /** * Returns the total number of elements in the array which have a property matching the given value. * * @function Phaser.Utils.Array.CountAllMatching * @since 3.4.0 * * @param {array} array - The array to search. * @param {string} property - The property to test on each array element. * @param {*} value - The value to test the property against. Must pass a strict (`===`) comparison check. * @param {integer} [startIndex] - An optional start index to search from. * @param {integer} [endIndex] - An optional end index to search to. * * @return {integer} The total number of elements with properties matching the given value. */ var CountAllMatching = function (array, property, value, startIndex, endIndex) { if (startIndex === undefined) { startIndex = 0; } if (endIndex === undefined) { endIndex = array.length; } var total = 0; if (SafeRange(array, startIndex, endIndex)) { for (var i = startIndex; i < endIndex; i++) { var child = array[i]; if (child[property] === value) { total++; } } } return total; }; module.exports = CountAllMatching; /***/ }), /* 494 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Moves the given element to the top of the array. * The array is modified in-place. * * @function Phaser.Utils.Array.BringToTop * @since 3.4.0 * * @param {array} array - The array. * @param {*} item - The element to move. * * @return {*} The element that was moved. */ var BringToTop = function (array, item) { var currentIndex = array.indexOf(item); if (currentIndex !== -1 && currentIndex < array.length) { array.splice(currentIndex, 1); array.push(item); } return item; }; module.exports = BringToTop; /***/ }), /* 495 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Adds the given item, or array of items, to the array starting at the index specified. * * Each item must be unique within the array. * * Existing elements in the array are shifted up. * * The array is modified in-place and returned. * * You can optionally specify a limit to the maximum size of the array. If the quantity of items being * added will take the array length over this limit, it will stop adding once the limit is reached. * * You can optionally specify a callback to be invoked for each item successfully added to the array. * * @function Phaser.Utils.Array.AddAt * @since 3.4.0 * * @param {array} array - The array to be added to. * @param {any|any[]} item - The item, or array of items, to add to the array. * @param {integer} [index=0] - The index in the array where the item will be inserted. * @param {integer} [limit] - Optional limit which caps the size of the array. * @param {function} [callback] - A callback to be invoked for each item successfully added to the array. * @param {object} [context] - The context in which the callback is invoked. * * @return {array} The input array. */ var AddAt = function (array, item, index, limit, callback, context) { if (index === undefined) { index = 0; } if (context === undefined) { context = array; } if (limit > 0) { var remaining = limit - array.length; // There's nothing more we can do here, the array is full if (remaining <= 0) { return null; } } // Fast path to avoid array mutation and iteration if (!Array.isArray(item)) { if (array.indexOf(item) === -1) { array.splice(index, 0, item); if (callback) { callback.call(context, item); } return item; } else { return null; } } // If we got this far, we have an array of items to insert // Ensure all the items are unique var itemLength = item.length - 1; while (itemLength >= 0) { if (array.indexOf(item[itemLength]) !== -1) { // Already exists in array, so remove it item.pop(); } itemLength--; } // Anything left? itemLength = item.length; if (itemLength === 0) { return null; } // Truncate to the limit if (limit > 0 && itemLength > remaining) { item.splice(remaining); itemLength = remaining; } for (var i = itemLength; i > 0; i--) { var entry = item[i]; array.splice(index, 0, entry); if (callback) { callback.call(context, entry); } } return item; }; module.exports = AddAt; /***/ }), /* 496 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Adds the given item, or array of items, to the array. * * Each item must be unique within the array. * * The array is modified in-place and returned. * * You can optionally specify a limit to the maximum size of the array. If the quantity of items being * added will take the array length over this limit, it will stop adding once the limit is reached. * * You can optionally specify a callback to be invoked for each item successfully added to the array. * * @function Phaser.Utils.Array.Add * @since 3.4.0 * * @param {array} array - The array to be added to. * @param {any|any[]} item - The item, or array of items, to add to the array. Each item must be unique within the array. * @param {integer} [limit] - Optional limit which caps the size of the array. * @param {function} [callback] - A callback to be invoked for each item successfully added to the array. * @param {object} [context] - The context in which the callback is invoked. * * @return {array} The input array. */ var Add = function (array, item, limit, callback, context) { if (context === undefined) { context = array; } if (limit > 0) { var remaining = limit - array.length; // There's nothing more we can do here, the array is full if (remaining <= 0) { return null; } } // Fast path to avoid array mutation and iteration if (!Array.isArray(item)) { if (array.indexOf(item) === -1) { array.push(item); if (callback) { callback.call(context, item); } return item; } else { return null; } } // If we got this far, we have an array of items to insert // Ensure all the items are unique var itemLength = item.length - 1; while (itemLength >= 0) { if (array.indexOf(item[itemLength]) !== -1) { // Already exists in array, so remove it item.pop(); } itemLength--; } // Anything left? itemLength = item.length; if (itemLength === 0) { return null; } if (limit > 0 && itemLength > remaining) { item.splice(remaining); itemLength = remaining; } for (var i = 0; i < itemLength; i++) { var entry = item[i]; array.push(entry); if (callback) { callback.call(context, entry); } } return item; }; module.exports = Add; /***/ }), /* 497 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var RotateMatrix = __webpack_require__(77); /** * [description] * * @function Phaser.Utils.Array.Matrix.RotateRight * @since 3.0.0 * * @param {array} matrix - [description] * * @return {array} [description] */ var RotateRight = function (matrix) { return RotateMatrix(matrix, -90); }; module.exports = RotateRight; /***/ }), /* 498 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var RotateMatrix = __webpack_require__(77); /** * [description] * * @function Phaser.Utils.Array.Matrix.RotateLeft * @since 3.0.0 * * @param {array} matrix - [description] * * @return {array} [description] */ var RotateLeft = function (matrix) { return RotateMatrix(matrix, 90); }; module.exports = RotateLeft; /***/ }), /* 499 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var RotateMatrix = __webpack_require__(77); /** * [description] * * @function Phaser.Utils.Array.Matrix.Rotate180 * @since 3.0.0 * * @param {array} matrix - [description] * * @return {array} [description] */ var Rotate180 = function (matrix) { return RotateMatrix(matrix, 180); }; module.exports = Rotate180; /***/ }), /* 500 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Utils.Array.Matrix.ReverseRows * @since 3.0.0 * * @param {array} matrix - [description] * * @return {array} [description] */ var ReverseRows = function (matrix) { return matrix.reverse(); }; module.exports = ReverseRows; /***/ }), /* 501 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * [description] * * @function Phaser.Utils.Array.Matrix.ReverseColumns * @since 3.0.0 * * @param {array} matrix - [description] * * @return {array} [description] */ var ReverseColumns = function (matrix) { for (var i = 0; i < matrix.length; i++) { matrix[i].reverse(); } return matrix; }; module.exports = ReverseColumns; /***/ }), /* 502 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Pad = __webpack_require__(133); var CheckMatrix = __webpack_require__(116); // Generates a string (which you can pass to console.log) from the given // Array Matrix. /** * [description] * * @function Phaser.Utils.Array.Matrix.MatrixToString * @since 3.0.0 * * @param {array} matrix - [description] * * @return {string} [description] */ var MatrixToString = function (matrix) { var str = ''; if (!CheckMatrix(matrix)) { return str; } for (var r = 0; r < matrix.length; r++) { for (var c = 0; c < matrix[r].length; c++) { var cell = matrix[r][c].toString(); if (cell !== 'undefined') { str += Pad(cell, 2); } else { str += '?'; } if (c < matrix[r].length - 1) { str += ' |'; } } if (r < matrix.length - 1) { str += '\n'; for (var i = 0; i < matrix[r].length; i++) { str += '---'; if (i < matrix[r].length - 1) { str += '+'; } } str += '\n'; } } return str; }; module.exports = MatrixToString; /***/ }), /* 503 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Utils.Array.Matrix */ module.exports = { CheckMatrix: __webpack_require__(116), MatrixToString: __webpack_require__(502), ReverseColumns: __webpack_require__(501), ReverseRows: __webpack_require__(500), Rotate180: __webpack_require__(499), RotateLeft: __webpack_require__(498), RotateMatrix: __webpack_require__(77), RotateRight: __webpack_require__(497), TransposeMatrix: __webpack_require__(181) }; /***/ }), /* 504 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var List = __webpack_require__(93); var PluginCache = __webpack_require__(12); var StableSort = __webpack_require__(83); /** * @classdesc * The Display List plugin. * * Display Lists belong to a Scene and maintain the list of Game Objects to render every frame. * * Some of these Game Objects may also be part of the Scene's [Update List]{@link Phaser.GameObjects.UpdateList}, for updating. * * @class DisplayList * @extends Phaser.Structs.List. * @memberOf Phaser.GameObjects * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene that this Display List belongs to. */ var DisplayList = new Class({ Extends: List, initialize: function DisplayList (scene) { List.call(this, scene); /** * The flag the determines whether Game Objects should be sorted when `depthSort()` is called. * * @name Phaser.GameObjects.DisplayList#sortChildrenFlag * @type {boolean} * @default false * @since 3.0.0 */ this.sortChildrenFlag = false; /** * The Scene that this Display List belongs to. * * @name Phaser.GameObjects.DisplayList#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * The Scene's Systems. * * @name Phaser.GameObjects.DisplayList#systems * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.systems = scene.sys; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('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.DisplayList#boot * @private * @since 3.5.1 */ boot: function () { this.systems.events.once('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.DisplayList#start * @private * @since 3.5.0 */ start: function () { this.systems.events.once('shutdown', this.shutdown, this); }, /** * Force a sort of the display list on the next call to depthSort. * * @method Phaser.GameObjects.DisplayList#queueDepthSort * @since 3.0.0 */ queueDepthSort: function () { this.sortChildrenFlag = true; }, /** * Immediately sorts the display list if the flag is set. * * @method Phaser.GameObjects.DisplayList#depthSort * @since 3.0.0 */ depthSort: function () { if (this.sortChildrenFlag) { StableSort.inplace(this.list, this.sortByDepth); this.sortChildrenFlag = false; } }, /** * Compare the depth of two Game Objects. * * @method Phaser.GameObjects.DisplayList#sortByDepth * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} childA - The first Game Object. * @param {Phaser.GameObjects.GameObject} childB - The second Game Object. * * @return {integer} The difference between the depths of each Game Object. */ sortByDepth: function (childA, childB) { return childA._depth - childB._depth; }, /** * Given an array of Game Objects, sort the array and return it, so that * the objects are in index order with the lowest at the bottom. * * @method Phaser.GameObjects.DisplayList#sortGameObjects * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject[]} gameObjects - The array of Game Objects to sort. * * @return {array} The sorted array of Game Objects. */ sortGameObjects: function (gameObjects) { if (gameObjects === undefined) { gameObjects = this.list; } this.scene.sys.depthSort(); return gameObjects.sort(this.sortIndexHandler.bind(this)); }, /** * Get the top-most Game Object in the given array of Game Objects, after sorting it. * * Note that the given array is sorted in place, even though it isn't returned directly it will still be updated. * * @method Phaser.GameObjects.DisplayList#getTopGameObject * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject[]} gameObjects - The array of Game Objects. * * @return {Phaser.GameObjects.GameObject} The top-most Game Object in the array of Game Objects. */ getTopGameObject: function (gameObjects) { this.sortGameObjects(gameObjects); return gameObjects[gameObjects.length - 1]; }, /** * 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.DisplayList#shutdown * @private * @since 3.0.0 */ shutdown: function () { this.removeAll(); this.systems.events.off('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.DisplayList#destroy * @private * @since 3.0.0 */ destroy: function () { this.shutdown(); this.scene.sys.events.off('start', this.start, this); this.scene = null; this.systems = null; } }); PluginCache.register('DisplayList', DisplayList, 'displayList'); module.exports = DisplayList; /***/ }), /* 505 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Visibility Handler hidden event. * * The document in which the Game is embedded has entered a hidden state. * * @event Phaser.Boot.VisibilityHandler#hidden */ /** * Visibility Handler visible event. * * The document in which the Game is embedded has entered a visible state. * * @event Phaser.Boot.VisibilityHandler#visible */ /** * Visibility Handler blur event. * * The window in which the Game is embedded has entered a blurred state. * * @event Phaser.Boot.VisibilityHandler#blur */ /** * Visibility Handler focus event. * * The window in which the Game is embedded has entered a focused state. * * @event Phaser.Boot.VisibilityHandler#focus */ /** * The Visibility Handler is responsible for listening out for document level visibility change events. * This includes `visibilitychange` if the browser supports it, and blur and focus events. It then uses * the provided Event Emitter and fires the related events. * * @function Phaser.Boot.VisibilityHandler * @fires Phaser.Boot.VisibilityHandler#hidden * @fires Phaser.Boot.VisibilityHandler#visible * @fires Phaser.Boot.VisibilityHandler#blur * @fires Phaser.Boot.VisibilityHandler#focus * @since 3.0.0 * * @param {Phaser.Game} game - The Game instance this Visibility Handler is working on. */ var VisibilityHandler = function (game) { var hiddenVar; var eventEmitter = game.events; if (document.hidden !== undefined) { hiddenVar = 'visibilitychange'; } else { var vendors = [ 'webkit', 'moz', 'ms' ]; vendors.forEach(function (prefix) { if (document[prefix + 'Hidden'] !== undefined) { document.hidden = function () { return document[prefix + 'Hidden']; }; hiddenVar = prefix + 'visibilitychange'; } }); } var onChange = function (event) { if (document.hidden || event.type === 'pause') { eventEmitter.emit('hidden'); } else { eventEmitter.emit('visible'); } }; if (hiddenVar) { document.addEventListener(hiddenVar, onChange, false); } window.onblur = function () { eventEmitter.emit('blur'); }; window.onfocus = function () { eventEmitter.emit('focus'); }; // Automatically give the window focus unless config says otherwise if (window.focus && game.config.autoFocus) { window.focus(); game.canvas.addEventListener('mousedown', function () { window.focus(); }, { passive: true }); } if (game.canvas) { game.canvas.onmouseout = function () { game.isOver = false; eventEmitter.emit('mouseout'); }; game.canvas.onmouseover = function () { game.isOver = true; eventEmitter.emit('mouseover'); }; } }; module.exports = VisibilityHandler; /***/ }), /* 506 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var GetValue = __webpack_require__(4); var NOOP = __webpack_require__(3); var RequestAnimationFrame = __webpack_require__(268); // Frame Rate config // fps: { // min: 10, // target: 60, // forceSetTimeOut: false, // deltaHistory: 10, // panicMax: 120 // } // http://www.testufo.com/#test=animation-time-graph /** * @callback TimeStepCallback * * @param {number} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout. * @param {number} average - The Delta Average. * @param {number} interpolation - Interpolation - how far between what is expected and where we are? */ /** * @classdesc * [description] * * @class TimeStep * @memberOf Phaser.Boot * @constructor * @since 3.0.0 * * @param {Phaser.Game} game - A reference to the Phaser.Game instance that owns this Time Step. * @param {FPSConfig} config */ var TimeStep = new Class({ initialize: function TimeStep (game, config) { /** * A reference to the Phaser.Game instance. * * @name Phaser.Boot.TimeStep#game * @type {Phaser.Game} * @readOnly * @since 3.0.0 */ this.game = game; /** * [description] * * @name Phaser.Boot.TimeStep#raf * @type {Phaser.DOM.RequestAnimationFrame} * @readOnly * @since 3.0.0 */ this.raf = new RequestAnimationFrame(); /** * A flag that is set once the TimeStep has started running and toggled when it stops. * * @name Phaser.Boot.TimeStep#started * @type {boolean} * @readOnly * @default false * @since 3.0.0 */ this.started = false; /** * A flag that is set once the TimeStep has started running and toggled when it stops. * The difference between this value and `started` is that `running` is toggled when * the TimeStep is sent to sleep, where-as `started` remains `true`, only changing if * the TimeStep is actually stopped, not just paused. * * @name Phaser.Boot.TimeStep#running * @type {boolean} * @readOnly * @default false * @since 3.0.0 */ this.running = false; /** * The minimum fps rate you want the Time Step to run at. * * @name Phaser.Boot.TimeStep#minFps * @type {integer} * @default 5 * @since 3.0.0 */ this.minFps = GetValue(config, 'min', 5); /** * The target fps rate for the Time Step to run at. * * Setting this value will not actually change the speed at which the browser runs, that is beyond * the control of Phaser. Instead, it allows you to determine performance issues and if the Time Step * is spiraling out of control. * * @name Phaser.Boot.TimeStep#targetFps * @type {integer} * @default 60 * @since 3.0.0 */ this.targetFps = GetValue(config, 'target', 60); /** * The minFps value in ms. * Defaults to 200ms between frames (i.e. super slow!) * * @name Phaser.Boot.TimeStep#_min * @type {number} * @private * @since 3.0.0 */ this._min = 1000 / this.minFps; /** * The targetFps value in ms. * Defaults to 16.66ms between frames (i.e. normal) * * @name Phaser.Boot.TimeStep#_target * @type {number} * @private * @since 3.0.0 */ this._target = 1000 / this.targetFps; /** * An exponential moving average of the frames per second. * * @name Phaser.Boot.TimeStep#actualFps * @type {integer} * @readOnly * @default 60 * @since 3.0.0 */ this.actualFps = this.targetFps; /** * [description] * * @name Phaser.Boot.TimeStep#nextFpsUpdate * @type {integer} * @readOnly * @default 0 * @since 3.0.0 */ this.nextFpsUpdate = 0; /** * The number of frames processed this second. * * @name Phaser.Boot.TimeStep#framesThisSecond * @type {integer} * @readOnly * @default 0 * @since 3.0.0 */ this.framesThisSecond = 0; /** * A callback to be invoked each time the Time Step steps. * * @name Phaser.Boot.TimeStep#callback * @type {TimeStepCallback} * @default NOOP * @since 3.0.0 */ this.callback = NOOP; /** * You can force the Time Step to use Set Timeout instead of Request Animation Frame by setting * the `forceSetTimeOut` property to `true` in the Game Configuration object. It cannot be changed at run-time. * * @name Phaser.Boot.TimeStep#forceSetTimeOut * @type {boolean} * @readOnly * @default false * @since 3.0.0 */ this.forceSetTimeOut = GetValue(config, 'forceSetTimeOut', false); /** * [description] * * @name Phaser.Boot.TimeStep#time * @type {integer} * @default 0 * @since 3.0.0 */ this.time = 0; /** * [description] * * @name Phaser.Boot.TimeStep#startTime * @type {integer} * @default 0 * @since 3.0.0 */ this.startTime = 0; /** * [description] * * @name Phaser.Boot.TimeStep#lastTime * @type {integer} * @default 0 * @since 3.0.0 */ this.lastTime = 0; /** * [description] * * @name Phaser.Boot.TimeStep#frame * @type {integer} * @readOnly * @default 0 * @since 3.0.0 */ this.frame = 0; /** * [description] * * @name Phaser.Boot.TimeStep#inFocus * @type {boolean} * @readOnly * @default true * @since 3.0.0 */ this.inFocus = true; /** * [description] * * @name Phaser.Boot.TimeStep#_pauseTime * @type {integer} * @private * @default 0 * @since 3.0.0 */ this._pauseTime = 0; /** * [description] * * @name Phaser.Boot.TimeStep#_coolDown * @type {integer} * @private * @default 0 * @since 3.0.0 */ this._coolDown = 0; /** * [description] * * @name Phaser.Boot.TimeStep#delta * @type {integer} * @default 0 * @since 3.0.0 */ this.delta = 0; /** * [description] * * @name Phaser.Boot.TimeStep#deltaIndex * @type {integer} * @default 0 * @since 3.0.0 */ this.deltaIndex = 0; /** * [description] * * @name Phaser.Boot.TimeStep#deltaHistory * @type {integer[]} * @since 3.0.0 */ this.deltaHistory = []; /** * [description] * * @name Phaser.Boot.TimeStep#deltaSmoothingMax * @type {integer} * @default 10 * @since 3.0.0 */ this.deltaSmoothingMax = GetValue(config, 'deltaHistory', 10); /** * [description] * * @name Phaser.Boot.TimeStep#panicMax * @type {integer} * @default 120 * @since 3.0.0 */ this.panicMax = GetValue(config, 'panicMax', 120); /** * The actual elapsed time in ms between one update and the next. * Unlike with `delta` no smoothing, capping, or averaging is applied to this value. * So please be careful when using this value in calculations. * * @name Phaser.Boot.TimeStep#rawDelta * @type {number} * @default 0 * @since 3.0.0 */ this.rawDelta = 0; }, /** * Called when the DOM window.onBlur event triggers. * * @method Phaser.Boot.TimeStep#blur * @since 3.0.0 */ blur: function () { this.inFocus = false; }, /** * Called when the DOM window.onFocus event triggers. * * @method Phaser.Boot.TimeStep#focus * @since 3.0.0 */ focus: function () { this.inFocus = true; this.resetDelta(); }, /** * Called when the visibility API says the game is 'hidden' (tab switch out of view, etc) * * @method Phaser.Boot.TimeStep#pause * @since 3.0.0 */ pause: function () { this._pauseTime = window.performance.now(); }, /** * Called when the visibility API says the game is 'visible' again (tab switch back into view, etc) * * @method Phaser.Boot.TimeStep#resume * @since 3.0.0 */ resume: function () { this.resetDelta(); this.startTime += this.time - this._pauseTime; }, /** * [description] * * @method Phaser.Boot.TimeStep#resetDelta * @since 3.0.0 */ resetDelta: function () { var now = window.performance.now(); this.time = now; this.lastTime = now; this.nextFpsUpdate = now + 1000; this.framesThisSecond = 0; this.frame = 0; // Pre-populate smoothing array for (var i = 0; i < this.deltaSmoothingMax; i++) { this.deltaHistory[i] = Math.min(this._target, this.deltaHistory[i]); } this.delta = 0; this.deltaIndex = 0; this._coolDown = this.panicMax; }, /** * Starts the Time Step running, if it is not already doing so. * Called automatically by the Game Boot process. * * @method Phaser.Boot.TimeStep#start * @since 3.0.0 * * @param {TimeStepCallback} callback - The callback to be invoked each time the Time Step steps. */ start: function (callback) { if (this.started) { return this; } this.started = true; this.running = true; for (var i = 0; i < this.deltaSmoothingMax; i++) { this.deltaHistory[i] = this._target; } this.resetDelta(); this.startTime = window.performance.now(); this.callback = callback; this.raf.start(this.step.bind(this), this.forceSetTimeOut); }, /** * The main step method. This is called each time the browser updates, either by Request Animation Frame, * or by Set Timeout. It is responsible for calculating the delta values, frame totals, cool down history and more. * You generally should never call this method directly. * * @method Phaser.Boot.TimeStep#step * @since 3.0.0 * * @param {number} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout. */ step: function (time) { this.frame++; var before = time - this.lastTime; if (before < 0) { // Because, Chrome. before = 0; } this.rawDelta = before; var idx = this.deltaIndex; var history = this.deltaHistory; var max = this.deltaSmoothingMax; // delta time (time is in ms) var dt = before; // When a browser switches tab, then comes back again, it takes around 10 frames before // the delta time settles down so we employ a 'cooling down' period before we start // trusting the delta values again, to avoid spikes flooding through our delta average if (this._coolDown > 0 || !this.inFocus) { this._coolDown--; dt = Math.min(dt, this._target); } if (dt > this._min) { // Probably super bad start time or browser tab context loss, // so use the last 'sane' dt value dt = history[idx]; // Clamp delta to min (in case history has become corrupted somehow) dt = Math.min(dt, this._min); } // Smooth out the delta over the previous X frames // add the delta to the smoothing array history[idx] = dt; // adjusts the delta history array index based on the smoothing count // this stops the array growing beyond the size of deltaSmoothingMax this.deltaIndex++; if (this.deltaIndex > max) { this.deltaIndex = 0; } // Delta Average var avg = 0; // Loop the history array, adding the delta values together for (var i = 0; i < max; i++) { avg += history[i]; } // Then divide by the array length to get the average delta avg /= max; // Set as the world delta value this.delta = avg; // Real-world timer advance this.time += this.rawDelta; // Update the estimate of the frame rate, `fps`. Every second, the number // of frames that occurred in that second are included in an exponential // moving average of all frames per second, with an alpha of 0.25. This // means that more recent seconds affect the estimated frame rate more than // older seconds. // // When a browser window is NOT minimized, but is covered up (i.e. you're using // another app which has spawned a window over the top of the browser), then it // will start to throttle the raf callback time. It waits for a while, and then // starts to drop the frame rate at 1 frame per second until it's down to just over 1fps. // So if the game was running at 60fps, and the player opens a new window, then // after 60 seconds (+ the 'buffer time') it'll be down to 1fps, so rafin'g at 1Hz. // // When they make the game visible again, the frame rate is increased at a rate of // approx. 8fps, back up to 60fps (or the max it can obtain) // // There is no easy way to determine if this drop in frame rate is because the // browser is throttling raf, or because the game is struggling with performance // because you're asking it to do too much on the device. if (time > this.nextFpsUpdate) { // Compute the new exponential moving average with an alpha of 0.25. this.actualFps = 0.25 * this.framesThisSecond + 0.75 * this.actualFps; this.nextFpsUpdate = time + 1000; this.framesThisSecond = 0; } this.framesThisSecond++; // Interpolation - how far between what is expected and where we are? var interpolation = avg / this._target; this.callback(time, avg, interpolation); // Shift time value over this.lastTime = time; }, /** * Manually calls TimeStep.step, passing in the performance.now value to it. * * @method Phaser.Boot.TimeStep#tick * @since 3.0.0 */ tick: function () { this.step(window.performance.now()); }, /** * Sends the TimeStep to sleep, stopping Request Animation Frame (or SetTimeout) and toggling the `running` flag to false. * * @method Phaser.Boot.TimeStep#sleep * @since 3.0.0 */ sleep: function () { if (this.running) { this.raf.stop(); this.running = false; } }, /** * Wakes-up the TimeStep, restarting Request Animation Frame (or SetTimeout) and toggling the `running` flag to true. * The `seamless` argument controls if the wake-up should adjust the start time or not. * * @method Phaser.Boot.TimeStep#wake * @since 3.0.0 * * @param {boolean} [seamless=false] - Adjust the startTime based on the lastTime values. */ wake: function (seamless) { if (this.running) { this.sleep(); } else if (seamless) { this.startTime += -this.lastTime + (this.lastTime = window.performance.now()); } this.raf.start(this.step.bind(this), this.useRAF); this.running = true; this.step(window.performance.now()); }, /** * Stops the TimeStep running. * * @method Phaser.Boot.TimeStep#stop * @since 3.0.0 * * @return {Phaser.Boot.TimeStep} The TimeStep object. */ stop: function () { this.running = false; this.started = false; this.raf.stop(); return this; }, /** * Destroys the TimeStep. This will stop Request Animation Frame, stop the step, clear the callbacks and null * any objects. * * @method Phaser.Boot.TimeStep#destroy * @since 3.0.0 */ destroy: function () { this.stop(); this.callback = NOOP; this.raf = null; this.game = null; } }); module.exports = TimeStep; /***/ }), /* 507 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var imageHeight = 0; /** * @function addFrame * @private * @since 3.0.0 */ var addFrame = function (texture, sourceIndex, name, frame) { // The frame values are the exact coordinates to cut the frame out of the atlas from var y = imageHeight - frame.y - frame.height; texture.add(name, sourceIndex, frame.x, y, frame.width, frame.height); // These are the original (non-trimmed) sprite values /* if (src.trimmed) { newFrame.setTrim( src.sourceSize.w, src.sourceSize.h, src.spriteSourceSize.x, src.spriteSourceSize.y, src.spriteSourceSize.w, src.spriteSourceSize.h ); } */ }; /** * Parses a Unity YAML File and creates Frames in the Texture. * For more details about Sprite Meta Data see https://docs.unity3d.com/ScriptReference/SpriteMetaData.html * * @function Phaser.Textures.Parsers.UnityYAML * @memberOf Phaser.Textures.Parsers * @private * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to. * @param {integer} sourceIndex - The index of the TextureSource. * @param {object} yaml - The YAML data. * * @return {Phaser.Textures.Texture} The Texture modified by this parser. */ var UnityYAML = function (texture, sourceIndex, yaml) { // Add in a __BASE entry (for the entire atlas) var source = texture.source[sourceIndex]; texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); imageHeight = source.height; var data = yaml.split('\n'); var lineRegExp = /^[ ]*(- )*(\w+)+[: ]+(.*)/; var prevSprite = ''; var currentSprite = ''; var rect = { x: 0, y: 0, width: 0, height: 0 }; // var pivot = { x: 0, y: 0 }; // var border = { x: 0, y: 0, z: 0, w: 0 }; for (var i = 0; i < data.length; i++) { var results = data[i].match(lineRegExp); if (!results) { continue; } var isList = (results[1] === '- '); var key = results[2]; var value = results[3]; if (isList) { if (currentSprite !== prevSprite) { addFrame(texture, sourceIndex, currentSprite, rect); prevSprite = currentSprite; } rect = { x: 0, y: 0, width: 0, height: 0 }; } if (key === 'name') { // Start new list currentSprite = value; continue; } switch (key) { case 'x': case 'y': case 'width': case 'height': rect[key] = parseInt(value, 10); break; // case 'pivot': // pivot = eval('var obj = ' + value); // break; // case 'border': // border = eval('var obj = ' + value); // break; } } if (currentSprite !== prevSprite) { addFrame(texture, sourceIndex, currentSprite, rect); } return texture; }; module.exports = UnityYAML; /* Example data: TextureImporter: spritePivot: {x: .5, y: .5} spriteBorder: {x: 0, y: 0, z: 0, w: 0} spritePixelsToUnits: 100 spriteSheet: sprites: - name: asteroids_0 rect: serializedVersion: 2 x: 5 y: 328 width: 65 height: 82 alignment: 0 pivot: {x: 0, y: 0} border: {x: 0, y: 0, z: 0, w: 0} - name: asteroids_1 rect: serializedVersion: 2 x: 80 y: 322 width: 53 height: 88 alignment: 0 pivot: {x: 0, y: 0} border: {x: 0, y: 0, z: 0, w: 0} spritePackingTag: Asteroids */ /***/ }), /* 508 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetFastValue = __webpack_require__(1); /** * Parses a Sprite Sheet and adds the Frames to the Texture, where the Sprite Sheet is stored as a frame within an Atlas. * * In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact * same size and cannot be trimmed or rotated. * * @function Phaser.Textures.Parsers.SpriteSheetFromAtlas * @memberOf Phaser.Textures.Parsers * @private * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to. * @param {Phaser.Textures.Frame} frame - The Frame that contains the Sprite Sheet. * @param {object} config - An object describing how to parse the Sprite Sheet. * @param {number} config.frameWidth - Width in pixels of a single frame in the sprite sheet. * @param {number} [config.frameHeight] - Height in pixels of a single frame in the sprite sheet. Defaults to frameWidth if not provided. * @param {number} [config.startFrame=0] - [description] * @param {number} [config.endFrame=-1] - [description] * @param {number} [config.margin=0] - If the frames have been drawn with a margin, specify the amount here. * @param {number} [config.spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. * * @return {Phaser.Textures.Texture} The Texture modified by this parser. */ var SpriteSheetFromAtlas = function (texture, frame, config) { var frameWidth = GetFastValue(config, 'frameWidth', null); var frameHeight = GetFastValue(config, 'frameHeight', frameWidth); // If missing we can't proceed if (!frameWidth) { throw new Error('TextureManager.SpriteSheetFromAtlas: Invalid frameWidth given.'); } // Add in a __BASE entry (for the entire atlas) // var source = texture.source[sourceIndex]; // texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); var startFrame = GetFastValue(config, 'startFrame', 0); var endFrame = GetFastValue(config, 'endFrame', -1); var margin = GetFastValue(config, 'margin', 0); var spacing = GetFastValue(config, 'spacing', 0); var x = frame.cutX; var y = frame.cutY; var cutWidth = frame.cutWidth; var cutHeight = frame.cutHeight; var sheetWidth = frame.realWidth; var sheetHeight = frame.realHeight; var row = Math.floor((sheetWidth - margin + spacing) / (frameWidth + spacing)); var column = Math.floor((sheetHeight - margin + spacing) / (frameHeight + spacing)); var total = row * column; // trim offsets var leftPad = frame.x; var leftWidth = frameWidth - leftPad; var rightWidth = frameWidth - ((sheetWidth - cutWidth) - leftPad); var topPad = frame.y; var topHeight = frameHeight - topPad; var bottomHeight = frameHeight - ((sheetHeight - cutHeight) - topPad); // console.log('x / y', x, y); // console.log('cutW / H', cutWidth, cutHeight); // console.log('sheetW / H', sheetWidth, sheetHeight); // console.log('row', row, 'column', column, 'total', total); // console.log('LW', leftWidth, 'RW', rightWidth, 'TH', topHeight, 'BH', bottomHeight); if (startFrame > total || startFrame < -total) { startFrame = 0; } if (startFrame < 0) { // Allow negative skipframes. startFrame = total + startFrame; } if (endFrame !== -1) { total = startFrame + (endFrame + 1); } var sheetFrame; var frameX = margin; var frameY = margin; var frameIndex = 0; var sourceIndex = frame.sourceIndex; for (var sheetY = 0; sheetY < column; sheetY++) { var topRow = (sheetY === 0); var bottomRow = (sheetY === column - 1); for (var sheetX = 0; sheetX < row; sheetX++) { var leftRow = (sheetX === 0); var rightRow = (sheetX === row - 1); sheetFrame = texture.add(frameIndex, sourceIndex, x + frameX, y + frameY, frameWidth, frameHeight); if (leftRow || topRow || rightRow || bottomRow) { var destX = (leftRow) ? leftPad : 0; var destY = (topRow) ? topPad : 0; var destWidth = frameWidth; var destHeight = frameHeight; if (leftRow) { destWidth = leftWidth; } else if (rightRow) { destWidth = rightWidth; } if (topRow) { destHeight = topHeight; } else if (bottomRow) { destHeight = bottomHeight; } sheetFrame.cutWidth = destWidth; sheetFrame.cutHeight = destHeight; sheetFrame.setTrim(frameWidth, frameHeight, destX, destY, destWidth, destHeight); } frameX += spacing; if (leftRow) { frameX += leftWidth; } else if (rightRow) { frameX += rightRow; } else { frameX += frameWidth; } frameIndex++; } frameX = margin; frameY += spacing; if (topRow) { frameY += topHeight; } else if (bottomRow) { frameY += bottomHeight; } else { frameY += frameHeight; } } return texture; }; module.exports = SpriteSheetFromAtlas; /***/ }), /* 509 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetFastValue = __webpack_require__(1); /** * Parses a Sprite Sheet and adds the Frames to the Texture. * * In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact * same size and cannot be trimmed or rotated. * * @function Phaser.Textures.Parsers.SpriteSheet * @memberOf Phaser.Textures.Parsers * @private * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to. * @param {integer} sourceIndex - The index of the TextureSource. * @param {integer} x - [description] * @param {integer} y - [description] * @param {integer} width - [description] * @param {integer} height - [description] * @param {object} config - An object describing how to parse the Sprite Sheet. * @param {number} config.frameWidth - Width in pixels of a single frame in the sprite sheet. * @param {number} [config.frameHeight] - Height in pixels of a single frame in the sprite sheet. Defaults to frameWidth if not provided. * @param {number} [config.startFrame=0] - [description] * @param {number} [config.endFrame=-1] - [description] * @param {number} [config.margin=0] - If the frames have been drawn with a margin, specify the amount here. * @param {number} [config.spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. * * @return {Phaser.Textures.Texture} The Texture modified by this parser. */ var SpriteSheet = function (texture, sourceIndex, x, y, width, height, config) { var frameWidth = GetFastValue(config, 'frameWidth', null); var frameHeight = GetFastValue(config, 'frameHeight', frameWidth); // If missing we can't proceed if (frameWidth === null) { throw new Error('TextureManager.SpriteSheet: Invalid frameWidth given.'); } // Add in a __BASE entry (for the entire atlas) var source = texture.source[sourceIndex]; texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); var startFrame = GetFastValue(config, 'startFrame', 0); var endFrame = GetFastValue(config, 'endFrame', -1); var margin = GetFastValue(config, 'margin', 0); var spacing = GetFastValue(config, 'spacing', 0); var row = Math.floor((width - margin + spacing) / (frameWidth + spacing)); var column = Math.floor((height - margin + spacing) / (frameHeight + spacing)); var total = row * column; if (startFrame > total || startFrame < -total) { startFrame = 0; } if (startFrame < 0) { // Allow negative skipframes. startFrame = total + startFrame; } if (endFrame !== -1) { total = startFrame + (endFrame + 1); } var fx = margin; var fy = margin; var ax = 0; var ay = 0; for (var i = 0; i < total; i++) { ax = 0; ay = 0; var w = fx + frameWidth; var h = fy + frameHeight; if (w > width) { ax = w - width; } if (h > height) { ay = h - height; } texture.add(i, sourceIndex, x + fx, y + fy, frameWidth - ax, frameHeight - ay); fx += frameWidth + spacing; if (fx + frameWidth > width) { fx = margin; fy += frameHeight + spacing; } } return texture; }; module.exports = SpriteSheet; /***/ }), /* 510 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clone = __webpack_require__(33); /** * Parses a Texture Atlas JSON Hash and adds the Frames to the Texture. * JSON format expected to match that defined by Texture Packer, with the frames property containing an object of Frames. * * @function Phaser.Textures.Parsers.JSONHash * @memberOf Phaser.Textures.Parsers * @private * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to. * @param {integer} sourceIndex - The index of the TextureSource. * @param {object} json - The JSON data. * * @return {Phaser.Textures.Texture} The Texture modified by this parser. */ var JSONHash = function (texture, sourceIndex, json) { // Malformed? if (!json['frames']) { console.warn('Invalid Texture Atlas JSON Hash given, missing \'frames\' Object'); return; } // Add in a __BASE entry (for the entire atlas) var source = texture.source[sourceIndex]; texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); // By this stage frames is a fully parsed Object var frames = json['frames']; var newFrame; for (var key in frames) { var src = frames[key]; // The frame values are the exact coordinates to cut the frame out of the atlas from newFrame = texture.add(key, sourceIndex, src.frame.x, src.frame.y, src.frame.w, src.frame.h); // These are the original (non-trimmed) sprite values if (src.trimmed) { newFrame.setTrim( src.sourceSize.w, src.sourceSize.h, src.spriteSourceSize.x, src.spriteSourceSize.y, src.spriteSourceSize.w, src.spriteSourceSize.h ); } if (src.rotated) { newFrame.rotated = true; newFrame.updateUVsInverted(); } // Copy over any extra data newFrame.customData = Clone(src); } // Copy over any additional data that was in the JSON to Texture.customData for (var dataKey in json) { if (dataKey === 'frames') { continue; } if (Array.isArray(json[dataKey])) { texture.customData[dataKey] = json[dataKey].slice(0); } else { texture.customData[dataKey] = json[dataKey]; } } return texture; }; module.exports = JSONHash; /***/ }), /* 511 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clone = __webpack_require__(33); /** * Parses a Texture Atlas JSON Array and adds the Frames to the Texture. * JSON format expected to match that defined by Texture Packer, with the frames property containing an array of Frames. * * @function Phaser.Textures.Parsers.JSONArray * @memberOf Phaser.Textures.Parsers * @private * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to. * @param {integer} sourceIndex - The index of the TextureSource. * @param {object} json - The JSON data. * * @return {Phaser.Textures.Texture} The Texture modified by this parser. */ var JSONArray = function (texture, sourceIndex, json) { // Malformed? if (!json['frames'] && !json['textures']) { console.warn('Invalid Texture Atlas JSON Array'); return; } // Add in a __BASE entry (for the entire atlas) var source = texture.source[sourceIndex]; texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); // By this stage frames is a fully parsed array var frames = (Array.isArray(json.textures)) ? json.textures[sourceIndex].frames : json.frames; var newFrame; for (var i = 0; i < frames.length; i++) { var src = frames[i]; // The frame values are the exact coordinates to cut the frame out of the atlas from newFrame = texture.add(src.filename, sourceIndex, src.frame.x, src.frame.y, src.frame.w, src.frame.h); // These are the original (non-trimmed) sprite values if (src.trimmed) { newFrame.setTrim( src.sourceSize.w, src.sourceSize.h, src.spriteSourceSize.x, src.spriteSourceSize.y, src.spriteSourceSize.w, src.spriteSourceSize.h ); } if (src.rotated) { newFrame.rotated = true; newFrame.updateUVsInverted(); } if (src.anchor) { newFrame.customPivot = true; newFrame.pivotX = src.anchor.x; newFrame.pivotY = src.anchor.y; } // Copy over any extra data newFrame.customData = Clone(src); } // Copy over any additional data that was in the JSON to Texture.customData for (var dataKey in json) { if (dataKey === 'frames') { continue; } if (Array.isArray(json[dataKey])) { texture.customData[dataKey] = json[dataKey].slice(0); } else { texture.customData[dataKey] = json[dataKey]; } } return texture; }; module.exports = JSONArray; /***/ }), /* 512 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Adds an Image Element to a Texture. * * @function Phaser.Textures.Parsers.Image * @memberOf Phaser.Textures.Parsers * @private * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to. * @param {integer} sourceIndex - The index of the TextureSource. * * @return {Phaser.Textures.Texture} The Texture modified by this parser. */ var Image = function (texture, sourceIndex) { var source = texture.source[sourceIndex]; texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); return texture; }; module.exports = Image; /***/ }), /* 513 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Adds a Canvas Element to a Texture. * * @function Phaser.Textures.Parsers.Canvas * @memberOf Phaser.Textures.Parsers * @private * @since 3.0.0 * * @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to. * @param {integer} sourceIndex - The index of the TextureSource. * * @return {Phaser.Textures.Texture} The Texture modified by this parser. */ var Canvas = function (texture, sourceIndex) { var source = texture.source[sourceIndex]; texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); return texture; }; module.exports = Canvas; /***/ }), /* 514 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Parses an XML Texture Atlas object and adds all the Frames into a Texture. * * @function Phaser.Textures.Parsers.AtlasXML * @memberOf Phaser.Textures.Parsers * @private * @since 3.7.0 * * @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to. * @param {integer} sourceIndex - The index of the TextureSource. * @param {*} xml - The XML data. * * @return {Phaser.Textures.Texture} The Texture modified by this parser. */ var AtlasXML = function (texture, sourceIndex, xml) { // Malformed? if (!xml.getElementsByTagName('TextureAtlas')) { console.warn('Invalid Texture Atlas XML given'); return; } // Add in a __BASE entry (for the entire atlas) var source = texture.source[sourceIndex]; texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); // By this stage frames is a fully parsed array var frames = xml.getElementsByTagName('SubTexture'); var newFrame; for (var i = 0; i < frames.length; i++) { var frame = frames[i].attributes; var name = frame.name.value; var x = parseInt(frame.x.value, 10); var y = parseInt(frame.y.value, 10); var width = parseInt(frame.width.value, 10); var height = parseInt(frame.height.value, 10); // The frame values are the exact coordinates to cut the frame out of the atlas from newFrame = texture.add(name, sourceIndex, x, y, width, height); // These are the original (non-trimmed) sprite values if (frame.frameX) { var frameX = Math.abs(parseInt(frame.frameX.value, 10)); var frameY = Math.abs(parseInt(frame.frameY.value, 10)); var frameWidth = parseInt(frame.frameWidth.value, 10); var frameHeight = parseInt(frame.frameHeight.value, 10); newFrame.setTrim( width, height, frameX, frameY, frameWidth, frameHeight ); } } return texture; }; module.exports = AtlasXML; /***/ }), /* 515 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var IsSizePowerOfTwo = __webpack_require__(85); var Texture = __webpack_require__(117); /** * @classdesc * A Canvas Texture is a special kind of Texture that is backed by an HTML Canvas Element as its source. * * You can use the properties of this texture to draw to the canvas element directly, using all of the standard * canvas operations available in the browser. Any Game Object can be given this texture and will render with it. * * Note: When running under WebGL the Canvas Texture needs to re-generate its base WebGLTexture and reupload it to * the GPU every time you modify it, otherwise the changes you make to this texture will not be visible. To do this * you should call `CanvasTexture.refresh()` once you are finished with your changes to the canvas. Try and keep * this to a minimum, especially on large canvas sizes, or you may inadvertently thrash the GPU by constantly uploading * texture data to it. This restriction does not apply if using the Canvas Renderer. * * It starts with only one frame that covers the whole of the canvas. You can add further frames, that specify * sections of the canvas using the `add` method. * * Should you need to resize the canvas use the `setSize` method so that it accurately updates all of the underlying * texture data as well. Forgetting to do this (i.e. by changing the canvas size directly from your code) could cause * graphical errors. * * @class CanvasTexture * @extends Phaser.Textures.Texture * @memberOf Phaser.Textures * @constructor * @since 3.7.0 * * @param {Phaser.Textures.TextureManager} manager - A reference to the Texture Manager this Texture belongs to. * @param {string} key - The unique string-based key of this Texture. * @param {HTMLCanvasElement} source - The canvas element that is used as the base of this texture. * @param {integer} width - The width of the canvas. * @param {integer} height - The height of the canvas. */ var CanvasTexture = new Class({ Extends: Texture, initialize: function CanvasTexture (manager, key, source, width, height) { Texture.call(this, manager, key, source, width, height); this.add('__BASE', 0, 0, 0, width, height); /** * A reference to the Texture Source of this Canvas. * * @name Phaser.Textures.TextureManager#_source * @type {Phaser.Textures.TextureSource} * @private * @since 3.7.0 */ this._source = this.frames['__BASE'].source; /** * The source Canvas Element. * * @name Phaser.Textures.TextureManager#canvas * @readOnly * @type {HTMLCanvasElement} * @since 3.7.0 */ this.canvas = this._source.image; /** * The 2D Canvas Rendering Context. * * @name Phaser.Textures.TextureManager#canvas * @readOnly * @type {CanvasRenderingContext2D} * @since 3.7.0 */ this.context = this.canvas.getContext('2d'); /** * The width of the Canvas. * This property is read-only, if you wish to change use `setSize`. * * @name Phaser.Textures.TextureManager#width * @readOnly * @type {integer} * @since 3.7.0 */ this.width = width; /** * The height of the Canvas. * This property is read-only, if you wish to change use `setSize`. * * @name Phaser.Textures.TextureManager#height * @readOnly * @type {integer} * @since 3.7.0 */ this.height = height; }, /** * This should be called manually if you are running under WebGL. * It will refresh the WebGLTexture from the Canvas source. Only call this if you know that the * canvas has changed, as there is a significant GPU texture allocation cost involved in doing so. * * @method Phaser.Textures.CanvasTexture#refresh * @since 3.7.0 * * @return {Phaser.Textures.CanvasTexture} This CanvasTexture. */ refresh: function () { this._source.update(); return this; }, /** * Gets the Canvas Element. * * @method Phaser.Textures.CanvasTexture#getCanvas * @since 3.7.0 * * @return {HTMLCanvasElement} The Canvas DOM element this texture is using. */ getCanvas: function () { return this.canvas; }, /** * Gets the 2D Canvas Rendering Context. * * @method Phaser.Textures.CanvasTexture#getContext * @since 3.7.0 * * @return {CanvasRenderingContext2D} The Canvas Rendering Context this texture is using. */ getContext: function () { return this.context; }, /** * Clears this Canvas Texture, resetting it back to transparent. * * @method Phaser.Textures.CanvasTexture#clear * @since 3.7.0 * * @return {Phaser.Textures.CanvasTexture} The Canvas Texture. */ clear: function () { this.context.clearRect(0, 0, this.width, this.height); return this; }, /** * Changes the size of this Canvas Texture. * * @method Phaser.Textures.CanvasTexture#setSize * @since 3.7.0 * * @param {integer} width - The new width of the Canvas. * @param {integer} [height] - The new height of the Canvas. If not given it will use the width as the height. * * @return {Phaser.Textures.CanvasTexture} The Canvas Texture. */ setSize: function (width, height) { if (height === undefined) { height = width; } if (width !== this.width || height !== this.height) { // Update the Canvas this.canvas.width = width; this.canvas.height = height; // Update the Texture Source this._source.width = width; this._source.height = height; this._source.isPowerOf2 = IsSizePowerOfTwo(width, height); // Update the Frame this.frames['__BASE'].setSize(width, height, 0, 0); this.refresh(); } return this; } }); module.exports = CanvasTexture; /***/ }), /* 516 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // These properties get injected into the Scene and map to local systems // The map value is the property that is injected into the Scene, the key is the Scene.Systems reference. // These defaults can be modified via the Scene config object // var config = { // map: { // add: 'makeStuff', // load: 'loader' // } // }; var InjectionMap = { game: 'game', anims: 'anims', cache: 'cache', plugins: 'plugins', registry: 'registry', sound: 'sound', textures: 'textures', events: 'events', cameras: 'cameras', cameras3d: 'cameras3d', add: 'add', make: 'make', scenePlugin: 'scene', displayList: 'children', lights: 'lights', data: 'data', input: 'input', load: 'load', time: 'time', tweens: 'tweens', arcadePhysics: 'physics', impactPhysics: 'impact', matterPhysics: 'matter' }; module.exports = InjectionMap; /***/ }), /* 517 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetFastValue = __webpack_require__(1); /** * Builds an array of which plugins (not including physics plugins) should be activated for the given Scene. * * @function Phaser.Scenes.GetScenePlugins * @since 3.0.0 * * @param {Phaser.Scenes.Systems} sys - [description] * * @return {array} [description] */ var GetScenePlugins = function (sys) { var defaultPlugins = sys.plugins.getDefaultScenePlugins(); var scenePlugins = GetFastValue(sys.settings, 'plugins', false); // Scene Plugins always override Default Plugins if (Array.isArray(scenePlugins)) { return scenePlugins; } else if (defaultPlugins) { return defaultPlugins; } else { // No default plugins or plugins in this scene return []; } }; module.exports = GetScenePlugins; /***/ }), /* 518 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GetFastValue = __webpack_require__(1); var UppercaseFirst = __webpack_require__(256); /** * Builds an array of which physics plugins should be activated for the given Scene. * * @function Phaser.Scenes.GetPhysicsPlugins * @since 3.0.0 * * @param {Phaser.Scenes.Systems} sys - The scene system to get the physics systems of. * * @return {array} An array of Physics systems to start for this Scene. */ var GetPhysicsPlugins = function (sys) { var defaultSystem = sys.game.config.defaultPhysicsSystem; var sceneSystems = GetFastValue(sys.settings, 'physics', false); if (!defaultSystem && !sceneSystems) { // No default physics system or systems in this scene return; } // Let's build the systems array var output = []; if (defaultSystem) { output.push(UppercaseFirst(defaultSystem + 'Physics')); } if (sceneSystems) { for (var key in sceneSystems) { key = UppercaseFirst(key.concat('Physics')); if (output.indexOf(key) === -1) { output.push(key); } } } // An array of Physics systems to start for this Scene return output; }; module.exports = GetPhysicsPlugins; /***/ }), /* 519 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Determines the full screen support of the browser running this Phaser Game instance. * These values are read-only and populated during the boot sequence of the game. * They are then referenced by internal game systems and are available for you to access * via `this.sys.game.device.fullscreen` from within any Scene. * * @typedef {object} Phaser.Device.Fullscreen * @since 3.0.0 * * @property {boolean} available - Does the browser support the Full Screen API? * @property {boolean} keyboard - Does the browser support access to the Keyboard during Full Screen mode? * @property {string} cancel - If the browser supports the Full Screen API this holds the call you need to use to cancel it. * @property {string} request - If the browser supports the Full Screen API this holds the call you need to use to activate it. */ var Fullscreen = { available: false, cancel: '', keyboard: false, request: '' }; /** * Checks for support of the Full Screen API. */ function init () { var i; var fs = [ 'requestFullscreen', 'requestFullScreen', 'webkitRequestFullscreen', 'webkitRequestFullScreen', 'msRequestFullscreen', 'msRequestFullScreen', 'mozRequestFullScreen', 'mozRequestFullscreen' ]; var element = document.createElement('div'); for (i = 0; i < fs.length; i++) { if (element[fs[i]]) { Fullscreen.available = true; Fullscreen.request = fs[i]; break; } } var cfs = [ 'cancelFullScreen', 'exitFullscreen', 'webkitCancelFullScreen', 'webkitExitFullscreen', 'msCancelFullScreen', 'msExitFullscreen', 'mozCancelFullScreen', 'mozExitFullscreen' ]; if (Fullscreen.available) { for (i = 0; i < cfs.length; i++) { if (document[cfs[i]]) { Fullscreen.cancel = cfs[i]; break; } } } // Keyboard Input? if (window['Element'] && Element['ALLOW_KEYBOARD_INPUT']) { Fullscreen.keyboard = true; } return Fullscreen; } module.exports = init(); /***/ }), /* 520 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Determines the video support of the browser running this Phaser Game instance. * These values are read-only and populated during the boot sequence of the game. * They are then referenced by internal game systems and are available for you to access * via `this.sys.game.device.video` from within any Scene. * * @typedef {object} Phaser.Device.Video * @since 3.0.0 * * @property {boolean} h264Video - Can this device play h264 mp4 video files? * @property {boolean} hlsVideo - Can this device play hls video files? * @property {boolean} mp4Video - Can this device play h264 mp4 video files? * @property {boolean} oggVideo - Can this device play ogg video files? * @property {boolean} vp9Video - Can this device play vp9 video files? * @property {boolean} webmVideo - Can this device play webm video files? */ var Video = { h264Video: false, hlsVideo: false, mp4Video: false, oggVideo: false, vp9Video: false, webmVideo: false }; function init () { var videoElement = document.createElement('video'); var result = !!videoElement.canPlayType; try { if (result) { if (videoElement.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, '')) { Video.oggVideo = true; } if (videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, '')) { // Without QuickTime, this value will be `undefined`. github.com/Modernizr/Modernizr/issues/546 Video.h264Video = true; Video.mp4Video = true; } if (videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, '')) { Video.webmVideo = true; } if (videoElement.canPlayType('video/webm; codecs="vp9"').replace(/^no$/, '')) { Video.vp9Video = true; } if (videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/, '')) { Video.hlsVideo = true; } } } catch (e) { // Nothing to do } return Video; } module.exports = init(); /***/ }), /* 521 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Browser = __webpack_require__(80); /** * Determines the audio playback capabilities of the device running this Phaser Game instance. * These values are read-only and populated during the boot sequence of the game. * They are then referenced by internal game systems and are available for you to access * via `this.sys.game.device.audio` from within any Scene. * * @typedef {object} Phaser.Device.Audio * @since 3.0.0 * * @property {boolean} audioData - Can this device play HTML Audio tags? * @property {boolean} dolby - Can this device play EC-3 Dolby Digital Plus files? * @property {boolean} m4a - Can this device can play m4a files. * @property {boolean} mp3 - Can this device play mp3 files? * @property {boolean} ogg - Can this device play ogg files? * @property {boolean} opus - Can this device play opus files? * @property {boolean} wav - Can this device play wav files? * @property {boolean} webAudio - Does this device have the Web Audio API? * @property {boolean} webm - Can this device play webm files? */ var Audio = { audioData: false, dolby: false, m4a: false, mp3: false, ogg: false, opus: false, wav: false, webAudio: false, webm: false }; function init () { Audio.audioData = !!(window['Audio']); Audio.webAudio = !!(window['AudioContext'] || window['webkitAudioContext']); var audioElement = document.createElement('audio'); var result = !!audioElement.canPlayType; try { if (result) { if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) { Audio.ogg = true; } if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '') || audioElement.canPlayType('audio/opus;').replace(/^no$/, '')) { Audio.opus = true; } if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) { Audio.mp3 = true; } // Mimetypes accepted: // developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements // bit.ly/iphoneoscodecs if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) { Audio.wav = true; } if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) { Audio.m4a = true; } if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) { Audio.webm = true; } if (audioElement.canPlayType('audio/mp4;codecs="ec-3"') !== '') { if (Browser.edge) { Audio.dolby = true; } else if (Browser.safari && Browser.safariVersion >= 9) { if ((/Mac OS X (\d+)_(\d+)/).test(navigator.userAgent)) { var major = parseInt(RegExp.$1, 10); var minor = parseInt(RegExp.$2, 10); if ((major === 10 && minor >= 11) || major > 10) { Audio.dolby = true; } } } } } } catch (e) { // Nothing to do here } return Audio; } module.exports = init(); /***/ }), /* 522 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var OS = __webpack_require__(57); var Browser = __webpack_require__(80); /** * Determines the input support of the browser running this Phaser Game instance. * These values are read-only and populated during the boot sequence of the game. * They are then referenced by internal game systems and are available for you to access * via `this.sys.game.device.input` from within any Scene. * * @typedef {object} Phaser.Device.Input * @since 3.0.0 * * @property {?string} wheelType - The newest type of Wheel/Scroll event supported: 'wheel', 'mousewheel', 'DOMMouseScroll' * @property {boolean} gamepads - Is navigator.getGamepads available? * @property {boolean} mspointer - Is mspointer available? * @property {boolean} touch - Is touch available? */ var Input = { gamepads: false, mspointer: false, touch: false, wheelEvent: null }; function init () { if ('ontouchstart' in document.documentElement || (navigator.maxTouchPoints && navigator.maxTouchPoints >= 1)) { Input.touch = true; } if (navigator.msPointerEnabled || navigator.pointerEnabled) { Input.mspointer = true; } if (navigator.getGamepads) { Input.gamepads = true; } if (!OS.cocoonJS) { // See https://developer.mozilla.org/en-US/docs/Web/Events/wheel if ('onwheel' in window || (Browser.ie && 'WheelEvent' in window)) { // DOM3 Wheel Event: FF 17+, IE 9+, Chrome 31+, Safari 7+ Input.wheelEvent = 'wheel'; } else if ('onmousewheel' in window) { // Non-FF legacy: IE 6-9, Chrome 1-31, Safari 5-7. Input.wheelEvent = 'mousewheel'; } else if (Browser.firefox && 'MouseScrollEvent' in window) { // FF prior to 17. This should probably be scrubbed. Input.wheelEvent = 'DOMMouseScroll'; } } return Input; } module.exports = init(); /***/ }), /* 523 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // This singleton is instantiated as soon as Phaser loads, // before a Phaser.Game instance has even been created. // Which means all instances of Phaser Games can share it, // without having to re-poll the device all over again /** * @namespace Phaser.Device * @since 3.0.0 */ /** * @typedef {object} Phaser.DeviceConf * * @property {Phaser.Device.OS} os - The OS Device functions. * @property {Phaser.Device.Browser} browser - The Browser Device functions. * @property {Phaser.Device.Features} features - The Features Device functions. * @property {Phaser.Device.Input} input - The Input Device functions. * @property {Phaser.Device.Audio} audio - The Audio Device functions. * @property {Phaser.Device.Video} video - The Video Device functions. * @property {Phaser.Device.Fullscreen} fullscreen - The Fullscreen Device functions. * @property {Phaser.Device.CanvasFeatures} canvasFeatures - The Canvas Device functions. */ module.exports = { os: __webpack_require__(57), browser: __webpack_require__(80), features: __webpack_require__(120), input: __webpack_require__(522), audio: __webpack_require__(521), video: __webpack_require__(520), fullscreen: __webpack_require__(519), canvasFeatures: __webpack_require__(203) }; /***/ }), /* 524 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CONST = __webpack_require__(20); /** * Called automatically by Phaser.Game and responsible for creating the console.log debug header. * * You can customize or disable the header via the Game Config object. * * @function Phaser.Boot.DebugHeader * @since 3.0.0 * * @param {Phaser.Game} game - The Phaser.Game instance which will output this debug header. */ var DebugHeader = function (game) { var config = game.config; if (config.hideBanner) { return; } var renderType = 'WebGL'; if (config.renderType === CONST.CANVAS) { renderType = 'Canvas'; } else if (config.renderType === CONST.HEADLESS) { renderType = 'Headless'; } var audioConfig = config.audio; var deviceAudio = game.device.audio; var audioType; if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio)) { audioType = 'Web Audio'; } else if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData)) { audioType = 'No Audio'; } else { audioType = 'HTML5 Audio'; } if (!game.device.browser.ie) { var c = ''; var args = [ c ]; if (Array.isArray(config.bannerBackgroundColor)) { var lastColor; config.bannerBackgroundColor.forEach(function (color) { c = c.concat('%c '); args.push('background: ' + color); lastColor = color; }); // inject the text color args[args.length - 1] = 'color: ' + config.bannerTextColor + '; background: ' + lastColor; } else { c = c.concat('%c '); args.push('color: ' + config.bannerTextColor + '; background: ' + config.bannerBackgroundColor); } // URL link background color (always white) args.push('background: #fff'); if (config.gameTitle) { c = c.concat(config.gameTitle); if (config.gameVersion) { c = c.concat(' v' + config.gameVersion); } if (!config.hidePhaser) { c = c.concat(' / '); } } if (!config.hidePhaser) { c = c.concat('Phaser v' + CONST.VERSION + ' (' + renderType + ' | ' + audioType + ')'); } c = c.concat(' %c ' + config.gameURL); // Inject the new string back into the args array args[0] = c; console.log.apply(console, args); } else if (window['console']) { console.log('Phaser v' + CONST.VERSION + ' / https://phaser.io'); } }; module.exports = DebugHeader; /***/ }), /* 525 */ /***/ (function(module, exports) { module.exports = [ '#define SHADER_NAME PHASER_TEXTURE_TINT_VS', '', 'precision mediump float;', '', 'uniform mat4 uProjectionMatrix;', 'uniform mat4 uViewMatrix;', 'uniform mat4 uModelMatrix;', '', 'attribute vec2 inPosition;', 'attribute vec2 inTexCoord;', 'attribute vec4 inTint;', '', 'varying vec2 outTexCoord;', 'varying vec4 outTint;', '', 'void main ()', '{', ' gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);', ' outTexCoord = inTexCoord;', ' outTint = inTint;', '}', '', '' ].join('\n'); /***/ }), /* 526 */ /***/ (function(module, exports) { module.exports = [ '#define SHADER_NAME PHASER_TEXTURE_TINT_FS', '', 'precision mediump float;', '', 'uniform sampler2D uMainSampler;', '', 'varying vec2 outTexCoord;', 'varying vec4 outTint;', '', 'void main()', '{', ' vec4 texel = texture2D(uMainSampler, outTexCoord);', ' texel *= vec4(outTint.rgb * outTint.a, outTint.a);', ' gl_FragColor = texel;', '}', '' ].join('\n'); /***/ }), /* 527 */ /***/ (function(module, exports) { module.exports = [ '#define SHADER_NAME PHASER_FORWARD_DIFFUSE_FS', '', 'precision mediump float;', '', 'struct Light', '{', ' vec2 position;', ' vec3 color;', ' float intensity;', ' float radius;', '};', '', 'const int kMaxLights = %LIGHT_COUNT%;', '', 'uniform vec4 uCamera; /* x, y, rotation, zoom */', 'uniform vec2 uResolution;', 'uniform sampler2D uMainSampler;', 'uniform sampler2D uNormSampler;', 'uniform vec3 uAmbientLightColor;', 'uniform Light uLights[kMaxLights];', '', 'varying vec2 outTexCoord;', 'varying vec4 outTint;', '', 'void main()', '{', ' vec3 finalColor = vec3(0.0, 0.0, 0.0);', ' vec4 color = texture2D(uMainSampler, outTexCoord) * vec4(outTint.rgb * outTint.a, outTint.a);', ' vec3 normalMap = texture2D(uNormSampler, outTexCoord).rgb;', ' vec3 normal = normalize(vec3(normalMap * 2.0 - 1.0));', ' vec2 res = vec2(min(uResolution.x, uResolution.y)) * uCamera.w;', '', ' for (int index = 0; index < kMaxLights; ++index)', ' {', ' Light light = uLights[index];', ' vec3 lightDir = vec3((light.position.xy / res) - (gl_FragCoord.xy / res), 0.1);', ' vec3 lightNormal = normalize(lightDir);', ' float distToSurf = length(lightDir) * uCamera.w;', ' float diffuseFactor = max(dot(normal, lightNormal), 0.0);', ' float radius = (light.radius / res.x * uCamera.w) * uCamera.w;', ' float attenuation = clamp(1.0 - distToSurf * distToSurf / (radius * radius), 0.0, 1.0);', ' vec3 diffuse = light.color * diffuseFactor;', ' finalColor += (attenuation * diffuse) * light.intensity;', ' }', '', ' vec4 colorOutput = vec4(uAmbientLightColor + finalColor, 1.0);', ' gl_FragColor = color * vec4(colorOutput.rgb * colorOutput.a, colorOutput.a);', '', '}', '' ].join('\n'); /***/ }), /* 528 */ /***/ (function(module, exports) { module.exports = [ '#define SHADER_NAME PHASER_FLAT_TINT_VS', '', 'precision mediump float;', '', 'uniform mat4 uProjectionMatrix;', 'uniform mat4 uViewMatrix;', 'uniform mat4 uModelMatrix;', '', 'attribute vec2 inPosition;', 'attribute vec4 inTint;', '', 'varying vec4 outTint;', '', 'void main () {', ' gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);', ' outTint = inTint;', '}', '' ].join('\n'); /***/ }), /* 529 */ /***/ (function(module, exports) { module.exports = [ '#define SHADER_NAME PHASER_FLAT_TINT_FS', '', 'precision mediump float;', '', 'varying vec4 outTint;', '', 'void main() {', ' gl_FragColor = vec4(outTint.rgb * outTint.a, outTint.a);', '}', '' ].join('\n'); /***/ }), /* 530 */ /***/ (function(module, exports) { module.exports = [ '#define SHADER_NAME PHASER_BITMAP_MASK_VS', '', 'precision mediump float;', '', 'attribute vec2 inPosition;', '', 'void main()', '{', ' gl_Position = vec4(inPosition, 0.0, 1.0);', '}', '' ].join('\n'); /***/ }), /* 531 */ /***/ (function(module, exports) { module.exports = [ '#define SHADER_NAME PHASER_BITMAP_MASK_FS', '', 'precision mediump float;', '', 'uniform vec2 uResolution;', 'uniform sampler2D uMainSampler;', 'uniform sampler2D uMaskSampler;', 'uniform bool uInvertMaskAlpha;', '', 'void main()', '{', ' vec2 uv = gl_FragCoord.xy / uResolution;', ' vec4 mainColor = texture2D(uMainSampler, uv);', ' vec4 maskColor = texture2D(uMaskSampler, uv);', ' float alpha = mainColor.a;', '', ' if (!uInvertMaskAlpha)', ' {', ' alpha *= (maskColor.a);', ' }', ' else', ' {', ' alpha *= (1.0 - maskColor.a);', ' }', '', ' gl_FragColor = vec4(mainColor.rgb * alpha, alpha);', '}', '' ].join('\n'); /***/ }), /* 532 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var CanvasInterpolation = __webpack_require__(272); var CanvasPool = __webpack_require__(22); var CONST = __webpack_require__(20); var Features = __webpack_require__(120); /** * Called automatically by Phaser.Game and responsible for creating the renderer it will use. * * Relies upon two webpack global flags to be defined: `WEBGL_RENDERER` and `CANVAS_RENDERER` during build time, but not at run-time. * * @function Phaser.Boot.CreateRenderer * @since 3.0.0 * * @param {Phaser.Game} game - The Phaser.Game instance on which the renderer will be set. */ var CreateRenderer = function (game) { var config = game.config; // Game either requested Canvas, // or requested AUTO or WEBGL but the browser doesn't support it, so fall back to Canvas if (config.renderType !== CONST.HEADLESS) { if (config.renderType === CONST.CANVAS || (config.renderType !== CONST.CANVAS && !Features.webGL)) { if (Features.canvas) { // They requested Canvas and their browser supports it config.renderType = CONST.CANVAS; } else { throw new Error('Cannot create Canvas or WebGL context, aborting.'); } } else { // Game requested WebGL and browser says it supports it config.renderType = CONST.WEBGL; } } // Pixel Art mode? if (config.pixelArt) { CanvasPool.disableSmoothing(); } // Does the game config provide its own canvas element to use? if (config.canvas) { game.canvas = config.canvas; } else { game.canvas = CanvasPool.create(game, config.width, config.height, config.renderType); } // Does the game config provide some canvas css styles to use? if (config.canvasStyle) { game.canvas.style = config.canvasStyle; } // Pixel Art mode? if (config.pixelArt) { CanvasInterpolation.setCrisp(game.canvas); } // Zoomed? if (config.zoom !== 1) { game.canvas.style.width = (config.width * config.zoom).toString() + 'px'; game.canvas.style.height = (config.height * config.zoom).toString() + 'px'; } if (config.renderType === CONST.HEADLESS) { // Nothing more to do here return; } var CanvasRenderer; var WebGLRenderer; if (true) { CanvasRenderer = __webpack_require__(267); WebGLRenderer = __webpack_require__(262); // Let the config pick the renderer type, as both are included if (config.renderType === CONST.WEBGL) { game.renderer = new WebGLRenderer(game); // The WebGL Renderer sets this value during its init, not on construction game.context = null; } else { game.renderer = new CanvasRenderer(game); game.context = game.renderer.gameContext; } } if (false) {} if (false) {} }; module.exports = CreateRenderer; /***/ }), /* 533 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var CONST = __webpack_require__(20); var GetFastValue = __webpack_require__(1); var GetValue = __webpack_require__(4); var IsPlainObject = __webpack_require__(8); var MATH = __webpack_require__(16); var NOOP = __webpack_require__(3); var DefaultPlugins = __webpack_require__(121); var ValueToColor = __webpack_require__(132); /** * This callback type is completely empty, a no-operation. * * @callback NOOP */ /** * @callback BootCallback * * @param {Phaser.Game} game - [description] */ /** * @typedef {object} FPSConfig * * @property {integer} [min=10] - [description] * @property {integer} [target=60] - [description] * @property {boolean} [forceSetTimeOut=false] - [description] * @property {integer} [deltaHistory=10] - [description] * @property {integer} [panicMax=120] - [description] */ /** * @typedef {object} LoaderConfig * * @property {string} [baseURL] - [description] * @property {string} [path] - [description] * @property {integer} [maxParallelDownloads=32] - [description] * @property {(string|undefined)} [crossOrigin=undefined] - [description] * @property {string} [responseType] - [description] * @property {boolean} [async=true] - [description] * @property {string} [user] - [description] * @property {string} [password] - [description] * @property {integer} [timeout=0] - [description] */ /** * @typedef {object} GameConfig * * @property {(integer|string)} [width=1024] - [description] * @property {(integer|string)} [height=768] - [description] * @property {number} [zoom=1] - [description] * @property {number} [resolution=1] - [description] * @property {number} [type=CONST.AUTO] - [description] * @property {*} [parent=null] - [description] * @property {HTMLCanvasElement} [canvas=null] - Provide your own Canvas element for Phaser to use instead of creating one. * @property {string} [canvasStyle=null] - [description] * @property {CanvasRenderingContext2D} [context] - Provide your own Canvas Context for Phaser to use, instead of creating one. * @property {object} [scene=null] - [description] * @property {string[]} [seed] - [description] * @property {string} [title=''] - [description] * @property {string} [url='http://phaser.io'] - [description] * @property {string} [version=''] - [description] * @property {boolean} [autoFocus=true] - Automatically call window.focus() when the game boots. * @property {(boolean|object)} [input] - [description] * @property {boolean} [input.keyboard=true] - [description] * @property {*} [input.keyboard.target=window] - [description] * @property {(boolean|object)} [input.mouse=true] - [description] * @property {*} [input.mouse.target=null] - [description] * @property {boolean} [input.touch=true] - [description] * @property {integer} [input.activePointers=1] - [description] * @property {*} [input.touch.target=null] - [description] * @property {boolean} [input.touch.capture=true] - [description] * @property {(boolean|object)} [input.gamepad=false] - [description] * @property {boolean} [disableContextMenu=false] - [description] * @property {(boolean|object)} [banner=false] - [description] * @property {boolean} [banner.hidePhaser=false] - [description] * @property {string} [banner.text='#ffffff'] - [description] * @property {string[]} [banner.background] - [description] * @property {FPSConfig} [fps] - [description] * @property {boolean} [render.antialias=true] - [description] * @property {boolean} [render.pixelArt=false] - [description] * @property {boolean} [render.autoResize=false] - [description] * @property {boolean} [render.roundPixels=false] - [description] * @property {boolean} [render.transparent=false] - [description] * @property {boolean} [render.clearBeforeRender=true] - [description] * @property {boolean} [render.premultipliedAlpha=true] - [description] * @property {boolean} [render.preserveDrawingBuffer=false] - [description] * @property {boolean} [render.failIfMajorPerformanceCaveat=false] - [description] * @property {string} [render.powerPreference='default'] - "high-performance", "low-power" or "default" * @property {(string|number)} [backgroundColor=0x000000] - [description] * @property {object} [callbacks] - [description] * @property {BootCallback} [callbacks.preBoot=NOOP] - [description] * @property {BootCallback} [callbacks.postBoot=NOOP] - [description] * @property {LoaderConfig} [loader] - [description] * @property {object} [images] - [description] * @property {string} [images.default] - [description] * @property {string} [images.missing] - [description] * @property {object} [physics] - [description] */ /** * @classdesc * [description] * * @class Config * @memberOf Phaser.Boot * @constructor * @since 3.0.0 * * @param {GameConfig} [GameConfig] - The configuration object for your Phaser Game instance. */ var Config = new Class({ initialize: function Config (config) { if (config === undefined) { config = {}; } var defaultBannerColor = [ '#ff0000', '#ffff00', '#00ff00', '#00ffff', '#000000' ]; var defaultBannerTextColor = '#ffffff'; /** * @const {(integer|string)} Phaser.Boot.Config#width - [description] */ this.width = GetValue(config, 'width', 1024); /** * @const {(integer|string)} Phaser.Boot.Config#height - [description] */ this.height = GetValue(config, 'height', 768); /** * @const {number} Phaser.Boot.Config#zoom - [description] */ this.zoom = GetValue(config, 'zoom', 1); /** * @const {number} Phaser.Boot.Config#resolution - [description] */ this.resolution = GetValue(config, 'resolution', 1); /** * @const {number} Phaser.Boot.Config#renderType - [description] */ this.renderType = GetValue(config, 'type', CONST.AUTO); /** * @const {?*} Phaser.Boot.Config#parent - [description] */ this.parent = GetValue(config, 'parent', null); /** * @const {?HTMLCanvasElement} Phaser.Boot.Config#canvas - Force Phaser to use your own Canvas element instead of creating one. */ this.canvas = GetValue(config, 'canvas', null); /** * @const {?(CanvasRenderingContext2D|WebGLRenderingContext)} Phaser.Boot.Config#context - Force Phaser to use your own Canvas context instead of creating one. */ this.context = GetValue(config, 'context', null); /** * @const {?string} Phaser.Boot.Config#canvasStyle - [description] */ this.canvasStyle = GetValue(config, 'canvasStyle', null); /** * @const {?object} Phaser.Boot.Config#sceneConfig - [description] */ this.sceneConfig = GetValue(config, 'scene', null); /** * @const {string[]} Phaser.Boot.Config#seed - [description] */ this.seed = GetValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]); MATH.RND.init(this.seed); /** * @const {string} Phaser.Boot.Config#gameTitle - [description] */ this.gameTitle = GetValue(config, 'title', ''); /** * @const {string} Phaser.Boot.Config#gameURL - [description] */ this.gameURL = GetValue(config, 'url', 'https://phaser.io'); /** * @const {string} Phaser.Boot.Config#gameVersion - [description] */ this.gameVersion = GetValue(config, 'version', ''); /** * @const {boolean} Phaser.Boot.Config#autoFocus - [description] */ this.autoFocus = GetValue(config, 'autoFocus', true); // Input /** * @const {boolean} Phaser.Boot.Config#inputKeyboard - [description] */ this.inputKeyboard = GetValue(config, 'input.keyboard', true); /** * @const {*} Phaser.Boot.Config#inputKeyboardEventTarget - [description] */ this.inputKeyboardEventTarget = GetValue(config, 'input.keyboard.target', window); /** * @const {(boolean|object)} Phaser.Boot.Config#inputMouse - [description] */ this.inputMouse = GetValue(config, 'input.mouse', true); /** * @const {?*} Phaser.Boot.Config#inputMouseEventTarget - [description] */ this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null); /** * @const {boolean} Phaser.Boot.Config#inputMouseCapture - [description] */ this.inputMouseCapture = GetValue(config, 'input.mouse.capture', true); /** * @const {boolean} Phaser.Boot.Config#inputTouch - [description] */ this.inputTouch = GetValue(config, 'input.touch', true); /** * @const {?*} Phaser.Boot.Config#inputTouchEventTarget - [description] */ this.inputTouchEventTarget = GetValue(config, 'input.touch.target', null); /** * @const {boolean} Phaser.Boot.Config#inputTouchCapture - [description] */ this.inputTouchCapture = GetValue(config, 'input.touch.capture', true); /** * @const {integer} Phaser.Boot.Config#inputActivePointers - [description] */ this.inputActivePointers = GetValue(config, 'input.activePointers', 1); /** * @const {boolean} Phaser.Boot.Config#inputGamepad - [description] */ this.inputGamepad = GetValue(config, 'input.gamepad', false); /** * @const {*} Phaser.Boot.Config#inputGamepadEventTarget - [description] */ this.inputGamepadEventTarget = GetValue(config, 'input.gamepad.target', window); /** * @const {boolean} Phaser.Boot.Config#disableContextMenu - [description] */ this.disableContextMenu = GetValue(config, 'disableContextMenu', false); /** * @const {any} Phaser.Boot.Config#audio - [description] */ this.audio = GetValue(config, 'audio'); // If you do: { banner: false } it won't display any banner at all /** * @const {boolean} Phaser.Boot.Config#hideBanner - [description] */ this.hideBanner = (GetValue(config, 'banner', null) === false); /** * @const {boolean} Phaser.Boot.Config#hidePhaser - [description] */ this.hidePhaser = GetValue(config, 'banner.hidePhaser', false); /** * @const {string} Phaser.Boot.Config#bannerTextColor - [description] */ this.bannerTextColor = GetValue(config, 'banner.text', defaultBannerTextColor); /** * @const {string[]} Phaser.Boot.Config#bannerBackgroundColor - [description] */ this.bannerBackgroundColor = GetValue(config, 'banner.background', defaultBannerColor); if (this.gameTitle === '' && this.hidePhaser) { this.hideBanner = true; } // Frame Rate config // fps: { // min: 10, // target: 60, // forceSetTimeOut: false, // deltaHistory: 10 // } /** * @const {?FPSConfig} Phaser.Boot.Config#fps - [description] */ this.fps = GetValue(config, 'fps', null); // Renderer Settings // These can either be in a `render` object within the Config, or specified on their own var renderConfig = GetValue(config, 'render', config); /** * @const {boolean} Phaser.Boot.Config#antialias - [description] */ this.antialias = GetValue(renderConfig, 'antialias', true); /** * @const {boolean} Phaser.Boot.Config#pixelArt - [description] */ this.pixelArt = GetValue(renderConfig, 'pixelArt', false); /** * @const {boolean} Phaser.Boot.Config#autoResize - [description] */ this.autoResize = GetValue(renderConfig, 'autoResize', false); /** * @const {boolean} Phaser.Boot.Config#roundPixels - [description] */ this.roundPixels = GetValue(renderConfig, 'roundPixels', false); /** * @const {boolean} Phaser.Boot.Config#transparent - [description] */ this.transparent = GetValue(renderConfig, 'transparent', false); /** * @const {boolean} Phaser.Boot.Config#zoclearBeforeRenderom - [description] */ this.clearBeforeRender = GetValue(renderConfig, 'clearBeforeRender', true); /** * @const {boolean} Phaser.Boot.Config#premultipliedAlpha - [description] */ this.premultipliedAlpha = GetValue(renderConfig, 'premultipliedAlpha', true); /** * @const {boolean} Phaser.Boot.Config#preserveDrawingBuffer - [description] */ this.preserveDrawingBuffer = GetValue(renderConfig, 'preserveDrawingBuffer', false); /** * @const {boolean} Phaser.Boot.Config#failIfMajorPerformanceCaveat - [description] */ this.failIfMajorPerformanceCaveat = GetValue(renderConfig, 'failIfMajorPerformanceCaveat', false); /** * @const {string} Phaser.Boot.Config#powerPreference - [description] */ this.powerPreference = GetValue(renderConfig, 'powerPreference', 'default'); var bgc = GetValue(config, 'backgroundColor', 0); /** * @const {Phaser.Display.Color} Phaser.Boot.Config#backgroundColor - [description] */ this.backgroundColor = ValueToColor(bgc); if (bgc === 0 && this.transparent) { this.backgroundColor.alpha = 0; } // Callbacks /** * @const {BootCallback} Phaser.Boot.Config#preBoot - [description] */ this.preBoot = GetValue(config, 'callbacks.preBoot', NOOP); /** * @const {BootCallback} Phaser.Boot.Config#postBoot - [description] */ this.postBoot = GetValue(config, 'callbacks.postBoot', NOOP); // Physics // physics: { // system: 'impact', // setBounds: true, // gravity: 0, // cellSize: 64 // } /** * @const {object} Phaser.Boot.Config#physics - [description] */ this.physics = GetValue(config, 'physics', {}); /** * @const {boolean} Phaser.Boot.Config#defaultPhysicsSystem - [description] */ this.defaultPhysicsSystem = GetValue(this.physics, 'default', false); // Loader Defaults /** * @const {string} Phaser.Boot.Config#loaderBaseURL - [description] */ this.loaderBaseURL = GetValue(config, 'loader.baseURL', ''); /** * @const {string} Phaser.Boot.Config#loaderPath - [description] */ this.loaderPath = GetValue(config, 'loader.path', ''); /** * @const {integer} Phaser.Boot.Config#loaderMaxParallelDownloads - [description] */ this.loaderMaxParallelDownloads = GetValue(config, 'loader.maxParallelDownloads', 32); /** * @const {(string|undefined)} Phaser.Boot.Config#loaderCrossOrigin - [description] */ this.loaderCrossOrigin = GetValue(config, 'loader.crossOrigin', undefined); /** * @const {string} Phaser.Boot.Config#loaderResponseType - [description] */ this.loaderResponseType = GetValue(config, 'loader.responseType', ''); /** * @const {boolean} Phaser.Boot.Config#loaderAsync - [description] */ this.loaderAsync = GetValue(config, 'loader.async', true); /** * @const {string} Phaser.Boot.Config#loaderUser - [description] */ this.loaderUser = GetValue(config, 'loader.user', ''); /** * @const {string} Phaser.Boot.Config#loaderPassword - [description] */ this.loaderPassword = GetValue(config, 'loader.password', ''); /** * @const {integer} Phaser.Boot.Config#loaderTimeout - [description] */ this.loaderTimeout = GetValue(config, 'loader.timeout', 0); // Plugins /* * Allows `plugins` property to either be an array, in which case it just replaces * the default plugins like previously, or a config object. * * plugins: { * global: [ * { key: 'TestPlugin', plugin: TestPlugin, start: true }, * ], * scene: [ * { key: 'WireFramePlugin', plugin: WireFramePlugin, systemKey: 'wireFramePlugin', sceneKey: 'wireframe' } * ], * default: [], OR * defaultMerge: { * 'ModPlayer' * } * } */ /** * @const {any} Phaser.Boot.Config#installGlobalPlugins - [description] */ this.installGlobalPlugins = []; /** * @const {any} Phaser.Boot.Config#installScenePlugins - [description] */ this.installScenePlugins = []; var plugins = GetValue(config, 'plugins', null); var defaultPlugins = DefaultPlugins.DefaultScene; if (plugins) { // Old 3.7 array format? if (Array.isArray(plugins)) { this.defaultPlugins = plugins; } else if (IsPlainObject(plugins)) { this.installGlobalPlugins = GetFastValue(plugins, 'global', []); this.installScenePlugins = GetFastValue(plugins, 'scene', []); if (Array.isArray(plugins.default)) { defaultPlugins = plugins.default; } else if (Array.isArray(plugins.defaultMerge)) { defaultPlugins = defaultPlugins.concat(plugins.defaultMerge); } } } /** * @const {any} Phaser.Boot.Config#defaultPlugins - The plugins installed into every Scene (in addition to CoreScene and Global). */ this.defaultPlugins = defaultPlugins; // Default / Missing Images var pngPrefix = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAg'; /** * @const {string} Phaser.Boot.Config#defaultImage - [description] */ this.defaultImage = GetValue(config, 'images.default', pngPrefix + 'AQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg=='); /** * @const {string} Phaser.Boot.Config#missingImage - [description] */ this.missingImage = GetValue(config, 'images.missing', pngPrefix + 'CAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg=='); } }); module.exports = Config; /***/ }), /* 534 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var AddToDOM = __webpack_require__(130); var AnimationManager = __webpack_require__(207); var CacheManager = __webpack_require__(205); var CanvasPool = __webpack_require__(22); var Class = __webpack_require__(0); var Config = __webpack_require__(533); var CreateRenderer = __webpack_require__(532); var DataManager = __webpack_require__(81); var DebugHeader = __webpack_require__(524); var Device = __webpack_require__(523); var DOMContentLoaded = __webpack_require__(271); var EventEmitter = __webpack_require__(9); var InputManager = __webpack_require__(201); var PluginManager = __webpack_require__(196); var SceneManager = __webpack_require__(194); var SoundManagerCreator = __webpack_require__(191); var TextureManager = __webpack_require__(184); var TimeStep = __webpack_require__(506); var VisibilityHandler = __webpack_require__(505); /** * @classdesc * The Phaser.Game instance is the main controller for the entire Phaser game. It is responsible * for handling the boot process, parsing the configuration values, creating the renderer, * and setting-up all of the global Phaser systems, such as sound and input. * Once that is complete it will start the Scene Manager and then begin the main game loop. * * You should generally avoid accessing any of the systems created by Game, and instead use those * made available to you via the Phaser.Scene Systems class instead. * * @class Game * @memberOf Phaser * @constructor * @since 3.0.0 * * @param {GameConfig} [GameConfig] - The configuration object for your Phaser Game instance. */ var Game = new Class({ initialize: function Game (config) { /** * The parsed Game Configuration object. * * The values stored within this object are read-only and should not be changed at run-time. * * @name Phaser.Game#config * @type {Phaser.Boot.Config} * @readOnly * @since 3.0.0 */ this.config = new Config(config); /** * A reference to either the Canvas or WebGL Renderer that this Game is using. * * @name Phaser.Game#renderer * @type {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} * @since 3.0.0 */ this.renderer = null; /** * A reference to the HTML Canvas Element that Phaser uses to render the game. * This is created automatically by Phaser unless you provide a `canvas` property * in your Game Config. * * @name Phaser.Game#canvas * @type {HTMLCanvasElement} * @since 3.0.0 */ this.canvas = null; /** * A reference to the Rendering Context belonging to the Canvas Element this game is rendering to. * If the game is running under Canvas it will be a 2d Canvas Rendering Context. * If the game is running under WebGL it will be a WebGL Rendering Context. * This context is created automatically by Phaser unless you provide a `context` property * in your Game Config. * * @name Phaser.Game#context * @type {(CanvasRenderingContext2D|WebGLRenderingContext)} * @since 3.0.0 */ this.context = null; /** * A flag indicating when this Game instance has finished its boot process. * * @name Phaser.Game#isBooted * @type {boolean} * @readOnly * @since 3.0.0 */ this.isBooted = false; /** * A flag indicating if this Game is currently running its game step or not. * * @name Phaser.Game#isRunning * @type {boolean} * @readOnly * @since 3.0.0 */ this.isRunning = false; /** * An Event Emitter which is used to broadcast game-level events from the global systems. * * @name Phaser.Game#events * @type {Phaser.Events.EventEmitter} * @since 3.0.0 */ this.events = new EventEmitter(); /** * An instance of the Animation Manager. * * The Animation Manager is a global system responsible for managing all animations used within your game. * * @name Phaser.Game#anims * @type {Phaser.Animations.AnimationManager} * @since 3.0.0 */ this.anims = new AnimationManager(this); /** * An instance of the Texture Manager. * * The Texture Manager is a global system responsible for managing all textures being used by your game. * * @name Phaser.Game#textures * @type {Phaser.Textures.TextureManager} * @since 3.0.0 */ this.textures = new TextureManager(this); /** * An instance of the Cache Manager. * * The Cache Manager is a global system responsible for caching, accessing and releasing external game assets. * * @name Phaser.Game#cache * @type {Phaser.Cache.CacheManager} * @since 3.0.0 */ this.cache = new CacheManager(this); /** * An instance of the Data Manager * * @name Phaser.Game#registry * @type {Phaser.Data.DataManager} * @since 3.0.0 */ this.registry = new DataManager(this); /** * An instance of the Input Manager. * * The Input Manager is a global system responsible for the capture of browser-level input events. * * @name Phaser.Game#input * @type {Phaser.Input.InputManager} * @since 3.0.0 */ this.input = new InputManager(this, this.config); /** * An instance of the Scene Manager. * * The Scene Manager is a global system responsible for creating, modifying and updating the Scenes in your game. * * @name Phaser.Game#scene * @type {Phaser.Scenes.SceneManager} * @since 3.0.0 */ this.scene = new SceneManager(this, this.config.sceneConfig); /** * A reference to the Device inspector. * * Contains information about the device running this game, such as OS, browser vendor and feature support. * Used by various systems to determine capabilities and code paths. * * @name Phaser.Game#device * @type {Phaser.DeviceConf} * @since 3.0.0 */ this.device = Device; /** * An instance of the base Sound Manager. * * The Sound Manager is a global system responsible for the playback and updating of all audio in your game. * * @name Phaser.Game#sound * @type {Phaser.Sound.BaseSoundManager} * @since 3.0.0 */ this.sound = SoundManagerCreator.create(this); /** * An instance of the Time Step. * * The Time Step is a global system responsible for setting-up and responding to the browser frame events, processing * them and calculating delta values. It then automatically calls the game step. * * @name Phaser.Game#loop * @type {Phaser.Boot.TimeStep} * @since 3.0.0 */ this.loop = new TimeStep(this, this.config.fps); /** * An instance of the Plugin Manager. * * The Plugin Manager is a global system that allows plugins to register themselves with it, and can then install * those plugins into Scenes as required. * * @name Phaser.Game#plugins * @type {Phaser.Plugins.PluginManager} * @since 3.0.0 */ this.plugins = new PluginManager(this, this.config); /** * Is this Game pending destruction at the start of the next frame? * * @name Phaser.Game#pendingDestroy * @type {boolean} * @private * @since 3.5.0 */ this.pendingDestroy = false; /** * Remove the Canvas once the destroy is over? * * @name Phaser.Game#removeCanvas * @type {boolean} * @private * @since 3.5.0 */ this.removeCanvas = false; /** * Does the window the game is running in currently have focus or not? * This is modified by the VisibilityHandler. * * @name Phaser.Game#hasFocus * @type {boolean} * @readOnly * @since 3.9.0 */ this.hasFocus = false; /** * Is the mouse pointer currently over the game canvas or not? * This is modified by the VisibilityHandler. * * @name Phaser.Game#isOver * @type {boolean} * @readOnly * @since 3.10.0 */ this.isOver = true; // Wait for the DOM Ready event, then call boot. DOMContentLoaded(this.boot.bind(this)); }, /** * Game boot event. * * This is an internal event dispatched when the game has finished booting, but before it is ready to start running. * The global systems use this event to know when to set themselves up, dispatching their own `ready` events as required. * * @event Phaser.Game#boot */ /** * This method is called automatically when the DOM is ready. It is responsible for creating the renderer, * displaying the Debug Header, adding the game canvas to the DOM and emitting the 'boot' event. * It listens for a 'ready' event from the base systems and once received it will call `Game.start`. * * @method Phaser.Game#boot * @protected * @fires Phaser.Game#boot * @since 3.0.0 */ boot: function () { this.isBooted = true; this.config.preBoot(this); CreateRenderer(this); DebugHeader(this); AddToDOM(this.canvas, this.config.parent); this.events.emit('boot'); // The Texture Manager has to wait on a couple of non-blocking events before it's fully ready, so it will emit this event this.events.once('ready', this.start, this); }, /** * Called automatically by Game.boot once all of the global systems have finished setting themselves up. * By this point the Game is now ready to start the main loop running. * It will also enable the Visibility Handler. * * @method Phaser.Game#start * @protected * @since 3.0.0 */ start: function () { this.isRunning = true; this.config.postBoot(this); if (this.renderer) { this.loop.start(this.step.bind(this)); } else { this.loop.start(this.headlessStep.bind(this)); } VisibilityHandler(this); var eventEmitter = this.events; eventEmitter.on('hidden', this.onHidden, this); eventEmitter.on('visible', this.onVisible, this); eventEmitter.on('blur', this.onBlur, this); eventEmitter.on('focus', this.onFocus, this); }, /** * Game Pre-Step event. * * This event is dispatched before the main Step starts. * By this point none of the Scene updates have happened. * Hook into it from plugins or systems that need to update before the Scene Manager does. * * @event Phaser.Game#prestepEvent * @param {number} time - [description] * @param {number} delta - [description] */ /** * Game Step event. * * This event is dispatched after Pre-Step and before the Scene Manager steps. * Hook into it from plugins or systems that need to update before the Scene Manager does, but after core Systems. * * @event Phaser.Game#stepEvent * @param {number} time - [description] * @param {number} delta - [description] */ /** * Game Post-Step event. * * This event is dispatched after the Scene Manager has updated. * Hook into it from plugins or systems that need to do things before the render starts. * * @event Phaser.Game#poststepEvent * @param {number} time - [description] * @param {number} delta - [description] */ /** * Game Pre-Render event. * * This event is dispatched immediately before any of the Scenes have started to render. * The renderer will already have been initialized this frame, clearing itself and preparing to receive * the Scenes for rendering, but it won't have actually drawn anything yet. * * @event Phaser.Game#prerenderEvent * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - A reference to the current renderer. */ /** * Game Post-Render event. * * This event is dispatched right at the end of the render process. * Every Scene will have rendered and drawn to the canvas. * * @event Phaser.Game#postrenderEvent * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - A reference to the current renderer. */ /** * The main Game Step. Called automatically by the Time Step, once per browser frame (typically as a result of * Request Animation Frame, or Set Timeout on very old browsers.) * * The step will update the global managers first, then proceed to update each Scene in turn, via the Scene Manager. * * It will then render each Scene in turn, via the Renderer. This process emits `prerender` and `postrender` events. * * @method Phaser.Game#step * @fires Phaser.Game#prestepEvent * @fires Phaser.Game#stepEvent * @fires Phaser.Game#poststepEvent * @fires Phaser.Game#prerenderEvent * @fires Phaser.Game#postrenderEvent * @since 3.0.0 * * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ step: function (time, delta) { if (this.pendingDestroy) { return this.runDestroy(); } var eventEmitter = this.events; // Global Managers like Input and Sound update in the prestep eventEmitter.emit('prestep', time, delta); // This is mostly meant for user-land code and plugins eventEmitter.emit('step', time, delta); // Update the Scene Manager and all active Scenes this.scene.update(time, delta); // Our final event before rendering starts eventEmitter.emit('poststep', time, delta); var renderer = this.renderer; // Run the Pre-render (clearing the canvas, setting background colors, etc) renderer.preRender(); eventEmitter.emit('prerender', renderer, time, delta); // The main render loop. Iterates all Scenes and all Cameras in those scenes, rendering to the renderer instance. this.scene.render(renderer); // The Post-Render call. Tidies up loose end, takes snapshots, etc. renderer.postRender(); // The final event before the step repeats. Your last chance to do anything to the canvas before it all starts again. eventEmitter.emit('postrender', renderer, time, delta); }, /** * A special version of the Game Step for the HEADLESS renderer only. * * The main Game Step. Called automatically by the Time Step, once per browser frame (typically as a result of * Request Animation Frame, or Set Timeout on very old browsers.) * * The step will update the global managers first, then proceed to update each Scene in turn, via the Scene Manager. * * This process emits `prerender` and `postrender` events, even though nothing actually displays. * * @method Phaser.Game#headlessStep * @fires Phaser.Game#prerenderEvent * @fires Phaser.Game#postrenderEvent * @since 3.2.0 * * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time elapsed since the last frame. */ headlessStep: function (time, delta) { var eventEmitter = this.events; // Global Managers eventEmitter.emit('prestep', time, delta); eventEmitter.emit('step', time, delta); // Scenes this.scene.update(time, delta); eventEmitter.emit('poststep', time, delta); // Render eventEmitter.emit('prerender'); eventEmitter.emit('postrender'); }, /** * Game Pause event. * * This event is dispatched when the game loop enters a paused state, usually as a result of the Visibility Handler. * * @event Phaser.Game#pauseEvent */ /** * Called automatically by the Visibility Handler. * This will pause the main loop and then emit a pause event. * * @method Phaser.Game#onHidden * @protected * @fires Phaser.Game#pauseEvent * @since 3.0.0 */ onHidden: function () { this.loop.pause(); this.events.emit('pause'); }, /** * Game Resume event. * * This event is dispatched when the game loop leaves a paused state and resumes running. * * @event Phaser.Game#resumeEvent */ /** * Called automatically by the Visibility Handler. * This will resume the main loop and then emit a resume event. * * @method Phaser.Game#onVisible * @protected * @fires Phaser.Game#resumeEvent * @since 3.0.0 */ onVisible: function () { this.loop.resume(); this.events.emit('resume'); }, /** * Called automatically by the Visibility Handler. * This will set the main loop into a 'blurred' state, which pauses it. * * @method Phaser.Game#onBlur * @protected * @since 3.0.0 */ onBlur: function () { this.hasFocus = false; this.loop.blur(); }, /** * Called automatically by the Visibility Handler. * This will set the main loop into a 'focused' state, which resumes it. * * @method Phaser.Game#onFocus * @protected * @since 3.0.0 */ onFocus: function () { this.hasFocus = true; this.loop.focus(); }, /** * Game Resize event. * * @event Phaser.Game#resizeEvent * @param {number} width - The new width of the Game. * @param {number} height - The new height of the Game. */ /** * Updates the Game Config with the new width and height values given. * Then resizes the Renderer and Input Manager scale. * * @method Phaser.Game#resize * @since 3.2.0 * * @param {number} width - The new width of the game. * @param {number} height - The new height of the game. */ resize: function (width, height) { this.config.width = width; this.config.height = height; this.renderer.resize(width, height); this.input.resize(); this.scene.resize(width, height); this.events.emit('resize', width, height); }, /** * Flags this Game instance as needing to be destroyed on the next frame. * It will wait until the current frame has completed and then call `runDestroy` internally. * * @method Phaser.Game#destroy * @since 3.0.0 * * @param {boolean} removeCanvas - Set to `true` if you would like the parent canvas element removed from the DOM, or `false` to leave it in place. */ destroy: function (removeCanvas) { this.pendingDestroy = true; this.removeCanvas = removeCanvas; }, /** * Destroys this Phaser.Game instance, all global systems, all sub-systems and all Scenes. * * @method Phaser.Game#runDestroy * @private * @since 3.5.0 */ runDestroy: function () { this.events.emit('destroy'); this.events.removeAllListeners(); this.scene.destroy(); if (this.renderer) { this.renderer.destroy(); } if (this.removeCanvas && this.canvas) { CanvasPool.remove(this.canvas); if (this.canvas.parentNode) { this.canvas.parentNode.removeChild(this.canvas); } } this.loop.destroy(); this.pendingDestroy = false; } }); module.exports = Game; /***/ }), /* 535 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var EE = __webpack_require__(9); var PluginCache = __webpack_require__(12); /** * @classdesc * EventEmitter is a Scene Systems plugin compatible version of eventemitter3. * * @class EventEmitter * @memberOf Phaser.Events * @constructor * @since 3.0.0 */ var EventEmitter = new Class({ Extends: EE, initialize: function EventEmitter () { EE.call(this); }, /** * Removes all listeners. * * @method Phaser.Events.EventEmitter#shutdown * @since 3.0.0 */ shutdown: function () { this.removeAllListeners(); }, /** * Removes all listeners. * * @method Phaser.Events.EventEmitter#destroy * @since 3.0.0 */ destroy: function () { this.removeAllListeners(); } }); /** * Return an array listing the events for which the emitter has registered listeners. * * @method Phaser.Events.EventEmitter#eventNames * @since 3.0.0 * * @return {array} */ /** * Return the listeners registered for a given event. * * @method Phaser.Events.EventEmitter#listeners * @since 3.0.0 * * @param {(string|symbol)} event - The event name. * * @return {array} The registered listeners. */ /** * Return the number of listeners listening to a given event. * * @method Phaser.Events.EventEmitter#listenerCount * @since 3.0.0 * * @param {(string|symbol)} event - The event name. * * @return {number} The number of listeners. */ /** * Calls each of the listeners registered for a given event. * * @method Phaser.Events.EventEmitter#emit * @since 3.0.0 * * @param {(string|symbol)} event - The event name. * @param {...*} [args] - Additional arguments that will be passed to the event handler. * * @return {boolean} `true` if the event had listeners, else `false`. */ /** * Add a listener for a given event. * * @method Phaser.Events.EventEmitter#on * @since 3.0.0 * * @param {(string|symbol)} event - The event name. * @param {function} fn - The listener function. * @param {*} [context=this] - The context to invoke the listener with. * * @return {Phaser.Events.EventEmitter} `this`. */ /** * Add a listener for a given event. * * @method Phaser.Events.EventEmitter#addListener * @since 3.0.0 * * @param {(string|symbol)} event - The event name. * @param {function} fn - The listener function. * @param {*} [context=this] - The context to invoke the listener with. * * @return {Phaser.Events.EventEmitter} `this`. */ /** * Add a one-time listener for a given event. * * @method Phaser.Events.EventEmitter#once * @since 3.0.0 * * @param {(string|symbol)} event - The event name. * @param {function} fn - The listener function. * @param {*} [context=this] - The context to invoke the listener with. * * @return {Phaser.Events.EventEmitter} `this`. */ /** * Remove the listeners of a given event. * * @method Phaser.Events.EventEmitter#removeListener * @since 3.0.0 * * @param {(string|symbol)} event - The event name. * @param {function} fn - Only remove the listeners that match this function. * @param {*} context - Only remove the listeners that have this context. * @param {boolean} once - Only remove one-time listeners. * * @return {Phaser.Events.EventEmitter} `this`. */ /** * Remove the listeners of a given event. * * @method Phaser.Events.EventEmitter#off * @since 3.0.0 * * @param {(string|symbol)} event - The event name. * @param {function} fn - Only remove the listeners that match this function. * @param {*} context - Only remove the listeners that have this context. * @param {boolean} once - Only remove one-time listeners. * * @return {Phaser.Events.EventEmitter} `this`. */ /** * Remove all listeners, or those of the specified event. * * @method Phaser.Events.EventEmitter#removeAllListeners * @since 3.0.0 * * @param {(string|symbol)} [event] - The event name. * * @return {Phaser.Events.EventEmitter} `this`. */ PluginCache.register('EventEmitter', EventEmitter, 'events'); module.exports = EventEmitter; /***/ }), /* 536 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Events */ module.exports = { EventEmitter: __webpack_require__(535) }; /***/ }), /* 537 */ /***/ (function(module, exports) { // shim for using process in browser var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it // don't break things. But we need to wrap it in a try catch in case it is // wrapped in strict mode code which doesn't define any globals. It's inside a // function because try/catches deoptimize in certain engines. var cachedSetTimeout; var cachedClearTimeout; function defaultSetTimout() { throw new Error('setTimeout has not been defined'); } function defaultClearTimeout () { throw new Error('clearTimeout has not been defined'); } (function () { try { if (typeof setTimeout === 'function') { cachedSetTimeout = setTimeout; } else { cachedSetTimeout = defaultSetTimout; } } catch (e) { cachedSetTimeout = defaultSetTimout; } try { if (typeof clearTimeout === 'function') { cachedClearTimeout = clearTimeout; } else { cachedClearTimeout = defaultClearTimeout; } } catch (e) { cachedClearTimeout = defaultClearTimeout; } } ()) function runTimeout(fun) { if (cachedSetTimeout === setTimeout) { //normal enviroments in sane situations return setTimeout(fun, 0); } // if setTimeout wasn't available but was latter defined if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { cachedSetTimeout = setTimeout; return setTimeout(fun, 0); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); } catch(e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedSetTimeout.call(null, fun, 0); } catch(e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error return cachedSetTimeout.call(this, fun, 0); } } } function runClearTimeout(marker) { if (cachedClearTimeout === clearTimeout) { //normal enviroments in sane situations return clearTimeout(marker); } // if clearTimeout wasn't available but was latter defined if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { cachedClearTimeout = clearTimeout; return clearTimeout(marker); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); } catch (e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedClearTimeout.call(null, marker); } catch (e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. // Some versions of I.E. have different rules for clearTimeout vs setTimeout return cachedClearTimeout.call(this, marker); } } } var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { if (!draining || !currentQueue) { return; } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); } else { queueIndex = -1; } if (queue.length) { drainQueue(); } } function drainQueue() { if (draining) { return; } var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; runClearTimeout(timeout); } process.nextTick = function (fun) { var args = new Array(arguments.length - 1); if (arguments.length > 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } }; // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.version = ''; // empty string to avoid regexp issues process.versions = {}; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.prependListener = noop; process.prependOnceListener = noop; process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); }; process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; /***/ }), /* 538 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Display.Masks */ module.exports = { BitmapMask: __webpack_require__(214), GeometryMask: __webpack_require__(213) }; /***/ }), /* 539 */, /* 540 */, /* 541 */, /* 542 */, /* 543 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Class = __webpack_require__(0); var DataManager = __webpack_require__(81); var PluginCache = __webpack_require__(12); /** * @classdesc * The Data Component features a means to store pieces of data specific to a Game Object, System or Plugin. * You can then search, query it, and retrieve the data. The parent must either extend EventEmitter, * or have a property called `events` that is an instance of it. * * @class DataManagerPlugin * @extends Phaser.Data.DataManager * @memberOf Phaser.Data * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - A reference to the Scene that this DataManager belongs to. */ var DataManagerPlugin = new Class({ Extends: DataManager, initialize: function DataManagerPlugin (scene) { DataManager.call(this, scene, scene.sys.events); /** * A reference to the Scene that this DataManager belongs to. * * @name Phaser.Data.DataManagerPlugin#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * A reference to the Scene's Systems. * * @name Phaser.Data.DataManagerPlugin#systems * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.systems = scene.sys; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('start', this.start, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Data.DataManagerPlugin#boot * @private * @since 3.5.1 */ boot: function () { this.events = this.systems.events; this.events.once('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.Data.DataManagerPlugin#start * @private * @since 3.5.0 */ start: function () { this.events.once('shutdown', this.shutdown, this); }, /** * 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.Data.DataManagerPlugin#shutdown * @private * @since 3.5.0 */ shutdown: function () { this.systems.events.off('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.Data.DataManagerPlugin#destroy * @since 3.5.0 */ destroy: function () { DataManager.prototype.destroy.call(this); this.events.off('start', this.start, this); this.scene = null; this.systems = null; } }); PluginCache.register('DataManagerPlugin', DataManagerPlugin, 'data'); module.exports = DataManagerPlugin; /***/ }), /* 544 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Data */ module.exports = { DataManager: __webpack_require__(81), DataManagerPlugin: __webpack_require__(543) }; /***/ }), /* 545 */, /* 546 */, /* 547 */, /* 548 */, /* 549 */, /* 550 */, /* 551 */, /* 552 */, /* 553 */, /* 554 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObject = __webpack_require__(2); /** * Renders this Game Object with the Canvas Renderer to the given Camera. * The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera. * This method should not be called directly. It is a utility function of the Render module. * * @method Phaser.GameObjects.Sprite#renderCanvas * @since 3.0.0 * @private * * @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer. * @param {Phaser.GameObjects.Sprite} src - The Game Object being rendered in this call. * @param {number} interpolationPercentage - Reserved for future use and custom pipelines. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object. * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested */ var SpriteCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix) { if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id))) { return; } renderer.drawImage(src, camera, parentMatrix); }; module.exports = SpriteCanvasRenderer; /***/ }), /* 555 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var GameObject = __webpack_require__(2); /** * Renders this Game Object with the WebGL Renderer to the given Camera. * The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera. * This method should not be called directly. It is a utility function of the Render module. * * @method Phaser.GameObjects.Sprite#renderWebGL * @since 3.0.0 * @private * * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer. * @param {Phaser.GameObjects.Sprite} src - The Game Object being rendered in this call. * @param {number} interpolationPercentage - Reserved for future use and custom pipelines. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object. * @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested */ var SpriteWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix) { if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id))) { return; } this.pipeline.batchSprite(src, camera, parentMatrix); }; module.exports = SpriteWebGLRenderer; /***/ }), /* 556 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var renderWebGL = __webpack_require__(3); var renderCanvas = __webpack_require__(3); if (true) { renderWebGL = __webpack_require__(555); } if (true) { renderCanvas = __webpack_require__(554); } module.exports = { renderWebGL: renderWebGL, renderCanvas: renderCanvas }; /***/ }), /* 557 */, /* 558 */, /* 559 */, /* 560 */, /* 561 */, /* 562 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Camera = __webpack_require__(123); var Class = __webpack_require__(0); var GetFastValue = __webpack_require__(1); var PluginCache = __webpack_require__(12); var RectangleContains = __webpack_require__(31); /** * @typedef {object} InputJSONCameraObject * * @property {string} [name=''] - [description] * @property {integer} [x=0] - [description] * @property {integer} [y=0] - [description] * @property {integer} [width] - [description] * @property {integer} [height] - [description] * @property {float} [zoom=1] - [description] * @property {float} [rotation=0] - [description] * @property {boolean} [roundPixels=false] - [description] * @property {float} [scrollX=0] - [description] * @property {float} [scrollY=0] - [description] * @property {(false|string)} [backgroundColor=false] - [description] * @property {?object} [bounds] - [description] * @property {number} [bounds.x=0] - [description] * @property {number} [bounds.y=0] - [description] * @property {number} [bounds.width] - [description] * @property {number} [bounds.height] - [description] */ /** * @classdesc * [description] * * @class CameraManager * @memberOf Phaser.Cameras.Scene2D * @constructor * @since 3.0.0 * * @param {Phaser.Scene} scene - The Scene that owns the Camera Manager plugin. */ var CameraManager = new Class({ initialize: function CameraManager (scene) { /** * The Scene that owns the Camera Manager plugin. * * @name Phaser.Cameras.Scene2D.CameraManager#scene * @type {Phaser.Scene} * @since 3.0.0 */ this.scene = scene; /** * A reference to the Scene.Systems handler for the Scene that owns the Camera Manager. * * @name Phaser.Cameras.Scene2D.CameraManager#systems * @type {Phaser.Scenes.Systems} * @since 3.0.0 */ this.systems = scene.sys; /** * The current Camera ID. * * @name Phaser.Cameras.Scene2D.CameraManager#currentCameraId * @type {number} * @default 1 * @readOnly * @since 3.0.0 */ this.currentCameraId = 1; /** * An Array of the Camera objects being managed by this Camera Manager. * * @name Phaser.Cameras.Scene2D.CameraManager#cameras * @type {Phaser.Cameras.Scene2D.Camera[]} * @since 3.0.0 */ this.cameras = []; /** * A pool of Camera objects available to be used by the Camera Manager. * * @name Phaser.Cameras.Scene2D.CameraManager#cameraPool * @type {Phaser.Cameras.Scene2D.Camera[]} * @since 3.0.0 */ this.cameraPool = []; /** * The default Camera in the Camera Manager. * * @name Phaser.Cameras.Scene2D.CameraManager#main * @type {Phaser.Cameras.Scene2D.Camera} * @since 3.0.0 */ this.main; /** * This scale affects all cameras. It's used by Scale Manager. * * @name Phaser.Cameras.Scene2D.CameraManager#baseScale * @type {number} * @since 3.0.0 */ this.baseScale = 1; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('start', this.start, this); }, /** * This method is called automatically, only once, when the Scene is first created. * Do not invoke it directly. * * @method Phaser.Cameras.Scene2D.CameraManager#boot * @private * @since 3.5.1 */ boot: function () { var sys = this.systems; if (sys.settings.cameras) { // We have cameras to create this.fromJSON(sys.settings.cameras); } else { // Make one this.add(); } this.main = this.cameras[0]; this.systems.events.once('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.Cameras.Scene2D.CameraManager#start * @private * @since 3.5.0 */ start: function () { if (!this.main) { this.boot(); } var eventEmitter = this.systems.events; eventEmitter.on('update', this.update, this); eventEmitter.once('shutdown', this.shutdown, this); }, /** * [description] * * @method Phaser.Cameras.Scene2D.CameraManager#add * @since 3.0.0 * * @param {number} [x=0] - [description] * @param {number} [y=0] - [description] * @param {number} [width] - [description] * @param {number} [height] - [description] * @param {boolean} [makeMain=false] - [description] * @param {string} [name=''] - [description] * * @return {Phaser.Cameras.Scene2D.Camera} [description] */ add: function (x, y, width, height, makeMain, name) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = this.scene.sys.game.config.width; } if (height === undefined) { height = this.scene.sys.game.config.height; } if (makeMain === undefined) { makeMain = false; } if (name === undefined) { name = ''; } var camera = null; if (this.cameraPool.length > 0) { camera = this.cameraPool.pop(); camera.setViewport(x, y, width, height); } else { camera = new Camera(x, y, width, height); } camera.setName(name); camera.setScene(this.scene); this.cameras.push(camera); if (makeMain) { this.main = camera; } camera._id = this.currentCameraId; this.currentCameraId = this.currentCameraId << 1; return camera; }, /** * [description] * * @method Phaser.Cameras.Scene2D.CameraManager#addExisting * @since 3.0.0 * * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] * * @return {Phaser.Cameras.Scene2D.Camera} [description] */ addExisting: function (camera) { var index = this.cameras.indexOf(camera); var poolIndex = this.cameraPool.indexOf(camera); if (index < 0 && poolIndex >= 0) { this.cameras.push(camera); this.cameraPool.slice(poolIndex, 1); return camera; } return null; }, /** * [description] * * @method Phaser.Cameras.Scene2D.CameraManager#fromJSON * @since 3.0.0 * * @param {(InputJSONCameraObject|InputJSONCameraObject[])} config - [description] * * @return {Phaser.Cameras.Scene2D.CameraManager} [description] */ fromJSON: function (config) { if (!Array.isArray(config)) { config = [ config ]; } var gameWidth = this.scene.sys.game.config.width; var gameHeight = this.scene.sys.game.config.height; for (var i = 0; i < config.length; i++) { var cameraConfig = config[i]; var x = GetFastValue(cameraConfig, 'x', 0); var y = GetFastValue(cameraConfig, 'y', 0); var width = GetFastValue(cameraConfig, 'width', gameWidth); var height = GetFastValue(cameraConfig, 'height', gameHeight); var camera = this.add(x, y, width, height); // Direct properties camera.name = GetFastValue(cameraConfig, 'name', ''); camera.zoom = GetFastValue(cameraConfig, 'zoom', 1); camera.rotation = GetFastValue(cameraConfig, 'rotation', 0); camera.scrollX = GetFastValue(cameraConfig, 'scrollX', 0); camera.scrollY = GetFastValue(cameraConfig, 'scrollY', 0); camera.roundPixels = GetFastValue(cameraConfig, 'roundPixels', false); camera.visible = GetFastValue(cameraConfig, 'visible', true); // Background Color var backgroundColor = GetFastValue(cameraConfig, 'backgroundColor', false); if (backgroundColor) { camera.setBackgroundColor(backgroundColor); } // Bounds var boundsConfig = GetFastValue(cameraConfig, 'bounds', null); if (boundsConfig) { var bx = GetFastValue(boundsConfig, 'x', 0); var by = GetFastValue(boundsConfig, 'y', 0); var bwidth = GetFastValue(boundsConfig, 'width', gameWidth); var bheight = GetFastValue(boundsConfig, 'height', gameHeight); camera.setBounds(bx, by, bwidth, bheight); } } return this; }, /** * [description] * * @method Phaser.Cameras.Scene2D.CameraManager#getCamera * @since 3.0.0 * * @param {string} name - [description] * * @return {Phaser.Cameras.Scene2D.Camera} [description] */ getCamera: function (name) { for (var i = 0; i < this.cameras.length; i++) { if (this.cameras[i].name === name) { return this.cameras[i]; } } return null; }, /** * Returns an array of all cameras below the given Pointer. * * The first camera in the array is the top-most camera in the camera list. * * @method Phaser.Cameras.Scene2D.CameraManager#getCamerasBelowPointer * @since 3.10.0 * * @param {Phaser.Input.Pointer} pointer - The Pointer to check against. * * @return {Phaser.Cameras.Scene2D.Camera[]} An array of cameras below the Pointer. */ getCamerasBelowPointer: function (pointer) { var cameras = this.cameras; var x = pointer.x; var y = pointer.y; var output = []; for (var i = 0; i < cameras.length; i++) { var camera = cameras[i]; if (camera.visible && camera.inputEnabled && RectangleContains(camera, x, y)) { // So the top-most camera is at the top of the search array output.unshift(camera); } } return output; }, /** * [description] * * @method Phaser.Cameras.Scene2D.CameraManager#remove * @since 3.0.0 * * @param {Phaser.Cameras.Scene2D.Camera} camera - [description] */ remove: function (camera) { var cameraIndex = this.cameras.indexOf(camera); if (cameraIndex >= 0 && this.cameras.length > 1) { this.cameraPool.push(this.cameras[cameraIndex]); this.cameras.splice(cameraIndex, 1); if (this.main === camera) { this.main = this.cameras[0]; } } }, /** * [description] * * @method Phaser.Cameras.Scene2D.CameraManager#render * @since 3.0.0 * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The Renderer that will render the children to this camera. * @param {Phaser.GameObjects.GameObject[]} children - An array of renderable Game Objects. * @param {number} interpolation - Interpolation value. Reserved for future use. */ render: function (renderer, children, interpolation) { var cameras = this.cameras; var baseScale = this.baseScale; for (var i = 0, l = cameras.length; i < l; ++i) { var camera = cameras[i]; if (camera.visible) { camera.preRender(baseScale, renderer.config.resolution); renderer.render(this.scene, children, interpolation, camera); } } }, /** * [description] * * @method Phaser.Cameras.Scene2D.CameraManager#resetAll * @since 3.0.0 * * @return {Phaser.Cameras.Scene2D.Camera} [description] */ resetAll: function () { while (this.cameras.length > 0) { this.cameraPool.push(this.cameras.pop()); } this.main = this.add(); return this.main; }, /** * [description] * * @method Phaser.Cameras.Scene2D.CameraManager#update * @since 3.0.0 * * @param {number} timestep - [description] * @param {number} delta - [description] */ update: function (timestep, delta) { for (var i = 0, l = this.cameras.length; i < l; ++i) { this.cameras[i].update(timestep, delta); } }, /** * Resizes all cameras to the given dimensions. * * @method Phaser.Cameras.Scene2D.CameraManager#resize * @since 3.2.0 * * @param {number} width - The new width of the camera. * @param {number} height - The new height of the camera. */ resize: function (width, height) { for (var i = 0, l = this.cameras.length; i < l; ++i) { this.cameras[i].setSize(width, height); } }, /** * 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.Cameras.Scene2D.CameraManager#shutdown * @private * @since 3.0.0 */ shutdown: function () { this.main = undefined; for (var i = 0; i < this.cameras.length; i++) { this.cameras[i].destroy(); } for (i = 0; i < this.cameraPool.length; i++) { this.cameraPool[i].destroy(); } this.cameras = []; this.cameraPool = []; var eventEmitter = this.systems.events; eventEmitter.off('update', this.update, this); eventEmitter.off('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.Cameras.Scene2D.CameraManager#destroy * @private * @since 3.0.0 */ destroy: function () { this.shutdown(); this.scene.sys.events.off('start', this.start, this); this.scene = null; this.systems = null; } }); PluginCache.register('CameraManager', CameraManager, 'cameras'); module.exports = CameraManager; /***/ }), /* 563 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clamp = __webpack_require__(23); var Class = __webpack_require__(0); var Vector2 = __webpack_require__(6); /** * @classdesc * A Camera Shake effect. * * This effect will shake the camera viewport by a random amount, bounded by the specified intensity, each frame. * * Only the camera viewport is moved. None of the objects it is displaying are impacted, i.e. their positions do * not change. * * The effect will dispatch several events on the Camera itself and you can also specify an `onUpdate` callback, * which is invoked each frame for the duration of the effect if required. * * @class Shake * @memberOf Phaser.Cameras.Scene2D.Effects * @constructor * @since 3.5.0 * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ var Shake = new Class({ initialize: function Shake (camera) { /** * The Camera this effect belongs to. * * @name Phaser.Cameras.Scene2D.Effects.Shake#camera * @type {Phaser.Cameras.Scene2D.Camera} * @readOnly * @since 3.5.0 */ this.camera = camera; /** * Is this effect actively running? * * @name Phaser.Cameras.Scene2D.Effects.Shake#isRunning * @type {boolean} * @readOnly * @default false * @since 3.5.0 */ this.isRunning = false; /** * The duration of the effect, in milliseconds. * * @name Phaser.Cameras.Scene2D.Effects.Shake#duration * @type {integer} * @readOnly * @default 0 * @since 3.5.0 */ this.duration = 0; /** * The intensity of the effect. Use small float values. The default when the effect starts is 0.05. * This is a Vector2 object, allowing you to control the shake intensity independently across x and y. * You can modify this value while the effect is active to create more varied shake effects. * * @name Phaser.Cameras.Scene2D.Effects.Shake#intensity * @type {Phaser.Math.Vector2} * @since 3.5.0 */ this.intensity = new Vector2(); /** * If this effect is running this holds the current percentage of the progress, a value between 0 and 1. * * @name Phaser.Cameras.Scene2D.Effects.Shake#progress * @type {float} * @since 3.5.0 */ this.progress = 0; /** * Effect elapsed timer. * * @name Phaser.Cameras.Scene2D.Effects.Shake#_elapsed * @type {number} * @private * @since 3.5.0 */ this._elapsed = 0; /** * How much to offset the camera by horizontally. * * @name Phaser.Cameras.Scene2D.Effects.Shake#_offsetX * @type {number} * @private * @default 0 * @since 3.0.0 */ this._offsetX = 0; /** * How much to offset the camera by vertically. * * @name Phaser.Cameras.Scene2D.Effects.Shake#_offsetY * @type {number} * @private * @default 0 * @since 3.0.0 */ this._offsetY = 0; /** * @callback CameraShakeCallback * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera on which the effect is running. * @param {float} progress - The progress of the effect. A value between 0 and 1. */ /** * This callback is invoked every frame for the duration of the effect. * * @name Phaser.Cameras.Scene2D.Effects.Shake#_onUpdate * @type {?CameraShakeCallback} * @private * @default null * @since 3.5.0 */ this._onUpdate; /** * On Complete callback scope. * * @name Phaser.Cameras.Scene2D.Effects.Shake#_onUpdateScope * @type {any} * @private * @since 3.5.0 */ this._onUpdateScope; }, /** * This event is fired when the shake effect begins to run on a camera. * * @event CameraShakeStartEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on. * @param {Phaser.Cameras.Scene2D.Effects.Shake} effect - A reference to the effect instance. * @param {integer} duration - The duration of the effect. * @param {float} intensity - The intensity of the effect. */ /** * This event is fired when the shake effect completes. * * @event CameraShakeCompleteEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on. * @param {Phaser.Cameras.Scene2D.Effects.Shake} effect - A reference to the effect instance. */ /** * Shakes the Camera by the given intensity over the duration specified. * * @method Phaser.Cameras.Scene2D.Effects.Shake#start * @fires CameraShakeStartEvent * @fires CameraShakeCompleteEvent * @since 3.5.0 * * @param {integer} [duration=100] - The duration of the effect in milliseconds. * @param {number} [intensity=0.05] - The intensity of the shake. * @param {boolean} [force=false] - Force the shake effect to start immediately, even if already running. * @param {CameraShakeCallback} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ start: function (duration, intensity, force, callback, context) { if (duration === undefined) { duration = 100; } if (intensity === undefined) { intensity = 0.05; } if (force === undefined) { force = false; } if (callback === undefined) { callback = null; } if (context === undefined) { context = this.camera.scene; } if (!force && this.isRunning) { return this.camera; } this.isRunning = true; this.duration = duration; this.progress = 0; if (typeof intensity === 'number') { this.intensity.set(intensity); } else { this.intensity.set(intensity.x, intensity.y); } this._elapsed = 0; this._offsetX = 0; this._offsetY = 0; this._onUpdate = callback; this._onUpdateScope = context; this.camera.emit('camerashakestart', this.camera, this, duration, intensity); return this.camera; }, /** * The pre-render step for this effect. Called automatically by the Camera. * * @method Phaser.Cameras.Scene2D.Effects.Shake#preRender * @since 3.5.0 */ preRender: function () { if (this.isRunning) { this.camera.matrix.translate(this._offsetX, this._offsetY); } }, /** * The main update loop for this effect. Called automatically by the Camera. * * @method Phaser.Cameras.Scene2D.Effects.Shake#update * @since 3.5.0 * * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ update: function (time, delta) { if (!this.isRunning) { return; } this._elapsed += delta; this.progress = Clamp(this._elapsed / this.duration, 0, 1); if (this._onUpdate) { this._onUpdate.call(this._onUpdateScope, this.camera, this.progress); } if (this._elapsed < this.duration) { var intensity = this.intensity; var width = this.camera.width; var height = this.camera.height; var zoom = this.camera.zoom; this._offsetX = (Math.random() * intensity.x * width * 2 - intensity.x * width) * zoom; this._offsetY = (Math.random() * intensity.y * height * 2 - intensity.y * height) * zoom; if (this.camera.roundPixels) { this._offsetX |= 0; this._offsetY |= 0; } } else { this.effectComplete(); } }, /** * Called internally when the effect completes. * * @method Phaser.Cameras.Scene2D.Effects.Shake#effectComplete * @since 3.5.0 */ effectComplete: function () { this._offsetX = 0; this._offsetY = 0; this._onUpdate = null; this._onUpdateScope = null; this.isRunning = false; this.camera.emit('camerashakecomplete', this.camera, this); }, /** * Resets this camera effect. * If it was previously running, it stops instantly without calling its onComplete callback or emitting an event. * * @method Phaser.Cameras.Scene2D.Effects.Shake#reset * @since 3.5.0 */ reset: function () { this.isRunning = false; this._offsetX = 0; this._offsetY = 0; this._onUpdate = null; this._onUpdateScope = null; }, /** * Destroys this effect, releasing it from the Camera. * * @method Phaser.Cameras.Scene2D.Effects.Shake#destroy * @since 3.5.0 */ destroy: function () { this.reset(); this.camera = null; this.intensity = null; } }); module.exports = Shake; /***/ }), /* 564 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clamp = __webpack_require__(23); var Class = __webpack_require__(0); /** * @classdesc * A Camera Flash effect. * * This effect will flash the camera viewport to the given color, over the duration specified. * * Only the camera viewport is flashed. None of the objects it is displaying are impacted, i.e. their colors do * not change. * * The effect will dispatch several events on the Camera itself and you can also specify an `onUpdate` callback, * which is invoked each frame for the duration of the effect, if required. * * @class Flash * @memberOf Phaser.Cameras.Scene2D.Effects * @constructor * @since 3.5.0 * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ var Flash = new Class({ initialize: function Flash (camera) { /** * The Camera this effect belongs to. * * @name Phaser.Cameras.Scene2D.Effects.Flash#camera * @type {Phaser.Cameras.Scene2D.Camera} * @readOnly * @since 3.5.0 */ this.camera = camera; /** * Is this effect actively running? * * @name Phaser.Cameras.Scene2D.Effects.Flash#isRunning * @type {boolean} * @readOnly * @default false * @since 3.5.0 */ this.isRunning = false; /** * The duration of the effect, in milliseconds. * * @name Phaser.Cameras.Scene2D.Effects.Flash#duration * @type {integer} * @readOnly * @default 0 * @since 3.5.0 */ this.duration = 0; /** * The value of the red color channel the camera will use for the fade effect. * A value between 0 and 255. * * @name Phaser.Cameras.Scene2D.Effects.Flash#red * @type {integer} * @private * @since 3.5.0 */ this.red = 0; /** * The value of the green color channel the camera will use for the fade effect. * A value between 0 and 255. * * @name Phaser.Cameras.Scene2D.Effects.Flash#green * @type {integer} * @private * @since 3.5.0 */ this.green = 0; /** * The value of the blue color channel the camera will use for the fade effect. * A value between 0 and 255. * * @name Phaser.Cameras.Scene2D.Effects.Flash#blue * @type {integer} * @private * @since 3.5.0 */ this.blue = 0; /** * The value of the alpha channel used during the fade effect. * A value between 0 and 1. * * @name Phaser.Cameras.Scene2D.Effects.Flash#alpha * @type {float} * @private * @since 3.5.0 */ this.alpha = 0; /** * If this effect is running this holds the current percentage of the progress, a value between 0 and 1. * * @name Phaser.Cameras.Scene2D.Effects.Flash#progress * @type {float} * @since 3.5.0 */ this.progress = 0; /** * Effect elapsed timer. * * @name Phaser.Cameras.Scene2D.Effects.Flash#_elapsed * @type {number} * @private * @since 3.5.0 */ this._elapsed = 0; /** * @callback CameraFlashCallback * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera on which the effect is running. * @param {float} progress - The progress of the effect. A value between 0 and 1. */ /** * This callback is invoked every frame for the duration of the effect. * * @name Phaser.Cameras.Scene2D.Effects.Flash#_onUpdate * @type {?CameraFlashCallback} * @private * @default null * @since 3.5.0 */ this._onUpdate; /** * On Complete callback scope. * * @name Phaser.Cameras.Scene2D.Effects.Flash#_onUpdateScope * @type {any} * @private * @since 3.5.0 */ this._onUpdateScope; }, /** * This event is fired when the flash effect begins to run on a camera. * * @event CameraFlashStartEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on. * @param {Phaser.Cameras.Scene2D.Effects.Flash} effect - A reference to the effect instance. * @param {integer} duration - The duration of the effect. * @param {integer} red - The red color channel value. * @param {integer} green - The green color channel value. * @param {integer} blue - The blue color channel value. */ /** * This event is fired when the flash effect completes. * * @event CameraFlashCompleteEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on. * @param {Phaser.Cameras.Scene2D.Effects.Flash} effect - A reference to the effect instance. */ /** * Flashes the Camera to or from the given color over the duration specified. * * @method Phaser.Cameras.Scene2D.Effects.Flash#start * @fires CameraFlashStartEvent * @fires CameraFlashCompleteEvent * @since 3.5.0 * * @param {integer} [duration=250] - The duration of the effect in milliseconds. * @param {integer} [red=255] - The amount to fade the red channel towards. A value between 0 and 255. * @param {integer} [green=255] - The amount to fade the green channel towards. A value between 0 and 255. * @param {integer} [blue=255] - The amount to fade the blue channel towards. A value between 0 and 255. * @param {boolean} [force=false] - Force the effect to start immediately, even if already running. * @param {CameraFlashCallback} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ start: function (duration, red, green, blue, force, callback, context) { if (duration === undefined) { duration = 250; } if (red === undefined) { red = 255; } if (green === undefined) { green = 255; } if (blue === undefined) { blue = 255; } if (force === undefined) { force = false; } if (callback === undefined) { callback = null; } if (context === undefined) { context = this.camera.scene; } if (!force && this.isRunning) { return this.camera; } this.isRunning = true; this.duration = duration; this.progress = 0; this.red = red; this.green = green; this.blue = blue; this.alpha = 1; this._elapsed = 0; this._onUpdate = callback; this._onUpdateScope = context; this.camera.emit('cameraflashstart', this.camera, this, duration, red, green, blue); return this.camera; }, /** * The main update loop for this effect. Called automatically by the Camera. * * @method Phaser.Cameras.Scene2D.Effects.Flash#update * @since 3.5.0 * * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ update: function (time, delta) { if (!this.isRunning) { return; } this._elapsed += delta; this.progress = Clamp(this._elapsed / this.duration, 0, 1); if (this._onUpdate) { this._onUpdate.call(this._onUpdateScope, this.camera, this.progress); } if (this._elapsed < this.duration) { this.alpha = 1 - this.progress; } else { this.effectComplete(); } }, /** * Called internally by the Canvas Renderer. * * @method Phaser.Cameras.Scene2D.Effects.Flash#postRenderCanvas * @since 3.5.0 * * @param {CanvasRenderingContext2D} ctx - The Canvas context to render to. * * @return {boolean} `true` if the effect drew to the renderer, otherwise `false`. */ postRenderCanvas: function (ctx) { if (!this.isRunning) { return false; } var camera = this.camera; ctx.fillStyle = 'rgba(' + this.red + ',' + this.green + ',' + this.blue + ',' + this.alpha + ')'; ctx.fillRect(camera.x, camera.y, camera.width, camera.height); return true; }, /** * Called internally by the WebGL Renderer. * * @method Phaser.Cameras.Scene2D.Effects.Flash#postRenderWebGL * @since 3.5.0 * * @param {Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline} pipeline - The WebGL Pipeline to render to. * @param {function} getTintFunction - A function that will return the gl safe tint colors. * * @return {boolean} `true` if the effect drew to the renderer, otherwise `false`. */ postRenderWebGL: function (pipeline, getTintFunction) { if (!this.isRunning) { return false; } var camera = this.camera; var red = this.red / 255; var blue = this.blue / 255; var green = this.green / 255; pipeline.batchFillRect( 0, 0, 1, 1, 0, camera.x, camera.y, camera.width, camera.height, getTintFunction(red, green, blue, 1), this.alpha, 1, 0, 0, 1, 0, 0, [ 1, 0, 0, 1, 0, 0 ] ); return true; }, /** * Called internally when the effect completes. * * @method Phaser.Cameras.Scene2D.Effects.Flash#effectComplete * @since 3.5.0 */ effectComplete: function () { this._onUpdate = null; this._onUpdateScope = null; this.isRunning = false; this.camera.emit('cameraflashcomplete', this.camera, this); }, /** * Resets this camera effect. * If it was previously running, it stops instantly without calling its onComplete callback or emitting an event. * * @method Phaser.Cameras.Scene2D.Effects.Flash#reset * @since 3.5.0 */ reset: function () { this.isRunning = false; this._onUpdate = null; this._onUpdateScope = null; }, /** * Destroys this effect, releasing it from the Camera. * * @method Phaser.Cameras.Scene2D.Effects.Flash#destroy * @since 3.5.0 */ destroy: function () { this.reset(); this.camera = null; } }); module.exports = Flash; /***/ }), /* 565 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clamp = __webpack_require__(23); var Class = __webpack_require__(0); /** * @classdesc * A Camera Fade effect. * * This effect will fade the camera viewport to the given color, over the duration specified. * * Only the camera viewport is faded. None of the objects it is displaying are impacted, i.e. their colors do * not change. * * The effect will dispatch several events on the Camera itself and you can also specify an `onUpdate` callback, * which is invoked each frame for the duration of the effect, if required. * * @class Fade * @memberOf Phaser.Cameras.Scene2D.Effects * @constructor * @since 3.5.0 * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ var Fade = new Class({ initialize: function Fade (camera) { /** * The Camera this effect belongs to. * * @name Phaser.Cameras.Scene2D.Effects.Fade#camera * @type {Phaser.Cameras.Scene2D.Camera} * @readOnly * @since 3.5.0 */ this.camera = camera; /** * Is this effect actively running? * * @name Phaser.Cameras.Scene2D.Effects.Fade#isRunning * @type {boolean} * @readOnly * @default false * @since 3.5.0 */ this.isRunning = false; /** * Has this effect finished running? * * This is different from `isRunning` because it remains set to `true` when the effect is over, * until the effect is either reset or started again. * * @name Phaser.Cameras.Scene2D.Effects.Fade#isComplete * @type {boolean} * @readOnly * @default false * @since 3.5.0 */ this.isComplete = false; /** * The direction of the fade. * `true` = fade out (transparent to color), `false` = fade in (color to transparent) * * @name Phaser.Cameras.Scene2D.Effects.Fade#direction * @type {boolean} * @readOnly * @since 3.5.0 */ this.direction = true; /** * The duration of the effect, in milliseconds. * * @name Phaser.Cameras.Scene2D.Effects.Fade#duration * @type {integer} * @readOnly * @default 0 * @since 3.5.0 */ this.duration = 0; /** * The value of the red color channel the camera will use for the fade effect. * A value between 0 and 255. * * @name Phaser.Cameras.Scene2D.Effects.Fade#red * @type {integer} * @private * @since 3.5.0 */ this.red = 0; /** * The value of the green color channel the camera will use for the fade effect. * A value between 0 and 255. * * @name Phaser.Cameras.Scene2D.Effects.Fade#green * @type {integer} * @private * @since 3.5.0 */ this.green = 0; /** * The value of the blue color channel the camera will use for the fade effect. * A value between 0 and 255. * * @name Phaser.Cameras.Scene2D.Effects.Fade#blue * @type {integer} * @private * @since 3.5.0 */ this.blue = 0; /** * The value of the alpha channel used during the fade effect. * A value between 0 and 1. * * @name Phaser.Cameras.Scene2D.Effects.Fade#alpha * @type {float} * @private * @since 3.5.0 */ this.alpha = 0; /** * If this effect is running this holds the current percentage of the progress, a value between 0 and 1. * * @name Phaser.Cameras.Scene2D.Effects.Fade#progress * @type {float} * @since 3.5.0 */ this.progress = 0; /** * Effect elapsed timer. * * @name Phaser.Cameras.Scene2D.Effects.Fade#_elapsed * @type {number} * @private * @since 3.5.0 */ this._elapsed = 0; /** * @callback CameraFadeCallback * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera on which the effect is running. * @param {float} progress - The progress of the effect. A value between 0 and 1. */ /** * This callback is invoked every frame for the duration of the effect. * * @name Phaser.Cameras.Scene2D.Effects.Fade#_onUpdate * @type {?CameraFadeCallback} * @private * @default null * @since 3.5.0 */ this._onUpdate; /** * On Complete callback scope. * * @name Phaser.Cameras.Scene2D.Effects.Fade#_onUpdateScope * @type {any} * @private * @since 3.5.0 */ this._onUpdateScope; }, /** * This event is fired when the fade in effect begins to run on a camera. * * @event CameraFadeInStartEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on. * @param {Phaser.Cameras.Scene2D.Effects.Fade} effect - A reference to the effect instance. * @param {integer} duration - The duration of the effect. * @param {integer} red - The red color channel value. * @param {integer} green - The green color channel value. * @param {integer} blue - The blue color channel value. */ /** * This event is fired when the fade out effect begins to run on a camera. * * @event CameraFadeOutStartEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on. * @param {Phaser.Cameras.Scene2D.Effects.Fade} effect - A reference to the effect instance. * @param {integer} duration - The duration of the effect. * @param {integer} red - The red color channel value. * @param {integer} green - The green color channel value. * @param {integer} blue - The blue color channel value. */ /** * This event is fired when the fade in effect completes. * * @event CameraFadeInCompleteEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on. * @param {Phaser.Cameras.Scene2D.Effects.Fade} effect - A reference to the effect instance. */ /** * This event is fired when the fade out effect completes. * * @event CameraFadeOutCompleteEvent * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on. * @param {Phaser.Cameras.Scene2D.Effects.Fade} effect - A reference to the effect instance. */ /** * Fades the Camera to or from the given color over the duration specified. * * @method Phaser.Cameras.Scene2D.Effects.Fade#start * @fires CameraFadeInStartEvent * @fires CameraFadeInCompleteEvent * @fires CameraFadeOutStartEvent * @fires CameraFadeOutCompleteEvent * @since 3.5.0 * * @param {boolean} [direction=true] - The direction of the fade. `true` = fade out (transparent to color), `false` = fade in (color to transparent) * @param {integer} [duration=1000] - The duration of the effect in milliseconds. * @param {integer} [red=0] - The amount to fade the red channel towards. A value between 0 and 255. * @param {integer} [green=0] - The amount to fade the green channel towards. A value between 0 and 255. * @param {integer} [blue=0] - The amount to fade the blue channel towards. A value between 0 and 255. * @param {boolean} [force=false] - Force the effect to start immediately, even if already running. * @param {CameraFadeCallback} [callback] - This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ start: function (direction, duration, red, green, blue, force, callback, context) { if (direction === undefined) { direction = true; } if (duration === undefined) { duration = 1000; } if (red === undefined) { red = 0; } if (green === undefined) { green = 0; } if (blue === undefined) { blue = 0; } if (force === undefined) { force = false; } if (callback === undefined) { callback = null; } if (context === undefined) { context = this.camera.scene; } if (!force && this.isRunning) { return this.camera; } this.isRunning = true; this.isComplete = false; this.duration = duration; this.direction = direction; this.progress = 0; this.red = red; this.green = green; this.blue = blue; this.alpha = (direction) ? Number.MIN_VALUE : 1; this._elapsed = 0; this._onUpdate = callback; this._onUpdateScope = context; var eventName = (direction) ? 'camerafadeoutstart' : 'camerafadeinstart'; this.camera.emit(eventName, this.camera, this, duration, red, green, blue); return this.camera; }, /** * The main update loop for this effect. Called automatically by the Camera. * * @method Phaser.Cameras.Scene2D.Effects.Fade#update * @since 3.5.0 * * @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ update: function (time, delta) { if (!this.isRunning) { return; } this._elapsed += delta; this.progress = Clamp(this._elapsed / this.duration, 0, 1); if (this._onUpdate) { this._onUpdate.call(this._onUpdateScope, this.camera, this.progress); } if (this._elapsed < this.duration) { this.alpha = (this.direction) ? this.progress : 1 - this.progress; } else { this.effectComplete(); } }, /** * Called internally by the Canvas Renderer. * * @method Phaser.Cameras.Scene2D.Effects.Fade#postRenderCanvas * @since 3.5.0 * * @param {CanvasRenderingContext2D} ctx - The Canvas context to render to. * * @return {boolean} `true` if the effect drew to the renderer, otherwise `false`. */ postRenderCanvas: function (ctx) { if (!this.isRunning && !this.isComplete) { return false; } var camera = this.camera; ctx.fillStyle = 'rgba(' + this.red + ',' + this.green + ',' + this.blue + ',' + this.alpha + ')'; ctx.fillRect(camera.x, camera.y, camera.width, camera.height); return true; }, /** * Called internally by the WebGL Renderer. * * @method Phaser.Cameras.Scene2D.Effects.Fade#postRenderWebGL * @since 3.5.0 * * @param {Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline} pipeline - The WebGL Pipeline to render to. * @param {function} getTintFunction - A function that will return the gl safe tint colors. * * @return {boolean} `true` if the effect drew to the renderer, otherwise `false`. */ postRenderWebGL: function (pipeline, getTintFunction) { if (!this.isRunning && !this.isComplete) { return false; } var camera = this.camera; var red = this.red / 255; var blue = this.blue / 255; var green = this.green / 255; pipeline.batchFillRect( 0, 0, 1, 1, 0, camera.x, camera.y, camera.width, camera.height, getTintFunction(red, green, blue, 1), this.alpha, 1, 0, 0, 1, 0, 0, [ 1, 0, 0, 1, 0, 0 ] ); return true; }, /** * Called internally when the effect completes. * * @method Phaser.Cameras.Scene2D.Effects.Fade#effectComplete * @since 3.5.0 */ effectComplete: function () { this._onUpdate = null; this._onUpdateScope = null; this.isRunning = false; this.isComplete = true; var eventName = (this.direction) ? 'camerafadeoutcomplete' : 'camerafadeincomplete'; this.camera.emit(eventName, this.camera, this); }, /** * Resets this camera effect. * If it was previously running, it stops instantly without calling its onComplete callback or emitting an event. * * @method Phaser.Cameras.Scene2D.Effects.Fade#reset * @since 3.5.0 */ reset: function () { this.isRunning = false; this.isComplete = false; this._onUpdate = null; this._onUpdateScope = null; }, /** * Destroys this effect, releasing it from the Camera. * * @method Phaser.Cameras.Scene2D.Effects.Fade#destroy * @since 3.5.0 */ destroy: function () { this.reset(); this.camera = null; } }); module.exports = Fade; /***/ }), /* 566 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Cameras.Scene2D */ module.exports = { Camera: __webpack_require__(123), CameraManager: __webpack_require__(562), Effects: __webpack_require__(204) }; /***/ }), /* 567 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Cache */ module.exports = { BaseCache: __webpack_require__(206), CacheManager: __webpack_require__(205) }; /***/ }), /* 568 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Animations */ module.exports = { Animation: __webpack_require__(210), AnimationFrame: __webpack_require__(208), AnimationManager: __webpack_require__(207) }; /***/ }), /* 569 */, /* 570 */, /* 571 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // bitmask flag for GameObject.renderMask var _FLAG = 1; // 0001 /** * Provides methods used for setting the visibility of a Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.Visible * @since 3.0.0 */ var Visible = { /** * Private internal value. Holds the visible value. * * @name Phaser.GameObjects.Components.Visible#_visible * @type {boolean} * @private * @default true * @since 3.0.0 */ _visible: true, /** * The visible state of the Game Object. * * An invisible Game Object will skip rendering, but will still process update logic. * * @name Phaser.GameObjects.Components.Visible#visible * @type {boolean} * @since 3.0.0 */ visible: { get: function () { return this._visible; }, set: function (value) { if (value) { this._visible = true; this.renderFlags |= _FLAG; } else { this._visible = false; this.renderFlags &= ~_FLAG; } } }, /** * Sets the visibility of this Game Object. * * An invisible Game Object will skip rendering, but will still process update logic. * * @method Phaser.GameObjects.Components.Visible#setVisible * @since 3.0.0 * * @param {boolean} value - The visible state of the Game Object. * * @return {this} This Game Object instance. */ setVisible: function (value) { this.visible = value; return this; } }; module.exports = Visible; /***/ }), /* 572 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var MATH_CONST = __webpack_require__(16); var TransformMatrix = __webpack_require__(64); var WrapAngle = __webpack_require__(212); var WrapAngleDegrees = __webpack_require__(211); // global bitmask flag for GameObject.renderMask (used by Scale) var _FLAG = 4; // 0100 /** * Provides methods used for getting and setting the position, scale and rotation of a Game Object. * * @name Phaser.GameObjects.Components.Transform * @since 3.0.0 */ var Transform = { /** * Private internal value. Holds the horizontal scale value. * * @name Phaser.GameObjects.Components.Transform#_scaleX * @type {float} * @private * @default 1 * @since 3.0.0 */ _scaleX: 1, /** * Private internal value. Holds the vertical scale value. * * @name Phaser.GameObjects.Components.Transform#_scaleY * @type {float} * @private * @default 1 * @since 3.0.0 */ _scaleY: 1, /** * Private internal value. Holds the rotation value in radians. * * @name Phaser.GameObjects.Components.Transform#_rotation * @type {float} * @private * @default 0 * @since 3.0.0 */ _rotation: 0, /** * The x position of this Game Object. * * @name Phaser.GameObjects.Components.Transform#x * @type {number} * @default 0 * @since 3.0.0 */ x: 0, /** * The y position of this Game Object. * * @name Phaser.GameObjects.Components.Transform#y * @type {number} * @default 0 * @since 3.0.0 */ y: 0, /** * The z position of this Game Object. * Note: Do not use this value to set the z-index, instead see the `depth` property. * * @name Phaser.GameObjects.Components.Transform#z * @type {number} * @default 0 * @since 3.0.0 */ z: 0, /** * The w position of this Game Object. * * @name Phaser.GameObjects.Components.Transform#w * @type {number} * @default 0 * @since 3.0.0 */ w: 0, /** * The horizontal scale of this Game Object. * * @name Phaser.GameObjects.Components.Transform#scaleX * @type {number} * @default 1 * @since 3.0.0 */ scaleX: { get: function () { return this._scaleX; }, set: function (value) { this._scaleX = value; if (this._scaleX === 0) { this.renderFlags &= ~_FLAG; } else { this.renderFlags |= _FLAG; } } }, /** * The vertical scale of this Game Object. * * @name Phaser.GameObjects.Components.Transform#scaleY * @type {number} * @default 1 * @since 3.0.0 */ scaleY: { get: function () { return this._scaleY; }, set: function (value) { this._scaleY = value; if (this._scaleY === 0) { this.renderFlags &= ~_FLAG; } else { this.renderFlags |= _FLAG; } } }, /** * The angle of this Game Object as expressed in degrees. * * Where 0 is to the right, 90 is down, 180 is left. * * If you prefer to work in radians, see the `rotation` property instead. * * @name Phaser.GameObjects.Components.Transform#angle * @type {integer} * @default 0 * @since 3.0.0 */ angle: { get: function () { return WrapAngleDegrees(this._rotation * MATH_CONST.RAD_TO_DEG); }, set: function (value) { // value is in degrees this.rotation = WrapAngleDegrees(value) * MATH_CONST.DEG_TO_RAD; } }, /** * The angle of this Game Object in radians. * * If you prefer to work in degrees, see the `angle` property instead. * * @name Phaser.GameObjects.Components.Transform#rotation * @type {number} * @default 1 * @since 3.0.0 */ rotation: { get: function () { return this._rotation; }, set: function (value) { // value is in radians this._rotation = WrapAngle(value); } }, /** * Sets the position of this Game Object. * * @method Phaser.GameObjects.Components.Transform#setPosition * @since 3.0.0 * * @param {number} [x=0] - The x position of this Game Object. * @param {number} [y=x] - The y position of this Game Object. If not set it will use the `x` value. * @param {number} [z=0] - The z position of this Game Object. * @param {number} [w=0] - The w position of this Game Object. * * @return {this} This Game Object instance. */ setPosition: function (x, y, z, w) { if (x === undefined) { x = 0; } if (y === undefined) { y = x; } if (z === undefined) { z = 0; } if (w === undefined) { w = 0; } this.x = x; this.y = y; this.z = z; this.w = w; return this; }, /** * Sets the position of this Game Object to be a random position within the confines of * the given area. * * If no area is specified a random position between 0 x 0 and the game width x height is used instead. * * The position does not factor in the size of this Game Object, meaning that only the origin is * guaranteed to be within the area. * * @method Phaser.GameObjects.Components.Transform#setRandomPosition * @since 3.8.0 * * @param {number} [x=0] - The x position of the top-left of the random area. * @param {number} [y=0] - The y position of the top-left of the random area. * @param {number} [width] - The width of the random area. * @param {number} [height] - The height of the random area. * * @return {this} This Game Object instance. */ setRandomPosition: function (x, y, width, height) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = this.scene.sys.game.config.width; } if (height === undefined) { height = this.scene.sys.game.config.height; } this.x = x + (Math.random() * width); this.y = y + (Math.random() * height); return this; }, /** * Sets the rotation of this Game Object. * * @method Phaser.GameObjects.Components.Transform#setRotation * @since 3.0.0 * * @param {number} [radians=0] - The rotation of this Game Object, in radians. * * @return {this} This Game Object instance. */ setRotation: function (radians) { if (radians === undefined) { radians = 0; } this.rotation = radians; return this; }, /** * Sets the angle of this Game Object. * * @method Phaser.GameObjects.Components.Transform#setAngle * @since 3.0.0 * * @param {number} [degrees=0] - The rotation of this Game Object, in degrees. * * @return {this} This Game Object instance. */ setAngle: function (degrees) { if (degrees === undefined) { degrees = 0; } this.angle = degrees; return this; }, /** * Sets the scale of this Game Object. * * @method Phaser.GameObjects.Components.Transform#setScale * @since 3.0.0 * * @param {number} x - The horizontal scale of this Game Object. * @param {number} [y=x] - The vertical scale of this Game Object. If not set it will use the `x` value. * * @return {this} This Game Object instance. */ setScale: function (x, y) { if (x === undefined) { x = 1; } if (y === undefined) { y = x; } this.scaleX = x; this.scaleY = y; return this; }, /** * Sets the x position of this Game Object. * * @method Phaser.GameObjects.Components.Transform#setX * @since 3.0.0 * * @param {number} [value=0] - The x position of this Game Object. * * @return {this} This Game Object instance. */ setX: function (value) { if (value === undefined) { value = 0; } this.x = value; return this; }, /** * Sets the y position of this Game Object. * * @method Phaser.GameObjects.Components.Transform#setY * @since 3.0.0 * * @param {number} [value=0] - The y position of this Game Object. * * @return {this} This Game Object instance. */ setY: function (value) { if (value === undefined) { value = 0; } this.y = value; return this; }, /** * Sets the z position of this Game Object. * * @method Phaser.GameObjects.Components.Transform#setZ * @since 3.0.0 * * @param {number} [value=0] - The z position of this Game Object. * * @return {this} This Game Object instance. */ setZ: function (value) { if (value === undefined) { value = 0; } this.z = value; return this; }, /** * Sets the w position of this Game Object. * * @method Phaser.GameObjects.Components.Transform#setW * @since 3.0.0 * * @param {number} [value=0] - The w position of this Game Object. * * @return {this} This Game Object instance. */ setW: function (value) { if (value === undefined) { value = 0; } this.w = value; return this; }, /** * Gets the local transform matrix for this Game Object. * * @method Phaser.GameObjects.Components.Transform#getLocalTransformMatrix * @since 3.4.0 * * @param {Phaser.GameObjects.Components.TransformMatrix} [tempMatrix] - The matrix to populate with the values from this Game Object. * * @return {Phaser.GameObjects.Components.TransformMatrix} The populated Transform Matrix. */ getLocalTransformMatrix: function (tempMatrix) { if (tempMatrix === undefined) { tempMatrix = new TransformMatrix(); } return tempMatrix.applyITRS(this.x, this.y, this._rotation, this._scaleX, this._scaleY); }, /** * Gets the world transform matrix for this Game Object, factoring in any parent Containers. * * @method Phaser.GameObjects.Components.Transform#getWorldTransformMatrix * @since 3.4.0 * * @param {Phaser.GameObjects.Components.TransformMatrix} [tempMatrix] - The matrix to populate with the values from this Game Object. * * @return {Phaser.GameObjects.Components.TransformMatrix} The populated Transform Matrix. */ getWorldTransformMatrix: function (tempMatrix) { if (tempMatrix === undefined) { tempMatrix = new TransformMatrix(); } var parent = this.parentContainer; if (!parent) { return this.getLocalTransformMatrix(tempMatrix); } var parents = []; while (parent) { parents.unshift(parent); parent = parent.parentContainer; } tempMatrix.loadIdentity(); var length = parents.length; for (var i = 0; i < length; ++i) { parent = parents[i]; tempMatrix.translate(parent.x, parent.y); tempMatrix.rotate(parent.rotation); tempMatrix.scale(parent.scaleX, parent.scaleY); } tempMatrix.translate(this.x, this.y); tempMatrix.rotate(this._rotation); tempMatrix.scale(this._scaleX, this._scaleY); return tempMatrix; } }; module.exports = Transform; /***/ }), /* 573 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @typedef {object} JSONGameObject * * @property {string} name - The name of this Game Object. * @property {string} type - A textual representation of this Game Object, i.e. `sprite`. * @property {number} x - The x position of this Game Object. * @property {number} y - The y position of this Game Object. * @property {object} scale - The scale of this Game Object * @property {number} scale.x - The horizontal scale of this Game Object. * @property {number} scale.y - The vertical scale of this Game Object. * @property {object} origin - The origin of this Game Object. * @property {float} origin.x - The horizontal origin of this Game Object. * @property {float} origin.y - The vertical origin of this Game Object. * @property {boolean} flipX - The horizontally flipped state of the Game Object. * @property {boolean} flipY - The vertically flipped state of the Game Object. * @property {number} rotation - The angle of this Game Object in radians. * @property {float} alpha - The alpha value of the Game Object. * @property {boolean} visible - The visible state of the Game Object. * @property {integer} scaleMode - The Scale Mode being used by this Game Object. * @property {(integer|string)} blendMode - Sets the Blend Mode being used by this Game Object. * @property {string} textureKey - The texture key of this Game Object. * @property {string} frameKey - The frame key of this Game Object. * @property {object} data - The data of this Game Object. */ /** * Build a JSON representation of the given Game Object. * * This is typically extended further by Game Object specific implementations. * * @method Phaser.GameObjects.Components.ToJSON * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to export as JSON. * * @return {JSONGameObject} The JSON representation of the Game Object. */ var ToJSON = function (gameObject) { var out = { name: gameObject.name, type: gameObject.type, x: gameObject.x, y: gameObject.y, depth: gameObject.depth, scale: { x: gameObject.scaleX, y: gameObject.scaleY }, origin: { x: gameObject.originX, y: gameObject.originY }, flipX: gameObject.flipX, flipY: gameObject.flipY, rotation: gameObject.rotation, alpha: gameObject.alpha, visible: gameObject.visible, scaleMode: gameObject.scaleMode, blendMode: gameObject.blendMode, textureKey: '', frameKey: '', data: {} }; if (gameObject.texture) { out.textureKey = gameObject.texture.key; out.frameKey = gameObject.frame.name; } return out; }; module.exports = ToJSON; /***/ }), /* 574 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @function GetColor * @since 3.0.0 * @private */ var GetColor = function (value) { return (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); }; /** * Provides methods used for setting the tint of a Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.Tint * @webglOnly * @since 3.0.0 */ var Tint = { /** * Private internal value. Holds the top-left tint value. * * @name Phaser.GameObjects.Components.Tint#_tintTL * @type {number} * @private * @default 16777215 * @since 3.0.0 */ _tintTL: 16777215, /** * Private internal value. Holds the top-right tint value. * * @name Phaser.GameObjects.Components.Tint#_tintTR * @type {number} * @private * @default 16777215 * @since 3.0.0 */ _tintTR: 16777215, /** * Private internal value. Holds the bottom-left tint value. * * @name Phaser.GameObjects.Components.Tint#_tintBL * @type {number} * @private * @default 16777215 * @since 3.0.0 */ _tintBL: 16777215, /** * Private internal value. Holds the bottom-right tint value. * * @name Phaser.GameObjects.Components.Tint#_tintBR * @type {number} * @private * @default 16777215 * @since 3.0.0 */ _tintBR: 16777215, /** * Clears all tint values associated with this Game Object. * Immediately sets the alpha levels back to 0xffffff (no tint) * * @method Phaser.GameObjects.Components.Tint#clearTint * @webglOnly * @since 3.0.0 * * @return {this} This Game Object instance. */ clearTint: function () { this.setTint(0xffffff); return this; }, /** * Sets the tint values for this Game Object. * * @method Phaser.GameObjects.Components.Tint#setTint * @webglOnly * @since 3.0.0 * * @param {integer} [topLeft=0xffffff] - The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. * @param {integer} [topRight] - The tint being applied to the top-right of the Game Object. * @param {integer} [bottomLeft] - The tint being applied to the bottom-left of the Game Object. * @param {integer} [bottomRight] - The tint being applied to the bottom-right of the Game Object. * * @return {this} This Game Object instance. */ setTint: function (topLeft, topRight, bottomLeft, bottomRight) { if (topLeft === undefined) { topLeft = 0xffffff; } if (topRight === undefined) { topRight = topLeft; bottomLeft = topLeft; bottomRight = topLeft; } this._tintTL = GetColor(topLeft); this._tintTR = GetColor(topRight); this._tintBL = GetColor(bottomLeft); this._tintBR = GetColor(bottomRight); return this; }, /** * The tint value being applied to the top-left of the Game Object. * This value is interpolated from the corner to the center of the Game Object. * * @name Phaser.GameObjects.Components.Tint#tintTopLeft * @type {integer} * @webglOnly * @since 3.0.0 */ tintTopLeft: { get: function () { return this._tintTL; }, set: function (value) { this._tintTL = GetColor(value); } }, /** * The tint value being applied to the top-right of the Game Object. * This value is interpolated from the corner to the center of the Game Object. * * @name Phaser.GameObjects.Components.Tint#tintTopRight * @type {integer} * @webglOnly * @since 3.0.0 */ tintTopRight: { get: function () { return this._tintTR; }, set: function (value) { this._tintTR = GetColor(value); } }, /** * The tint value being applied to the bottom-left of the Game Object. * This value is interpolated from the corner to the center of the Game Object. * * @name Phaser.GameObjects.Components.Tint#tintBottomLeft * @type {integer} * @webglOnly * @since 3.0.0 */ tintBottomLeft: { get: function () { return this._tintBL; }, set: function (value) { this._tintBL = GetColor(value); } }, /** * The tint value being applied to the bottom-right of the Game Object. * This value is interpolated from the corner to the center of the Game Object. * * @name Phaser.GameObjects.Components.Tint#tintBottomRight * @type {integer} * @webglOnly * @since 3.0.0 */ tintBottomRight: { get: function () { return this._tintBR; }, set: function (value) { this._tintBR = GetColor(value); } }, /** * The tint value being applied to the whole of the Game Object. * * @name Phaser.GameObjects.Components.Tint#tint * @type {integer} * @webglOnly * @since 3.0.0 */ tint: { set: function (value) { this.setTint(value, value, value, value); } } }; module.exports = Tint; /***/ }), /* 575 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ // bitmask flag for GameObject.renderMask var _FLAG = 8; // 1000 /** * Provides methods used for getting and setting the texture of a Game Object. * * @name Phaser.GameObjects.Components.Texture * @since 3.0.0 */ var Texture = { /** * The Texture this Game Object is using to render with. * * @name Phaser.GameObjects.Components.Texture#texture * @type {Phaser.Textures.Texture|Phaser.Textures.CanvasTexture} * @since 3.0.0 */ texture: null, /** * The Texture Frame this Game Object is using to render with. * * @name Phaser.GameObjects.Components.Texture#frame * @type {Phaser.Textures.Frame} * @since 3.0.0 */ frame: null, /** * Sets the texture and frame this Game Object will use to render with. * * Textures are referenced by their string-based keys, as stored in the Texture Manager. * * @method Phaser.GameObjects.Components.Texture#setTexture * @since 3.0.0 * * @param {string} key - The key of the texture to be used, as stored in the Texture Manager. * @param {(string|integer)} [frame] - The name or index of the frame within the Texture. * * @return {this} This Game Object instance. */ setTexture: function (key, frame) { this.texture = this.scene.sys.textures.get(key); return this.setFrame(frame); }, /** * Sets the frame this Game Object will use to render with. * * The Frame has to belong to the current Texture being used. * * It can be either a string or an index. * * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. * * @method Phaser.GameObjects.Components.Texture#setFrame * @since 3.0.0 * * @param {(string|integer)} frame - The name or index of the frame within the Texture. * @param {boolean} [updateSize=true] - Should this call adjust the size of the Game Object? * @param {boolean} [updateOrigin=true] - Should this call adjust the origin of the Game Object? * * @return {this} This Game Object instance. */ setFrame: function (frame, updateSize, updateOrigin) { if (updateSize === undefined) { updateSize = true; } if (updateOrigin === undefined) { updateOrigin = true; } this.frame = this.texture.get(frame); if (!this.frame.cutWidth || !this.frame.cutHeight) { this.renderFlags &= ~_FLAG; } else { this.renderFlags |= _FLAG; } if (this._sizeComponent && updateSize) { this.setSizeToFrame(); } if (this._originComponent && updateOrigin) { if (this.frame.customPivot) { this.setOrigin(this.frame.pivotX, this.frame.pivotY); } else { this.updateDisplayOrigin(); } } return this; } }; module.exports = Texture; /***/ }), /* 576 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Provides methods used for getting and setting the size of a Game Object. * * @name Phaser.GameObjects.Components.Size * @since 3.0.0 */ var Size = { /** * A property indicating that a Game Object has this component. * * @name Phaser.GameObjects.Components.Size#_sizeComponent * @type {boolean} * @private * @default true * @since 3.2.0 */ _sizeComponent: true, /** * The native (un-scaled) width of this Game Object. * * @name Phaser.GameObjects.Components.Size#width * @type {number} * @since 3.0.0 */ width: 0, /** * The native (un-scaled) height of this Game Object. * * @name Phaser.GameObjects.Components.Size#height * @type {number} * @since 3.0.0 */ height: 0, /** * The displayed width of this Game Object. * This value takes into account the scale factor. * * @name Phaser.GameObjects.Components.Size#displayWidth * @type {number} * @since 3.0.0 */ displayWidth: { get: function () { return this.scaleX * this.frame.realWidth; }, set: function (value) { this.scaleX = value / this.frame.realWidth; } }, /** * The displayed height of this Game Object. * This value takes into account the scale factor. * * @name Phaser.GameObjects.Components.Size#displayHeight * @type {number} * @since 3.0.0 */ displayHeight: { get: function () { return this.scaleY * this.frame.realHeight; }, set: function (value) { this.scaleY = value / this.frame.realHeight; } }, /** * Sets the size of this Game Object to be that of the given Frame. * * @method Phaser.GameObjects.Components.Size#setSizeToFrame * @since 3.0.0 * * @param {Phaser.Textures.Frame} frame - The frame to base the size of this Game Object on. * * @return {this} This Game Object instance. */ setSizeToFrame: function (frame) { if (frame === undefined) { frame = this.frame; } this.width = frame.realWidth; this.height = frame.realHeight; return this; }, /** * Sets the size of this Game Object. * * @method Phaser.GameObjects.Components.Size#setSize * @since 3.0.0 * * @param {number} width - The width of this Game Object. * @param {number} height - The height of this Game Object. * * @return {this} This Game Object instance. */ setSize: function (width, height) { this.width = width; this.height = height; return this; }, /** * Sets the display size of this Game Object. * Calling this will adjust the scale. * * @method Phaser.GameObjects.Components.Size#setDisplaySize * @since 3.0.0 * * @param {number} width - The width of this Game Object. * @param {number} height - The height of this Game Object. * * @return {this} This Game Object instance. */ setDisplaySize: function (width, height) { this.displayWidth = width; this.displayHeight = height; return this; } }; module.exports = Size; /***/ }), /* 577 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Provides methods used for getting and setting the Scroll Factor of a Game Object. * * @name Phaser.GameObjects.Components.ScrollFactor * @since 3.0.0 */ var ScrollFactor = { /** * The horizontal scroll factor of this Game Object. * * The scroll factor controls the influence of the movement of a Camera upon this Game Object. * * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. * It does not change the Game Objects actual position values. * * A value of 1 means it will move exactly in sync with a camera. * A value of 0 means it will not move at all, even if the camera moves. * Other values control the degree to which the camera movement is mapped to this Game Object. * * @name Phaser.GameObjects.Components.ScrollFactor#scrollFactorX * @type {number} * @default 1 * @since 3.0.0 */ scrollFactorX: 1, /** * The vertical scroll factor of this Game Object. * * The scroll factor controls the influence of the movement of a Camera upon this Game Object. * * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. * It does not change the Game Objects actual position values. * * A value of 1 means it will move exactly in sync with a camera. * A value of 0 means it will not move at all, even if the camera moves. * Other values control the degree to which the camera movement is mapped to this Game Object. * * @name Phaser.GameObjects.Components.ScrollFactor#scrollFactorY * @type {number} * @default 1 * @since 3.0.0 */ scrollFactorY: 1, /** * Sets the scroll factor of this Game Object. * * The scroll factor controls the influence of the movement of a Camera upon this Game Object. * * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. * It does not change the Game Objects actual position values. * * A value of 1 means it will move exactly in sync with a camera. * A value of 0 means it will not move at all, even if the camera moves. * Other values control the degree to which the camera movement is mapped to this Game Object. * * @method Phaser.GameObjects.Components.ScrollFactor#setScrollFactor * @since 3.0.0 * * @param {number} x - The horizontal scroll factor of this Game Object. * @param {number} [y=x] - The vertical scroll factor of this Game Object. If not set it will use the `x` value. * * @return {this} This Game Object instance. */ setScrollFactor: function (x, y) { if (y === undefined) { y = x; } this.scrollFactorX = x; this.scrollFactorY = y; return this; } }; module.exports = ScrollFactor; /***/ }), /* 578 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var ScaleModes = __webpack_require__(59); /** * Provides methods used for getting and setting the scale of a Game Object. * * @name Phaser.GameObjects.Components.ScaleMode * @since 3.0.0 */ var ScaleMode = { _scaleMode: ScaleModes.DEFAULT, /** * The Scale Mode being used by this Game Object. * Can be either `ScaleModes.LINEAR` or `ScaleModes.NEAREST`. * * @name Phaser.GameObjects.Components.ScaleMode#scaleMode * @type {Phaser.ScaleModes} * @since 3.0.0 */ scaleMode: { get: function () { return this._scaleMode; }, set: function (value) { if (value === ScaleModes.LINEAR || value === ScaleModes.NEAREST) { this._scaleMode = value; } } }, /** * Sets the Scale Mode being used by this Game Object. * Can be either `ScaleModes.LINEAR` or `ScaleModes.NEAREST`. * * @method Phaser.GameObjects.Components.ScaleMode#setScaleMode * @since 3.0.0 * * @param {Phaser.ScaleModes} value - The Scale Mode to be used by this Game Object. * * @return {this} This Game Object instance. */ setScaleMode: function (value) { this.scaleMode = value; return this; } }; module.exports = ScaleMode; /***/ }), /* 579 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Provides methods used for getting and setting the origin of a Game Object. * Values are normalized, given in the range 0 to 1. * Display values contain the calculated pixel values. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.Origin * @since 3.0.0 */ var Origin = { /** * A property indicating that a Game Object has this component. * * @name Phaser.GameObjects.Components.Origin#_originComponent * @type {boolean} * @private * @default true * @since 3.2.0 */ _originComponent: true, /** * The horizontal origin of this Game Object. * The origin maps the relationship between the size and position of the Game Object. * The default value is 0.5, meaning all Game Objects are positioned based on their center. * Setting the value to 0 means the position now relates to the left of the Game Object. * * @name Phaser.GameObjects.Components.Origin#originX * @type {float} * @default 0.5 * @since 3.0.0 */ originX: 0.5, /** * The vertical origin of this Game Object. * The origin maps the relationship between the size and position of the Game Object. * The default value is 0.5, meaning all Game Objects are positioned based on their center. * Setting the value to 0 means the position now relates to the top of the Game Object. * * @name Phaser.GameObjects.Components.Origin#originY * @type {float} * @default 0.5 * @since 3.0.0 */ originY: 0.5, // private + read only _displayOriginX: 0, _displayOriginY: 0, /** * The horizontal display origin of this Game Object. * The origin is a normalized value between 0 and 1. * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. * * @name Phaser.GameObjects.Components.Origin#displayOriginX * @type {float} * @since 3.0.0 */ displayOriginX: { get: function () { return this._displayOriginX; }, set: function (value) { this._displayOriginX = value; this.originX = value / this.width; } }, /** * The vertical display origin of this Game Object. * The origin is a normalized value between 0 and 1. * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. * * @name Phaser.GameObjects.Components.Origin#displayOriginY * @type {float} * @since 3.0.0 */ displayOriginY: { get: function () { return this._displayOriginY; }, set: function (value) { this._displayOriginY = value; this.originY = value / this.height; } }, /** * Sets the origin of this Game Object. * * The values are given in the range 0 to 1. * * @method Phaser.GameObjects.Components.Origin#setOrigin * @since 3.0.0 * * @param {number} [x=0.5] - The horizontal origin value. * @param {number} [y=x] - The vertical origin value. If not defined it will be set to the value of `x`. * * @return {this} This Game Object instance. */ setOrigin: function (x, y) { if (x === undefined) { x = 0.5; } if (y === undefined) { y = x; } this.originX = x; this.originY = y; return this.updateDisplayOrigin(); }, /** * Sets the origin of this Game Object based on the Pivot values in its Frame. * * @method Phaser.GameObjects.Components.Origin#setOriginFromFrame * @since 3.0.0 * * @return {this} This Game Object instance. */ setOriginFromFrame: function () { if (!this.frame || !this.frame.customPivot) { return this.setOrigin(); } else { this.originX = this.frame.pivotX; this.originY = this.frame.pivotY; } return this.updateDisplayOrigin(); }, /** * Sets the display origin of this Game Object. * The difference between this and setting the origin is that you can use pixel values for setting the display origin. * * @method Phaser.GameObjects.Components.Origin#setDisplayOrigin * @since 3.0.0 * * @param {number} [x=0] - The horizontal display origin value. * @param {number} [y=x] - The vertical display origin value. If not defined it will be set to the value of `x`. * * @return {this} This Game Object instance. */ setDisplayOrigin: function (x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = x; } this.displayOriginX = x; this.displayOriginY = y; return this; }, /** * Updates the Display Origin cached values internally stored on this Game Object. * You don't usually call this directly, but it is exposed for edge-cases where you may. * * @method Phaser.GameObjects.Components.Origin#updateDisplayOrigin * @since 3.0.0 * * @return {this} This Game Object instance. */ updateDisplayOrigin: function () { this._displayOriginX = Math.round(this.originX * this.width); this._displayOriginY = Math.round(this.originY * this.height); return this; } }; module.exports = Origin; /***/ }), /* 580 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Provides methods used for getting and setting the transform values of a Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.MatrixStack * @since 3.2.0 */ var MatrixStack = { /** * The matrix stack. * * @name Phaser.GameObjects.Components.MatrixStack#matrixStack * @type {Float32Array} * @private * @since 3.2.0 */ matrixStack: null, /** * The current matrix. * * @name Phaser.GameObjects.Components.MatrixStack#currentMatrix * @type {Float32Array} * @private * @since 3.2.0 */ currentMatrix: null, /** * The current index of the top of the matrix stack. * * @name Phaser.GameObjects.Components.MatrixStack#currentMatrixIndex * @type {integer} * @private * @since 3.2.0 */ currentMatrixIndex: 0, /** * Initialize the matrix stack. * * @method Phaser.GameObjects.Components.MatrixStack#initMatrixStack * @since 3.2.0 * * @return {this} This Game Object instance. */ initMatrixStack: function () { this.matrixStack = new Float32Array(6000); // up to 1000 matrices this.currentMatrix = new Float32Array([ 1, 0, 0, 1, 0, 0 ]); this.currentMatrixIndex = 0; return this; }, /** * Push the current matrix onto the matrix stack. * * @method Phaser.GameObjects.Components.MatrixStack#save * @since 3.2.0 * * @return {this} This Game Object instance. */ save: function () { if (this.currentMatrixIndex >= this.matrixStack.length) { return this; } var matrixStack = this.matrixStack; var currentMatrix = this.currentMatrix; var currentMatrixIndex = this.currentMatrixIndex; this.currentMatrixIndex += 6; matrixStack[currentMatrixIndex + 0] = currentMatrix[0]; matrixStack[currentMatrixIndex + 1] = currentMatrix[1]; matrixStack[currentMatrixIndex + 2] = currentMatrix[2]; matrixStack[currentMatrixIndex + 3] = currentMatrix[3]; matrixStack[currentMatrixIndex + 4] = currentMatrix[4]; matrixStack[currentMatrixIndex + 5] = currentMatrix[5]; return this; }, /** * Pop the top of the matrix stack into the current matrix. * * @method Phaser.GameObjects.Components.MatrixStack#restore * @since 3.2.0 * * @return {this} This Game Object instance. */ restore: function () { if (this.currentMatrixIndex <= 0) { return this; } this.currentMatrixIndex -= 6; var matrixStack = this.matrixStack; var currentMatrix = this.currentMatrix; var currentMatrixIndex = this.currentMatrixIndex; currentMatrix[0] = matrixStack[currentMatrixIndex + 0]; currentMatrix[1] = matrixStack[currentMatrixIndex + 1]; currentMatrix[2] = matrixStack[currentMatrixIndex + 2]; currentMatrix[3] = matrixStack[currentMatrixIndex + 3]; currentMatrix[4] = matrixStack[currentMatrixIndex + 4]; currentMatrix[5] = matrixStack[currentMatrixIndex + 5]; return this; }, /** * Resets the current matrix to the identity matrix. * * @method Phaser.GameObjects.Components.MatrixStack#loadIdentity * @since 3.2.0 * * @return {this} This Game Object instance. */ loadIdentity: function () { this.setTransform(1, 0, 0, 1, 0, 0); return this; }, /** * Transform the current matrix. * * @method Phaser.GameObjects.Components.MatrixStack#transform * @since 3.2.0 * * @param {number} a - The Scale X value. * @param {number} b - The Shear Y value. * @param {number} c - The Shear X value. * @param {number} d - The Scale Y value. * @param {number} tx - The Translate X value. * @param {number} ty - The Translate Y value. * * @return {this} This Game Object instance. */ transform: function (a, b, c, d, tx, ty) { var currentMatrix = this.currentMatrix; var m0 = currentMatrix[0]; var m1 = currentMatrix[1]; var m2 = currentMatrix[2]; var m3 = currentMatrix[3]; var m4 = currentMatrix[4]; var m5 = currentMatrix[5]; currentMatrix[0] = m0 * a + m2 * b; currentMatrix[1] = m1 * a + m3 * b; currentMatrix[2] = m0 * c + m2 * d; currentMatrix[3] = m1 * c + m3 * d; currentMatrix[4] = m0 * tx + m2 * ty + m4; currentMatrix[5] = m1 * tx + m3 * ty + m5; return this; }, /** * Set a transform matrix as the current matrix. * * @method Phaser.GameObjects.Components.MatrixStack#setTransform * @since 3.2.0 * * @param {number} a - The Scale X value. * @param {number} b - The Shear Y value. * @param {number} c - The Shear X value. * @param {number} d - The Scale Y value. * @param {number} tx - The Translate X value. * @param {number} ty - The Translate Y value. * * @return {this} This Game Object instance. */ setTransform: function (a, b, c, d, tx, ty) { var currentMatrix = this.currentMatrix; currentMatrix[0] = a; currentMatrix[1] = b; currentMatrix[2] = c; currentMatrix[3] = d; currentMatrix[4] = tx; currentMatrix[5] = ty; return this; }, /** * Translate the current matrix. * * @method Phaser.GameObjects.Components.MatrixStack#translate * @since 3.2.0 * * @param {number} x - The horizontal translation value. * @param {number} y - The vertical translation value. * * @return {this} This Game Object instance. */ translate: function (x, y) { var currentMatrix = this.currentMatrix; var m0 = currentMatrix[0]; var m1 = currentMatrix[1]; var m2 = currentMatrix[2]; var m3 = currentMatrix[3]; var m4 = currentMatrix[4]; var m5 = currentMatrix[5]; currentMatrix[4] = m0 * x + m2 * y + m4; currentMatrix[5] = m1 * x + m3 * y + m5; return this; }, /** * Scale the current matrix. * * @method Phaser.GameObjects.Components.MatrixStack#scale * @since 3.2.0 * * @param {number} x - The horizontal scale value. * @param {number} y - The vertical scale value. * * @return {this} This Game Object instance. */ scale: function (x, y) { var currentMatrix = this.currentMatrix; var m0 = currentMatrix[0]; var m1 = currentMatrix[1]; var m2 = currentMatrix[2]; var m3 = currentMatrix[3]; currentMatrix[0] = m0 * x; currentMatrix[1] = m1 * x; currentMatrix[2] = m2 * y; currentMatrix[3] = m3 * y; return this; }, /** * Rotate the current matrix. * * @method Phaser.GameObjects.Components.MatrixStack#rotate * @since 3.2.0 * * @param {number} t - The angle of rotation, in radians. * * @return {this} This Game Object instance. */ rotate: function (t) { var currentMatrix = this.currentMatrix; var m0 = currentMatrix[0]; var m1 = currentMatrix[1]; var m2 = currentMatrix[2]; var m3 = currentMatrix[3]; var st = Math.sin(t); var ct = Math.cos(t); currentMatrix[0] = m0 * ct + m2 * st; currentMatrix[1] = m1 * ct + m3 * st; currentMatrix[2] = m0 * -st + m2 * ct; currentMatrix[3] = m1 * -st + m3 * ct; return this; } }; module.exports = MatrixStack; /***/ }), /* 581 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BitmapMask = __webpack_require__(214); var GeometryMask = __webpack_require__(213); /** * Provides methods used for getting and setting the mask of a Game Object. * * @name Phaser.GameObjects.Components.Mask * @since 3.0.0 */ var Mask = { /** * The Mask this Game Object is using during render. * * @name Phaser.GameObjects.Components.Mask#mask * @type {Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask} * @since 3.0.0 */ mask: null, /** * Sets the mask that this Game Object will use to render with. * * The mask must have been previously created and can be either a * GeometryMask or a BitmapMask. * * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. * * If a mask is already set on this Game Object it will be immediately replaced. * * @method Phaser.GameObjects.Components.Mask#setMask * @since 3.6.2 * * @param {Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask} mask - The mask this Game Object will use when rendering. * * @return {this} This Game Object instance. */ setMask: function (mask) { this.mask = mask; return this; }, /** * Clears the mask that this Game Object was using. * * @method Phaser.GameObjects.Components.Mask#clearMask * @since 3.6.2 * * @param {boolean} [destroyMask=false] - Destroy the mask before clearing it? * * @return {this} This Game Object instance. */ clearMask: function (destroyMask) { if (destroyMask === undefined) { destroyMask = false; } if (destroyMask) { this.mask.destroy(); } this.mask = null; return this; }, /** * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. * * If you do not provide a renderable object, and this Game Object has a texture, * it will use itself as the object. This means you can call this method to create * a Bitmap Mask from any renderable Game Object. * * @method Phaser.GameObjects.Components.Mask#createBitmapMask * @since 3.6.2 * * @param {Phaser.GameObjects.GameObject} [renderable] - A renderable Game Object that uses a texture, such as a Sprite. * * @return {Phaser.Display.Masks.BitmapMask} This Bitmap Mask that was created. */ createBitmapMask: function (renderable) { if (renderable === undefined && this.texture) { // eslint-disable-next-line consistent-this renderable = this; } return new BitmapMask(this.scene, renderable); }, /** * Creates and returns a Geometry Mask. This mask can be used by any Game Object, * including this one. * * To create the mask you need to pass in a reference to a Graphics Game Object. * * If you do not provide a graphics object, and this Game Object is an instance * of a Graphics object, then it will use itself to create the mask. * * This means you can call this method to create a Geometry Mask from any Graphics Game Object. * * @method Phaser.GameObjects.Components.Mask#createGeometryMask * @since 3.6.2 * * @param {Phaser.GameObjects.Graphics} [graphics] - A Graphics Game Object. The geometry within it will be used as the mask. * * @return {Phaser.Display.Masks.GeometryMask} This Geometry Mask that was created. */ createGeometryMask: function (graphics) { if (graphics === undefined && this.type === 'Graphics') { // eslint-disable-next-line consistent-this graphics = this; } return new GeometryMask(this.scene, graphics); } }; module.exports = Mask; /***/ }), /* 582 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Rectangle = __webpack_require__(14); var RotateAround = __webpack_require__(292); var Vector2 = __webpack_require__(6); /** * Provides methods used for obtaining the bounds of a Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.GetBounds * @since 3.0.0 */ var GetBounds = { /** * Gets the center coordinate of this Game Object, regardless of origin. * The returned point is calculated in local space and does not factor in any parent containers * * @method Phaser.GameObjects.Components.GetBounds#getCenter * @since 3.0.0 * * @generic {Phaser.Math.Vector2} O - [output,$return] * * @param {(Phaser.Math.Vector2|object)} [output] - An object to store the values in. If not provided a new Vector2 will be created. * * @return {(Phaser.Math.Vector2|object)} The values stored in the output object. */ getCenter: function (output) { if (output === undefined) { output = new Vector2(); } output.x = this.x - (this.displayWidth * this.originX) + (this.displayWidth / 2); output.y = this.y - (this.displayHeight * this.originY) + (this.displayHeight / 2); return output; }, /** * Gets the top-left corner coordinate of this Game Object, regardless of origin. * The returned point is calculated in local space and does not factor in any parent containers * * @method Phaser.GameObjects.Components.GetBounds#getTopLeft * @since 3.0.0 * * @generic {Phaser.Math.Vector2} O - [output,$return] * * @param {(Phaser.Math.Vector2|object)} [output] - An object to store the values in. If not provided a new Vector2 will be created. * @param {boolean} [includeParent=false] - If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? * * @return {(Phaser.Math.Vector2|object)} The values stored in the output object. */ getTopLeft: function (output, includeParent) { if (!output) { output = new Vector2(); } if (includeParent === undefined) { includeParent = false; } output.x = this.x - (this.displayWidth * this.originX); output.y = this.y - (this.displayHeight * this.originY); if (this.rotation !== 0) { RotateAround(output, this.x, this.y, this.rotation); } if (includeParent && this.parentContainer) { var parentMatrix = this.parentContainer.getBoundsTransformMatrix(); parentMatrix.transformPoint(output.x, output.y, output); } return output; }, /** * Gets the top-right corner coordinate of this Game Object, regardless of origin. * The returned point is calculated in local space and does not factor in any parent containers * * @method Phaser.GameObjects.Components.GetBounds#getTopRight * @since 3.0.0 * * @generic {Phaser.Math.Vector2} O - [output,$return] * * @param {(Phaser.Math.Vector2|object)} [output] - An object to store the values in. If not provided a new Vector2 will be created. * @param {boolean} [includeParent=false] - If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? * * @return {(Phaser.Math.Vector2|object)} The values stored in the output object. */ getTopRight: function (output, includeParent) { if (!output) { output = new Vector2(); } if (includeParent === undefined) { includeParent = false; } output.x = (this.x - (this.displayWidth * this.originX)) + this.displayWidth; output.y = this.y - (this.displayHeight * this.originY); if (this.rotation !== 0) { RotateAround(output, this.x, this.y, this.rotation); } if (includeParent && this.parentContainer) { var parentMatrix = this.parentContainer.getBoundsTransformMatrix(); parentMatrix.transformPoint(output.x, output.y, output); } return output; }, /** * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. * The returned point is calculated in local space and does not factor in any parent containers * * @method Phaser.GameObjects.Components.GetBounds#getBottomLeft * @since 3.0.0 * * @generic {Phaser.Math.Vector2} O - [output,$return] * * @param {(Phaser.Math.Vector2|object)} [output] - An object to store the values in. If not provided a new Vector2 will be created. * @param {boolean} [includeParent=false] - If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? * * @return {(Phaser.Math.Vector2|object)} The values stored in the output object. */ getBottomLeft: function (output, includeParent) { if (!output) { output = new Vector2(); } if (includeParent === undefined) { includeParent = false; } output.x = this.x - (this.displayWidth * this.originX); output.y = (this.y - (this.displayHeight * this.originY)) + this.displayHeight; if (this.rotation !== 0) { RotateAround(output, this.x, this.y, this.rotation); } if (includeParent && this.parentContainer) { var parentMatrix = this.parentContainer.getBoundsTransformMatrix(); parentMatrix.transformPoint(output.x, output.y, output); } return output; }, /** * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. * The returned point is calculated in local space and does not factor in any parent containers * * @method Phaser.GameObjects.Components.GetBounds#getBottomRight * @since 3.0.0 * * @generic {Phaser.Math.Vector2} O - [output,$return] * * @param {(Phaser.Math.Vector2|object)} [output] - An object to store the values in. If not provided a new Vector2 will be created. * @param {boolean} [includeParent=false] - If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? * * @return {(Phaser.Math.Vector2|object)} The values stored in the output object. */ getBottomRight: function (output, includeParent) { if (!output) { output = new Vector2(); } if (includeParent === undefined) { includeParent = false; } output.x = (this.x - (this.displayWidth * this.originX)) + this.displayWidth; output.y = (this.y - (this.displayHeight * this.originY)) + this.displayHeight; if (this.rotation !== 0) { RotateAround(output, this.x, this.y, this.rotation); } if (includeParent && this.parentContainer) { var parentMatrix = this.parentContainer.getBoundsTransformMatrix(); parentMatrix.transformPoint(output.x, output.y, output); } return output; }, /** * Gets the bounds of this Game Object, regardless of origin. * The values are stored and returned in a Rectangle, or Rectangle-like, object. * * @method Phaser.GameObjects.Components.GetBounds#getBounds * @since 3.0.0 * * @generic {Phaser.Geom.Rectangle} O - [output,$return] * * @param {(Phaser.Geom.Rectangle|object)} [output] - An object to store the values in. If not provided a new Rectangle will be created. * * @return {(Phaser.Geom.Rectangle|object)} The values stored in the output object. */ getBounds: function (output) { if (output === undefined) { output = new Rectangle(); } // We can use the output object to temporarily store the x/y coords in: var TLx, TLy, TRx, TRy, BLx, BLy, BRx, BRy; // Instead of doing a check if parent container is // defined per corner we only do it once. if (this.parentContainer) { var parentMatrix = this.parentContainer.getBoundsTransformMatrix(); this.getTopLeft(output); parentMatrix.transformPoint(output.x, output.y, output); TLx = output.x; TLy = output.y; this.getTopRight(output); parentMatrix.transformPoint(output.x, output.y, output); TRx = output.x; TRy = output.y; this.getBottomLeft(output); parentMatrix.transformPoint(output.x, output.y, output); BLx = output.x; BLy = output.y; this.getBottomRight(output); parentMatrix.transformPoint(output.x, output.y, output); BRx = output.x; BRy = output.y; } else { this.getTopLeft(output); TLx = output.x; TLy = output.y; this.getTopRight(output); TRx = output.x; TRy = output.y; this.getBottomLeft(output); BLx = output.x; BLy = output.y; this.getBottomRight(output); BRx = output.x; BRy = output.y; } output.x = Math.min(TLx, TRx, BLx, BRx); output.y = Math.min(TLy, TRy, BLy, BRy); output.width = Math.max(TLx, TRx, BLx, BRx) - output.x; output.height = Math.max(TLy, TRy, BLy, BRy) - output.y; return output; } }; module.exports = GetBounds; /***/ }), /* 583 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Provides methods used for visually flipping a Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.Flip * @since 3.0.0 */ var Flip = { /** * The horizontally flipped state of the Game Object. * A Game Object that is flipped horizontally will render inversed on the horizontal axis. * Flipping always takes place from the middle of the texture and does not impact the scale value. * * @name Phaser.GameObjects.Components.Flip#flipX * @type {boolean} * @default false * @since 3.0.0 */ flipX: false, /** * The vertically flipped state of the Game Object. * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) * Flipping always takes place from the middle of the texture and does not impact the scale value. * * @name Phaser.GameObjects.Components.Flip#flipY * @type {boolean} * @default false * @since 3.0.0 */ flipY: false, /** * Toggles the horizontal flipped state of this Game Object. * * @method Phaser.GameObjects.Components.Flip#toggleFlipX * @since 3.0.0 * * @return {this} This Game Object instance. */ toggleFlipX: function () { this.flipX = !this.flipX; return this; }, /** * Toggles the vertical flipped state of this Game Object. * * @method Phaser.GameObjects.Components.Flip#toggleFlipY * @since 3.0.0 * * @return {this} This Game Object instance. */ toggleFlipY: function () { this.flipY = !this.flipY; return this; }, /** * Sets the horizontal flipped state of this Game Object. * * @method Phaser.GameObjects.Components.Flip#setFlipX * @since 3.0.0 * * @param {boolean} value - The flipped state. `false` for no flip, or `true` to be flipped. * * @return {this} This Game Object instance. */ setFlipX: function (value) { this.flipX = value; return this; }, /** * Sets the vertical flipped state of this Game Object. * * @method Phaser.GameObjects.Components.Flip#setFlipY * @since 3.0.0 * * @param {boolean} value - The flipped state. `false` for no flip, or `true` to be flipped. * * @return {this} This Game Object instance. */ setFlipY: function (value) { this.flipY = value; return this; }, /** * Sets the horizontal and vertical flipped state of this Game Object. * * @method Phaser.GameObjects.Components.Flip#setFlip * @since 3.0.0 * * @param {boolean} x - The horizontal flipped state. `false` for no flip, or `true` to be flipped. * @param {boolean} y - The horizontal flipped state. `false` for no flip, or `true` to be flipped. * * @return {this} This Game Object instance. */ setFlip: function (x, y) { this.flipX = x; this.flipY = y; return this; }, /** * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. * * @method Phaser.GameObjects.Components.Flip#resetFlip * @since 3.0.0 * * @return {this} This Game Object instance. */ resetFlip: function () { this.flipX = false; this.flipY = false; return this; } }; module.exports = Flip; /***/ }), /* 584 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Provides methods used for setting the depth of a Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.Depth * @since 3.0.0 */ var Depth = { /** * Private internal value. Holds the depth of the Game Object. * * @name Phaser.GameObjects.Components.Depth#_depth * @type {integer} * @private * @default 0 * @since 3.0.0 */ _depth: 0, /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * * @name Phaser.GameObjects.Components.Depth#depth * @type {number} * @since 3.0.0 */ depth: { get: function () { return this._depth; }, set: function (value) { this.scene.sys.queueDepthSort(); this._depth = value; } }, /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * * @method Phaser.GameObjects.Components.Depth#setDepth * @since 3.0.0 * * @param {integer} value - The depth of this Game Object. * * @return {this} This Game Object instance. */ setDepth: function (value) { if (value === undefined) { value = 0; } this.depth = value; return this; } }; module.exports = Depth; /***/ }), /* 585 */ /***/ (function(module, exports) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Provides methods used for calculating and setting the size of a non-Frame based Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.ComputedSize * @since 3.0.0 */ var ComputedSize = { /** * The native (un-scaled) width of this Game Object. * * @name Phaser.GameObjects.Components.ComputedSize#width * @type {number} * @since 3.0.0 */ width: 0, /** * The native (un-scaled) height of this Game Object. * * @name Phaser.GameObjects.Components.ComputedSize#height * @type {number} * @since 3.0.0 */ height: 0, /** * The displayed width of this Game Object. * This value takes into account the scale factor. * * @name Phaser.GameObjects.Components.ComputedSize#displayWidth * @type {number} * @since 3.0.0 */ displayWidth: { get: function () { return this.scaleX * this.width; }, set: function (value) { this.scaleX = value / this.width; } }, /** * The displayed height of this Game Object. * This value takes into account the scale factor. * * @name Phaser.GameObjects.Components.ComputedSize#displayHeight * @type {number} * @since 3.0.0 */ displayHeight: { get: function () { return this.scaleY * this.height; }, set: function (value) { this.scaleY = value / this.height; } }, /** * Sets the size of this Game Object. * * @method Phaser.GameObjects.Components.ComputedSize#setSize * @since 3.4.0 * * @param {number} width - The width of this Game Object. * @param {number} height - The height of this Game Object. * * @return {this} This Game Object instance. */ setSize: function (width, height) { this.width = width; this.height = height; return this; }, /** * Sets the display size of this Game Object. * Calling this will adjust the scale. * * @method Phaser.GameObjects.Components.ComputedSize#setDisplaySize * @since 3.4.0 * * @param {number} width - The width of this Game Object. * @param {number} height - The height of this Game Object. * * @return {this} This Game Object instance. */ setDisplaySize: function (width, height) { this.displayWidth = width; this.displayHeight = height; return this; } }; module.exports = ComputedSize; /***/ }), /* 586 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var BlendModes = __webpack_require__(51); /** * Provides methods used for setting the blend mode of a Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.BlendMode * @since 3.0.0 */ var BlendMode = { /** * Private internal value. Holds the current blend mode. * * @name Phaser.GameObjects.Components.BlendMode#_blendMode * @type {integer} * @private * @default 0 * @since 3.0.0 */ _blendMode: BlendModes.NORMAL, /** * Sets the Blend Mode being used by this Game Object. * * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) * * Under WebGL only the following Blend Modes are available: * * * ADD * * MULTIPLY * * SCREEN * * Canvas has more available depending on browser support. * * You can also create your own custom Blend Modes in WebGL. * * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these * reasons try to be careful about the construction of your Scene and the frequency of which blend modes * are used. * * @name Phaser.GameObjects.Components.BlendMode#blendMode * @type {(Phaser.BlendModes|string)} * @since 3.0.0 */ blendMode: { get: function () { return this._blendMode; }, set: function (value) { if (typeof value === 'string') { value = BlendModes[value]; } value |= 0; if (value >= 0) { this._blendMode = value; } } }, /** * Sets the Blend Mode being used by this Game Object. * * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) * * Under WebGL only the following Blend Modes are available: * * * ADD * * MULTIPLY * * SCREEN * * Canvas has more available depending on browser support. * * You can also create your own custom Blend Modes in WebGL. * * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these * reasons try to be careful about the construction of your Scene and the frequency of which blend modes * are used. * * @method Phaser.GameObjects.Components.BlendMode#setBlendMode * @since 3.0.0 * * @param {(string|Phaser.BlendModes)} value - The BlendMode value. Either a string or a CONST. * * @return {this} This Game Object instance. */ setBlendMode: function (value) { this.blendMode = value; return this; } }; module.exports = BlendMode; /***/ }), /* 587 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ var Clamp = __webpack_require__(23); // bitmask flag for GameObject.renderMask var _FLAG = 2; // 0010 /** * Provides methods used for setting the alpha properties of a Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.Alpha * @since 3.0.0 */ var Alpha = { /** * Private internal value. Holds the global alpha value. * * @name Phaser.GameObjects.Components.Alpha#_alpha * @type {float} * @private * @default 1 * @since 3.0.0 */ _alpha: 1, /** * Private internal value. Holds the top-left alpha value. * * @name Phaser.GameObjects.Components.Alpha#_alphaTL * @type {float} * @private * @default 1 * @since 3.0.0 */ _alphaTL: 1, /** * Private internal value. Holds the top-right alpha value. * * @name Phaser.GameObjects.Components.Alpha#_alphaTR * @type {float} * @private * @default 1 * @since 3.0.0 */ _alphaTR: 1, /** * Private internal value. Holds the bottom-left alpha value. * * @name Phaser.GameObjects.Components.Alpha#_alphaBL * @type {float} * @private * @default 1 * @since 3.0.0 */ _alphaBL: 1, /** * Private internal value. Holds the bottom-right alpha value. * * @name Phaser.GameObjects.Components.Alpha#_alphaBR * @type {float} * @private * @default 1 * @since 3.0.0 */ _alphaBR: 1, /** * Clears all alpha values associated with this Game Object. * * Immediately sets the alpha levels back to 1 (fully opaque). * * @method Phaser.GameObjects.Components.Alpha#clearAlpha * @since 3.0.0 * * @return {this} This Game Object instance. */ clearAlpha: function () { return this.setAlpha(1); }, /** * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. * * If your game is running under WebGL you can optionally specify four different alpha values, each of which * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. * * @method Phaser.GameObjects.Components.Alpha#setAlpha * @since 3.0.0 * * @param {float} [topLeft=1] - The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. * @param {float} [topRight] - The alpha value used for the top-right of the Game Object. WebGL only. * @param {float} [bottomLeft] - The alpha value used for the bottom-left of the Game Object. WebGL only. * @param {float} [bottomRight] - The alpha value used for the bottom-right of the Game Object. WebGL only. * * @return {this} This Game Object instance. */ setAlpha: function (topLeft, topRight, bottomLeft, bottomRight) { if (topLeft === undefined) { topLeft = 1; } // Treat as if there is only one alpha value for the whole Game Object if (topRight === undefined) { this.alpha = topLeft; } else { this._alphaTL = Clamp(topLeft, 0, 1); this._alphaTR = Clamp(topRight, 0, 1); this._alphaBL = Clamp(bottomLeft, 0, 1); this._alphaBR = Clamp(bottomRight, 0, 1); } return this; }, /** * The alpha value of the Game Object. * * This is a global value, impacting the entire Game Object, not just a region of it. * * @name Phaser.GameObjects.Components.Alpha#alpha * @type {float} * @since 3.0.0 */ alpha: { get: function () { return this._alpha; }, set: function (value) { var v = Clamp(value, 0, 1); this._alpha = v; this._alphaTL = v; this._alphaTR = v; this._alphaBL = v; this._alphaBR = v; if (v === 0) { this.renderFlags &= ~_FLAG; } else { this.renderFlags |= _FLAG; } } }, /** * The alpha value starting from the top-left of the Game Object. * This value is interpolated from the corner to the center of the Game Object. * * @name Phaser.GameObjects.Components.Alpha#alphaTopLeft * @type {float} * @webglOnly * @since 3.0.0 */ alphaTopLeft: { get: function () { return this._alphaTL; }, set: function (value) { var v = Clamp(value, 0, 1); this._alphaTL = v; if (v !== 0) { this.renderFlags |= _FLAG; } } }, /** * The alpha value starting from the top-right of the Game Object. * This value is interpolated from the corner to the center of the Game Object. * * @name Phaser.GameObjects.Components.Alpha#alphaTopRight * @type {float} * @webglOnly * @since 3.0.0 */ alphaTopRight: { get: function () { return this._alphaTR; }, set: function (value) { var v = Clamp(value, 0, 1); this._alphaTR = v; if (v !== 0) { this.renderFlags |= _FLAG; } } }, /** * The alpha value starting from the bottom-left of the Game Object. * This value is interpolated from the corner to the center of the Game Object. * * @name Phaser.GameObjects.Components.Alpha#alphaBottomLeft * @type {float} * @webglOnly * @since 3.0.0 */ alphaBottomLeft: { get: function () { return this._alphaBL; }, set: function (value) { var v = Clamp(value, 0, 1); this._alphaBL = v; if (v !== 0) { this.renderFlags |= _FLAG; } } }, /** * The alpha value starting from the bottom-right of the Game Object. * This value is interpolated from the corner to the center of the Game Object. * * @name Phaser.GameObjects.Components.Alpha#alphaBottomRight * @type {float} * @webglOnly * @since 3.0.0 */ alphaBottomRight: { get: function () { return this._alphaBR; }, set: function (value) { var v = Clamp(value, 0, 1); this._alphaBR = v; if (v !== 0) { this.renderFlags |= _FLAG; } } } }; module.exports = Alpha; /***/ }), /* 588 */, /* 589 */, /* 590 */, /* 591 */, /* 592 */, /* 593 */, /* 594 */, /* 595 */, /* 596 */, /* 597 */, /* 598 */, /* 599 */, /* 600 */ /***/ (function(module, exports) { /** * 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 (fakeType) { var proto = new Array(); // jshint ignore:line window[fakeType] = 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[fakeType].prototype = proto; window[fakeType].constructor = window[fakeType]; }; 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 } /***/ }), /* 601 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(global) {// References: // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ // https://gist.github.com/1579671 // http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision // https://gist.github.com/timhall/4078614 // https://github.com/Financial-Times/polyfill-service/tree/master/polyfills/requestAnimationFrame // Expected to be used with Browserfiy // Browserify automatically detects the use of `global` and passes the // correct reference of `global`, `self`, and finally `window` // Date.now if (!(Date.now && Date.prototype.getTime)) { Date.now = function now() { return new Date().getTime(); }; } // performance.now if (!(global.performance && global.performance.now)) { var startTime = Date.now(); if (!global.performance) { global.performance = {}; } global.performance.now = function () { return Date.now() - startTime; }; } // requestAnimationFrame var lastTime = Date.now(); var vendors = ['ms', 'moz', 'webkit', 'o']; for(var x = 0; x < vendors.length && !global.requestAnimationFrame; ++x) { global.requestAnimationFrame = global[vendors[x] + 'RequestAnimationFrame']; global.cancelAnimationFrame = global[vendors[x] + 'CancelAnimationFrame'] || global[vendors[x] + 'CancelRequestAnimationFrame']; } if (!global.requestAnimationFrame) { global.requestAnimationFrame = function (callback) { if (typeof callback !== 'function') { throw new TypeError(callback + 'is not a function'); } var currentTime = Date.now(), delay = 16 + lastTime - currentTime; if (delay < 0) { delay = 0; } lastTime = currentTime; return setTimeout(function () { lastTime = Date.now(); callback(performance.now()); }, delay); }; } if (!global.cancelAnimationFrame) { global.cancelAnimationFrame = function(id) { clearTimeout(id); }; } /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(215))) /***/ }), /* 602 */ /***/ (function(module, exports) { /** * performance.now */ (function () { if ('performance' in window === false) { window.performance = {}; } // Thanks IE8 Date.now = (Date.now || function () { return new Date().getTime(); }); if ('now' in window.performance === false) { var nowOffset = Date.now(); if (performance.timing && performance.timing.navigationStart) { nowOffset = performance.timing.navigationStart; } window.performance.now = function now () { return Date.now() - nowOffset; } } })(); /***/ }), /* 603 */ /***/ (function(module, exports) { // 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); }; } /***/ }), /* 604 */ /***/ (function(module, exports) { /** * A polyfill for Function.prototype.bind */ if (!Function.prototype.bind) { /* jshint freeze: false */ 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)) { /* jshint supernew: true */ return new F; } })(target.prototype); return bound; }; })(); } /***/ }), /* 605 */ /***/ (function(module, exports) { /** * 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(){}; } /***/ }), /* 606 */ /***/ (function(module, exports) { /* Copyright 2013 Chris Wilson Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* This monkeypatch library is intended to be included in projects that are written to the proper AudioContext spec (instead of webkitAudioContext), and that use the new naming and proper bits of the Web Audio API (e.g. using BufferSourceNode.start() instead of BufferSourceNode.noteOn()), but may have to run on systems that only support the deprecated bits. This library should be harmless to include if the browser supports unprefixed "AudioContext", and/or if it supports the new names. The patches this library handles: if window.AudioContext is unsupported, it will be aliased to webkitAudioContext(). if AudioBufferSourceNode.start() is unimplemented, it will be routed to noteOn() or noteGrainOn(), depending on parameters. The following aliases only take effect if the new names are not already in place: AudioBufferSourceNode.stop() is aliased to noteOff() AudioContext.createGain() is aliased to createGainNode() AudioContext.createDelay() is aliased to createDelayNode() AudioContext.createScriptProcessor() is aliased to createJavaScriptNode() AudioContext.createPeriodicWave() is aliased to createWaveTable() OscillatorNode.start() is aliased to noteOn() OscillatorNode.stop() is aliased to noteOff() OscillatorNode.setPeriodicWave() is aliased to setWaveTable() AudioParam.setTargetAtTime() is aliased to setTargetValueAtTime() This library does NOT patch the enumerated type changes, as it is recommended in the specification that implementations support both integer and string types for AudioPannerNode.panningModel, AudioPannerNode.distanceModel BiquadFilterNode.type and OscillatorNode.type. */ (function () { function fixSetTarget(param) { if (!param) // if NYI, just return return; if (!param.setTargetAtTime) param.setTargetAtTime = param.setTargetValueAtTime; } if (window.hasOwnProperty('webkitAudioContext') && !window.hasOwnProperty('AudioContext')) { window.AudioContext = webkitAudioContext; if (!AudioContext.prototype.hasOwnProperty('createGain')) AudioContext.prototype.createGain = AudioContext.prototype.createGainNode; if (!AudioContext.prototype.hasOwnProperty('createDelay')) AudioContext.prototype.createDelay = AudioContext.prototype.createDelayNode; if (!AudioContext.prototype.hasOwnProperty('createScriptProcessor')) AudioContext.prototype.createScriptProcessor = AudioContext.prototype.createJavaScriptNode; if (!AudioContext.prototype.hasOwnProperty('createPeriodicWave')) AudioContext.prototype.createPeriodicWave = AudioContext.prototype.createWaveTable; AudioContext.prototype.internal_createGain = AudioContext.prototype.createGain; AudioContext.prototype.createGain = function() { var node = this.internal_createGain(); fixSetTarget(node.gain); return node; }; AudioContext.prototype.internal_createDelay = AudioContext.prototype.createDelay; AudioContext.prototype.createDelay = function(maxDelayTime) { var node = maxDelayTime ? this.internal_createDelay(maxDelayTime) : this.internal_createDelay(); fixSetTarget(node.delayTime); return node; }; AudioContext.prototype.internal_createBufferSource = AudioContext.prototype.createBufferSource; AudioContext.prototype.createBufferSource = function() { var node = this.internal_createBufferSource(); if (!node.start) { node.start = function ( when, offset, duration ) { if ( offset || duration ) this.noteGrainOn( when || 0, offset, duration ); else this.noteOn( when || 0 ); }; } else { node.internal_start = node.start; node.start = function( when, offset, duration ) { if( typeof duration !== 'undefined' ) node.internal_start( when || 0, offset, duration ); else node.internal_start( when || 0, offset || 0 ); }; } if (!node.stop) { node.stop = function ( when ) { this.noteOff( when || 0 ); }; } else { node.internal_stop = node.stop; node.stop = function( when ) { node.internal_stop( when || 0 ); }; } fixSetTarget(node.playbackRate); return node; }; AudioContext.prototype.internal_createDynamicsCompressor = AudioContext.prototype.createDynamicsCompressor; AudioContext.prototype.createDynamicsCompressor = function() { var node = this.internal_createDynamicsCompressor(); fixSetTarget(node.threshold); fixSetTarget(node.knee); fixSetTarget(node.ratio); fixSetTarget(node.reduction); fixSetTarget(node.attack); fixSetTarget(node.release); return node; }; AudioContext.prototype.internal_createBiquadFilter = AudioContext.prototype.createBiquadFilter; AudioContext.prototype.createBiquadFilter = function() { var node = this.internal_createBiquadFilter(); fixSetTarget(node.frequency); fixSetTarget(node.detune); fixSetTarget(node.Q); fixSetTarget(node.gain); return node; }; if (AudioContext.prototype.hasOwnProperty( 'createOscillator' )) { AudioContext.prototype.internal_createOscillator = AudioContext.prototype.createOscillator; AudioContext.prototype.createOscillator = function() { var node = this.internal_createOscillator(); if (!node.start) { node.start = function ( when ) { this.noteOn( when || 0 ); }; } else { node.internal_start = node.start; node.start = function ( when ) { node.internal_start( when || 0); }; } if (!node.stop) { node.stop = function ( when ) { this.noteOff( when || 0 ); }; } else { node.internal_stop = node.stop; node.stop = function( when ) { node.internal_stop( when || 0 ); }; } if (!node.setPeriodicWave) node.setPeriodicWave = node.setWaveTable; fixSetTarget(node.frequency); fixSetTarget(node.detune); return node; }; } } if (window.hasOwnProperty('webkitOfflineAudioContext') && !window.hasOwnProperty('OfflineAudioContext')) { window.OfflineAudioContext = webkitOfflineAudioContext; } })(); /***/ }), /* 607 */ /***/ (function(module, exports) { /** * A polyfill for Array.isArray */ if (!Array.isArray) { Array.isArray = function (arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; } /***/ }), /* 608 */ /***/ (function(module, exports) { /** * 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); } } }; } /***/ }), /* 609 */ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(608); __webpack_require__(607); __webpack_require__(606); __webpack_require__(605); __webpack_require__(604); __webpack_require__(603); __webpack_require__(602); __webpack_require__(601); __webpack_require__(600); /***/ }), /* 610 */, /* 611 */, /* 612 */, /* 613 */, /* 614 */, /* 615 */, /* 616 */, /* 617 */, /* 618 */, /* 619 */, /* 620 */, /* 621 */, /* 622 */, /* 623 */, /* 624 */, /* 625 */, /* 626 */, /* 627 */, /* 628 */, /* 629 */, /* 630 */, /* 631 */, /* 632 */, /* 633 */, /* 634 */, /* 635 */, /* 636 */, /* 637 */, /* 638 */, /* 639 */, /* 640 */, /* 641 */, /* 642 */, /* 643 */, /* 644 */, /* 645 */, /* 646 */, /* 647 */, /* 648 */, /* 649 */, /* 650 */, /* 651 */, /* 652 */, /* 653 */, /* 654 */, /* 655 */, /* 656 */, /* 657 */, /* 658 */, /* 659 */, /* 660 */, /* 661 */, /* 662 */, /* 663 */, /* 664 */, /* 665 */, /* 666 */, /* 667 */, /* 668 */, /* 669 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Renderer.WebGL.Pipelines */ module.exports = { BitmapMaskPipeline: __webpack_require__(260), FlatTintPipeline: __webpack_require__(259), ForwardDiffuseLightPipeline: __webpack_require__(148), TextureTintPipeline: __webpack_require__(129) }; /***/ }), /* 670 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Renderer.WebGL */ module.exports = { Utils: __webpack_require__(27), WebGLPipeline: __webpack_require__(84), WebGLRenderer: __webpack_require__(262), Pipelines: __webpack_require__(669), // Constants BYTE: 0, SHORT: 1, UNSIGNED_BYTE: 2, UNSIGNED_SHORT: 3, FLOAT: 4 }; /***/ }), /* 671 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @callback SnapshotCallback * * @param {HTMLImageElement} snapshot - [description] */ /** * @namespace Phaser.Renderer.Snapshot */ module.exports = { Canvas: __webpack_require__(265), WebGL: __webpack_require__(261) }; /***/ }), /* 672 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @namespace Phaser.Renderer.Canvas */ module.exports = { BlitImage: __webpack_require__(266), CanvasRenderer: __webpack_require__(267), DrawImage: __webpack_require__(264), GetBlendModes: __webpack_require__(263) }; /***/ }), /* 673 */ /***/ (function(module, exports, __webpack_require__) { /** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * @typedef {object} RendererConfig * * @property {boolean} clearBeforeRender - [description] * @property {boolean} pixelArt - [description] * @property {Phaser.Display.Color} backgroundColor - [description] * @property {number} resolution - [description] * @property {boolean} autoResize - [description] * @property {boolean} roundPixels - [description] */ /** * @namespace Phaser.Renderer */ module.exports = { Canvas: __webpack_require__(672), Snapshot: __webpack_require__(671), WebGL: __webpack_require__(670) }; /***/ }), /* 674 */, /* 675 */, /* 676 */, /* 677 */, /* 678 */, /* 679 */, /* 680 */, /* 681 */, /* 682 */, /* 683 */, /* 684 */, /* 685 */, /* 686 */, /* 687 */, /* 688 */, /* 689 */, /* 690 */, /* 691 */, /* 692 */, /* 693 */, /* 694 */, /* 695 */, /* 696 */, /* 697 */, /* 698 */, /* 699 */, /* 700 */, /* 701 */, /* 702 */, /* 703 */, /* 704 */, /* 705 */, /* 706 */, /* 707 */, /* 708 */, /* 709 */, /* 710 */, /* 711 */, /* 712 */, /* 713 */, /* 714 */, /* 715 */, /* 716 */, /* 717 */, /* 718 */, /* 719 */, /* 720 */, /* 721 */, /* 722 */, /* 723 */, /* 724 */, /* 725 */, /* 726 */, /* 727 */, /* 728 */, /* 729 */, /* 730 */, /* 731 */, /* 732 */, /* 733 */, /* 734 */, /* 735 */, /* 736 */, /* 737 */, /* 738 */, /* 739 */, /* 740 */, /* 741 */, /* 742 */, /* 743 */, /* 744 */, /* 745 */, /* 746 */, /* 747 */, /* 748 */, /* 749 */, /* 750 */, /* 751 */, /* 752 */, /* 753 */, /* 754 */, /* 755 */, /* 756 */, /* 757 */, /* 758 */, /* 759 */, /* 760 */, /* 761 */, /* 762 */, /* 763 */, /* 764 */, /* 765 */, /* 766 */, /* 767 */, /* 768 */, /* 769 */, /* 770 */, /* 771 */, /* 772 */, /* 773 */, /* 774 */, /* 775 */, /* 776 */, /* 777 */, /* 778 */, /* 779 */, /* 780 */, /* 781 */, /* 782 */, /* 783 */, /* 784 */, /* 785 */, /* 786 */, /* 787 */, /* 788 */, /* 789 */, /* 790 */, /* 791 */, /* 792 */, /* 793 */, /* 794 */, /* 795 */, /* 796 */, /* 797 */, /* 798 */, /* 799 */, /* 800 */, /* 801 */, /* 802 */, /* 803 */, /* 804 */, /* 805 */, /* 806 */, /* 807 */, /* 808 */, /* 809 */, /* 810 */, /* 811 */, /* 812 */, /* 813 */, /* 814 */, /* 815 */, /* 816 */, /* 817 */, /* 818 */, /* 819 */, /* 820 */, /* 821 */, /* 822 */, /* 823 */, /* 824 */, /* 825 */, /* 826 */, /* 827 */, /* 828 */, /* 829 */, /* 830 */, /* 831 */, /* 832 */, /* 833 */, /* 834 */, /* 835 */, /* 836 */, /* 837 */, /* 838 */, /* 839 */, /* 840 */, /* 841 */, /* 842 */, /* 843 */, /* 844 */, /* 845 */, /* 846 */, /* 847 */, /* 848 */, /* 849 */, /* 850 */, /* 851 */, /* 852 */, /* 853 */, /* 854 */, /* 855 */, /* 856 */, /* 857 */, /* 858 */, /* 859 */, /* 860 */, /* 861 */, /* 862 */, /* 863 */, /* 864 */, /* 865 */, /* 866 */, /* 867 */, /* 868 */, /* 869 */, /* 870 */, /* 871 */, /* 872 */, /* 873 */, /* 874 */, /* 875 */, /* 876 */, /* 877 */, /* 878 */, /* 879 */, /* 880 */, /* 881 */, /* 882 */, /* 883 */, /* 884 */, /* 885 */, /* 886 */, /* 887 */, /* 888 */, /* 889 */, /* 890 */, /* 891 */, /* 892 */, /* 893 */, /* 894 */, /* 895 */, /* 896 */, /* 897 */, /* 898 */, /* 899 */, /* 900 */, /* 901 */, /* 902 */, /* 903 */, /* 904 */, /* 905 */, /* 906 */, /* 907 */, /* 908 */, /* 909 */, /* 910 */, /* 911 */, /* 912 */, /* 913 */, /* 914 */, /* 915 */, /* 916 */, /* 917 */, /* 918 */, /* 919 */, /* 920 */, /* 921 */, /* 922 */, /* 923 */, /* 924 */, /* 925 */, /* 926 */, /* 927 */, /* 928 */, /* 929 */, /* 930 */, /* 931 */, /* 932 */, /* 933 */, /* 934 */, /* 935 */, /* 936 */, /* 937 */, /* 938 */, /* 939 */, /* 940 */, /* 941 */, /* 942 */, /* 943 */, /* 944 */, /* 945 */, /* 946 */, /* 947 */, /* 948 */, /* 949 */, /* 950 */, /* 951 */, /* 952 */, /* 953 */, /* 954 */, /* 955 */, /* 956 */, /* 957 */, /* 958 */, /* 959 */, /* 960 */, /* 961 */, /* 962 */, /* 963 */, /* 964 */, /* 965 */, /* 966 */, /* 967 */, /* 968 */, /* 969 */, /* 970 */, /* 971 */, /* 972 */, /* 973 */, /* 974 */, /* 975 */, /* 976 */, /* 977 */, /* 978 */, /* 979 */, /* 980 */, /* 981 */, /* 982 */, /* 983 */, /* 984 */, /* 985 */, /* 986 */, /* 987 */, /* 988 */, /* 989 */, /* 990 */, /* 991 */, /* 992 */, /* 993 */, /* 994 */, /* 995 */, /* 996 */, /* 997 */, /* 998 */, /* 999 */, /* 1000 */, /* 1001 */, /* 1002 */, /* 1003 */, /* 1004 */, /* 1005 */, /* 1006 */, /* 1007 */, /* 1008 */, /* 1009 */, /* 1010 */, /* 1011 */, /* 1012 */, /* 1013 */, /* 1014 */, /* 1015 */, /* 1016 */, /* 1017 */, /* 1018 */, /* 1019 */, /* 1020 */, /* 1021 */, /* 1022 */, /* 1023 */, /* 1024 */, /* 1025 */, /* 1026 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(global) {/** * @author Richard Davey * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ __webpack_require__(609); var CONST = __webpack_require__(20); var Extend = __webpack_require__(17); /** * @namespace Phaser */ var Phaser = { Animation: __webpack_require__(568), Cache: __webpack_require__(567), Cameras: { Scene2D: __webpack_require__(566) }, Class: __webpack_require__(0), Data: __webpack_require__(544), Display: { Masks: __webpack_require__(538) }, Events: __webpack_require__(536), Game: __webpack_require__(534), GameObjects: { DisplayList: __webpack_require__(504), GameObjectCreator: __webpack_require__(13), GameObjectFactory: __webpack_require__(11), UpdateList: __webpack_require__(476), Components: __webpack_require__(15), BuildGameObject: __webpack_require__(24), BuildGameObjectAnimation: __webpack_require__(127), GameObject: __webpack_require__(2), Graphics: __webpack_require__(115), Image: __webpack_require__(69), Sprite: __webpack_require__(34), Text: __webpack_require__(110), Factories: { Graphics: __webpack_require__(410), Image: __webpack_require__(409), Sprite: __webpack_require__(408), Text: __webpack_require__(407) }, Creators: { Graphics: __webpack_require__(406), Image: __webpack_require__(405), Sprite: __webpack_require__(404), Text: __webpack_require__(403) } }, Input: __webpack_require__(383), Loader: { FileTypes: { AnimationJSONFile: __webpack_require__(360), AtlasJSONFile: __webpack_require__(359), AudioFile: __webpack_require__(168), AudioSpriteFile: __webpack_require__(358), HTML5AudioFile: __webpack_require__(167), ImageFile: __webpack_require__(37), JSONFile: __webpack_require__(28), MultiAtlasFile: __webpack_require__(357), PluginFile: __webpack_require__(356), ScriptFile: __webpack_require__(355), SpriteSheetFile: __webpack_require__(354), TextFile: __webpack_require__(224), XMLFile: __webpack_require__(143) }, File: __webpack_require__(19), FileTypesManager: __webpack_require__(7), GetURL: __webpack_require__(108), LoaderPlugin: __webpack_require__(353), MergeXHRSettings: __webpack_require__(107), MultiFile: __webpack_require__(36), XHRLoader: __webpack_require__(169), XHRSettings: __webpack_require__(75) }, Math: { Between: __webpack_require__(149), DegToRad: __webpack_require__(38), FloatBetween: __webpack_require__(248), RadToDeg: __webpack_require__(150), Vector2: __webpack_require__(6) }, Plugins: __webpack_require__(330), Renderer: __webpack_require__(673), Scene: __webpack_require__(193), Scenes: __webpack_require__(328), Sound: __webpack_require__(326), Structs: __webpack_require__(325), Textures: __webpack_require__(324), Time: __webpack_require__(308), Tweens: __webpack_require__(306) }; // Merge in the consts Phaser = Extend(false, Phaser, CONST); // Export it module.exports = Phaser; global.Phaser = Phaser; /* * "Documentation is like pizza: when it is good, it is very, very good; * and when it is bad, it is better than nothing." * -- Dick Brandon */ /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(215))) /***/ }) /******/ ]); });