From 128149617fc7bffb3b2eab907187ebc16242d3a2 Mon Sep 17 00:00:00 2001 From: redmi Date: Wed, 16 Apr 2025 11:07:11 +0800 Subject: [PATCH 01/11] replace NOOP to empty method --- src/sound/BaseSound.js | 5 ++- src/sound/BaseSoundManager.js | 21 +++++++--- src/sound/noaudio/NoAudioSoundManager.js | 53 +++++++++++++++++------- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/sound/BaseSound.js b/src/sound/BaseSound.js index 4ca93423af..2c172945b1 100644 --- a/src/sound/BaseSound.js +++ b/src/sound/BaseSound.js @@ -9,7 +9,6 @@ var Class = require('../utils/Class'); var EventEmitter = require('eventemitter3'); var Events = require('./events'); var Extend = require('../utils/object/Extend'); -var NOOP = require('../utils/NOOP'); /** * @classdesc @@ -446,7 +445,9 @@ var BaseSound = new Class({ * @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, + update: function () + { + }, /** * Method used internally to calculate total playback rate of the sound. diff --git a/src/sound/BaseSoundManager.js b/src/sound/BaseSoundManager.js index d0bcedd563..d77d7bd8fb 100644 --- a/src/sound/BaseSoundManager.js +++ b/src/sound/BaseSoundManager.js @@ -12,7 +12,6 @@ var Events = require('./events'); var GameEvents = require('../core/events'); var GetAll = require('../utils/array/GetAll'); var GetFirst = require('../utils/array/GetFirst'); -var NOOP = require('../utils/NOOP'); var Vector2 = require('../math/Vector2'); /** @@ -193,7 +192,9 @@ var BaseSoundManager = new Class({ * * @return {Phaser.Sound.BaseSound} The new sound instance. */ - add: NOOP, + add: function () + { + }, /** * Adds a new audio sprite sound into the sound manager. @@ -494,7 +495,9 @@ var BaseSoundManager = new Class({ * @param {number} [x] - The x position of the Spatial Audio listener. * @param {number} [y] - The y position of the Spatial Audio listener. */ - setListenerPosition: NOOP, + setListenerPosition: function () + { + }, /** * Stops all the sounds in the game. @@ -592,7 +595,9 @@ var BaseSoundManager = new Class({ * @protected * @since 3.0.0 */ - unlock: NOOP, + unlock: function () + { + }, /** * Method used internally for pausing sound manager if @@ -603,7 +608,9 @@ var BaseSoundManager = new Class({ * @protected * @since 3.0.0 */ - onBlur: NOOP, + onBlur: function () + { + }, /** * Method used internally for resuming sound manager if @@ -614,7 +621,9 @@ var BaseSoundManager = new Class({ * @protected * @since 3.0.0 */ - onFocus: NOOP, + onFocus: function () + { + }, /** * Internal handler for Phaser.Core.Events#BLUR. diff --git a/src/sound/noaudio/NoAudioSoundManager.js b/src/sound/noaudio/NoAudioSoundManager.js index 05c03cedea..cfc8095b38 100644 --- a/src/sound/noaudio/NoAudioSoundManager.js +++ b/src/sound/noaudio/NoAudioSoundManager.js @@ -9,7 +9,6 @@ var BaseSoundManager = require('../BaseSoundManager'); var Class = require('../../utils/Class'); var EventEmitter = require('eventemitter3'); var NoAudioSound = require('./NoAudioSound'); -var NOOP = require('../../utils/NOOP'); /** * @classdesc @@ -227,7 +226,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#onBlur * @since 3.0.0 */ - onBlur: NOOP, + onBlur: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -235,7 +236,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#onFocus * @since 3.0.0 */ - onFocus: NOOP, + onFocus: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -243,7 +246,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#onGameBlur * @since 3.0.0 */ - onGameBlur: NOOP, + onGameBlur: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -251,7 +256,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#onGameFocus * @since 3.0.0 */ - onGameFocus: NOOP, + onGameFocus: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -259,7 +266,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#pauseAll * @since 3.0.0 */ - pauseAll: NOOP, + pauseAll: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -267,7 +276,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#resumeAll * @since 3.0.0 */ - resumeAll: NOOP, + resumeAll: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -275,7 +286,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#stopAll * @since 3.0.0 */ - stopAll: NOOP, + stopAll: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -283,7 +296,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#update * @since 3.0.0 */ - update: NOOP, + update: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -293,7 +308,9 @@ var NoAudioSoundManager = new Class({ * * @return {this} This Sound Manager. */ - setRate: NOOP, + setRate: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -303,7 +320,9 @@ var NoAudioSoundManager = new Class({ * * @return {this} This Sound Manager. */ - setDetune: NOOP, + setDetune: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -311,7 +330,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#setMute * @since 3.0.0 */ - setMute: NOOP, + setMute: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -319,7 +340,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#setVolume * @since 3.0.0 */ - setVolume: NOOP, + setVolume: function () + { + }, /** * Empty function for the No Audio Sound Manager. @@ -327,7 +350,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#unlock * @since 3.0.0 */ - unlock: NOOP, + unlock: function () + { + }, /** * Method used internally for iterating only over active sounds and skipping sounds that are marked for removal. From 8695308e8abc54d780a31db0c40de9d89483a0b9 Mon Sep 17 00:00:00 2001 From: redmi Date: Wed, 16 Apr 2025 11:18:43 +0800 Subject: [PATCH 02/11] replace 'return false null this' to method --- src/sound/noaudio/NoAudioSound.js | 100 ++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 32 deletions(-) diff --git a/src/sound/noaudio/NoAudioSound.js b/src/sound/noaudio/NoAudioSound.js index ffe836e4f6..d165a2d60b 100644 --- a/src/sound/noaudio/NoAudioSound.js +++ b/src/sound/noaudio/NoAudioSound.js @@ -11,21 +11,6 @@ var EventEmitter = require('eventemitter3'); var Extend = require('../../utils/object/Extend'); var NOOP = require('../../utils/NOOP'); -var returnFalse = function () -{ - return false; -}; - -var returnNull = function () -{ - return null; -}; - -var returnThis = function () -{ - return this; -}; - /** * @classdesc * No audio implementation of the sound. It is used if audio has been @@ -288,7 +273,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - addMarker: returnFalse, + addMarker: function () + { + return false; + }, /** * @method Phaser.Sound.NoAudioSound#updateMarker @@ -298,7 +286,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - updateMarker: returnFalse, + updateMarker: function () + { + return false; + }, /** * @method Phaser.Sound.NoAudioSound#removeMarker @@ -308,7 +299,10 @@ var NoAudioSound = new Class({ * * @return {null} null */ - removeMarker: returnNull, + removeMarker: function () + { + return null; + }, /** * @method Phaser.Sound.NoAudioSound#play @@ -319,7 +313,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - play: returnFalse, + play: function () + { + return false; + }, /** * @method Phaser.Sound.NoAudioSound#pause @@ -327,7 +324,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - pause: returnFalse, + pause: function () + { + return false; + }, /** * Resumes the sound. @@ -337,7 +337,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - resume: returnFalse, + resume: function () + { + return false; + }, /** * Stop playing this sound. @@ -347,7 +350,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - stop: returnFalse, + stop: function () + { + return false; + }, /** * Sets the muted state of this Sound. @@ -359,7 +365,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setMute: returnThis, + setMute: function () + { + return this; + }, /** * Sets the volume of this Sound. @@ -371,7 +380,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setVolume: returnThis, + setVolume: function () + { + return this; + }, /** * Sets the playback rate of this Sound. @@ -386,7 +398,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setRate: returnThis, + setRate: function () + { + return this; + }, /** * Sets the detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -399,7 +414,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setDetune: returnThis, + setDetune: function () + { + return this; + }, /** * Seeks to a specific point in this sound. @@ -411,7 +429,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setSeek: returnThis, + setSeek: function () + { + return this; + }, /** * Sets the loop state of this Sound. @@ -423,7 +444,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setLoop: returnThis, + setLoop: function () + { + return this; + }, /** * Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). @@ -437,7 +461,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setPan: returnThis, + setPan: function () + { + return this; + }, /** * Method used internally for applying config values to some of the sound properties. @@ -445,7 +472,10 @@ var NoAudioSound = new Class({ * @method Phaser.Sound.NoAudioSound#applyConfig * @since 3.0.0 */ - applyConfig: returnNull, + applyConfig: function () + { + return null; + }, /** * Method used internally for resetting values of some of the config properties. @@ -453,7 +483,10 @@ var NoAudioSound = new Class({ * @method Phaser.Sound.NoAudioSound#resetConfig * @since 3.0.0 */ - resetConfig: returnNull, + resetConfig: function () + { + return null; + }, /** * Update method called automatically by sound manager on every game step. @@ -473,7 +506,10 @@ var NoAudioSound = new Class({ * @method Phaser.Sound.NoAudioSound#calculateRate * @since 3.0.0 */ - calculateRate: returnNull, + calculateRate: function () + { + return null; + }, /** * Destroys this sound and all associated events and marks it for removal from the sound manager. From 382def8d5d0509ae36c424c05cf6d9ad5eb17cd9 Mon Sep 17 00:00:00 2001 From: redmi Date: Wed, 16 Apr 2025 11:21:26 +0800 Subject: [PATCH 03/11] replace NOOP to empty method --- src/sound/noaudio/NoAudioSound.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sound/noaudio/NoAudioSound.js b/src/sound/noaudio/NoAudioSound.js index d165a2d60b..550c8520b1 100644 --- a/src/sound/noaudio/NoAudioSound.js +++ b/src/sound/noaudio/NoAudioSound.js @@ -9,7 +9,6 @@ var BaseSound = require('../BaseSound'); var Class = require('../../utils/Class'); var EventEmitter = require('eventemitter3'); var Extend = require('../../utils/object/Extend'); -var NOOP = require('../../utils/NOOP'); /** * @classdesc @@ -498,7 +497,9 @@ var NoAudioSound = new Class({ * @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, + update: function () + { + }, /** * Method used internally to calculate total playback rate of the sound. From 60a6efb8402e7a8e441173f766bc1e653194d6ab Mon Sep 17 00:00:00 2001 From: redmi Date: Wed, 16 Apr 2025 13:26:14 +0800 Subject: [PATCH 04/11] needs to empty between initialize and function --- src/curves/LineCurve.js | 2 +- src/loader/filetypes/AnimationJSONFile.js | 3 +-- src/loader/filetypes/AudioFile.js | 2 +- src/loader/filetypes/JSONFile.js | 3 +-- src/loader/filetypes/PackFile.js | 3 +-- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/curves/LineCurve.js b/src/curves/LineCurve.js index 65b0c9d5c6..91901743cc 100644 --- a/src/curves/LineCurve.js +++ b/src/curves/LineCurve.js @@ -29,9 +29,9 @@ var LineCurve = new Class({ Extends: Curve, + // vec2s or array initialize: - // vec2s or array function LineCurve (p0, p1) { Curve.call(this, 'LineCurve'); diff --git a/src/loader/filetypes/AnimationJSONFile.js b/src/loader/filetypes/AnimationJSONFile.js index 4c88728e8f..caea21a126 100644 --- a/src/loader/filetypes/AnimationJSONFile.js +++ b/src/loader/filetypes/AnimationJSONFile.js @@ -33,10 +33,9 @@ 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 + initialize: function AnimationJSONFile (loader, key, url, xhrSettings, dataKey) { diff --git a/src/loader/filetypes/AudioFile.js b/src/loader/filetypes/AudioFile.js index af807329f7..179993621b 100644 --- a/src/loader/filetypes/AudioFile.js +++ b/src/loader/filetypes/AudioFile.js @@ -36,9 +36,9 @@ var AudioFile = new Class({ Extends: File, + // URL is an object created by AudioFile.findAudioURL initialize: - // URL is an object created by AudioFile.findAudioURL function AudioFile (loader, key, urlConfig, xhrSettings, audioContext) { if (IsPlainObject(key)) diff --git a/src/loader/filetypes/JSONFile.js b/src/loader/filetypes/JSONFile.js index e524cf85ac..c7574a75b8 100644 --- a/src/loader/filetypes/JSONFile.js +++ b/src/loader/filetypes/JSONFile.js @@ -36,10 +36,9 @@ 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 + initialize: function JSONFile (loader, key, url, xhrSettings, dataKey) { diff --git a/src/loader/filetypes/PackFile.js b/src/loader/filetypes/PackFile.js index 653c9bc91f..21c70ccd65 100644 --- a/src/loader/filetypes/PackFile.js +++ b/src/loader/filetypes/PackFile.js @@ -33,10 +33,9 @@ var PackFile = 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 + initialize: function PackFile (loader, key, url, xhrSettings, dataKey) { From 60da19f98ac224225d342deca38badb2b4d7260d Mon Sep 17 00:00:00 2001 From: redmi Date: Wed, 16 Apr 2025 13:27:08 +0800 Subject: [PATCH 05/11] name for initialize --- src/renderer/webgl/renderNodes/BatchHandlerPointLight.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js b/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js index 8ed631c2f7..c22cd2d321 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js @@ -25,7 +25,7 @@ var BatchHandlerPointLight = new Class({ Extends: BatchHandler, - initialize: function (manager, config) + initialize: function BatchHandlerPointLight (manager, config) { BatchHandler.call(this, manager, this.defaultConfig, config); From 7b5ba6f7acf3fd5346d233fcb9fed518a2fc61f7 Mon Sep 17 00:00:00 2001 From: redmi Date: Wed, 16 Apr 2025 23:44:35 +0800 Subject: [PATCH 06/11] add override param --- src/utils/Class.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/Class.js b/src/utils/Class.js index 84def02a4a..b19d549250 100644 --- a/src/utils/Class.js +++ b/src/utils/Class.js @@ -75,8 +75,9 @@ function hasNonConfigurable (obj, k) * @param {Object} definition A dictionary of functions for the class. * @param {boolean} isClassDescriptor Is the definition a class descriptor? * @param {Object} [extend] The parent constructor object. + * @param {boolean} [override=true] Overrides same property. */ -function extend (ctor, definition, isClassDescriptor, extend) +function extend (ctor, definition, isClassDescriptor, extend, override = true) { for (var k in definition) { @@ -85,6 +86,11 @@ function extend (ctor, definition, isClassDescriptor, extend) continue; } + if (!override && Object.hasOwn(ctor.prototype, k)) + { + continue; + } + var def = getProperty(definition, k, isClassDescriptor); if (def !== false) @@ -125,8 +131,9 @@ function extend (ctor, definition, isClassDescriptor, extend) * @ignore * @param {Object} myClass The constructor object to mix into. * @param {Object|Array} mixins The mixins to apply to the constructor. + * @param {boolean} [override=true] Overrides same property. */ -function mixin (myClass, mixins) +function mixin (myClass, mixins, override = true) { if (!mixins) { @@ -140,7 +147,7 @@ function mixin (myClass, mixins) for (var i = 0; i < mixins.length; i++) { - extend(myClass, mixins[i].prototype || mixins[i]); + extend(myClass, mixins[i].prototype || mixins[i], undefined, undefined, override); } } From 521b283cdac5f5738b96bd5f18a95a47d37662cc Mon Sep 17 00:00:00 2001 From: redmi Date: Thu, 17 Apr 2025 01:08:07 +0800 Subject: [PATCH 07/11] format --- src/renderer/webgl/renderNodes/BatchHandler.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/renderer/webgl/renderNodes/BatchHandler.js b/src/renderer/webgl/renderNodes/BatchHandler.js index 15db072d47..a9e5c45f24 100644 --- a/src/renderer/webgl/renderNodes/BatchHandler.js +++ b/src/renderer/webgl/renderNodes/BatchHandler.js @@ -363,7 +363,9 @@ var BatchHandler = new Class({ * @param {number} width - The new width of the renderer. * @param {number} height - The new height of the renderer. */ - resize: function (width, height) {}, + resize: function (width, height) + { + }, /** * Update the number of draw calls per batch. @@ -377,7 +379,9 @@ var BatchHandler = new Class({ * @since 4.0.0 * @param {number} [count] - The new number of draw calls per batch. If undefined, the maximum number of texture units is used. */ - updateTextureCount: function (count) {}, + updateTextureCount: function (count) + { + }, /** * Draw then empty the current batch. @@ -392,7 +396,9 @@ var BatchHandler = new Class({ * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. * @param {...*} [args] - Additional arguments to pass to the batch handler. */ - run: function (drawingContext) {}, + run: function (drawingContext) + { + }, /** * Add an instance to the batch. Game objects call this method to add @@ -402,7 +408,9 @@ var BatchHandler = new Class({ * @param {...*} [args] - Arguments to pass to the batch handler. These will vary depending on the handler. * @since 4.0.0 */ - batch: function () {} + batch: function () + { + } }); module.exports = BatchHandler; From dbe2d612bd754ce2e742a4e3f840e30596b80a93 Mon Sep 17 00:00:00 2001 From: redmi Date: Thu, 17 Apr 2025 01:12:37 +0800 Subject: [PATCH 08/11] format --- src/renderer/webgl/renderNodes/RenderNode.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/webgl/renderNodes/RenderNode.js b/src/renderer/webgl/renderNodes/RenderNode.js index 9c06894343..f4263a1b0a 100644 --- a/src/renderer/webgl/renderNodes/RenderNode.js +++ b/src/renderer/webgl/renderNodes/RenderNode.js @@ -82,7 +82,8 @@ var RenderNode = new Class({ * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The context currently in use. */ onRunBegin: function (drawingContext) - {}, + { + }, /** * By default this is an empty method hook that you can override and use in your own custom render nodes. @@ -95,7 +96,8 @@ var RenderNode = new Class({ * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The context currently in use. */ onRunEnd: function (drawingContext) - {}, + { + }, /** * Set whether the node should report debug information. From fc8530bcfde3872ad33d0114ff44c883440f70c3 Mon Sep 17 00:00:00 2001 From: redmi Date: Thu, 17 Apr 2025 01:34:37 +0800 Subject: [PATCH 09/11] class syntax batch replace by `src/a.php` script --- src/a.php | 77 ++ src/animations/Animation.js | 100 +- src/animations/AnimationFrame.js | 16 +- src/animations/AnimationManager.js | 92 +- src/animations/AnimationState.js | 179 ++-- src/cache/BaseCache.js | 36 +- src/cache/CacheManager.js | 16 +- src/cameras/2d/BaseCamera.js | 423 ++++---- src/cameras/2d/Camera.js | 88 +- src/cameras/2d/CameraManager.js | 80 +- src/cameras/2d/effects/Fade.js | 36 +- src/cameras/2d/effects/Flash.js | 36 +- src/cameras/2d/effects/Pan.js | 28 +- src/cameras/2d/effects/RotateTo.js | 28 +- src/cameras/2d/effects/Shake.js | 32 +- src/cameras/2d/effects/Zoom.js | 28 +- src/cameras/controls/FixedKeyControl.js | 28 +- src/cameras/controls/SmoothedKeyControl.js | 28 +- src/core/Config.js | 8 +- src/core/Game.js | 68 +- src/core/TimeStep.js | 76 +- src/curves/CubicBezierCurve.js | 32 +- src/curves/Curve.js | 72 +- src/curves/EllipseCurve.js | 231 ++--- src/curves/LineCurve.js | 48 +- src/curves/QuadraticBezierCurve.js | 32 +- src/curves/SplineCurve.js | 36 +- src/curves/path/MoveTo.js | 28 +- src/curves/path/Path.js | 108 +- src/data/DataManager.js | 112 +- src/data/DataManagerPlugin.js | 28 +- src/display/ColorMatrix.js | 96 +- src/display/RGB.js | 87 +- src/display/color/Color.js | 360 +++---- src/display/mask/GeometryMask.js | 24 +- src/display/shader/BaseShader.js | 6 +- src/dom/RequestAnimationFrame.js | 20 +- src/events/EventEmitter.js | 20 +- src/filters/Barrel.js | 9 +- src/filters/Blend.js | 13 +- src/filters/Blur.js | 40 +- src/filters/Bokeh.js | 14 +- src/filters/ColorMatrix.js | 13 +- src/filters/Controller.js | 22 +- src/filters/Displacement.js | 17 +- src/filters/Glow.js | 61 +- src/filters/Mask.js | 25 +- src/filters/ParallelFilters.js | 9 +- src/filters/Pixelate.js | 9 +- src/filters/Sampler.js | 9 +- src/filters/Shadow.js | 41 +- src/filters/Threshold.js | 17 +- src/gameobjects/DisplayList.js | 52 +- src/gameobjects/GameObject.js | 115 ++- src/gameobjects/GameObjectCreator.js | 24 +- src/gameobjects/GameObjectFactory.js | 28 +- src/gameobjects/UpdateList.js | 32 +- .../bitmaptext/dynamic/DynamicBitmapText.js | 37 +- .../bitmaptext/static/BitmapText.js | 302 +++--- src/gameobjects/blitter/Blitter.js | 86 +- src/gameobjects/blitter/Bob.js | 94 +- src/gameobjects/captureframe/CaptureFrame.js | 45 +- src/gameobjects/components/FilterList.js | 82 +- src/gameobjects/components/TransformMatrix.js | 346 +++---- src/gameobjects/container/Container.js | 336 +++--- src/gameobjects/domelement/DOMElement.js | 138 ++- src/gameobjects/extern/Extern.js | 59 +- src/gameobjects/graphics/Graphics.js | 242 +++-- src/gameobjects/group/Group.js | 240 +++-- src/gameobjects/image/Image.js | 62 +- src/gameobjects/layer/Layer.js | 145 ++- src/gameobjects/lights/Light.js | 146 ++- src/gameobjects/lights/LightsManager.js | 56 +- src/gameobjects/lights/LightsPlugin.js | 20 +- src/gameobjects/nineslice/NineSlice.js | 245 ++--- src/gameobjects/nineslice/NineSliceVertex.js | 20 +- src/gameobjects/particles/EmitterColorOp.js | 32 +- src/gameobjects/particles/EmitterOp.js | 92 +- src/gameobjects/particles/GravityWell.js | 77 +- src/gameobjects/particles/Particle.js | 48 +- src/gameobjects/particles/ParticleBounds.js | 16 +- src/gameobjects/particles/ParticleEmitter.js | 958 ++++++++---------- .../particles/ParticleProcessor.js | 16 +- src/gameobjects/particles/zones/DeathZone.js | 12 +- src/gameobjects/particles/zones/EdgeZone.js | 20 +- src/gameobjects/particles/zones/RandomZone.js | 12 +- src/gameobjects/pathfollower/PathFollower.js | 25 +- src/gameobjects/pointlight/PointLight.js | 115 +-- .../rendertexture/RenderTexture.js | 93 +- src/gameobjects/rope/Rope.js | 168 ++- src/gameobjects/shader/Shader.js | 70 +- src/gameobjects/shape/Shape.js | 118 +-- src/gameobjects/shape/arc/Arc.js | 152 ++- src/gameobjects/shape/curve/Curve.js | 50 +- src/gameobjects/shape/ellipse/Ellipse.js | 54 +- src/gameobjects/shape/grid/Grid.js | 33 +- src/gameobjects/shape/isobox/IsoBox.js | 33 +- .../shape/isotriangle/IsoTriangle.js | 37 +- src/gameobjects/shape/line/Line.js | 29 +- src/gameobjects/shape/polygon/Polygon.js | 33 +- src/gameobjects/shape/rectangle/Rectangle.js | 41 +- src/gameobjects/shape/star/Star.js | 100 +- src/gameobjects/shape/triangle/Triangle.js | 29 +- src/gameobjects/sprite/Sprite.js | 118 ++- .../spritegpulayer/SpriteGPULayer.js | 136 +-- src/gameobjects/stamp/Stamp.js | 29 +- src/gameobjects/text/Text.js | 229 ++--- src/gameobjects/text/TextStyle.js | 124 ++- src/gameobjects/tilesprite/TileSprite.js | 217 ++-- src/gameobjects/video/Video.js | 302 +++--- src/gameobjects/zone/Zone.js | 105 +- src/geom/circle/Circle.js | 158 ++- src/geom/ellipse/Ellipse.js | 128 ++- src/geom/line/Line.js | 152 ++- src/geom/polygon/Polygon.js | 24 +- src/geom/rectangle/Rectangle.js | 218 ++-- src/geom/triangle/Triangle.js | 228 ++--- src/input/InputManager.js | 104 +- src/input/InputPlugin.js | 425 ++++---- src/input/Pointer.js | 177 ++-- src/input/gamepad/Axis.js | 20 +- src/input/gamepad/Button.js | 16 +- src/input/gamepad/Gamepad.js | 198 ++-- src/input/gamepad/GamepadPlugin.js | 115 +-- src/input/keyboard/KeyboardManager.js | 40 +- src/input/keyboard/KeyboardPlugin.js | 103 +- src/input/keyboard/combo/KeyCombo.js | 23 +- src/input/keyboard/keys/Key.js | 36 +- src/input/mouse/MouseManager.js | 36 +- src/input/touch/TouchManager.js | 28 +- src/loader/File.js | 64 +- src/loader/LoaderPlugin.js | 112 +- src/loader/MultiFile.js | 32 +- src/loader/filetypes/AnimationJSONFile.js | 20 +- src/loader/filetypes/AsepriteFile.js | 18 +- src/loader/filetypes/AtlasJSONFile.js | 18 +- src/loader/filetypes/AtlasXMLFile.js | 18 +- src/loader/filetypes/AudioFile.js | 16 +- src/loader/filetypes/AudioSpriteFile.js | 22 +- src/loader/filetypes/BinaryFile.js | 16 +- src/loader/filetypes/BitmapFontFile.js | 18 +- src/loader/filetypes/CSSFile.js | 16 +- src/loader/filetypes/CompressedTextureFile.js | 28 +- src/loader/filetypes/FontFile.js | 16 +- src/loader/filetypes/GLSLFile.js | 20 +- src/loader/filetypes/HTML5AudioFile.js | 28 +- src/loader/filetypes/HTMLFile.js | 16 +- src/loader/filetypes/HTMLTextureFile.js | 20 +- src/loader/filetypes/ImageFile.js | 28 +- src/loader/filetypes/JSONFile.js | 16 +- src/loader/filetypes/MultiAtlasFile.js | 20 +- src/loader/filetypes/MultiScriptFile.js | 16 +- src/loader/filetypes/PackFile.js | 16 +- src/loader/filetypes/PluginFile.js | 16 +- src/loader/filetypes/SVGFile.js | 20 +- src/loader/filetypes/SceneFile.js | 20 +- src/loader/filetypes/ScenePluginFile.js | 16 +- src/loader/filetypes/ScriptFile.js | 16 +- src/loader/filetypes/SpriteSheetFile.js | 16 +- src/loader/filetypes/TextFile.js | 16 +- src/loader/filetypes/TilemapCSVFile.js | 20 +- src/loader/filetypes/TilemapImpactFile.js | 16 +- src/loader/filetypes/TilemapJSONFile.js | 16 +- src/loader/filetypes/UnityAtlasFile.js | 18 +- src/loader/filetypes/VideoFile.js | 20 +- src/loader/filetypes/XMLFile.js | 16 +- src/math/Euler.js | 108 +- src/math/Matrix3.js | 72 +- src/math/Matrix4.js | 172 ++-- src/math/Quaternion.js | 192 ++-- src/math/Vector2.js | 164 ++- src/math/Vector3.js | 168 ++- src/math/Vector4.js | 88 +- .../RandomDataGenerator.js | 88 +- src/physics/arcade/ArcadeImage.js | 47 +- src/physics/arcade/ArcadePhysics.js | 104 +- src/physics/arcade/ArcadeSprite.js | 47 +- src/physics/arcade/Body.js | 367 ++++--- src/physics/arcade/Collider.js | 20 +- src/physics/arcade/Factory.js | 56 +- src/physics/arcade/PhysicsGroup.js | 41 +- src/physics/arcade/StaticBody.js | 187 ++-- src/physics/arcade/StaticPhysicsGroup.js | 37 +- src/physics/arcade/World.js | 188 ++-- src/physics/matter-js/BodyBounds.js | 48 +- src/physics/matter-js/Factory.js | 116 ++- src/physics/matter-js/MatterImage.js | 41 +- src/physics/matter-js/MatterPhysics.js | 124 ++- src/physics/matter-js/MatterSprite.js | 41 +- src/physics/matter-js/MatterTileBody.js | 55 +- src/physics/matter-js/PointerConstraint.js | 36 +- src/physics/matter-js/World.js | 180 ++-- src/plugins/BasePlugin.js | 24 +- src/plugins/PluginManager.js | 88 +- src/plugins/ScenePlugin.js | 20 +- src/renderer/canvas/CanvasRenderer.js | 80 +- src/renderer/webgl/DrawingContext.js | 76 +- src/renderer/webgl/DrawingContextPool.js | 30 +- src/renderer/webgl/ProgramManager.js | 70 +- src/renderer/webgl/ShaderProgramFactory.js | 22 +- src/renderer/webgl/WebGLRenderer.js | 244 +++-- .../webgl/renderNodes/BatchHandler.js | 33 +- .../renderNodes/BatchHandlerPointLight.js | 28 +- .../webgl/renderNodes/BatchHandlerQuad.js | 51 +- .../webgl/renderNodes/BatchHandlerStrip.js | 19 +- .../renderNodes/BatchHandlerTileSprite.js | 23 +- .../webgl/renderNodes/BatchHandlerTriFlat.js | 35 +- src/renderer/webgl/renderNodes/Camera.js | 13 +- src/renderer/webgl/renderNodes/DrawLine.js | 13 +- .../renderNodes/DynamicTextureHandler.js | 17 +- src/renderer/webgl/renderNodes/FillCamera.js | 13 +- src/renderer/webgl/renderNodes/FillPath.js | 13 +- src/renderer/webgl/renderNodes/FillRect.js | 13 +- src/renderer/webgl/renderNodes/FillTri.js | 13 +- .../webgl/renderNodes/ListCompositor.js | 13 +- .../webgl/renderNodes/RebindContext.js | 13 +- src/renderer/webgl/renderNodes/RenderNode.js | 24 +- .../webgl/renderNodes/RenderNodeManager.js | 57 +- src/renderer/webgl/renderNodes/ShaderQuad.js | 25 +- src/renderer/webgl/renderNodes/StrokePath.js | 13 +- .../webgl/renderNodes/YieldContext.js | 13 +- .../webgl/renderNodes/filters/BaseFilter.js | 13 +- .../renderNodes/filters/BaseFilterShader.js | 25 +- .../webgl/renderNodes/filters/FilterBarrel.js | 13 +- .../webgl/renderNodes/filters/FilterBlend.js | 21 +- .../webgl/renderNodes/filters/FilterBlur.js | 13 +- .../renderNodes/filters/FilterBlurHigh.js | 13 +- .../renderNodes/filters/FilterBlurLow.js | 13 +- .../renderNodes/filters/FilterBlurMed.js | 13 +- .../webgl/renderNodes/filters/FilterBokeh.js | 13 +- .../renderNodes/filters/FilterColorMatrix.js | 13 +- .../renderNodes/filters/FilterDisplacement.js | 17 +- .../webgl/renderNodes/filters/FilterGlow.js | 17 +- .../webgl/renderNodes/filters/FilterMask.js | 17 +- .../filters/FilterParallelFilters.js | 13 +- .../renderNodes/filters/FilterPixelate.js | 13 +- .../renderNodes/filters/FilterSampler.js | 13 +- .../webgl/renderNodes/filters/FilterShadow.js | 13 +- .../renderNodes/filters/FilterThreshold.js | 13 +- .../renderNodes/submitter/SubmitterQuad.js | 19 +- .../submitter/SubmitterSpriteGPULayer.js | 27 +- .../renderNodes/submitter/SubmitterTile.js | 15 +- .../submitter/SubmitterTileSprite.js | 15 +- .../submitter/SubmitterTilemapGPULayer.js | 27 +- .../renderNodes/texturer/TexturerImage.js | 13 +- .../texturer/TexturerTileSprite.js | 13 +- .../transformer/TransformerImage.js | 15 +- .../transformer/TransformerStamp.js | 16 +- .../transformer/TransformerTile.js | 15 +- .../transformer/TransformerTileSprite.js | 15 +- .../webgl/wrappers/WebGLBufferWrapper.js | 32 +- .../webgl/wrappers/WebGLFramebufferWrapper.js | 20 +- .../webgl/wrappers/WebGLGlobalWrapper.js | 128 ++- .../webgl/wrappers/WebGLProgramWrapper.js | 40 +- .../wrappers/WebGLShaderSetterWrapper.js | 6 +- .../wrappers/WebGLTextureUnitsWrapper.js | 24 +- .../webgl/wrappers/WebGLTextureWrapper.js | 52 +- .../webgl/wrappers/WebGLVAOWrapper.js | 18 +- .../WebGLVertexBufferLayoutWrapper.js | 10 +- src/scale/ScaleManager.js | 229 ++--- src/scene/Scene.js | 12 +- src/scene/SceneManager.js | 168 ++- src/scene/ScenePlugin.js | 152 ++- src/scene/Systems.js | 104 +- src/sound/BaseSound.js | 60 +- src/sound/BaseSoundManager.js | 174 ++-- src/sound/html5/HTML5AudioSound.js | 363 ++++--- src/sound/html5/HTML5AudioSoundManager.js | 102 +- src/sound/noaudio/NoAudioSound.js | 88 +- src/sound/noaudio/NoAudioSoundManager.js | 112 +- src/sound/webaudio/WebAudioSound.js | 391 ++++--- src/sound/webaudio/WebAudioSoundManager.js | 106 +- src/structs/List.js | 233 ++--- src/structs/Map.js | 60 +- src/structs/ProcessQueue.js | 59 +- src/structs/Size.js | 122 ++- src/textures/CanvasTexture.js | 72 +- src/textures/DynamicTexture.js | 100 +- src/textures/Frame.js | 143 ++- src/textures/Texture.js | 64 +- src/textures/TextureManager.js | 160 ++- src/textures/TextureSource.js | 32 +- src/tilemaps/ImageCollection.js | 16 +- src/tilemaps/ObjectHelper.js | 43 +- src/tilemaps/Tile.js | 181 ++-- src/tilemaps/Tilemap.js | 299 +++--- src/tilemaps/TilemapGPULayer.js | 37 +- src/tilemaps/TilemapLayer.js | 64 +- src/tilemaps/TilemapLayerBase.js | 237 +++-- src/tilemaps/Tileset.js | 60 +- src/tilemaps/mapdata/LayerData.js | 8 +- src/tilemaps/mapdata/MapData.js | 8 +- src/tilemaps/mapdata/ObjectLayer.js | 8 +- src/time/Clock.js | 52 +- src/time/Timeline.js | 64 +- src/time/TimerEvent.js | 56 +- src/tweens/TweenManager.js | 136 ++- src/tweens/tween/BaseTween.js | 152 ++- src/tweens/tween/BaseTweenData.js | 100 +- src/tweens/tween/Tween.js | 80 +- src/tweens/tween/TweenChain.js | 72 +- src/tweens/tween/TweenData.js | 28 +- src/tweens/tween/TweenFrameData.js | 28 +- 303 files changed, 10481 insertions(+), 11889 deletions(-) create mode 100644 src/a.php diff --git a/src/a.php b/src/a.php new file mode 100644 index 0000000000..dd293dea29 --- /dev/null +++ b/src/a.php @@ -0,0 +1,77 @@ += 0 && index < this.frames.length); - }, + } /** * Called internally when this Animation first starts to play. @@ -357,13 +355,13 @@ var Animation = new Class({ * * @param {Phaser.Animations.AnimationState} state - The Animation State belonging to the Game Object invoking this call. */ - getFirstTick: function (state) + getFirstTick(state) { // When is the first update due? state.accumulator = 0; state.nextTick = state.frameRate === state.currentAnim.frameRate ? state.currentFrame.duration || state.msPerFrame : state.msPerFrame; - }, + } /** * Returns the AnimationFrame at the provided index @@ -375,10 +373,10 @@ var Animation = new Class({ * * @return {Phaser.Animations.AnimationFrame} The frame at the index provided from the animation sequence */ - getFrameAt: function (index) + getFrameAt(index) { return this.frames[index]; - }, + } /** * Creates AnimationFrame instances based on the given frame data. @@ -392,7 +390,7 @@ var Animation = new Class({ * * @return {Phaser.Animations.AnimationFrame[]} An array of newly created AnimationFrame instances. */ - getFrames: function (textureManager, frames, defaultTextureKey, sortFrames) + getFrames(textureManager, frames, defaultTextureKey, sortFrames) { if (sortFrames === undefined) { sortFrames = true; } @@ -501,7 +499,7 @@ var Animation = new Class({ } return out; - }, + } /** * Called internally. Sets the accumulator and nextTick values of the current Animation. @@ -511,12 +509,12 @@ var Animation = new Class({ * * @param {Phaser.Animations.AnimationState} state - The Animation State belonging to the Game Object invoking this call. */ - getNextTick: function (state) + getNextTick(state) { state.accumulator -= state.nextTick; state.nextTick = state.frameRate === state.currentAnim.frameRate ? state.currentFrame.duration || state.msPerFrame : state.msPerFrame; - }, + } /** * Returns the frame closest to the given progress value between 0 and 1. @@ -528,12 +526,12 @@ var Animation = new Class({ * * @return {Phaser.Animations.AnimationFrame} The frame closest to the given progress value. */ - getFrameByProgress: function (value) + getFrameByProgress(value) { value = Clamp(value, 0, 1); return FindClosestInSorted(value, this.frames, 'progress'); - }, + } /** * Advance the animation frame. @@ -543,7 +541,7 @@ var Animation = new Class({ * * @param {Phaser.Animations.AnimationState} state - The Animation State to advance. */ - nextFrame: function (state) + nextFrame(state) { var frame = state.currentFrame; @@ -578,7 +576,7 @@ var Animation = new Class({ { this.updateAndGetNextTick(state, frame.nextFrame); } - }, + } /** * Handle the yoyo functionality in nextFrame and previousFrame methods. @@ -590,7 +588,7 @@ var Animation = new Class({ * @param {Phaser.Animations.AnimationState} state - The Animation State to advance. * @param {boolean} isReverse - Is animation in reverse mode? (Default: false) */ - handleYoyoFrame: function (state, isReverse) + handleYoyoFrame(state, isReverse) { if (!isReverse) { isReverse = false; } @@ -618,7 +616,7 @@ var Animation = new Class({ var frame = (isReverse) ? state.currentFrame.nextFrame : state.currentFrame.prevFrame; this.updateAndGetNextTick(state, frame); - }, + } /** * Returns the animation last frame. @@ -628,10 +626,10 @@ var Animation = new Class({ * * @return {Phaser.Animations.AnimationFrame} The last Animation Frame. */ - getLastFrame: function () + getLastFrame() { return this.frames[this.frames.length - 1]; - }, + } /** * Called internally when the Animation is playing backwards. @@ -642,7 +640,7 @@ var Animation = new Class({ * * @param {Phaser.Animations.AnimationState} state - The Animation State belonging to the Game Object invoking this call. */ - previousFrame: function (state) + previousFrame(state) { var frame = state.currentFrame; @@ -676,7 +674,7 @@ var Animation = new Class({ { this.updateAndGetNextTick(state, frame.prevFrame); } - }, + } /** * Update Frame and Wait next tick. @@ -688,12 +686,12 @@ var Animation = new Class({ * @param {Phaser.Animations.AnimationState} state - The Animation State. * @param {Phaser.Animations.AnimationFrame} frame - An Animation frame. */ - updateAndGetNextTick: function (state, frame) + updateAndGetNextTick(state, frame) { state.setCurrentFrame(frame); this.getNextTick(state); - }, + } /** * Removes the given AnimationFrame from this Animation instance. @@ -706,7 +704,7 @@ var Animation = new Class({ * * @return {this} This Animation object. */ - removeFrame: function (frame) + removeFrame(frame) { var index = this.frames.indexOf(frame); @@ -716,7 +714,7 @@ var Animation = new Class({ } return this; - }, + } /** * Removes a frame from the AnimationFrame array at the provided index @@ -729,14 +727,14 @@ var Animation = new Class({ * * @return {this} This Animation object. */ - removeFrameAt: function (index) + removeFrameAt(index) { this.frames.splice(index, 1); this.updateFrameSequence(); return this; - }, + } /** * Called internally during playback. Forces the animation to repeat, providing there are enough counts left @@ -750,7 +748,7 @@ var Animation = new Class({ * * @param {Phaser.Animations.AnimationState} state - The Animation State belonging to the Game Object invoking this call. */ - repeatAnimation: function (state) + repeatAnimation(state) { if (state._pendingStop === 2) { @@ -790,7 +788,7 @@ var Animation = new Class({ state.handleRepeat(); } } - }, + } /** * Converts the animation data to JSON. @@ -800,7 +798,7 @@ var Animation = new Class({ * * @return {Phaser.Types.Animations.JSONAnimation} The resulting JSONAnimation formatted object. */ - toJSON: function () + toJSON() { var output = { key: this.key, @@ -825,7 +823,7 @@ var Animation = new Class({ }); return output; - }, + } /** * Called internally whenever frames are added to, or removed from, this Animation. @@ -835,7 +833,7 @@ var Animation = new Class({ * * @return {this} This Animation object. */ - updateFrameSequence: function () + updateFrameSequence() { var len = this.frames.length; var slice = 1 / (len - 1); @@ -882,7 +880,7 @@ var Animation = new Class({ } return this; - }, + } /** * Pauses playback of this Animation. The paused state is set immediately. @@ -892,12 +890,12 @@ var Animation = new Class({ * * @return {this} This Animation object. */ - pause: function () + pause() { this.paused = true; return this; - }, + } /** * Resumes playback of this Animation. The paused state is reset immediately. @@ -907,12 +905,12 @@ var Animation = new Class({ * * @return {this} This Animation object. */ - resume: function () + resume() { this.paused = false; return this; - }, + } /** * Destroys this Animation instance. It will remove all event listeners, @@ -922,7 +920,7 @@ var Animation = new Class({ * @method Phaser.Animations.Animation#destroy * @since 3.0.0 */ - destroy: function () + destroy() { if (this.manager.off) { @@ -942,6 +940,6 @@ var Animation = new Class({ this.manager = null; } -}); +}; module.exports = Animation; diff --git a/src/animations/AnimationFrame.js b/src/animations/AnimationFrame.js index 26227bcb58..26ff5c9268 100644 --- a/src/animations/AnimationFrame.js +++ b/src/animations/AnimationFrame.js @@ -26,11 +26,9 @@ var Class = require('../utils/Class'); * @param {Phaser.Textures.Frame} frame - A reference to the Texture Frame this AnimationFrame uses for rendering. * @param {boolean} [isKeyFrame=false] - Is this Frame a Keyframe within the Animation? */ -var AnimationFrame = new Class({ +var AnimationFrame = class { - initialize: - - function AnimationFrame (textureKey, textureFrame, index, frame, isKeyFrame) + constructor(textureKey, textureFrame, index, frame, isKeyFrame) { if (isKeyFrame === undefined) { isKeyFrame = false; } @@ -144,7 +142,7 @@ var AnimationFrame = new Class({ * @since 3.50.0 */ this.isKeyFrame = isKeyFrame; - }, + } /** * Generates a JavaScript object suitable for converting to JSON. @@ -154,7 +152,7 @@ var AnimationFrame = new Class({ * * @return {Phaser.Types.Animations.JSONAnimationFrame} The AnimationFrame data. */ - toJSON: function () + toJSON() { return { key: this.textureKey, @@ -162,7 +160,7 @@ var AnimationFrame = new Class({ duration: this.duration, keyframe: this.isKeyFrame }; - }, + } /** * Destroys this object by removing references to external resources and callbacks. @@ -170,11 +168,11 @@ var AnimationFrame = new Class({ * @method Phaser.Animations.AnimationFrame#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.frame = undefined; } -}); +}; module.exports = AnimationFrame; diff --git a/src/animations/AnimationManager.js b/src/animations/AnimationManager.js index 866a485a01..c3e0446b78 100644 --- a/src/animations/AnimationManager.js +++ b/src/animations/AnimationManager.js @@ -34,15 +34,11 @@ var Pad = require('../utils/string/Pad'); * * @param {Phaser.Game} game - A reference to the Phaser.Game instance. */ -var AnimationManager = new Class({ +var AnimationManager = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function AnimationManager (game) + constructor(game) { - EventEmitter.call(this); + super(); /** * A reference to the Phaser.Game instance. @@ -119,7 +115,7 @@ var AnimationManager = new Class({ this.name = 'AnimationManager'; game.events.once(GameEvents.BOOT, this.boot, this); - }, + } /** * Registers event listeners after the Game boots. @@ -128,12 +124,12 @@ var AnimationManager = new Class({ * @listens Phaser.Core.Events#DESTROY * @since 3.0.0 */ - boot: function () + boot() { this.textureManager = this.game.textures; this.game.events.once(GameEvents.DESTROY, this.destroy, this); - }, + } /** * Adds a mix between two animations. @@ -163,7 +159,7 @@ var AnimationManager = new Class({ * * @return {this} This Animation Manager. */ - addMix: function (animA, animB, delay) + addMix(animA, animB, delay) { var anims = this.anims; var mixes = this.mixes; @@ -186,7 +182,7 @@ var AnimationManager = new Class({ } return this; - }, + } /** * Removes a mix between two animations. @@ -208,7 +204,7 @@ var AnimationManager = new Class({ * * @return {this} This Animation Manager. */ - removeMix: function (animA, animB) + removeMix(animA, animB) { var mixes = this.mixes; @@ -236,7 +232,7 @@ var AnimationManager = new Class({ } return this; - }, + } /** * Returns the mix delay between two animations. @@ -254,7 +250,7 @@ var AnimationManager = new Class({ * * @return {number} The mix duration, or zero if no mix exists. */ - getMix: function (animA, animB) + getMix(animA, animB) { var mixes = this.mixes; @@ -271,7 +267,7 @@ var AnimationManager = new Class({ { return 0; } - }, + } /** * Adds an existing Animation to the Animation Manager. @@ -285,7 +281,7 @@ var AnimationManager = new Class({ * * @return {this} This Animation Manager. */ - add: function (key, animation) + add(key, animation) { if (this.anims.has(key)) { @@ -301,7 +297,7 @@ var AnimationManager = new Class({ this.emit(Events.ADD_ANIMATION, key, animation); return this; - }, + } /** * Checks to see if the given key is already in use within the Animation Manager or not. @@ -315,10 +311,10 @@ var AnimationManager = new Class({ * * @return {boolean} `true` if the Animation already exists in the Animation Manager, or `false` if the key is available. */ - exists: function (key) + exists(key) { return this.anims.has(key); - }, + } /** * Create one, or more animations from a loaded Aseprite JSON file. @@ -397,7 +393,7 @@ var AnimationManager = new Class({ * * @return {Phaser.Animations.Animation[]} An array of Animation instances that were successfully created. */ - createFromAseprite: function (key, tags, target) + createFromAseprite(key, tags, target) { var output = []; @@ -487,7 +483,7 @@ var AnimationManager = new Class({ } return output; - }, + } /** * Creates a new Animation and adds it to the Animation Manager. @@ -510,7 +506,7 @@ var AnimationManager = new Class({ * * @return {(Phaser.Animations.Animation|false)} The Animation that was created, or `false` if the key is already in use. */ - create: function (config) + create(config) { var key = config.key; @@ -535,7 +531,7 @@ var AnimationManager = new Class({ } return anim; - }, + } /** * Loads this Animation Manager's Animations and settings from a JSON object. @@ -548,7 +544,7 @@ var AnimationManager = new Class({ * * @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) + fromJSON(data, clearCurrentAnimations) { if (clearCurrentAnimations === undefined) { clearCurrentAnimations = false; } @@ -584,7 +580,7 @@ var AnimationManager = new Class({ } return output; - }, + } /** * Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object. @@ -625,7 +621,7 @@ var AnimationManager = new Class({ * * @return {Phaser.Types.Animations.AnimationFrame[]} The array of {@link Phaser.Types.Animations.AnimationFrame} objects. */ - generateFrameNames: function (key, config) + generateFrameNames(key, config) { var prefix = GetValue(config, 'prefix', ''); var start = GetValue(config, 'start', 0); @@ -684,7 +680,7 @@ var AnimationManager = new Class({ } return out; - }, + } /** * Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object. @@ -733,7 +729,7 @@ var AnimationManager = new Class({ * * @return {Phaser.Types.Animations.AnimationFrame[]} The array of {@link Phaser.Types.Animations.AnimationFrame} objects. */ - generateFrameNumbers: function (key, config) + generateFrameNumbers(key, config) { var start = GetValue(config, 'start', 0); var end = GetValue(config, 'end', -1); @@ -788,7 +784,7 @@ var AnimationManager = new Class({ } return out; - }, + } /** * Get an Animation. @@ -800,10 +796,10 @@ var AnimationManager = new Class({ * * @return {Phaser.Animations.Animation} The Animation. */ - get: function (key) + get(key) { return this.anims.get(key); - }, + } /** * Returns an array of all Animation keys that are using the given @@ -817,7 +813,7 @@ var AnimationManager = new Class({ * * @return {string[]} An array of Animation keys that feature the given Texture. */ - getAnimsFromTexture: function (key) + getAnimsFromTexture(key) { var texture = this.textureManager.get(key); @@ -843,7 +839,7 @@ var AnimationManager = new Class({ } return out; - }, + } /** * Pause all animations. @@ -854,7 +850,7 @@ var AnimationManager = new Class({ * * @return {this} This Animation Manager. */ - pauseAll: function () + pauseAll() { if (!this.paused) { @@ -864,7 +860,7 @@ var AnimationManager = new Class({ } return this; - }, + } /** * Play an animation on the given Game Objects that have an Animation Component. @@ -877,7 +873,7 @@ var AnimationManager = new Class({ * * @return {this} This Animation Manager. */ - play: function (key, children) + play(key, children) { if (!Array.isArray(children)) { @@ -890,7 +886,7 @@ var AnimationManager = new Class({ } return this; - }, + } /** * Takes an array of Game Objects that have an Animation Component and then @@ -931,7 +927,7 @@ var AnimationManager = new Class({ * * @return {this} This Animation Manager. */ - staggerPlay: function (key, children, stagger, staggerFirst) + staggerPlay(key, children, stagger, staggerFirst) { if (stagger === undefined) { stagger = 0; } if (staggerFirst === undefined) { staggerFirst = true; } @@ -956,7 +952,7 @@ var AnimationManager = new Class({ } return this; - }, + } /** * Removes an Animation from this Animation Manager, based on the given key. @@ -972,7 +968,7 @@ var AnimationManager = new Class({ * * @return {Phaser.Animations.Animation} The Animation instance that was removed from the Animation Manager. */ - remove: function (key) + remove(key) { var anim = this.get(key); @@ -986,7 +982,7 @@ var AnimationManager = new Class({ } return anim; - }, + } /** * Resume all paused animations. @@ -997,7 +993,7 @@ var AnimationManager = new Class({ * * @return {this} This Animation Manager. */ - resumeAll: function () + resumeAll() { if (this.paused) { @@ -1007,7 +1003,7 @@ var AnimationManager = new Class({ } return this; - }, + } /** * Returns the Animation data as JavaScript object based on the given key. @@ -1020,7 +1016,7 @@ var AnimationManager = new Class({ * * @return {Phaser.Types.Animations.JSONAnimations} The resulting JSONAnimations formatted object. */ - toJSON: function (key) + toJSON(key) { var output = { anims: [], @@ -1040,7 +1036,7 @@ var AnimationManager = new Class({ } return output; - }, + } /** * Destroy this Animation Manager and clean up animation definitions and references to other objects. @@ -1049,7 +1045,7 @@ var AnimationManager = new Class({ * @method Phaser.Animations.AnimationManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.anims.clear(); this.mixes.clear(); @@ -1059,6 +1055,6 @@ var AnimationManager = new Class({ this.game = null; } -}); +}; module.exports = AnimationManager; diff --git a/src/animations/AnimationState.js b/src/animations/AnimationState.js index 7e2ddb94c5..765e620274 100644 --- a/src/animations/AnimationState.js +++ b/src/animations/AnimationState.js @@ -38,11 +38,9 @@ var GetFastValue = require('../utils/object/GetFastValue'); * * @param {Phaser.GameObjects.GameObject} parent - The Game Object to which this animation component belongs. */ -var AnimationState = new Class({ +var AnimationState = class { - initialize: - - function AnimationState (parent) + constructor(parent) { /** * The Game Object to which this animation component belongs. @@ -479,7 +477,7 @@ var AnimationState = new Class({ * @since 3.4.0 */ this._pendingStopValue; - }, + } /** * Sets an animation, or an array of animations, to be played in the future, after the current one completes or stops. @@ -502,7 +500,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - chain: function (key) + chain(key) { var parent = this.parent; @@ -534,7 +532,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Returns the key of the animation currently loaded into this component. @@ -546,10 +544,10 @@ var AnimationState = new Class({ * * @return {string} The key of the Animation currently loaded into this component, or an empty string if none loaded. */ - getName: function () + getName() { return (this.currentAnim) ? this.currentAnim.key : ''; - }, + } /** * Returns the key of the animation frame currently displayed by this component. @@ -559,10 +557,10 @@ var AnimationState = new Class({ * * @return {string} The key of the Animation Frame currently displayed by this component, or an empty string if no animation has been loaded. */ - getFrameName: function () + getFrameName() { return (this.currentFrame) ? this.currentFrame.textureFrame : ''; - }, + } /** * Internal method used to load an animation into this component. @@ -575,7 +573,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - load: function (key) + load(key) { if (this.isPlaying) { @@ -639,7 +637,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Pause the current animation and set the `isPlaying` property to `false`. @@ -652,7 +650,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - pause: function (atFrame) + pause(atFrame) { if (!this._paused) { @@ -667,7 +665,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Resumes playback of a paused animation and sets the `isPlaying` property to `true`. @@ -680,7 +678,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - resume: function (fromFrame) + resume(fromFrame) { if (this._paused) { @@ -694,7 +692,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Waits for the specified delay, in milliseconds, then starts playback of the given animation. @@ -717,7 +715,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - playAfterDelay: function (key, delay) + playAfterDelay(key, delay) { if (!this.isPlaying) { @@ -743,7 +741,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Waits for the current animation to complete the `repeatCount` number of repeat cycles, then starts playback @@ -763,7 +761,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - playAfterRepeat: function (key, repeatCount) + playAfterRepeat(key, repeatCount) { if (repeatCount === undefined) { repeatCount = 1; } @@ -794,7 +792,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Start playing the given animation on this Sprite. @@ -856,7 +854,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - play: function (key, ignoreIfPlaying) + play(key, ignoreIfPlaying) { if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; } @@ -889,7 +887,7 @@ var AnimationState = new Class({ this._wasPlaying = true; return this.startAnimation(key); - }, + } /** * Start playing the given animation on this Sprite, in reverse. @@ -951,7 +949,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - playReverse: function (key, ignoreIfPlaying) + playReverse(key, ignoreIfPlaying) { if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; } @@ -970,7 +968,7 @@ var AnimationState = new Class({ this._wasPlaying = true; return this.startAnimation(key); - }, + } /** * Load the animation based on the key and set-up all of the internal values @@ -984,7 +982,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - startAnimation: function (key) + startAnimation(key) { this.load(key); @@ -1023,7 +1021,7 @@ var AnimationState = new Class({ } return gameObject; - }, + } /** * Handles the start of an animation playback. @@ -1032,7 +1030,7 @@ var AnimationState = new Class({ * @private * @since 3.50.0 */ - handleStart: function () + handleStart() { if (this.showOnStart) { @@ -1044,7 +1042,7 @@ var AnimationState = new Class({ this.hasStarted = true; this.emitEvents(Events.ANIMATION_START); - }, + } /** * Handles the repeat of an animation. @@ -1053,12 +1051,12 @@ var AnimationState = new Class({ * @private * @since 3.50.0 */ - handleRepeat: function () + handleRepeat() { this.pendingRepeat = false; this.emitEvents(Events.ANIMATION_REPEAT); - }, + } /** * Handles the stop of an animation playback. @@ -1067,14 +1065,14 @@ var AnimationState = new Class({ * @private * @since 3.50.0 */ - handleStop: function () + handleStop() { this._pendingStop = 0; this.isPlaying = false; this.emitEvents(Events.ANIMATION_STOP); - }, + } /** * Handles the completion of an animation playback. @@ -1083,7 +1081,7 @@ var AnimationState = new Class({ * @private * @since 3.50.0 */ - handleComplete: function () + handleComplete() { this._pendingStop = 0; @@ -1095,7 +1093,7 @@ var AnimationState = new Class({ } this.emitEvents(Events.ANIMATION_COMPLETE, Events.ANIMATION_COMPLETE_KEY); - }, + } /** * Fires the given animation event. @@ -1106,7 +1104,7 @@ var AnimationState = new Class({ * * @param {string} event - The Animation Event to dispatch. */ - emitEvents: function (event, keyEvent) + emitEvents(event, keyEvent) { var anim = this.currentAnim; @@ -1125,7 +1123,7 @@ var AnimationState = new Class({ gameObject.emit(keyEvent + anim.key, anim, frame, gameObject, frameKey); } } - }, + } /** * Reverse the Animation that is already playing on the Game Object. @@ -1135,7 +1133,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - reverse: function () + reverse() { if (this.isPlaying) { @@ -1145,7 +1143,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Returns a value between 0 and 1 indicating how far this animation is through, ignoring repeats and yoyos. @@ -1158,7 +1156,7 @@ var AnimationState = new Class({ * * @return {number} The progress of the current animation in frames, between 0 and 1. */ - getProgress: function () + getProgress() { var frame = this.currentFrame; @@ -1175,7 +1173,7 @@ var AnimationState = new Class({ } return p; - }, + } /** * Takes a value between 0 and 1 and uses it to set how far this animation is through playback. @@ -1192,7 +1190,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - setProgress: function (value) + setProgress(value) { if (!this.forward) { @@ -1202,7 +1200,7 @@ var AnimationState = new Class({ this.setCurrentFrame(this.currentAnim.getFrameByProgress(value)); return this.parent; - }, + } /** * Sets the number of times that the animation should repeat after its first play through. @@ -1222,12 +1220,12 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - setRepeat: function (value) + setRepeat(value) { this.repeatCounter = (value === -1) ? Number.MAX_VALUE : value; return this.parent; - }, + } /** * Handle the removal of an animation from the Animation Manager. @@ -1238,7 +1236,7 @@ var AnimationState = new Class({ * @param {string} [key] - The key of the removed Animation. * @param {Phaser.Animations.Animation} [animation] - The removed Animation. */ - globalRemove: function (key, animation) + globalRemove(key, animation) { if (animation === undefined) { animation = this.currentAnim; } @@ -1248,7 +1246,7 @@ var AnimationState = new Class({ this.setCurrentFrame(this.currentAnim.frames[0]); } - }, + } /** * Restarts the current animation from its beginning. @@ -1269,7 +1267,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - restart: function (includeDelay, resetRepeats) + restart(includeDelay, resetRepeats) { if (includeDelay === undefined) { includeDelay = false; } if (resetRepeats === undefined) { resetRepeats = false; } @@ -1304,7 +1302,7 @@ var AnimationState = new Class({ this.setCurrentFrame(anim.frames[0]); return this.parent; - }, + } /** * The current animation has completed. This dispatches the `ANIMATION_COMPLETE` event. @@ -1321,7 +1319,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - complete: function () + complete() { this._pendingStop = 0; @@ -1342,7 +1340,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Immediately stops the current animation from playing and dispatches the `ANIMATION_STOP` event. @@ -1357,7 +1355,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - stop: function () + stop() { this._pendingStop = 0; @@ -1380,7 +1378,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Stops the current animation from playing after the specified time delay, given in milliseconds. @@ -1400,13 +1398,13 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - stopAfterDelay: function (delay) + stopAfterDelay(delay) { this._pendingStop = 1; this._pendingStopValue = delay; return this.parent; - }, + } /** * Stops the current animation from playing when it next repeats. @@ -1428,7 +1426,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - stopAfterRepeat: function (repeatCount) + stopAfterRepeat(repeatCount) { if (repeatCount === undefined) { repeatCount = 1; } @@ -1441,7 +1439,7 @@ var AnimationState = new Class({ this._pendingStopValue = repeatCount; return this.parent; - }, + } /** * Stops the current animation from playing when it next sets the given frame. @@ -1462,13 +1460,13 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component. */ - stopOnFrame: function (frame) + stopOnFrame(frame) { this._pendingStop = 3; this._pendingStopValue = frame; return this.parent; - }, + } /** * Returns the total number of frames in this animation, or returns zero if no @@ -1479,10 +1477,10 @@ var AnimationState = new Class({ * * @return {number} The total number of frames in the current animation, or zero if no animation has been loaded. */ - getTotalFrames: function () + getTotalFrames() { return (this.currentAnim) ? this.currentAnim.getTotalFrames() : 0; - }, + } /** * The internal update loop for the AnimationState Component. @@ -1495,7 +1493,7 @@ var AnimationState = new Class({ * @param {number} time - The current timestamp. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ - update: function (time, delta) + update(time, delta) { var anim = this.currentAnim; @@ -1559,7 +1557,7 @@ var AnimationState = new Class({ } while (this.isPlaying && this.accumulator > this.nextTick && safetyNet < 60); } } - }, + } /** * Sets the given Animation Frame as being the current frame @@ -1574,7 +1572,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to. */ - setCurrentFrame: function (animationFrame) + setCurrentFrame(animationFrame) { var gameObject = this.parent; @@ -1618,7 +1616,7 @@ var AnimationState = new Class({ } return gameObject; - }, + } /** * Advances the animation to the next frame, regardless of the time or animation state. @@ -1632,7 +1630,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to. */ - nextFrame: function () + nextFrame() { if (this.currentAnim) { @@ -1640,7 +1638,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Advances the animation to the previous frame, regardless of the time or animation state. @@ -1654,7 +1652,7 @@ var AnimationState = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to. */ - previousFrame: function () + previousFrame() { if (this.currentAnim) { @@ -1662,7 +1660,7 @@ var AnimationState = new Class({ } return this.parent; - }, + } /** * Get an Animation instance that has been created locally on this Sprite. @@ -1676,10 +1674,10 @@ var AnimationState = new Class({ * * @return {Phaser.Animations.Animation} The Animation, or `null` if the key is invalid. */ - get: function (key) + get(key) { return (this.anims) ? this.anims.get(key) : null; - }, + } /** * Checks to see if the given key is already used locally within the animations stored on this Sprite. @@ -1691,10 +1689,10 @@ var AnimationState = new Class({ * * @return {boolean} `true` if the Animation exists locally, or `false` if the key is available, or there are no local animations. */ - exists: function (key) + exists(key) { return (this.anims) ? this.anims.has(key) : false; - }, + } /** * Creates a new Animation that is local specifically to this Sprite. @@ -1720,7 +1718,7 @@ var AnimationState = new Class({ * * @return {(Phaser.Animations.Animation|false)} The Animation that was created, or `false` if the key is already in use. */ - create: function (config) + create(config) { var key = config.key; @@ -1748,7 +1746,7 @@ var AnimationState = new Class({ } return anim; - }, + } /** * Create one, or more animations from a loaded Aseprite JSON file. @@ -1832,10 +1830,10 @@ var AnimationState = new Class({ * * @return {Phaser.Animations.Animation[]} An array of Animation instances that were successfully created. */ - createFromAseprite: function (key, tags) + createFromAseprite(key, tags) { return this.animationManager.createFromAseprite(key, tags, this.parent); - }, + } /** * Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object. @@ -1875,10 +1873,10 @@ var AnimationState = new Class({ * * @return {Phaser.Types.Animations.AnimationFrame[]} The array of {@link Phaser.Types.Animations.AnimationFrame} objects. */ - generateFrameNames: function (key, config) + generateFrameNames(key, config) { return this.animationManager.generateFrameNames(key, config); - }, + } /** * Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object. @@ -1925,10 +1923,10 @@ var AnimationState = new Class({ * * @return {Phaser.Types.Animations.AnimationFrame[]} The array of {@link Phaser.Types.Animations.AnimationFrame} objects. */ - generateFrameNumbers: function (key, config) + generateFrameNumbers(key, config) { return this.animationManager.generateFrameNumbers(key, config); - }, + } /** * Removes a locally created Animation from this Sprite, based on the given key. @@ -1942,7 +1940,7 @@ var AnimationState = new Class({ * * @return {Phaser.Animations.Animation} The Animation instance that was removed from this Sprite, if the key was valid. */ - remove: function (key) + remove(key) { var anim = this.get(key); @@ -1957,7 +1955,7 @@ var AnimationState = new Class({ } return anim; - }, + } /** * Destroy this Animation component. @@ -1967,7 +1965,7 @@ var AnimationState = new Class({ * @method Phaser.Animations.AnimationState#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.animationManager.off(Events.REMOVE_ANIMATION, this.globalRemove, this); @@ -1983,7 +1981,7 @@ var AnimationState = new Class({ this.currentAnim = null; this.currentFrame = null; - }, + } /** * `true` if the current animation is paused, otherwise `false`. @@ -1993,15 +1991,12 @@ var AnimationState = new Class({ * @type {boolean} * @since 3.4.0 */ - isPaused: { - - get: function () - { - return this._paused; - } + get isPaused() + { + return this._paused; } -}); +}; module.exports = AnimationState; diff --git a/src/cache/BaseCache.js b/src/cache/BaseCache.js index be3252c053..384ae04ca3 100644 --- a/src/cache/BaseCache.js +++ b/src/cache/BaseCache.js @@ -22,11 +22,9 @@ var Events = require('./events'); * @constructor * @since 3.0.0 */ -var BaseCache = new Class({ +var BaseCache = class { - initialize: - - function BaseCache () + constructor() { /** * The Map in which the cache objects are stored. @@ -47,7 +45,7 @@ var BaseCache = new Class({ * @since 3.0.0 */ this.events = new EventEmitter(); - }, + } /** * Adds an item to this cache. The item is referenced by a unique string, which you are responsible @@ -62,14 +60,14 @@ var BaseCache = new Class({ * * @return {this} This BaseCache object. */ - add: function (key, data) + add(key, data) { this.entries.set(key, data); this.events.emit(Events.ADD, this, key, data); return this; - }, + } /** * Checks if this cache contains an item matching the given key. @@ -82,10 +80,10 @@ var BaseCache = new Class({ * * @return {boolean} Returns `true` if the cache contains an item matching the given key, otherwise `false`. */ - has: function (key) + has(key) { return this.entries.has(key); - }, + } /** * Checks if this cache contains an item matching the given key. @@ -98,10 +96,10 @@ var BaseCache = new Class({ * * @return {boolean} Returns `true` if the cache contains an item matching the given key, otherwise `false`. */ - exists: function (key) + exists(key) { return this.entries.has(key); - }, + } /** * Gets an item from this cache based on the given key. @@ -113,10 +111,10 @@ var BaseCache = new Class({ * * @return {*} The item in the cache, or `null` if no item matching the given key was found. */ - get: function (key) + get(key) { return this.entries.get(key); - }, + } /** * Removes and item from this cache based on the given key. @@ -133,7 +131,7 @@ var BaseCache = new Class({ * * @return {this} This BaseCache object. */ - remove: function (key) + remove(key) { var entry = this.get(key); @@ -145,7 +143,7 @@ var BaseCache = new Class({ } return this; - }, + } /** * Returns all keys in use in this cache. @@ -155,10 +153,10 @@ var BaseCache = new Class({ * * @return {string[]} Array containing all the keys. */ - getKeys: function () + getKeys() { return this.entries.keys(); - }, + } /** * Destroys this cache and all items within it. @@ -166,7 +164,7 @@ var BaseCache = new Class({ * @method Phaser.Cache.BaseCache#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.entries.clear(); this.events.removeAllListeners(); @@ -175,6 +173,6 @@ var BaseCache = new Class({ this.events = null; } -}); +}; module.exports = BaseCache; diff --git a/src/cache/CacheManager.js b/src/cache/CacheManager.js index b376c9ab36..19d3b07640 100644 --- a/src/cache/CacheManager.js +++ b/src/cache/CacheManager.js @@ -23,11 +23,9 @@ var GameEvents = require('../core/events'); * * @param {Phaser.Game} game - A reference to the Phaser.Game instance that owns this CacheManager. */ -var CacheManager = new Class({ +var CacheManager = class { - initialize: - - function CacheManager (game) + constructor(game) { /** * A reference to the Phaser.Game instance that owns this CacheManager. @@ -160,7 +158,7 @@ var CacheManager = new Class({ this.custom = {}; this.game.events.once(GameEvents.DESTROY, this.destroy, this); - }, + } /** * Add your own custom Cache for storing your own files. @@ -174,7 +172,7 @@ var CacheManager = new Class({ * * @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) + addCustom(key) { if (!this.custom.hasOwnProperty(key)) { @@ -182,7 +180,7 @@ var CacheManager = new Class({ } return this.custom[key]; - }, + } /** * Removes all entries from all BaseCaches and destroys all custom caches. @@ -190,7 +188,7 @@ var CacheManager = new Class({ * @method Phaser.Cache.CacheManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { var keys = [ 'binary', @@ -223,6 +221,6 @@ var CacheManager = new Class({ this.game = null; } -}); +}; module.exports = CacheManager; diff --git a/src/cameras/2d/BaseCamera.js b/src/cameras/2d/BaseCamera.js index 5ad44e5cc1..8d4e8fad5e 100644 --- a/src/cameras/2d/BaseCamera.js +++ b/src/cameras/2d/BaseCamera.js @@ -56,25 +56,24 @@ var Vector2 = require('../../math/Vector2'); * @param {number} width - The width of the Camera, in pixels. * @param {number} height - The height of the Camera, in pixels. */ -var BaseCamera = new Class({ +var BaseCamera = class extends EventEmitter { - Extends: EventEmitter, - - Mixins: [ - Components.AlphaSingle, - Components.Visible - ], - - initialize: + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.Visible + ], false); + } - function BaseCamera (x, y, width, height) + constructor(x, y, width, height) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = 0; } if (height === undefined) { height = 0; } - EventEmitter.call(this); + super(); /** * A reference to the Scene this camera belongs to. @@ -573,7 +572,7 @@ var BaseCamera = new Class({ * @since 3.86.0 */ this.renderRoundPixels = true; - }, + } /** * Adds the given Game Object to this cameras render list. @@ -586,10 +585,10 @@ var BaseCamera = new Class({ * * @param {Phaser.GameObjects.GameObject} child - The Game Object to add to the render list. */ - addToRenderList: function (child) + addToRenderList(child) { this.renderList.push(child); - }, + } /** * Set the Alpha level of this Camera. The alpha controls the opacity of the Camera as it renders. @@ -621,7 +620,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setOrigin: function (x, y) + setOrigin(x, y) { if (x === undefined) { x = 0.5; } if (y === undefined) { y = x; } @@ -630,7 +629,7 @@ var BaseCamera = new Class({ this.originY = y; return this; - }, + } /** * Calculates what the Camera.scrollX and scrollY values would need to be in order to move @@ -646,7 +645,7 @@ var BaseCamera = new Class({ * * @return {Phaser.Math.Vector2} The scroll coordinates stored in the `x` and `y` properties. */ - getScroll: function (x, y, out) + getScroll(x, y, out) { if (out === undefined) { out = new Vector2(); } @@ -663,7 +662,7 @@ var BaseCamera = new Class({ } return out; - }, + } /** * Moves the Camera horizontally so that it is centered on the given x coordinate, bounds allowing. @@ -676,7 +675,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - centerOnX: function (x) + centerOnX(x) { var originX = this.width * 0.5; @@ -690,7 +689,7 @@ var BaseCamera = new Class({ } return this; - }, + } /** * Moves the Camera vertically so that it is centered on the given y coordinate, bounds allowing. @@ -703,7 +702,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - centerOnY: function (y) + centerOnY(y) { var originY = this.height * 0.5; @@ -717,7 +716,7 @@ var BaseCamera = new Class({ } return this; - }, + } /** * Moves the Camera so that it is centered on the given coordinates, bounds allowing. @@ -730,13 +729,13 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - centerOn: function (x, y) + centerOn(x, y) { this.centerOnX(x); this.centerOnY(y); return this; - }, + } /** * Moves the Camera so that it is looking at the center of the Camera Bounds, if enabled. @@ -746,7 +745,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - centerToBounds: function () + centerToBounds() { if (this.useBounds) { @@ -761,7 +760,7 @@ var BaseCamera = new Class({ } return this; - }, + } /** * Moves the Camera so that it is re-centered based on its viewport size. @@ -771,13 +770,13 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - centerToSize: function () + centerToSize() { 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 @@ -792,7 +791,7 @@ var BaseCamera = new Class({ * * @return {Phaser.GameObjects.GameObject[]} An array of Game Objects visible to this Camera. */ - cull: function (renderableObjects) + cull(renderableObjects) { if (this.disableCull) { @@ -855,7 +854,7 @@ var BaseCamera = new Class({ } return culledObjects; - }, + } /** * Converts the given `x` and `y` coordinates into World space, based on this Cameras transform. @@ -872,7 +871,7 @@ var BaseCamera = new Class({ * * @return {Phaser.Math.Vector2} An object holding the converted values in its `x` and `y` properties. */ - getWorldPoint: function (x, y, output) + getWorldPoint(x, y, output) { if (output === undefined) { output = new Vector2(); } @@ -910,7 +909,7 @@ var BaseCamera = new Class({ output.y = (x * imb + y * imd) + imf; return output; - }, + } /** * Given a Game Object, or an array of Game Objects, it will update all of their camera filter settings @@ -923,7 +922,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - ignore: function (entries) + ignore(entries) { var id = this.id; @@ -951,7 +950,7 @@ var BaseCamera = new Class({ } return this; - }, + } /** * Takes an x value and checks it's within the range of the Camera bounds, adjusting if required. @@ -964,7 +963,7 @@ var BaseCamera = new Class({ * * @return {number} The adjusted value to use as scrollX. */ - clampX: function (x) + clampX(x) { var bounds = this._bounds; @@ -983,7 +982,7 @@ var BaseCamera = new Class({ } return x; - }, + } /** * Takes a y value and checks it's within the range of the Camera bounds, adjusting if required. @@ -996,7 +995,7 @@ var BaseCamera = new Class({ * * @return {number} The adjusted value to use as scrollY. */ - clampY: function (y) + clampY(y) { var bounds = this._bounds; @@ -1015,7 +1014,7 @@ var BaseCamera = new Class({ } return y; - }, + } /* var gap = this._zoomInversed; @@ -1030,7 +1029,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - removeBounds: function () + removeBounds() { this.useBounds = false; @@ -1039,7 +1038,7 @@ var BaseCamera = new Class({ this._bounds.setEmpty(); return this; - }, + } /** * Set the rotation of this Camera. This causes everything it renders to appear rotated. @@ -1053,14 +1052,14 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setAngle: function (value) + setAngle(value) { if (value === undefined) { value = 0; } this.rotation = DegToRad(value); return this; - }, + } /** * Sets the background color for this Camera. @@ -1077,7 +1076,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setBackgroundColor: function (color) + setBackgroundColor(color) { if (color === undefined) { color = 'rgba(0,0,0,0)'; } @@ -1086,7 +1085,7 @@ var BaseCamera = new Class({ this.transparent = (this.backgroundColor.alpha === 0); return this; - }, + } /** * Set the bounds of the Camera. The bounds are an axis-aligned rectangle. @@ -1118,7 +1117,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setBounds: function (x, y, width, height, centerOn) + setBounds(x, y, width, height, centerOn) { if (centerOn === undefined) { centerOn = false; } @@ -1138,7 +1137,7 @@ var BaseCamera = new Class({ } return this; - }, + } /** * Sets the `forceComposite` property of this Camera. @@ -1154,12 +1153,12 @@ var BaseCamera = new Class({ * * @returns {this} This Camera instance. */ - setForceComposite: function (value) + setForceComposite(value) { this.forceComposite = value; return this; - }, + } /** * Returns a rectangle containing the bounds of the Camera. @@ -1175,7 +1174,7 @@ var BaseCamera = new Class({ * * @return {Phaser.Geom.Rectangle} A rectangle containing the bounds of this Camera. */ - getBounds: function (out) + getBounds(out) { if (out === undefined) { out = new Rectangle(); } @@ -1184,7 +1183,7 @@ var BaseCamera = new Class({ out.setTo(source.x, source.y, source.width, source.height); return out; - }, + } /** * Sets the name of this Camera. @@ -1197,14 +1196,14 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setName: function (value) + setName(value) { if (value === undefined) { value = ''; } this.name = value; return this; - }, + } /** * Set the position of the Camera viewport within the game. @@ -1219,7 +1218,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setPosition: function (x, y) + setPosition(x, y) { if (y === undefined) { y = x; } @@ -1227,7 +1226,7 @@ var BaseCamera = new Class({ this.y = y; return this; - }, + } /** * Set the rotation of this Camera. This causes everything it renders to appear rotated. @@ -1241,14 +1240,14 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setRotation: function (value) + setRotation(value) { if (value === undefined) { value = 0; } this.rotation = value; return this; - }, + } /** * Should the Camera round pixel values to whole integers when rendering Game Objects? @@ -1262,12 +1261,12 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setRoundPixels: function (value) + setRoundPixels(value) { this.roundPixels = value; return this; - }, + } /** * Sets the Scene the Camera is bound to. @@ -1280,7 +1279,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setScene: function (scene, isSceneCamera) + setScene(scene, isSceneCamera) { if (isSceneCamera === undefined) { isSceneCamera = true; } @@ -1301,7 +1300,7 @@ var BaseCamera = new Class({ this.updateSystem(); return this; - }, + } /** * Set the position of where the Camera is looking within the game. @@ -1318,7 +1317,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setScroll: function (x, y) + setScroll(x, y) { if (y === undefined) { y = x; } @@ -1326,7 +1325,7 @@ var BaseCamera = new Class({ this.scrollY = y; return this; - }, + } /** * Set the size of the Camera viewport. @@ -1343,7 +1342,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setSize: function (width, height) + setSize(width, height) { if (height === undefined) { height = width; } @@ -1351,7 +1350,7 @@ var BaseCamera = new Class({ this.height = height; return this; - }, + } /** * This method sets the position and size of the Camera viewport in a single call. @@ -1374,7 +1373,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setViewport: function (x, y, width, height) + setViewport(x, y, width, height) { this.x = x; this.y = y; @@ -1382,7 +1381,7 @@ var BaseCamera = new Class({ this.height = height; return this; - }, + } /** * Set the zoom value of the Camera. @@ -1404,7 +1403,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setZoom: function (x, y) + setZoom(x, y) { if (x === undefined) { x = 1; } if (y === undefined) { y = x; } @@ -1423,7 +1422,7 @@ var BaseCamera = new Class({ this.zoomY = y; return this; - }, + } /** * Sets the mask to be applied to this Camera during rendering. @@ -1445,7 +1444,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - setMask: function (mask, fixedPosition) + setMask(mask, fixedPosition) { if (fixedPosition === undefined) { fixedPosition = true; } @@ -1454,7 +1453,7 @@ var BaseCamera = new Class({ this._maskCamera = (fixedPosition) ? this.cameraManager.default : this; return this; - }, + } /** * Clears the mask that this Camera was using. @@ -1466,7 +1465,7 @@ var BaseCamera = new Class({ * * @return {this} This Camera instance. */ - clearMask: function (destroyMask) + clearMask(destroyMask) { if (destroyMask === undefined) { destroyMask = false; } @@ -1478,7 +1477,7 @@ var BaseCamera = new Class({ this.mask = null; return this; - }, + } /** * Sets the visibility of this Camera. @@ -1501,7 +1500,7 @@ var BaseCamera = new Class({ * * @return {Phaser.Types.Cameras.Scene2D.JSONCamera} A well-formed object suitable for conversion to JSON. */ - toJSON: function () + toJSON() { var output = { name: this.name, @@ -1528,7 +1527,7 @@ var BaseCamera = new Class({ } return output; - }, + } /** * Internal method called automatically by the Camera Manager. @@ -1540,10 +1539,10 @@ var BaseCamera = new Class({ * @param {number} 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 () + update() { // NOOP - }, + } /** * Set if this Camera is being used as a Scene Camera, or a Texture @@ -1554,12 +1553,12 @@ var BaseCamera = new Class({ * * @param {boolean} value - Is this being used as a Scene Camera, or a Texture camera? */ - setIsSceneCamera: function (value) + setIsSceneCamera(value) { this.isSceneCamera = value; return this; - }, + } /** * Internal method called automatically when the viewport changes. @@ -1568,7 +1567,7 @@ var BaseCamera = new Class({ * @private * @since 3.12.0 */ - updateSystem: function () + updateSystem() { if (!this.scaleManager || !this.isSceneCamera) { @@ -1592,7 +1591,7 @@ var BaseCamera = new Class({ this.dirty = true; this._customViewport = custom; - }, + } /** * Destroys this Camera instance and its internal properties and references. @@ -1607,7 +1606,7 @@ var BaseCamera = new Class({ * @fires Phaser.Cameras.Scene2D.Events#DESTROY * @since 3.0.0 */ - destroy: function () + destroy() { this.emit(Events.DESTROY, this); @@ -1633,7 +1632,7 @@ var BaseCamera = new Class({ this.scaleManager = null; this.sceneManager = null; this.cameraManager = null; - }, + } /** * The x position of the Camera viewport, relative to the top-left of the game canvas. @@ -1644,20 +1643,17 @@ var BaseCamera = new Class({ * @type {number} * @since 3.0.0 */ - x: { - - get: function () - { - return this._x; - }, - set: function (value) - { - this._x = value; - this.updateSystem(); - } + get x() + { + return this._x; + } - }, + set x(value) + { + this._x = value; + this.updateSystem(); + } /** * The y position of the Camera viewport, relative to the top-left of the game canvas. @@ -1668,20 +1664,17 @@ var BaseCamera = new Class({ * @type {number} * @since 3.0.0 */ - y: { - get: function () - { - return this._y; - }, - - set: function (value) - { - this._y = value; - this.updateSystem(); - } + get y() + { + return this._y; + } - }, + set y(value) + { + this._y = value; + this.updateSystem(); + } /** * The width of the Camera viewport, in pixels. @@ -1693,20 +1686,17 @@ var BaseCamera = new Class({ * @type {number} * @since 3.0.0 */ - width: { - get: function () - { - return this._width; - }, - - set: function (value) - { - this._width = value; - this.updateSystem(); - } + get width() + { + return this._width; + } - }, + set width(value) + { + this._width = value; + this.updateSystem(); + } /** * The height of the Camera viewport, in pixels. @@ -1718,20 +1708,17 @@ var BaseCamera = new Class({ * @type {number} * @since 3.0.0 */ - height: { - get: function () - { - return this._height; - }, - - set: function (value) - { - this._height = value; - this.updateSystem(); - } + get height() + { + return this._height; + } - }, + set height(value) + { + this._height = value; + this.updateSystem(); + } /** * The horizontal scroll position of this Camera. @@ -1748,23 +1735,20 @@ var BaseCamera = new Class({ * @default 0 * @since 3.0.0 */ - scrollX: { - get: function () - { - return this._scrollX; - }, + get scrollX() + { + return this._scrollX; + } - set: function (value) + set scrollX(value) + { + if (value !== this._scrollX) { - if (value !== this._scrollX) - { - this._scrollX = value; - this.dirty = true; - } + this._scrollX = value; + this.dirty = true; } - - }, + } /** * The vertical scroll position of this Camera. @@ -1781,23 +1765,20 @@ var BaseCamera = new Class({ * @default 0 * @since 3.0.0 */ - scrollY: { - get: function () - { - return this._scrollY; - }, + get scrollY() + { + return this._scrollY; + } - set: function (value) + set scrollY(value) + { + if (value !== this._scrollY) { - if (value !== this._scrollY) - { - this._scrollY = value; - this.dirty = true; - } + this._scrollY = value; + this.dirty = true; } - - }, + } /** * The Camera zoom value. Change this value to zoom in, or out of, a Scene. @@ -1815,22 +1796,19 @@ var BaseCamera = new Class({ * @default 1 * @since 3.0.0 */ - zoom: { - - get: function () - { - return (this._zoomX + this._zoomY) / 2; - }, - set: function (value) - { - this._zoomX = value; - this._zoomY = value; + get zoom() + { + return (this._zoomX + this._zoomY) / 2; + } - this.dirty = true; - } + set zoom(value) + { + this._zoomX = value; + this._zoomY = value; - }, + this.dirty = true; + } /** * The Camera horizontal zoom value. Change this value to zoom in, or out of, a Scene. @@ -1848,20 +1826,17 @@ var BaseCamera = new Class({ * @default 1 * @since 3.50.0 */ - zoomX: { - - get: function () - { - return this._zoomX; - }, - set: function (value) - { - this._zoomX = value; - this.dirty = true; - } + get zoomX() + { + return this._zoomX; + } - }, + set zoomX(value) + { + this._zoomX = value; + this.dirty = true; + } /** * The Camera vertical zoom value. Change this value to zoom in, or out of, a Scene. @@ -1879,20 +1854,17 @@ var BaseCamera = new Class({ * @default 1 * @since 3.50.0 */ - zoomY: { - - get: function () - { - return this._zoomY; - }, - set: function (value) - { - this._zoomY = value; - this.dirty = true; - } + get zoomY() + { + return this._zoomY; + } - }, + set zoomY(value) + { + this._zoomY = value; + this.dirty = true; + } /** * The rotation of the Camera in radians. @@ -1909,20 +1881,17 @@ var BaseCamera = new Class({ * @default 0 * @since 3.11.0 */ - rotation: { - get: function () - { - return this._rotation; - }, - - set: function (value) - { - this._rotation = value; - this.dirty = true; - } + get rotation() + { + return this._rotation; + } - }, + set rotation(value) + { + this._rotation = value; + this.dirty = true; + } /** * The horizontal position of the center of the Camera's viewport, relative to the left of the game canvas. @@ -1932,14 +1901,11 @@ var BaseCamera = new Class({ * @readonly * @since 3.10.0 */ - centerX: { - get: function () - { - return this.x + (0.5 * this.width); - } - - }, + get centerX() + { + return this.x + (0.5 * this.width); + } /** * The vertical position of the center of the Camera's viewport, relative to the top of the game canvas. @@ -1949,14 +1915,11 @@ var BaseCamera = new Class({ * @readonly * @since 3.10.0 */ - centerY: { - get: function () - { - return this.y + (0.5 * this.height); - } - - }, + get centerY() + { + return this.y + (0.5 * this.height); + } /** * The displayed width of the camera viewport, factoring in the camera zoom level. @@ -1972,14 +1935,11 @@ var BaseCamera = new Class({ * @readonly * @since 3.11.0 */ - displayWidth: { - get: function () - { - return this.width / this.zoomX; - } - - }, + get displayWidth() + { + return this.width / this.zoomX; + } /** * The displayed height of the camera viewport, factoring in the camera zoom level. @@ -1995,15 +1955,12 @@ var BaseCamera = new Class({ * @readonly * @since 3.11.0 */ - displayHeight: { - - get: function () - { - return this.height / this.zoomY; - } + get displayHeight() + { + return this.height / this.zoomY; } -}); +}; module.exports = BaseCamera; diff --git a/src/cameras/2d/Camera.js b/src/cameras/2d/Camera.js index d2a30d73d2..be6d209b91 100644 --- a/src/cameras/2d/Camera.js +++ b/src/cameras/2d/Camera.js @@ -50,15 +50,11 @@ var Vector2 = require('../../math/Vector2'); * @param {number} width - The width of the Camera, in pixels. * @param {number} height - The height of the Camera, in pixels. */ -var Camera = new Class({ +var Camera = class extends BaseCamera { - Extends: BaseCamera, - - initialize: - - function Camera (x, y, width, height) + constructor(x, y, width, height) { - BaseCamera.call(this, x, y, width, height); + super(x, y, width, height); /** * The filters for this camera. @@ -210,7 +206,7 @@ var Camera = new Class({ * @since 3.0.0 */ this._follow = null; - }, + } /** * Sets the Camera dead zone. @@ -236,7 +232,7 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - setDeadzone: function (width, height) + setDeadzone(width, height) { if (width === undefined) { @@ -272,7 +268,7 @@ var Camera = new Class({ } return this; - }, + } /** * Fades the Camera in from the given color over the duration specified. @@ -292,10 +288,10 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - fadeIn: function (duration, red, green, blue, callback, context) + fadeIn(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. @@ -316,10 +312,10 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - fadeOut: function (duration, red, green, blue, callback, context) + fadeOut(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. @@ -340,10 +336,10 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - fadeFrom: function (duration, red, green, blue, force, callback, context) + fadeFrom(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. @@ -364,10 +360,10 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - fade: function (duration, red, green, blue, force, callback, context) + fade(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. @@ -388,10 +384,10 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - flash: function (duration, red, green, blue, force, callback, context) + flash(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. @@ -410,10 +406,10 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - shake: function (duration, intensity, force, callback, context) + shake(duration, intensity, force, callback, context) { return this.shakeEffect.start(duration, intensity, force, callback, context); - }, + } /** * This effect will scroll the Camera so that the center of its viewport finishes at the given destination, @@ -436,10 +432,10 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - pan: function (x, y, duration, ease, force, callback, context) + pan(x, y, duration, ease, force, callback, context) { return this.panEffect.start(x, y, duration, ease, force, callback, context); - }, + } /** * Rotate the Camera to the given angle over the duration and with the ease specified. @@ -459,10 +455,10 @@ var Camera = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} This Camera instance. */ - rotateTo: function (angle, shortestPath, duration, ease, force, callback, context) + rotateTo(angle, shortestPath, duration, ease, force, callback, context) { return this.rotateToEffect.start(angle, shortestPath, duration, ease, force, callback, context); - }, + } /** * This effect will zoom the Camera to the given scale, over the duration and with the ease specified. @@ -483,10 +479,10 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - zoomTo: function (zoom, duration, ease, force, callback, context) + zoomTo(zoom, duration, ease, force, callback, context) { return this.zoomEffect.start(zoom, duration, ease, force, callback, context); - }, + } /** * Internal preRender step. @@ -495,7 +491,7 @@ var Camera = new Class({ * @protected * @since 3.0.0 */ - preRender: function () + preRender() { this.renderList.length = 0; @@ -604,7 +600,7 @@ var Camera = new Class({ { this.emit(Events.FOLLOW_UPDATE, this, follow); } - }, + } /** * Returns the view matrix of the camera. This is used internally. @@ -618,7 +614,7 @@ var Camera = new Class({ * @param {boolean} [forceComposite=false] - If `true`, the view matrix will always be `matrix`. This is typically used when rendering to a framebuffer, so the external matrix is irrelevant. * @returns {Phaser.GameObjects.Components.TransformMatrix} The view matrix of the camera. */ - getViewMatrix: function (forceComposite) + getViewMatrix(forceComposite) { if ( forceComposite || this.forceComposite || @@ -632,7 +628,7 @@ var Camera = new Class({ { return this.matrixCombined; } - }, + } /** * Sets the linear interpolation value to use when following a target. @@ -652,7 +648,7 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - setLerp: function (x, y) + setLerp(x, y) { if (x === undefined) { x = 1; } if (y === undefined) { y = x; } @@ -660,7 +656,7 @@ var Camera = new Class({ this.lerp.set(x, y); return this; - }, + } /** * Sets the horizontal and vertical offset of the camera from its follow target. @@ -674,7 +670,7 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - setFollowOffset: function (x, y) + setFollowOffset(x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -682,7 +678,7 @@ var Camera = new Class({ this.followOffset.set(x, y); return this; - }, + } /** * Sets the Camera to follow a Game Object. @@ -710,7 +706,7 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - startFollow: function (target, roundPixels, lerpX, lerpY, offsetX, offsetY) + startFollow(target, roundPixels, lerpX, lerpY, offsetX, offsetY) { if (roundPixels === undefined) { roundPixels = false; } if (lerpX === undefined) { lerpX = 1; } @@ -747,7 +743,7 @@ var Camera = new Class({ } return this; - }, + } /** * Stops a Camera from following a Game Object, if previously set via `Camera.startFollow`. @@ -757,12 +753,12 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - stopFollow: function () + stopFollow() { this._follow = null; return this; - }, + } /** * Resets any active FX, such as a fade, flash or shake. Useful to call after a fade in order to @@ -773,7 +769,7 @@ var Camera = new Class({ * * @return {this} This Camera instance. */ - resetFX: function () + resetFX() { this.rotateToEffect.reset(); this.panEffect.reset(); @@ -782,7 +778,7 @@ var Camera = new Class({ this.fadeEffect.reset(); return this; - }, + } /** * Internal method called automatically by the Camera Manager. @@ -794,7 +790,7 @@ var Camera = new Class({ * @param {number} 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) + update(time, delta) { if (this.visible) { @@ -805,7 +801,7 @@ var Camera = new Class({ this.flashEffect.update(time, delta); this.fadeEffect.update(time, delta); } - }, + } /** * Destroys this Camera instance. You rarely need to call this directly. @@ -817,7 +813,7 @@ var Camera = new Class({ * @fires Phaser.Cameras.Scene2D.Events#DESTROY * @since 3.0.0 */ - destroy: function () + destroy() { this.resetFX(); @@ -831,6 +827,6 @@ var Camera = new Class({ this.deadzone = null; } -}); +}; module.exports = Camera; diff --git a/src/cameras/2d/CameraManager.js b/src/cameras/2d/CameraManager.js index d7427203b6..6038c4ceb7 100644 --- a/src/cameras/2d/CameraManager.js +++ b/src/cameras/2d/CameraManager.js @@ -50,11 +50,9 @@ var SceneEvents = require('../../scene/events'); * * @param {Phaser.Scene} scene - The Scene that owns the Camera Manager plugin. */ -var CameraManager = new Class({ +var CameraManager = class { - initialize: - - function CameraManager (scene) + constructor(scene) { /** * The Scene that owns the Camera Manager plugin. @@ -129,7 +127,7 @@ var CameraManager = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -140,7 +138,7 @@ var CameraManager = new Class({ * @listens Phaser.Scenes.Events#DESTROY * @since 3.5.1 */ - boot: function () + boot() { var sys = this.systems; @@ -163,7 +161,7 @@ var CameraManager = new Class({ sys.game.scale.on(ScaleEvents.RESIZE, this.onResize, this); this.systems.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -176,7 +174,7 @@ var CameraManager = new Class({ * @listens Phaser.Scenes.Events#SHUTDOWN * @since 3.5.0 */ - start: function () + start() { if (!this.main) { @@ -200,7 +198,7 @@ var CameraManager = new Class({ eventEmitter.on(SceneEvents.UPDATE, this.update, this); eventEmitter.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * Adds a new Camera into the Camera Manager. The Camera Manager can support up to 31 different Cameras. @@ -231,7 +229,7 @@ var CameraManager = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} The newly created Camera. */ - add: function (x, y, width, height, makeMain, name) + add(x, y, width, height, makeMain, name) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -256,7 +254,7 @@ var CameraManager = new Class({ } return camera; - }, + } /** * Adds an existing Camera into the Camera Manager. @@ -279,7 +277,7 @@ var CameraManager = new Class({ * * @return {?Phaser.Cameras.Scene2D.Camera} The Camera that was added to the Camera Manager, or `null` if it couldn't be added. */ - addExisting: function (camera, makeMain) + addExisting(camera, makeMain) { if (makeMain === undefined) { makeMain = false; } @@ -302,7 +300,7 @@ var CameraManager = new Class({ } return null; - }, + } /** * Gets the next available Camera ID number. @@ -316,7 +314,7 @@ var CameraManager = new Class({ * * @return {number} The next available Camera ID, or 0 if they're all already in use. */ - getNextID: function () + getNextID() { var cameras = this.cameras; @@ -350,7 +348,7 @@ var CameraManager = new Class({ } return 0; - }, + } /** * Gets the total number of Cameras in this Camera Manager. @@ -364,7 +362,7 @@ var CameraManager = new Class({ * * @return {number} The total number of Cameras in this Camera Manager. */ - getTotal: function (isVisible) + getTotal(isVisible) { if (isVisible === undefined) { isVisible = false; } @@ -383,7 +381,7 @@ var CameraManager = new Class({ } return total; - }, + } /** * Populates this Camera Manager based on the given configuration object, or an array of config objects. @@ -397,7 +395,7 @@ var CameraManager = new Class({ * * @return {this} This Camera Manager instance. */ - fromJSON: function (config) + fromJSON(config) { if (!Array.isArray(config)) { @@ -452,7 +450,7 @@ var CameraManager = new Class({ } return this; - }, + } /** * Gets a Camera based on its name. @@ -467,7 +465,7 @@ var CameraManager = new Class({ * * @return {?Phaser.Cameras.Scene2D.Camera} The first Camera with a name matching the given string, otherwise `null`. */ - getCamera: function (name) + getCamera(name) { var cameras = this.cameras; @@ -480,7 +478,7 @@ var CameraManager = new Class({ } return null; - }, + } /** * Returns an array of all cameras below the given Pointer. @@ -494,7 +492,7 @@ var CameraManager = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera[]} An array of cameras below the Pointer. */ - getCamerasBelowPointer: function (pointer) + getCamerasBelowPointer(pointer) { var cameras = this.cameras; @@ -515,7 +513,7 @@ var CameraManager = new Class({ } return output; - }, + } /** * Removes the given Camera, or an array of Cameras, from this Camera Manager. @@ -535,7 +533,7 @@ var CameraManager = new Class({ * * @return {number} The total number of Cameras removed. */ - remove: function (camera, runDestroy) + remove(camera, runDestroy) { if (runDestroy === undefined) { runDestroy = true; } @@ -574,7 +572,7 @@ var CameraManager = new Class({ } return total; - }, + } /** * The internal render method. This is called automatically by the Scene and should not be invoked directly. @@ -589,7 +587,7 @@ var CameraManager = new Class({ * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The Renderer that will render the children to this camera. * @param {Phaser.GameObjects.DisplayList} displayList - The Display List for the Scene. */ - render: function (renderer, displayList) + render(renderer, displayList) { var scene = this.scene; var cameras = this.cameras; @@ -607,7 +605,7 @@ var CameraManager = new Class({ renderer.render(scene, visibleChildren, camera); } } - }, + } /** * Takes an array of Game Objects and a Camera and returns a new array @@ -622,13 +620,13 @@ var CameraManager = new Class({ * * @return {Phaser.GameObjects.GameObject[]} A filtered list of only Game Objects within the Scene that will render against the given Camera. */ - getVisibleChildren: function (children, camera) + getVisibleChildren(children, camera) { return children.filter(function (child) { return child.willRender(camera); }); - }, + } /** * Resets this Camera Manager. @@ -641,7 +639,7 @@ var CameraManager = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} The freshly created main Camera. */ - resetAll: function () + resetAll() { for (var i = 0; i < this.cameras.length; i++) { @@ -653,7 +651,7 @@ var CameraManager = new Class({ this.main = this.add(); return this.main; - }, + } /** * The main update loop. Called automatically when the Scene steps. @@ -665,13 +663,13 @@ var CameraManager = new Class({ * @param {number} 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) + update(time, delta) { for (var i = 0; i < this.cameras.length; i++) { this.cameras[i].update(time, delta); } - }, + } /** * The event handler that manages the `resize` event dispatched by the Scale Manager. @@ -682,7 +680,7 @@ var CameraManager = new Class({ * @param {Phaser.Structs.Size} gameSize - The default Game Size object. This is the un-modified game dimensions. * @param {Phaser.Structs.Size} baseSize - The base Size object. The game dimensions. The canvas width / height values match this. */ - onResize: function (gameSize, baseSize, displaySize, previousWidth, previousHeight) + onResize(gameSize, baseSize, displaySize, previousWidth, previousHeight) { for (var i = 0; i < this.cameras.length; i++) { @@ -696,7 +694,7 @@ var CameraManager = new Class({ cam.setSize(baseSize.width, baseSize.height); } } - }, + } /** * Resizes all cameras to the given dimensions. @@ -707,13 +705,13 @@ var CameraManager = new Class({ * @param {number} width - The new width of the camera. * @param {number} height - The new height of the camera. */ - resize: function (width, height) + resize(width, height) { for (var i = 0; i < this.cameras.length; i++) { this.cameras[i].setSize(width, height); } - }, + } /** * The Scene that owns this plugin is shutting down. @@ -723,7 +721,7 @@ var CameraManager = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { this.main = undefined; @@ -738,7 +736,7 @@ var CameraManager = new Class({ eventEmitter.off(SceneEvents.UPDATE, this.update, this); eventEmitter.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -748,7 +746,7 @@ var CameraManager = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -762,7 +760,7 @@ var CameraManager = new Class({ this.systems = null; } -}); +}; PluginCache.register('CameraManager', CameraManager, 'cameras'); diff --git a/src/cameras/2d/effects/Fade.js b/src/cameras/2d/effects/Fade.js index 25a5d305df..7ba6191135 100644 --- a/src/cameras/2d/effects/Fade.js +++ b/src/cameras/2d/effects/Fade.js @@ -27,11 +27,9 @@ var Events = require('../events'); * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ -var Fade = new Class({ +var Fade = class { - initialize: - - function Fade (camera) + constructor(camera) { /** * The Camera this effect belongs to. @@ -173,7 +171,7 @@ var Fade = new Class({ * @since 3.5.0 */ this._onUpdateScope; - }, + } /** * Fades the Camera to or from the given color over the duration specified. @@ -195,7 +193,7 @@ var Fade = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ - start: function (direction, duration, red, green, blue, force, callback, context) + start(direction, duration, red, green, blue, force, callback, context) { if (direction === undefined) { direction = true; } if (duration === undefined) { duration = 1000; } @@ -232,7 +230,7 @@ var Fade = new Class({ 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. @@ -243,7 +241,7 @@ var Fade = new Class({ * @param {number} 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) + update(time, delta) { if (!this.isRunning) { @@ -268,7 +266,7 @@ var Fade = new Class({ this.alpha = (this.direction) ? 1 : 0; this.effectComplete(); } - }, + } /** * Called internally by the Canvas Renderer. @@ -280,7 +278,7 @@ var Fade = new Class({ * * @return {boolean} `true` if the effect drew to the renderer, otherwise `false`. */ - postRenderCanvas: function (ctx) + postRenderCanvas(ctx) { if (!this.isRunning && !this.isComplete) { @@ -293,7 +291,7 @@ var Fade = new Class({ ctx.fillRect(camera.x, camera.y, camera.width, camera.height); return true; - }, + } /** * Called internally by the WebGL Renderer. @@ -303,10 +301,10 @@ var Fade = new Class({ * * @return {boolean} `true` if the effect should draw to the renderer, otherwise `false`. */ - postRenderWebGL: function () + postRenderWebGL() { return this.isRunning || this.isComplete; - }, + } /** * Called internally when the effect completes. @@ -316,7 +314,7 @@ var Fade = new Class({ * @fires Phaser.Cameras.Scene2D.Events#FADE_OUT_COMPLETE * @since 3.5.0 */ - effectComplete: function () + effectComplete() { this._onUpdate = null; this._onUpdateScope = null; @@ -327,7 +325,7 @@ var Fade = new Class({ var eventName = (this.direction) ? Events.FADE_OUT_COMPLETE : Events.FADE_IN_COMPLETE; this.camera.emit(eventName, this.camera, this); - }, + } /** * Resets this camera effect. @@ -336,14 +334,14 @@ var Fade = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Fade#reset * @since 3.5.0 */ - reset: function () + reset() { this.isRunning = false; this.isComplete = false; this._onUpdate = null; this._onUpdateScope = null; - }, + } /** * Destroys this effect, releasing it from the Camera. @@ -351,13 +349,13 @@ var Fade = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Fade#destroy * @since 3.5.0 */ - destroy: function () + destroy() { this.reset(); this.camera = null; } -}); +}; module.exports = Fade; diff --git a/src/cameras/2d/effects/Flash.js b/src/cameras/2d/effects/Flash.js index 892d5a20d7..f9424567a0 100644 --- a/src/cameras/2d/effects/Flash.js +++ b/src/cameras/2d/effects/Flash.js @@ -27,11 +27,9 @@ var Events = require('../events'); * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ -var Flash = new Class({ +var Flash = class { - initialize: - - function Flash (camera) + constructor(camera) { /** * The Camera this effect belongs to. @@ -158,7 +156,7 @@ var Flash = new Class({ * @since 3.5.0 */ this._onUpdateScope; - }, + } /** * Flashes the Camera to or from the given color over the duration specified. @@ -179,7 +177,7 @@ var Flash = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ - start: function (duration, red, green, blue, force, callback, context) + start(duration, red, green, blue, force, callback, context) { if (duration === undefined) { duration = 250; } if (red === undefined) { red = 255; } @@ -211,7 +209,7 @@ var Flash = new Class({ this.camera.emit(Events.FLASH_START, this.camera, this, duration, red, green, blue); return this.camera; - }, + } /** * The main update loop for this effect. Called automatically by the Camera. @@ -222,7 +220,7 @@ var Flash = new Class({ * @param {number} 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) + update(time, delta) { if (!this.isRunning) { @@ -246,7 +244,7 @@ var Flash = new Class({ { this.effectComplete(); } - }, + } /** * Called internally by the Canvas Renderer. @@ -258,7 +256,7 @@ var Flash = new Class({ * * @return {boolean} `true` if the effect drew to the renderer, otherwise `false`. */ - postRenderCanvas: function (ctx) + postRenderCanvas(ctx) { if (!this.isRunning) { @@ -271,7 +269,7 @@ var Flash = new Class({ ctx.fillRect(camera.x, camera.y, camera.width, camera.height); return true; - }, + } /** * Called internally by the WebGL Renderer. @@ -281,10 +279,10 @@ var Flash = new Class({ * * @return {boolean} `true` if the effect should draw to the renderer, otherwise `false`. */ - postRenderWebGL: function () + postRenderWebGL() { return this.isRunning; - }, + } /** * Called internally when the effect completes. @@ -293,7 +291,7 @@ var Flash = new Class({ * @fires Phaser.Cameras.Scene2D.Events#FLASH_COMPLETE * @since 3.5.0 */ - effectComplete: function () + effectComplete() { this.alpha = this._alpha; this._onUpdate = null; @@ -302,7 +300,7 @@ var Flash = new Class({ this.isRunning = false; this.camera.emit(Events.FLASH_COMPLETE, this.camera, this); - }, + } /** * Resets this camera effect. @@ -311,13 +309,13 @@ var Flash = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Flash#reset * @since 3.5.0 */ - reset: function () + reset() { this.isRunning = false; this._onUpdate = null; this._onUpdateScope = null; - }, + } /** * Destroys this effect, releasing it from the Camera. @@ -325,13 +323,13 @@ var Flash = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Flash#destroy * @since 3.5.0 */ - destroy: function () + destroy() { this.reset(); this.camera = null; } -}); +}; module.exports = Flash; diff --git a/src/cameras/2d/effects/Pan.js b/src/cameras/2d/effects/Pan.js index 213eec5aca..a81b925433 100644 --- a/src/cameras/2d/effects/Pan.js +++ b/src/cameras/2d/effects/Pan.js @@ -30,11 +30,9 @@ var Vector2 = require('../../../math/Vector2'); * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ -var Pan = new Class({ +var Pan = class { - initialize: - - function Pan (camera) + constructor(camera) { /** * The Camera this effect belongs to. @@ -143,7 +141,7 @@ var Pan = new Class({ * @since 3.11.0 */ this._onUpdateScope; - }, + } /** * This effect will scroll the Camera so that the center of its viewport finishes at the given destination, @@ -166,7 +164,7 @@ var Pan = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ - start: function (x, y, duration, ease, force, callback, context) + start(x, y, duration, ease, force, callback, context) { if (duration === undefined) { duration = 1000; } if (ease === undefined) { ease = EaseMap.Linear; } @@ -212,7 +210,7 @@ var Pan = new Class({ this.camera.emit(Events.PAN_START, this.camera, this, duration, x, y); return cam; - }, + } /** * The main update loop for this effect. Called automatically by the Camera. @@ -223,7 +221,7 @@ var Pan = new Class({ * @param {number} 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) + update(time, delta) { if (!this.isRunning) { @@ -265,7 +263,7 @@ var Pan = new Class({ this.effectComplete(); } - }, + } /** * Called internally when the effect completes. @@ -274,7 +272,7 @@ var Pan = new Class({ * @fires Phaser.Cameras.Scene2D.Events#PAN_COMPLETE * @since 3.11.0 */ - effectComplete: function () + effectComplete() { this._onUpdate = null; this._onUpdateScope = null; @@ -282,7 +280,7 @@ var Pan = new Class({ this.isRunning = false; this.camera.emit(Events.PAN_COMPLETE, this.camera, this); - }, + } /** * Resets this camera effect. @@ -291,13 +289,13 @@ var Pan = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Pan#reset * @since 3.11.0 */ - reset: function () + reset() { this.isRunning = false; this._onUpdate = null; this._onUpdateScope = null; - }, + } /** * Destroys this effect, releasing it from the Camera. @@ -305,7 +303,7 @@ var Pan = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Pan#destroy * @since 3.11.0 */ - destroy: function () + destroy() { this.reset(); @@ -314,6 +312,6 @@ var Pan = new Class({ this.destination = null; } -}); +}; module.exports = Pan; diff --git a/src/cameras/2d/effects/RotateTo.js b/src/cameras/2d/effects/RotateTo.js index e107292589..6cdb6001f6 100644 --- a/src/cameras/2d/effects/RotateTo.js +++ b/src/cameras/2d/effects/RotateTo.js @@ -36,11 +36,9 @@ var WrapAngle = require('../../../math/angle/Wrap'); * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ -var RotateTo = new Class({ +var RotateTo = class { - initialize: - - function RotateTo (camera) + constructor(camera) { /** * The Camera this effect belongs to. @@ -167,7 +165,7 @@ var RotateTo = new Class({ * @since 3.23.0 */ this.shortestPath = false; - }, + } /** * Rotate the Camera to the given angle over the duration and with the ease specified. @@ -189,7 +187,7 @@ var RotateTo = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ - start: function (angle, shortestPath, duration, ease, force, callback, context) + start(angle, shortestPath, duration, ease, force, callback, context) { if (duration === undefined) { duration = 1000; } if (ease === undefined) { ease = EaseMap.Linear; } @@ -247,7 +245,7 @@ var RotateTo = new Class({ this.camera.emit(Events.ROTATE_START, this.camera, this, duration, this.destination); return cam; - }, + } /** * The main update loop for this effect. Called automatically by the Camera. @@ -258,7 +256,7 @@ var RotateTo = new Class({ * @param {number} 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) + update(time, delta) { if (!this.isRunning) { @@ -300,7 +298,7 @@ var RotateTo = new Class({ this.effectComplete(); } - }, + } /** * Called internally when the effect completes. @@ -308,7 +306,7 @@ var RotateTo = new Class({ * @method Phaser.Cameras.Scene2D.Effects.RotateTo#effectComplete * @since 3.23.0 */ - effectComplete: function () + effectComplete() { this._onUpdate = null; this._onUpdateScope = null; @@ -316,7 +314,7 @@ var RotateTo = new Class({ this.isRunning = false; this.camera.emit(Events.ROTATE_COMPLETE, this.camera, this); - }, + } /** * Resets this camera effect. @@ -325,13 +323,13 @@ var RotateTo = new Class({ * @method Phaser.Cameras.Scene2D.Effects.RotateTo#reset * @since 3.23.0 */ - reset: function () + reset() { this.isRunning = false; this._onUpdate = null; this._onUpdateScope = null; - }, + } /** * Destroys this effect, releasing it from the Camera. @@ -339,7 +337,7 @@ var RotateTo = new Class({ * @method Phaser.Cameras.Scene2D.Effects.RotateTo#destroy * @since 3.23.0 */ - destroy: function () + destroy() { this.reset(); @@ -348,6 +346,6 @@ var RotateTo = new Class({ this.destination = null; } -}); +}; module.exports = RotateTo; diff --git a/src/cameras/2d/effects/Shake.js b/src/cameras/2d/effects/Shake.js index ad24f6a635..7e0488412f 100644 --- a/src/cameras/2d/effects/Shake.js +++ b/src/cameras/2d/effects/Shake.js @@ -28,11 +28,9 @@ var Vector2 = require('../../../math/Vector2'); * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ -var Shake = new Class({ +var Shake = class { - initialize: - - function Shake (camera) + constructor(camera) { /** * The Camera this effect belongs to. @@ -138,7 +136,7 @@ var Shake = new Class({ * @since 3.5.0 */ this._onUpdateScope; - }, + } /** * Shakes the Camera by the given intensity over the duration specified. @@ -157,7 +155,7 @@ var Shake = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ - start: function (duration, intensity, force, callback, context) + start(duration, intensity, force, callback, context) { if (duration === undefined) { duration = 100; } if (intensity === undefined) { intensity = 0.05; } @@ -193,7 +191,7 @@ var Shake = new Class({ this.camera.emit(Events.SHAKE_START, this.camera, this, duration, intensity); return this.camera; - }, + } /** * The pre-render step for this effect. Called automatically by the Camera. @@ -201,13 +199,13 @@ var Shake = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Shake#preRender * @since 3.5.0 */ - preRender: function () + preRender() { if (this.isRunning) { this.camera.matrix.translate(this._offsetX, this._offsetY); } - }, + } /** * The main update loop for this effect. Called automatically by the Camera. @@ -218,7 +216,7 @@ var Shake = new Class({ * @param {number} 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) + update(time, delta) { if (!this.isRunning) { @@ -254,7 +252,7 @@ var Shake = new Class({ { this.effectComplete(); } - }, + } /** * Called internally when the effect completes. @@ -263,7 +261,7 @@ var Shake = new Class({ * @fires Phaser.Cameras.Scene2D.Events#SHAKE_COMPLETE * @since 3.5.0 */ - effectComplete: function () + effectComplete() { this._offsetX = 0; this._offsetY = 0; @@ -274,7 +272,7 @@ var Shake = new Class({ this.isRunning = false; this.camera.emit(Events.SHAKE_COMPLETE, this.camera, this); - }, + } /** * Resets this camera effect. @@ -283,7 +281,7 @@ var Shake = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Shake#reset * @since 3.5.0 */ - reset: function () + reset() { this.isRunning = false; @@ -292,7 +290,7 @@ var Shake = new Class({ this._onUpdate = null; this._onUpdateScope = null; - }, + } /** * Destroys this effect, releasing it from the Camera. @@ -300,7 +298,7 @@ var Shake = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Shake#destroy * @since 3.5.0 */ - destroy: function () + destroy() { this.reset(); @@ -308,6 +306,6 @@ var Shake = new Class({ this.intensity = null; } -}); +}; module.exports = Shake; diff --git a/src/cameras/2d/effects/Zoom.js b/src/cameras/2d/effects/Zoom.js index 5ed32b4a3e..f8576108e3 100644 --- a/src/cameras/2d/effects/Zoom.js +++ b/src/cameras/2d/effects/Zoom.js @@ -25,11 +25,9 @@ var Events = require('../events'); * * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera this effect is acting upon. */ -var Zoom = new Class({ +var Zoom = class { - initialize: - - function Zoom (camera) + constructor(camera) { /** * The Camera this effect belongs to. @@ -129,7 +127,7 @@ var Zoom = new Class({ * @since 3.11.0 */ this._onUpdateScope; - }, + } /** * This effect will zoom the Camera to the given scale, over the duration and with the ease specified. @@ -150,7 +148,7 @@ var Zoom = new Class({ * * @return {Phaser.Cameras.Scene2D.Camera} The Camera on which the effect was started. */ - start: function (zoom, duration, ease, force, callback, context) + start(zoom, duration, ease, force, callback, context) { if (duration === undefined) { duration = 1000; } if (ease === undefined) { ease = EaseMap.Linear; } @@ -193,7 +191,7 @@ var Zoom = new Class({ this.camera.emit(Events.ZOOM_START, this.camera, this, duration, zoom); return cam; - }, + } /** * The main update loop for this effect. Called automatically by the Camera. @@ -204,7 +202,7 @@ var Zoom = new Class({ * @param {number} 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) + update(time, delta) { if (!this.isRunning) { @@ -235,7 +233,7 @@ var Zoom = new Class({ this.effectComplete(); } - }, + } /** * Called internally when the effect completes. @@ -244,7 +242,7 @@ var Zoom = new Class({ * @fires Phaser.Cameras.Scene2D.Events#ZOOM_COMPLETE * @since 3.11.0 */ - effectComplete: function () + effectComplete() { this._onUpdate = null; this._onUpdateScope = null; @@ -252,7 +250,7 @@ var Zoom = new Class({ this.isRunning = false; this.camera.emit(Events.ZOOM_COMPLETE, this.camera, this); - }, + } /** * Resets this camera effect. @@ -261,13 +259,13 @@ var Zoom = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Zoom#reset * @since 3.11.0 */ - reset: function () + reset() { this.isRunning = false; this._onUpdate = null; this._onUpdateScope = null; - }, + } /** * Destroys this effect, releasing it from the Camera. @@ -275,13 +273,13 @@ var Zoom = new Class({ * @method Phaser.Cameras.Scene2D.Effects.Zoom#destroy * @since 3.11.0 */ - destroy: function () + destroy() { this.reset(); this.camera = null; } -}); +}; module.exports = Zoom; diff --git a/src/cameras/controls/FixedKeyControl.js b/src/cameras/controls/FixedKeyControl.js index 70bbb484ba..ffed86ea6a 100644 --- a/src/cameras/controls/FixedKeyControl.js +++ b/src/cameras/controls/FixedKeyControl.js @@ -33,11 +33,9 @@ var GetValue = require('../../utils/object/GetValue'); * * @param {Phaser.Types.Cameras.Controls.FixedKeyControlConfig} config - The Fixed Key Control configuration object. */ -var FixedKeyControl = new Class({ +var FixedKeyControl = class { - initialize: - - function FixedKeyControl (config) + constructor(config) { /** * The Camera that this Control will update. @@ -191,7 +189,7 @@ var FixedKeyControl = new Class({ * @since 3.0.0 */ this.active = (this.camera !== null); - }, + } /** * Starts the Key Control running, providing it has been linked to a camera. @@ -201,12 +199,12 @@ var FixedKeyControl = new Class({ * * @return {this} This Key Control instance. */ - start: function () + start() { this.active = (this.camera !== null); return this; - }, + } /** * Stops this Key Control from running. Call `start` to start it again. @@ -216,12 +214,12 @@ var FixedKeyControl = new Class({ * * @return {this} This Key Control instance. */ - stop: function () + stop() { this.active = false; return this; - }, + } /** * Binds this Key Control to a camera. @@ -233,12 +231,12 @@ var FixedKeyControl = new Class({ * * @return {this} This Key Control instance. */ - setCamera: function (camera) + setCamera(camera) { this.camera = camera; return this; - }, + } /** * Applies the results of pressing the control keys to the Camera. @@ -250,7 +248,7 @@ var FixedKeyControl = new Class({ * * @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - update: function (delta) + update(delta) { if (!this.active) { @@ -299,7 +297,7 @@ var FixedKeyControl = new Class({ cam.zoom = this.maxZoom; } } - }, + } /** * Destroys this Key Control. @@ -307,7 +305,7 @@ var FixedKeyControl = new Class({ * @method Phaser.Cameras.Controls.FixedKeyControl#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.camera = null; @@ -320,6 +318,6 @@ var FixedKeyControl = new Class({ this.zoomOut = null; } -}); +}; module.exports = FixedKeyControl; diff --git a/src/cameras/controls/SmoothedKeyControl.js b/src/cameras/controls/SmoothedKeyControl.js index e838dd0553..a4262b5362 100644 --- a/src/cameras/controls/SmoothedKeyControl.js +++ b/src/cameras/controls/SmoothedKeyControl.js @@ -39,11 +39,9 @@ var GetValue = require('../../utils/object/GetValue'); * * @param {Phaser.Types.Cameras.Controls.SmoothedKeyControlConfig} config - The Smoothed Key Control configuration object. */ -var SmoothedKeyControl = new Class({ +var SmoothedKeyControl = class { - initialize: - - function SmoothedKeyControl (config) + constructor(config) { /** * The Camera that this Control will update. @@ -285,7 +283,7 @@ var SmoothedKeyControl = new Class({ * @since 3.0.0 */ this.active = (this.camera !== null); - }, + } /** * Starts the Key Control running, providing it has been linked to a camera. @@ -295,12 +293,12 @@ var SmoothedKeyControl = new Class({ * * @return {this} This Key Control instance. */ - start: function () + start() { this.active = (this.camera !== null); return this; - }, + } /** * Stops this Key Control from running. Call `start` to start it again. @@ -310,12 +308,12 @@ var SmoothedKeyControl = new Class({ * * @return {this} This Key Control instance. */ - stop: function () + stop() { this.active = false; return this; - }, + } /** * Binds this Key Control to a camera. @@ -327,12 +325,12 @@ var SmoothedKeyControl = new Class({ * * @return {this} This Key Control instance. */ - setCamera: function (camera) + setCamera(camera) { this.camera = camera; return this; - }, + } /** * Applies the results of pressing the control keys to the Camera. @@ -344,7 +342,7 @@ var SmoothedKeyControl = new Class({ * * @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - update: function (delta) + update(delta) { if (!this.active) { @@ -475,7 +473,7 @@ var SmoothedKeyControl = new Class({ cam.zoom = this.maxZoom; } } - }, + } /** * Destroys this Key Control. @@ -483,7 +481,7 @@ var SmoothedKeyControl = new Class({ * @method Phaser.Cameras.Controls.SmoothedKeyControl#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.camera = null; @@ -496,6 +494,6 @@ var SmoothedKeyControl = new Class({ this.zoomOut = null; } -}); +}; module.exports = SmoothedKeyControl; diff --git a/src/core/Config.js b/src/core/Config.js index 0dfa6f9f8a..02c0a8c699 100644 --- a/src/core/Config.js +++ b/src/core/Config.js @@ -28,11 +28,9 @@ var ValueToColor = require('../display/color/ValueToColor'); * * @see Phaser.Game#config */ -var Config = new Class({ +var Config = class { - initialize: - - function Config (config) + constructor(config) { if (config === undefined) { config = {}; } @@ -664,6 +662,6 @@ var Config = new Class({ } } -}); +}; module.exports = Config; diff --git a/src/core/Game.js b/src/core/Game.js index fe7cc83fe6..40664bd227 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -54,11 +54,9 @@ if (typeof FEATURE_SOUND) * * @param {Phaser.Types.Core.GameConfig} [GameConfig] - The configuration object for your Phaser Game instance. */ -var Game = new Class({ +var Game = class { - initialize: - - function Game (config) + constructor(config) { /** * The parsed Game Configuration object. @@ -334,7 +332,7 @@ var Game = new Class({ // Wait for the DOM Ready event, then call boot. DOMContentLoaded(this.boot.bind(this)); - }, + } /** * This method is called automatically when the DOM is ready. It is responsible for creating the renderer, @@ -347,7 +345,7 @@ var Game = new Class({ * @listens Phaser.Textures.Events#READY * @since 3.0.0 */ - boot: function () + boot() { if (!PluginCache.hasCore('EventEmitter')) { @@ -379,7 +377,7 @@ var Game = new Class({ { window.PHASER_GAME = this; } - }, + } /** * Called automatically when the Texture Manager has finished setting up and preparing the @@ -390,13 +388,13 @@ var Game = new Class({ * @fires Phaser.Game#READY * @since 3.12.0 */ - texturesReady: function () + texturesReady() { // Start all the other systems this.events.emit(Events.READY); this.start(); - }, + } /** * Called automatically by Game.boot once all of the global systems have finished setting themselves up. @@ -407,7 +405,7 @@ var Game = new Class({ * @protected * @since 3.0.0 */ - start: function () + start() { this.isRunning = true; @@ -430,7 +428,7 @@ var Game = new Class({ eventEmitter.on(Events.VISIBLE, this.onVisible, this); eventEmitter.on(Events.BLUR, this.onBlur, this); eventEmitter.on(Events.FOCUS, this.onFocus, this); - }, + } /** * The main Game Step. Called automatically by the Time Step, once per browser frame (typically as a result of @@ -451,7 +449,7 @@ var Game = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - step: function (time, delta) + step(time, delta) { if (this.pendingDestroy) { @@ -500,7 +498,7 @@ var Game = new Class({ // The final event before the step repeats. Your last chance to do anything to the canvas before it all starts again. eventEmitter.emit(Events.POST_RENDER, renderer, time, delta); - }, + } /** * A special version of the Game Step for the HEADLESS renderer only. @@ -520,7 +518,7 @@ var Game = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - headlessStep: function (time, delta) + headlessStep(time, delta) { if (this.pendingDestroy) { @@ -556,7 +554,7 @@ var Game = new Class({ eventEmitter.emit(Events.PRE_RENDER, null, time, delta); eventEmitter.emit(Events.POST_RENDER, null, time, delta); - }, + } /** * Called automatically by the Visibility Handler. @@ -567,12 +565,12 @@ var Game = new Class({ * @fires Phaser.Core.Events#PAUSE * @since 3.0.0 */ - onHidden: function () + onHidden() { this.loop.pause(); this.events.emit(Events.PAUSE); - }, + } /** * This will pause the entire game and emit a `PAUSE` event. @@ -585,7 +583,7 @@ var Game = new Class({ * @fires Phaser.Core.Events#PAUSE * @since 3.60.0 */ - pause: function () + pause() { var wasPaused = this.isPaused; @@ -595,7 +593,7 @@ var Game = new Class({ { this.events.emit(Events.PAUSE); } - }, + } /** * Called automatically by the Visibility Handler. @@ -606,12 +604,12 @@ var Game = new Class({ * @fires Phaser.Core.Events#RESUME * @since 3.0.0 */ - onVisible: function () + onVisible() { this.loop.resume(); this.events.emit(Events.RESUME, this.loop.pauseDuration); - }, + } /** * This will resume the entire game and emit a `RESUME` event. @@ -622,7 +620,7 @@ var Game = new Class({ * @fires Phaser.Core.Events#RESUME * @since 3.60.0 */ - resume: function () + resume() { var wasPaused = this.isPaused; @@ -632,7 +630,7 @@ var Game = new Class({ { this.events.emit(Events.RESUME, 0); } - }, + } /** * Called automatically by the Visibility Handler. @@ -642,12 +640,12 @@ var Game = new Class({ * @protected * @since 3.0.0 */ - onBlur: function () + onBlur() { this.hasFocus = false; this.loop.blur(); - }, + } /** * Called automatically by the Visibility Handler. @@ -657,12 +655,12 @@ var Game = new Class({ * @protected * @since 3.0.0 */ - onFocus: function () + onFocus() { this.hasFocus = true; this.loop.focus(); - }, + } /** * Returns the current game frame. @@ -674,10 +672,10 @@ var Game = new Class({ * * @return {number} The current game frame. */ - getFrame: function () + getFrame() { return this.loop.frame; - }, + } /** * Returns the time that the current game step started at, as based on `performance.now`. @@ -687,10 +685,10 @@ var Game = new Class({ * * @return {number} The current game timestamp. */ - getTime: function () + getTime() { return this.loop.now; - }, + } /** * Flags this Game instance as needing to be destroyed on the _next frame_, making this an asynchronous operation. @@ -709,7 +707,7 @@ var Game = new Class({ * @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. * @param {boolean} [noReturn=false] - If `true` all the core Phaser plugins are destroyed. You cannot create another instance of Phaser on the same web page if you do this. */ - destroy: function (removeCanvas, noReturn) + destroy(removeCanvas, noReturn) { if (noReturn === undefined) { noReturn = false; } @@ -717,7 +715,7 @@ var Game = new Class({ this.removeCanvas = removeCanvas; this.noReturn = noReturn; - }, + } /** * Destroys this Phaser.Game instance, all global systems, all sub-systems and all Scenes. @@ -726,7 +724,7 @@ var Game = new Class({ * @private * @since 3.5.0 */ - runDestroy: function () + runDestroy() { this.scene.destroy(); @@ -759,7 +757,7 @@ var Game = new Class({ this.pendingDestroy = false; } -}); +}; module.exports = Game; diff --git a/src/core/TimeStep.js b/src/core/TimeStep.js index 28a58061c3..756edd5480 100644 --- a/src/core/TimeStep.js +++ b/src/core/TimeStep.js @@ -34,11 +34,9 @@ var RequestAnimationFrame = require('../dom/RequestAnimationFrame'); * @param {Phaser.Game} game - A reference to the Phaser.Game instance that owns this Time Step. * @param {Phaser.Types.Core.FPSConfig} config */ -var TimeStep = new Class({ +var TimeStep = class { - initialize: - - function TimeStep (game, config) + constructor(game, config) { /** * A reference to the Phaser.Game instance. @@ -433,7 +431,7 @@ var TimeStep = new Class({ * @since 3.22.0 */ this.smoothStep = GetValue(config, 'smoothStep', true); - }, + } /** * Called by the Game instance when the DOM window.onBlur event triggers. @@ -441,10 +439,10 @@ var TimeStep = new Class({ * @method Phaser.Core.TimeStep#blur * @since 3.0.0 */ - blur: function () + blur() { this.inFocus = false; - }, + } /** * Called by the Game instance when the DOM window.onFocus event triggers. @@ -452,12 +450,12 @@ var TimeStep = new Class({ * @method Phaser.Core.TimeStep#focus * @since 3.0.0 */ - focus: function () + focus() { this.inFocus = true; this.resetDelta(); - }, + } /** * Called when the visibility API says the game is 'hidden' (tab switch out of view, etc) @@ -465,10 +463,10 @@ var TimeStep = new Class({ * @method Phaser.Core.TimeStep#pause * @since 3.0.0 */ - pause: function () + pause() { this._pauseTime = window.performance.now(); - }, + } /** * Called when the visibility API says the game is 'visible' again (tab switch back into view, etc) @@ -476,13 +474,13 @@ var TimeStep = new Class({ * @method Phaser.Core.TimeStep#resume * @since 3.0.0 */ - resume: function () + resume() { this.resetDelta(); this.pauseDuration = this.time - this._pauseTime; this.startTime += this.pauseDuration; - }, + } /** * Resets the time, lastTime, fps averages and delta history. @@ -491,7 +489,7 @@ var TimeStep = new Class({ * @method Phaser.Core.TimeStep#resetDelta * @since 3.0.0 */ - resetDelta: function () + resetDelta() { var now = window.performance.now(); @@ -511,7 +509,7 @@ var TimeStep = new Class({ this.deltaIndex = 0; this._coolDown = this.panicMax; - }, + } /** * Starts the Time Step running, if it is not already doing so. @@ -522,7 +520,7 @@ var TimeStep = new Class({ * * @param {Phaser.Types.Core.TimeStepCallback} callback - The callback to be invoked each time the Time Step steps. */ - start: function (callback) + start(callback) { if (this.started) { @@ -546,7 +544,7 @@ var TimeStep = new Class({ var step = (this.hasFpsLimit) ? this.stepLimitFPS.bind(this) : this.step.bind(this); this.raf.start(step, this.forceSetTimeOut, this._target); - }, + } /** * Takes the delta value and smooths it based on the previous frames. @@ -560,7 +558,7 @@ var TimeStep = new Class({ * * @return {number} The smoothed delta value. */ - smoothDelta: function (delta) + smoothDelta(delta) { var idx = this.deltaIndex; var history = this.deltaHistory; @@ -610,7 +608,7 @@ var TimeStep = new Class({ avg /= max; return avg; - }, + } /** * Update the estimate of the frame rate, `fps`. Every second, the number @@ -640,12 +638,12 @@ var TimeStep = new Class({ * * @param {number} time - The timestamp passed in from RequestAnimationFrame or setTimeout. */ - updateFPS: function (time) + updateFPS(time) { this.actualFps = 0.25 * this.framesThisSecond + 0.75 * this.actualFps; this.nextFpsUpdate = time + 1000; this.framesThisSecond = 0; - }, + } /** * The main step method with an fps limiter. This is called each time the browser updates, either by Request Animation Frame, @@ -657,7 +655,7 @@ var TimeStep = new Class({ * * @param {number} time - The timestamp passed in from RequestAnimationFrame or setTimeout. */ - stepLimitFPS: function (time) + stepLimitFPS(time) { this.now = time; @@ -696,7 +694,7 @@ var TimeStep = new Class({ this.lastTime = time; this.frame++; - }, + } /** * The main step method. This is called each time the browser updates, either by Request Animation Frame, @@ -708,7 +706,7 @@ var TimeStep = new Class({ * * @param {number} time - The timestamp passed in from RequestAnimationFrame or setTimeout. */ - step: function (time) + step(time) { this.now = time; @@ -742,7 +740,7 @@ var TimeStep = new Class({ this.lastTime = time; this.frame++; - }, + } /** * Manually calls `TimeStep.step`. @@ -750,7 +748,7 @@ var TimeStep = new Class({ * @method Phaser.Core.TimeStep#tick * @since 3.0.0 */ - tick: function () + tick() { var now = window.performance.now(); @@ -762,7 +760,7 @@ var TimeStep = new Class({ { this.step(now); } - }, + } /** * Sends the TimeStep to sleep, stopping Request Animation Frame (or SetTimeout) and toggling the `running` flag to false. @@ -770,7 +768,7 @@ var TimeStep = new Class({ * @method Phaser.Core.TimeStep#sleep * @since 3.0.0 */ - sleep: function () + sleep() { if (this.running) { @@ -778,7 +776,7 @@ var TimeStep = new Class({ this.running = false; } - }, + } /** * Wakes-up the TimeStep, restarting Request Animation Frame (or SetTimeout) and toggling the `running` flag to true. @@ -789,7 +787,7 @@ var TimeStep = new Class({ * * @param {boolean} [seamless=false] - Adjust the startTime based on the lastTime values. */ - wake: function (seamless) + wake(seamless) { if (seamless === undefined) { seamless = false; } @@ -815,7 +813,7 @@ var TimeStep = new Class({ this.fpsLimitTriggered = false; this.tick(); - }, + } /** * Gets the duration which the game has been running, in seconds. @@ -825,10 +823,10 @@ var TimeStep = new Class({ * * @return {number} The duration in seconds. */ - getDuration: function () + getDuration() { return Math.round(this.lastTime - this.startTime) / 1000; - }, + } /** * Gets the duration which the game has been running, in ms. @@ -838,10 +836,10 @@ var TimeStep = new Class({ * * @return {number} The duration in ms. */ - getDurationMS: function () + getDurationMS() { return Math.round(this.lastTime - this.startTime); - }, + } /** * Stops the TimeStep running. @@ -851,7 +849,7 @@ var TimeStep = new Class({ * * @return {this} The TimeStep object. */ - stop: function () + stop() { this.running = false; this.started = false; @@ -859,7 +857,7 @@ var TimeStep = new Class({ this.raf.stop(); return this; - }, + } /** * Destroys the TimeStep. This will stop Request Animation Frame, stop the step, clear the callbacks and null @@ -868,7 +866,7 @@ var TimeStep = new Class({ * @method Phaser.Core.TimeStep#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.stop(); @@ -879,6 +877,6 @@ var TimeStep = new Class({ this.callback = null; } -}); +}; module.exports = TimeStep; diff --git a/src/curves/CubicBezierCurve.js b/src/curves/CubicBezierCurve.js index 94561fcc66..230c9f785e 100644 --- a/src/curves/CubicBezierCurve.js +++ b/src/curves/CubicBezierCurve.js @@ -26,15 +26,11 @@ var Vector2 = require('../math/Vector2'); * @param {Phaser.Math.Vector2} p2 - Control Point 2. * @param {Phaser.Math.Vector2} p3 - End Point. */ -var CubicBezierCurve = new Class({ +var CubicBezierCurve = class extends Curve { - Extends: Curve, - - initialize: - - function CubicBezierCurve (p0, p1, p2, p3) + constructor(p0, p1, p2, p3) { - Curve.call(this, 'CubicBezierCurve'); + super('CubicBezierCurve'); if (Array.isArray(p0)) { @@ -79,7 +75,7 @@ var CubicBezierCurve = new Class({ * @since 3.0.0 */ this.p3 = p3; - }, + } /** * Gets the starting point on the curve. @@ -93,12 +89,12 @@ var CubicBezierCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getStartPoint: function (out) + getStartPoint(out) { if (out === undefined) { out = new Vector2(); } return out.copy(this.p0); - }, + } /** * Returns the resolution of this curve. @@ -110,10 +106,10 @@ var CubicBezierCurve = new Class({ * * @return {number} The resolution of the curve. */ - getResolution: function (divisions) + getResolution(divisions) { return divisions; - }, + } /** * Get point at relative position in curve according to length. @@ -128,7 +124,7 @@ var CubicBezierCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getPoint: function (t, out) + getPoint(t, out) { if (out === undefined) { out = new Vector2(); } @@ -138,7 +134,7 @@ var CubicBezierCurve = new Class({ var p3 = this.p3; return out.set(CubicBezier(t, p0.x, p1.x, p2.x, p3.x), CubicBezier(t, p0.y, p1.y, p2.y, p3.y)); - }, + } /** * Draws this curve to the specified graphics object. @@ -153,7 +149,7 @@ var CubicBezierCurve = new Class({ * * @return {Phaser.GameObjects.Graphics} The graphics object this curve was drawn to. Useful for method chaining. */ - draw: function (graphics, pointsTotal) + draw(graphics, pointsTotal) { if (pointsTotal === undefined) { pointsTotal = 32; } @@ -171,7 +167,7 @@ var CubicBezierCurve = new Class({ // So you can chain graphics calls return graphics; - }, + } /** * Returns a JSON object that describes this curve. @@ -181,7 +177,7 @@ var CubicBezierCurve = new Class({ * * @return {Phaser.Types.Curves.JSONCurve} The JSON object containing this curve data. */ - toJSON: function () + toJSON() { return { type: this.type, @@ -194,7 +190,7 @@ var CubicBezierCurve = new Class({ }; } -}); +}; /** * Generates a curve from a JSON object. diff --git a/src/curves/Curve.js b/src/curves/Curve.js index 599dbddc55..87042fccb0 100644 --- a/src/curves/Curve.js +++ b/src/curves/Curve.js @@ -22,11 +22,9 @@ var Vector2 = require('../math/Vector2'); * * @param {string} type - The curve type. */ -var Curve = new Class({ +var Curve = class { - initialize: - - function Curve (type) + constructor(type) { /** * String based identifier for the type of curve. @@ -106,7 +104,7 @@ var Curve = new Class({ * @since 3.0.0 */ this._tmpVec2B = new Vector2(); - }, + } /** * Draws this curve on the given Graphics object. @@ -124,13 +122,13 @@ var Curve = new Class({ * * @return {Phaser.GameObjects.Graphics} The Graphics object to which the curve was drawn. */ - draw: function (graphics, pointsTotal) + draw(graphics, pointsTotal) { if (pointsTotal === undefined) { pointsTotal = 32; } // So you can chain graphics calls return graphics.strokePoints(this.getPoints(pointsTotal)); - }, + } /** * Returns a Rectangle where the position and dimensions match the bounds of this Curve. @@ -146,7 +144,7 @@ var Curve = new Class({ * * @return {Phaser.Geom.Rectangle} A Rectangle object holding the bounds of this curve. If `out` was given it will be this object. */ - getBounds: function (out, accuracy) + getBounds(out, accuracy) { if (!out) { out = new Rectangle(); } if (accuracy === undefined) { accuracy = 16; } @@ -164,7 +162,7 @@ var Curve = new Class({ var spaced = Math.max(1, Math.round(len / accuracy)); return FromPoints(this.getSpacedPoints(spaced), out); - }, + } /** * Returns an array of points, spaced out X distance pixels apart. @@ -177,14 +175,14 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2[]} An Array of Vector2 objects. */ - getDistancePoints: function (distance) + getDistancePoints(distance) { var len = this.getLength(); var spaced = Math.max(1, len / distance); return this.getSpacedPoints(spaced); - }, + } /** * Get a point at the end of the curve. @@ -196,12 +194,12 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2} Vector2 containing the coordinates of the curves end point. */ - getEndPoint: function (out) + getEndPoint(out) { if (out === undefined) { out = new Vector2(); } return this.getPointAt(1, out); - }, + } /** * Get total curve arc length @@ -211,12 +209,12 @@ var Curve = new Class({ * * @return {number} The total length of the curve. */ - getLength: function () + getLength() { var lengths = this.getLengths(); return lengths[lengths.length - 1]; - }, + } /** @@ -237,7 +235,7 @@ var Curve = new Class({ * * @return {number[]} An array of cumulative lengths. */ - getLengths: function (divisions) + getLengths(divisions) { if (divisions === undefined) { divisions = this.arcLengthDivisions; } @@ -269,7 +267,7 @@ var Curve = new Class({ this.cacheArcLengths = cache; return cache; // { sums: cache, sum:sum }; Sum is in the last element. - }, + } // Get point at relative position in curve according to arc length @@ -288,12 +286,12 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2} The point. */ - getPointAt: function (u, out) + getPointAt(u, out) { var t = this.getUtoTmapping(u); return this.getPoint(t, out); - }, + } // Get sequence of points using getPoint( t ) @@ -321,7 +319,7 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2[]} An array of Vector2 points from the curve. */ - getPoints: function (divisions, stepRate, out) + getPoints(divisions, stepRate, out) { if (out === undefined) { out = []; } @@ -344,7 +342,7 @@ var Curve = new Class({ } return out; - }, + } /** * Get a random point from the curve. @@ -358,12 +356,12 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2} The point. */ - getRandomPoint: function (out) + getRandomPoint(out) { if (out === undefined) { out = new Vector2(); } return this.getPoint(Math.random(), out); - }, + } // Get sequence of points using getPointAt( u ) @@ -381,7 +379,7 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2[]} An array of Vector2 points. */ - getSpacedPoints: function (divisions, stepRate, out) + getSpacedPoints(divisions, stepRate, out) { if (out === undefined) { out = []; } @@ -406,7 +404,7 @@ var Curve = new Class({ } return out; - }, + } /** * Get a point at the start of the curve. @@ -420,12 +418,12 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2} The point. */ - getStartPoint: function (out) + getStartPoint(out) { if (out === undefined) { out = new Vector2(); } return this.getPointAt(0, out); - }, + } /** * Get a unit vector tangent at a relative position on the curve. @@ -443,7 +441,7 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2} Vector approximating the tangent line at the point t (delta +/- 0.0001) */ - getTangent: function (t, out) + getTangent(t, out) { if (out === undefined) { out = new Vector2(); } @@ -467,7 +465,7 @@ var Curve = new Class({ this.getPoint(t2, out); return out.subtract(this._tmpVec2A).normalize(); - }, + } /** * Get a unit vector tangent at a relative position on the curve, by arc length. @@ -482,12 +480,12 @@ var Curve = new Class({ * * @return {Phaser.Math.Vector2} The tangent vector. */ - getTangentAt: function (u, out) + getTangentAt(u, out) { var t = this.getUtoTmapping(u); return this.getTangent(t, out); - }, + } /** * Given a distance in pixels, get a t to find p. @@ -500,7 +498,7 @@ var Curve = new Class({ * * @return {number} The distance. */ - getTFromDistance: function (distance, divisions) + getTFromDistance(distance, divisions) { if (distance <= 0) { @@ -508,7 +506,7 @@ var Curve = new Class({ } return this.getUtoTmapping(0, distance, divisions); - }, + } /** * Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant. @@ -522,7 +520,7 @@ var Curve = new Class({ * * @return {number} The equidistant value. */ - getUtoTmapping: function (u, distance, divisions) + getUtoTmapping(u, distance, divisions) { var arcLengths = this.getLengths(divisions); @@ -589,7 +587,7 @@ var Curve = new Class({ // add that fractional amount to t return (i + segmentFraction) / (il - 1); - }, + } /** * Calculate and cache the arc lengths. @@ -599,13 +597,13 @@ var Curve = new Class({ * * @see Phaser.Curves.Curve#getLengths() */ - updateArcLengths: function () + updateArcLengths() { this.needsUpdate = true; this.getLengths(); } -}); +}; module.exports = Curve; diff --git a/src/curves/EllipseCurve.js b/src/curves/EllipseCurve.js index 4f8045c946..1a7c61f1b5 100644 --- a/src/curves/EllipseCurve.js +++ b/src/curves/EllipseCurve.js @@ -34,13 +34,9 @@ var Vector2 = require('../math/Vector2'); * @param {boolean} [clockwise=false] - Whether the ellipse angles are given as clockwise (`true`) or counter-clockwise (`false`). * @param {number} [rotation=0] - The rotation of the ellipse, in degrees. */ -var EllipseCurve = new Class({ +var EllipseCurve = class extends Curve { - Extends: Curve, - - initialize: - - function EllipseCurve (x, y, xRadius, yRadius, startAngle, endAngle, clockwise, rotation) + constructor(x, y, xRadius, yRadius, startAngle, endAngle, clockwise, rotation) { if (typeof x === 'object') { @@ -64,7 +60,7 @@ var EllipseCurve = new Class({ if (rotation === undefined) { rotation = 0; } } - Curve.call(this, 'EllipseCurve'); + super('EllipseCurve'); // Center point @@ -138,7 +134,7 @@ var EllipseCurve = new Class({ * @since 3.0.0 */ this._rotation = DegToRad(rotation); - }, + } /** * Gets the starting point on the curve. @@ -152,12 +148,12 @@ var EllipseCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getStartPoint: function (out) + getStartPoint(out) { if (out === undefined) { out = new Vector2(); } return this.getPoint(0, out); - }, + } /** * Get the resolution of the curve. @@ -169,10 +165,10 @@ var EllipseCurve = new Class({ * * @return {number} The curve resolution. */ - getResolution: function (divisions) + getResolution(divisions) { return divisions * 2; - }, + } /** * Get point at relative position in curve according to length. @@ -187,7 +183,7 @@ var EllipseCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getPoint: function (t, out) + getPoint(t, out) { if (out === undefined) { out = new Vector2(); } @@ -248,7 +244,7 @@ var EllipseCurve = new Class({ } return out.set(x, y); - }, + } /** * Sets the horizontal radius of this curve. @@ -260,12 +256,12 @@ var EllipseCurve = new Class({ * * @return {this} This curve object. */ - setXRadius: function (value) + setXRadius(value) { this.xRadius = value; return this; - }, + } /** * Sets the vertical radius of this curve. @@ -277,12 +273,12 @@ var EllipseCurve = new Class({ * * @return {this} This curve object. */ - setYRadius: function (value) + setYRadius(value) { this.yRadius = value; return this; - }, + } /** * Sets the width of this curve. @@ -294,12 +290,12 @@ var EllipseCurve = new Class({ * * @return {this} This curve object. */ - setWidth: function (value) + setWidth(value) { this.xRadius = value / 2; return this; - }, + } /** * Sets the height of this curve. @@ -311,12 +307,12 @@ var EllipseCurve = new Class({ * * @return {this} This curve object. */ - setHeight: function (value) + setHeight(value) { this.yRadius = value / 2; return this; - }, + } /** * Sets the start angle of this curve. @@ -328,12 +324,12 @@ var EllipseCurve = new Class({ * * @return {this} This curve object. */ - setStartAngle: function (value) + setStartAngle(value) { this.startAngle = value; return this; - }, + } /** * Sets the end angle of this curve. @@ -345,12 +341,12 @@ var EllipseCurve = new Class({ * * @return {this} This curve object. */ - setEndAngle: function (value) + setEndAngle(value) { this.endAngle = value; return this; - }, + } /** * Sets if this curve extends clockwise or anti-clockwise. @@ -362,12 +358,12 @@ var EllipseCurve = new Class({ * * @return {this} This curve object. */ - setClockwise: function (value) + setClockwise(value) { this.clockwise = value; return this; - }, + } /** * Sets the rotation of this curve. @@ -379,12 +375,12 @@ var EllipseCurve = new Class({ * * @return {this} This curve object. */ - setRotation: function (value) + setRotation(value) { this.rotation = value; return this; - }, + } /** * The x coordinate of the center of the ellipse. @@ -393,19 +389,16 @@ var EllipseCurve = new Class({ * @type {number} * @since 3.0.0 */ - x: { - get: function () - { - return this.p0.x; - }, - - set: function (value) - { - this.p0.x = value; - } + get x() + { + return this.p0.x; + } - }, + set x(value) + { + this.p0.x = value; + } /** * The y coordinate of the center of the ellipse. @@ -414,19 +407,16 @@ var EllipseCurve = new Class({ * @type {number} * @since 3.0.0 */ - y: { - get: function () - { - return this.p0.y; - }, - - set: function (value) - { - this.p0.y = value; - } + get y() + { + return this.p0.y; + } - }, + set y(value) + { + this.p0.y = value; + } /** * The horizontal radius of the ellipse. @@ -435,19 +425,16 @@ var EllipseCurve = new Class({ * @type {number} * @since 3.0.0 */ - xRadius: { - get: function () - { - return this._xRadius; - }, - - set: function (value) - { - this._xRadius = value; - } + get xRadius() + { + return this._xRadius; + } - }, + set xRadius(value) + { + this._xRadius = value; + } /** * The vertical radius of the ellipse. @@ -456,19 +443,16 @@ var EllipseCurve = new Class({ * @type {number} * @since 3.0.0 */ - yRadius: { - get: function () - { - return this._yRadius; - }, - - set: function (value) - { - this._yRadius = value; - } + get yRadius() + { + return this._yRadius; + } - }, + set yRadius(value) + { + this._yRadius = value; + } /** * The start angle of the ellipse in degrees. @@ -477,19 +461,16 @@ var EllipseCurve = new Class({ * @type {number} * @since 3.0.0 */ - startAngle: { - - get: function () - { - return RadToDeg(this._startAngle); - }, - set: function (value) - { - this._startAngle = DegToRad(value); - } + get startAngle() + { + return RadToDeg(this._startAngle); + } - }, + set startAngle(value) + { + this._startAngle = DegToRad(value); + } /** * The end angle of the ellipse in degrees. @@ -498,19 +479,16 @@ var EllipseCurve = new Class({ * @type {number} * @since 3.0.0 */ - endAngle: { - - get: function () - { - return RadToDeg(this._endAngle); - }, - set: function (value) - { - this._endAngle = DegToRad(value); - } + get endAngle() + { + return RadToDeg(this._endAngle); + } - }, + set endAngle(value) + { + this._endAngle = DegToRad(value); + } /** * `true` if the ellipse rotation is clockwise or `false` if anti-clockwise. @@ -519,19 +497,16 @@ var EllipseCurve = new Class({ * @type {boolean} * @since 3.0.0 */ - clockwise: { - - get: function () - { - return this._clockwise; - }, - set: function (value) - { - this._clockwise = value; - } + get clockwise() + { + return this._clockwise; + } - }, + set clockwise(value) + { + this._clockwise = value; + } /** * The rotation of the ellipse, relative to the center, in degrees. @@ -540,19 +515,16 @@ var EllipseCurve = new Class({ * @type {number} * @since 3.14.0 */ - angle: { - - get: function () - { - return RadToDeg(this._rotation); - }, - set: function (value) - { - this._rotation = DegToRad(value); - } + get angle() + { + return RadToDeg(this._rotation); + } - }, + set angle(value) + { + this._rotation = DegToRad(value); + } /** * The rotation of the ellipse, relative to the center, in radians. @@ -561,19 +533,16 @@ var EllipseCurve = new Class({ * @type {number} * @since 3.0.0 */ - rotation: { - - get: function () - { - return this._rotation; - }, - set: function (value) - { - this._rotation = value; - } + get rotation() + { + return this._rotation; + } - }, + set rotation(value) + { + this._rotation = value; + } /** * JSON serialization of the curve. @@ -583,7 +552,7 @@ var EllipseCurve = new Class({ * * @return {Phaser.Types.Curves.JSONEllipseCurve} The JSON object containing this curve data. */ - toJSON: function () + toJSON() { return { type: this.type, @@ -598,7 +567,7 @@ var EllipseCurve = new Class({ }; } -}); +}; /** * Creates a curve from the provided Ellipse Curve Configuration object. diff --git a/src/curves/LineCurve.js b/src/curves/LineCurve.js index 91901743cc..e95e1bb9b3 100644 --- a/src/curves/LineCurve.js +++ b/src/curves/LineCurve.js @@ -25,16 +25,12 @@ var Vector2 = require('../math/Vector2'); * @param {(Phaser.Math.Vector2|number[])} p0 - The first endpoint. * @param {Phaser.Math.Vector2} [p1] - The second endpoint. */ -var LineCurve = new Class({ - - Extends: Curve, +var LineCurve = class extends Curve { // vec2s or array - initialize: - - function LineCurve (p0, p1) + constructor(p0, p1) { - Curve.call(this, 'LineCurve'); + super('LineCurve'); if (Array.isArray(p0)) { @@ -71,7 +67,7 @@ var LineCurve = new Class({ * @since 3.0.0 */ this.arcLengthDivisions = 1; - }, + } /** * Returns a Rectangle where the position and dimensions match the bounds of this Curve. @@ -85,12 +81,12 @@ var LineCurve = new Class({ * * @return {Phaser.Geom.Rectangle} A Rectangle object holding the bounds of this curve. If `out` was given it will be this object. */ - getBounds: function (out) + getBounds(out) { if (out === undefined) { out = new Rectangle(); } return FromPoints([ this.p0, this.p1 ], out); - }, + } /** * Gets the starting point on the curve. @@ -104,12 +100,12 @@ var LineCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getStartPoint: function (out) + getStartPoint(out) { if (out === undefined) { out = new Vector2(); } return out.copy(this.p0); - }, + } /** * Gets the resolution of the line. @@ -121,12 +117,12 @@ var LineCurve = new Class({ * * @return {number} The resolution. Equal to the number of divisions. */ - getResolution: function (divisions) + getResolution(divisions) { if (divisions === undefined) { divisions = 1; } return divisions; - }, + } /** * Get point at relative position in curve according to length. @@ -141,7 +137,7 @@ var LineCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getPoint: function (t, out) + getPoint(t, out) { if (out === undefined) { out = new Vector2(); } @@ -153,7 +149,7 @@ var LineCurve = new Class({ out.copy(this.p1).subtract(this.p0).scale(t).add(this.p0); return out; - }, + } // Line curve is linear, so we can overwrite default getPointAt @@ -170,10 +166,10 @@ var LineCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getPointAt: function (u, out) + getPointAt(u, out) { return this.getPoint(u, out); - }, + } /** * Gets the slope of the line as a unit vector. @@ -188,14 +184,14 @@ var LineCurve = new Class({ * * @return {Phaser.Math.Vector2} The tangent vector. */ - getTangent: function (t, out) + getTangent(t, out) { if (out === undefined) { out = new Vector2(); } out.copy(this.p1).subtract(this.p0).normalize(); return out; - }, + } /** * Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant. @@ -209,7 +205,7 @@ var LineCurve = new Class({ * * @return {number} The equidistant value. */ - getUtoTmapping: function (u, distance, divisions) + getUtoTmapping(u, distance, divisions) { var t; @@ -229,7 +225,7 @@ var LineCurve = new Class({ } return t; - }, + } // Override default Curve.draw because this is better than calling getPoints on a line! @@ -248,13 +244,13 @@ var LineCurve = new Class({ * * @return {Phaser.GameObjects.Graphics} The Graphics object to which the curve was drawn. */ - draw: function (graphics) + draw(graphics) { graphics.lineBetween(this.p0.x, this.p0.y, this.p1.x, this.p1.y); // So you can chain graphics calls return graphics; - }, + } /** * Gets a JSON representation of the line. @@ -264,7 +260,7 @@ var LineCurve = new Class({ * * @return {Phaser.Types.Curves.JSONCurve} The JSON object containing this curve data. */ - toJSON: function () + toJSON() { return { type: this.type, @@ -275,7 +271,7 @@ var LineCurve = new Class({ }; } -}); +}; /** * Configures this line from a JSON representation. diff --git a/src/curves/QuadraticBezierCurve.js b/src/curves/QuadraticBezierCurve.js index 32a8844c08..b92e77199d 100644 --- a/src/curves/QuadraticBezierCurve.js +++ b/src/curves/QuadraticBezierCurve.js @@ -23,15 +23,11 @@ var Vector2 = require('../math/Vector2'); * @param {Phaser.Math.Vector2} p1 - Control Point 1. * @param {Phaser.Math.Vector2} p2 - Control Point 2. */ -var QuadraticBezier = new Class({ +var QuadraticBezier = class extends Curve { - Extends: Curve, - - initialize: - - function QuadraticBezier (p0, p1, p2) + constructor(p0, p1, p2) { - Curve.call(this, 'QuadraticBezierCurve'); + super('QuadraticBezierCurve'); if (Array.isArray(p0)) { @@ -66,7 +62,7 @@ var QuadraticBezier = new Class({ * @since 3.2.0 */ this.p2 = p2; - }, + } /** * Gets the starting point on the curve. @@ -80,12 +76,12 @@ var QuadraticBezier = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getStartPoint: function (out) + getStartPoint(out) { if (out === undefined) { out = new Vector2(); } return out.copy(this.p0); - }, + } /** * Get the resolution of the curve. @@ -97,10 +93,10 @@ var QuadraticBezier = new Class({ * * @return {number} The curve resolution. */ - getResolution: function (divisions) + getResolution(divisions) { return divisions; - }, + } /** * Get point at relative position in curve according to length. @@ -115,7 +111,7 @@ var QuadraticBezier = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getPoint: function (t, out) + getPoint(t, out) { if (out === undefined) { out = new Vector2(); } @@ -127,7 +123,7 @@ var QuadraticBezier = new Class({ QuadraticBezierInterpolation(t, p0.x, p1.x, p2.x), QuadraticBezierInterpolation(t, p0.y, p1.y, p2.y) ); - }, + } /** * Draws this curve on the given Graphics object. @@ -145,7 +141,7 @@ var QuadraticBezier = new Class({ * * @return {Phaser.GameObjects.Graphics} `Graphics` object that was drawn to. */ - draw: function (graphics, pointsTotal) + draw(graphics, pointsTotal) { if (pointsTotal === undefined) { pointsTotal = 32; } @@ -163,7 +159,7 @@ var QuadraticBezier = new Class({ // So you can chain graphics calls return graphics; - }, + } /** * Converts the curve into a JSON compatible object. @@ -173,7 +169,7 @@ var QuadraticBezier = new Class({ * * @return {Phaser.Types.Curves.JSONCurve} The JSON object containing this curve data. */ - toJSON: function () + toJSON() { return { type: this.type, @@ -185,7 +181,7 @@ var QuadraticBezier = new Class({ }; } -}); +}; /** * Creates a curve from a JSON object, e. g. created by `toJSON`. diff --git a/src/curves/SplineCurve.js b/src/curves/SplineCurve.js index fbe932c012..e55343b681 100644 --- a/src/curves/SplineCurve.js +++ b/src/curves/SplineCurve.js @@ -23,17 +23,13 @@ var Vector2 = require('../math/Vector2'); * * @param {(Phaser.Math.Vector2[]|number[]|number[][])} [points] - The points that configure the curve. */ -var SplineCurve = new Class({ +var SplineCurve = class extends Curve { - Extends: Curve, - - initialize: - - function SplineCurve (points) + constructor(points) { if (points === undefined) { points = []; } - Curve.call(this, 'SplineCurve'); + super('SplineCurve'); /** * The Vector2 points that configure the curve. @@ -46,7 +42,7 @@ var SplineCurve = new Class({ this.points = []; this.addPoints(points); - }, + } /** * Add a list of points to the current list of Vector2 points of the curve. @@ -58,7 +54,7 @@ var SplineCurve = new Class({ * * @return {this} This curve object. */ - addPoints: function (points) + addPoints(points) { for (var i = 0; i < points.length; i++) { @@ -86,7 +82,7 @@ var SplineCurve = new Class({ } return this; - }, + } /** * Add a point to the current list of Vector2 points of the curve. @@ -99,14 +95,14 @@ var SplineCurve = new Class({ * * @return {Phaser.Math.Vector2} The new Vector2 added to the curve */ - addPoint: function (x, y) + addPoint(x, y) { var vec = new Vector2(x, y); this.points.push(vec); return vec; - }, + } /** * Gets the starting point on the curve. @@ -120,12 +116,12 @@ var SplineCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getStartPoint: function (out) + getStartPoint(out) { if (out === undefined) { out = new Vector2(); } return out.copy(this.points[0]); - }, + } /** * Get the resolution of the curve. @@ -137,10 +133,10 @@ var SplineCurve = new Class({ * * @return {number} The curve resolution. */ - getResolution: function (divisions) + getResolution(divisions) { return divisions * this.points.length; - }, + } /** * Get point at relative position in curve according to length. @@ -155,7 +151,7 @@ var SplineCurve = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getPoint: function (t, out) + getPoint(t, out) { if (out === undefined) { out = new Vector2(); } @@ -173,7 +169,7 @@ var SplineCurve = new Class({ var p3 = points[(intPoint > points.length - 3) ? points.length - 1 : intPoint + 2]; return out.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y)); - }, + } /** * Exports a JSON object containing this curve data. @@ -183,7 +179,7 @@ var SplineCurve = new Class({ * * @return {Phaser.Types.Curves.JSONCurve} The JSON object containing this curve data. */ - toJSON: function () + toJSON() { var points = []; @@ -199,7 +195,7 @@ var SplineCurve = new Class({ }; } -}); +}; /** * Imports a JSON object containing this curve data. diff --git a/src/curves/path/MoveTo.js b/src/curves/path/MoveTo.js index 3bd5a4dd75..fc282cb796 100644 --- a/src/curves/path/MoveTo.js +++ b/src/curves/path/MoveTo.js @@ -20,11 +20,9 @@ var Vector2 = require('../../math/Vector2'); * @param {number} [x=0] - `x` pixel coordinate. * @param {number} [y=0] - `y` pixel coordinate. */ -var MoveTo = new Class({ +var MoveTo = class { - initialize: - - function MoveTo (x, y) + constructor(x, y) { /** * Denotes that this Curve does not influence the bounds, points, and drawing of its parent Path. Must be `false` or some methods in the parent Path will throw errors. @@ -44,7 +42,7 @@ var MoveTo = new Class({ * @since 3.0.0 */ this.p0 = new Vector2(x, y); - }, + } /** * Get point at relative position in curve according to length. @@ -59,12 +57,12 @@ var MoveTo = new Class({ * * @return {Phaser.Math.Vector2} The coordinates of the point on the curve. If an `out` object was given this will be returned. */ - getPoint: function (t, out) + getPoint(t, out) { if (out === undefined) { out = new Vector2(); } return out.copy(this.p0); - }, + } /** * Retrieves the point at given position in the curve. This will always return this curve's only point. @@ -79,10 +77,10 @@ var MoveTo = new Class({ * * @return {Phaser.Math.Vector2} The modified `out` vector, or a new `Vector2` if none was provided. */ - getPointAt: function (u, out) + getPointAt(u, out) { return this.getPoint(u, out); - }, + } /** * Gets the resolution of this curve. @@ -92,10 +90,10 @@ var MoveTo = new Class({ * * @return {number} The resolution of this curve. For a MoveTo the value is always 1. */ - getResolution: function () + getResolution() { return 1; - }, + } /** * Gets the length of this curve. @@ -105,10 +103,10 @@ var MoveTo = new Class({ * * @return {number} The length of this curve. For a MoveTo the value is always 0. */ - getLength: function () + getLength() { return 0; - }, + } /** * Converts this curve into a JSON-serializable object. @@ -118,7 +116,7 @@ var MoveTo = new Class({ * * @return {Phaser.Types.Curves.JSONCurve} A primitive object with the curve's type and only point. */ - toJSON: function () + toJSON() { return { type: 'MoveTo', @@ -128,6 +126,6 @@ var MoveTo = new Class({ }; } -}); +}; module.exports = MoveTo; diff --git a/src/curves/path/Path.js b/src/curves/path/Path.js index 306756ca81..e330e9fa83 100644 --- a/src/curves/path/Path.js +++ b/src/curves/path/Path.js @@ -34,11 +34,9 @@ var MATH_CONST = require('../../math/const'); * @param {number} [x=0] - The X coordinate of the Path's starting point or a {@link Phaser.Types.Curves.JSONPath}. * @param {number} [y=0] - The Y coordinate of the Path's starting point. */ -var Path = new Class({ +var Path = class { - initialize: - - function Path (x, y) + constructor(x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -135,7 +133,7 @@ var Path = new Class({ { this.startPoint.set(x, y); } - }, + } /** * Appends a Curve to the end of the Path. @@ -149,12 +147,12 @@ var Path = new Class({ * * @return {this} This Path object. */ - add: function (curve) + add(curve) { this.curves.push(curve); return this; - }, + } /** * Creates a circular Ellipse Curve positioned at the end of the Path. @@ -168,12 +166,12 @@ var Path = new Class({ * * @return {this} This Path object. */ - circleTo: function (radius, clockwise, rotation) + circleTo(radius, clockwise, rotation) { if (clockwise === undefined) { clockwise = false; } return this.ellipseTo(radius, radius, 0, 360, clockwise, rotation); - }, + } /** * Ensures that the Path is closed. @@ -187,7 +185,7 @@ var Path = new Class({ * * @return {this} This Path object. */ - closePath: function () + closePath() { // Add a line curve if start and end of lines are not connected var startPoint = this.curves[0].getPoint(0); @@ -200,7 +198,7 @@ var Path = new Class({ } return this; - }, + } /** * Creates a cubic bezier curve starting at the previous end point and ending at p3, using p1 and p2 as control points. @@ -217,7 +215,7 @@ var Path = new Class({ * * @return {this} This Path object. */ - cubicBezierTo: function (x, y, control1X, control1Y, control2X, control2Y) + cubicBezierTo(x, y, control1X, control1Y, control2X, control2Y) { var p0 = this.getEndPoint(); var p1; @@ -239,7 +237,7 @@ var Path = new Class({ } return this.add(new CubicBezierCurve(p0, p1, p2, p3)); - }, + } // Creates a quadratic bezier curve starting at the previous end point and ending at p2, using p1 as a control point @@ -256,7 +254,7 @@ var Path = new Class({ * * @return {this} This Path object. */ - quadraticBezierTo: function (x, y, controlX, controlY) + quadraticBezierTo(x, y, controlX, controlY) { var p0 = this.getEndPoint(); var p1; @@ -275,7 +273,7 @@ var Path = new Class({ } return this.add(new QuadraticBezierCurve(p0, p1, p2)); - }, + } /** * Draws all Curves in the Path to a Graphics Game Object. @@ -290,7 +288,7 @@ var Path = new Class({ * * @return {Phaser.GameObjects.Graphics} The Graphics object which was drawn to. */ - draw: function (graphics, pointsTotal) + draw(graphics, pointsTotal) { for (var i = 0; i < this.curves.length; i++) { @@ -305,7 +303,7 @@ var Path = new Class({ } return graphics; - }, + } /** * Creates an ellipse curve positioned at the previous end point, using the given parameters. @@ -322,7 +320,7 @@ var Path = new Class({ * * @return {this} This Path object. */ - ellipseTo: function (xRadius, yRadius, startAngle, endAngle, clockwise, rotation) + ellipseTo(xRadius, yRadius, startAngle, endAngle, clockwise, rotation) { var ellipse = new EllipseCurve(0, 0, xRadius, yRadius, startAngle, endAngle, clockwise, rotation); @@ -337,7 +335,7 @@ var Path = new Class({ ellipse.y = end.y; return this.add(ellipse); - }, + } /** * Creates a Path from a Path Configuration object. @@ -351,7 +349,7 @@ var Path = new Class({ * * @return {this} This Path object. */ - fromJSON: function (data) + fromJSON(data) { // data should be an object matching the Path.toJSON object structure. @@ -391,7 +389,7 @@ var Path = new Class({ } return this; - }, + } /** * Returns a Rectangle with a position and size matching the bounds of this Path. @@ -406,7 +404,7 @@ var Path = new Class({ * * @return {Phaser.Geom.Rectangle} The modified `out` Rectangle, or a new Rectangle if none was provided. */ - getBounds: function (out, accuracy) + getBounds(out, accuracy) { if (out === undefined) { out = new Rectangle(); } if (accuracy === undefined) { accuracy = 16; } @@ -440,7 +438,7 @@ var Path = new Class({ out.bottom = maxBottom; return out; - }, + } /** * Returns an array containing the length of the Path at the end of each Curve. @@ -452,7 +450,7 @@ var Path = new Class({ * * @return {number[]} An array containing the length of the Path at the end of each one of its Curves. */ - getCurveLengths: function () + getCurveLengths() { // We use cache values if curves and cache array are same length @@ -477,7 +475,7 @@ var Path = new Class({ this.cacheLengths = lengths; return lengths; - }, + } /** * Returns the Curve that forms the Path at the given normalized location (between 0 and 1). @@ -489,7 +487,7 @@ var Path = new Class({ * * @return {?Phaser.Curves.Curve} The Curve that is part of this Path at a given location, or `null` if no curve was found. */ - getCurveAt: function (t) + getCurveAt(t) { var d = t * this.getLength(); var curveLengths = this.getCurveLengths(); @@ -506,7 +504,7 @@ var Path = new Class({ } return null; - }, + } /** * Returns the ending point of the Path. @@ -522,7 +520,7 @@ var Path = new Class({ * * @return {Phaser.Math.Vector2} The modified `out` object, or a new Vector2 if none was provided. */ - getEndPoint: function (out) + getEndPoint(out) { if (out === undefined) { out = new Vector2(); } @@ -536,7 +534,7 @@ var Path = new Class({ } return out; - }, + } /** * Returns the total length of the Path. @@ -548,12 +546,12 @@ var Path = new Class({ * * @return {number} The total length of the Path. */ - getLength: function () + getLength() { var lens = this.getCurveLengths(); return lens[lens.length - 1]; - }, + } // To get accurate point with reference to // entire path distance at time t, @@ -579,7 +577,7 @@ var Path = new Class({ * * @return {?Phaser.Math.Vector2} The modified `out` object, or a new `Vector2` if none was provided. */ - getPoint: function (t, out) + getPoint(t, out) { if (out === undefined) { out = new Vector2(); } @@ -605,7 +603,7 @@ var Path = new Class({ // loop where sum != 0, sum > d , sum+1 } All data values. */ - getAll: function () + getAll() { var results = {}; @@ -185,7 +183,7 @@ var DataManager = new Class({ } return results; - }, + } /** * Queries the DataManager for the values of keys matching the given regular expression. @@ -197,7 +195,7 @@ var DataManager = new Class({ * * @return {Object.} The values of the keys matching the search string. */ - query: function (search) + query(search) { var results = {}; @@ -210,7 +208,7 @@ var DataManager = new Class({ } return results; - }, + } /** * Sets a value for the given key. If the key doesn't already exist in the Data Manager then it is created. @@ -260,7 +258,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - set: function (key, data) + set(key, data) { if (this._frozen) { @@ -280,7 +278,7 @@ var DataManager = new Class({ } return this; - }, + } /** * Increase a value for the given key. If the key doesn't already exist in the Data Manager then it is increased from 0. @@ -298,7 +296,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - inc: function (key, amount) + inc(key, amount) { if (this._frozen) { @@ -320,7 +318,7 @@ var DataManager = new Class({ this.set(key, (value + amount)); return this; - }, + } /** * Toggle a boolean value for the given key. If the key doesn't already exist in the Data Manager then it is toggled from false. @@ -337,7 +335,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - toggle: function (key) + toggle(key) { if (this._frozen) { @@ -347,7 +345,7 @@ var DataManager = new Class({ this.set(key, !this.get(key)); return this; - }, + } /** * Internal value setter, called automatically by the `set` method. @@ -364,7 +362,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - setValue: function (key, data) + setValue(key, data) { if (this._frozen) { @@ -414,7 +412,7 @@ var DataManager = new Class({ } return this; - }, + } /** * Passes all data entries to the given callback. @@ -428,7 +426,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - each: function (callback, context) + each(callback, context) { var args = [ this.parent, null, undefined ]; @@ -446,7 +444,7 @@ var DataManager = new Class({ } return this; - }, + } /** * Merge the given object of key value pairs into this DataManager. @@ -465,7 +463,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - merge: function (data, overwrite) + merge(data, overwrite) { if (overwrite === undefined) { overwrite = true; } @@ -479,7 +477,7 @@ var DataManager = new Class({ } return this; - }, + } /** * Remove the value for the given key. @@ -501,7 +499,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - remove: function (key) + remove(key) { if (this._frozen) { @@ -521,7 +519,7 @@ var DataManager = new Class({ } return this; - }, + } /** * Internal value remover, called automatically by the `remove` method. @@ -535,7 +533,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - removeValue: function (key) + removeValue(key) { if (this.has(key)) { @@ -548,7 +546,7 @@ var DataManager = new Class({ } return this; - }, + } /** * Retrieves the data associated with the given 'key', deletes it from this Data Manager, then returns it. @@ -561,7 +559,7 @@ var DataManager = new Class({ * * @return {*} The value of the given key. */ - pop: function (key) + pop(key) { var data = undefined; @@ -576,7 +574,7 @@ var DataManager = new Class({ } return data; - }, + } /** * Determines whether the given key is set in this Data Manager. @@ -591,10 +589,10 @@ var DataManager = new Class({ * * @return {boolean} Returns `true` if the key exists, otherwise `false`. */ - has: function (key) + has(key) { return this.list.hasOwnProperty(key); - }, + } /** * Freeze or unfreeze this Data Manager. A frozen Data Manager will block all attempts @@ -607,12 +605,12 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - setFreeze: function (value) + setFreeze(value) { this._frozen = value; return this; - }, + } /** * Delete all data in this Data Manager and unfreeze it. @@ -622,7 +620,7 @@ var DataManager = new Class({ * * @return {this} This Data Manager instance. */ - reset: function () + reset() { for (var key in this.list) { @@ -633,7 +631,7 @@ var DataManager = new Class({ this._frozen = false; return this; - }, + } /** * Destroy this data manager. @@ -641,7 +639,7 @@ var DataManager = new Class({ * @method Phaser.Data.DataManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.reset(); @@ -650,7 +648,7 @@ var DataManager = new Class({ this.events.off(Events.REMOVE_DATA); this.parent = null; - }, + } /** * Gets or sets the frozen state of this Data Manager. @@ -660,19 +658,16 @@ var DataManager = new Class({ * @type {boolean} * @since 3.0.0 */ - freeze: { - - get: function () - { - return this._frozen; - }, - set: function (value) - { - this._frozen = (value) ? true : false; - } + get freeze() + { + return this._frozen; + } - }, + set freeze(value) + { + this._frozen = (value) ? true : false; + } /** * Return the total number of entries in this Data Manager. @@ -681,25 +676,22 @@ var DataManager = new Class({ * @type {number} * @since 3.0.0 */ - count: { - get: function () - { - var i = 0; + get count() + { + var i = 0; - for (var key in this.list) + for (var key in this.list) + { + if (this.list[key] !== undefined) { - if (this.list[key] !== undefined) - { - i++; - } + i++; } - - return i; } + return i; } -}); +}; module.exports = DataManager; diff --git a/src/data/DataManagerPlugin.js b/src/data/DataManagerPlugin.js index d0dac9fe8f..d7055ef464 100644 --- a/src/data/DataManagerPlugin.js +++ b/src/data/DataManagerPlugin.js @@ -23,15 +23,11 @@ var SceneEvents = require('../scene/events'); * * @param {Phaser.Scene} scene - A reference to the Scene that this DataManager belongs to. */ -var DataManagerPlugin = new Class({ +var DataManagerPlugin = class extends DataManager { - Extends: DataManager, - - initialize: - - function DataManagerPlugin (scene) + constructor(scene) { - DataManager.call(this, scene, scene.sys.events); + super(scene, scene.sys.events); /** * A reference to the Scene that this DataManager belongs to. @@ -53,7 +49,7 @@ var DataManagerPlugin = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -63,12 +59,12 @@ var DataManagerPlugin = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.events = this.systems.events; this.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -79,10 +75,10 @@ var DataManagerPlugin = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { this.events.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is shutting down. @@ -92,10 +88,10 @@ var DataManagerPlugin = new Class({ * @private * @since 3.5.0 */ - shutdown: function () + shutdown() { this.systems.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -104,7 +100,7 @@ var DataManagerPlugin = new Class({ * @method Phaser.Data.DataManagerPlugin#destroy * @since 3.5.0 */ - destroy: function () + destroy() { DataManager.prototype.destroy.call(this); @@ -114,7 +110,7 @@ var DataManagerPlugin = new Class({ this.systems = null; } -}); +}; PluginCache.register('DataManagerPlugin', DataManagerPlugin, 'data'); diff --git a/src/display/ColorMatrix.js b/src/display/ColorMatrix.js index bccfa1c81c..594d5204a6 100644 --- a/src/display/ColorMatrix.js +++ b/src/display/ColorMatrix.js @@ -21,11 +21,9 @@ var tempMatrix = new Float32Array(20); * @constructor * @since 3.50.0 */ -var ColorMatrix = new Class({ +var ColorMatrix = class { - initialize: - - function ColorMatrix () + constructor() { /** * Internal ColorMatrix array. @@ -70,7 +68,7 @@ var ColorMatrix = new Class({ this._data = new Float32Array(20); this.reset(); - }, + } /** * Sets this ColorMatrix from the given array of color values. @@ -82,14 +80,14 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - set: function (value) + set(value) { this._matrix.set(value); this._dirty = true; return this; - }, + } /** * Resets the ColorMatrix to default values and also resets @@ -100,7 +98,7 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - reset: function () + reset() { var m = this._matrix; @@ -116,7 +114,7 @@ var ColorMatrix = new Class({ this._dirty = true; return this; - }, + } /** * Gets the ColorMatrix as a Float32Array. @@ -128,7 +126,7 @@ var ColorMatrix = new Class({ * * @return {Float32Array} The ColorMatrix as a Float32Array. */ - getData: function () + getData() { var data = this._data; @@ -145,7 +143,7 @@ var ColorMatrix = new Class({ } return data; - }, + } /** * Changes the brightness of this ColorMatrix by the given amount. @@ -158,7 +156,7 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - brightness: function (value, multiply) + brightness(value, multiply) { if (value === undefined) { value = 0; } if (multiply === undefined) { multiply = false; } @@ -171,7 +169,7 @@ var ColorMatrix = new Class({ 0, 0, b, 0, 0, 0, 0, 0, 1, 0 ], multiply); - }, + } /** * Changes the saturation of this ColorMatrix by the given amount. @@ -184,7 +182,7 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - saturate: function (value, multiply) + saturate(value, multiply) { if (value === undefined) { value = 0; } if (multiply === undefined) { multiply = false; } @@ -198,7 +196,7 @@ var ColorMatrix = new Class({ y, y, x, 0, 0, 0, 0, 0, 1, 0 ], multiply); - }, + } /** * Desaturates this ColorMatrix (removes color from it). @@ -210,12 +208,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - desaturate: function (multiply) + desaturate(multiply) { if (multiply === undefined) { multiply = false; } return this.saturate(-1, multiply); - }, + } /** * Rotates the hues of this ColorMatrix by the value given. @@ -228,7 +226,7 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - hue: function (rotation, multiply) + hue(rotation, multiply) { if (rotation === undefined) { rotation = 0; } if (multiply === undefined) { multiply = false; } @@ -247,7 +245,7 @@ var ColorMatrix = new Class({ lumR + cos * (-lumR) + sin * (-(1 - lumR)),lumG + cos * (-lumG) + sin * (lumG),lumB + cos * (1 - lumB) + sin * (lumB), 0, 0, 0, 0, 0, 1, 0 ], multiply); - }, + } /** * Sets this ColorMatrix to be grayscale. @@ -260,13 +258,13 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - grayscale: function (value, multiply) + grayscale(value, multiply) { if (value === undefined) { value = 1; } if (multiply === undefined) { multiply = false; } return this.saturate(-value, multiply); - }, + } /** * Sets this ColorMatrix to be black and white. @@ -278,12 +276,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - blackWhite: function (multiply) + blackWhite(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.BLACK_WHITE, multiply); - }, + } /** * Change the contrast of this ColorMatrix by the amount given. @@ -296,7 +294,7 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - contrast: function (value, multiply) + contrast(value, multiply) { if (value === undefined) { value = 0; } if (multiply === undefined) { multiply = false; } @@ -310,7 +308,7 @@ var ColorMatrix = new Class({ 0, 0, v, 0, o, 0, 0, 0, 1, 0 ], multiply); - }, + } /** * Converts this ColorMatrix to have negative values. @@ -322,12 +320,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - negative: function (multiply) + negative(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.NEGATIVE, multiply); - }, + } /** * Apply a desaturated luminance to this ColorMatrix. @@ -339,12 +337,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - desaturateLuminance: function (multiply) + desaturateLuminance(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.DESATURATE_LUMINANCE, multiply); - }, + } /** * Applies a sepia tone to this ColorMatrix. @@ -356,12 +354,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - sepia: function (multiply) + sepia(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.SEPIA, multiply); - }, + } /** * Applies a night vision tone to this ColorMatrix. @@ -374,7 +372,7 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - night: function (intensity, multiply) + night(intensity, multiply) { if (intensity === undefined) { intensity = 0.1; } if (multiply === undefined) { multiply = false; } @@ -385,7 +383,7 @@ var ColorMatrix = new Class({ 0, intensity, intensity * 2.0, 0, 0, 0, 0, 0, 1, 0 ], multiply); - }, + } /** * Applies a trippy color tone to this ColorMatrix. @@ -397,12 +395,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - lsd: function (multiply) + lsd(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.LSD, multiply); - }, + } /** * Applies a brown tone to this ColorMatrix. @@ -414,12 +412,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - brown: function (multiply) + brown(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.BROWN, multiply); - }, + } /** * Applies a vintage pinhole color effect to this ColorMatrix. @@ -431,12 +429,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - vintagePinhole: function (multiply) + vintagePinhole(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.VINTAGE, multiply); - }, + } /** * Applies a kodachrome color effect to this ColorMatrix. @@ -448,12 +446,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - kodachrome: function (multiply) + kodachrome(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.KODACHROME, multiply); - }, + } /** * Applies a technicolor color effect to this ColorMatrix. @@ -465,12 +463,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - technicolor: function (multiply) + technicolor(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.TECHNICOLOR, multiply); - }, + } /** * Applies a polaroid color effect to this ColorMatrix. @@ -482,12 +480,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - polaroid: function (multiply) + polaroid(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.POLAROID, multiply); - }, + } /** * Shifts the values of this ColorMatrix into BGR order. @@ -499,12 +497,12 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - shiftToBGR: function (multiply) + shiftToBGR(multiply) { if (multiply === undefined) { multiply = false; } return this.multiply(ColorMatrix.SHIFT_BGR, multiply); - }, + } /** * Multiplies the two given matrices. @@ -517,7 +515,7 @@ var ColorMatrix = new Class({ * * @return {this} This ColorMatrix instance. */ - multiply: function (a, multiply) + multiply(a, multiply) { if (multiply === undefined) { multiply = false; } @@ -570,7 +568,7 @@ var ColorMatrix = new Class({ return this; } -}); +}; /** * A constant array used by the ColorMatrix class for black_white operations. diff --git a/src/display/RGB.js b/src/display/RGB.js index 2fc3b1b876..706b35b2b5 100644 --- a/src/display/RGB.js +++ b/src/display/RGB.js @@ -21,11 +21,9 @@ var NOOP = require('../utils/NOOP'); * @param {number} [green=0] - The green color value. A number between 0 and 1. * @param {number} [blue=0] - The blue color value. A number between 0 and 1. */ -var RGB = new Class({ +var RGB = class { - initialize: - - function RGB (red, green, blue) + constructor(red, green, blue) { /** * Cached RGB values. @@ -58,7 +56,7 @@ var RGB = new Class({ this.dirty = false; this.set(red, green, blue); - }, + } /** * Sets the red, green and blue values of this RGB object, flags it as being @@ -73,7 +71,7 @@ var RGB = new Class({ * * @return {this} This RGB instance. */ - set: function (red, green, blue) + set(red, green, blue) { if (red === undefined) { red = 0; } if (green === undefined) { green = 0; } @@ -84,7 +82,7 @@ var RGB = new Class({ this.onChange(); return this; - }, + } /** * Compares the given rgb parameters with those in this object and returns @@ -99,12 +97,12 @@ var RGB = new Class({ * * @return {boolean} `true` if the given values match those in this object, otherwise `false`. */ - equals: function (red, green, blue) + equals(red, green, blue) { var rgb = this._rgb; return (rgb[0] === red && rgb[1] === green && rgb[2] === blue); - }, + } /** * Internal on change handler. Sets this object as being dirty and @@ -114,14 +112,14 @@ var RGB = new Class({ * @method Phaser.Display.RGB#onChange * @since 3.50.0 */ - onChange: function () + onChange() { this.dirty = true; var rgb = this._rgb; this.onChangeCallback.call(this, rgb[0], rgb[1], rgb[2]); - }, + } /** * The red color value. Between 0 and 1. @@ -133,20 +131,17 @@ var RGB = new Class({ * @type {number} * @since 3.50.0 */ - r: { - - get: function () - { - return this._rgb[0]; - }, - set: function (value) - { - this._rgb[0] = value; - this.onChange(); - } + get r() + { + return this._rgb[0]; + } - }, + set r(value) + { + this._rgb[0] = value; + this.onChange(); + } /** * The green color value. Between 0 and 1. @@ -158,20 +153,17 @@ var RGB = new Class({ * @type {number} * @since 3.50.0 */ - g: { - - get: function () - { - return this._rgb[1]; - }, - set: function (value) - { - this._rgb[1] = value; - this.onChange(); - } + get g() + { + return this._rgb[1]; + } - }, + set g(value) + { + this._rgb[1] = value; + this.onChange(); + } /** * The blue color value. Between 0 and 1. @@ -183,20 +175,17 @@ var RGB = new Class({ * @type {number} * @since 3.50.0 */ - b: { - - get: function () - { - return this._rgb[2]; - }, - set: function (value) - { - this._rgb[2] = value; - this.onChange(); - } + get b() + { + return this._rgb[2]; + } - }, + set b(value) + { + this._rgb[2] = value; + this.onChange(); + } /** * Nulls any external references this object contains. @@ -204,11 +193,11 @@ var RGB = new Class({ * @method Phaser.Display.RGB#destroy * @since 3.50.0 */ - destroy: function () + destroy() { this.onChangeCallback = null; } -}); +}; module.exports = RGB; diff --git a/src/display/color/Color.js b/src/display/color/Color.js index 9542476dcd..2f7bb48509 100644 --- a/src/display/color/Color.js +++ b/src/display/color/Color.js @@ -28,11 +28,9 @@ var RGBToHSV = require('./RGBToHSV'); * @param {number} [blue=0] - The blue color value. A number between 0 and 255. * @param {number} [alpha=255] - The alpha value. A number between 0 and 255. */ -var Color = new Class({ +var Color = class { - initialize: - - function Color (red, green, blue, alpha) + constructor(red, green, blue, alpha) { if (red === undefined) { red = 0; } if (green === undefined) { green = 0; } @@ -172,7 +170,7 @@ var Color = new Class({ this._rgba = ''; this.setTo(red, green, blue, alpha); - }, + } /** * Sets this color to be transparent. Sets all values to zero. @@ -182,7 +180,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - transparent: function () + transparent() { this._locked = true; @@ -194,7 +192,7 @@ var Color = new Class({ this._locked = false; return this.update(true); - }, + } /** * Sets the color of this Color component. @@ -210,7 +208,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - setTo: function (red, green, blue, alpha, updateHSV) + setTo(red, green, blue, alpha, updateHSV) { if (alpha === undefined) { alpha = 255; } if (updateHSV === undefined) { updateHSV = true; } @@ -225,7 +223,7 @@ var Color = new Class({ this._locked = false; return this.update(updateHSV); - }, + } /** * Sets the red, green, blue and alpha GL values of this Color component. @@ -240,7 +238,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - setGLTo: function (red, green, blue, alpha) + setGLTo(red, green, blue, alpha) { if (alpha === undefined) { alpha = 1; } @@ -254,7 +252,7 @@ var Color = new Class({ this._locked = false; return this.update(true); - }, + } /** * Sets the color based on the color object given. @@ -266,7 +264,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - setFromRGB: function (color) + setFromRGB(color) { this._locked = true; @@ -282,7 +280,7 @@ var Color = new Class({ this._locked = false; return this.update(true); - }, + } /** * Sets the color based on the hue, saturation and lightness values given. @@ -296,10 +294,10 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - setFromHSV: function (h, s, v) + setFromHSV(h, s, v) { return HSVToRGB(h, s, v, this); - }, + } /** * Updates the internal cache values. @@ -310,7 +308,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - update: function (updateHSV) + update(updateHSV) { if (updateHSV === undefined) { updateHSV = false; } @@ -334,7 +332,7 @@ var Color = new Class({ } return this; - }, + } /** * Updates the internal hsv cache values. @@ -345,7 +343,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - updateHSV: function () + updateHSV() { var r = this.r; var g = this.g; @@ -354,7 +352,7 @@ var Color = new Class({ RGBToHSV(r, g, b, this); return this; - }, + } /** * Returns a new Color component using the values from this one. @@ -364,10 +362,10 @@ var Color = new Class({ * * @return {Phaser.Display.Color} A new Color object. */ - clone: function () + clone() { return new Color(this.r, this.g, this.b, this.a); - }, + } /** * Sets this Color object to be grayscaled based on the shade value given. @@ -379,10 +377,10 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - gray: function (shade) + gray(shade) { return this.setTo(shade, shade, shade); - }, + } /** * Sets this Color object to be a random color between the `min` and `max` values given. @@ -395,7 +393,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - random: function (min, max) + random(min, max) { if (min === undefined) { min = 0; } if (max === undefined) { max = 255; } @@ -405,7 +403,7 @@ var Color = new Class({ var b = Math.floor(min + Math.random() * (max - min)); return this.setTo(r, g, b); - }, + } /** * Sets this Color object to be a random grayscale color between the `min` and `max` values given. @@ -418,7 +416,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - randomGray: function (min, max) + randomGray(min, max) { if (min === undefined) { min = 0; } if (max === undefined) { max = 255; } @@ -426,7 +424,7 @@ var Color = new Class({ var s = Math.floor(min + Math.random() * (max - min)); return this.setTo(s, s, s); - }, + } /** * Increase the saturation of this Color by the percentage amount given. @@ -439,12 +437,12 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - saturate: function (amount) + saturate(amount) { this.s += amount / 100; return this; - }, + } /** * Decrease the saturation of this Color by the percentage amount given. @@ -457,12 +455,12 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - desaturate: function (amount) + desaturate(amount) { this.s -= amount / 100; return this; - }, + } /** * Increase the lightness of this Color by the percentage amount given. @@ -474,12 +472,12 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - lighten: function (amount) + lighten(amount) { this.v += amount / 100; return this; - }, + } /** * Decrease the lightness of this Color by the percentage amount given. @@ -491,12 +489,12 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - darken: function (amount) + darken(amount) { this.v -= amount / 100; return this; - }, + } /** * Brighten this Color by the percentage amount given. @@ -508,7 +506,7 @@ var Color = new Class({ * * @return {Phaser.Display.Color} This Color object. */ - brighten: function (amount) + brighten(amount) { var r = this.r; var g = this.g; @@ -519,7 +517,7 @@ var Color = new Class({ b = Math.max(0, Math.min(255, b - Math.round(255 * - (amount / 100)))); return this.setTo(r, g, b); - }, + } /** * The color of this Color component, not including the alpha channel. @@ -529,14 +527,11 @@ var Color = new Class({ * @readonly * @since 3.0.0 */ - color: { - - get: function () - { - return this._color; - } - }, + get color() + { + return this._color; + } /** * The color of this Color component, including the alpha channel. @@ -546,14 +541,11 @@ var Color = new Class({ * @readonly * @since 3.0.0 */ - color32: { - get: function () - { - return this._color32; - } - - }, + get color32() + { + return this._color32; + } /** * The color of this Color component as a string which can be used in CSS color values. @@ -563,14 +555,11 @@ var Color = new Class({ * @readonly * @since 3.0.0 */ - rgba: { - - get: function () - { - return this._rgba; - } - }, + get rgba() + { + return this._rgba; + } /** * The red color value, normalized to the range 0 to 1. @@ -579,23 +568,20 @@ var Color = new Class({ * @type {number} * @since 3.0.0 */ - redGL: { - - get: function () - { - return this.gl[0]; - }, - set: function (value) - { - this.gl[0] = Math.min(Math.abs(value), 1); + get redGL() + { + return this.gl[0]; + } - this.r = Math.floor(this.gl[0] * 255); + set redGL(value) + { + this.gl[0] = Math.min(Math.abs(value), 1); - this.update(true); - } + this.r = Math.floor(this.gl[0] * 255); - }, + this.update(true); + } /** * The green color value, normalized to the range 0 to 1. @@ -604,23 +590,20 @@ var Color = new Class({ * @type {number} * @since 3.0.0 */ - greenGL: { - get: function () - { - return this.gl[1]; - }, - - set: function (value) - { - this.gl[1] = Math.min(Math.abs(value), 1); + get greenGL() + { + return this.gl[1]; + } - this.g = Math.floor(this.gl[1] * 255); + set greenGL(value) + { + this.gl[1] = Math.min(Math.abs(value), 1); - this.update(true); - } + this.g = Math.floor(this.gl[1] * 255); - }, + this.update(true); + } /** * The blue color value, normalized to the range 0 to 1. @@ -629,23 +612,20 @@ var Color = new Class({ * @type {number} * @since 3.0.0 */ - blueGL: { - get: function () - { - return this.gl[2]; - }, - - set: function (value) - { - this.gl[2] = Math.min(Math.abs(value), 1); + get blueGL() + { + return this.gl[2]; + } - this.b = Math.floor(this.gl[2] * 255); + set blueGL(value) + { + this.gl[2] = Math.min(Math.abs(value), 1); - this.update(true); - } + this.b = Math.floor(this.gl[2] * 255); - }, + this.update(true); + } /** * The alpha color value, normalized to the range 0 to 1. @@ -654,23 +634,20 @@ var Color = new Class({ * @type {number} * @since 3.0.0 */ - alphaGL: { - get: function () - { - return this.gl[3]; - }, - - set: function (value) - { - this.gl[3] = Math.min(Math.abs(value), 1); + get alphaGL() + { + return this.gl[3]; + } - this.a = Math.floor(this.gl[3] * 255); + set alphaGL(value) + { + this.gl[3] = Math.min(Math.abs(value), 1); - this.update(); - } + this.a = Math.floor(this.gl[3] * 255); - }, + this.update(); + } /** * The red color value, normalized to the range 0 to 255. @@ -679,25 +656,22 @@ var Color = new Class({ * @type {number} * @since 3.0.0 */ - red: { - - get: function () - { - return this.r; - }, - set: function (value) - { - value = Math.floor(Math.abs(value)); + get red() + { + return this.r; + } - this.r = Math.min(value, 255); + set red(value) + { + value = Math.floor(Math.abs(value)); - this.gl[0] = value / 255; + this.r = Math.min(value, 255); - this.update(true); - } + this.gl[0] = value / 255; - }, + this.update(true); + } /** * The green color value, normalized to the range 0 to 255. @@ -706,25 +680,22 @@ var Color = new Class({ * @type {number} * @since 3.0.0 */ - green: { - - get: function () - { - return this.g; - }, - set: function (value) - { - value = Math.floor(Math.abs(value)); + get green() + { + return this.g; + } - this.g = Math.min(value, 255); + set green(value) + { + value = Math.floor(Math.abs(value)); - this.gl[1] = value / 255; + this.g = Math.min(value, 255); - this.update(true); - } + this.gl[1] = value / 255; - }, + this.update(true); + } /** * The blue color value, normalized to the range 0 to 255. @@ -733,25 +704,22 @@ var Color = new Class({ * @type {number} * @since 3.0.0 */ - blue: { - - get: function () - { - return this.b; - }, - set: function (value) - { - value = Math.floor(Math.abs(value)); + get blue() + { + return this.b; + } - this.b = Math.min(value, 255); + set blue(value) + { + value = Math.floor(Math.abs(value)); - this.gl[2] = value / 255; + this.b = Math.min(value, 255); - this.update(true); - } + this.gl[2] = value / 255; - }, + this.update(true); + } /** * The alpha color value, normalized to the range 0 to 255. @@ -760,25 +728,22 @@ var Color = new Class({ * @type {number} * @since 3.0.0 */ - alpha: { - - get: function () - { - return this.a; - }, - set: function (value) - { - value = Math.floor(Math.abs(value)); + get alpha() + { + return this.a; + } - this.a = Math.min(value, 255); + set alpha(value) + { + value = Math.floor(Math.abs(value)); - this.gl[3] = value / 255; + this.a = Math.min(value, 255); - this.update(); - } + this.gl[3] = value / 255; - }, + this.update(); + } /** * The hue color value. A number between 0 and 1. @@ -788,21 +753,18 @@ var Color = new Class({ * @type {number} * @since 3.13.0 */ - h: { - get: function () - { - return this._h; - }, - - set: function (value) - { - this._h = value; + get h() + { + return this._h; + } - HSVToRGB(value, this._s, this._v, this); - } + set h(value) + { + this._h = value; - }, + HSVToRGB(value, this._s, this._v, this); + } /** * The saturation color value. A number between 0 and 1. @@ -812,21 +774,18 @@ var Color = new Class({ * @type {number} * @since 3.13.0 */ - s: { - get: function () - { - return this._s; - }, - - set: function (value) - { - this._s = value; + get s() + { + return this._s; + } - HSVToRGB(this._h, value, this._v, this); - } + set s(value) + { + this._s = value; - }, + HSVToRGB(this._h, value, this._v, this); + } /** * The lightness color value. A number between 0 and 1. @@ -836,22 +795,19 @@ var Color = new Class({ * @type {number} * @since 3.13.0 */ - v: { - get: function () - { - return this._v; - }, - - set: function (value) - { - this._v = value; + get v() + { + return this._v; + } - HSVToRGB(this._h, this._s, value, this); - } + set v(value) + { + this._v = value; + HSVToRGB(this._h, this._s, value, this); } -}); +}; module.exports = Color; diff --git a/src/display/mask/GeometryMask.js b/src/display/mask/GeometryMask.js index 7a6afc2222..1ebb2bcdfd 100644 --- a/src/display/mask/GeometryMask.js +++ b/src/display/mask/GeometryMask.js @@ -36,11 +36,9 @@ var Class = require('../../utils/Class'); * @param {Phaser.Scene} scene - This parameter is not used. * @param {Phaser.GameObjects.Graphics} graphicsGeometry - The Graphics Game Object to use for the Geometry Mask. Doesn't have to be in the Display List. */ -var GeometryMask = new Class({ +var GeometryMask = class { - initialize: - - function GeometryMask (scene, graphicsGeometry) + constructor(scene, graphicsGeometry) { /** * The Graphics object which describes the Geometry Mask. @@ -50,7 +48,7 @@ var GeometryMask = new Class({ * @since 3.0.0 */ this.geometryMask = graphicsGeometry; - }, + } /** * Sets a new Graphics object for the Geometry Mask. @@ -62,12 +60,12 @@ var GeometryMask = new Class({ * * @return {this} This Geometry Mask */ - setShape: function (graphicsGeometry) + setShape(graphicsGeometry) { this.geometryMask = graphicsGeometry; return this; - }, + } /** * Sets the clipping path of a 2D canvas context to the Geometry Mask's underlying Graphics object. @@ -79,7 +77,7 @@ var GeometryMask = new Class({ * @param {Phaser.GameObjects.GameObject} mask - The Game Object being rendered. * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera the Game Object is being rendered through. */ - preRenderCanvas: function (renderer, mask, camera) + preRenderCanvas(renderer, mask, camera) { var geometryMask = this.geometryMask; @@ -88,7 +86,7 @@ var GeometryMask = new Class({ geometryMask.renderCanvas(renderer, geometryMask, camera, null, null, true); renderer.currentContext.clip(); - }, + } /** * Restore the canvas context's previous clipping path, thus turning off the mask for it. @@ -98,10 +96,10 @@ var GeometryMask = new Class({ * * @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - The Canvas Renderer instance being restored. */ - postRenderCanvas: function (renderer) + postRenderCanvas(renderer) { renderer.currentContext.restore(); - }, + } /** * Destroys this GeometryMask and nulls any references it holds. @@ -112,11 +110,11 @@ var GeometryMask = new Class({ * @method Phaser.Display.Masks.GeometryMask#destroy * @since 3.7.0 */ - destroy: function () + destroy() { this.geometryMask = null; } -}); +}; module.exports = GeometryMask; diff --git a/src/display/shader/BaseShader.js b/src/display/shader/BaseShader.js index a85c778c54..277a750212 100644 --- a/src/display/shader/BaseShader.js +++ b/src/display/shader/BaseShader.js @@ -33,8 +33,8 @@ var Class = require('../../utils/Class'); * @param {string} glsl - The GLSL source code for the shader. * @param {object} [metadata] - Additional metadata for this shader code. */ -var BaseShader = new Class({ - initialize: function BaseShader (key, glsl, metadata) +var BaseShader = class { + constructor(key, glsl, metadata) { if (metadata === undefined) { metadata = {}; } @@ -71,6 +71,6 @@ var BaseShader = new Class({ */ this.metadata = metadata; } -}); +}; module.exports = BaseShader; diff --git a/src/dom/RequestAnimationFrame.js b/src/dom/RequestAnimationFrame.js index c4ccb9f6c2..7bbcf0a56e 100644 --- a/src/dom/RequestAnimationFrame.js +++ b/src/dom/RequestAnimationFrame.js @@ -18,11 +18,9 @@ var NOOP = require('../utils/NOOP'); * @constructor * @since 3.0.0 */ -var RequestAnimationFrame = new Class({ +var RequestAnimationFrame = class { - initialize: - - function RequestAnimationFrame () + constructor() { /** * True if RequestAnimationFrame is running, otherwise false. @@ -115,7 +113,7 @@ var RequestAnimationFrame = new Class({ _this.callback(window.performance.now()); }; - }, + } /** * Starts the requestAnimationFrame or setTimeout process running. @@ -127,7 +125,7 @@ var RequestAnimationFrame = new Class({ * @param {boolean} forceSetTimeOut - Should it use SetTimeout, even if RAF is available? * @param {number} delay - The setTimeout delay rate in ms. */ - start: function (callback, forceSetTimeOut, delay) + start(callback, forceSetTimeOut, delay) { if (this.isRunning) { @@ -143,7 +141,7 @@ var RequestAnimationFrame = new Class({ this.isRunning = true; this.timeOutID = (forceSetTimeOut) ? window.setTimeout(this.stepTimeout, 0) : window.requestAnimationFrame(this.step); - }, + } /** * Stops the requestAnimationFrame or setTimeout from running. @@ -151,7 +149,7 @@ var RequestAnimationFrame = new Class({ * @method Phaser.DOM.RequestAnimationFrame#stop * @since 3.0.0 */ - stop: function () + stop() { this.isRunning = false; @@ -163,7 +161,7 @@ var RequestAnimationFrame = new Class({ { window.cancelAnimationFrame(this.timeOutID); } - }, + } /** * Stops the step from running and clears the callback reference. @@ -171,13 +169,13 @@ var RequestAnimationFrame = new Class({ * @method Phaser.DOM.RequestAnimationFrame#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.stop(); this.callback = NOOP; } -}); +}; module.exports = RequestAnimationFrame; diff --git a/src/events/EventEmitter.js b/src/events/EventEmitter.js index 16e7e81c5f..4cac931a9b 100644 --- a/src/events/EventEmitter.js +++ b/src/events/EventEmitter.js @@ -17,16 +17,12 @@ var PluginCache = require('../plugins/PluginCache'); * @constructor * @since 3.0.0 */ -var EventEmitter = new Class({ +var EventEmitter = class extends EE { - Extends: EE, - - initialize: - - function EventEmitter () + constructor() { - EE.call(this); - }, + super(); + } /** * Removes all listeners. @@ -34,10 +30,10 @@ var EventEmitter = new Class({ * @method Phaser.Events.EventEmitter#shutdown * @since 3.0.0 */ - shutdown: function () + shutdown() { this.removeAllListeners(); - }, + } /** * Removes all listeners. @@ -45,12 +41,12 @@ var EventEmitter = new Class({ * @method Phaser.Events.EventEmitter#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.removeAllListeners(); } -}); +}; /** * Return an array listing the events for which the emitter has registered listeners. diff --git a/src/filters/Barrel.js b/src/filters/Barrel.js index db667ffbf6..ebd9134388 100644 --- a/src/filters/Barrel.js +++ b/src/filters/Barrel.js @@ -32,14 +32,13 @@ var Controller = require('./Controller'); * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that owns this filter. * @param {number} [amount=1] - The amount of distortion applied to the barrel effect. A value of 1 is no distortion. Typically keep this within +- 1. */ -var Barrel = new Class({ - Extends: Controller, +var Barrel = class extends Controller { - initialize: function Barrel (camera, amount) + constructor(camera, amount) { if (amount === undefined) { amount = 1; } - Controller.call(this, camera, 'FilterBarrel'); + super(camera, 'FilterBarrel'); /** * The amount of distortion applied to the barrel effect. @@ -52,6 +51,6 @@ var Barrel = new Class({ */ this.amount = amount; } -}); +}; module.exports = Barrel; diff --git a/src/filters/Blend.js b/src/filters/Blend.js index c162f85121..383d057d89 100644 --- a/src/filters/Blend.js +++ b/src/filters/Blend.js @@ -35,17 +35,16 @@ var Controller = require('./Controller'); * @param {number} [amount=1] - The amount of the blend effect to apply to the view. At 0, the original image is preserved. At 1, the blend texture is fully applied. The expected range is 0 to 1, but you can go outside that range for different effects. * @param {number[]} [color=[1, 1, 1, 1]] - The color to apply to the blend texture. Each value corresponds to a color channel in RGBA. The expected range is 0 to 1, but you can go outside that range for different effects. */ -var Blend = new Class({ - Extends: Controller, +var Blend = class extends Controller { - initialize: function Blend (camera, texture, blendMode, amount, color) + constructor(camera, texture, blendMode, amount, color) { if (texture === undefined) { texture = '__WHITE'; } if (blendMode === undefined) { blendMode = 0; } if (amount === undefined) { amount = 1; } if (color === undefined) { color = [ 1, 1, 1, 1 ]; } - Controller.call(this, camera, 'FilterBlend'); + super(camera, 'FilterBlend'); /** * The underlying texture used for the mask. @@ -91,7 +90,7 @@ var Blend = new Class({ this.color = color; this.setTexture(texture); - }, + } /** * Sets the texture used for the blend. @@ -101,7 +100,7 @@ var Blend = new Class({ * @param {string} [texture='__WHITE'] - The unique string-based key of the texture to use for displacement, which must exist in the Texture Manager. * @returns {this} This Filter Controller. */ - setTexture: function (texture) + setTexture(texture) { var phaserTexture = this.camera.scene.sys.textures.getFrame(texture); @@ -112,6 +111,6 @@ var Blend = new Class({ return this; } -}); +}; module.exports = Blend; diff --git a/src/filters/Blur.js b/src/filters/Blur.js index 9ccdcaebee..a7f5b4a106 100644 --- a/src/filters/Blur.js +++ b/src/filters/Blur.js @@ -40,10 +40,9 @@ var Controller = require('./Controller'); * @param {number} [color=0xffffff] - The color of the blur, as a hex value. * @param {number} [steps=4] - The number of steps to run the blur effect for. This value should always be an integer. */ -var Blur = new Class({ - Extends: Controller, +var Blur = class extends Controller { - initialize: function Blur (camera, quality, x, y, strength, color, steps) + constructor(camera, quality, x, y, strength, color, steps) { if (quality === undefined) { quality = 0; } if (x === undefined) { x = 2; } @@ -51,7 +50,7 @@ var Blur = new Class({ if (strength === undefined) { strength = 1; } if (steps === undefined) { steps = 4; } - Controller.call(this, camera, 'FilterBlur'); + super(camera, 'FilterBlur'); /** * The quality of the blur effect. @@ -138,7 +137,7 @@ var Blur = new Class({ * @since 4.0.0 */ this.steps = steps; - }, + } /** * The color of the blur as a number value. @@ -147,27 +146,24 @@ var Blur = new Class({ * @type {number} * @since 4.0.0 */ - color: { - - get: function () - { - var color = this.glcolor; - return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0)); - }, + get color() + { + var color = this.glcolor; - set: function (value) - { - var color = this.glcolor; + return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0)); + } - color[0] = ((value >> 16) & 0xFF) / 255; - color[1] = ((value >> 8) & 0xFF) / 255; - color[2] = (value & 0xFF) / 255; - } + set color(value) + { + var color = this.glcolor; - }, + color[0] = ((value >> 16) & 0xFF) / 255; + color[1] = ((value >> 8) & 0xFF) / 255; + color[2] = (value & 0xFF) / 255; + } - getPadding: function () + getPadding() { var override = this.paddingOverride; if (override) @@ -188,6 +184,6 @@ var Blur = new Class({ return this.currentPadding; } -}); +}; module.exports = Blur; diff --git a/src/filters/Bokeh.js b/src/filters/Bokeh.js index d0e2c24e7c..25dad24d43 100644 --- a/src/filters/Bokeh.js +++ b/src/filters/Bokeh.js @@ -45,11 +45,9 @@ var Controller = require('./Controller'); * @param {number} [blurY=1] - If Tilt Shift, the amount of vertical blur. * @param {number} [strength=1] - If Tilt Shift, the strength of the blur. * */ -var Bokeh = new Class({ +var Bokeh = class extends Controller { - Extends: Controller, - - initialize: function Bokeh (camera, radius, amount, contrast, isTiltShift, blurX, blurY, strength) + constructor(camera, radius, amount, contrast, isTiltShift, blurX, blurY, strength) { if (radius === undefined) { radius = 0.5; } if (amount === undefined) { amount = 1; } @@ -59,7 +57,7 @@ var Bokeh = new Class({ if (blurY === undefined) { blurY = 1; } if (strength === undefined) { strength = 1; } - Controller.call(this, camera, 'FilterBokeh'); + super(camera, 'FilterBokeh'); /** * The radius of the bokeh effect. @@ -139,9 +137,9 @@ var Bokeh = new Class({ * @since 4.0.0 */ this.strength = strength; - }, + } - getPadding: function () + getPadding() { var override = this.paddingOverride; if (override) @@ -167,6 +165,6 @@ var Bokeh = new Class({ return this.currentPadding; } -}); +}; module.exports = Bokeh; diff --git a/src/filters/ColorMatrix.js b/src/filters/ColorMatrix.js index 488e313546..dbc36d190c 100644 --- a/src/filters/ColorMatrix.js +++ b/src/filters/ColorMatrix.js @@ -39,12 +39,11 @@ var DisplayColorMatrix = require('../display/ColorMatrix'); * @since 4.0.0 * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that owns this filter. */ -var ColorMatrix = new Class({ - Extends: Controller, +var ColorMatrix = class extends Controller { - initialize: function ColorMatrix (camera) + constructor(camera) { - Controller.call(this, camera, 'FilterColorMatrix'); + super(camera, 'FilterColorMatrix'); /** * The color matrix for this effect. @@ -55,14 +54,14 @@ var ColorMatrix = new Class({ * @since 4.0.0 */ this.colorMatrix = new DisplayColorMatrix(); - }, + } - destroy: function () + destroy() { this.colorMatrix = null; Controller.prototype.destroy.call(this); } -}); +}; module.exports = ColorMatrix; diff --git a/src/filters/Controller.js b/src/filters/Controller.js index 2df61a878b..a8be7e497f 100644 --- a/src/filters/Controller.js +++ b/src/filters/Controller.js @@ -24,8 +24,8 @@ var Rectangle = require('../geom/rectangle/Rectangle'); * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that owns this filter. * @param {string} renderNode - The ID of the RenderNode that this filter uses. */ -var Controller = new Class({ - initialize: function Controller (camera, renderNode) +var Controller = class { + constructor(camera, renderNode) { /** * Toggle this boolean to enable or disable this filter, @@ -108,7 +108,7 @@ var Controller = new Class({ * @default false */ this.ignoreDestroy = false; - }, + } /** * Returns the padding required for this filter, @@ -124,10 +124,10 @@ var Controller = new Class({ * @since 4.0.0 * @returns {Phaser.Geom.Rectangle} The padding required by this filter. */ - getPadding: function () + getPadding() { return this.paddingOverride || this.currentPadding; - }, + } /** * Sets the padding override. @@ -142,7 +142,7 @@ var Controller = new Class({ * @param {number} [right=0] - The right padding. * @param {number} [bottom=0] - The bottom padding. */ - setPaddingOverride: function (left, top, right, bottom) + setPaddingOverride(left, top, right, bottom) { if (left === null) { @@ -158,7 +158,7 @@ var Controller = new Class({ this.paddingOverride = new Rectangle(left, top, right - left, bottom - top); return this; - }, + } /** * Sets the active state of this filter. @@ -170,12 +170,12 @@ var Controller = new Class({ * @param {boolean} value - `true` to enable this filter, or `false` to disable it. * @returns {this} This filter instance. */ - setActive: function (value) + setActive(value) { this.active = value; return this; - }, + } /** * Destroys this Controller and nulls any references it holds. @@ -183,12 +183,12 @@ var Controller = new Class({ * @method Phaser.Filters.Controller#destroy * @since 4.0.0 */ - destroy: function () + destroy() { this.active = false; this.renderNode = null; this.camera = null; } -}); +}; module.exports = Controller; diff --git a/src/filters/Displacement.js b/src/filters/Displacement.js index f3476fcea0..1966952729 100644 --- a/src/filters/Displacement.js +++ b/src/filters/Displacement.js @@ -38,16 +38,15 @@ var Controller = require('./Controller'); * @param {number} [x=0.005] - The amount of horizontal displacement to apply. A very small float number, such as 0.005. * @param {number} [y=0.005] - The amount of vertical displacement to apply. A very small float number, such as 0.005. */ -var Displacement = new Class({ - Extends: Controller, +var Displacement = class extends Controller { - initialize: function Displacement (camera, texture, x, y) + constructor(camera, texture, x, y) { if (texture === undefined) { texture = '__WHITE'; } if (x === undefined) { x = 0.005; } if (y === undefined) { y = 0.005; } - Controller.call(this, camera, 'FilterDisplacement'); + super(camera, 'FilterDisplacement'); /** * The amount of horizontal displacement to apply. @@ -83,7 +82,7 @@ var Displacement = new Class({ this.glTexture; this.setTexture(texture); - }, + } /** * Sets the Texture to be used for the displacement effect. @@ -95,7 +94,7 @@ var Displacement = new Class({ * @param {string} [texture='__WHITE'] - The unique string-based key of the texture to use for displacement, which must exist in the Texture Manager. * @returns {this} This Filter Controller. */ - setTexture: function (texture) + setTexture(texture) { var phaserTexture = this.camera.scene.sys.textures.getFrame(texture); @@ -105,9 +104,9 @@ var Displacement = new Class({ } return this; - }, + } - getPadding: function () + getPadding() { var override = this.paddingOverride; if (override) @@ -124,6 +123,6 @@ var Displacement = new Class({ return this.currentPadding; } -}); +}; module.exports = Displacement; diff --git a/src/filters/Glow.js b/src/filters/Glow.js index 73b503387b..0a64a8ac20 100644 --- a/src/filters/Glow.js +++ b/src/filters/Glow.js @@ -46,10 +46,9 @@ var Controller = require('./Controller'); * @param {number} [quality=10] - The quality of the glow effect. This cannot be changed after the filter has been created. * @param {number} [distance=10] - The distance of the glow effect. This cannot be changed after the filter has been created. */ -var Glow = new Class({ - Extends: Controller, +var Glow = class extends Controller { - initialize: function Glow (camera, color, outerStrength, innerStrength, scale, knockout, quality, distance) + constructor(camera, color, outerStrength, innerStrength, scale, knockout, quality, distance) { if (outerStrength === undefined) { outerStrength = 4; } if (innerStrength === undefined) { innerStrength = 0; } @@ -58,7 +57,7 @@ var Glow = new Class({ if (quality === undefined) { quality = camera.scene.sys.game.config.glowQuality; } if (distance === undefined) { distance = camera.scene.sys.game.config.glowDistance; } - Controller.call(this, camera, 'FilterGlow'); + super(camera, 'FilterGlow'); /** * The strength of the glow outward from the edge of textures. @@ -144,7 +143,7 @@ var Glow = new Class({ { this.color = color; } - }, + } /** * The color of the glow as a number value. @@ -153,25 +152,22 @@ var Glow = new Class({ * @type {number} * @since 4.0.0 */ - color: { - - get: function () - { - var color = this.glcolor; - return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0)); - }, + get color() + { + var color = this.glcolor; - set: function (value) - { - var color = this.glcolor; + return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0)); + } - color[0] = ((value >> 16) & 0xFF) / 255; - color[1] = ((value >> 8) & 0xFF) / 255; - color[2] = (value & 0xFF) / 255; - } + set color(value) + { + var color = this.glcolor; - }, + color[0] = ((value >> 16) & 0xFF) / 255; + color[1] = ((value >> 8) & 0xFF) / 255; + color[2] = (value & 0xFF) / 255; + } /** * The distance of the glow effect. @@ -184,14 +180,11 @@ var Glow = new Class({ * @since 4.0.0 * @readonly */ - distance: { - get: function () - { - return this._distance; - } - - }, + get distance() + { + return this._distance; + } /** * The quality of the glow effect. @@ -205,15 +198,13 @@ var Glow = new Class({ * @since 4.0.0 * @readonly */ - quality: { - get: function () - { - return this._quality; - } - }, + get quality() + { + return this._quality; + } - getPadding: function () + getPadding() { var override = this.paddingOverride; if (override) @@ -232,6 +223,6 @@ var Glow = new Class({ return padding; } -}); +}; module.exports = Glow; diff --git a/src/filters/Mask.js b/src/filters/Mask.js index 0d374e0f76..8ce2c469ff 100644 --- a/src/filters/Mask.js +++ b/src/filters/Mask.js @@ -62,15 +62,14 @@ var Controller = require('./Controller'); * @param {Phaser.Cameras.Scene2D.Camera} [viewCamera] - The Camera to use when rendering the mask with a GameObject. If not specified, uses the scene's `main` camera. * @param {'local'|'world'} [viewTransform='world'] - The transform to use when rendering the mask with a GameObject. 'local' uses the GameObject's own properties. 'world' uses the GameObject's `parentContainer` value to compute a world position. */ -var Mask = new Class({ - Extends: Controller, +var Mask = class extends Controller { - initialize: function Mask (camera, mask, invert, viewCamera, viewTransform) + constructor(camera, mask, invert, viewCamera, viewTransform) { if (mask === undefined) { mask = '__WHITE'; } if (invert === undefined) { invert = false; } - Controller.call(this, camera, 'FilterMask'); + super(camera, 'FilterMask'); /** * The underlying texture used for the mask. @@ -173,7 +172,7 @@ var Mask = new Class({ { this.setGameObject(mask); } - }, + } /** * Updates the DynamicTexture for the mask. @@ -188,7 +187,7 @@ var Mask = new Class({ * @param {number} width - The width of the DynamicTexture. * @param {number} height - The height of the DynamicTexture */ - updateDynamicTexture: function (width, height) + updateDynamicTexture(width, height) { var gameObject = this.maskGameObject; @@ -220,7 +219,7 @@ var Mask = new Class({ this._dynamicTexture.render(); this.needsUpdate = false; - }, + } /** * Sets the GameObject used for the mask. @@ -230,7 +229,7 @@ var Mask = new Class({ * @param {Phaser.GameObjects.GameObject} gameObject - The GameObject to use for the mask. * @returns {this} This Filter Controller. */ - setGameObject: function (gameObject) + setGameObject(gameObject) { this.maskGameObject = gameObject; this.needsUpdate = true; @@ -241,7 +240,7 @@ var Mask = new Class({ // if this filter is being used as an internal filter. return this; - }, + } /** * Sets the texture used for the mask. @@ -251,7 +250,7 @@ var Mask = new Class({ * @param {string} [texture='__WHITE'] - The unique string-based key of the texture to use for displacement, which must exist in the Texture Manager. * @returns {this} This Filter Controller. */ - setTexture: function (texture) + setTexture(texture) { var phaserTexture = this.camera.scene.sys.textures.getFrame(texture); @@ -262,9 +261,9 @@ var Mask = new Class({ } return this; - }, + } - destroy: function () + destroy() { if (this._dynamicTexture) { @@ -276,6 +275,6 @@ var Mask = new Class({ Controller.prototype.destroy.call(this); } -}); +}; module.exports = Mask; diff --git a/src/filters/ParallelFilters.js b/src/filters/ParallelFilters.js index 86a109d3b8..24a23744c0 100644 --- a/src/filters/ParallelFilters.js +++ b/src/filters/ParallelFilters.js @@ -57,12 +57,11 @@ var Blend = require('./Blend'); * @since 4.0.0 * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that owns this filter. */ -var ParallelFilters = new Class({ - Extends: Controller, +var ParallelFilters = class extends Controller { - initialize: function ParallelFilters (camera) + constructor(camera) { - Controller.call(this, camera, 'FilterParallelFilters'); + super(camera, 'FilterParallelFilters'); /** * The top FilterList. @@ -96,6 +95,6 @@ var ParallelFilters = new Class({ */ this.blend = new Blend(camera); } -}); +}; module.exports = ParallelFilters; diff --git a/src/filters/Pixelate.js b/src/filters/Pixelate.js index 90fa28ae7e..50d825e0eb 100644 --- a/src/filters/Pixelate.js +++ b/src/filters/Pixelate.js @@ -32,14 +32,13 @@ var Controller = require('./Controller'); * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that owns this filter. * @param {number} [amount=1] - The amount of pixelation to apply. */ -var Pixelate = new Class({ - Extends: Controller, +var Pixelate = class extends Controller { - initialize: function Pixelate (camera, amount) + constructor(camera, amount) { if (amount === undefined) { amount = 1; } - Controller.call(this, camera, 'FilterPixelate'); + super(camera, 'FilterPixelate'); /** * The amount of pixelation to apply. @@ -53,6 +52,6 @@ var Pixelate = new Class({ */ this.amount = amount; } -}); +}; module.exports = Pixelate; diff --git a/src/filters/Sampler.js b/src/filters/Sampler.js index 9e3b2e90bd..636b56efb5 100644 --- a/src/filters/Sampler.js +++ b/src/filters/Sampler.js @@ -36,14 +36,13 @@ var Controller = require('./Controller'); * @param {Phaser.Types.Renderer.Snapshot.SnapshotCallback} callback - The callback to call with the results of the sampler. * @param {null|Phaser.Types.Math.Vector2Like|Phaser.Geom.Rectangle} [region=null] - The region to sample. If `null`, the entire camera view is sampled. If a `Phaser.Types.Math.Vector2Like`, a point is sampled. If a `Phaser.Geom.Rectangle`, the region is sampled. */ -var Sampler = new Class({ - Extends: Controller, +var Sampler = class extends Controller { - initialize: function Sampler (camera, callback, region) + constructor(camera, callback, region) { if (region === undefined) { region = null; } - Controller.call(this, camera, 'FilterSampler'); + super(camera, 'FilterSampler'); this.allowBaseDraw = false; @@ -66,6 +65,6 @@ var Sampler = new Class({ */ this.region = region; } -}); +}; module.exports = Sampler; diff --git a/src/filters/Shadow.js b/src/filters/Shadow.js index 838073e2de..6bf0438c81 100644 --- a/src/filters/Shadow.js +++ b/src/filters/Shadow.js @@ -40,11 +40,9 @@ var Controller = require('./Controller'); * @param {number} [samples=6] - The number of samples that the shadow effect will run for. * @param {number} [intensity=1] - The intensity of the shadow effect. */ -var Shadow = new Class({ +var Shadow = class extends Controller { - Extends: Controller, - - initialize: function Shadow (camera, x, y, decay, power, color, samples, intensity) + constructor(camera, x, y, decay, power, color, samples, intensity) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -53,7 +51,7 @@ var Shadow = new Class({ if (samples === undefined) { samples = 6; } if (intensity === undefined) { intensity = 1; } - Controller.call(this, camera, 'FilterShadow'); + super(camera, 'FilterShadow'); /** * The horizontal offset of the shadow effect. @@ -124,7 +122,7 @@ var Shadow = new Class({ { this.color = color; } - }, + } /** * The color of the shadow. @@ -133,27 +131,24 @@ var Shadow = new Class({ * @type {number} * @since 4.0.0 */ - color: { - get: function () - { - var color = this.glcolor; - - return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0)); - }, + get color() + { + var color = this.glcolor; - set: function (value) - { - var color = this.glcolor; + return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0)); + } - color[0] = ((value >> 16) & 0xFF) / 255; - color[1] = ((value >> 8) & 0xFF) / 255; - color[2] = (value & 0xFF) / 255; - } + set color(value) + { + var color = this.glcolor; - }, + color[0] = ((value >> 16) & 0xFF) / 255; + color[1] = ((value >> 8) & 0xFF) / 255; + color[2] = (value & 0xFF) / 255; + } - getPadding: function () + getPadding() { var override = this.paddingOverride; if (override) @@ -172,6 +167,6 @@ var Shadow = new Class({ return this.currentPadding; } -}); +}; module.exports = Shadow; diff --git a/src/filters/Threshold.js b/src/filters/Threshold.js index 95ed1a8565..2057417c23 100644 --- a/src/filters/Threshold.js +++ b/src/filters/Threshold.js @@ -44,12 +44,11 @@ var Controller = require('./Controller'); * @param {number|number[]} [edge2=0.5] - The second edge of the threshold. This may be an array of the RGBA channels, or a single number to apply to all 4 channels. * @param {boolean|boolean[]} [invert=false] - Whether each channel is inverted. This may be an array of the RGBA channels, or a single boolean to apply to all 4 channels. */ -var Threshold = new Class({ - Extends: Controller, +var Threshold = class extends Controller { - initialize: function Threshold (camera, edge1, edge2, invert) + constructor(camera, edge1, edge2, invert) { - Controller.call(this, camera, 'FilterThreshold'); + super(camera, 'FilterThreshold'); /** * The first edge of the threshold. @@ -86,7 +85,7 @@ var Threshold = new Class({ this.setEdge(edge1, edge2); this.setInvert(invert); - }, + } /** * Set the edges of the threshold. @@ -101,7 +100,7 @@ var Threshold = new Class({ * @param {number|number[]} [edge2=0.5] - The second edge of the threshold. This may be an array of the RGBA channels, or a single number to apply to all 4 channels. * @return {Phaser.Filters.Threshold} This Threshold instance. */ - setEdge: function (edge1, edge2) + setEdge(edge1, edge2) { if (edge1 === undefined) { @@ -142,7 +141,7 @@ var Threshold = new Class({ } return this; - }, + } /** * Set the invert state of the threshold. @@ -153,7 +152,7 @@ var Threshold = new Class({ * @param {boolean|boolean[]} [invert=false] - Whether each channel is inverted. This may be an array of the RGBA channels, or a single boolean to apply to all 4 channels. * @return {Phaser.Filters.Threshold} This Threshold instance. */ - setInvert: function (invert) + setInvert(invert) { if (invert === undefined) { @@ -171,6 +170,6 @@ var Threshold = new Class({ return this; } -}); +}; module.exports = Threshold; diff --git a/src/gameobjects/DisplayList.js b/src/gameobjects/DisplayList.js index 32f41c4ea8..0c0e130a32 100644 --- a/src/gameobjects/DisplayList.js +++ b/src/gameobjects/DisplayList.js @@ -27,15 +27,11 @@ var StableSort = require('../utils/array/StableSort'); * * @param {Phaser.Scene} scene - The Scene that this Display List belongs to. */ -var DisplayList = new Class({ +var DisplayList = class extends List { - Extends: List, - - initialize: - - function DisplayList (scene) + constructor(scene) { - List.call(this, scene); + super(scene); /** * The flag the determines whether Game Objects should be sorted when `depthSort()` is called. @@ -80,7 +76,7 @@ var DisplayList = new Class({ this.events.once(SceneEvents.BOOT, this.boot, this); this.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -90,10 +86,10 @@ var DisplayList = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * Internal method called from `List.addCallback`. @@ -106,7 +102,7 @@ var DisplayList = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that was added to the list. */ - addChildCallback: function (gameObject) + addChildCallback(gameObject) { if (gameObject.displayList && gameObject.displayList !== this) { @@ -128,7 +124,7 @@ var DisplayList = new Class({ this.events.emit(SceneEvents.ADDED_TO_SCENE, gameObject, this.scene); } - }, + } /** * Internal method called from `List.removeCallback`. @@ -141,7 +137,7 @@ var DisplayList = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that was removed from the list. */ - removeChildCallback: function (gameObject) + removeChildCallback(gameObject) { this.queueDepthSort(); @@ -150,7 +146,7 @@ var DisplayList = new Class({ gameObject.emit(GameObjectEvents.REMOVED_FROM_SCENE, gameObject, this.scene); this.events.emit(SceneEvents.REMOVED_FROM_SCENE, gameObject, this.scene); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -161,10 +157,10 @@ var DisplayList = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { this.events.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * Force a sort of the display list on the next call to depthSort. @@ -172,10 +168,10 @@ var DisplayList = new Class({ * @method Phaser.GameObjects.DisplayList#queueDepthSort * @since 3.0.0 */ - queueDepthSort: function () + queueDepthSort() { this.sortChildrenFlag = true; - }, + } /** * Immediately sorts the display list if the flag is set. @@ -183,7 +179,7 @@ var DisplayList = new Class({ * @method Phaser.GameObjects.DisplayList#depthSort * @since 3.0.0 */ - depthSort: function () + depthSort() { if (this.sortChildrenFlag) { @@ -191,7 +187,7 @@ var DisplayList = new Class({ this.sortChildrenFlag = false; } - }, + } /** * Compare the depth of two Game Objects. @@ -204,10 +200,10 @@ var DisplayList = new Class({ * * @return {number} The difference between the depths of each Game Object. */ - sortByDepth: function (childA, childB) + sortByDepth(childA, childB) { return childA._depth - childB._depth; - }, + } /** * Returns an array which contains all objects currently on the Display List. @@ -218,10 +214,10 @@ var DisplayList = new Class({ * * @return {Phaser.GameObjects.GameObject[]} The group members. */ - getChildren: function () + getChildren() { return this.list; - }, + } /** * The Scene that owns this plugin is shutting down. @@ -232,7 +228,7 @@ var DisplayList = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { var list = this.list; var i = list.length; @@ -248,7 +244,7 @@ var DisplayList = new Class({ list.length = 0; this.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -258,7 +254,7 @@ var DisplayList = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -269,7 +265,7 @@ var DisplayList = new Class({ this.events = null; } -}); +}; PluginCache.register('DisplayList', DisplayList, 'displayList'); diff --git a/src/gameobjects/GameObject.js b/src/gameobjects/GameObject.js index 55b4d70aec..41b4034247 100644 --- a/src/gameobjects/GameObject.js +++ b/src/gameobjects/GameObject.js @@ -30,20 +30,19 @@ var SceneEvents = require('../scene/events'); * @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({ +var GameObject = class extends EventEmitter { - Extends: EventEmitter, - - Mixins: [ - Components.Filters, - Components.RenderSteps - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Filters, + Components.RenderSteps + ], false); + } - function GameObject (scene, type) + constructor(scene, type) { - EventEmitter.call(this); + super(); /** * A reference to the Scene to which this Game Object belongs. @@ -226,7 +225,7 @@ var GameObject = new Class({ // Tell the Scene to re-sort the children scene.sys.queueDepthSort(); - }, + } /** * Sets the `active` property of this Game Object and returns this Game Object for further chaining. @@ -239,12 +238,12 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - setActive: function (value) + setActive(value) { this.active = value; return this; - }, + } /** * Sets the `name` property of this Game Object and returns this Game Object for further chaining. @@ -257,12 +256,12 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - setName: function (value) + setName(value) { this.name = value; return this; - }, + } /** * Sets the current state of this Game Object. @@ -281,12 +280,12 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - setState: function (value) + setState(value) { this.state = value; return this; - }, + } /** * Adds a Data Manager component to this Game Object. @@ -297,7 +296,7 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - setDataEnabled: function () + setDataEnabled() { if (!this.data) { @@ -305,7 +304,7 @@ var GameObject = new Class({ } return this; - }, + } /** * Allows you to store a key value pair within this Game Objects Data Manager. @@ -357,7 +356,7 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - setData: function (key, value) + setData(key, value) { if (!this.data) { @@ -367,7 +366,7 @@ var GameObject = new Class({ this.data.set(key, value); return this; - }, + } /** * Increase a value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is increased from 0. @@ -387,7 +386,7 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - incData: function (key, amount) + incData(key, amount) { if (!this.data) { @@ -397,7 +396,7 @@ var GameObject = new Class({ this.data.inc(key, amount); return this; - }, + } /** * Toggle a boolean value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is toggled from false. @@ -416,7 +415,7 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - toggleData: function (key) + toggleData(key) { if (!this.data) { @@ -426,7 +425,7 @@ var GameObject = new Class({ this.data.toggle(key); return this; - }, + } /** * Retrieves the value for the given key in this Game Objects Data Manager, or undefined if it doesn't exist. @@ -458,7 +457,7 @@ var GameObject = new Class({ * * @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) + getData(key) { if (!this.data) { @@ -466,7 +465,7 @@ var GameObject = new Class({ } return this.data.get(key); - }, + } /** * Pass this Game Object to the Input Manager to enable it for Input. @@ -499,12 +498,12 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - setInteractive: function (hitArea, hitAreaCallback, dropZone) + setInteractive(hitArea, hitAreaCallback, dropZone) { this.scene.sys.input.enable(this, hitArea, hitAreaCallback, dropZone); return this; - }, + } /** * If this Game Object has previously been enabled for input, this will disable it. @@ -522,14 +521,14 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - disableInteractive: function (resetCursor) + disableInteractive(resetCursor) { if (resetCursor === undefined) { resetCursor = false; } this.scene.sys.input.disable(this, resetCursor); return this; - }, + } /** * If this Game Object has previously been enabled for input, this will queue it @@ -558,7 +557,7 @@ var GameObject = new Class({ * * @return {this} This GameObject. */ - removeInteractive: function (resetCursor) + removeInteractive(resetCursor) { if (resetCursor === undefined) { resetCursor = false; } @@ -572,7 +571,7 @@ var GameObject = new Class({ this.input = undefined; return this; - }, + } /** * This callback is invoked when this Game Object is added to a Scene. @@ -585,9 +584,9 @@ var GameObject = new Class({ * @method Phaser.GameObjects.GameObject#addedToScene * @since 3.50.0 */ - addedToScene: function () + addedToScene() { - }, + } /** * This callback is invoked when this Game Object is removed from a Scene. @@ -600,9 +599,9 @@ var GameObject = new Class({ * @method Phaser.GameObjects.GameObject#removedFromScene * @since 3.50.0 */ - removedFromScene: function () + removedFromScene() { - }, + } /** * To be overridden by custom GameObjects. Allows base objects to be used in a Pool. @@ -612,9 +611,9 @@ var GameObject = new Class({ * * @param {...*} [args] - args */ - update: function () + update() { - }, + } /** * Returns a JSON representation of the Game Object. @@ -624,10 +623,10 @@ var GameObject = new Class({ * * @return {Phaser.Types.GameObjects.JSONGameObject} A JSON representation of the Game Object. */ - toJSON: function () + toJSON() { return ComponentsToJSON(this); - }, + } /** * Compares the renderMask with the renderFlags to see if this Game Object will render or not. @@ -640,12 +639,12 @@ var GameObject = new Class({ * * @return {boolean} True if the Game Object should be rendered, otherwise false. */ - willRender: function (camera) + willRender(camera) { var listWillRender = (this.displayList && this.displayList.active) ? this.displayList.willRender(camera) : true; return !(!listWillRender || GameObject.RENDER_MASK !== this.renderFlags || (this.cameraFilter !== 0 && (this.cameraFilter & camera.id))); - }, + } /** * Returns an array containing the display list index of either this Game Object, or if it has one, @@ -660,7 +659,7 @@ var GameObject = new Class({ * * @return {number[]} An array of display list position indexes. */ - getIndexList: function () + getIndexList() { // eslint-disable-next-line consistent-this var child = this; @@ -694,7 +693,7 @@ var GameObject = new Class({ } return indexes; - }, + } /** * Adds this Game Object to the given Display List. @@ -721,7 +720,7 @@ var GameObject = new Class({ * * @return {this} This Game Object. */ - addToDisplayList: function (displayList) + addToDisplayList(displayList) { if (displayList === undefined) { displayList = this.scene.sys.displayList; } @@ -745,7 +744,7 @@ var GameObject = new Class({ } return this; - }, + } /** * Adds this Game Object to the Update List belonging to the Scene. @@ -762,7 +761,7 @@ var GameObject = new Class({ * * @return {this} This Game Object. */ - addToUpdateList: function () + addToUpdateList() { if (this.scene && this.preUpdate) { @@ -770,7 +769,7 @@ var GameObject = new Class({ } return this; - }, + } /** * Removes this Game Object from the Display List it is currently on. @@ -790,7 +789,7 @@ var GameObject = new Class({ * * @return {this} This Game Object. */ - removeFromDisplayList: function () + removeFromDisplayList() { var displayList = this.displayList || this.scene.sys.displayList; @@ -808,7 +807,7 @@ var GameObject = new Class({ } return this; - }, + } /** * Removes this Game Object from the Scene's Update List. @@ -825,7 +824,7 @@ var GameObject = new Class({ * * @return {this} This Game Object. */ - removeFromUpdateList: function () + removeFromUpdateList() { if (this.scene && this.preUpdate) { @@ -833,7 +832,7 @@ var GameObject = new Class({ } return this; - }, + } /** * Returns a reference to the underlying display list _array_ that contains this Game Object, @@ -851,7 +850,7 @@ var GameObject = new Class({ * * @return {?Phaser.GameObjects.GameObject[]} The internal Display List array of Game Objects, or `null`. */ - getDisplayList: function () + getDisplayList() { var list = null; @@ -865,7 +864,7 @@ var GameObject = new Class({ } return list; - }, + } /** * Destroys this Game Object removing it from the Display List and Update List and @@ -886,7 +885,7 @@ var GameObject = new Class({ * * @param {boolean} [fromScene=false] - `True` if this Game Object is being destroyed by the Scene, `false` if not. */ - destroy: function (fromScene) + destroy(fromScene) { // This Game Object has already been destroyed if (!this.scene || this.ignoreDestroy) @@ -942,7 +941,7 @@ var GameObject = new Class({ this.parentContainer = undefined; } -}); +}; /** * The bitmask that `GameObject.renderFlags` is compared against to determine if the Game Object will render or not. diff --git a/src/gameobjects/GameObjectCreator.js b/src/gameobjects/GameObjectCreator.js index 32f84f3847..a7d720b609 100644 --- a/src/gameobjects/GameObjectCreator.js +++ b/src/gameobjects/GameObjectCreator.js @@ -24,11 +24,9 @@ var SceneEvents = require('../scene/events'); * * @param {Phaser.Scene} scene - The Scene to which this Game Object Factory belongs. */ -var GameObjectCreator = new Class({ +var GameObjectCreator = class { - initialize: - - function GameObjectCreator (scene) + constructor(scene) { /** * The Scene to which this Game Object Creator belongs. @@ -82,7 +80,7 @@ var GameObjectCreator = new Class({ this.events.once(SceneEvents.BOOT, this.boot, this); this.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -92,13 +90,13 @@ var GameObjectCreator = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.displayList = this.systems.displayList; this.updateList = this.systems.updateList; this.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -109,10 +107,10 @@ var GameObjectCreator = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { this.events.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is shutting down. @@ -122,10 +120,10 @@ var GameObjectCreator = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { this.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -135,7 +133,7 @@ var GameObjectCreator = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -149,7 +147,7 @@ var GameObjectCreator = new Class({ this.updateList = null; } -}); +}; /** * Static method called directly by the Game Object creator functions. diff --git a/src/gameobjects/GameObjectFactory.js b/src/gameobjects/GameObjectFactory.js index 42ada62147..426d08695b 100644 --- a/src/gameobjects/GameObjectFactory.js +++ b/src/gameobjects/GameObjectFactory.js @@ -23,11 +23,9 @@ var SceneEvents = require('../scene/events'); * * @param {Phaser.Scene} scene - The Scene to which this Game Object Factory belongs. */ -var GameObjectFactory = new Class({ +var GameObjectFactory = class { - initialize: - - function GameObjectFactory (scene) + constructor(scene) { /** * The Scene to which this Game Object Factory belongs. @@ -81,7 +79,7 @@ var GameObjectFactory = new Class({ this.events.once(SceneEvents.BOOT, this.boot, this); this.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -91,13 +89,13 @@ var GameObjectFactory = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.displayList = this.systems.displayList; this.updateList = this.systems.updateList; this.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -108,10 +106,10 @@ var GameObjectFactory = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { this.events.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * Adds an existing Game Object to this Scene. @@ -128,7 +126,7 @@ var GameObjectFactory = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that was added. */ - existing: function (child) + existing(child) { if (child.renderCanvas || child.renderWebGL) { @@ -143,7 +141,7 @@ var GameObjectFactory = new Class({ } return child; - }, + } /** * The Scene that owns this plugin is shutting down. @@ -153,10 +151,10 @@ var GameObjectFactory = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { this.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -166,7 +164,7 @@ var GameObjectFactory = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -180,7 +178,7 @@ var GameObjectFactory = new Class({ this.updateList = null; } -}); +}; /** * Static method called directly by the Game Object factory functions. diff --git a/src/gameobjects/UpdateList.js b/src/gameobjects/UpdateList.js index 43c898ea4e..794fbd3325 100644 --- a/src/gameobjects/UpdateList.js +++ b/src/gameobjects/UpdateList.js @@ -25,15 +25,11 @@ var SceneEvents = require('../scene/events'); * * @param {Phaser.Scene} scene - The Scene that the Update List belongs to. */ -var UpdateList = new Class({ +var UpdateList = class extends ProcessQueue { - Extends: ProcessQueue, - - initialize: - - function UpdateList (scene) + constructor(scene) { - ProcessQueue.call(this); + super(); // No duplicates in this list this.checkQueue = true; @@ -98,7 +94,7 @@ var UpdateList = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -108,10 +104,10 @@ var UpdateList = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.systems.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -122,14 +118,14 @@ var UpdateList = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { var eventEmitter = this.systems.events; eventEmitter.on(SceneEvents.PRE_UPDATE, this.update, this); eventEmitter.on(SceneEvents.UPDATE, this.sceneUpdate, this); eventEmitter.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The update step. @@ -142,7 +138,7 @@ var UpdateList = new Class({ * @param {number} time - The current timestamp. * @param {number} delta - The delta time elapsed since the last frame. */ - sceneUpdate: function (time, delta) + sceneUpdate(time, delta) { var list = this._active; var length = list.length; @@ -156,7 +152,7 @@ var UpdateList = new Class({ gameObject.preUpdate.call(gameObject, time, delta); } } - }, + } /** * The Scene that owns this plugin is shutting down. @@ -166,7 +162,7 @@ var UpdateList = new Class({ * @method Phaser.GameObjects.UpdateList#shutdown * @since 3.0.0 */ - shutdown: function () + shutdown() { var i = this._active.length; @@ -202,7 +198,7 @@ var UpdateList = new Class({ eventEmitter.off(SceneEvents.PRE_UPDATE, this.update, this); eventEmitter.off(SceneEvents.UPDATE, this.sceneUpdate, this); eventEmitter.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -212,7 +208,7 @@ var UpdateList = new Class({ * @method Phaser.GameObjects.UpdateList#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -291,7 +287,7 @@ var UpdateList = new Class({ * @readonly * @since 3.20.0 */ -}); +}; PluginCache.register('UpdateList', UpdateList, 'updateList'); diff --git a/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js b/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js index 138e4c6484..399bb17390 100644 --- a/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js +++ b/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js @@ -51,19 +51,18 @@ var Render = require('./DynamicBitmapTextRender'); * @param {number} [size] - The font size of this Bitmap Text. * @param {number} [align=0] - The alignment of the text in a multi-line BitmapText object. */ -var DynamicBitmapText = new Class({ +var DynamicBitmapText = class extends BitmapText { - Extends: BitmapText, - - Mixins: [ - Render - ], - - initialize: + static + { + Class.mixin(this, [ + Render + ], false); + } - function DynamicBitmapText (scene, x, y, font, text, size, align) + constructor(scene, x, y, font, text, size, align) { - BitmapText.call(this, scene, x, y, font, text, size, align); + super(scene, x, y, font, text, size, align); this.type = 'DynamicBitmapText'; @@ -145,7 +144,7 @@ var DynamicBitmapText = new Class({ rotation: 0, data: 0 }; - }, + } /** * Set the crop size of this Bitmap Text. @@ -158,13 +157,13 @@ var DynamicBitmapText = new Class({ * * @return {this} This Game Object. */ - setSize: function (width, height) + setSize(width, height) { this.cropWidth = width; this.cropHeight = height; return this; - }, + } /** * Set a callback that alters how each character of the Bitmap Text is rendered. @@ -182,12 +181,12 @@ var DynamicBitmapText = new Class({ * * @return {this} This Game Object. */ - setDisplayCallback: function (callback) + setDisplayCallback(callback) { this.displayCallback = callback; return this; - }, + } /** * Set the horizontal scroll position of this Bitmap Text. @@ -199,12 +198,12 @@ var DynamicBitmapText = new Class({ * * @return {this} This Game Object. */ - setScrollX: function (value) + setScrollX(value) { this.scrollX = value; return this; - }, + } /** * Set the vertical scroll position of this Bitmap Text. @@ -216,13 +215,13 @@ var DynamicBitmapText = new Class({ * * @return {this} This Game Object. */ - setScrollY: function (value) + setScrollY(value) { this.scrollY = value; return this; } -}); +}; module.exports = DynamicBitmapText; diff --git a/src/gameobjects/bitmaptext/static/BitmapText.js b/src/gameobjects/bitmaptext/static/BitmapText.js index 78aafd14c6..e2f83fdb7b 100644 --- a/src/gameobjects/bitmaptext/static/BitmapText.js +++ b/src/gameobjects/bitmaptext/static/BitmapText.js @@ -66,35 +66,34 @@ var Render = require('./BitmapTextRender'); * @param {number} [size] - The font size of this Bitmap Text. * @param {number} [align=0] - The alignment of the text in a multi-line BitmapText object. */ -var BitmapText = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.Depth, - Components.GetBounds, - Components.Lighting, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.ScrollFactor, - Components.Texture, - Components.Tint, - Components.Transform, - Components.Visible, - Render - ], - - initialize: - - function BitmapText (scene, x, y, font, text, size, align) +var BitmapText = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.Depth, + Components.GetBounds, + Components.Lighting, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.ScrollFactor, + Components.Texture, + Components.Tint, + Components.Transform, + Components.Visible, + Render + ], false); + } + + constructor(scene, x, y, font, text, size, align) { if (text === undefined) { text = ''; } if (align === undefined) { align = 0; } - GameObject.call(this, scene, 'BitmapText'); + super(scene, 'BitmapText'); /** * The key of the Bitmap Font used by this Bitmap Text. @@ -298,7 +297,7 @@ var BitmapText = new Class({ this.initRenderNodes(this._defaultRenderNodesMap); this.setText(text); - }, + } /** * The default render nodes to initialize. @@ -310,12 +309,11 @@ var BitmapText = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultBitmapTextNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultBitmapTextNodes; + } /** * Set the lines of text in this BitmapText to be left-aligned. @@ -326,14 +324,14 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setLeftAlign: function () + setLeftAlign() { this._align = BitmapText.ALIGN_LEFT; this._dirty = true; return this; - }, + } /** * Set the lines of text in this BitmapText to be center-aligned. @@ -344,14 +342,14 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setCenterAlign: function () + setCenterAlign() { this._align = BitmapText.ALIGN_CENTER; this._dirty = true; return this; - }, + } /** * Set the lines of text in this BitmapText to be right-aligned. @@ -362,14 +360,14 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setRightAlign: function () + setRightAlign() { this._align = BitmapText.ALIGN_RIGHT; this._dirty = true; return this; - }, + } /** * Set the font size of this Bitmap Text. @@ -381,14 +379,14 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setFontSize: function (size) + setFontSize(size) { this._fontSize = size; this._dirty = true; return this; - }, + } /** * Sets the letter spacing between each character of this Bitmap Text. @@ -402,7 +400,7 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setLetterSpacing: function (spacing) + setLetterSpacing(spacing) { if (spacing === undefined) { spacing = 0; } @@ -411,7 +409,7 @@ var BitmapText = new Class({ this._dirty = true; return this; - }, + } /** * Sets the line spacing value. This value is added to the font height to @@ -428,14 +426,14 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setLineSpacing: function (spacing) + setLineSpacing(spacing) { if (spacing === undefined) { spacing = 0; } this.lineSpacing = spacing; return this; - }, + } /** * Set the textual content of this BitmapText. @@ -449,7 +447,7 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setText: function (value) + setText(value) { if (!value && value !== 0) { @@ -471,7 +469,7 @@ var BitmapText = new Class({ } return this; - }, + } /** * Sets a drop shadow effect on this Bitmap Text. @@ -496,7 +494,7 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setDropShadow: function (x, y, color, alpha) + setDropShadow(x, y, color, alpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -509,7 +507,7 @@ var BitmapText = new Class({ this.dropShadowAlpha = alpha; return this; - }, + } /** * Sets a tint on a range of characters in this Bitmap Text, starting from the `start` parameter index @@ -552,7 +550,7 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setCharacterTint: function (start, length, tintFill, topLeft, topRight, bottomLeft, bottomRight) + setCharacterTint(start, length, tintFill, topLeft, topRight, bottomLeft, bottomRight) { if (start === undefined) { start = 0; } if (length === undefined) { length = 1; } @@ -618,7 +616,7 @@ var BitmapText = new Class({ } return this; - }, + } /** * Sets a tint on a matching word within this Bitmap Text. @@ -661,7 +659,7 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setWordTint: function (word, count, tintFill, topLeft, topRight, bottomLeft, bottomRight) + setWordTint(word, count, tintFill, topLeft, topRight, bottomLeft, bottomRight) { if (count === undefined) { count = 1; } @@ -691,7 +689,7 @@ var BitmapText = new Class({ } return this; - }, + } /** * Calculate the bounds of this Bitmap Text. @@ -712,7 +710,7 @@ var BitmapText = new Class({ * * @return {Phaser.Types.GameObjects.BitmapText.BitmapTextSize} An object that describes the size of this Bitmap Text. */ - getTextBounds: function (round) + getTextBounds(round) { // local = The BitmapText based on fontSize and 0x0 coords // global = The BitmapText, taking into account scale and world position @@ -728,7 +726,7 @@ var BitmapText = new Class({ } return bounds; - }, + } /** * Gets the character located at the given x/y coordinate within this Bitmap Text. @@ -754,7 +752,7 @@ var BitmapText = new Class({ * * @return {Phaser.Types.GameObjects.BitmapText.BitmapTextCharacter} The character object at the given position, or `null`. */ - getCharacterAt: function (x, y, camera) + getCharacterAt(x, y, camera) { var point = this.getLocalPoint(x, y, null, camera); @@ -777,7 +775,7 @@ var BitmapText = new Class({ } return null; - }, + } /** * Updates the Display Origin cached values internally stored on this Game Object. @@ -788,14 +786,14 @@ var BitmapText = new Class({ * * @return {this} This Game Object instance. */ - updateDisplayOrigin: function () + updateDisplayOrigin() { this._dirty = true; this.getTextBounds(false); return this; - }, + } /** * Changes the font this BitmapText is using to render. @@ -812,7 +810,7 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setFont: function (key, size, align) + setFont(key, size, align) { if (size === undefined) { size = this._fontSize; } if (align === undefined) { align = this._align; } @@ -833,7 +831,7 @@ var BitmapText = new Class({ } return this; - }, + } /** * Sets the maximum display width of this BitmapText in pixels. @@ -855,7 +853,7 @@ var BitmapText = new Class({ * * @return {this} This BitmapText Object. */ - setMaxWidth: function (value, wordWrapCharCode) + setMaxWidth(value, wordWrapCharCode) { this._maxWidth = value; @@ -867,7 +865,7 @@ var BitmapText = new Class({ } return this; - }, + } /** * Controls the alignment of each line of text in this BitmapText object. @@ -887,20 +885,17 @@ var BitmapText = new Class({ * @type {number} * @since 3.11.0 */ - align: { - - set: function (value) - { - this._align = value; - this._dirty = true; - }, - get: function () - { - return this._align; - } + set align(value) + { + this._align = value; + this._dirty = true; + } - }, + get align() + { + return this._align; + } /** * The text that this Bitmap Text object displays. @@ -911,19 +906,16 @@ var BitmapText = new Class({ * @type {string} * @since 3.0.0 */ - text: { - - set: function (value) - { - this.setText(value); - }, - get: function () - { - return this._text; - } + set text(value) + { + this.setText(value); + } - }, + get text() + { + return this._text; + } /** * The font size of this Bitmap Text. @@ -934,20 +926,17 @@ var BitmapText = new Class({ * @type {number} * @since 3.0.0 */ - fontSize: { - set: function (value) - { - this._fontSize = value; - this._dirty = true; - }, - - get: function () - { - return this._fontSize; - } + set fontSize(value) + { + this._fontSize = value; + this._dirty = true; + } - }, + get fontSize() + { + return this._fontSize; + } /** * Adds / Removes spacing between characters. @@ -960,20 +949,17 @@ var BitmapText = new Class({ * @type {number} * @since 3.0.0 */ - letterSpacing: { - set: function (value) - { - this._letterSpacing = value; - this._dirty = true; - }, - - get: function () - { - return this._letterSpacing; - } + set letterSpacing(value) + { + this._letterSpacing = value; + this._dirty = true; + } - }, + get letterSpacing() + { + return this._letterSpacing; + } /** * Adds / Removes spacing between lines. @@ -986,20 +972,17 @@ var BitmapText = new Class({ * @type {number} * @since 3.60.0 */ - lineSpacing: { - set: function (value) - { - this._lineSpacing = value; - this._dirty = true; - }, - - get: function () - { - return this._lineSpacing; - } + set lineSpacing(value) + { + this._lineSpacing = value; + this._dirty = true; + } - }, + get lineSpacing() + { + return this._lineSpacing; + } /** * The maximum display width of this BitmapText in pixels. @@ -1015,20 +998,17 @@ var BitmapText = new Class({ * @type {number} * @since 3.21.0 */ - maxWidth: { - set: function (value) - { - this._maxWidth = value; - this._dirty = true; - }, - - get: function () - { - return this._maxWidth; - } + set maxWidth(value) + { + this._maxWidth = value; + this._dirty = true; + } - }, + get maxWidth() + { + return this._maxWidth; + } /** * The width of this Bitmap Text. @@ -1040,16 +1020,13 @@ var BitmapText = new Class({ * @readonly * @since 3.0.0 */ - width: { - get: function () - { - this.getTextBounds(false); - - return this._bounds.global.width; - } + get width() + { + this.getTextBounds(false); - }, + return this._bounds.global.width; + } /** * The height of this Bitmap text. @@ -1061,16 +1038,13 @@ var BitmapText = new Class({ * @readonly * @since 3.0.0 */ - height: { - - get: function () - { - this.getTextBounds(false); - return this._bounds.global.height; - } + get height() + { + this.getTextBounds(false); - }, + return this._bounds.global.height; + } /** * The displayed width of this Bitmap Text. @@ -1084,14 +1058,11 @@ var BitmapText = new Class({ * @readonly * @since 3.60.0 */ - displayWidth: { - get: function () - { - return this.width; - } - - }, + get displayWidth() + { + return this.width; + } /** * The displayed height of this Bitmap Text. @@ -1105,14 +1076,11 @@ var BitmapText = new Class({ * @readonly * @since 3.60.0 */ - displayHeight: { - get: function () - { - return this.height; - } - - }, + get displayHeight() + { + return this.height; + } /** * Build a JSON representation of this Bitmap Text. @@ -1122,7 +1090,7 @@ var BitmapText = new Class({ * * @return {Phaser.Types.GameObjects.BitmapText.JSONBitmapText} A JSON representation of this Bitmap Text. */ - toJSON: function () + toJSON() { var out = Components.ToJSON(this); @@ -1140,7 +1108,7 @@ var BitmapText = new Class({ out.data = data; return out; - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -1149,14 +1117,14 @@ var BitmapText = new Class({ * @protected * @since 3.50.0 */ - preDestroy: function () + preDestroy() { this.charColors.length = 0; this._bounds = null; this.fontData = null; } -}); +}; /** * Left align the text characters in a multi-line BitmapText object. diff --git a/src/gameobjects/blitter/Blitter.js b/src/gameobjects/blitter/Blitter.js index 28fe3b08b3..baf2cc66fb 100644 --- a/src/gameobjects/blitter/Blitter.js +++ b/src/gameobjects/blitter/Blitter.js @@ -60,30 +60,29 @@ var List = require('../../structs/List'); * @param {string} [texture='__DEFAULT'] - The key of the texture this Game Object will use for rendering. The Texture must already exist in the Texture Manager. * @param {(string|number)} [frame=0] - The Frame of the Texture that this Game Object will use. Only set if the Texture has multiple frames, such as a Texture Atlas or Sprite Sheet. */ -var Blitter = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.Depth, - Components.Lighting, - Components.Mask, - Components.RenderNodes, - Components.ScrollFactor, - Components.Size, - Components.Texture, - Components.Transform, - Components.Visible, - BlitterRender - ], - - initialize: - - function Blitter (scene, x, y, texture, frame) +var Blitter = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.Depth, + Components.Lighting, + Components.Mask, + Components.RenderNodes, + Components.ScrollFactor, + Components.Size, + Components.Texture, + Components.Transform, + Components.Visible, + BlitterRender + ], false); + } + + constructor(scene, x, y, texture, frame) { - GameObject.call(this, scene, 'Blitter'); + super(scene, 'Blitter'); this.setTexture(texture, frame); this.setPosition(x, y); @@ -120,7 +119,7 @@ var Blitter = new Class({ * @since 3.0.0 */ this.dirty = false; - }, + } /** * The default render nodes to use for this Game Object. @@ -132,12 +131,11 @@ var Blitter = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultBlitterNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultBlitterNodes; + } /** * Creates a new Bob in this Blitter. @@ -156,7 +154,7 @@ var Blitter = new Class({ * * @return {Phaser.GameObjects.Bob} The newly created Bob object. */ - create: function (x, y, frame, visible, index) + create(x, y, frame, visible, index) { if (visible === undefined) { visible = true; } if (index === undefined) { index = this.children.length; } @@ -177,7 +175,7 @@ var Blitter = new Class({ this.dirty = true; return bob; - }, + } /** * Creates multiple Bob objects within this Blitter and then passes each of them to the specified callback. @@ -192,7 +190,7 @@ var Blitter = new Class({ * * @return {Phaser.GameObjects.Bob[]} An array of Bob objects that were created. */ - createFromCallback: function (callback, quantity, frame, visible) + createFromCallback(callback, quantity, frame, visible) { var bobs = this.createMultiple(quantity, frame, visible); @@ -204,7 +202,7 @@ var Blitter = new Class({ } return bobs; - }, + } /** * Creates multiple Bobs in one call. @@ -223,7 +221,7 @@ var Blitter = new Class({ * * @return {Phaser.GameObjects.Bob[]} An array of Bob objects that were created. */ - createMultiple: function (quantity, frame, visible) + createMultiple(quantity, frame, visible) { if (frame === undefined) { frame = this.frame.name; } if (visible === undefined) { visible = true; } @@ -245,7 +243,7 @@ var Blitter = new Class({ }); return bobs; - }, + } /** * Checks if the given child can render or not, by checking its `visible` and `alpha` values. @@ -257,10 +255,10 @@ var Blitter = new Class({ * * @return {boolean} Returns `true` if the given child can render, otherwise `false`. */ - childCanRender: function (child) + childCanRender(child) { return (child.visible && child.alpha > 0); - }, + } /** * Returns an array of Bobs to be rendered. @@ -271,7 +269,7 @@ var Blitter = new Class({ * * @return {Phaser.GameObjects.Bob[]} An array of Bob objects that will be rendered this frame. */ - getRenderList: function () + getRenderList() { if (this.dirty) { @@ -280,7 +278,7 @@ var Blitter = new Class({ } return this.renderList; - }, + } /** * Removes all Bobs from the children List and clears the dirty flag. @@ -288,11 +286,11 @@ var Blitter = new Class({ * @method Phaser.GameObjects.Blitter#clear * @since 3.0.0 */ - clear: function () + clear() { this.children.removeAll(); this.dirty = true; - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -301,13 +299,13 @@ var Blitter = new Class({ * @protected * @since 3.9.0 */ - preDestroy: function () + preDestroy() { this.children.destroy(); this.renderList = []; } -}); +}; module.exports = Blitter; diff --git a/src/gameobjects/blitter/Bob.js b/src/gameobjects/blitter/Bob.js index 809c58aa27..d458ba248a 100644 --- a/src/gameobjects/blitter/Bob.js +++ b/src/gameobjects/blitter/Bob.js @@ -34,11 +34,9 @@ var Frame = require('../../textures/Frame'); * @param {(string|number)} frame - The Frame this Bob will render with, as defined in the Texture the parent Blitter is using. * @param {boolean} visible - Should the Bob render visible or not to start with? */ -var Bob = new Class({ +var Bob = class { - initialize: - - function Bob (blitter, x, y, frame, visible) + constructor(blitter, x, y, frame, visible) { /** * The Blitter object that this Bob belongs to. @@ -151,7 +149,7 @@ var Bob = new Class({ * @since 3.60.0 */ this.hasTransformComponent = true; - }, + } /** * Changes the Texture Frame being used by this Bob. @@ -165,7 +163,7 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - setFrame: function (frame) + setFrame(frame) { if (frame === undefined) { @@ -181,7 +179,7 @@ var Bob = new Class({ } return this; - }, + } /** * Resets the horizontal and vertical flipped state of this Bob back to their default un-flipped state. @@ -191,13 +189,13 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - resetFlip: function () + resetFlip() { this.flipX = false; this.flipY = false; return this; - }, + } /** * Resets this Bob. @@ -215,7 +213,7 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - reset: function (x, y, frame) + reset(x, y, frame) { this.x = x; this.y = y; @@ -234,7 +232,7 @@ var Bob = new Class({ } return this; - }, + } /** * Changes the position of this Bob to the values given. @@ -247,13 +245,13 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - setPosition: function (x, y) + setPosition(x, y) { this.x = x; this.y = y; return this; - }, + } /** * Sets the horizontal flipped state of this Bob. @@ -265,12 +263,12 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - setFlipX: function (value) + setFlipX(value) { this.flipX = value; return this; - }, + } /** * Sets the vertical flipped state of this Bob. @@ -282,12 +280,12 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - setFlipY: function (value) + setFlipY(value) { this.flipY = value; return this; - }, + } /** * Sets the horizontal and vertical flipped state of this Bob. @@ -300,13 +298,13 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - setFlip: function (x, y) + setFlip(x, y) { this.flipX = x; this.flipY = y; return this; - }, + } /** * Sets the visibility of this Bob. @@ -320,12 +318,12 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - setVisible: function (value) + setVisible(value) { this.visible = value; return this; - }, + } /** * Set the Alpha level of this Bob. The alpha controls the opacity of the Game Object as it renders. @@ -340,12 +338,12 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - setAlpha: function (value) + setAlpha(value) { this.alpha = value; return this; - }, + } /** * Sets the tint of this Bob. @@ -357,12 +355,12 @@ var Bob = new Class({ * * @return {this} This Bob Game Object. */ - setTint: function (value) + setTint(value) { this.tint = value; return this; - }, + } /** * Destroys this Bob instance. @@ -371,7 +369,7 @@ var Bob = new Class({ * @method Phaser.GameObjects.Bob#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.parent.dirty = true; @@ -380,7 +378,7 @@ var Bob = new Class({ this.parent = undefined; this.frame = undefined; this.data = undefined; - }, + } /** * The visible state of the Bob. @@ -391,20 +389,17 @@ var Bob = new Class({ * @type {boolean} * @since 3.0.0 */ - visible: { - - get: function () - { - return this._visible; - }, - set: function (value) - { - this.parent.dirty |= (this._visible !== value); - this._visible = value; - } + get visible() + { + return this._visible; + } - }, + set visible(value) + { + this.parent.dirty |= (this._visible !== value); + this._visible = value; + } /** * The alpha value of the Bob, between 0 and 1. @@ -415,21 +410,18 @@ var Bob = new Class({ * @type {number} * @since 3.0.0 */ - alpha: { - get: function () - { - return this._alpha; - }, - - set: function (value) - { - this.parent.dirty |= ((this._alpha > 0) !== (value > 0)); - this._alpha = value; - } + get alpha() + { + return this._alpha; + } + set alpha(value) + { + this.parent.dirty |= ((this._alpha > 0) !== (value > 0)); + this._alpha = value; } -}); +}; module.exports = Bob; diff --git a/src/gameobjects/captureframe/CaptureFrame.js b/src/gameobjects/captureframe/CaptureFrame.js index aeb1533fbf..77639f519a 100644 --- a/src/gameobjects/captureframe/CaptureFrame.js +++ b/src/gameobjects/captureframe/CaptureFrame.js @@ -66,20 +66,22 @@ var CaptureFrameRender = require('./CaptureFrameRender.js'); * @param {Phaser.Scene} scene - The Scene to which this CaptureFrame belongs. * @param {string} key - The key of the texture to create from this CaptureFrame. */ -var CaptureFrame = new Class({ - Extends: GameObject, +var CaptureFrame = class extends GameObject { - Mixins: [ - Components.BlendMode, - Components.Depth, - Components.RenderNodes, - Components.Visible, - CaptureFrameRender - ], + static + { + Class.mixin(this, [ + Components.BlendMode, + Components.Depth, + Components.RenderNodes, + Components.Visible, + CaptureFrameRender + ], false); + } - initialize: function CaptureFrame (scene, key) + constructor(scene, key) { - GameObject.call(this, scene, 'CaptureFrame'); + super(scene, 'CaptureFrame'); var renderer = scene.renderer; @@ -109,7 +111,7 @@ var CaptureFrame = new Class({ this.captureTexture = scene.sys.textures.addGLTexture(key, this.drawingContext.texture); this.initRenderNodes(this._defaultRenderNodesMap); - }, + } /** * The default render nodes for this Game Object. @@ -121,12 +123,11 @@ var CaptureFrame = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultQuadNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultQuadNodes; + } /** * Set the alpha value of this CaptureFrame. @@ -138,10 +139,10 @@ var CaptureFrame = new Class({ * @param {number} alpha - The alpha value (not used). * @returns {this} */ - setAlpha: function (alpha) + setAlpha(alpha) { return this; - }, + } /** * Set the scroll factor of this CaptureFrame. @@ -154,10 +155,10 @@ var CaptureFrame = new Class({ * @param {number} y - The vertical scroll factor (not used). * @returns {this} */ - setScrollFactor: function (x, y) + setScrollFactor(x, y) { return this; } -}); +}; module.exports = CaptureFrame; diff --git a/src/gameobjects/components/FilterList.js b/src/gameobjects/components/FilterList.js index 91a73612bb..098c968f3c 100644 --- a/src/gameobjects/components/FilterList.js +++ b/src/gameobjects/components/FilterList.js @@ -85,8 +85,8 @@ var Threshold = require('../../filters/Threshold'); * * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that owns this list. */ -var FilterList = new Class({ - initialize: function FilterList (camera) +var FilterList = class { + constructor(camera) { /** * The Camera that owns this list. @@ -111,7 +111,7 @@ var FilterList = new Class({ * @since 4.0.0 */ this.list = []; - }, + } /** * Destroys and removes all filters in this list. @@ -120,7 +120,7 @@ var FilterList = new Class({ * @since 4.0.0 * @returns {this} This FilterList instance. */ - clear: function () + clear() { for (var i = 0; i < this.list.length; i++) { @@ -134,7 +134,7 @@ var FilterList = new Class({ this.list.length = 0; return this; - }, + } /** * Adds a filter to this list. @@ -147,7 +147,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Controller} The filter that was added. */ - add: function (filter, index) + add(filter, index) { if (index === undefined) { @@ -159,7 +159,7 @@ var FilterList = new Class({ } return filter; - }, + } /** * Removes a filter from this list, then destroys it. @@ -172,7 +172,7 @@ var FilterList = new Class({ * * @return {this} This FilterList instance. */ - remove: function (filter, forceDestroy) + remove(filter, forceDestroy) { var index = this.list.indexOf(filter); @@ -186,7 +186,7 @@ var FilterList = new Class({ } return this; - }, + } /** * Returns all active filters in this list. @@ -195,10 +195,10 @@ var FilterList = new Class({ * @since 4.0.0 * @return {Phaser.Filters.Controller[]} The active filters in this list. */ - getActive: function () + getActive() { return this.list.filter(isActive); - }, + } /** * Adds a Barrel effect. @@ -211,10 +211,10 @@ var FilterList = new Class({ * @param {number} [amount=1] - The amount of distortion applied to the barrel effect. A value of 1 is no distortion. Typically keep this within +- 1. * @return {Phaser.Filters.Barrel} The new Barrel filter controller. */ - addBarrel: function (amount) + addBarrel(amount) { return this.add(new Barrel(this.camera, amount)); - }, + } /** * Adds a Blend effect. @@ -231,7 +231,7 @@ var FilterList = new Class({ * @param {number[]} [color=[1, 1, 1, 1]] - The color to apply to the blend texture. Each value corresponds to a color channel in RGBA. The expected range is 0 to 1, but you can go outside that range for different effects. * @return {Phaser.Filters.Blend} The new Blend filter controller. */ - addBlend: function (texture, blendMode, amount, color) + addBlend(texture, blendMode, amount, color) { return this.add(new Blend( this.camera, @@ -240,7 +240,7 @@ var FilterList = new Class({ amount, color )); - }, + } /** * Adds a Blur effect. @@ -262,7 +262,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Blur} The new Blur filter controller. */ - addBlur: function (quality, x, y, strength, color, steps) + addBlur(quality, x, y, strength, color, steps) { return this.add(new Blur( this.camera, @@ -273,7 +273,7 @@ var FilterList = new Class({ color, steps )); - }, + } /** * Adds a Bokeh effect. @@ -294,7 +294,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Bokeh} The new Bokeh filter controller. */ - addBokeh: function (radius, amount, contrast) + addBokeh(radius, amount, contrast) { return this.add(new Bokeh( this.camera, @@ -302,7 +302,7 @@ var FilterList = new Class({ amount, contrast )); - }, + } /** * Adds a Color Matrix effect. @@ -317,10 +317,10 @@ var FilterList = new Class({ * @since 4.0.0 * @return {Phaser.Filters.ColorMatrix} The new ColorMatrix filter controller. */ - addColorMatrix: function () + addColorMatrix() { return this.add(new ColorMatrix(this.camera)); - }, + } /** * Adds a Displacement effect. @@ -340,7 +340,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Displacement} The new Displacement filter controller. */ - addDisplacement: function (texture, x, y) + addDisplacement(texture, x, y) { return this.add(new Displacement( this.camera, @@ -348,7 +348,7 @@ var FilterList = new Class({ x, y )); - }, + } /** * Adds a Glow effect. @@ -371,7 +371,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Glow} The new Glow filter controller. */ - addGlow: function (color, outerStrength, innerStrength, scale, knockout, quality, distance) + addGlow(color, outerStrength, innerStrength, scale, knockout, quality, distance) { return this.add(new Glow( this.camera, @@ -383,7 +383,7 @@ var FilterList = new Class({ quality, distance )); - }, + } /** * Adds a Mask effect. @@ -424,7 +424,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Mask} The new Mask filter controller. */ - addMask: function (mask, invert, viewCamera, viewTransform) + addMask(mask, invert, viewCamera, viewTransform) { return this.add(new Mask( this.camera, @@ -433,7 +433,7 @@ var FilterList = new Class({ viewCamera, viewTransform )); - }, + } /** * Adds a Parallel Filters effect. @@ -471,7 +471,7 @@ var FilterList = new Class({ * @since 4.0.0 * @return {Phaser.Filters.ParallelFilters} The new Parallel Filters filter controller. */ - addParallelFilters: function () + addParallelFilters() { // This import avoids a circular dependency. if (!ParallelFilters) @@ -479,7 +479,7 @@ var FilterList = new Class({ ParallelFilters = require('../../filters/ParallelFilters'); } return this.add(new ParallelFilters(this.camera)); - }, + } /** * Adds a Pixelate effect. @@ -496,13 +496,13 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Pixelate} The new Pixelate filter controller. */ - addPixelate: function (amount) + addPixelate(amount) { return this.add(new Pixelate( this.camera, amount )); - }, + } /** * Adds a Sampler effect. @@ -522,14 +522,14 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Sampler} The new Sampler filter controller. */ - addSampler: function (callback, region) + addSampler(callback, region) { return this.add(new Sampler( this.camera, callback, region )); - }, + } /** * Adds a Shadow effect. @@ -551,7 +551,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Shadow} The new Shadow filter controller. */ - addShadow: function (x, y, decay, power, color, samples, intensity) + addShadow(x, y, decay, power, color, samples, intensity) { return this.add(new Shadow( this.camera, @@ -563,7 +563,7 @@ var FilterList = new Class({ samples, intensity )); - }, + } /** * Adds a Threshold effect. @@ -590,7 +590,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Threshold} The new Threshold filter controller. */ - addThreshold: function (edge1, edge2, invert) + addThreshold(edge1, edge2, invert) { return this.add(new Threshold( this.camera, @@ -598,7 +598,7 @@ var FilterList = new Class({ edge2, invert )); - }, + } /** * Adds a Tilt Shift effect. @@ -621,7 +621,7 @@ var FilterList = new Class({ * * @return {Phaser.Filters.Bokeh} The new Bokeh filter controller. */ - addTiltShift: function (radius, amount, contrast, blurX, blurY, strength) + addTiltShift(radius, amount, contrast, blurX, blurY, strength) { return this.add(new Bokeh( this.camera, @@ -633,7 +633,7 @@ var FilterList = new Class({ blurY, strength )); - }, + } /** * Destroys this FilterList. @@ -641,13 +641,13 @@ var FilterList = new Class({ * @method Phaser.GameObjects.Components.FilterList#destroy * @since 4.0.0 */ - destroy: function () + destroy() { this.clear(); this.camera = null; } -}); +}; function isActive (filter) { diff --git a/src/gameobjects/components/TransformMatrix.js b/src/gameobjects/components/TransformMatrix.js index db4e39362f..1d92140ec3 100644 --- a/src/gameobjects/components/TransformMatrix.js +++ b/src/gameobjects/components/TransformMatrix.js @@ -32,11 +32,9 @@ var Vector2 = require('../../math/Vector2'); * @param {number} [tx=0] - The Translate X value. * @param {number} [ty=0] - The Translate Y value. */ -var TransformMatrix = new Class({ +var TransformMatrix = class { - initialize: - - function TransformMatrix (a, b, c, d, tx, ty) + constructor(a, b, c, d, tx, ty) { if (a === undefined) { a = 1; } if (b === undefined) { b = 0; } @@ -77,7 +75,7 @@ var TransformMatrix = new Class({ * @since 3.60.0 */ this.quad = new Float32Array(8); - }, + } /** * The Scale X value. @@ -86,19 +84,16 @@ var TransformMatrix = new Class({ * @type {number} * @since 3.4.0 */ - a: { - - get: function () - { - return this.matrix[0]; - }, - set: function (value) - { - this.matrix[0] = value; - } + get a() + { + return this.matrix[0]; + } - }, + set a(value) + { + this.matrix[0] = value; + } /** * The Skew Y value. @@ -107,19 +102,16 @@ var TransformMatrix = new Class({ * @type {number} * @since 3.4.0 */ - b: { - - get: function () - { - return this.matrix[1]; - }, - set: function (value) - { - this.matrix[1] = value; - } + get b() + { + return this.matrix[1]; + } - }, + set b(value) + { + this.matrix[1] = value; + } /** * The Skew X value. @@ -128,19 +120,16 @@ var TransformMatrix = new Class({ * @type {number} * @since 3.4.0 */ - c: { - - get: function () - { - return this.matrix[2]; - }, - set: function (value) - { - this.matrix[2] = value; - } + get c() + { + return this.matrix[2]; + } - }, + set c(value) + { + this.matrix[2] = value; + } /** * The Scale Y value. @@ -149,19 +138,16 @@ var TransformMatrix = new Class({ * @type {number} * @since 3.4.0 */ - d: { - - get: function () - { - return this.matrix[3]; - }, - set: function (value) - { - this.matrix[3] = value; - } + get d() + { + return this.matrix[3]; + } - }, + set d(value) + { + this.matrix[3] = value; + } /** * The Translate X value. @@ -170,19 +156,16 @@ var TransformMatrix = new Class({ * @type {number} * @since 3.11.0 */ - e: { - - get: function () - { - return this.matrix[4]; - }, - set: function (value) - { - this.matrix[4] = value; - } + get e() + { + return this.matrix[4]; + } - }, + set e(value) + { + this.matrix[4] = value; + } /** * The Translate Y value. @@ -191,19 +174,16 @@ var TransformMatrix = new Class({ * @type {number} * @since 3.11.0 */ - f: { - - get: function () - { - return this.matrix[5]; - }, - set: function (value) - { - this.matrix[5] = value; - } + get f() + { + return this.matrix[5]; + } - }, + set f(value) + { + this.matrix[5] = value; + } /** * The Translate X value. @@ -212,19 +192,16 @@ var TransformMatrix = new Class({ * @type {number} * @since 3.4.0 */ - tx: { - - get: function () - { - return this.matrix[4]; - }, - set: function (value) - { - this.matrix[4] = value; - } + get tx() + { + return this.matrix[4]; + } - }, + set tx(value) + { + this.matrix[4] = value; + } /** * The Translate Y value. @@ -233,19 +210,16 @@ var TransformMatrix = new Class({ * @type {number} * @since 3.4.0 */ - ty: { - get: function () - { - return this.matrix[5]; - }, - - set: function (value) - { - this.matrix[5] = value; - } + get ty() + { + return this.matrix[5]; + } - }, + set ty(value) + { + this.matrix[5] = value; + } /** * The rotation of the Matrix. Value is in radians. @@ -255,14 +229,11 @@ var TransformMatrix = new Class({ * @readonly * @since 3.4.0 */ - rotation: { - get: function () - { - return Math.acos(this.a / this.scaleX) * ((Math.atan(-this.c / this.a) < 0) ? -1 : 1); - } - - }, + get rotation() + { + return Math.acos(this.a / this.scaleX) * ((Math.atan(-this.c / this.a) < 0) ? -1 : 1); + } /** * The rotation of the Matrix, normalized to be within the Phaser right-handed @@ -273,36 +244,33 @@ var TransformMatrix = new Class({ * @readonly * @since 3.19.0 */ - rotationNormalized: { - get: function () + get rotationNormalized() + { + var matrix = this.matrix; + + var a = matrix[0]; + var b = matrix[1]; + var c = matrix[2]; + var d = matrix[3]; + + if (a || b) { - var matrix = this.matrix; - - var a = matrix[0]; - var b = matrix[1]; - var c = matrix[2]; - var d = matrix[3]; - - if (a || b) - { - // var r = Math.sqrt(a * a + b * b); - - return (b > 0) ? Math.acos(a / this.scaleX) : -Math.acos(a / this.scaleX); - } - else if (c || d) - { - // var s = Math.sqrt(c * c + d * d); - - return MATH_CONST.PI_OVER_2 - ((d > 0) ? Math.acos(-c / this.scaleY) : -Math.acos(c / this.scaleY)); - } - else - { - return 0; - } + // var r = Math.sqrt(a * a + b * b); + + return (b > 0) ? Math.acos(a / this.scaleX) : -Math.acos(a / this.scaleX); } + else if (c || d) + { + // var s = Math.sqrt(c * c + d * d); - }, + return MATH_CONST.PI_OVER_2 - ((d > 0) ? Math.acos(-c / this.scaleY) : -Math.acos(c / this.scaleY)); + } + else + { + return 0; + } + } /** * The decomposed horizontal scale of the Matrix. This value is always positive. @@ -312,14 +280,11 @@ var TransformMatrix = new Class({ * @readonly * @since 3.4.0 */ - scaleX: { - get: function () - { - return Math.sqrt((this.a * this.a) + (this.b * this.b)); - } - - }, + get scaleX() + { + return Math.sqrt((this.a * this.a) + (this.b * this.b)); + } /** * The decomposed vertical scale of the Matrix. This value is always positive. @@ -329,14 +294,11 @@ var TransformMatrix = new Class({ * @readonly * @since 3.4.0 */ - scaleY: { - get: function () - { - return Math.sqrt((this.c * this.c) + (this.d * this.d)); - } - - }, + get scaleY() + { + return Math.sqrt((this.c * this.c) + (this.d * this.d)); + } /** * Reset the Matrix to an identity matrix. @@ -346,7 +308,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - loadIdentity: function () + loadIdentity() { var matrix = this.matrix; @@ -358,7 +320,7 @@ var TransformMatrix = new Class({ matrix[5] = 0; return this; - }, + } /** * Translate the Matrix. @@ -371,7 +333,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - translate: function (x, y) + translate(x, y) { var matrix = this.matrix; @@ -379,7 +341,7 @@ var TransformMatrix = new Class({ matrix[5] = matrix[1] * x + matrix[3] * y + matrix[5]; return this; - }, + } /** * Scale the Matrix. @@ -392,7 +354,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - scale: function (x, y) + scale(x, y) { var matrix = this.matrix; @@ -402,7 +364,7 @@ var TransformMatrix = new Class({ matrix[3] *= y; return this; - }, + } /** * Rotate the Matrix. @@ -414,7 +376,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - rotate: function (angle) + rotate(angle) { var sin = Math.sin(angle); var cos = Math.cos(angle); @@ -432,7 +394,7 @@ var TransformMatrix = new Class({ matrix[3] = b * -sin + d * cos; return this; - }, + } /** * Multiply this Matrix by the given Matrix. @@ -449,7 +411,7 @@ var TransformMatrix = new Class({ * * @return {(this|Phaser.GameObjects.Components.TransformMatrix)} Either this TransformMatrix, or the `out` Matrix, if given in the arguments. */ - multiply: function (rhs, out) + multiply(rhs, out) { var matrix = this.matrix; var source = rhs.matrix; @@ -478,7 +440,7 @@ var TransformMatrix = new Class({ destinationMatrix[5] = (sourceE * localB) + (sourceF * localD) + localF; return destinationMatrix; - }, + } /** * Multiply this Matrix by the matrix given, including the offset. @@ -495,7 +457,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - multiplyWithOffset: function (src, offsetX, offsetY) + multiplyWithOffset(src, offsetX, offsetY) { var matrix = this.matrix; var otherMatrix = src.matrix; @@ -525,7 +487,7 @@ var TransformMatrix = new Class({ matrix[5] = tx1 * b0 + ty1 * d0 + psf; return this; - }, + } /** * Transform the Matrix. @@ -542,7 +504,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - transform: function (a, b, c, d, tx, ty) + transform(a, b, c, d, tx, ty) { var matrix = this.matrix; @@ -561,7 +523,7 @@ var TransformMatrix = new Class({ matrix[5] = tx * b0 + ty * d0 + ty0; return this; - }, + } /** * Transform a point in to the local space of this Matrix. @@ -575,7 +537,7 @@ var TransformMatrix = new Class({ * * @return {Phaser.Types.Math.Vector2Like} The Point containing the transformed coordinates. */ - transformPoint: function (x, y, point) + transformPoint(x, y, point) { if (point === undefined) { point = { x: 0, y: 0 }; } @@ -592,7 +554,7 @@ var TransformMatrix = new Class({ point.y = x * b + y * d + ty; return point; - }, + } /** * Invert the Matrix. @@ -602,7 +564,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - invert: function () + invert() { var matrix = this.matrix; @@ -623,7 +585,7 @@ var TransformMatrix = new Class({ matrix[5] = -(a * ty - b * tx) / n; return this; - }, + } /** * Set the values of this Matrix to copy those of the matrix given. @@ -635,7 +597,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - copyFrom: function (src) + copyFrom(src) { var matrix = this.matrix; @@ -647,7 +609,7 @@ var TransformMatrix = new Class({ matrix[5] = src.f; return this; - }, + } /** * Set the values of this Matrix to copy those of the array given. @@ -660,7 +622,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - copyFromArray: function (src) + copyFromArray(src) { var matrix = this.matrix; @@ -672,7 +634,7 @@ var TransformMatrix = new Class({ matrix[5] = src[5]; return this; - }, + } /** * Set the values of this Matrix to copy those of the matrix given, @@ -691,7 +653,7 @@ var TransformMatrix = new Class({ * * @returns {this} This TransformMatrix. */ - copyWithScrollFactorFrom: function (src, scrollX, scrollY, scrollFactorX, scrollFactorY) + copyWithScrollFactorFrom(src, scrollX, scrollY, scrollFactorX, scrollFactorY) { var matrix = this.matrix; @@ -707,7 +669,7 @@ var TransformMatrix = new Class({ matrix[5] = src.b * sx + src.d * sy + src.f; return this; - }, + } /** * Copy the values from this Matrix to the given Canvas Rendering Context. @@ -720,14 +682,14 @@ var TransformMatrix = new Class({ * * @return {CanvasRenderingContext2D} The Canvas Rendering Context. */ - copyToContext: function (ctx) + copyToContext(ctx) { var matrix = this.matrix; ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); return ctx; - }, + } /** * Copy the values from this Matrix to the given Canvas Rendering Context. @@ -740,13 +702,13 @@ var TransformMatrix = new Class({ * * @return {CanvasRenderingContext2D} The Canvas Rendering Context. */ - setToContext: function (ctx) + setToContext(ctx) { // using old way for old browser compatibility #6965 ctx.setTransform(this.a, this.b, this.c, this.d, this.e, this.f); return ctx; - }, + } /** * Copy the values in this Matrix to the array given. @@ -760,7 +722,7 @@ var TransformMatrix = new Class({ * * @return {array} An array where elements 0 to 5 contain the values from this matrix. */ - copyToArray: function (out) + copyToArray(out) { var matrix = this.matrix; @@ -779,7 +741,7 @@ var TransformMatrix = new Class({ } return out; - }, + } /** * Set the values of this Matrix. @@ -796,7 +758,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - setTransform: function (a, b, c, d, tx, ty) + setTransform(a, b, c, d, tx, ty) { var matrix = this.matrix; @@ -808,7 +770,7 @@ var TransformMatrix = new Class({ matrix[5] = ty; return this; - }, + } /** * Decompose this Matrix into its translation, scale and rotation values using QR decomposition. @@ -822,7 +784,7 @@ var TransformMatrix = new Class({ * * @return {Phaser.Types.GameObjects.DecomposeMatrixResults} The decomposed Matrix. */ - decomposeMatrix: function () + decomposeMatrix() { var decomposedMatrix = this.decomposedMatrix; @@ -867,7 +829,7 @@ var TransformMatrix = new Class({ } return decomposedMatrix; - }, + } /** * Apply the identity, translate, rotate and scale operations on the Matrix. @@ -883,7 +845,7 @@ var TransformMatrix = new Class({ * * @return {this} This TransformMatrix. */ - applyITRS: function (x, y, rotation, scaleX, scaleY) + applyITRS(x, y, rotation, scaleX, scaleY) { var matrix = this.matrix; @@ -901,7 +863,7 @@ var TransformMatrix = new Class({ matrix[3] = radianCos * scaleY; return this; - }, + } /** * Takes the `x` and `y` values and returns a new position in the `output` vector that is the inverse of @@ -918,7 +880,7 @@ var TransformMatrix = new Class({ * * @return {Phaser.Math.Vector2} The coordinates, inverse-transformed through this matrix. */ - applyInverse: function (x, y, output) + applyInverse(x, y, output) { if (output === undefined) { output = new Vector2(); } @@ -937,7 +899,7 @@ var TransformMatrix = new Class({ output.y = (a * id * y) + (-b * id * x) + (((-ty * a) + (tx * b)) * id); return output; - }, + } /** * Performs the 8 calculations required to create the vertices of @@ -957,7 +919,7 @@ var TransformMatrix = new Class({ * * @return {Float32Array} The quad Float32Array. */ - setQuad: function (x, y, xw, yh, quad) + setQuad(x, y, xw, yh, quad) { if (quad === undefined) { quad = this.quad; } @@ -983,7 +945,7 @@ var TransformMatrix = new Class({ quad[7] = xw * b + y * d + f; return quad; - }, + } /** * Returns the X component of this matrix multiplied by the given values. @@ -997,10 +959,10 @@ var TransformMatrix = new Class({ * * @return {number} The calculated x value. */ - getX: function (x, y) + getX(x, y) { return x * this.a + y * this.c + this.e; - }, + } /** * Returns the Y component of this matrix multiplied by the given values. @@ -1014,10 +976,10 @@ var TransformMatrix = new Class({ * * @return {number} The calculated y value. */ - getY: function (x, y) + getY(x, y) { return x * this.b + y * this.d + this.f; - }, + } /** * Returns the X component of this matrix multiplied by the given values. @@ -1033,7 +995,7 @@ var TransformMatrix = new Class({ * * @return {number} The calculated x value. */ - getXRound: function (x, y, round) + getXRound(x, y, round) { var v = this.getX(x, y); @@ -1043,7 +1005,7 @@ var TransformMatrix = new Class({ } return v; - }, + } /** * Returns the Y component of this matrix multiplied by the given values. @@ -1059,7 +1021,7 @@ var TransformMatrix = new Class({ * * @return {number} The calculated y value. */ - getYRound: function (x, y, round) + getYRound(x, y, round) { var v = this.getY(x, y); @@ -1069,7 +1031,7 @@ var TransformMatrix = new Class({ } return v; - }, + } /** * Returns a string that can be used in a CSS Transform call as a `matrix` property. @@ -1079,12 +1041,12 @@ var TransformMatrix = new Class({ * * @return {string} A string containing the CSS Transform matrix values. */ - getCSSMatrix: function () + getCSSMatrix() { var m = this.matrix; return 'matrix(' + m[0] + ',' + m[1] + ',' + m[2] + ',' + m[3] + ',' + m[4] + ',' + m[5] + ')'; - }, + } /** * Destroys this Transform Matrix. @@ -1092,13 +1054,13 @@ var TransformMatrix = new Class({ * @method Phaser.GameObjects.Components.TransformMatrix#destroy * @since 3.4.0 */ - destroy: function () + destroy() { this.matrix = null; this.quad = null; this.decomposedMatrix = null; } -}); +}; module.exports = TransformMatrix; diff --git a/src/gameobjects/container/Container.js b/src/gameobjects/container/Container.js index ecc09874dc..871845adc8 100644 --- a/src/gameobjects/container/Container.js +++ b/src/gameobjects/container/Container.js @@ -80,26 +80,25 @@ var tempTransformMatrix = new Components.TransformMatrix(); * @param {number} [y=0] - The vertical position of this Game Object in the world. * @param {Phaser.GameObjects.GameObject[]} [children] - An optional array of Game Objects to add to this Container. */ -var Container = new Class({ +var Container = class extends GameObject { - Extends: GameObject, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.ComputedSize, - Components.Depth, - Components.Mask, - Components.Transform, - Components.Visible, - Render - ], - - initialize: + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.ComputedSize, + Components.Depth, + Components.Mask, + Components.Transform, + Components.Visible, + Render + ], false); + } - function Container (scene, x, y, children) + constructor(scene, x, y, children) { - GameObject.call(this, scene, 'Container'); + super(scene, 'Container'); /** * An array holding the children of this Container. @@ -242,7 +241,7 @@ var Container = new Class({ { this.add(children); } - }, + } /** * Internal value to allow Containers to be used for input and physics. @@ -254,14 +253,11 @@ var Container = new Class({ * @override * @since 3.4.0 */ - originX: { - - get: function () - { - return 0.5; - } - }, + get originX() + { + return 0.5; + } /** * Internal value to allow Containers to be used for input and physics. @@ -273,14 +269,11 @@ var Container = new Class({ * @override * @since 3.4.0 */ - originY: { - get: function () - { - return 0.5; - } - - }, + get originY() + { + return 0.5; + } /** * Internal value to allow Containers to be used for input and physics. @@ -292,14 +285,11 @@ var Container = new Class({ * @override * @since 3.4.0 */ - displayOriginX: { - - get: function () - { - return this.width * 0.5; - } - }, + get displayOriginX() + { + return this.width * 0.5; + } /** * Internal value to allow Containers to be used for input and physics. @@ -311,14 +301,11 @@ var Container = new Class({ * @override * @since 3.4.0 */ - displayOriginY: { - - get: function () - { - return this.height * 0.5; - } - }, + get displayOriginY() + { + return this.height * 0.5; + } /** * Does this Container exclusively manage its children? @@ -340,14 +327,14 @@ var Container = new Class({ * * @return {this} This Container. */ - setExclusive: function (value) + setExclusive(value) { if (value === undefined) { value = true; } this.exclusive = value; return this; - }, + } /** * Gets the bounds of this Container. It works by iterating all children of the Container, @@ -369,7 +356,7 @@ var Container = new Class({ * * @return {Phaser.Geom.Rectangle} The values stored in the output object. */ - getBounds: function (output) + getBounds(output) { if (output === undefined) { output = new Rectangle(); } @@ -413,7 +400,7 @@ var Container = new Class({ } return output; - }, + } /** * Internal add handler. @@ -424,7 +411,7 @@ var Container = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that was just added to this Container. */ - addHandler: function (gameObject) + addHandler(gameObject) { gameObject.once(Events.DESTROY, this.onChildDestroyed, this); @@ -441,7 +428,7 @@ var Container = new Class({ gameObject.addedToScene(); } - }, + } /** * Internal remove handler. @@ -452,7 +439,7 @@ var Container = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that was just removed from this Container. */ - removeHandler: function (gameObject) + removeHandler(gameObject) { gameObject.off(Events.DESTROY, this.remove, this); @@ -464,7 +451,7 @@ var Container = new Class({ gameObject.addToDisplayList(); } - }, + } /** * Takes a Point-like object, such as a Vector2, or object with public x and y properties, @@ -478,7 +465,7 @@ var Container = new Class({ * * @return {Phaser.Types.Math.Vector2Like} The transformed point. */ - pointToContainer: function (source, output) + pointToContainer(source, output) { if (output === undefined) { output = new Vector2(); } @@ -502,7 +489,7 @@ var Container = new Class({ tempMatrix.transformPoint(source.x, source.y, output); return output; - }, + } /** * Returns the world transform matrix as used for Bounds checks. @@ -514,10 +501,10 @@ var Container = new Class({ * * @return {Phaser.GameObjects.Components.TransformMatrix} The world transform matrix. */ - getBoundsTransformMatrix: function () + getBoundsTransformMatrix() { return this.getWorldTransformMatrix(tempTransformMatrix, this.localTransform); - }, + } /** * Adds the given Game Object, or array of Game Objects, to this Container. @@ -534,12 +521,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - add: function (child) + add(child) { ArrayUtils.Add(this.list, child, this.maxSize, this.addHandler, this); return this; - }, + } /** * Adds the given Game Object, or array of Game Objects, to this Container at the specified position. @@ -559,12 +546,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - addAt: function (child, index) + addAt(child, index) { ArrayUtils.AddAt(this.list, child, index, this.maxSize, this.addHandler, this); return this; - }, + } /** * Returns the Game Object at the given position in this Container. @@ -579,10 +566,10 @@ var Container = new Class({ * * @return {?Phaser.GameObjects.GameObject} The Game Object at the specified index, or `null` if none found. */ - getAt: function (index) + getAt(index) { return this.list[index]; - }, + } /** * Returns the index of the given Game Object in this Container. @@ -597,10 +584,10 @@ var Container = new Class({ * * @return {number} The index of the Game Object in this Container, or -1 if not found. */ - getIndex: function (child) + getIndex(child) { return this.list.indexOf(child); - }, + } /** * Sort the contents of this Container so the items are in order based on the given property. @@ -614,7 +601,7 @@ var Container = new Class({ * * @return {this} This Container instance. */ - sort: function (property, handler) + sort(property, handler) { if (!property) { @@ -632,7 +619,7 @@ var Container = new Class({ ArrayUtils.StableSort(this.list, handler); return this; - }, + } /** * Searches for the first instance of a child with its `name` property matching the given argument. @@ -648,10 +635,10 @@ var Container = new Class({ * * @return {?Phaser.GameObjects.GameObject} The first child with a matching name, or `null` if none were found. */ - getByName: function (name) + getByName(name) { return ArrayUtils.GetFirst(this.list, 'name', name); - }, + } /** * Returns a random Game Object from this Container. @@ -667,10 +654,10 @@ var Container = new Class({ * * @return {?Phaser.GameObjects.GameObject} A random child from the Container, or `null` if the Container is empty. */ - getRandom: function (startIndex, length) + getRandom(startIndex, length) { return ArrayUtils.GetRandom(this.list, startIndex, length); - }, + } /** * Gets the first Game Object in this Container. @@ -695,10 +682,10 @@ var Container = new Class({ * * @return {?Phaser.GameObjects.GameObject} The first matching Game Object, or `null` if none was found. */ - getFirst: function (property, value, startIndex, endIndex) + getFirst(property, value, startIndex, endIndex) { return ArrayUtils.GetFirst(this.list, property, value, startIndex, endIndex); - }, + } /** * Returns all Game Objects in this Container. @@ -728,10 +715,10 @@ var Container = new Class({ * * @return {Phaser.GameObjects.GameObject[]} An array of matching Game Objects from this Container. */ - getAll: function (property, value, startIndex, endIndex) + getAll(property, value, startIndex, endIndex) { return ArrayUtils.GetAll(this.list, property, value, startIndex, endIndex); - }, + } /** * Returns the total number of Game Objects in this Container that have a property @@ -751,10 +738,10 @@ var Container = new Class({ * * @return {number} The total number of Game Objects in this Container with a property matching the given value. */ - count: function (property, value, startIndex, endIndex) + count(property, value, startIndex, endIndex) { return ArrayUtils.CountAllMatching(this.list, property, value, startIndex, endIndex); - }, + } /** * Swaps the position of two Game Objects in this Container. @@ -771,12 +758,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - swap: function (child1, child2) + swap(child1, child2) { ArrayUtils.Swap(this.list, child1, child2); return this; - }, + } /** * Moves a Game Object to a new position within this Container. @@ -797,12 +784,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - moveTo: function (child, index) + moveTo(child, index) { ArrayUtils.MoveTo(this.list, child, index); return this; - }, + } /** * Moves a Game Object above another one within this Container. @@ -821,12 +808,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - moveAbove: function (child1, child2) + moveAbove(child1, child2) { ArrayUtils.MoveAbove(this.list, child1, child2); return this; - }, + } /** * Moves a Game Object below another one within this Container. @@ -845,12 +832,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - moveBelow: function (child1, child2) + moveBelow(child1, child2) { ArrayUtils.MoveBelow(this.list, child1, child2); return this; - }, + } /** * Removes the given Game Object, or array of Game Objects, from this Container. @@ -870,7 +857,7 @@ var Container = new Class({ * * @return {this} This Container instance. */ - remove: function (child, destroyChild) + remove(child, destroyChild) { var removed = ArrayUtils.Remove(this.list, child, this.removeHandler, this); @@ -888,7 +875,7 @@ var Container = new Class({ } return this; - }, + } /** * Removes the Game Object at the given position in this Container. @@ -903,7 +890,7 @@ var Container = new Class({ * * @return {this} This Container instance. */ - removeAt: function (index, destroyChild) + removeAt(index, destroyChild) { var removed = ArrayUtils.RemoveAt(this.list, index, this.removeHandler, this); @@ -913,7 +900,7 @@ var Container = new Class({ } return this; - }, + } /** * Removes the Game Objects between the given positions in this Container. @@ -929,7 +916,7 @@ var Container = new Class({ * * @return {this} This Container instance. */ - removeBetween: function (startIndex, endIndex, destroyChild) + removeBetween(startIndex, endIndex, destroyChild) { var removed = ArrayUtils.RemoveBetween(this.list, startIndex, endIndex, this.removeHandler, this); @@ -942,7 +929,7 @@ var Container = new Class({ } return this; - }, + } /** * Removes all Game Objects from this Container. @@ -956,7 +943,7 @@ var Container = new Class({ * * @return {this} This Container instance. */ - removeAll: function (destroyChild) + removeAll(destroyChild) { var list = this.list; @@ -980,7 +967,7 @@ var Container = new Class({ } return this; - }, + } /** * Brings the given Game Object to the top of this Container. @@ -996,12 +983,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - bringToTop: function (child) + bringToTop(child) { ArrayUtils.BringToTop(this.list, child); return this; - }, + } /** * Sends the given Game Object to the bottom of this Container. @@ -1017,12 +1004,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - sendToBack: function (child) + sendToBack(child) { ArrayUtils.SendToBack(this.list, child); return this; - }, + } /** * Moves the given Game Object up one place in this Container, unless it's already at the top. @@ -1037,12 +1024,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - moveUp: function (child) + moveUp(child) { ArrayUtils.MoveUp(this.list, child); return this; - }, + } /** * Moves the given Game Object down one place in this Container, unless it's already at the bottom. @@ -1057,12 +1044,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - moveDown: function (child) + moveDown(child) { ArrayUtils.MoveDown(this.list, child); return this; - }, + } /** * Reverses the order of all Game Objects in this Container. @@ -1072,12 +1059,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - reverse: function () + reverse() { this.list.reverse(); return this; - }, + } /** * Shuffles the all Game Objects in this Container using the Fisher-Yates implementation. @@ -1087,12 +1074,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - shuffle: function () + shuffle() { ArrayUtils.Shuffle(this.list); return this; - }, + } /** * Replaces a Game Object in this Container with the new Game Object. @@ -1110,7 +1097,7 @@ var Container = new Class({ * * @return {this} This Container instance. */ - replace: function (oldChild, newChild, destroyChild) + replace(oldChild, newChild, destroyChild) { var moved = ArrayUtils.Replace(this.list, oldChild, newChild); @@ -1126,7 +1113,7 @@ var Container = new Class({ } return this; - }, + } /** * Returns `true` if the given Game Object is a direct child of this Container. @@ -1143,10 +1130,10 @@ var Container = new Class({ * * @return {boolean} True if the Game Object is an immediate child of this Container, otherwise false. */ - exists: function (child) + exists(child) { return (this.list.indexOf(child) > -1); - }, + } /** * Sets the property to the given value on all Game Objects in this Container. @@ -1165,12 +1152,12 @@ var Container = new Class({ * * @return {this} This Container instance. */ - setAll: function (property, value, startIndex, endIndex) + setAll(property, value, startIndex, endIndex) { ArrayUtils.SetAll(this.list, property, value, startIndex, endIndex); return this; - }, + } /** * @callback EachContainerCallback @@ -1198,7 +1185,7 @@ var Container = new Class({ * * @return {this} This Container instance. */ - each: function (callback, context) + each(callback, context) { var args = [ null ]; var i; @@ -1218,7 +1205,7 @@ var Container = new Class({ } return this; - }, + } /** * Passes all Game Objects in this Container to the given callback. @@ -1235,7 +1222,7 @@ var Container = new Class({ * * @return {this} This Container instance. */ - iterate: function (callback, context) + iterate(callback, context) { var args = [ null ]; var i; @@ -1253,7 +1240,7 @@ var Container = new Class({ } return this; - }, + } /** * Sets the scroll factor of this Container and optionally all of its children. @@ -1281,7 +1268,7 @@ var Container = new Class({ * * @return {this} This Game Object instance. */ - setScrollFactor: function (x, y, updateChildren) + setScrollFactor(x, y, updateChildren) { if (y === undefined) { y = x; } if (updateChildren === undefined) { updateChildren = false; } @@ -1296,7 +1283,7 @@ var Container = new Class({ } return this; - }, + } /** * The number of Game Objects inside this Container. @@ -1306,14 +1293,11 @@ var Container = new Class({ * @readonly * @since 3.4.0 */ - length: { - - get: function () - { - return this.list.length; - } - }, + get length() + { + return this.list.length; + } /** * Returns the first Game Object within the Container, or `null` if it is empty. @@ -1325,23 +1309,20 @@ var Container = new Class({ * @readonly * @since 3.4.0 */ - first: { - get: function () - { - this.position = 0; + get first() + { + this.position = 0; - if (this.list.length > 0) - { - return this.list[0]; - } - else - { - return null; - } + if (this.list.length > 0) + { + return this.list[0]; } - - }, + else + { + return null; + } + } /** * Returns the last Game Object within the Container, or `null` if it is empty. @@ -1353,23 +1334,20 @@ var Container = new Class({ * @readonly * @since 3.4.0 */ - last: { - get: function () + get last() + { + if (this.list.length > 0) { - if (this.list.length > 0) - { - this.position = this.list.length - 1; + this.position = this.list.length - 1; - return this.list[this.position]; - } - else - { - return null; - } + return this.list[this.position]; } - - }, + else + { + return null; + } + } /** * Returns the next Game Object within the Container, or `null` if it is empty. @@ -1381,23 +1359,20 @@ var Container = new Class({ * @readonly * @since 3.4.0 */ - next: { - get: function () + get next() + { + if (this.position < this.list.length) { - if (this.position < this.list.length) - { - this.position++; + this.position++; - return this.list[this.position]; - } - else - { - return null; - } + return this.list[this.position]; } - - }, + else + { + return null; + } + } /** * Returns the previous Game Object within the Container, or `null` if it is empty. @@ -1409,23 +1384,20 @@ var Container = new Class({ * @readonly * @since 3.4.0 */ - previous: { - get: function () + get previous() + { + if (this.position > 0) { - if (this.position > 0) - { - this.position--; + this.position--; - return this.list[this.position]; - } - else - { - return null; - } + return this.list[this.position]; } - - }, + else + { + return null; + } + } /** * Internal destroy handler, called as part of the destroy process. @@ -1434,14 +1406,14 @@ var Container = new Class({ * @protected * @since 3.9.0 */ - preDestroy: function () + preDestroy() { this.removeAll(!!this.exclusive); this.localTransform.destroy(); this.list = []; - }, + } /** * Internal handler, called when a child is destroyed. @@ -1450,7 +1422,7 @@ var Container = new Class({ * @protected * @since 3.80.0 */ - onChildDestroyed: function (gameObject) + onChildDestroyed(gameObject) { ArrayUtils.Remove(this.list, gameObject); @@ -1462,6 +1434,6 @@ var Container = new Class({ } } -}); +}; module.exports = Container; diff --git a/src/gameobjects/domelement/DOMElement.js b/src/gameobjects/domelement/DOMElement.js index 9b11381513..924544e972 100644 --- a/src/gameobjects/domelement/DOMElement.js +++ b/src/gameobjects/domelement/DOMElement.js @@ -100,26 +100,25 @@ var Vector4 = require('../../math/Vector4'); * @param {(string|any)} [style] - If a string, will be set directly as the elements `style` property value. If a plain object, will be iterated and the values transferred. In both cases the values replacing whatever CSS styles may have been previously set. * @param {string} [innerText] - If given, will be set directly as the elements `innerText` property value, replacing whatever was there before. */ -var DOMElement = new Class({ +var DOMElement = class extends GameObject { - Extends: GameObject, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.Depth, - Components.Origin, - Components.ScrollFactor, - Components.Transform, - Components.Visible, - DOMElementRender - ], - - initialize: + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.Depth, + Components.Origin, + Components.ScrollFactor, + Components.Transform, + Components.Visible, + DOMElementRender + ], false); + } - function DOMElement (scene, x, y, element, style, innerText) + constructor(scene, x, y, element, style, innerText) { - GameObject.call(this, scene, 'DOMElement'); + super(scene, 'DOMElement'); /** * A reference to the parent DOM Container that the Game instance created when it started. @@ -315,7 +314,7 @@ var DOMElement = new Class({ scene.sys.events.on(SCENE_EVENTS.SLEEP, this.handleSceneEvent, this); scene.sys.events.on(SCENE_EVENTS.WAKE, this.handleSceneEvent, this); scene.sys.events.on(SCENE_EVENTS.PRE_RENDER, this.preRender, this); - }, + } /** * Handles a Scene Sleep and Wake event. @@ -326,7 +325,7 @@ var DOMElement = new Class({ * * @param {Phaser.Scenes.Systems} sys - The Scene Systems. */ - handleSceneEvent: function (sys) + handleSceneEvent(sys) { var node = this.node; var style = node.style; @@ -335,7 +334,7 @@ var DOMElement = new Class({ { style.display = (sys.settings.visible) ? 'block' : 'none'; } - }, + } /** * Sets the horizontal and vertical skew values of this DOM Element. @@ -350,7 +349,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - setSkew: function (x, y) + setSkew(x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = x; } @@ -359,7 +358,7 @@ var DOMElement = new Class({ this.skewY = y; return this; - }, + } /** * Sets the perspective CSS property of the _parent DOM Container_. This determines the distance between the z=0 @@ -378,12 +377,12 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - setPerspective: function (value) + setPerspective(value) { this.parent.style.perspective = value + 'px'; return this; - }, + } /** * The perspective CSS property value of the _parent DOM Container_. This determines the distance between the z=0 @@ -399,19 +398,16 @@ var DOMElement = new Class({ * @type {number} * @since 3.17.0 */ - perspective: { - get: function () - { - return parseFloat(this.parent.style.perspective); - }, - - set: function (value) - { - this.parent.style.perspective = value + 'px'; - } + get perspective() + { + return parseFloat(this.parent.style.perspective); + } - }, + set perspective(value) + { + this.parent.style.perspective = value + 'px'; + } /** * Adds one or more native DOM event listeners onto the underlying Element of this Game Object. @@ -434,7 +430,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - addListener: function (events) + addListener(events) { if (this.node) { @@ -447,7 +443,7 @@ var DOMElement = new Class({ } return this; - }, + } /** * Removes one or more native DOM event listeners from the underlying Element of this Game Object. @@ -459,7 +455,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - removeListener: function (events) + removeListener(events) { if (this.node) { @@ -472,7 +468,7 @@ var DOMElement = new Class({ } return this; - }, + } /** * Internal event proxy to dispatch native DOM Events via this Game Object. @@ -483,10 +479,10 @@ var DOMElement = new Class({ * * @param {any} event - The native DOM event. */ - dispatchNativeEvent: function (event) + dispatchNativeEvent(event) { this.emit(event.type, event); - }, + } /** * Creates a native DOM Element, adds it to the parent DOM Container and then binds it to this Game Object, @@ -530,10 +526,10 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - createElement: function (tagName, style, innerText) + createElement(tagName, style, innerText) { return this.setElement(document.createElement(tagName), style, innerText); - }, + } /** * Binds a new DOM Element to this Game Object. If this Game Object already has an Element it is removed from the DOM @@ -586,7 +582,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - setElement: function (element, style, innerText) + setElement(element, style, innerText) { // Already got an element? Remove it first this.removeElement(); @@ -648,7 +644,7 @@ var DOMElement = new Class({ } return this.updateSize(); - }, + } /** * Takes a block of html from the HTML Cache, that has previously been preloaded into the game, and then @@ -688,7 +684,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - createFromCache: function (key, tagName) + createFromCache(key, tagName) { var html = this.cache.get(key); @@ -698,7 +694,7 @@ var DOMElement = new Class({ } return this; - }, + } /** * Takes a string of html and then creates a DOM Element from it. The HTML is set as the `innerHTML` @@ -731,7 +727,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - createFromHTML: function (html, tagName) + createFromHTML(html, tagName) { if (tagName === undefined) { tagName = 'div'; } @@ -755,7 +751,7 @@ var DOMElement = new Class({ element.innerHTML = html; return this.updateSize(); - }, + } /** * Removes the current DOM Element bound to this Game Object from the DOM entirely and resets the @@ -766,7 +762,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - removeElement: function () + removeElement() { if (this.node) { @@ -776,7 +772,7 @@ var DOMElement = new Class({ } return this; - }, + } /** * Internal method that sets the `displayWidth` and `displayHeight` properties, and the `clientWidth` @@ -789,7 +785,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - updateSize: function () + updateSize() { var node = this.node; @@ -800,7 +796,7 @@ var DOMElement = new Class({ this.displayHeight = this.height * this.scaleY; return this; - }, + } /** * Gets all children from this DOM Elements node, using `querySelectorAll('*')` and then iterates through @@ -815,7 +811,7 @@ var DOMElement = new Class({ * * @return {?Element} The first matching child DOM Element, or `null` if not found. */ - getChildByProperty: function (property, value) + getChildByProperty(property, value) { if (this.node) { @@ -831,7 +827,7 @@ var DOMElement = new Class({ } return null; - }, + } /** * Gets all children from this DOM Elements node, using `querySelectorAll('*')` and then iterates through @@ -846,10 +842,10 @@ var DOMElement = new Class({ * * @return {?Element} The first matching child DOM Element, or `null` if not found. */ - getChildByID: function (id) + getChildByID(id) { return this.getChildByProperty('id', id); - }, + } /** * Gets all children from this DOM Elements node, using `querySelectorAll('*')` and then iterates through @@ -864,10 +860,10 @@ var DOMElement = new Class({ * * @return {?Element} The first matching child DOM Element, or `null` if not found. */ - getChildByName: function (name) + getChildByName(name) { return this.getChildByProperty('name', name); - }, + } /** * Sets the `className` property of the DOM Element node and updates the internal sizes. @@ -879,7 +875,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - setClassName: function (className) + setClassName(className) { if (this.node) { @@ -889,7 +885,7 @@ var DOMElement = new Class({ } return this; - }, + } /** * Sets the `innerText` property of the DOM Element node and updates the internal sizes. @@ -903,7 +899,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - setText: function (text) + setText(text) { if (this.node) { @@ -913,7 +909,7 @@ var DOMElement = new Class({ } return this; - }, + } /** * Sets the `innerHTML` property of the DOM Element node and updates the internal sizes. @@ -925,7 +921,7 @@ var DOMElement = new Class({ * * @return {this} This DOM Element instance. */ - setHTML: function (html) + setHTML(html) { if (this.node) { @@ -935,7 +931,7 @@ var DOMElement = new Class({ } return this; - }, + } /** * Runs internal update tasks. @@ -944,7 +940,7 @@ var DOMElement = new Class({ * @private * @since 3.60.0 */ - preRender: function () + preRender() { var parent = this.parentContainer; var node = this.node; @@ -953,7 +949,7 @@ var DOMElement = new Class({ { node.style.display = 'none'; } - }, + } /** * Compares the renderMask with the renderFlags to see if this Game Object will render or not. @@ -965,10 +961,10 @@ var DOMElement = new Class({ * * @return {boolean} `true` if the Game Object should be rendered, otherwise `false`. */ - willRender: function () + willRender() { return true; - }, + } /** * Handles the pre-destroy step for the DOM Element, which removes the underlying node from the DOM. @@ -977,7 +973,7 @@ var DOMElement = new Class({ * @private * @since 3.17.0 */ - preDestroy: function () + preDestroy() { this.removeElement(); @@ -986,6 +982,6 @@ var DOMElement = new Class({ this.scene.sys.events.off(SCENE_EVENTS.PRE_RENDER, this.preRender, this); } -}); +}; module.exports = DOMElement; diff --git a/src/gameobjects/extern/Extern.js b/src/gameobjects/extern/Extern.js index 522099f9dd..5535dac79e 100644 --- a/src/gameobjects/extern/Extern.js +++ b/src/gameobjects/extern/Extern.js @@ -75,56 +75,55 @@ var ExternRender = require('./ExternRender'); * * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. */ -var Extern = new Class({ +var Extern = class extends GameObject { - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.Depth, - Components.Flip, - Components.Origin, - Components.ScrollFactor, - Components.Size, - Components.Texture, - Components.Tint, - Components.Transform, - Components.Visible, - ExternRender - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.Depth, + Components.Flip, + Components.Origin, + Components.ScrollFactor, + Components.Size, + Components.Texture, + Components.Tint, + Components.Transform, + Components.Visible, + ExternRender + ], false); + } - function Extern (scene) + constructor(scene) { - GameObject.call(this, scene, 'Extern'); - }, + super(scene, 'Extern'); + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } - preUpdate: function () + preUpdate() { // override this! // Arguments: time, delta - }, + } - render: function () + render() { // override this! // Arguments: renderer, drawingContext, calcMatrix, displayList, displayListIndex } -}); +}; module.exports = Extern; diff --git a/src/gameobjects/graphics/Graphics.js b/src/gameobjects/graphics/Graphics.js index 8fe8e85b82..6d9a8ffc8a 100644 --- a/src/gameobjects/graphics/Graphics.js +++ b/src/gameobjects/graphics/Graphics.js @@ -81,31 +81,30 @@ var Render = require('./GraphicsRender'); * @param {Phaser.Scene} scene - The Scene to which this Graphics object belongs. * @param {Phaser.Types.GameObjects.Graphics.Options} [options] - Options that set the position and default style of this Graphics object. */ -var Graphics = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.Depth, - Components.Lighting, - Components.Mask, - Components.RenderNodes, - Components.Transform, - Components.Visible, - Components.ScrollFactor, - Render - ], - - initialize: - - function Graphics (scene, options) +var Graphics = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.Depth, + Components.Lighting, + Components.Mask, + Components.RenderNodes, + Components.Transform, + Components.Visible, + Components.ScrollFactor, + Render + ], false); + } + + constructor(scene, options) { var x = GetValue(options, 'x', 0); var y = GetValue(options, 'y', 0); - GameObject.call(this, scene, 'Graphics'); + super(scene, 'Graphics'); this.setPosition(x, y); this.initRenderNodes(this._defaultRenderNodesMap); @@ -235,7 +234,7 @@ var Graphics = new Class({ this.fillStyle(0, 0); this.setDefaultStyles(options); - }, + } /** * The default render nodes for this Game Object. @@ -247,12 +246,11 @@ var Graphics = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultGraphicsNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultGraphicsNodes; + } /** * Set the default style settings for this Graphics object. @@ -264,7 +262,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - setDefaultStyles: function (options) + setDefaultStyles(options) { if (GetValue(options, 'lineStyle', null)) { @@ -284,7 +282,7 @@ var Graphics = new Class({ } return this; - }, + } /** * Set the current line style. Used for all 'stroke' related functions. @@ -298,7 +296,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - lineStyle: function (lineWidth, color, alpha) + lineStyle(lineWidth, color, alpha) { if (alpha === undefined) { alpha = 1; } @@ -310,7 +308,7 @@ var Graphics = new Class({ this._lineWidth = lineWidth; return this; - }, + } /** * Set the current fill style. Used for all 'fill' related functions. @@ -323,7 +321,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillStyle: function (color, alpha) + fillStyle(color, alpha) { if (alpha === undefined) { alpha = 1; } @@ -333,7 +331,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Sets a gradient fill style. This is a WebGL only feature. @@ -365,7 +363,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillGradientStyle: function (topLeft, topRight, bottomLeft, bottomRight, alphaTopLeft, alphaTopRight, alphaBottomLeft, alphaBottomRight) + fillGradientStyle(topLeft, topRight, bottomLeft, bottomRight, alphaTopLeft, alphaTopRight, alphaBottomLeft, alphaBottomRight) { if (alphaTopLeft === undefined) { alphaTopLeft = 1; } if (alphaTopRight === undefined) { alphaTopRight = alphaTopLeft; } @@ -379,7 +377,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Sets a gradient line style. This is a WebGL only feature. @@ -407,7 +405,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - lineGradientStyle: function (lineWidth, topLeft, topRight, bottomLeft, bottomRight, alpha) + lineGradientStyle(lineWidth, topLeft, topRight, bottomLeft, bottomRight, alpha) { if (alpha === undefined) { alpha = 1; } @@ -417,7 +415,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Start a new shape path. @@ -427,14 +425,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - beginPath: function () + beginPath() { this.commandBuffer.push( Commands.BEGIN_PATH ); return this; - }, + } /** * Close the current path. @@ -444,14 +442,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - closePath: function () + closePath() { this.commandBuffer.push( Commands.CLOSE_PATH ); return this; - }, + } /** * Fill the current path. @@ -461,14 +459,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillPath: function () + fillPath() { this.commandBuffer.push( Commands.FILL_PATH ); return this; - }, + } /** * Fill the current path. @@ -481,14 +479,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fill: function () + fill() { this.commandBuffer.push( Commands.FILL_PATH ); return this; - }, + } /** * Stroke the current path. @@ -498,14 +496,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokePath: function () + strokePath() { this.commandBuffer.push( Commands.STROKE_PATH ); return this; - }, + } /** * Stroke the current path. @@ -518,14 +516,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - stroke: function () + stroke() { this.commandBuffer.push( Commands.STROKE_PATH ); return this; - }, + } /** * Fill the given circle. @@ -537,10 +535,10 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillCircleShape: function (circle) + fillCircleShape(circle) { return this.fillCircle(circle.x, circle.y, circle.radius); - }, + } /** * Stroke the given circle. @@ -552,10 +550,10 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeCircleShape: function (circle) + strokeCircleShape(circle) { return this.strokeCircle(circle.x, circle.y, circle.radius); - }, + } /** * Fill a circle with the given position and radius. @@ -569,14 +567,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillCircle: function (x, y, radius) + fillCircle(x, y, radius) { this.beginPath(); this.arc(x, y, radius, 0, MATH_CONST.TAU); this.fillPath(); return this; - }, + } /** * Stroke a circle with the given position and radius. @@ -590,14 +588,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeCircle: function (x, y, radius) + strokeCircle(x, y, radius) { this.beginPath(); this.arc(x, y, radius, 0, MATH_CONST.TAU); this.strokePath(); return this; - }, + } /** * Fill the given rectangle. @@ -609,10 +607,10 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillRectShape: function (rect) + fillRectShape(rect) { return this.fillRect(rect.x, rect.y, rect.width, rect.height); - }, + } /** * Stroke the given rectangle. @@ -624,10 +622,10 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeRectShape: function (rect) + strokeRectShape(rect) { return this.strokeRect(rect.x, rect.y, rect.width, rect.height); - }, + } /** * Fill a rectangle with the given position and size. @@ -642,7 +640,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillRect: function (x, y, width, height) + fillRect(x, y, width, height) { this.commandBuffer.push( Commands.FILL_RECT, @@ -650,7 +648,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Stroke a rectangle with the given position and size. @@ -665,7 +663,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeRect: function (x, y, width, height) + strokeRect(x, y, width, height) { var lineWidthHalf = this._lineWidth / 2; var minx = x - lineWidthHalf; @@ -692,7 +690,7 @@ var Graphics = new Class({ this.strokePath(); return this; - }, + } /** * Fill a rounded rectangle with the given position, size and radius. @@ -708,7 +706,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillRoundedRect: function (x, y, width, height, radius) + fillRoundedRect(x, y, width, height, radius) { if (radius === undefined) { radius = 20; } @@ -784,7 +782,7 @@ var Graphics = new Class({ this.fillPath(); return this; - }, + } /** * Stroke a rounded rectangle with the given position, size and radius. @@ -800,7 +798,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeRoundedRect: function (x, y, width, height, radius) + strokeRoundedRect(x, y, width, height, radius) { if (radius === undefined) { radius = 20; } @@ -882,7 +880,7 @@ var Graphics = new Class({ this.strokePath(); return this; - }, + } /** * Fill the given point. @@ -897,10 +895,10 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillPointShape: function (point, size) + fillPointShape(point, size) { return this.fillPoint(point.x, point.y, size); - }, + } /** * Fill a point at the given position. @@ -916,7 +914,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillPoint: function (x, y, size) + fillPoint(x, y, size) { if (!size || size < 1) { @@ -934,7 +932,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Fill the given triangle. @@ -946,10 +944,10 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillTriangleShape: function (triangle) + fillTriangleShape(triangle) { return this.fillTriangle(triangle.x1, triangle.y1, triangle.x2, triangle.y2, triangle.x3, triangle.y3); - }, + } /** * Stroke the given triangle. @@ -961,10 +959,10 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeTriangleShape: function (triangle) + strokeTriangleShape(triangle) { return this.strokeTriangle(triangle.x1, triangle.y1, triangle.x2, triangle.y2, triangle.x3, triangle.y3); - }, + } /** * Fill a triangle with the given points. @@ -981,7 +979,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillTriangle: function (x0, y0, x1, y1, x2, y2) + fillTriangle(x0, y0, x1, y1, x2, y2) { this.commandBuffer.push( Commands.FILL_TRIANGLE, @@ -989,7 +987,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Stroke a triangle with the given points. @@ -1006,7 +1004,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeTriangle: function (x0, y0, x1, y1, x2, y2) + strokeTriangle(x0, y0, x1, y1, x2, y2) { this.commandBuffer.push( Commands.STROKE_TRIANGLE, @@ -1014,7 +1012,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Draw the given line. @@ -1026,10 +1024,10 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeLineShape: function (line) + strokeLineShape(line) { return this.lineBetween(line.x1, line.y1, line.x2, line.y2); - }, + } /** * Draw a line between the given points. @@ -1044,7 +1042,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - lineBetween: function (x1, y1, x2, y2) + lineBetween(x1, y1, x2, y2) { this.beginPath(); this.moveTo(x1, y1); @@ -1052,7 +1050,7 @@ var Graphics = new Class({ this.strokePath(); return this; - }, + } /** * Draw a line from the current drawing position to the given position. @@ -1067,7 +1065,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - lineTo: function (x, y) + lineTo(x, y) { this.commandBuffer.push( Commands.LINE_TO, @@ -1075,7 +1073,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Move the current drawing position to the given position. @@ -1088,7 +1086,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - moveTo: function (x, y) + moveTo(x, y) { this.commandBuffer.push( Commands.MOVE_TO, @@ -1096,7 +1094,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Stroke the shape represented by the given array of points. @@ -1115,7 +1113,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokePoints: function (points, closeShape, closePath, endIndex) + strokePoints(points, closeShape, closePath, endIndex) { if (closeShape === undefined) { closeShape = false; } if (closePath === undefined) { closePath = false; } @@ -1143,7 +1141,7 @@ var Graphics = new Class({ this.strokePath(); return this; - }, + } /** * Fill the shape represented by the given array of points. @@ -1162,7 +1160,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillPoints: function (points, closeShape, closePath, endIndex) + fillPoints(points, closeShape, closePath, endIndex) { if (closeShape === undefined) { closeShape = false; } if (closePath === undefined) { closePath = false; } @@ -1190,7 +1188,7 @@ var Graphics = new Class({ this.fillPath(); return this; - }, + } /** * Stroke the given ellipse. @@ -1203,14 +1201,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeEllipseShape: function (ellipse, smoothness) + strokeEllipseShape(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. @@ -1226,7 +1224,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - strokeEllipse: function (x, y, width, height, smoothness) + strokeEllipse(x, y, width, height, smoothness) { if (smoothness === undefined) { smoothness = 32; } @@ -1235,7 +1233,7 @@ var Graphics = new Class({ var points = ellipse.getPoints(smoothness); return this.strokePoints(points, true); - }, + } /** * Fill the given ellipse. @@ -1248,14 +1246,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillEllipseShape: function (ellipse, smoothness) + fillEllipseShape(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. @@ -1271,7 +1269,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - fillEllipse: function (x, y, width, height, smoothness) + fillEllipse(x, y, width, height, smoothness) { if (smoothness === undefined) { smoothness = 32; } @@ -1280,7 +1278,7 @@ var Graphics = new Class({ var points = ellipse.getPoints(smoothness); return this.fillPoints(points, true); - }, + } /** * Draw an arc. @@ -1310,7 +1308,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - arc: function (x, y, radius, startAngle, endAngle, anticlockwise, overshoot) + arc(x, y, radius, startAngle, endAngle, anticlockwise, overshoot) { if (anticlockwise === undefined) { anticlockwise = false; } if (overshoot === undefined) { overshoot = 0; } @@ -1321,7 +1319,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Creates a pie-chart slice shape centered at `x`, `y` with the given radius. @@ -1346,7 +1344,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - slice: function (x, y, radius, startAngle, endAngle, anticlockwise, overshoot) + slice(x, y, radius, startAngle, endAngle, anticlockwise, overshoot) { if (anticlockwise === undefined) { anticlockwise = false; } if (overshoot === undefined) { overshoot = 0; } @@ -1360,7 +1358,7 @@ var Graphics = new Class({ this.commandBuffer.push(Commands.CLOSE_PATH); return this; - }, + } /** * Saves the state of the Graphics by pushing the current state onto a stack. @@ -1372,14 +1370,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - save: function () + save() { this.commandBuffer.push( Commands.SAVE ); return this; - }, + } /** * Restores the most recently saved state of the Graphics by popping from the state stack. @@ -1393,14 +1391,14 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - restore: function () + restore() { this.commandBuffer.push( Commands.RESTORE ); return this; - }, + } /** * Inserts a translation command into this Graphics objects command buffer. @@ -1419,7 +1417,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - translateCanvas: function (x, y) + translateCanvas(x, y) { this.commandBuffer.push( Commands.TRANSLATE, @@ -1427,7 +1425,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Inserts a scale command into this Graphics objects command buffer. @@ -1446,7 +1444,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - scaleCanvas: function (x, y) + scaleCanvas(x, y) { this.commandBuffer.push( Commands.SCALE, @@ -1454,7 +1452,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Inserts a rotation command into this Graphics objects command buffer. @@ -1472,7 +1470,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - rotateCanvas: function (radians) + rotateCanvas(radians) { this.commandBuffer.push( Commands.ROTATE, @@ -1480,7 +1478,7 @@ var Graphics = new Class({ ); return this; - }, + } /** * Clear the command buffer and reset the fill style and line style to their defaults. @@ -1490,7 +1488,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - clear: function () + clear() { this.commandBuffer.length = 0; @@ -1505,7 +1503,7 @@ var Graphics = new Class({ } return this; - }, + } /** * Generate a texture from this Graphics object. @@ -1529,7 +1527,7 @@ var Graphics = new Class({ * * @return {this} This Game Object. */ - generateTexture: function (key, width, height) + generateTexture(key, width, height) { var sys = this.scene.sys; var renderer = sys.game.renderer; @@ -1589,7 +1587,7 @@ var Graphics = new Class({ } return this; - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -1598,12 +1596,12 @@ var Graphics = new Class({ * @protected * @since 3.9.0 */ - preDestroy: function () + preDestroy() { this.commandBuffer = []; } -}); +}; /** * A Camera used specifically by the Graphics system for rendering to textures. diff --git a/src/gameobjects/group/Group.js b/src/gameobjects/group/Group.js index aaa4cdcf34..8e5bad14c8 100644 --- a/src/gameobjects/group/Group.js +++ b/src/gameobjects/group/Group.js @@ -36,15 +36,11 @@ var Sprite = require('../sprite/Sprite'); * @see Phaser.Physics.Arcade.Group * @see Phaser.Physics.Arcade.StaticGroup */ -var Group = new Class({ +var Group = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function Group (scene, children, config) + constructor(scene, children, config) { - EventEmitter.call(this); + super(); // They can pass in any of the following as the first argument: @@ -255,19 +251,19 @@ var Group = new Class({ this.on(Events.ADDED_TO_SCENE, this.addedToScene, this); this.on(Events.REMOVED_FROM_SCENE, this.removedFromScene, this); - }, + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } /** * Creates a new Game Object and adds it to this group, unless the group {@link Phaser.GameObjects.Group#isFull is full}. @@ -286,7 +282,7 @@ var Group = new Class({ * * @return {any} The new Game Object (usually a Sprite, etc.). */ - create: function (x, y, key, frame, visible, active) + create(x, y, key, frame, visible, active) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -312,7 +308,7 @@ var Group = new Class({ this.add(child); return child; - }, + } /** * Creates several Game Objects and adds them to this group. @@ -328,7 +324,7 @@ var Group = new Class({ * * @return {any[]} The newly created Game Objects. */ - createMultiple: function (config) + createMultiple(config) { if (this.isFull()) { @@ -353,7 +349,7 @@ var Group = new Class({ } return output; - }, + } /** * A helper for {@link Phaser.GameObjects.Group#createMultiple}. @@ -365,7 +361,7 @@ var Group = new Class({ * * @return {any[]} The newly created Game Objects. */ - createFromConfig: function (options) + createFromConfig(options) { if (this.isFull()) { @@ -539,7 +535,7 @@ var Group = new Class({ } return entries; - }, + } /** * Updates any group members, if {@link Phaser.GameObjects.Group#runChildUpdate} is enabled. @@ -550,7 +546,7 @@ var Group = new Class({ * @param {number} time - The current timestamp. * @param {number} delta - The delta time elapsed since the last frame. */ - preUpdate: function (time, delta) + preUpdate(time, delta) { if (!this.runChildUpdate || this.children.size === 0) { @@ -564,7 +560,7 @@ var Group = new Class({ child.update(time, delta); } }); - }, + } /** * Adds a Game Object to this group. @@ -579,7 +575,7 @@ var Group = new Class({ * * @return {this} This Group object. */ - add: function (child, addToScene) + add(child, addToScene) { if (addToScene === undefined) { addToScene = false; } @@ -609,7 +605,7 @@ var Group = new Class({ child.on(Events.DESTROY, this.remove, this); return this; - }, + } /** * Adds several Game Objects to this group. @@ -624,7 +620,7 @@ var Group = new Class({ * * @return {this} This group. */ - addMultiple: function (children, addToScene) + addMultiple(children, addToScene) { if (addToScene === undefined) { addToScene = false; } @@ -637,7 +633,7 @@ var Group = new Class({ } return this; - }, + } /** * Removes a member of this Group and optionally removes it from the Scene and / or destroys it. @@ -653,7 +649,7 @@ var Group = new Class({ * * @return {this} This Group object. */ - remove: function (child, removeFromScene, destroyChild) + remove(child, removeFromScene, destroyChild) { if (removeFromScene === undefined) { removeFromScene = false; } if (destroyChild === undefined) { destroyChild = false; } @@ -688,7 +684,7 @@ var Group = new Class({ } return this; - }, + } /** * Removes all members of this Group and optionally removes them from the Scene and / or destroys them. @@ -703,7 +699,7 @@ var Group = new Class({ * * @return {this} This group. */ - clear: function (removeFromScene, destroyChild) + clear(removeFromScene, destroyChild) { if (removeFromScene === undefined) { removeFromScene = false; } if (destroyChild === undefined) { destroyChild = false; } @@ -728,7 +724,7 @@ var Group = new Class({ children.clear(); return this; - }, + } /** * Tests if a Game Object is a member of this group. @@ -740,10 +736,10 @@ var Group = new Class({ * * @return {boolean} True if the Game Object is a member of this group. */ - contains: function (child) + contains(child) { return this.children.has(child); - }, + } /** * All members of the group. @@ -753,10 +749,10 @@ var Group = new Class({ * * @return {Phaser.GameObjects.GameObject[]} The group members. */ - getChildren: function () + getChildren() { return Array.from(this.children); - }, + } /** * The number of members of the group. @@ -766,10 +762,10 @@ var Group = new Class({ * * @return {number} */ - getLength: function () + getLength() { return this.children.size; - }, + } /** * Returns all children in this Group that match the given criteria based on the `property` and `value` arguments. @@ -790,10 +786,10 @@ var Group = new Class({ * * @return {any[]} An array of matching Group members. The array will be empty if nothing matched. */ - getMatching: function (property, value, startIndex, endIndex) + getMatching(property, value, startIndex, endIndex) { return GetAll(Array.from(this.children), property, value, startIndex, endIndex); - }, + } /** * Scans the Group, from top to bottom, for the first member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -815,10 +811,10 @@ var Group = new Class({ * * @return {?any} The first matching group member, or a newly created member, or null. */ - getFirst: function (state, createIfNull, x, y, key, frame, visible) + getFirst(state, createIfNull, x, y, key, frame, visible) { return this.getHandler(true, 1, state, createIfNull, x, y, key, frame, visible); - }, + } /** * Scans the Group, from top to bottom, for the nth member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -841,10 +837,10 @@ var Group = new Class({ * * @return {?any} The first matching group member, or a newly created member, or null. */ - getFirstNth: function (nth, state, createIfNull, x, y, key, frame, visible) + getFirstNth(nth, state, createIfNull, x, y, key, frame, visible) { return this.getHandler(true, nth, state, createIfNull, x, y, key, frame, visible); - }, + } /** * Scans the Group for the last member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -866,10 +862,10 @@ var Group = new Class({ * * @return {?any} The first matching group member, or a newly created member, or null. */ - getLast: function (state, createIfNull, x, y, key, frame, visible) + getLast(state, createIfNull, x, y, key, frame, visible) { return this.getHandler(false, 1, state, createIfNull, x, y, key, frame, visible); - }, + } /** * Scans the Group for the last nth member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -892,10 +888,10 @@ var Group = new Class({ * * @return {?any} The first matching group member, or a newly created member, or null. */ - getLastNth: function (nth, state, createIfNull, x, y, key, frame, visible) + getLastNth(nth, state, createIfNull, x, y, key, frame, visible) { return this.getHandler(false, nth, state, createIfNull, x, y, key, frame, visible); - }, + } /** * Scans the group for the last member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -920,7 +916,7 @@ var Group = new Class({ * * @return {?any} The first matching group member, or a newly created member, or null. */ - getHandler: function (forwards, nth, state, createIfNull, x, y, key, frame, visible) + getHandler(forwards, nth, state, createIfNull, x, y, key, frame, visible) { if (state === undefined) { state = false; } if (createIfNull === undefined) { createIfNull = false; } @@ -998,7 +994,7 @@ var Group = new Class({ { return null; } - }, + } /** * Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `false`, @@ -1019,10 +1015,10 @@ var Group = new Class({ * * @return {?any} The first inactive group member, or a newly created member, or null. */ - get: function (x, y, key, frame, visible) + get(x, y, key, frame, visible) { return this.getFirst(false, true, x, y, key, frame, visible); - }, + } /** * Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `true`, @@ -1043,10 +1039,10 @@ var Group = new Class({ * * @return {any} The first active group member, or a newly created member, or null. */ - getFirstAlive: function (createIfNull, x, y, key, frame, visible) + getFirstAlive(createIfNull, x, y, key, frame, visible) { return this.getFirst(true, createIfNull, x, y, key, frame, visible); - }, + } /** * Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `false`, @@ -1068,10 +1064,10 @@ var Group = new Class({ * * @return {any} The first inactive group member, or a newly created member, or null. */ - getFirstDead: function (createIfNull, x, y, key, frame, visible) + getFirstDead(createIfNull, x, y, key, frame, visible) { return this.getFirst(false, createIfNull, x, y, key, frame, visible); - }, + } /** * {@link Phaser.Animations.AnimationState#play Plays} an animation for all members of this group. @@ -1084,12 +1080,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - playAnimation: function (key, startFrame) + playAnimation(key, startFrame) { Actions.PlayAnimation(Array.from(this.children), key, startFrame); return this; - }, + } /** * Whether this group's size at its {@link Phaser.GameObjects.Group#maxSize maximum}. @@ -1099,7 +1095,7 @@ var Group = new Class({ * * @return {boolean} True if the number of members equals {@link Phaser.GameObjects.Group#maxSize}. */ - isFull: function () + isFull() { if (this.maxSize === -1) { @@ -1109,7 +1105,7 @@ var Group = new Class({ { return (this.children.size >= this.maxSize); } - }, + } /** * Counts the number of active (or inactive) group members. @@ -1121,7 +1117,7 @@ var Group = new Class({ * * @return {number} The number of group members with an active state matching the `active` argument. */ - countActive: function (value) + countActive(value) { if (value === undefined) { value = true; } @@ -1136,7 +1132,7 @@ var Group = new Class({ }); return total; - }, + } /** * Counts the number of in-use (active) group members. @@ -1146,10 +1142,10 @@ var Group = new Class({ * * @return {number} The number of group members with an active state of true. */ - getTotalUsed: function () + getTotalUsed() { return this.countActive(); - }, + } /** * The difference of {@link Phaser.GameObjects.Group#maxSize} and the number of active group members. @@ -1161,13 +1157,13 @@ var Group = new Class({ * * @return {number} maxSize minus the number of active group numbers; or a large number (if maxSize is -1). */ - getTotalFree: function () + getTotalFree() { var used = this.getTotalUsed(); var capacity = (this.maxSize === -1) ? 999999999999 : this.maxSize; return (capacity - used); - }, + } /** * Sets the `active` property of this Group. @@ -1180,12 +1176,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setActive: function (value) + setActive(value) { this.active = value; return this; - }, + } /** * Sets the `name` property of this Group. @@ -1198,12 +1194,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setName: function (value) + setName(value) { this.name = value; return this; - }, + } /** * Sets the property as defined in `key` of each group member to the given value. @@ -1219,12 +1215,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - propertyValueSet: function (key, value, step, index, direction) + propertyValueSet(key, value, step, index, direction) { Actions.PropertyValueSet(Array.from(this.children), key, value, step, index, direction); return this; - }, + } /** * Adds the given value to the property as defined in `key` of each group member. @@ -1240,12 +1236,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - propertyValueInc: function (key, value, step, index, direction) + propertyValueInc(key, value, step, index, direction) { Actions.PropertyValueInc(Array.from(this.children), key, value, step, index, direction); return this; - }, + } /** * Sets the x of each group member. @@ -1258,12 +1254,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setX: function (value, step) + setX(value, step) { Actions.SetX(Array.from(this.children), value, step); return this; - }, + } /** * Sets the y of each group member. @@ -1276,12 +1272,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setY: function (value, step) + setY(value, step) { Actions.SetY(Array.from(this.children), value, step); return this; - }, + } /** * Sets the x, y of each group member. @@ -1296,12 +1292,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setXY: function (x, y, stepX, stepY) + setXY(x, y, stepX, stepY) { Actions.SetXY(Array.from(this.children), x, y, stepX, stepY); return this; - }, + } /** * Adds the given value to the x of each group member. @@ -1314,12 +1310,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - incX: function (value, step) + incX(value, step) { Actions.IncX(Array.from(this.children), value, step); return this; - }, + } /** * Adds the given value to the y of each group member. @@ -1332,12 +1328,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - incY: function (value, step) + incY(value, step) { Actions.IncY(Array.from(this.children), value, step); return this; - }, + } /** * Adds the given value to the x, y of each group member. @@ -1352,12 +1348,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - incXY: function (x, y, stepX, stepY) + incXY(x, y, stepX, stepY) { Actions.IncXY(Array.from(this.children), x, y, stepX, stepY); return this; - }, + } /** * Iterate through the group members changing the position of each element to be that of the element that came before @@ -1374,12 +1370,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - shiftPosition: function (x, y, direction) + shiftPosition(x, y, direction) { Actions.ShiftPosition(Array.from(this.children), x, y, direction); return this; - }, + } /** * Sets the angle of each group member. @@ -1392,12 +1388,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - angle: function (value, step) + angle(value, step) { Actions.Angle(Array.from(this.children), value, step); return this; - }, + } /** * Sets the rotation of each group member. @@ -1410,12 +1406,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - rotate: function (value, step) + rotate(value, step) { Actions.Rotate(Array.from(this.children), value, step); return this; - }, + } /** * Rotates each group member around the given point by the given angle. @@ -1428,12 +1424,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - rotateAround: function (point, angle) + rotateAround(point, angle) { Actions.RotateAround(Array.from(this.children), point, angle); return this; - }, + } /** * Rotates each group member around the given point by the given angle and distance. @@ -1447,12 +1443,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - rotateAroundDistance: function (point, angle, distance) + rotateAroundDistance(point, angle, distance) { Actions.RotateAroundDistance(Array.from(this.children), point, angle, distance); return this; - }, + } /** * Sets the alpha of each group member. @@ -1465,12 +1461,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setAlpha: function (value, step) + setAlpha(value, step) { Actions.SetAlpha(Array.from(this.children), value, step); return this; - }, + } /** * Sets the tint of each group member. @@ -1485,12 +1481,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setTint: function (topLeft, topRight, bottomLeft, bottomRight) + setTint(topLeft, topRight, bottomLeft, bottomRight) { Actions.SetTint(Array.from(this.children), topLeft, topRight, bottomLeft, bottomRight); return this; - }, + } /** * Sets the originX, originY of each group member. @@ -1505,12 +1501,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setOrigin: function (originX, originY, stepX, stepY) + setOrigin(originX, originY, stepX, stepY) { Actions.SetOrigin(Array.from(this.children), originX, originY, stepX, stepY); return this; - }, + } /** * Sets the scaleX of each group member. @@ -1523,12 +1519,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - scaleX: function (value, step) + scaleX(value, step) { Actions.ScaleX(Array.from(this.children), value, step); return this; - }, + } /** * Sets the scaleY of each group member. @@ -1541,12 +1537,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - scaleY: function (value, step) + scaleY(value, step) { Actions.ScaleY(Array.from(this.children), value, step); return this; - }, + } /** * Sets the scaleX, scaleY of each group member. @@ -1561,12 +1557,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - scaleXY: function (scaleX, scaleY, stepX, stepY) + scaleXY(scaleX, scaleY, stepX, stepY) { Actions.ScaleXY(Array.from(this.children), scaleX, scaleY, stepX, stepY); return this; - }, + } /** * Sets the depth of each group member. @@ -1579,12 +1575,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setDepth: function (value, step) + setDepth(value, step) { Actions.SetDepth(Array.from(this.children), value, step); return this; - }, + } /** * Sets the blendMode of each group member. @@ -1596,12 +1592,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setBlendMode: function (value) + setBlendMode(value) { Actions.SetBlendMode(Array.from(this.children), value); return this; - }, + } /** * Passes all group members to the Input Manager to enable them for input with identical areas and callbacks. @@ -1614,12 +1610,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setHitArea: function (hitArea, hitAreaCallback) + setHitArea(hitArea, hitAreaCallback) { Actions.SetHitArea(Array.from(this.children), hitArea, hitAreaCallback); return this; - }, + } /** * Shuffles the group members in place. @@ -1629,12 +1625,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - shuffle: function () + shuffle() { Actions.Shuffle(Array.from(this.children)); return this; - }, + } /** * Deactivates a member of this group. @@ -1644,13 +1640,13 @@ var Group = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - A member of this group. */ - kill: function (gameObject) + kill(gameObject) { if (this.children.has(gameObject)) { gameObject.setActive(false); } - }, + } /** * Deactivates and hides a member of this group. @@ -1660,14 +1656,14 @@ var Group = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - A member of this group. */ - killAndHide: function (gameObject) + killAndHide(gameObject) { if (this.children.has(gameObject)) { gameObject.setActive(false); gameObject.setVisible(false); } - }, + } /** * Sets the visible of each group member. @@ -1681,12 +1677,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - setVisible: function (value, index, direction) + setVisible(value, index, direction) { Actions.SetVisible(Array.from(this.children), value, index, direction); return this; - }, + } /** * Toggles (flips) the visible state of each member of this group. @@ -1696,12 +1692,12 @@ var Group = new Class({ * * @return {this} This Group object. */ - toggleVisible: function () + toggleVisible() { Actions.ToggleVisible(Array.from(this.children)); return this; - }, + } /** * Empties this Group of all children and removes it from the Scene. @@ -1720,7 +1716,7 @@ var Group = new Class({ * @param {boolean} [destroyChildren=false] - Also {@link Phaser.GameObjects.GameObject#destroy} each Group member. * @param {boolean} [removeFromScene=false] - Optionally remove each Group member from the Scene. */ - destroy: function (destroyChildren, removeFromScene) + destroy(destroyChildren, removeFromScene) { if (destroyChildren === undefined) { destroyChildren = false; } if (removeFromScene === undefined) { removeFromScene = false; } @@ -1743,6 +1739,6 @@ var Group = new Class({ this.children = undefined; } -}); +}; module.exports = Group; diff --git a/src/gameobjects/image/Image.js b/src/gameobjects/image/Image.js index ddd8664f96..ae180ac967 100644 --- a/src/gameobjects/image/Image.js +++ b/src/gameobjects/image/Image.js @@ -47,34 +47,33 @@ var ImageRender = require('./ImageRender'); * @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with. */ -var Image = new Class({ +var Image = class extends GameObject { - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.Depth, - Components.Flip, - Components.GetBounds, - Components.Lighting, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.ScrollFactor, - Components.Size, - Components.TextureCrop, - Components.Tint, - Components.Transform, - Components.Visible, - ImageRender - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.Depth, + Components.Flip, + Components.GetBounds, + Components.Lighting, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.ScrollFactor, + Components.Size, + Components.TextureCrop, + Components.Tint, + Components.Transform, + Components.Visible, + ImageRender + ], false); + } - function Image (scene, x, y, texture, frame) + constructor(scene, x, y, texture, frame) { - GameObject.call(this, scene, 'Image'); + super(scene, 'Image'); /** * The internal crop data object, as used by `setCrop` and passed to the `Frame.setCropUVs` method. @@ -91,7 +90,7 @@ var Image = new Class({ this.setSizeToFrame(); this.setOriginFromFrame(); this.initRenderNodes(this._defaultRenderNodesMap); - }, + } /** * The default render nodes for this Game Object. @@ -103,13 +102,12 @@ var Image = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultImageNodes; - } + + get _defaultRenderNodesMap() + { + return DefaultImageNodes; } -}); +}; module.exports = Image; diff --git a/src/gameobjects/layer/Layer.js b/src/gameobjects/layer/Layer.js index 078ca7abd9..d06184cd9c 100644 --- a/src/gameobjects/layer/Layer.js +++ b/src/gameobjects/layer/Layer.js @@ -73,27 +73,26 @@ var StableSort = require('../../utils/array/StableSort'); * @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 {Phaser.GameObjects.GameObject[]} [children] - An optional array of Game Objects to add to this Layer. */ -var Layer = new Class({ +var Layer = class extends List { - Extends: List, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.Depth, - Components.Filters, - Components.Mask, - Components.RenderSteps, // This does not extend GameObject so it must mixin RenderSteps here. - Components.Visible, - EventEmitter, - Render - ], - - initialize: + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.Depth, + Components.Filters, + Components.Mask, + Components.RenderSteps, // This does not extend GameObject so it must mixin RenderSteps here. + Components.Visible, + EventEmitter, + Render + ], false); + } - function Layer (scene, children) + constructor(scene, children) { - List.call(this, scene); + super(scene); EventEmitter.call(this); /** @@ -319,7 +318,7 @@ var Layer = new Class({ // Tell the Scene to re-sort the children scene.sys.queueDepthSort(); - }, + } /** * Sets the `active` property of this Game Object and returns this Game Object for further chaining. @@ -332,12 +331,12 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - setActive: function (value) + setActive(value) { this.active = value; return this; - }, + } /** * Sets the `name` property of this Game Object and returns this Game Object for further chaining. @@ -350,12 +349,12 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - setName: function (value) + setName(value) { this.name = value; return this; - }, + } /** * Sets the current state of this Game Object. @@ -374,12 +373,12 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - setState: function (value) + setState(value) { this.state = value; return this; - }, + } /** * Adds a Data Manager component to this Game Object. @@ -390,7 +389,7 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - setDataEnabled: function () + setDataEnabled() { if (!this.data) { @@ -398,7 +397,7 @@ var Layer = new Class({ } return this; - }, + } /** * Allows you to store a key value pair within this Game Objects Data Manager. @@ -447,7 +446,7 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - setData: function (key, value) + setData(key, value) { if (!this.data) { @@ -457,7 +456,7 @@ var Layer = new Class({ this.data.set(key, value); return this; - }, + } /** * Increase a value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is increased from 0. @@ -477,7 +476,7 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - incData: function (key, value) + incData(key, value) { if (!this.data) { @@ -487,7 +486,7 @@ var Layer = new Class({ this.data.inc(key, value); return this; - }, + } /** * Toggle a boolean value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is toggled from false. @@ -506,7 +505,7 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - toggleData: function (key) + toggleData(key) { if (!this.data) { @@ -516,7 +515,7 @@ var Layer = new Class({ this.data.toggle(key); return this; - }, + } /** * Retrieves the value for the given key in this Game Objects Data Manager, or undefined if it doesn't exist. @@ -548,7 +547,7 @@ var Layer = new Class({ * * @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) + getData(key) { if (!this.data) { @@ -556,7 +555,7 @@ var Layer = new Class({ } return this.data.get(key); - }, + } /** * A Layer cannot be enabled for input. @@ -569,10 +568,10 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - setInteractive: function () + setInteractive() { return this; - }, + } /** * A Layer cannot be enabled for input. @@ -585,10 +584,10 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - disableInteractive: function () + disableInteractive() { return this; - }, + } /** * A Layer cannot be enabled for input. @@ -601,10 +600,10 @@ var Layer = new Class({ * * @return {this} This GameObject. */ - removeInteractive: function () + removeInteractive() { return this; - }, + } /** * This callback is invoked when this Game Object is added to a Scene. @@ -617,9 +616,9 @@ var Layer = new Class({ * @method Phaser.GameObjects.Layer#addedToScene * @since 3.50.0 */ - addedToScene: function () + addedToScene() { - }, + } /** * This callback is invoked when this Game Object is removed from a Scene. @@ -632,9 +631,9 @@ var Layer = new Class({ * @method Phaser.GameObjects.Layer#removedFromScene * @since 3.50.0 */ - removedFromScene: function () + removedFromScene() { - }, + } /** * To be overridden by custom GameObjects. Allows base objects to be used in a Pool. @@ -644,9 +643,9 @@ var Layer = new Class({ * * @param {...*} [args] - args */ - update: function () + update() { - }, + } /** * Returns a JSON representation of the Game Object. @@ -656,10 +655,10 @@ var Layer = new Class({ * * @return {Phaser.Types.GameObjects.JSONGameObject} A JSON representation of the Game Object. */ - toJSON: function () + toJSON() { return ComponentsToJSON(this); - }, + } /** * Compares the renderMask with the renderFlags to see if this Game Object will render or not. @@ -672,10 +671,10 @@ var Layer = new Class({ * * @return {boolean} True if the Game Object should be rendered, otherwise false. */ - willRender: function (camera) + willRender(camera) { return !(this.renderFlags !== 15 || this.list.length === 0 || (this.cameraFilter !== 0 && (this.cameraFilter & camera.id))); - }, + } /** * Returns an array containing the display list index of either this Game Object, or if it has one, @@ -690,7 +689,7 @@ var Layer = new Class({ * * @return {number[]} An array of display list position indexes. */ - getIndexList: function () + getIndexList() { // eslint-disable-next-line consistent-this var child = this; @@ -717,7 +716,7 @@ var Layer = new Class({ indexes.unshift(this.displayList.getIndex(child)); return indexes; - }, + } /** * Internal method called from `List.addCallback`. @@ -730,7 +729,7 @@ var Layer = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that was added to the list. */ - addChildCallback: function (gameObject) + addChildCallback(gameObject) { var displayList = gameObject.displayList; @@ -749,7 +748,7 @@ var Layer = new Class({ this.events.emit(SceneEvents.ADDED_TO_SCENE, gameObject, this.scene); } - }, + } /** * Internal method called from `List.removeCallback`. @@ -762,7 +761,7 @@ var Layer = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that was removed from the list. */ - removeChildCallback: function (gameObject) + removeChildCallback(gameObject) { this.queueDepthSort(); @@ -771,7 +770,7 @@ var Layer = new Class({ gameObject.emit(GameObjectEvents.REMOVED_FROM_SCENE, gameObject, this.scene); this.events.emit(SceneEvents.REMOVED_FROM_SCENE, gameObject, this.scene); - }, + } /** * Force a sort of the display list on the next call to depthSort. @@ -779,10 +778,10 @@ var Layer = new Class({ * @method Phaser.GameObjects.Layer#queueDepthSort * @since 3.50.0 */ - queueDepthSort: function () + queueDepthSort() { this.sortChildrenFlag = true; - }, + } /** * Immediately sorts the display list if the flag is set. @@ -790,7 +789,7 @@ var Layer = new Class({ * @method Phaser.GameObjects.Layer#depthSort * @since 3.50.0 */ - depthSort: function () + depthSort() { if (this.sortChildrenFlag) { @@ -798,7 +797,7 @@ var Layer = new Class({ this.sortChildrenFlag = false; } - }, + } /** * Compare the depth of two Game Objects. @@ -811,10 +810,10 @@ var Layer = new Class({ * * @return {number} The difference between the depths of each Game Object. */ - sortByDepth: function (childA, childB) + sortByDepth(childA, childB) { return childA._depth - childB._depth; - }, + } /** * Returns a reference to the array which contains all Game Objects in this Layer. @@ -826,10 +825,10 @@ var Layer = new Class({ * * @return {Phaser.GameObjects.GameObject[]} An array of Game Objects within this Layer. */ - getChildren: function () + getChildren() { return this.list; - }, + } /** * Adds this Layer to the given Display List. @@ -856,7 +855,7 @@ var Layer = new Class({ * * @return {this} This Layer instance. */ - addToDisplayList: function (displayList) + addToDisplayList(displayList) { if (displayList === undefined) { displayList = this.scene.sys.displayList; } @@ -880,7 +879,7 @@ var Layer = new Class({ } return this; - }, + } /** * Removes this Layer from the Display List it is currently on. @@ -900,7 +899,7 @@ var Layer = new Class({ * * @return {this} This Layer instance. */ - removeFromDisplayList: function () + removeFromDisplayList() { var displayList = this.displayList || this.scene.sys.displayList; @@ -918,7 +917,7 @@ var Layer = new Class({ } return this; - }, + } /** * Returns a reference to the underlying display list _array_ that contains this Game Object, @@ -936,7 +935,7 @@ var Layer = new Class({ * * @return {?Phaser.GameObjects.GameObject[]} The internal Display List array of Game Objects, or `null`. */ - getDisplayList: function () + getDisplayList() { var list = null; @@ -950,7 +949,7 @@ var Layer = new Class({ } return list; - }, + } /** * Destroys this Layer removing it from the Display List and Update List and @@ -972,7 +971,7 @@ var Layer = new Class({ * * @param {boolean} [fromScene=false] - `True` if this Game Object is being destroyed by the Scene, `false` if not. */ - destroy: function (fromScene) + destroy(fromScene) { // This Game Object has already been destroyed if (!this.scene || this.ignoreDestroy) @@ -1143,6 +1142,6 @@ var Layer = new Class({ * @return {this} This Layer instance. */ -}); +}; module.exports = Layer; diff --git a/src/gameobjects/lights/Light.js b/src/gameobjects/lights/Light.js index 52701110d0..c7864e794a 100644 --- a/src/gameobjects/lights/Light.js +++ b/src/gameobjects/lights/Light.js @@ -44,21 +44,20 @@ var Utils = require('../../renderer/webgl/Utils'); * @param {number} intensity - The intensity of the light. * @param {number} [z] - The z position of the light. If not given, it will be set to `radius * 0.1`. */ -var Light = new Class({ +var Light = class extends Circle { - Extends: Circle, - - Mixins: [ - Components.Origin, - Components.ScrollFactor, - Components.Visible - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Origin, + Components.ScrollFactor, + Components.Visible + ], false); + } - function Light (x, y, radius, r, g, b, intensity, z) + constructor(x, y, radius, r, g, b, intensity, z) { - Circle.call(this, x, y, radius); + super(x, y, radius); /** * The color of the light. @@ -129,7 +128,7 @@ var Light = new Class({ this.setScrollFactor(1, 1); this.setOrigin(); this.setDisplayOrigin(radius); - }, + } /** * The width of this Light Game Object. This is the same as `Light.diameter`. @@ -138,19 +137,16 @@ var Light = new Class({ * @type {number} * @since 3.60.0 */ - displayWidth: { - get: function () - { - return this.diameter; - }, - - set: function (value) - { - this.diameter = value; - } + get displayWidth() + { + return this.diameter; + } - }, + set displayWidth(value) + { + this.diameter = value; + } /** * The height of this Light Game Object. This is the same as `Light.diameter`. @@ -159,19 +155,16 @@ var Light = new Class({ * @type {number} * @since 3.60.0 */ - displayHeight: { - - get: function () - { - return this.diameter; - }, - set: function (value) - { - this.diameter = value; - } + get displayHeight() + { + return this.diameter; + } - }, + set displayHeight(value) + { + this.diameter = value; + } /** * The width of this Light Game Object. This is the same as `Light.diameter`. @@ -180,19 +173,16 @@ var Light = new Class({ * @type {number} * @since 3.60.0 */ - width: { - - get: function () - { - return this.diameter; - }, - set: function (value) - { - this.diameter = value; - } + get width() + { + return this.diameter; + } - }, + set width(value) + { + this.diameter = value; + } /** * The height of this Light Game Object. This is the same as `Light.diameter`. @@ -201,19 +191,16 @@ var Light = new Class({ * @type {number} * @since 3.60.0 */ - height: { - - get: function () - { - return this.diameter; - }, - set: function (value) - { - this.diameter = value; - } + get height() + { + return this.diameter; + } - }, + set height(value) + { + this.diameter = value; + } /** * The z position of the light, as a fraction of the radius. @@ -225,17 +212,16 @@ var Light = new Class({ * @type {number} * @since 4.0.0 */ - zNormal: { - get: function () - { - return this.z / this.radius; - }, - - set: function (value) - { - this.z = value * this.radius; - } - }, + + get zNormal() + { + return this.z / this.radius; + } + + set zNormal(value) + { + this.z = value * this.radius; + } /** * Compares the renderMask with the renderFlags to see if this Game Object will render or not. @@ -248,10 +234,10 @@ var Light = new Class({ * * @return {boolean} True if the Game Object should be rendered, otherwise false. */ - willRender: function (camera) + willRender(camera) { return !(Light.RENDER_MASK !== this.renderFlags || (this.cameraFilter !== 0 && (this.cameraFilter & camera.id))); - }, + } /** * Set the color of the light from a single integer RGB value. @@ -263,14 +249,14 @@ var Light = new Class({ * * @return {this} This Light object. */ - setColor: function (rgb) + setColor(rgb) { var color = Utils.getFloatsFromUintRGB(rgb); this.color.set(color[0], color[1], color[2]); return this; - }, + } /** * Set the intensity of the light. @@ -282,12 +268,12 @@ var Light = new Class({ * * @return {this} This Light object. */ - setIntensity: function (intensity) + setIntensity(intensity) { this.intensity = intensity; return this; - }, + } /** * Set the radius of the light. @@ -299,12 +285,12 @@ var Light = new Class({ * * @return {this} This Light object. */ - setRadius: function (radius) + setRadius(radius) { this.radius = radius; return this; - }, + } /** * Set the z position of the light. @@ -316,12 +302,12 @@ var Light = new Class({ * * @return {this} This Light object. */ - setZ: function (z) + setZ(z) { this.z = z; return this; - }, + } /** * Set the z position of the light as a fraction of the radius. @@ -336,14 +322,14 @@ var Light = new Class({ * * @return {this} This Light object. */ - setZNormal: function (z) + setZNormal(z) { this.z = z * this.radius; return this; } -}); +}; /** * The bitmask that `GameObject.renderFlags` is compared against to determine if the Game Object will render or not. diff --git a/src/gameobjects/lights/LightsManager.js b/src/gameobjects/lights/LightsManager.js index 895cee600c..c1dd17fc59 100644 --- a/src/gameobjects/lights/LightsManager.js +++ b/src/gameobjects/lights/LightsManager.js @@ -31,11 +31,9 @@ var Utils = require('../../renderer/webgl/Utils'); * @constructor * @since 3.0.0 */ -var LightsManager = new Class({ +var LightsManager = class { - initialize: - - function LightsManager () + constructor() { /** * The Lights in the Scene. @@ -86,7 +84,7 @@ var LightsManager = new Class({ * @since 3.50.0 */ this.visibleLights = 0; - }, + } /** * Creates a new Point Light Game Object and adds it to the Scene. @@ -129,10 +127,10 @@ var LightsManager = new Class({ * * @return {Phaser.GameObjects.PointLight} The Game Object that was created. */ - addPointLight: function (x, y, color, radius, intensity, attenuation) + addPointLight(x, y, color, radius, intensity, attenuation) { return this.systems.displayList.add(new PointLight(this.scene, x, y, color, radius, intensity, attenuation)); - }, + } /** * Enable the Lights Manager. @@ -142,7 +140,7 @@ var LightsManager = new Class({ * * @return {this} This Lights Manager instance. */ - enable: function () + enable() { if (this.maxLights === -1) { @@ -152,7 +150,7 @@ var LightsManager = new Class({ this.active = true; return this; - }, + } /** * Disable the Lights Manager. @@ -162,12 +160,12 @@ var LightsManager = new Class({ * * @return {this} This Lights Manager instance. */ - disable: function () + disable() { this.active = false; return this; - }, + } /** * Get all lights that can be seen by the given Camera. @@ -184,7 +182,7 @@ var LightsManager = new Class({ * * @return {Phaser.GameObjects.Light[]} The culled Lights. */ - getLights: function (camera) + getLights(camera) { var lights = this.lights; var worldView = camera.worldView; @@ -218,12 +216,12 @@ var LightsManager = new Class({ this.visibleLights = visibleLights.length; return visibleLights; - }, + } - sortByDistance: function (a, b) + sortByDistance(a, b) { return (a.distance >= b.distance); - }, + } /** * Set the ambient light color. @@ -235,14 +233,14 @@ var LightsManager = new Class({ * * @return {this} This Lights Manager instance. */ - setAmbientColor: function (rgb) + setAmbientColor(rgb) { var color = Utils.getFloatsFromUintRGB(rgb); this.ambientColor.set(color[0], color[1], color[2]); return this; - }, + } /** * Returns the maximum number of Lights allowed to appear at once. @@ -252,10 +250,10 @@ var LightsManager = new Class({ * * @return {number} The maximum number of Lights allowed to appear at once. */ - getMaxVisibleLights: function () + getMaxVisibleLights() { return this.maxLights; - }, + } /** * Get the number of Lights managed by this Lights Manager. @@ -265,10 +263,10 @@ var LightsManager = new Class({ * * @return {number} The number of Lights managed by this Lights Manager. */ - getLightCount: function () + getLightCount() { return this.lights.length; - }, + } /** * Add a Light. @@ -285,7 +283,7 @@ var LightsManager = new Class({ * * @return {Phaser.GameObjects.Light} The Light that was added. */ - addLight: function (x, y, radius, rgb, intensity, z) + addLight(x, y, radius, rgb, intensity, z) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -301,7 +299,7 @@ var LightsManager = new Class({ this.lights.push(light); return light; - }, + } /** * Remove a Light. @@ -313,7 +311,7 @@ var LightsManager = new Class({ * * @return {this} This Lights Manager instance. */ - removeLight: function (light) + removeLight(light) { var index = this.lights.indexOf(light); @@ -323,7 +321,7 @@ var LightsManager = new Class({ } return this; - }, + } /** * Shut down the Lights Manager. @@ -334,10 +332,10 @@ var LightsManager = new Class({ * @method Phaser.GameObjects.LightsManager#shutdown * @since 3.0.0 */ - shutdown: function () + shutdown() { this.lights.length = 0; - }, + } /** * Destroy the Lights Manager. @@ -347,11 +345,11 @@ var LightsManager = new Class({ * @method Phaser.GameObjects.LightsManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); } -}); +}; module.exports = LightsManager; diff --git a/src/gameobjects/lights/LightsPlugin.js b/src/gameobjects/lights/LightsPlugin.js index 6cc3963243..e116979619 100644 --- a/src/gameobjects/lights/LightsPlugin.js +++ b/src/gameobjects/lights/LightsPlugin.js @@ -39,13 +39,9 @@ var SceneEvents = require('../../scene/events'); * * @param {Phaser.Scene} scene - The Scene that this Lights Plugin belongs to. */ -var LightsPlugin = new Class({ +var LightsPlugin = class extends LightsManager { - Extends: LightsManager, - - initialize: - - function LightsPlugin (scene) + constructor(scene) { /** * A reference to the Scene that this Lights Plugin belongs to. @@ -70,8 +66,8 @@ var LightsPlugin = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); } - LightsManager.call(this); - }, + super(); + } /** * Boot the Lights Plugin. @@ -79,13 +75,13 @@ var LightsPlugin = new Class({ * @method Phaser.GameObjects.LightsPlugin#boot * @since 3.0.0 */ - boot: function () + boot() { var eventEmitter = this.systems.events; eventEmitter.on(SceneEvents.SHUTDOWN, this.shutdown, this); eventEmitter.on(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * Destroy the Lights Plugin. @@ -95,7 +91,7 @@ var LightsPlugin = new Class({ * @method Phaser.GameObjects.LightsPlugin#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -103,7 +99,7 @@ var LightsPlugin = new Class({ this.systems = undefined; } -}); +}; PluginCache.register('LightsPlugin', LightsPlugin, 'lights'); diff --git a/src/gameobjects/nineslice/NineSlice.js b/src/gameobjects/nineslice/NineSlice.js index baa2084bcd..62a1166a11 100644 --- a/src/gameobjects/nineslice/NineSlice.js +++ b/src/gameobjects/nineslice/NineSlice.js @@ -121,28 +121,27 @@ var Vertex = require('./NineSliceVertex'); * @param {number} [topHeight=0] - The size of the top horizontal row (C). Set to zero or undefined to create a 3 slice object. * @param {number} [bottomHeight=0] - The size of the bottom horizontal row (D). Set to zero or undefined to create a 3 slice object. */ -var NineSlice = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.Depth, - Components.GetBounds, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.ScrollFactor, - Components.Texture, - Components.Transform, - Components.Visible, - NineSliceRender - ], - - initialize: - - function NineSlice (scene, x, y, texture, frame, width, height, leftWidth, rightWidth, topHeight, bottomHeight) +var NineSlice = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.Depth, + Components.GetBounds, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.ScrollFactor, + Components.Texture, + Components.Transform, + Components.Visible, + NineSliceRender + ], false); + } + + constructor(scene, x, y, texture, frame, width, height, leftWidth, rightWidth, topHeight, bottomHeight) { // if (width === undefined) { width = 256; } // if (height === undefined) { height = 256; } @@ -152,7 +151,7 @@ var NineSlice = new Class({ // if (topHeight === undefined) { topHeight = 0; } // if (bottomHeight === undefined) { bottomHeight = 0; } - GameObject.call(this, scene, 'NineSlice'); + super(scene, 'NineSlice'); /** * Internal width value. Do not modify this property directly. @@ -336,7 +335,7 @@ var NineSlice = new Class({ this.updateDisplayOrigin(); this.initRenderNodes(this._defaultRenderNodesMap); - }, + } /** * The default render nodes for this Game Object. @@ -348,12 +347,11 @@ var NineSlice = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultNineSliceNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultNineSliceNodes; + } /** * Resets the width, height and slices for this NineSlice Game Object. @@ -376,7 +374,7 @@ var NineSlice = new Class({ * * @return {this} This Game Object instance. */ - setSlices: function (width, height, leftWidth, rightWidth, topHeight, bottomHeight, skipScale9) + setSlices(width, height, leftWidth, rightWidth, topHeight, bottomHeight, skipScale9) { if (leftWidth === undefined) { leftWidth = 10; } if (rightWidth === undefined) { rightWidth = 10; } @@ -450,7 +448,7 @@ var NineSlice = new Class({ } return this; - }, + } /** * Updates all of the vertice UV coordinates. This is called automatically @@ -462,7 +460,7 @@ var NineSlice = new Class({ * @method Phaser.GameObjects.NineSlice#updateUVs * @since 3.60.0 */ - updateUVs: function () + updateUVs() { var left = this.leftWidth; var right = this.rightWidth; @@ -485,7 +483,7 @@ var NineSlice = new Class({ this.updateQuadUVs(42, left / width, 1 - bot / height, 1 - right / width, 1); this.updateQuadUVs(48, 1 - right / width, 1 - bot / height, 1, 1); } - }, + } /** * Recalculates all of the vertices in this Nine Slice Game Object @@ -502,7 +500,7 @@ var NineSlice = new Class({ * @method Phaser.GameObjects.NineSlice#updateVertices * @since 3.60.0 */ - updateVertices: function () + updateVertices() { var left = this.leftWidth; var right = this.rightWidth; @@ -525,7 +523,7 @@ var NineSlice = new Class({ this.updateQuad(42, -0.5 + (left / width), -0.5 + (bot / height), 0.5 - (right / width), -0.5); this.updateQuad(48, 0.5 - (right / width), -0.5 + (bot / height), 0.5, -0.5); } - }, + } /** * Internally updates the position coordinates across all vertices of the @@ -543,7 +541,7 @@ var NineSlice = new Class({ * @param {number} x2 - The bottom-right quad coordinate. * @param {number} y2 - The bottom-right quad coordinate. */ - updateQuad: function (offset, x1, y1, x2, y2) + updateQuad(offset, x1, y1, x2, y2) { var width = this.width; var height = this.height; @@ -558,7 +556,7 @@ var NineSlice = new Class({ verts[offset + 3].resize(x1, y2, width, height, originX, originY); verts[offset + 4].resize(x2, y2, width, height, originX, originY); verts[offset + 5].resize(x2, y1, width, height, originX, originY); - }, + } /** * Internally updates the UV coordinates across all vertices of the @@ -576,7 +574,7 @@ var NineSlice = new Class({ * @param {number} u2 - The bottom-right UV coordinate. * @param {number} v2 - The bottom-right UV coordinate. */ - updateQuadUVs: function (offset, u1, v1, u2, v2) + updateQuadUVs(offset, u1, v1, u2, v2) { var verts = this.vertices; @@ -611,7 +609,7 @@ var NineSlice = new Class({ verts[offset + 3].setUVs(u1, v2); verts[offset + 4].setUVs(u2, v2); verts[offset + 5].setUVs(u2, v1); - }, + } /** * Clears all tint values associated with this Game Object. @@ -625,12 +623,12 @@ var NineSlice = new Class({ * * @return {this} This Game Object instance. */ - clearTint: function () + clearTint() { this.setTint(0xffffff); return this; - }, + } /** * Sets an additive tint on this Game Object. @@ -653,7 +651,7 @@ var NineSlice = new Class({ * * @return {this} This Game Object instance. */ - setTint: function (color) + setTint(color) { if (color === undefined) { color = 0xffffff; } @@ -662,7 +660,7 @@ var NineSlice = new Class({ this.tintFill = false; return this; - }, + } /** * Sets a fill-based tint on this Game Object. @@ -686,14 +684,14 @@ var NineSlice = new Class({ * * @return {this} This Game Object instance. */ - setTintFill: function (color) + setTintFill(color) { this.setTint(color); this.tintFill = true; return this; - }, + } /** * Does this Game Object have a tint applied? @@ -707,14 +705,11 @@ var NineSlice = new Class({ * @readonly * @since 3.60.0 */ - isTinted: { - - get: function () - { - return (this.tint !== 0xffffff); - } - }, + get isTinted() + { + return (this.tint !== 0xffffff); + } /** * The displayed width of this Game Object. @@ -730,21 +725,18 @@ var NineSlice = new Class({ * @type {number} * @since 3.60.0 */ - width: { - - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = Math.max(value, this.leftWidth + this.rightWidth); + get width() + { + return this._width; + } - this.updateVertices(); - } + set width(value) + { + this._width = Math.max(value, this.leftWidth + this.rightWidth); - }, + this.updateVertices(); + } /** * The displayed height of this Game Object. @@ -763,24 +755,21 @@ var NineSlice = new Class({ * @type {number} * @since 3.60.0 */ - height: { - get: function () - { - return this._height; - }, + get height() + { + return this._height; + } - set: function (value) + set height(value) + { + if (!this.is3Slice) { - if (!this.is3Slice) - { - this._height = Math.max(value, this.topHeight + this.bottomHeight); + this._height = Math.max(value, this.topHeight + this.bottomHeight); - this.updateVertices(); - } + this.updateVertices(); } - - }, + } /** * The displayed width of this Game Object. @@ -793,19 +782,16 @@ var NineSlice = new Class({ * @type {number} * @since 3.60.0 */ - displayWidth: { - - get: function () - { - return this.scaleX * this.width; - }, - set: function (value) - { - this.scaleX = value / this.width; - } + get displayWidth() + { + return this.scaleX * this.width; + } - }, + set displayWidth(value) + { + this.scaleX = value / this.width; + } /** * The displayed height of this Game Object. @@ -818,19 +804,16 @@ var NineSlice = new Class({ * @type {number} * @since 3.60.0 */ - displayHeight: { - - get: function () - { - return this.scaleY * this.height; - }, - set: function (value) - { - this.scaleY = value / this.height; - } + get displayHeight() + { + return this.scaleY * this.height; + } - }, + set displayHeight(value) + { + this.scaleY = value / this.height; + } /** * Sets the size of this Game Object. @@ -853,7 +836,7 @@ var NineSlice = new Class({ * * @return {this} This Game Object instance. */ - setSize: function (width, height) + setSize(width, height) { this.width = width; this.height = height; @@ -869,7 +852,7 @@ var NineSlice = new Class({ } return this; - }, + } /** * Sets the display size of this Game Object. @@ -884,13 +867,13 @@ var NineSlice = new Class({ * * @return {this} This Game Object instance. */ - setDisplaySize: function (width, height) + setDisplaySize(width, height) { this.displayWidth = width; this.displayHeight = height; return this; - }, + } /** * The horizontal origin of this Game Object. @@ -902,20 +885,17 @@ var NineSlice = new Class({ * @type {number} * @since 3.60.0 */ - originX: { - - get: function () - { - return this._originX; - }, - set: function (value) - { - this._originX = value; - this.updateVertices(); - } + get originX() + { + return this._originX; + } - }, + set originX(value) + { + this._originX = value; + this.updateVertices(); + } /** * The vertical origin of this Game Object. @@ -927,20 +907,17 @@ var NineSlice = new Class({ * @type {number} * @since 3.60.0 */ - originY: { - - get: function () - { - return this._originY; - }, - set: function (value) - { - this._originY = value; - this.updateVertices(); - } + get originY() + { + return this._originY; + } - }, + set originY(value) + { + this._originY = value; + this.updateVertices(); + } /** * Sets the origin of this Game Object. @@ -955,7 +932,7 @@ var NineSlice = new Class({ * * @return {this} This Game Object instance. */ - setOrigin: function (x, y) + setOrigin(x, y) { if (x === undefined) { x = 0.5; } if (y === undefined) { y = x; } @@ -966,7 +943,7 @@ var NineSlice = new Class({ this.updateVertices(); return this.updateDisplayOrigin(); - }, + } /** * This method is included but does nothing for the Nine Slice Game Object, @@ -979,7 +956,7 @@ var NineSlice = new Class({ * * @return {this} This Game Object instance. */ - setSizeToFrame: function () + setSizeToFrame() { if (this.is3Slice) { @@ -993,7 +970,7 @@ var NineSlice = new Class({ this.updateUVs(); return this; - }, + } /** * Handles the pre-destroy step for the Nine Slice, which removes the vertices. @@ -1002,11 +979,11 @@ var NineSlice = new Class({ * @private * @since 3.60.0 */ - preDestroy: function () + preDestroy() { this.vertices = []; } -}); +}; module.exports = NineSlice; diff --git a/src/gameobjects/nineslice/NineSliceVertex.js b/src/gameobjects/nineslice/NineSliceVertex.js index af9b1a244f..489af23851 100644 --- a/src/gameobjects/nineslice/NineSliceVertex.js +++ b/src/gameobjects/nineslice/NineSliceVertex.js @@ -24,15 +24,11 @@ var Vector2 = require('../../math/Vector2'); * @param {number} u - The UV u coordinate of the vertex. * @param {number} v - The UV v coordinate of the vertex. */ -var Vertex = new Class({ +var Vertex = class extends Vector2 { - Extends: Vector2, - - initialize: - - function Vertex (x, y, u, v) + constructor(x, y, u, v) { - Vector2.call(this, x, y); + super(x, y); /** * The projected x coordinate of this vertex. @@ -69,7 +65,7 @@ var Vertex = new Class({ * @since 4.0.0 */ this.v = v; - }, + } /** * Sets the U and V properties. @@ -82,13 +78,13 @@ var Vertex = new Class({ * * @return {this} This Vertex. */ - setUVs: function (u, v) + setUVs(u, v) { this.u = u; this.v = v; return this; - }, + } /** * Resizes this Vertex by setting the x and y coordinates, then transforms this vertex @@ -106,7 +102,7 @@ var Vertex = new Class({ * * @return {this} This Vertex. */ - resize: function (x, y, width, height, originX, originY) + resize(x, y, width, height, originX, originY) { this.x = x; this.y = y; @@ -134,6 +130,6 @@ var Vertex = new Class({ return this; } -}); +}; module.exports = Vertex; diff --git a/src/gameobjects/particles/EmitterColorOp.js b/src/gameobjects/particles/EmitterColorOp.js index 889cb427c0..89cbe483ab 100644 --- a/src/gameobjects/particles/EmitterColorOp.js +++ b/src/gameobjects/particles/EmitterColorOp.js @@ -26,15 +26,11 @@ var IntegerToRGB = require('../../display/color/IntegerToRGB'); * * @param {string} key - The name of the property. */ -var EmitterColorOp = new Class({ +var EmitterColorOp = class extends EmitterOp { - Extends: EmitterOp, - - initialize: - - function EmitterColorOp (key) + constructor(key) { - EmitterOp.call(this, key, null, false); + super(key, null, false); this.active = false; @@ -72,7 +68,7 @@ var EmitterColorOp = new Class({ * @since 3.60.0 */ this.b = []; - }, + } /** * Checks the type of `EmitterOp.propertyValue` to determine which @@ -83,10 +79,10 @@ var EmitterColorOp = new Class({ * * @return {number} A number between 0 and 9 which should be passed to `setMethods`. */ - getMethod: function () + getMethod() { return (this.propertyValue === null) ? 0 : 9; - }, + } /** * Sets the EmitterColorOp method values, if in use. @@ -96,7 +92,7 @@ var EmitterColorOp = new Class({ * * @return {this} This Emitter Op object. */ - setMethods: function () + setMethods() { var value = this.propertyValue; var current = value; @@ -137,7 +133,7 @@ var EmitterColorOp = new Class({ this.current = current; return this; - }, + } /** * Sets the Ease function to use for Color interpolation. @@ -147,12 +143,12 @@ var EmitterColorOp = new Class({ * * @param {string} ease - The string-based name of the Ease function to use. */ - setEase: function (value) + setEase(value) { this.easeName = value; this.ease = GetEaseFunction(value); - }, + } /** * An `onEmit` callback for an eased property. @@ -167,12 +163,12 @@ var EmitterColorOp = new Class({ * * @return {number} {@link Phaser.GameObjects.Particles.EmitterColorOp#start}, as the new value of the property. */ - easedValueEmit: function () + easedValueEmit() { this.current = this.start; return this.start; - }, + } /** * An `onUpdate` callback that returns an eased value between the @@ -188,7 +184,7 @@ var EmitterColorOp = new Class({ * * @return {number} The new value of the property. */ - easeValueUpdate: function (particle, key, t) + easeValueUpdate(particle, key, t) { var v = this.ease(t); @@ -203,6 +199,6 @@ var EmitterColorOp = new Class({ return current; } -}); +}; module.exports = EmitterColorOp; diff --git a/src/gameobjects/particles/EmitterOp.js b/src/gameobjects/particles/EmitterOp.js index 7298399e66..e8366357bd 100644 --- a/src/gameobjects/particles/EmitterOp.js +++ b/src/gameobjects/particles/EmitterOp.js @@ -34,11 +34,9 @@ var Wrap = require('../../math/Wrap'); * @param {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType|Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType} defaultValue - The default value of the property. * @param {boolean} [emitOnly=false] - Whether the property can only be modified when a Particle is emitted. */ -var EmitterOp = new Class({ +var EmitterOp = class { - initialize: - - function EmitterOp (key, defaultValue, emitOnly) + constructor(key, defaultValue, emitOnly) { if (emitOnly === undefined) { emitOnly = false; } @@ -242,7 +240,7 @@ var EmitterOp = new Class({ * @since 3.60.0 */ this._onUpdate; - }, + } /** * Load the property from a Particle Emitter configuration object. @@ -255,7 +253,7 @@ var EmitterOp = new Class({ * @param {Phaser.Types.GameObjects.Particles.ParticleEmitterConfig} [config] - Settings for the Particle Emitter that owns this property. * @param {string} [newKey] - The new key to use for this property, if any. */ - loadConfig: function (config, newKey) + loadConfig(config, newKey) { if (config === undefined) { @@ -282,7 +280,7 @@ var EmitterOp = new Class({ // Reset it back again this.onUpdate = this.defaultUpdate; } - }, + } /** * Build a JSON representation of this Particle Emitter property. @@ -292,10 +290,10 @@ var EmitterOp = new Class({ * * @return {object} A JSON representation of this Particle Emitter property. */ - toJSON: function () + toJSON() { return JSON.stringify(this.propertyValue); - }, + } /** * Change the current value of the property and update its callback methods. @@ -307,7 +305,7 @@ var EmitterOp = new Class({ * * @return {this} This Emitter Op object. */ - onChange: function (value) + onChange(value) { var current; @@ -355,7 +353,7 @@ var EmitterOp = new Class({ this.current = current; return this; - }, + } /** * Checks the type of `EmitterOp.propertyValue` to determine which @@ -366,7 +364,7 @@ var EmitterOp = new Class({ * * @return {number} A number between 0 and 9 which should be passed to `setMethods`. */ - getMethod: function () + getMethod() { var value = this.propertyValue; @@ -431,7 +429,7 @@ var EmitterOp = new Class({ } return 0; - }, + } /** * Update the {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and @@ -444,7 +442,7 @@ var EmitterOp = new Class({ * * @return {this} This Emitter Op object. */ - setMethods: function () + setMethods() { var value = this.propertyValue; var current = value; @@ -543,7 +541,7 @@ var EmitterOp = new Class({ this.current = current; return this; - }, + } /** * Check whether an object has the given property. @@ -556,10 +554,10 @@ var EmitterOp = new Class({ * * @return {boolean} `true` if the property exists in the object, `false` otherwise. */ - has: function (object, key) + has(object, key) { return object.hasOwnProperty(key); - }, + } /** * Check whether an object has both of the given properties. @@ -573,10 +571,10 @@ var EmitterOp = new Class({ * * @return {boolean} `true` if both properties exist in the object, `false` otherwise. */ - hasBoth: function (object, key1, key2) + hasBoth(object, key1, key2) { return object.hasOwnProperty(key1) && object.hasOwnProperty(key2); - }, + } /** * Check whether an object has at least one of the given properties. @@ -590,10 +588,10 @@ var EmitterOp = new Class({ * * @return {boolean} `true` if at least one of the properties exists in the object, `false` if neither exist. */ - hasEither: function (object, key1, key2) + hasEither(object, key1, key2) { return object.hasOwnProperty(key1) || object.hasOwnProperty(key2); - }, + } /** * The returned value sets what the property will be at the START of the particles life, on emit. @@ -603,10 +601,10 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - defaultEmit: function () + defaultEmit() { return this.defaultValue; - }, + } /** * The returned value updates the property for the duration of the particles life. @@ -621,10 +619,10 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - defaultUpdate: function (particle, key, t, value) + defaultUpdate(particle, key, t, value) { return value; - }, + } /** * The returned value sets what the property will be at the START of the particles life, on emit. @@ -640,14 +638,14 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - proxyEmit: function (particle, key, value) + proxyEmit(particle, key, value) { var result = this._onEmit(particle, key, value); this.current = result; return result; - }, + } /** * The returned value updates the property for the duration of the particles life. @@ -664,14 +662,14 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - proxyUpdate: function (particle, key, t, value) + proxyUpdate(particle, key, t, value) { var result = this._onUpdate(particle, key, t, value); this.current = result; return result; - }, + } /** * An `onEmit` callback that returns the current value of the property. @@ -681,10 +679,10 @@ var EmitterOp = new Class({ * * @return {number} The current value of the property. */ - staticValueEmit: function () + staticValueEmit() { return this.current; - }, + } /** * An `onUpdate` callback that returns the current value of the property. @@ -694,10 +692,10 @@ var EmitterOp = new Class({ * * @return {number} The current value of the property. */ - staticValueUpdate: function () + staticValueUpdate() { return this.current; - }, + } /** * An `onEmit` callback that returns a random value from the current value array. @@ -707,14 +705,14 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - randomStaticValueEmit: function () + randomStaticValueEmit() { var randomIndex = Math.floor(Math.random() * this.propertyValue.length); this.current = this.propertyValue[randomIndex]; return this.current; - }, + } /** * An `onEmit` callback that returns a value between the {@link Phaser.GameObjects.Particles.EmitterOp#start} and @@ -728,7 +726,7 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - randomRangedValueEmit: function (particle, key) + randomRangedValueEmit(particle, key) { var value = FloatBetween(this.start, this.end); @@ -741,7 +739,7 @@ var EmitterOp = new Class({ this.current = value; return value; - }, + } /** * An `onEmit` callback that returns a value between the {@link Phaser.GameObjects.Particles.EmitterOp#start} and @@ -755,7 +753,7 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - randomRangedIntEmit: function (particle, key) + randomRangedIntEmit(particle, key) { var value = Between(this.start, this.end); @@ -768,7 +766,7 @@ var EmitterOp = new Class({ this.current = value; return value; - }, + } /** * An `onEmit` callback that returns a stepped value between the @@ -780,7 +778,7 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - steppedEmit: function () + steppedEmit() { var current = this.counter; @@ -831,7 +829,7 @@ var EmitterOp = new Class({ this.current = current; return current; - }, + } /** * An `onEmit` callback for an eased property. @@ -846,7 +844,7 @@ var EmitterOp = new Class({ * * @return {number} {@link Phaser.GameObjects.Particles.EmitterOp#start}, as the new value of the property. */ - easedValueEmit: function (particle, key) + easedValueEmit(particle, key) { if (particle && particle.data[key]) { @@ -859,7 +857,7 @@ var EmitterOp = new Class({ this.current = this.start; return this.start; - }, + } /** * An `onUpdate` callback that returns an eased value between the @@ -875,7 +873,7 @@ var EmitterOp = new Class({ * * @return {number} The new value of the property. */ - easeValueUpdate: function (particle, key, t) + easeValueUpdate(particle, key, t) { var data = particle.data[key]; @@ -894,7 +892,7 @@ var EmitterOp = new Class({ this.current = current; return current; - }, + } /** * Destroys this EmitterOp instance and all of its references. @@ -905,7 +903,7 @@ var EmitterOp = new Class({ * @method Phaser.GameObjects.Particles.EmitterOp#destroy * @since 3.60.0 */ - destroy: function () + destroy() { this.propertyValue = null; this.defaultValue = null; @@ -914,6 +912,6 @@ var EmitterOp = new Class({ this._onEmit = null; this._onUpdate = null; } -}); +}; module.exports = EmitterOp; diff --git a/src/gameobjects/particles/GravityWell.js b/src/gameobjects/particles/GravityWell.js index 33b0b5af6c..1ea4a8f4a0 100644 --- a/src/gameobjects/particles/GravityWell.js +++ b/src/gameobjects/particles/GravityWell.js @@ -30,13 +30,9 @@ var ParticleProcessor = require('./ParticleProcessor'); * @param {number} [epsilon=100] - The minimum distance for which the gravity force is calculated. * @param {number} [gravity=50] - The gravitational force of this Gravity Well. */ -var GravityWell = new Class({ +var GravityWell = class extends ParticleProcessor { - Extends: ParticleProcessor, - - initialize: - - function GravityWell (x, y, power, epsilon, gravity) + constructor(x, y, power, epsilon, gravity) { if (typeof x === 'object') { @@ -57,7 +53,7 @@ var GravityWell = new Class({ if (gravity === undefined) { gravity = 50; } } - ParticleProcessor.call(this, x, y, true); + super(x, y, true); /** * Internal gravity value. @@ -90,7 +86,7 @@ var GravityWell = new Class({ * @since 3.0.0 */ this._epsilon = epsilon * epsilon; - }, + } /** * Takes a Particle and updates it based on the properties of this Gravity Well. @@ -102,7 +98,7 @@ var GravityWell = new Class({ * @param {number} delta - The delta time in ms. * @param {number} step - The delta value divided by 1000. */ - update: function (particle, delta) + update(particle, delta) { var x = this.x - particle.x; var y = this.y - particle.y; @@ -124,7 +120,7 @@ var GravityWell = new Class({ particle.velocityX += x * factor; particle.velocityY += y * factor; - }, + } /** * The minimum distance for which the gravity force is calculated. @@ -135,19 +131,16 @@ var GravityWell = new Class({ * @type {number} * @since 3.0.0 */ - epsilon: { - get: function () - { - return Math.sqrt(this._epsilon); - }, - - set: function (value) - { - this._epsilon = value * value; - } + get epsilon() + { + return Math.sqrt(this._epsilon); + } - }, + set epsilon(value) + { + this._epsilon = value * value; + } /** * The strength of the gravity force - larger numbers produce a stronger force. @@ -158,19 +151,16 @@ var GravityWell = new Class({ * @type {number} * @since 3.0.0 */ - power: { - - get: function () - { - return this._power / this._gravity; - }, - set: function (value) - { - this._power = value * this._gravity; - } + get power() + { + return this._power / this._gravity; + } - }, + set power(value) + { + this._power = value * this._gravity; + } /** * The gravitational force of this Gravity Well. @@ -181,22 +171,19 @@ var GravityWell = new Class({ * @type {number} * @since 3.0.0 */ - gravity: { - get: function () - { - return this._gravity; - }, - - set: function (value) - { - var pwr = this.power; - this._gravity = value; - this.power = pwr; - } + get gravity() + { + return this._gravity; + } + set gravity(value) + { + var pwr = this.power; + this._gravity = value; + this.power = pwr; } -}); +}; module.exports = GravityWell; diff --git a/src/gameobjects/particles/Particle.js b/src/gameobjects/particles/Particle.js index ab9c77dcbc..a547700d81 100644 --- a/src/gameobjects/particles/Particle.js +++ b/src/gameobjects/particles/Particle.js @@ -26,11 +26,9 @@ var Vector2 = require('../../math/Vector2'); * * @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter to which this Particle belongs. */ -var Particle = new Class({ +var Particle = class { - initialize: - - function Particle (emitter) + constructor(emitter) { /** * The Emitter to which this Particle belongs. @@ -353,7 +351,7 @@ var Particle = new Class({ * @since 3.60.0 */ this.bounds = new Rectangle(); - }, + } /** * The Event Emitter proxy. @@ -372,10 +370,10 @@ var Particle = new Class({ * * @return {boolean} `true` if the event had listeners, else `false`. */ - emit: function (event, a1, a2, a3, a4, a5) + emit(event, a1, a2, a3, a4, a5) { return this.emitter.emit(event, a1, a2, a3, a4, a5); - }, + } /** * Checks to see if this Particle is alive and updating. @@ -385,10 +383,10 @@ var Particle = new Class({ * * @return {boolean} `true` if this Particle is alive and updating, otherwise `false`. */ - isAlive: function () + isAlive() { return (this.lifeCurrent > 0); - }, + } /** * Kills this particle. This sets the `lifeCurrent` value to 0, which forces @@ -397,10 +395,10 @@ var Particle = new Class({ * @method Phaser.GameObjects.Particles.Particle#kill * @since 3.60.0 */ - kill: function () + kill() { this.lifeCurrent = 0; - }, + } /** * Sets the position of this particle to the given x/y coordinates. @@ -413,14 +411,14 @@ var Particle = new Class({ * @param {number} [x=0] - The x coordinate to set this Particle to. * @param {number} [y=0] - The y coordinate to set this Particle to. */ - setPosition: function (x, y) + setPosition(x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } this.x = x; this.y = y; - }, + } /** * Starts this Particle from the given coordinates. @@ -433,7 +431,7 @@ var Particle = new Class({ * * @return {boolean} `true` if the Particle is alive, or `false` if it was spawned inside a DeathZone. */ - fire: function (x, y) + fire(x, y) { var emitter = this.emitter; var ops = emitter.ops; @@ -558,7 +556,7 @@ var Particle = new Class({ } return true; - }, + } /** * The main update method for this Particle. @@ -574,7 +572,7 @@ var Particle = new Class({ * * @return {boolean} Returns `true` if this Particle has now expired and should be removed, otherwise `false` if still active. */ - update: function (delta, step, processors) + update(delta, step, processors) { if (this.lifeCurrent <= 0) { @@ -663,7 +661,7 @@ var Particle = new Class({ this.lifeCurrent -= delta; return (this.lifeCurrent <= 0 && this.holdCurrent <= 0); - }, + } /** * An internal method that calculates the velocity of the Particle and @@ -679,7 +677,7 @@ var Particle = new Class({ * @param {Phaser.GameObjects.Particles.ParticleProcessor[]} processors - An array of all active Particle Processors. * @param {number} t - The current normalized lifetime of the particle, between 0 (birth) and 1 (death). */ - computeVelocity: function (emitter, delta, step, processors, t) + computeVelocity(emitter, delta, step, processors, t) { var ops = emitter.ops; @@ -719,7 +717,7 @@ var Particle = new Class({ processor.update(this, delta, step, t); } } - }, + } /** * This is a NOOP method and does nothing when called. @@ -727,10 +725,10 @@ var Particle = new Class({ * @method Phaser.GameObjects.Particles.Particle#setSizeToFrame * @since 3.60.0 */ - setSizeToFrame: function () + setSizeToFrame() { // NOOP - }, + } /** * Gets the bounds of this particle as a Geometry Rectangle, factoring in any @@ -745,7 +743,7 @@ var Particle = new Class({ * * @return {Phaser.Geom.Rectangle} A Rectangle containing the transformed bounds of this particle. */ - getBounds: function (matrix) + getBounds(matrix) { if (matrix === undefined) { matrix = this.emitter.getWorldTransformMatrix(); } @@ -784,7 +782,7 @@ var Particle = new Class({ bounds.height = Math.max(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y) - bounds.y; return bounds; - }, + } /** * Destroys this Particle. @@ -792,7 +790,7 @@ var Particle = new Class({ * @method Phaser.GameObjects.Particles.Particle#destroy * @since 3.60.0 */ - destroy: function () + destroy() { if (this.anims) { @@ -806,6 +804,6 @@ var Particle = new Class({ this.scene = null; } -}); +}; module.exports = Particle; diff --git a/src/gameobjects/particles/ParticleBounds.js b/src/gameobjects/particles/ParticleBounds.js index dfb635673f..cdb86ea03c 100644 --- a/src/gameobjects/particles/ParticleBounds.js +++ b/src/gameobjects/particles/ParticleBounds.js @@ -38,20 +38,16 @@ var Rectangle = require('../../geom/rectangle/Rectangle'); * @param {boolean} [collideTop=true] - Whether particles interact with the top edge of the bounds. * @param {boolean} [collideBottom=true] - Whether particles interact with the bottom edge of the bounds. */ -var ParticleBounds = new Class({ +var ParticleBounds = class extends ParticleProcessor { - Extends: ParticleProcessor, - - initialize: - - function ParticleBounds (x, y, width, height, collideLeft, collideRight, collideTop, collideBottom) + constructor(x, y, width, height, collideLeft, collideRight, collideTop, collideBottom) { if (collideLeft === undefined) { collideLeft = true; } if (collideRight === undefined) { collideRight = true; } if (collideTop === undefined) { collideTop = true; } if (collideBottom === undefined) { collideBottom = true; } - ParticleProcessor.call(this, x, y, true); + super(x, y, true); /** * A rectangular boundary constraining particle movement. Use the Emitter properties `collideLeft`, @@ -104,7 +100,7 @@ var ParticleBounds = new Class({ * @since 3.60.0 */ this.collideBottom = collideBottom; - }, + } /** * Takes a Particle and updates it against the bounds. @@ -114,7 +110,7 @@ var ParticleBounds = new Class({ * * @param {Phaser.GameObjects.Particles.Particle} particle - The Particle to update. */ - update: function (particle) + update(particle) { var bounds = this.bounds; var bounce = -particle.bounce; @@ -143,6 +139,6 @@ var ParticleBounds = new Class({ } } -}); +}; module.exports = ParticleBounds; diff --git a/src/gameobjects/particles/ParticleEmitter.js b/src/gameobjects/particles/ParticleEmitter.js index c2cfd9d2b9..065b306221 100644 --- a/src/gameobjects/particles/ParticleEmitter.js +++ b/src/gameobjects/particles/ParticleEmitter.js @@ -336,29 +336,28 @@ var configOpMap = [ * @param {(string|Phaser.Textures.Texture)} [texture] - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {Phaser.Types.GameObjects.Particles.ParticleEmitterConfig} [config] - Settings for this emitter. */ -var ParticleEmitter = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.Depth, - Components.Lighting, - Components.Mask, - Components.RenderNodes, - Components.ScrollFactor, - Components.Texture, - Components.Transform, - Components.Visible, - Render - ], - - initialize: +var ParticleEmitter = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.Depth, + Components.Lighting, + Components.Mask, + Components.RenderNodes, + Components.ScrollFactor, + Components.Texture, + Components.Transform, + Components.Visible, + Render + ], false); + } - function ParticleEmitter (scene, x, y, texture, config) + constructor(scene, x, y, texture, config) { - GameObject.call(this, scene, 'ParticleEmitter'); + super(scene, 'ParticleEmitter'); /** * The Particle Class which will be emitted by this Emitter. @@ -920,7 +919,7 @@ var ParticleEmitter = new Class({ { this.setConfig(config); } - }, + } /** * The default render nodes for this Game Object. @@ -932,24 +931,23 @@ var ParticleEmitter = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultParticleEmitterNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultParticleEmitterNodes; + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } /** * Takes an Emitter Configuration file and resets this Emitter, using any @@ -962,7 +960,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setConfig: function (config) + setConfig(config) { if (!config) { @@ -1085,7 +1083,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Takes an existing Emitter Configuration file and updates this Emitter. @@ -1100,7 +1098,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - updateConfig: function (config) + updateConfig(config) { if (config) { @@ -1115,7 +1113,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Creates a description of this emitter suitable for JSON serialization. @@ -1125,7 +1123,7 @@ var ParticleEmitter = new Class({ * * @return {Phaser.Types.GameObjects.JSONGameObject} A JSON representation of the Game Object. */ - toJSON: function () + toJSON() { var output = ComponentsToJSON(this); @@ -1166,7 +1164,7 @@ var ParticleEmitter = new Class({ } return output; - }, + } /** * Resets the internal counter trackers. @@ -1179,7 +1177,7 @@ var ParticleEmitter = new Class({ * @param {number} frequency - The frequency counter. * @param {boolean} on - Set the complete flag. */ - resetCounters: function (frequency, on) + resetCounters(frequency, on) { var counters = this.counters; @@ -1191,7 +1189,7 @@ var ParticleEmitter = new Class({ { counters[5] = 1; } - }, + } /** * Continuously moves the particle origin to follow a Game Object's position. @@ -1206,7 +1204,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - startFollow: function (target, offsetX, offsetY, trackVisible) + startFollow(target, offsetX, offsetY, trackVisible) { if (offsetX === undefined) { offsetX = 0; } if (offsetY === undefined) { offsetY = 0; } @@ -1217,7 +1215,7 @@ var ParticleEmitter = new Class({ this.trackVisible = trackVisible; return this; - }, + } /** * Stops following a Game Object. @@ -1227,14 +1225,14 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - stopFollow: function () + stopFollow() { this.follow = null; this.followOffset.set(0, 0); this.trackVisible = false; return this; - }, + } /** * Chooses a texture frame from {@link Phaser.GameObjects.Particles.ParticleEmitter#frames}. @@ -1244,7 +1242,7 @@ var ParticleEmitter = new Class({ * * @return {Phaser.Textures.Frame} The texture frame. */ - getFrame: function () + getFrame() { var frames = this.frames; var len = frames.length; @@ -1278,7 +1276,7 @@ var ParticleEmitter = new Class({ } return this.texture.get(current); - }, + } /** * Sets a pattern for assigning texture frames to emitted particles. The `frames` configuration can be any of: @@ -1298,7 +1296,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setEmitterFrame: function (frames, pickRandom, quantity) + setEmitterFrame(frames, pickRandom, quantity) { if (pickRandom === undefined) { pickRandom = true; } if (quantity === undefined) { quantity = 1; } @@ -1345,7 +1343,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Chooses an animation from {@link Phaser.GameObjects.Particles.ParticleEmitter#anims}, if populated. @@ -1355,7 +1353,7 @@ var ParticleEmitter = new Class({ * * @return {string} The animation to play, or `null` if there aren't any. */ - getAnim: function () + getAnim() { var anims = this.anims; var len = anims.length; @@ -1386,7 +1384,7 @@ var ParticleEmitter = new Class({ return anim; } - }, + } /** * Sets a pattern for assigning animations to emitted particles. The `anims` configuration can be any of: @@ -1406,7 +1404,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setAnim: function (anims, pickRandom, quantity) + setAnim(anims, pickRandom, quantity) { if (pickRandom === undefined) { pickRandom = true; } if (quantity === undefined) { quantity = 1; } @@ -1453,7 +1451,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#radial} particle movement on or off. @@ -1465,14 +1463,14 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setRadial: function (value) + setRadial(value) { if (value === undefined) { value = true; } this.radial = value; return this; - }, + } /** * Creates a Particle Bounds processor and adds it to this Emitter. @@ -1510,7 +1508,7 @@ var ParticleEmitter = new Class({ * * @return {Phaser.GameObjects.Particles.ParticleBounds} The Particle Bounds processor. */ - addParticleBounds: function (x, y, width, height, collideLeft, collideRight, collideTop, collideBottom) + addParticleBounds(x, y, width, height, collideLeft, collideRight, collideTop, collideBottom) { if (typeof x === 'object') { @@ -1523,7 +1521,7 @@ var ParticleEmitter = new Class({ } return this.addParticleProcessor(new ParticleBounds(x, y, width, height, collideLeft, collideRight, collideTop, collideBottom)); - }, + } /** * Sets the initial radial speed of emitted particles. @@ -1538,7 +1536,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setParticleSpeed: function (x, y) + setParticleSpeed(x, y) { if (y === undefined) { y = x; } @@ -1557,7 +1555,7 @@ var ParticleEmitter = new Class({ this.radial = true; return this; - }, + } /** * Sets the vertical and horizontal scale of the emitted particles. @@ -1572,7 +1570,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setParticleScale: function (x, y) + setParticleScale(x, y) { if (x === undefined) { x = 1; } if (y === undefined) { y = x; } @@ -1581,7 +1579,7 @@ var ParticleEmitter = new Class({ this.ops.scaleY.onChange(y); return this; - }, + } /** * Sets the gravity applied to emitted particles. @@ -1594,13 +1592,13 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setParticleGravity: function (x, y) + setParticleGravity(x, y) { this.gravityX = x; this.gravityY = y; return this; - }, + } /** * Sets the opacity (alpha) of emitted particles. @@ -1614,12 +1612,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setParticleAlpha: function (value) + setParticleAlpha(value) { this.ops.alpha.onChange(value); return this; - }, + } /** * Sets the color tint of emitted particles. @@ -1634,12 +1632,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setParticleTint: function (value) + setParticleTint(value) { this.ops.tint.onChange(value); return this; - }, + } /** * Sets the angle of a {@link Phaser.GameObjects.Particles.ParticleEmitter#radial} particle stream. @@ -1653,12 +1651,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setEmitterAngle: function (value) + setEmitterAngle(value) { this.ops.angle.onChange(value); return this; - }, + } /** * Sets the lifespan of newly emitted particles in milliseconds. @@ -1670,12 +1668,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setParticleLifespan: function (value) + setParticleLifespan(value) { this.ops.lifespan.onChange(value); return this; - }, + } /** * Sets the number of particles released at each flow cycle or explosion. @@ -1687,12 +1685,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setQuantity: function (quantity) + setQuantity(quantity) { this.quantity = quantity; return this; - }, + } /** * Sets the emitter's {@link Phaser.GameObjects.Particles.ParticleEmitter#frequency} @@ -1706,7 +1704,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setFrequency: function (frequency, quantity) + setFrequency(frequency, quantity) { this.frequency = frequency; @@ -1718,7 +1716,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Adds a new Particle Death Zone to this Emitter. @@ -1741,7 +1739,7 @@ var ParticleEmitter = new Class({ * * @return {Phaser.GameObjects.Particles.Zones.DeathZone[]} An array of the Death Zones that were added to this Emitter. */ - addDeathZone: function (config) + addDeathZone(config) { if (!Array.isArray(config)) { @@ -1784,7 +1782,7 @@ var ParticleEmitter = new Class({ this.deathZones = this.deathZones.concat(output); return output; - }, + } /** * Removes the given Particle Death Zone from this Emitter. @@ -1796,12 +1794,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - removeDeathZone: function (zone) + removeDeathZone(zone) { Remove(this.deathZones, zone); return this; - }, + } /** * Clear all Death Zones from this Particle Emitter. @@ -1811,12 +1809,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - clearDeathZones: function () + clearDeathZones() { this.deathZones.length = 0; return this; - }, + } /** * Adds a new Particle Emission Zone to this Emitter. @@ -1837,7 +1835,7 @@ var ParticleEmitter = new Class({ * * @return {Phaser.Types.GameObjects.Particles.EmitZoneObject[]} An array of the Emission Zones that were added to this Emitter. */ - addEmitZone: function (config) + addEmitZone(config) { if (!Array.isArray(config)) { @@ -1892,7 +1890,7 @@ var ParticleEmitter = new Class({ this.emitZones = this.emitZones.concat(output); return output; - }, + } /** * Removes the given Particle Emission Zone from this Emitter. @@ -1904,14 +1902,14 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - removeEmitZone: function (zone) + removeEmitZone(zone) { Remove(this.emitZones, zone); this.zoneIndex = 0; return this; - }, + } /** * Clear all Emission Zones from this Particle Emitter. @@ -1921,14 +1919,14 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - clearEmitZones: function () + clearEmitZones() { this.emitZones.length = 0; this.zoneIndex = 0; return this; - }, + } /** * Takes the given particle and sets its x/y coordinates to match the next available @@ -1943,7 +1941,7 @@ var ParticleEmitter = new Class({ * * @param {Phaser.GameObjects.Particles.Particle} particle - The particle to set the emission zone for. */ - getEmitZone: function (particle) + getEmitZone(particle) { var zones = this.emitZones; var len = zones.length; @@ -1975,7 +1973,7 @@ var ParticleEmitter = new Class({ } } } - }, + } /** * Takes the given particle and checks to see if any of the configured Death Zones @@ -1990,7 +1988,7 @@ var ParticleEmitter = new Class({ * * @return {boolean} `true` if the particle should be killed, otherwise `false`. */ - getDeathZone: function (particle) + getDeathZone(particle) { var zones = this.deathZones; @@ -2007,7 +2005,7 @@ var ParticleEmitter = new Class({ } return false; - }, + } /** * Changes the currently active Emission Zone. The zones should have already @@ -2028,7 +2026,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setEmitZone: function (zone) + setEmitZone(zone) { var index; @@ -2047,7 +2045,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Adds a Particle Processor, such as a Gravity Well, to this Emitter. @@ -2063,7 +2061,7 @@ var ParticleEmitter = new Class({ * * @return {T} The Particle Processor that was added to this Emitter Manager. */ - addParticleProcessor: function (processor) + addParticleProcessor(processor) { if (!this.processors.exists(processor)) { @@ -2078,7 +2076,7 @@ var ParticleEmitter = new Class({ } return processor; - }, + } /** * Removes a Particle Processor from this Emitter. @@ -2096,7 +2094,7 @@ var ParticleEmitter = new Class({ * * @return {?T} The Particle Processor that was removed, or null if it could not be found. */ - removeParticleProcessor: function (processor) + removeParticleProcessor(processor) { if (this.processors.exists(processor)) { @@ -2106,7 +2104,7 @@ var ParticleEmitter = new Class({ } return processor; - }, + } /** * Gets all active Particle Processors. @@ -2116,10 +2114,10 @@ var ParticleEmitter = new Class({ * * @return {Phaser.GameObjects.Particles.ParticleProcessor[]} - An array of active Particle Processors. */ - getProcessors: function () + getProcessors() { return this.processors.getAll('active', true); - }, + } /** * Creates a new Gravity Well, adds it to this Emitter and returns a reference to it. @@ -2131,10 +2129,10 @@ var ParticleEmitter = new Class({ * * @return {Phaser.GameObjects.Particles.GravityWell} The Gravity Well that was created. */ - createGravityWell: function (config) + createGravityWell(config) { return this.addParticleProcessor(new GravityWell(config)); - }, + } /** * Creates inactive particles and adds them to this emitter's pool. @@ -2149,7 +2147,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - reserve: function (count) + reserve(count) { var dead = this.dead; @@ -2169,7 +2167,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Gets the number of active (in-use) particles in this emitter. @@ -2179,10 +2177,10 @@ var ParticleEmitter = new Class({ * * @return {number} The number of particles with `active=true`. */ - getAliveParticleCount: function () + getAliveParticleCount() { return this.alive.length; - }, + } /** * Gets the number of inactive (available) particles in this emitter. @@ -2192,10 +2190,10 @@ var ParticleEmitter = new Class({ * * @return {number} The number of particles with `active=false`. */ - getDeadParticleCount: function () + getDeadParticleCount() { return this.dead.length; - }, + } /** * Gets the total number of particles in this emitter. @@ -2205,10 +2203,10 @@ var ParticleEmitter = new Class({ * * @return {number} The number of particles, including both alive and dead. */ - getParticleCount: function () + getParticleCount() { return this.getAliveParticleCount() + this.getDeadParticleCount(); - }, + } /** * Whether this emitter is at either its hard-cap limit (maxParticles), if set, or @@ -2219,7 +2217,7 @@ var ParticleEmitter = new Class({ * * @return {boolean} Returns `true` if this Emitter is at its limit, or `false` if no limit, or below the `maxParticles` level. */ - atLimit: function () + atLimit() { if (this.maxParticles > 0 && this.getParticleCount() >= this.maxParticles) { @@ -2227,7 +2225,7 @@ var ParticleEmitter = new Class({ } return (this.maxAliveParticles > 0 && this.getAliveParticleCount() >= this.maxAliveParticles); - }, + } /** * Sets a function to call for each newly emitted particle. @@ -2240,7 +2238,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - onParticleEmit: function (callback, context) + onParticleEmit(callback, context) { if (callback === undefined) { @@ -2259,7 +2257,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Sets a function to call for each particle death. @@ -2272,7 +2270,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - onParticleDeath: function (callback, context) + onParticleDeath(callback, context) { if (callback === undefined) { @@ -2291,7 +2289,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Deactivates every particle in this emitter immediately. @@ -2303,7 +2301,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - killAll: function () + killAll() { var dead = this.dead; var alive = this.alive; @@ -2314,7 +2312,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Calls a function for each active particle in this emitter. The function is @@ -2328,7 +2326,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - forEachAlive: function (callback, context) + forEachAlive(callback, context) { var alive = this.alive; var length = alive.length; @@ -2340,7 +2338,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Calls a function for each inactive particle in this emitter. @@ -2353,7 +2351,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - forEachDead: function (callback, context) + forEachDead(callback, context) { var dead = this.dead; var length = dead.length; @@ -2364,7 +2362,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#on} the emitter and resets the flow counter. @@ -2385,7 +2383,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - start: function (advance, duration) + start(advance, duration) { if (advance === undefined) { advance = 0; } @@ -2409,7 +2407,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#emitting off} the emitter and @@ -2427,7 +2425,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - stop: function (kill) + stop(kill) { if (kill === undefined) { kill = false; } @@ -2444,7 +2442,7 @@ var ParticleEmitter = new Class({ } return this; - }, + } /** * {@link Phaser.GameObjects.Particles.ParticleEmitter#active Deactivates} the emitter. @@ -2454,12 +2452,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - pause: function () + pause() { this.active = false; return this; - }, + } /** * {@link Phaser.GameObjects.Particles.ParticleEmitter#active Activates} the emitter. @@ -2469,12 +2467,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - resume: function () + resume() { this.active = true; return this; - }, + } /** * Set the property by which active particles are sorted prior to be rendered. @@ -2497,7 +2495,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setSortProperty: function (property, ascending) + setSortProperty(property, ascending) { if (property === undefined) { property = ''; } if (ascending === undefined) { ascending = this.true; } @@ -2507,7 +2505,7 @@ var ParticleEmitter = new Class({ this.sortCallback = this.depthSortCallback; return this; - }, + } /** * Sets a callback to be used to sort the particles before rendering each frame. @@ -2531,7 +2529,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - setSortCallback: function (callback) + setSortCallback(callback) { if (this.sortProperty !== '') { @@ -2545,7 +2543,7 @@ var ParticleEmitter = new Class({ this.sortCallback = callback; return this; - }, + } /** * Sorts active particles with {@link Phaser.GameObjects.Particles.ParticleEmitter#depthSortCallback}. @@ -2555,12 +2553,12 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - depthSort: function () + depthSort() { StableSort(this.alive, this.sortCallback.bind(this)); return this; - }, + } /** * Calculates the difference of two particles, for sorting them by depth. @@ -2573,7 +2571,7 @@ var ParticleEmitter = new Class({ * * @return {number} The difference of a and b's y coordinates. */ - depthSortCallback: function (a, b) + depthSortCallback(a, b) { var key = this.sortProperty; @@ -2585,7 +2583,7 @@ var ParticleEmitter = new Class({ { return b[key] - a[key]; } - }, + } /** * Puts the emitter in flow mode (frequency >= 0) and starts (or restarts) a particle flow. @@ -2602,7 +2600,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - flow: function (frequency, count, stopAfter) + flow(frequency, count, stopAfter) { if (count === undefined) { count = 1; } @@ -2617,7 +2615,7 @@ var ParticleEmitter = new Class({ } return this.start(); - }, + } /** * Puts the emitter in explode mode (frequency = -1), stopping any current particle flow, and emits several particles all at once. @@ -2632,7 +2630,7 @@ var ParticleEmitter = new Class({ * * @return {(Phaser.GameObjects.Particles.Particle|undefined)} The most recently emitted Particle, or `undefined` if the emitter is at its limit. */ - explode: function (count, x, y) + explode(count, x, y) { this.frequency = -1; @@ -2643,7 +2641,7 @@ var ParticleEmitter = new Class({ this.emit(Events.EXPLODE, this, particle); return particle; - }, + } /** * Emits particles at the given position. If no position is given, it will @@ -2658,10 +2656,10 @@ var ParticleEmitter = new Class({ * * @return {(Phaser.GameObjects.Particles.Particle|undefined)} The most recently emitted Particle, or `undefined` if the emitter is at its limit. */ - emitParticleAt: function (x, y, count) + emitParticleAt(x, y, count) { return this.emitParticle(count, x, y); - }, + } /** * Emits particles at a given position (or the emitters current position). @@ -2677,7 +2675,7 @@ var ParticleEmitter = new Class({ * * @see Phaser.GameObjects.Particles.Particle#fire */ - emitParticle: function (count, x, y) + emitParticle(count, x, y) { if (this.atLimit()) { @@ -2742,7 +2740,7 @@ var ParticleEmitter = new Class({ } return particle; - }, + } /** * Fast forwards this Particle Emitter and all of its particles. @@ -2765,7 +2763,7 @@ var ParticleEmitter = new Class({ * * @return {this} This Particle Emitter. */ - fastForward: function (time, delta) + fastForward(time, delta) { if (delta === undefined) { delta = 1000 / 60; } @@ -2783,7 +2781,7 @@ var ParticleEmitter = new Class({ this.skipping = false; return this; - }, + } /** * Updates this emitter and its particles. @@ -2795,7 +2793,7 @@ var ParticleEmitter = new Class({ * @param {number} 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. */ - preUpdate: function (time, delta) + preUpdate(time, delta) { // Scale the delta delta *= this.timeScale; @@ -2907,7 +2905,7 @@ var ParticleEmitter = new Class({ this.stop(); } } - }, + } /** * Takes either a Rectangle Geometry object or an Arcade Physics Body and tests @@ -2923,7 +2921,7 @@ var ParticleEmitter = new Class({ * * @return {Phaser.GameObjects.Particles.Particle[]} An array of Particles that overlap with the given target. */ - overlap: function (target) + overlap(target) { var matrix = this.getWorldTransformMatrix(); @@ -2943,7 +2941,7 @@ var ParticleEmitter = new Class({ } return output; - }, + } /** * Returns a bounds Rectangle calculated from the bounds of all currently @@ -2973,7 +2971,7 @@ var ParticleEmitter = new Class({ * * @return {Phaser.Geom.Rectangle} A Rectangle containing the calculated bounds of this Emitter. */ - getBounds: function (padding, advance, delta, output) + getBounds(padding, advance, delta, output) { if (padding === undefined) { padding = 0; } if (advance === undefined) { advance = 0; } @@ -3045,7 +3043,7 @@ var ParticleEmitter = new Class({ } return output; - }, + } /** * Prints a warning to the console if you mistakenly call this function @@ -3054,10 +3052,10 @@ var ParticleEmitter = new Class({ * @method Phaser.GameObjects.Particles.ParticleEmitter#createEmitter * @since 3.60.0 */ - createEmitter: function () + createEmitter() { throw new Error('createEmitter removed. See ParticleEmitter docs for info'); - }, + } /** * The x coordinate the particles are emitted from. @@ -3071,19 +3069,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType|Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType} * @since 3.60.0 */ - particleX: { - - get: function () - { - return this.ops.x.current; - }, - set: function (value) - { - this.ops.x.onChange(value); - } + get particleX() + { + return this.ops.x.current; + } - }, + set particleX(value) + { + this.ops.x.onChange(value); + } /** * The y coordinate the particles are emitted from. @@ -3097,19 +3092,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType|Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType} * @since 3.60.0 */ - particleY: { - - get: function () - { - return this.ops.y.current; - }, - set: function (value) - { - this.ops.y.onChange(value); - } + get particleY() + { + return this.ops.y.current; + } - }, + set particleY(value) + { + this.ops.y.onChange(value); + } /** * The horizontal acceleration applied to emitted particles, in pixels per second squared. @@ -3121,19 +3113,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - accelerationX: { - - get: function () - { - return this.ops.accelerationX.current; - }, - set: function (value) - { - this.ops.accelerationX.onChange(value); - } + get accelerationX() + { + return this.ops.accelerationX.current; + } - }, + set accelerationX(value) + { + this.ops.accelerationX.onChange(value); + } /** * The vertical acceleration applied to emitted particles, in pixels per second squared. @@ -3145,19 +3134,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - accelerationY: { - - get: function () - { - return this.ops.accelerationY.current; - }, - set: function (value) - { - this.ops.accelerationY.onChange(value); - } + get accelerationY() + { + return this.ops.accelerationY.current; + } - }, + set accelerationY(value) + { + this.ops.accelerationY.onChange(value); + } /** * The maximum horizontal velocity emitted particles can reach, in pixels per second squared. @@ -3170,19 +3156,16 @@ var ParticleEmitter = new Class({ * @since 3.60.0 * @default 10000 */ - maxVelocityX: { - get: function () - { - return this.ops.maxVelocityX.current; - }, - - set: function (value) - { - this.ops.maxVelocityX.onChange(value); - } + get maxVelocityX() + { + return this.ops.maxVelocityX.current; + } - }, + set maxVelocityX(value) + { + this.ops.maxVelocityX.onChange(value); + } /** * The maximum vertical velocity emitted particles can reach, in pixels per second squared. @@ -3195,19 +3178,16 @@ var ParticleEmitter = new Class({ * @since 3.60.0 * @default 10000 */ - maxVelocityY: { - get: function () - { - return this.ops.maxVelocityY.current; - }, - - set: function (value) - { - this.ops.maxVelocityY.onChange(value); - } + get maxVelocityY() + { + return this.ops.maxVelocityY.current; + } - }, + set maxVelocityY(value) + { + this.ops.maxVelocityY.onChange(value); + } /** * The initial speed of emitted particles, in pixels per second. @@ -3224,20 +3204,17 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - speed: { - get: function () - { - return this.ops.speedX.current; - }, - - set: function (value) - { - this.ops.speedX.onChange(value); - this.ops.speedY.onChange(value); - } + get speed() + { + return this.ops.speedX.current; + } - }, + set speed(value) + { + this.ops.speedX.onChange(value); + this.ops.speedY.onChange(value); + } /** * The initial horizontal speed of emitted particles, in pixels per second. @@ -3249,19 +3226,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - speedX: { - get: function () - { - return this.ops.speedX.current; - }, - - set: function (value) - { - this.ops.speedX.onChange(value); - } + get speedX() + { + return this.ops.speedX.current; + } - }, + set speedX(value) + { + this.ops.speedX.onChange(value); + } /** * The initial vertical speed of emitted particles, in pixels per second. @@ -3273,19 +3247,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - speedY: { - get: function () - { - return this.ops.speedY.current; - }, - - set: function (value) - { - this.ops.speedY.onChange(value); - } + get speedY() + { + return this.ops.speedY.current; + } - }, + set speedY(value) + { + this.ops.speedY.onChange(value); + } /** * The x coordinate emitted particles move toward, when {@link Phaser.GameObjects.Particles.ParticleEmitter#moveTo} is true. @@ -3297,19 +3268,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - moveToX: { - - get: function () - { - return this.ops.moveToX.current; - }, - set: function (value) - { - this.ops.moveToX.onChange(value); - } + get moveToX() + { + return this.ops.moveToX.current; + } - }, + set moveToX(value) + { + this.ops.moveToX.onChange(value); + } /** * The y coordinate emitted particles move toward, when {@link Phaser.GameObjects.Particles.ParticleEmitter#moveTo} is true. @@ -3321,19 +3289,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - moveToY: { - get: function () - { - return this.ops.moveToY.current; - }, - - set: function (value) - { - this.ops.moveToY.onChange(value); - } + get moveToY() + { + return this.ops.moveToY.current; + } - }, + set moveToY(value) + { + this.ops.moveToY.onChange(value); + } /** * The amount of velocity particles will use when rebounding off the @@ -3347,19 +3312,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - bounce: { - - get: function () - { - return this.ops.bounce.current; - }, - set: function (value) - { - this.ops.bounce.onChange(value); - } + get bounce() + { + return this.ops.bounce.current; + } - }, + set bounce(value) + { + this.ops.bounce.onChange(value); + } /** * The horizontal scale of emitted particles. @@ -3373,19 +3335,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - particleScaleX: { - - get: function () - { - return this.ops.scaleX.current; - }, - set: function (value) - { - this.ops.scaleX.onChange(value); - } + get particleScaleX() + { + return this.ops.scaleX.current; + } - }, + set particleScaleX(value) + { + this.ops.scaleX.onChange(value); + } /** * The vertical scale of emitted particles. @@ -3399,19 +3358,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - particleScaleY: { - - get: function () - { - return this.ops.scaleY.current; - }, - set: function (value) - { - this.ops.scaleY.onChange(value); - } + get particleScaleY() + { + return this.ops.scaleY.current; + } - }, + set particleScaleY(value) + { + this.ops.scaleY.onChange(value); + } /** * A color tint value that is applied to the texture of the emitted @@ -3438,19 +3394,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - particleColor: { - - get: function () - { - return this.ops.color.current; - }, - set: function (value) - { - this.ops.color.onChange(value); - } + get particleColor() + { + return this.ops.color.current; + } - }, + set particleColor(value) + { + this.ops.color.onChange(value); + } /** * Controls the easing function used when you have created an @@ -3464,19 +3417,16 @@ var ParticleEmitter = new Class({ * @type {string} * @since 3.60.0 */ - colorEase: { - - get: function () - { - return this.ops.color.easeName; - }, - set: function (value) - { - this.ops.color.setEase(value); - } + get colorEase() + { + return this.ops.color.easeName; + } - }, + set colorEase(value) + { + this.ops.color.setEase(value); + } /** * A color tint value that is applied to the texture of the emitted @@ -3500,19 +3450,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - particleTint: { - - get: function () - { - return this.ops.tint.current; - }, - set: function (value) - { - this.ops.tint.onChange(value); - } + get particleTint() + { + return this.ops.tint.current; + } - }, + set particleTint(value) + { + this.ops.tint.onChange(value); + } /** * The alpha value of the emitted particles. This is a value @@ -3527,19 +3474,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - particleAlpha: { - - get: function () - { - return this.ops.alpha.current; - }, - set: function (value) - { - this.ops.alpha.onChange(value); - } + get particleAlpha() + { + return this.ops.alpha.current; + } - }, + set particleAlpha(value) + { + this.ops.alpha.onChange(value); + } /** * The lifespan of the emitted particles. This value is given @@ -3553,19 +3497,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - lifespan: { - get: function () - { - return this.ops.lifespan.current; - }, - - set: function (value) - { - this.ops.lifespan.onChange(value); - } + get lifespan() + { + return this.ops.lifespan.current; + } - }, + set lifespan(value) + { + this.ops.lifespan.onChange(value); + } /** * The angle at which the particles are emitted. The values are @@ -3580,19 +3521,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - particleAngle: { - - get: function () - { - return this.ops.angle.current; - }, - set: function (value) - { - this.ops.angle.onChange(value); - } + get particleAngle() + { + return this.ops.angle.current; + } - }, + set particleAngle(value) + { + this.ops.angle.onChange(value); + } /** * The rotation (or angle) of each particle when it is emitted. @@ -3607,19 +3545,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - particleRotate: { - - get: function () - { - return this.ops.rotate.current; - }, - set: function (value) - { - this.ops.rotate.onChange(value); - } + get particleRotate() + { + return this.ops.rotate.current; + } - }, + set particleRotate(value) + { + this.ops.rotate.onChange(value); + } /** * The number of particles that are emitted each time an emission @@ -3636,19 +3571,16 @@ var ParticleEmitter = new Class({ * @see Phaser.GameObjects.Particles.ParticleEmitter#setQuantity * @since 3.60.0 */ - quantity: { - - get: function () - { - return this.ops.quantity.current; - }, - set: function (value) - { - this.ops.quantity.onChange(value); - } + get quantity() + { + return this.ops.quantity.current; + } - }, + set quantity(value) + { + this.ops.quantity.onChange(value); + } /** * The number of milliseconds to wait after emission before @@ -3663,19 +3595,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - delay: { - - get: function () - { - return this.ops.delay.current; - }, - set: function (value) - { - this.ops.delay.onChange(value); - } + get delay() + { + return this.ops.delay.current; + } - }, + set delay(value) + { + this.ops.delay.onChange(value); + } /** * The number of milliseconds to wait after a particle has finished @@ -3693,19 +3622,16 @@ var ParticleEmitter = new Class({ * @type {Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType} * @since 3.60.0 */ - hold: { - - get: function () - { - return this.ops.hold.current; - }, - set: function (value) - { - this.ops.hold.onChange(value); - } + get hold() + { + return this.ops.hold.current; + } - }, + set hold(value) + { + this.ops.hold.onChange(value); + } /** * The internal flow counter. @@ -3716,19 +3642,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - flowCounter: { - - get: function () - { - return this.counters[0]; - }, - set: function (value) - { - this.counters[0] = value; - } + get flowCounter() + { + return this.counters[0]; + } - }, + set flowCounter(value) + { + this.counters[0] = value; + } /** * The internal frame counter. @@ -3739,19 +3662,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - frameCounter: { - - get: function () - { - return this.counters[1]; - }, - set: function (value) - { - this.counters[1] = value; - } + get frameCounter() + { + return this.counters[1]; + } - }, + set frameCounter(value) + { + this.counters[1] = value; + } /** * The internal animation counter. @@ -3762,19 +3682,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - animCounter: { - - get: function () - { - return this.counters[2]; - }, - set: function (value) - { - this.counters[2] = value; - } + get animCounter() + { + return this.counters[2]; + } - }, + set animCounter(value) + { + this.counters[2] = value; + } /** * The internal elasped counter. @@ -3785,19 +3702,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - elapsed: { - - get: function () - { - return this.counters[3]; - }, - set: function (value) - { - this.counters[3] = value; - } + get elapsed() + { + return this.counters[3]; + } - }, + set elapsed(value) + { + this.counters[3] = value; + } /** * The internal stop counter. @@ -3808,19 +3722,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - stopCounter: { - get: function () - { - return this.counters[4]; - }, - - set: function (value) - { - this.counters[4] = value; - } + get stopCounter() + { + return this.counters[4]; + } - }, + set stopCounter(value) + { + this.counters[4] = value; + } /** * The internal complete flag. @@ -3831,19 +3742,16 @@ var ParticleEmitter = new Class({ * @type {boolean} * @since 3.60.0 */ - completeFlag: { - get: function () - { - return this.counters[5]; - }, - - set: function (value) - { - this.counters[5] = value; - } + get completeFlag() + { + return this.counters[5]; + } - }, + set completeFlag(value) + { + this.counters[5] = value; + } /** * The internal zone index. @@ -3854,19 +3762,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - zoneIndex: { - get: function () - { - return this.counters[6]; - }, - - set: function (value) - { - this.counters[6] = value; - } + get zoneIndex() + { + return this.counters[6]; + } - }, + set zoneIndex(value) + { + this.counters[6] = value; + } /** * The internal zone total. @@ -3877,19 +3782,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - zoneTotal: { - get: function () - { - return this.counters[7]; - }, - - set: function (value) - { - this.counters[7] = value; - } + get zoneTotal() + { + return this.counters[7]; + } - }, + set zoneTotal(value) + { + this.counters[7] = value; + } /** * The current frame index. @@ -3900,19 +3802,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - currentFrame: { - get: function () - { - return this.counters[8]; - }, - - set: function (value) - { - this.counters[8] = value; - } + get currentFrame() + { + return this.counters[8]; + } - }, + set currentFrame(value) + { + this.counters[8] = value; + } /** * The current animation index. @@ -3923,19 +3822,16 @@ var ParticleEmitter = new Class({ * @type {number} * @since 3.60.0 */ - currentAnim: { - get: function () - { - return this.counters[9]; - }, - - set: function (value) - { - this.counters[9] = value; - } + get currentAnim() + { + return this.counters[9]; + } - }, + set currentAnim(value) + { + this.counters[9] = value; + } /** * Destroys this Particle Emitter and all Particles it owns. @@ -3943,7 +3839,7 @@ var ParticleEmitter = new Class({ * @method Phaser.GameObjects.Particles.ParticleEmitter#preDestroy * @since 3.60.0 */ - preDestroy: function () + preDestroy() { this.texture = null; this.frames = null; @@ -3985,6 +3881,6 @@ var ParticleEmitter = new Class({ this.worldMatrix.destroy(); } -}); +}; module.exports = ParticleEmitter; diff --git a/src/gameobjects/particles/ParticleProcessor.js b/src/gameobjects/particles/ParticleProcessor.js index 06f236d0ed..a0430eb542 100644 --- a/src/gameobjects/particles/ParticleProcessor.js +++ b/src/gameobjects/particles/ParticleProcessor.js @@ -24,11 +24,9 @@ var Class = require('../../utils/Class'); * @param {number} [y=0] - The y coordinate of the Particle Processor, in world space. * @param {boolean} [active=true] - The active state of this Particle Processor. */ -var ParticleProcessor = new Class({ +var ParticleProcessor = class { - initialize: - - function ParticleProcessor (x, y, active) + constructor(x, y, active) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -74,7 +72,7 @@ var ParticleProcessor = new Class({ * @since 3.60.0 */ this.active = active; - }, + } /** * The Particle Processor update method should be overriden by your own @@ -89,9 +87,9 @@ var ParticleProcessor = new Class({ * @param {number} step - The delta value divided by 1000. * @param {number} t - The current normalized lifetime of the particle, between 0 (birth) and 1 (death). */ - update: function () + update() { - }, + } /** * Destroys this Particle Processor by removing all external references. @@ -101,11 +99,11 @@ var ParticleProcessor = new Class({ * @method Phaser.GameObjects.Particles.ParticleProcessor#destroy * @since 3.60.0 */ - destroy: function () + destroy() { this.emitter = null; } -}); +}; module.exports = ParticleProcessor; diff --git a/src/gameobjects/particles/zones/DeathZone.js b/src/gameobjects/particles/zones/DeathZone.js index 0bd6978cb8..3ade477da3 100644 --- a/src/gameobjects/particles/zones/DeathZone.js +++ b/src/gameobjects/particles/zones/DeathZone.js @@ -23,11 +23,9 @@ var Class = require('../../../utils/Class'); * @param {Phaser.Types.GameObjects.Particles.DeathZoneSource} source - An object instance that has a `contains` method that returns a boolean when given `x` and `y` arguments. * @param {boolean} killOnEnter - Should the Particle be killed when it enters the zone? `true` or leaves it? `false` */ -var DeathZone = new Class({ +var DeathZone = class { - initialize: - - function DeathZone (source, killOnEnter) + constructor(source, killOnEnter) { /** * An object instance that has a `contains` method that returns a boolean when given `x` and `y` arguments. @@ -48,7 +46,7 @@ var DeathZone = new Class({ * @since 3.0.0 */ this.killOnEnter = killOnEnter; - }, + } /** * Checks if the given Particle will be killed or not by this zone. @@ -60,7 +58,7 @@ var DeathZone = new Class({ * * @return {boolean} Return `true` if the Particle is to be killed, otherwise return `false`. */ - willKill: function (particle) + willKill(particle) { var pos = particle.worldPosition; var withinZone = this.source.contains(pos.x, pos.y); @@ -68,6 +66,6 @@ var DeathZone = new Class({ return (withinZone && this.killOnEnter || !withinZone && !this.killOnEnter); } -}); +}; module.exports = DeathZone; diff --git a/src/gameobjects/particles/zones/EdgeZone.js b/src/gameobjects/particles/zones/EdgeZone.js index 9701588b6d..09cd7d651e 100644 --- a/src/gameobjects/particles/zones/EdgeZone.js +++ b/src/gameobjects/particles/zones/EdgeZone.js @@ -22,11 +22,9 @@ var Class = require('../../../utils/Class'); * @param {boolean} [seamless=true] - Whether one endpoint will be removed if it's identical to the other. * @param {number} [total=-1] - The total number of particles this zone will emit before passing over to the next emission zone in the Emitter. -1 means it will never pass over and you must use `setEmitZone` to change it. */ -var EdgeZone = new Class({ +var EdgeZone = class { - initialize: - - function EdgeZone (source, quantity, stepRate, yoyo, seamless, total) + constructor(source, quantity, stepRate, yoyo, seamless, total) { if (yoyo === undefined) { yoyo = false; } if (seamless === undefined) { seamless = true; } @@ -140,7 +138,7 @@ var EdgeZone = new Class({ this.total = total; this.updateSource(); - }, + } /** * Update the {@link Phaser.GameObjects.Particles.Zones.EdgeZone#points} from the EdgeZone's @@ -153,7 +151,7 @@ var EdgeZone = new Class({ * * @return {this} This Edge Zone. */ - updateSource: function () + updateSource() { this.points = this.source.getPoints(this.quantity, this.stepRate); @@ -180,7 +178,7 @@ var EdgeZone = new Class({ } return this; - }, + } /** * Change the source of the EdgeZone. @@ -192,12 +190,12 @@ var EdgeZone = new Class({ * * @return {this} This Edge Zone. */ - changeSource: function (source) + changeSource(source) { this.source = source; return this.updateSource(); - }, + } /** * Get the next point in the Zone and set its coordinates on the given Particle. @@ -207,7 +205,7 @@ var EdgeZone = new Class({ * * @param {Phaser.GameObjects.Particles.Particle} particle - The Particle. */ - getPoint: function (particle) + getPoint(particle) { if (this._direction === 0) { @@ -253,6 +251,6 @@ var EdgeZone = new Class({ } } -}); +}; module.exports = EdgeZone; diff --git a/src/gameobjects/particles/zones/RandomZone.js b/src/gameobjects/particles/zones/RandomZone.js index d31ac2e89d..83a7d30b7b 100644 --- a/src/gameobjects/particles/zones/RandomZone.js +++ b/src/gameobjects/particles/zones/RandomZone.js @@ -18,11 +18,9 @@ var Vector2 = require('../../../math/Vector2'); * * @param {Phaser.Types.GameObjects.Particles.RandomZoneSource} source - An object instance with a `getRandomPoint(point)` method. */ -var RandomZone = new Class({ +var RandomZone = class { - initialize: - - function RandomZone (source) + constructor(source) { /** * An object instance with a `getRandomPoint(point)` method. @@ -60,7 +58,7 @@ var RandomZone = new Class({ * @since 3.60.0 */ this.total = -1; - }, + } /** * Get the next point in the Zone and set its coordinates on the given Particle. @@ -70,7 +68,7 @@ var RandomZone = new Class({ * * @param {Phaser.GameObjects.Particles.Particle} particle - The Particle. */ - getPoint: function (particle) + getPoint(particle) { var vec = this._tempVec; @@ -80,6 +78,6 @@ var RandomZone = new Class({ particle.y = vec.y; } -}); +}; module.exports = RandomZone; diff --git a/src/gameobjects/pathfollower/PathFollower.js b/src/gameobjects/pathfollower/PathFollower.js index 2d3884e8c3..82b3e31cd6 100644 --- a/src/gameobjects/pathfollower/PathFollower.js +++ b/src/gameobjects/pathfollower/PathFollower.js @@ -36,22 +36,21 @@ var Sprite = require('../sprite/Sprite'); * @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with. */ -var PathFollower = new Class({ +var PathFollower = class extends Sprite { - Extends: Sprite, - - Mixins: [ - Components.PathFollower - ], - - initialize: + static + { + Class.mixin(this, [ + Components.PathFollower + ], false); + } - function PathFollower (scene, path, x, y, texture, frame) + constructor(scene, path, x, y, texture, frame) { - Sprite.call(this, scene, x, y, texture, frame); + super(scene, x, y, texture, frame); this.path = path; - }, + } /** * Internal update handler that advances this PathFollower along the path. @@ -65,12 +64,12 @@ var PathFollower = new Class({ * @param {number} 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. */ - preUpdate: function (time, delta) + preUpdate(time, delta) { this.anims.update(time, delta); this.pathUpdate(time); } -}); +}; module.exports = PathFollower; diff --git a/src/gameobjects/pointlight/PointLight.js b/src/gameobjects/pointlight/PointLight.js index 182aa62dc5..6add99d067 100644 --- a/src/gameobjects/pointlight/PointLight.js +++ b/src/gameobjects/pointlight/PointLight.js @@ -61,32 +61,31 @@ var Render = require('./PointLightRender'); * @param {number} [intensity=1] - The intensity, or color blend, of the Point Light. * @param {number} [attenuation=0.1] - The attenuation of the Point Light. This is the reduction of light from the center point. */ -var PointLight = new Class({ +var PointLight = class extends GameObject { - Extends: GameObject, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.Depth, - Components.Mask, - Components.RenderNodes, - Components.ScrollFactor, - Components.Transform, - Components.Visible, - Render - ], - - initialize: + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.Depth, + Components.Mask, + Components.RenderNodes, + Components.ScrollFactor, + Components.Transform, + Components.Visible, + Render + ], false); + } - function PointLight (scene, x, y, color, radius, intensity, attenuation) + constructor(scene, x, y, color, radius, intensity, attenuation) { if (color === undefined) { color = 0xffffff; } if (radius === undefined) { radius = 128; } if (intensity === undefined) { intensity = 1; } if (attenuation === undefined) { attenuation = 0.1; } - GameObject.call(this, scene, 'PointLight'); + super(scene, 'PointLight'); this.initRenderNodes(this._defaultRenderNodesMap); @@ -132,7 +131,7 @@ var PointLight = new Class({ this.height = radius * 2; this._radius = radius; - }, + } /** * The default render nodes for this Game Object. @@ -144,12 +143,11 @@ var PointLight = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultPointLightNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultPointLightNodes; + } /** * The radius of the Point Light. @@ -158,58 +156,43 @@ var PointLight = new Class({ * @type {number} * @since 3.50.0 */ - radius: { - - get: function () - { - return this._radius; - }, - - set: function (value) - { - this._radius = value; - this.width = value * 2; - this.height = value * 2; - } - - }, - - originX: { - get: function () - { - return 0.5; - } - - }, + get radius() + { + return this._radius; + } - originY: { + set radius(value) + { + this._radius = value; + this.width = value * 2; + this.height = value * 2; + } - get: function () - { - return 0.5; - } - }, + get originX() + { + return 0.5; + } - displayOriginX: { - get: function () - { - return this._radius; - } + get originY() + { + return 0.5; + } - }, - displayOriginY: { + get displayOriginX() + { + return this._radius; + } - get: function () - { - return this._radius; - } + get displayOriginY() + { + return this._radius; } -}); +}; module.exports = PointLight; diff --git a/src/gameobjects/rendertexture/RenderTexture.js b/src/gameobjects/rendertexture/RenderTexture.js index e0bccef6da..2d6fa516e9 100644 --- a/src/gameobjects/rendertexture/RenderTexture.js +++ b/src/gameobjects/rendertexture/RenderTexture.js @@ -60,17 +60,16 @@ var RenderTextureRenderModes = require('./RenderTextureRenderModes'); * @param {number} [height=32] - The height of the Render Texture. * @param {boolean} [forceEven=true] - Force the given width and height to be rounded to even values. This significantly improves the rendering quality. Set to false if you know you need an odd sized texture. */ -var RenderTexture = new Class({ +var RenderTexture = class extends Image { - Extends: Image, - - Mixins: [ - RenderTextureRender - ], - - initialize: + static + { + Class.mixin(this, [ + RenderTextureRender + ], false); + } - function RenderTexture (scene, x, y, width, height, forceEven) + constructor(scene, x, y, width, height, forceEven) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -80,7 +79,7 @@ var RenderTexture = new Class({ var dynamicTexture = scene.sys.textures.addDynamicTexture(UUID(), width, height, forceEven); - Image.call(this, scene, x, y, dynamicTexture); + super(scene, x, y, dynamicTexture); this.type = 'RenderTexture'; @@ -138,7 +137,7 @@ var RenderTexture = new Class({ * @since 4.0.0 */ this.isCurrentlyRendering = false; - }, + } /** * Sets the internal size of this Render Texture, as used for frame or physics body creation. @@ -160,7 +159,7 @@ var RenderTexture = new Class({ * * @return {this} This Game Object instance. */ - setSize: function (width, height) + setSize(width, height) { this.width = width; this.height = height; @@ -176,7 +175,7 @@ var RenderTexture = new Class({ } return this; - }, + } /** * Resizes the Render Texture to the new dimensions given. @@ -200,14 +199,14 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture. */ - resize: function (width, height, forceEven) + resize(width, height, forceEven) { this.texture.setSize(width, height, forceEven); this.setSize(this.texture.width, this.texture.height); return this; - }, + } /** * Stores a copy of this Render Texture in the Texture Manager using the given key. @@ -244,7 +243,7 @@ var RenderTexture = new Class({ * * @return {Phaser.Textures.DynamicTexture} The Texture that was saved. */ - saveTexture: function (key) + saveTexture(key) { var texture = this.texture; @@ -256,7 +255,7 @@ var RenderTexture = new Class({ } return texture; - }, + } /** * Set the `renderMode` of this Render Texture. @@ -274,7 +273,7 @@ var RenderTexture = new Class({ * @param {boolean} [preserve=false] - Whether to call `preserve(true)` to preserve the current command buffer. * @returns {this} This Render Texture instance. */ - setRenderMode: function (mode, preserve) + setRenderMode(mode, preserve) { this.renderMode = mode; @@ -284,7 +283,7 @@ var RenderTexture = new Class({ } return this; - }, + } /** * Render the buffered drawing commands to this Dynamic Texture. @@ -293,12 +292,12 @@ var RenderTexture = new Class({ * @method Phaser.GameObjects.RenderTexture#render * @since 4.0.0 */ - render: function () + render() { this.texture.render(); return this; - }, + } /** * Fills this Render Texture with the given color. @@ -320,12 +319,12 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - fill: function (rgb, alpha, x, y, width, height) + fill(rgb, alpha, x, y, width, height) { this.texture.fill(rgb, alpha, x, y, width, height); return this; - }, + } /** * Clears a portion or everything from this Render Texture by erasing it and resetting it back to @@ -341,12 +340,12 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - clear: function (x, y, width, height) + clear(x, y, width, height) { this.texture.clear(x, y, width, height); return this; - }, + } /** * Takes the given texture key and frame and then stamps it at the given @@ -372,12 +371,12 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - stamp: function (key, frame, x, y, config) + stamp(key, frame, x, y, config) { this.texture.stamp(key, frame, x, y, config); return this; - }, + } /** * Draws the given object, or an array of objects, to this Render Texture using a blend mode of ERASE. @@ -395,12 +394,12 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - erase: function (entries, x, y) + erase(entries, x, y) { this.texture.erase(entries, x, y); return this; - }, + } /** * Draws the given object, or an array of objects, to this RenderTexture. @@ -452,12 +451,12 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - draw: function (entries, x, y, alpha, tint) + draw(entries, x, y, alpha, tint) { this.texture.draw(entries, x, y, alpha, tint); return this; - }, + } /** * Draws the given object to this Render Texture. @@ -472,12 +471,12 @@ var RenderTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - capture: function (entry, config) + capture(entry, config) { this.texture.capture(entry, config); return this; - }, + } /** * Takes the given Texture Frame and draws it to this Dynamic Texture as a fill pattern, @@ -507,12 +506,12 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - repeat: function (key, frame, x, y, width, height, config) + repeat(key, frame, x, y, width, height, config) { this.texture.repeat(key, frame, x, y, width, height, config); return this; - }, + } /** * Sets the preserve flag for this Dynamic Texture. @@ -528,12 +527,12 @@ var RenderTexture = new Class({ * @param {boolean} preserve - Whether to preserve the command buffer after rendering. * @returns {this} This Render Texture instance. */ - preserve: function (preserve) + preserve(preserve) { this.texture.preserve(preserve); return this; - }, + } /** * Adds a callback to run during the render process. @@ -547,12 +546,12 @@ var RenderTexture = new Class({ * @param {Function} callback - A callback function to run during the render process. * @returns {this} This Render Texture instance. */ - callback: function (callback) + callback(callback) { this.texture.callback(callback); return this; - }, + } /** * Takes a snapshot of the given area of this Render Texture. @@ -582,12 +581,12 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - snapshotArea: function (x, y, width, height, callback, type, encoderOptions) + snapshotArea(x, y, width, height, callback, type, encoderOptions) { this.texture.snapshotArea(x, y, width, height, callback, type, encoderOptions); return this; - }, + } /** * Takes a snapshot of the whole of this Render Texture. @@ -613,10 +612,10 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - snapshot: function (callback, type, encoderOptions) + snapshot(callback, type, encoderOptions) { return this.texture.snapshot(callback, type, encoderOptions); - }, + } /** * Takes a snapshot of the given pixel from this Render Texture. @@ -639,10 +638,10 @@ var RenderTexture = new Class({ * * @return {this} This Render Texture instance. */ - snapshotPixel: function (x, y, callback) + snapshotPixel(x, y, callback) { return this.texture.snapshotPixel(x, y, callback); - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -651,7 +650,7 @@ var RenderTexture = new Class({ * @protected * @since 3.9.0 */ - preDestroy: function () + preDestroy() { this.camera = null; @@ -661,6 +660,6 @@ var RenderTexture = new Class({ } } -}); +}; module.exports = RenderTexture; diff --git a/src/gameobjects/rope/Rope.js b/src/gameobjects/rope/Rope.js index e0dcdf9f2d..c33f292782 100644 --- a/src/gameobjects/rope/Rope.js +++ b/src/gameobjects/rope/Rope.js @@ -58,34 +58,33 @@ var Vector2 = require('../../math/Vector2'); * @param {number[]} [colors] - An optional array containing the color data for this Rope. You should provide one color value per pair of vertices. * @param {number[]} [alphas] - An optional array containing the alpha data for this Rope. You should provide one alpha value per pair of vertices. */ -var Rope = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.Depth, - Components.Flip, - Components.Mask, - Components.RenderNodes, - Components.Size, - Components.Texture, - Components.Transform, - Components.Visible, - Components.ScrollFactor, - RopeRender - ], - - initialize: - - function Rope (scene, x, y, texture, frame, points, horizontal, colors, alphas) +var Rope = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.Depth, + Components.Flip, + Components.Mask, + Components.RenderNodes, + Components.Size, + Components.Texture, + Components.Transform, + Components.Visible, + Components.ScrollFactor, + RopeRender + ], false); + } + + constructor(scene, x, y, texture, frame, points, horizontal, colors, alphas) { if (texture === undefined) { texture = '__DEFAULT'; } if (points === undefined) { points = 2; } if (horizontal === undefined) { horizontal = true; } - GameObject.call(this, scene, 'Rope'); + super(scene, 'Rope'); /** * The Animation State of this Rope. @@ -288,7 +287,7 @@ var Rope = new Class({ this.setPoints(points, colors, alphas); this.updateVertices(); - }, + } /** * The default render nodes for this Game Object. @@ -300,24 +299,23 @@ var Rope = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultRopeNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultRopeNodes; + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } /** * The Rope update loop. @@ -329,7 +327,7 @@ var Rope = new Class({ * @param {number} time - The current timestamp. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ - preUpdate: function (time, delta) + preUpdate(time, delta) { var prevFrame = this.anims.currentFrame; @@ -340,7 +338,7 @@ var Rope = new Class({ this.updateUVs(); this.updateVertices(); } - }, + } /** * Start playing the given animation. @@ -354,12 +352,12 @@ var Rope = new Class({ * * @return {this} This Game Object. */ - play: function (key, ignoreIfPlaying, startFrame) + play(key, ignoreIfPlaying, startFrame) { this.anims.play(key, ignoreIfPlaying, startFrame); return this; - }, + } /** * Flags this Rope as being dirty. A dirty rope will recalculate all of its vertices data @@ -371,12 +369,12 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - setDirty: function () + setDirty() { this.dirty = true; return this; - }, + } /** * Sets the alignment of the points in this Rope to be horizontal, in a strip format. @@ -393,7 +391,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - setHorizontal: function (points, colors, alphas) + setHorizontal(points, colors, alphas) { if (points === undefined) { points = this.points.length; } @@ -405,7 +403,7 @@ var Rope = new Class({ this.horizontal = true; return this.setPoints(points, colors, alphas); - }, + } /** * Sets the alignment of the points in this Rope to be vertical, in a column format. @@ -422,7 +420,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - setVertical: function (points, colors, alphas) + setVertical(points, colors, alphas) { if (points === undefined) { points = this.points.length; } @@ -434,7 +432,7 @@ var Rope = new Class({ this.horizontal = false; return this.setPoints(points, colors, alphas); - }, + } /** * Sets the tint fill mode. @@ -456,14 +454,14 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - setTintFill: function (value) + setTintFill(value) { if (value === undefined) { value = false; } this.tintFill = value; return this; - }, + } /** * Set the alpha values used by the Rope during rendering. @@ -491,7 +489,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - setAlphas: function (alphas, bottomAlpha) + setAlphas(alphas, bottomAlpha) { var total = this.points.length; @@ -562,7 +560,7 @@ var Rope = new Class({ return this; - }, + } /** * Set the color values used by the Rope during rendering. @@ -588,7 +586,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - setColors: function (colors) + setColors(colors) { var total = this.points.length; @@ -647,7 +645,7 @@ var Rope = new Class({ } return this; - }, + } /** * Sets the points used by this Rope. @@ -690,7 +688,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - setPoints: function (points, colors, alphas) + setPoints(points, colors, alphas) { if (points === undefined) { points = 2; } @@ -769,7 +767,7 @@ var Rope = new Class({ } return this; - }, + } /** * Updates all of the UVs based on the Rope.points and `flipX` and `flipY` settings. @@ -779,7 +777,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - updateUVs: function () + updateUVs() { var currentUVs = this.uv; var total = this.points.length; @@ -857,7 +855,7 @@ var Rope = new Class({ } return this; - }, + } /** * Resizes all of the internal arrays: `vertices`, `uv`, `colors` and `alphas` to the new @@ -870,7 +868,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - resizeArrays: function (newSize) + resizeArrays(newSize) { var colors = this.colors; var alphas = this.alphas; @@ -894,7 +892,7 @@ var Rope = new Class({ this.dirty = true; return this; - }, + } /** * Updates the vertices based on the Rope points. @@ -908,7 +906,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - updateVertices: function () + updateVertices() { var perp = this._perp; var points = this.points; @@ -962,7 +960,7 @@ var Rope = new Class({ } return this; - }, + } /** * This method enables rendering of the Rope vertices to the given Graphics instance. @@ -996,7 +994,7 @@ var Rope = new Class({ * * @return {this} This Game Object instance. */ - setDebug: function (graphic, callback) + setDebug(graphic, callback) { this.debugGraphic = graphic; @@ -1014,7 +1012,7 @@ var Rope = new Class({ } return this; - }, + } /** * The built-in Rope vertices debug rendering method. @@ -1028,7 +1026,7 @@ var Rope = new Class({ * @param {number} meshLength - The number of vertices in the mesh. * @param {number[]} verts - An array of translated vertex coordinates. */ - renderDebugVerts: function (src, meshLength, verts) + renderDebugVerts(src, meshLength, verts) { var graphic = src.debugGraphic; @@ -1056,7 +1054,7 @@ var Rope = new Class({ px1 = x1; py1 = y1; } - }, + } /** * Handles the pre-destroy step for the Rope, which removes the Animation component and typed arrays. @@ -1065,7 +1063,7 @@ var Rope = new Class({ * @private * @since 3.23.0 */ - preDestroy: function () + preDestroy() { this.anims.destroy(); @@ -1079,7 +1077,7 @@ var Rope = new Class({ this.debugCallback = null; this.debugGraphic = null; - }, + } /** * The horizontally flipped state of the Game Object. @@ -1093,21 +1091,18 @@ var Rope = new Class({ * @default false * @since 3.23.0 */ - flipX: { - get: function () - { - return this._flipX; - }, - - set: function (value) - { - this._flipX = value; + get flipX() + { + return this._flipX; + } - return this.updateUVs(); - } + set flipX(value) + { + this._flipX = value; - }, + return this.updateUVs(); + } /** * The vertically flipped state of the Game Object. @@ -1121,22 +1116,19 @@ var Rope = new Class({ * @default false * @since 3.23.0 */ - flipY: { - - get: function () - { - return this._flipY; - }, - set: function (value) - { - this._flipY = value; + get flipY() + { + return this._flipY; + } - return this.updateUVs(); - } + set flipY(value) + { + this._flipY = value; + return this.updateUVs(); } -}); +}; module.exports = Rope; diff --git a/src/gameobjects/shader/Shader.js b/src/gameobjects/shader/Shader.js index 4519fafed2..d961592861 100644 --- a/src/gameobjects/shader/Shader.js +++ b/src/gameobjects/shader/Shader.js @@ -99,22 +99,24 @@ var ShaderRender = require('./ShaderRender'); * @param {number} [height=128] - The height of the Game Object. * @param {string[]|Phaser.Textures.Texture[]} [textures] - The textures that the shader uses, if any. If you intend to define the textures later, use `'__DEFAULT'` as a placeholder, to avoid initialization errors. */ -var Shader = new Class({ - Extends: GameObject, - - Mixins: [ - Components.BlendMode, - Components.ComputedSize, - Components.Depth, - Components.GetBounds, - Components.Origin, - Components.ScrollFactor, - Components.Transform, - Components.Visible, - ShaderRender - ], - - initialize: function Shader (scene, config, x, y, width, height, textures) +var Shader = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.BlendMode, + Components.ComputedSize, + Components.Depth, + Components.GetBounds, + Components.Origin, + Components.ScrollFactor, + Components.Transform, + Components.Visible, + ShaderRender + ], false); + } + + constructor(scene, config, x, y, width, height, textures) { if (config === undefined) { config = {}; } if (typeof config === 'string') @@ -126,7 +128,7 @@ var Shader = new Class({ if (width === undefined) { width = 128; } if (height === undefined) { height = 128; } - GameObject.call(this, scene, 'Shader'); + super(scene, 'Shader'); var renderer = scene.sys.renderer; @@ -246,7 +248,7 @@ var Shader = new Class({ this.setPosition(x, y); this.setSize(width, height); this.setOrigin(0.5, 0.5); - }, + } /** * Returns the current value of a uniform from the render node. @@ -263,10 +265,10 @@ var Shader = new Class({ * @param {string} name - The name of the uniform to get. * @return {any} The value of the uniform. */ - getUniform: function (name) + getUniform(name) { return this.renderNode.programManager.uniforms[name]; - }, + } /** * Set the textures that the shader uses. @@ -297,7 +299,7 @@ var Shader = new Class({ * @since 4.0.0 * @param {string[]|Phaser.Textures.Texture[]} [textures] - The textures that the shader uses. */ - setTextures: function (textures) + setTextures(textures) { if (textures === undefined) { textures = []; } @@ -314,7 +316,7 @@ var Shader = new Class({ } return this; - }, + } /** * Changes this Shader so instead of rendering to the display list @@ -366,7 +368,7 @@ var Shader = new Class({ * * @return {this} This Shader instance. */ - setRenderToTexture: function (key) + setRenderToTexture(key) { if (this.renderToTexture) { @@ -399,7 +401,7 @@ var Shader = new Class({ this.renderWebGLStep(renderer, this, this.drawingContext); return this; - }, + } /** * The function which sets uniforms for the shader. @@ -427,10 +429,10 @@ var Shader = new Class({ * @param {function} setUniform - The function which sets uniforms. `(name: string, value: any) => void`. * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - A reference to the current drawing context. */ - setupUniforms: function (setUniform, drawingContext) + setupUniforms(setUniform, drawingContext) { // NOOP - }, + } /** * A NOOP method so you can pass a Shader to a Container. @@ -441,10 +443,10 @@ var Shader = new Class({ * @since 3.17.0 * @return {this} This Shader instance. */ - setAlpha: function () + setAlpha() { return this; - }, + } /** * Set the texture coordinates of the shader. @@ -480,7 +482,7 @@ var Shader = new Class({ * @param {number} [bottomRightY=0] - The bottom-right y coordinate of the texture. * @return {this} This Shader instance */ - setTextureCoordinates: function ( + setTextureCoordinates( topLeftX, topLeftY, topRightX, topRightY, bottomLeftX, bottomLeftY, @@ -502,7 +504,7 @@ var Shader = new Class({ this.textureCoordinateBottomRight.set(bottomRightX, bottomRightY); return this; - }, + } /** * Set the texture coordinates of the shader from a frame. @@ -514,7 +516,7 @@ var Shader = new Class({ * @param {Phaser.Textures.Frame|string} frame - The frame to set the texture coordinates from. If a string is given, it will be used to look up the frame in the texture. * @param {Phaser.Textures.Texture|string} [texture] - The texture that the frame is from. This is only used if `frame` is a string. If a string is given, it will be used to look up the texture in the Texture Manager. If not given, the first member of `Shader.textures` is used. If `Shader.textures` is empty, an error will occur. */ - setTextureCoordinatesFromFrame: function (frame, texture) + setTextureCoordinatesFromFrame(frame, texture) { if (typeof frame === 'string') { @@ -535,7 +537,7 @@ var Shader = new Class({ var v1 = frame.v1; this.setTextureCoordinates(u0, v0, u1, v0, u0, v1, u1, v1); - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -544,7 +546,7 @@ var Shader = new Class({ * @protected * @since 3.17.0 */ - preDestroy: function () + preDestroy() { this.renderNode = null; @@ -563,6 +565,6 @@ var Shader = new Class({ this.texture = null; } } -}); +}; module.exports = Shader; diff --git a/src/gameobjects/shape/Shape.js b/src/gameobjects/shape/Shape.js index c31224088c..a5d93d50df 100644 --- a/src/gameobjects/shape/Shape.js +++ b/src/gameobjects/shape/Shape.js @@ -40,31 +40,30 @@ var Line = require('../../geom/line/Line'); * @param {string} [type] - The internal type of the Shape. * @param {any} [data] - The data of the source shape geometry, if any. */ -var Shape = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.AlphaSingle, - Components.BlendMode, - Components.Depth, - Components.GetBounds, - Components.Lighting, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.ScrollFactor, - Components.Transform, - Components.Visible - ], - - initialize: - - function Shape (scene, type, data) +var Shape = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.BlendMode, + Components.Depth, + Components.GetBounds, + Components.Lighting, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.ScrollFactor, + Components.Transform, + Components.Visible + ], false); + } + + constructor(scene, type, data) { if (type === undefined) { type = 'Shape'; } - GameObject.call(this, scene, type); + super(scene, type); /** * The source Shape data. Typically a geometry object. @@ -216,7 +215,7 @@ var Shape = new Class({ } this.initRenderNodes(this._defaultRenderNodesMap); - }, + } /** * The default render nodes for this Game Object. @@ -228,12 +227,11 @@ var Shape = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultGraphicsNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultGraphicsNodes; + } /** * Sets the fill color and alpha for this Shape. @@ -252,7 +250,7 @@ var Shape = new Class({ * * @return {this} This Game Object instance. */ - setFillStyle: function (color, alpha) + setFillStyle(color, alpha) { if (alpha === undefined) { alpha = 1; } @@ -268,7 +266,7 @@ var Shape = new Class({ } return this; - }, + } /** * Sets the stroke color and alpha for this Shape. @@ -288,7 +286,7 @@ var Shape = new Class({ * * @return {this} This Game Object instance. */ - setStrokeStyle: function (lineWidth, color, alpha) + setStrokeStyle(lineWidth, color, alpha) { if (alpha === undefined) { alpha = 1; } @@ -305,7 +303,7 @@ var Shape = new Class({ } return this; - }, + } /** * Sets if this Shape path is closed during rendering when stroked. @@ -320,12 +318,12 @@ var Shape = new Class({ * * @return {this} This Game Object instance. */ - setClosePath: function (value) + setClosePath(value) { this.closePath = value; return this; - }, + } /** * Sets the internal size of this Game Object, as used for frame or physics body creation. @@ -347,13 +345,13 @@ var Shape = new Class({ * * @return {this} This Game Object instance. */ - setSize: function (width, height) + setSize(width, height) { this.width = width; this.height = height; return this; - }, + } /** * Sets the display size of this Shape. @@ -368,13 +366,13 @@ var Shape = new Class({ * * @return {this} This Shape instance. */ - setDisplaySize: function (width, height) + setDisplaySize(width, height) { this.displayWidth = width; this.displayHeight = height; return this; - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -383,13 +381,13 @@ var Shape = new Class({ * @protected * @since 3.13.0 */ - preDestroy: function () + preDestroy() { this.geom = null; this._tempLine = null; this.pathData = []; this.pathIndexes = []; - }, + } /** * The displayed width of this Game Object. @@ -402,19 +400,16 @@ var Shape = new Class({ * @type {number} * @since 3.13.0 */ - displayWidth: { - get: function () - { - return this.scaleX * this.width; - }, - - set: function (value) - { - this.scaleX = value / this.width; - } + get displayWidth() + { + return this.scaleX * this.width; + } - }, + set displayWidth(value) + { + this.scaleX = value / this.width; + } /** * The displayed height of this Game Object. @@ -427,20 +422,17 @@ var Shape = new Class({ * @type {number} * @since 3.13.0 */ - displayHeight: { - get: function () - { - return this.scaleY * this.height; - }, - - set: function (value) - { - this.scaleY = value / this.height; - } + get displayHeight() + { + return this.scaleY * this.height; + } + set displayHeight(value) + { + this.scaleY = value / this.height; } -}); +}; module.exports = Shape; diff --git a/src/gameobjects/shape/arc/Arc.js b/src/gameobjects/shape/arc/Arc.js index 548f2bbc33..2e2d31fb77 100644 --- a/src/gameobjects/shape/arc/Arc.js +++ b/src/gameobjects/shape/arc/Arc.js @@ -46,17 +46,16 @@ var Shape = require('../Shape'); * @param {number} [fillColor] - The color the arc will be filled with, i.e. 0xff0000 for red. * @param {number} [fillAlpha] - The alpha the arc will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ -var Arc = new Class({ +var Arc = class extends Shape { - Extends: Shape, - - Mixins: [ - ArcRender - ], - - initialize: + static + { + Class.mixin(this, [ + ArcRender + ], false); + } - function Arc (scene, x, y, radius, startAngle, endAngle, anticlockwise, fillColor, fillAlpha) + constructor(scene, x, y, radius, startAngle, endAngle, anticlockwise, fillColor, fillAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -65,7 +64,7 @@ var Arc = new Class({ if (endAngle === undefined) { endAngle = 360; } if (anticlockwise === undefined) { anticlockwise = false; } - Shape.call(this, scene, 'Arc', new GeomCircle(0, 0, radius)); + super(scene, 'Arc', new GeomCircle(0, 0, radius)); /** * Private internal value. Holds the start angle in degrees. @@ -120,7 +119,7 @@ var Arc = new Class({ this.updateDisplayOrigin(); this.updateData(); - }, + } /** * The number of iterations used when drawing the arc. @@ -132,21 +131,18 @@ var Arc = new Class({ * @default 0.01 * @since 3.13.0 */ - iterations: { - - get: function () - { - return this._iterations; - }, - set: function (value) - { - this._iterations = value; + get iterations() + { + return this._iterations; + } - this.updateData(); - } + set iterations(value) + { + this._iterations = value; - }, + this.updateData(); + } /** * The radius of the arc. @@ -155,24 +151,21 @@ var Arc = new Class({ * @type {number} * @since 3.13.0 */ - radius: { - get: function () - { - return this.geom.radius; - }, - - set: function (value) - { - this.geom.radius = value; + get radius() + { + return this.geom.radius; + } - var diameter = value * 2; - this.setSize(diameter, diameter); - this.updateDisplayOrigin(); - this.updateData(); - } + set radius(value) + { + this.geom.radius = value; - }, + var diameter = value * 2; + this.setSize(diameter, diameter); + this.updateDisplayOrigin(); + this.updateData(); + } /** * The start angle of the arc, in degrees. @@ -181,21 +174,18 @@ var Arc = new Class({ * @type {number} * @since 3.13.0 */ - startAngle: { - get: function () - { - return this._startAngle; - }, - - set: function (value) - { - this._startAngle = value; + get startAngle() + { + return this._startAngle; + } - this.updateData(); - } + set startAngle(value) + { + this._startAngle = value; - }, + this.updateData(); + } /** * The end angle of the arc, in degrees. @@ -204,21 +194,18 @@ var Arc = new Class({ * @type {number} * @since 3.13.0 */ - endAngle: { - - get: function () - { - return this._endAngle; - }, - set: function (value) - { - this._endAngle = value; + get endAngle() + { + return this._endAngle; + } - this.updateData(); - } + set endAngle(value) + { + this._endAngle = value; - }, + this.updateData(); + } /** * The winding order of the start and end angles. @@ -227,21 +214,18 @@ var Arc = new Class({ * @type {boolean} * @since 3.13.0 */ - anticlockwise: { - - get: function () - { - return this._anticlockwise; - }, - set: function (value) - { - this._anticlockwise = value; + get anticlockwise() + { + return this._anticlockwise; + } - this.updateData(); - } + set anticlockwise(value) + { + this._anticlockwise = value; - }, + this.updateData(); + } /** * Sets the radius of the arc. @@ -254,12 +238,12 @@ var Arc = new Class({ * * @return {this} This Game Object instance. */ - setRadius: function (value) + setRadius(value) { this.radius = value; return this; - }, + } /** * Sets the number of iterations used when drawing the arc. @@ -274,14 +258,14 @@ var Arc = new Class({ * * @return {this} This Game Object instance. */ - setIterations: function (value) + setIterations(value) { if (value === undefined) { value = 0.01; } this.iterations = value; return this; - }, + } /** * Sets the starting angle of the arc, in degrees. @@ -294,7 +278,7 @@ var Arc = new Class({ * * @return {this} This Game Object instance. */ - setStartAngle: function (angle, anticlockwise) + setStartAngle(angle, anticlockwise) { this._startAngle = angle; @@ -304,7 +288,7 @@ var Arc = new Class({ } return this.updateData(); - }, + } /** * Sets the ending angle of the arc, in degrees. @@ -317,7 +301,7 @@ var Arc = new Class({ * * @return {this} This Game Object instance. */ - setEndAngle: function (angle, anticlockwise) + setEndAngle(angle, anticlockwise) { this._endAngle = angle; @@ -327,7 +311,7 @@ var Arc = new Class({ } return this.updateData(); - }, + } /** * Internal method that updates the data and path values. @@ -338,7 +322,7 @@ var Arc = new Class({ * * @return {this} This Game Object instance. */ - updateData: function () + updateData() { var step = this._iterations; var iteration = step; @@ -398,6 +382,6 @@ var Arc = new Class({ return this; } -}); +}; module.exports = Arc; diff --git a/src/gameobjects/shape/curve/Curve.js b/src/gameobjects/shape/curve/Curve.js index 3255a2725c..dc46de3fb4 100644 --- a/src/gameobjects/shape/curve/Curve.js +++ b/src/gameobjects/shape/curve/Curve.js @@ -40,22 +40,21 @@ var Shape = require('../Shape'); * @param {number} [fillColor] - The color the curve will be filled with, i.e. 0xff0000 for red. * @param {number} [fillAlpha] - The alpha the curve will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ -var Curve = new Class({ +var Curve = class extends Shape { - Extends: Shape, - - Mixins: [ - CurveRender - ], - - initialize: + static + { + Class.mixin(this, [ + CurveRender + ], false); + } - function Curve (scene, x, y, curve, fillColor, fillAlpha) + constructor(scene, x, y, curve, fillColor, fillAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } - Shape.call(this, scene, 'Curve', curve); + super(scene, 'Curve', curve); /** * Private internal value. @@ -89,7 +88,7 @@ var Curve = new Class({ } this.updateData(); - }, + } /** * The smoothness of the curve. The number of points used when rendering it. @@ -100,21 +99,18 @@ var Curve = new Class({ * @default 32 * @since 3.13.0 */ - smoothness: { - - get: function () - { - return this._smoothness; - }, - set: function (value) - { - this._smoothness = value; + get smoothness() + { + return this._smoothness; + } - this.updateData(); - } + set smoothness(value) + { + this._smoothness = value; - }, + this.updateData(); + } /** * Sets the smoothness of the curve. The number of points used when rendering it. @@ -128,12 +124,12 @@ var Curve = new Class({ * * @return {this} This Game Object instance. */ - setSmoothness: function (value) + setSmoothness(value) { this._smoothness = value; return this.updateData(); - }, + } /** * Internal method that updates the data and path values. @@ -144,7 +140,7 @@ var Curve = new Class({ * * @return {this} This Game Object instance. */ - updateData: function () + updateData() { var bounds = this._curveBounds; var smoothness = this._smoothness; @@ -171,6 +167,6 @@ var Curve = new Class({ return this; } -}); +}; module.exports = Curve; diff --git a/src/gameobjects/shape/ellipse/Ellipse.js b/src/gameobjects/shape/ellipse/Ellipse.js index 87a50b5fb1..0cc6066368 100644 --- a/src/gameobjects/shape/ellipse/Ellipse.js +++ b/src/gameobjects/shape/ellipse/Ellipse.js @@ -42,24 +42,23 @@ var Shape = require('../Shape'); * @param {number} [fillColor] - The color the ellipse will be filled with, i.e. 0xff0000 for red. * @param {number} [fillAlpha] - The alpha the ellipse will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ -var Ellipse = new Class({ +var Ellipse = class extends Shape { - Extends: Shape, - - Mixins: [ - EllipseRender - ], - - initialize: + static + { + Class.mixin(this, [ + EllipseRender + ], false); + } - function Ellipse (scene, x, y, width, height, fillColor, fillAlpha) + constructor(scene, x, y, width, height, fillColor, fillAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = 128; } if (height === undefined) { height = 128; } - Shape.call(this, scene, 'Ellipse', new GeomEllipse(width / 2, height / 2, width, height)); + super(scene, 'Ellipse', new GeomEllipse(width / 2, height / 2, width, height)); /** * Private internal value. @@ -84,7 +83,7 @@ var Ellipse = new Class({ this.updateDisplayOrigin(); this.updateData(); - }, + } /** * The smoothness of the ellipse. The number of points used when rendering it. @@ -95,21 +94,18 @@ var Ellipse = new Class({ * @default 64 * @since 3.13.0 */ - smoothness: { - get: function () - { - return this._smoothness; - }, - - set: function (value) - { - this._smoothness = value; + get smoothness() + { + return this._smoothness; + } - this.updateData(); - } + set smoothness(value) + { + this._smoothness = value; - }, + this.updateData(); + } /** * Sets the size of the ellipse by changing the underlying geometry data, rather than scaling the object. @@ -123,7 +119,7 @@ var Ellipse = new Class({ * * @return {this} This Game Object instance. */ - setSize: function (width, height) + setSize(width, height) { this.width = width; this.height = height; @@ -133,7 +129,7 @@ var Ellipse = new Class({ this.updateDisplayOrigin(); return this.updateData(); - }, + } /** * Sets the smoothness of the ellipse. The number of points used when rendering it. @@ -147,12 +143,12 @@ var Ellipse = new Class({ * * @return {this} This Game Object instance. */ - setSmoothness: function (value) + setSmoothness(value) { this._smoothness = value; return this.updateData(); - }, + } /** * Internal method that updates the data and path values. @@ -163,7 +159,7 @@ var Ellipse = new Class({ * * @return {this} This Game Object instance. */ - updateData: function () + updateData() { var path = []; var points = this.geom.getPoints(this._smoothness); @@ -181,6 +177,6 @@ var Ellipse = new Class({ return this; } -}); +}; module.exports = Ellipse; diff --git a/src/gameobjects/shape/grid/Grid.js b/src/gameobjects/shape/grid/Grid.js index b471953db3..c11d30203c 100644 --- a/src/gameobjects/shape/grid/Grid.js +++ b/src/gameobjects/shape/grid/Grid.js @@ -41,17 +41,16 @@ var GridRender = require('./GridRender'); * @param {number} [strokeFillColor] - The color of the lines between the grid cells. See the `setStrokeStyle` method. * @param {number} [strokeFillAlpha] - The alpha of the lines between the grid cells. */ -var Grid = new Class({ +var Grid = class extends Shape { - Extends: Shape, - - Mixins: [ - GridRender - ], - - initialize: + static + { + Class.mixin(this, [ + GridRender + ], false); + } - function Grid (scene, x, y, width, height, cellWidth, cellHeight, fillColor, fillAlpha, strokeFillColor, strokeFillAlpha) + constructor(scene, x, y, width, height, cellWidth, cellHeight, fillColor, fillAlpha, strokeFillColor, strokeFillAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -60,7 +59,7 @@ var Grid = new Class({ if (cellWidth === undefined) { cellWidth = 32; } if (cellHeight === undefined) { cellHeight = 32; } - Shape.call(this, scene, 'Grid', null); + super(scene, 'Grid', null); /** * The width of each grid cell. @@ -157,7 +156,7 @@ var Grid = new Class({ } this.updateDisplayOrigin(); - }, + } /** * Sets the fill color and alpha level that the alternating grid cells will use. @@ -176,7 +175,7 @@ var Grid = new Class({ * * @return {this} This Game Object instance. */ - setAltFillStyle: function (fillColor, fillAlpha) + setAltFillStyle(fillColor, fillAlpha) { if (fillAlpha === undefined) { fillAlpha = 1; } @@ -192,7 +191,7 @@ var Grid = new Class({ } return this; - }, + } /** * Sets the cell padding for the grid. @@ -208,12 +207,12 @@ var Grid = new Class({ * @param {number} [value] - The cell padding value. * @return {this} This Game Object instance. */ - setCellPadding: function (value) + setCellPadding(value) { this.cellPadding = value || 0; return this; - }, + } /** * Sets how to stroke the outside of the Grid object. @@ -225,7 +224,7 @@ var Grid = new Class({ * @param {boolean} strokeOutside - Whether to stroke the outside edges of the Grid object. * @param {boolean} [strokeOutsideIncomplete] - Whether to stroke the outside edges of the Grid object when the cell is incomplete. */ - setStrokeOutside: function (strokeOutside, strokeOutsideIncomplete) + setStrokeOutside(strokeOutside, strokeOutsideIncomplete) { this.strokeOutside = strokeOutside; @@ -237,6 +236,6 @@ var Grid = new Class({ return this; } -}); +}; module.exports = Grid; diff --git a/src/gameobjects/shape/isobox/IsoBox.js b/src/gameobjects/shape/isobox/IsoBox.js index d4d7ac3adc..c579da9814 100644 --- a/src/gameobjects/shape/isobox/IsoBox.js +++ b/src/gameobjects/shape/isobox/IsoBox.js @@ -39,17 +39,16 @@ var Shape = require('../Shape'); * @param {number} [fillLeft=0x999999] - The fill color of the left face of the iso box. * @param {number} [fillRight=0xcccccc] - The fill color of the right face of the iso box. */ -var IsoBox = new Class({ +var IsoBox = class extends Shape { - Extends: Shape, - - Mixins: [ - IsoBoxRender - ], - - initialize: + static + { + Class.mixin(this, [ + IsoBoxRender + ], false); + } - function IsoBox (scene, x, y, size, height, fillTop, fillLeft, fillRight) + constructor(scene, x, y, size, height, fillTop, fillLeft, fillRight) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -59,7 +58,7 @@ var IsoBox = new Class({ if (fillLeft === undefined) { fillLeft = 0x999999; } if (fillRight === undefined) { fillRight = 0xcccccc; } - Shape.call(this, scene, 'IsoBox', null); + super(scene, 'IsoBox', null); /** * The projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. @@ -134,7 +133,7 @@ var IsoBox = new Class({ this.setSize(size, height); this.updateDisplayOrigin(); - }, + } /** * Sets the projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. @@ -147,12 +146,12 @@ var IsoBox = new Class({ * * @return {this} This Game Object instance. */ - setProjection: function (value) + setProjection(value) { this.projection = value; return this; - }, + } /** * Sets which faces of the iso box will be rendered. @@ -167,7 +166,7 @@ var IsoBox = new Class({ * * @return {this} This Game Object instance. */ - setFaces: function (showTop, showLeft, showRight) + setFaces(showTop, showLeft, showRight) { if (showTop === undefined) { showTop = true; } if (showLeft === undefined) { showLeft = true; } @@ -178,7 +177,7 @@ var IsoBox = new Class({ this.showRight = showRight; return this; - }, + } /** * Sets the fill colors for each face of the iso box. @@ -193,7 +192,7 @@ var IsoBox = new Class({ * * @return {this} This Game Object instance. */ - setFillStyle: function (fillTop, fillLeft, fillRight) + setFillStyle(fillTop, fillLeft, fillRight) { this.fillTop = fillTop; this.fillLeft = fillLeft; @@ -204,6 +203,6 @@ var IsoBox = new Class({ return this; } -}); +}; module.exports = IsoBox; diff --git a/src/gameobjects/shape/isotriangle/IsoTriangle.js b/src/gameobjects/shape/isotriangle/IsoTriangle.js index 0e99f09d1d..54f87baaef 100644 --- a/src/gameobjects/shape/isotriangle/IsoTriangle.js +++ b/src/gameobjects/shape/isotriangle/IsoTriangle.js @@ -41,17 +41,16 @@ var Shape = require('../Shape'); * @param {number} [fillLeft=0x999999] - The fill color of the left face of the iso triangle. * @param {number} [fillRight=0xcccccc] - The fill color of the right face of the iso triangle. */ -var IsoTriangle = new Class({ +var IsoTriangle = class extends Shape { - Extends: Shape, - - Mixins: [ - IsoTriangleRender - ], - - initialize: + static + { + Class.mixin(this, [ + IsoTriangleRender + ], false); + } - function IsoTriangle (scene, x, y, size, height, reversed, fillTop, fillLeft, fillRight) + constructor(scene, x, y, size, height, reversed, fillTop, fillLeft, fillRight) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -62,7 +61,7 @@ var IsoTriangle = new Class({ if (fillLeft === undefined) { fillLeft = 0x999999; } if (fillRight === undefined) { fillRight = 0xcccccc; } - Shape.call(this, scene, 'IsoTriangle', null); + super(scene, 'IsoTriangle', null); /** * The projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. @@ -147,7 +146,7 @@ var IsoTriangle = new Class({ this.setSize(size, height); this.updateDisplayOrigin(); - }, + } /** * Sets the projection level of the iso triangle. Change this to change the 'angle' at which you are looking at the pyramid. @@ -160,12 +159,12 @@ var IsoTriangle = new Class({ * * @return {this} This Game Object instance. */ - setProjection: function (value) + setProjection(value) { this.projection = value; return this; - }, + } /** * Sets if the iso triangle will be rendered upside down or not. @@ -178,12 +177,12 @@ var IsoTriangle = new Class({ * * @return {this} This Game Object instance. */ - setReversed: function (reversed) + setReversed(reversed) { this.isReversed = reversed; return this; - }, + } /** * Sets which faces of the iso triangle will be rendered. @@ -198,7 +197,7 @@ var IsoTriangle = new Class({ * * @return {this} This Game Object instance. */ - setFaces: function (showTop, showLeft, showRight) + setFaces(showTop, showLeft, showRight) { if (showTop === undefined) { showTop = true; } if (showLeft === undefined) { showLeft = true; } @@ -209,7 +208,7 @@ var IsoTriangle = new Class({ this.showRight = showRight; return this; - }, + } /** * Sets the fill colors for each face of the iso triangle. @@ -224,7 +223,7 @@ var IsoTriangle = new Class({ * * @return {this} This Game Object instance. */ - setFillStyle: function (fillTop, fillLeft, fillRight) + setFillStyle(fillTop, fillLeft, fillRight) { this.fillTop = fillTop; this.fillLeft = fillLeft; @@ -235,6 +234,6 @@ var IsoTriangle = new Class({ return this; } -}); +}; module.exports = IsoTriangle; diff --git a/src/gameobjects/shape/line/Line.js b/src/gameobjects/shape/line/Line.js index 84e4881a96..3534510fc1 100644 --- a/src/gameobjects/shape/line/Line.js +++ b/src/gameobjects/shape/line/Line.js @@ -43,17 +43,16 @@ var LineRender = require('./LineRender'); * @param {number} [strokeColor] - The color the line will be drawn in, i.e. 0xff0000 for red. * @param {number} [strokeAlpha] - The alpha the line will be drawn in. You can also set the alpha of the overall Shape using its `alpha` property. */ -var Line = new Class({ +var Line = class extends Shape { - Extends: Shape, - - Mixins: [ - LineRender - ], - - initialize: + static + { + Class.mixin(this, [ + LineRender + ], false); + } - function Line (scene, x, y, x1, y1, x2, y2, strokeColor, strokeAlpha) + constructor(scene, x, y, x1, y1, x2, y2, strokeColor, strokeAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -62,7 +61,7 @@ var Line = new Class({ if (x2 === undefined) { x2 = 128; } if (y2 === undefined) { y2 = 0; } - Shape.call(this, scene, 'Line', new GeomLine(x1, y1, x2, y2)); + super(scene, 'Line', new GeomLine(x1, y1, x2, y2)); var width = Math.max(1, this.geom.right - this.geom.left); var height = Math.max(1, this.geom.bottom - this.geom.top); @@ -106,7 +105,7 @@ var Line = new Class({ } this.updateDisplayOrigin(); - }, + } /** * Sets the width of the line. @@ -124,7 +123,7 @@ var Line = new Class({ * * @return {this} This Game Object instance. */ - setLineWidth: function (startWidth, endWidth) + setLineWidth(startWidth, endWidth) { if (endWidth === undefined) { endWidth = startWidth; } @@ -134,7 +133,7 @@ var Line = new Class({ this.lineWidth = startWidth; return this; - }, + } /** * Sets the start and end coordinates of this Line. @@ -149,13 +148,13 @@ var Line = new Class({ * * @return {this} This Line object. */ - setTo: function (x1, y1, x2, y2) + setTo(x1, y1, x2, y2) { this.geom.setTo(x1, y1, x2, y2); return this; } -}); +}; module.exports = Line; diff --git a/src/gameobjects/shape/polygon/Polygon.js b/src/gameobjects/shape/polygon/Polygon.js index fc86f42e64..697da16ae1 100644 --- a/src/gameobjects/shape/polygon/Polygon.js +++ b/src/gameobjects/shape/polygon/Polygon.js @@ -50,22 +50,21 @@ var Smooth = require('../../../geom/polygon/Smooth'); * @param {number} [fillColor] - The color the polygon will be filled with, i.e. 0xff0000 for red. * @param {number} [fillAlpha] - The alpha the polygon will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ -var Polygon = new Class({ +var Polygon = class extends Shape { - Extends: Shape, - - Mixins: [ - PolygonRender - ], - - initialize: + static + { + Class.mixin(this, [ + PolygonRender + ], false); + } - function Polygon (scene, x, y, points, fillColor, fillAlpha) + constructor(scene, x, y, points, fillColor, fillAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } - Shape.call(this, scene, 'Polygon', new GeomPolygon(points)); + super(scene, 'Polygon', new GeomPolygon(points)); var bounds = GetAABB(this.geom); @@ -79,7 +78,7 @@ var Polygon = new Class({ this.updateDisplayOrigin(); this.updateData(); - }, + } /** * Smooths the polygon over the number of iterations specified. @@ -93,7 +92,7 @@ var Polygon = new Class({ * * @return {this} This Game Object instance. */ - smooth: function (iterations) + smooth(iterations) { if (iterations === undefined) { iterations = 1; } @@ -103,7 +102,7 @@ var Polygon = new Class({ } return this.updateData(); - }, + } /** * Sets this Polygon to the given points. @@ -128,7 +127,7 @@ var Polygon = new Class({ * * @return {this} This Game Object instance. */ - setTo: function (points) + setTo(points) { this.geom.setTo(points); @@ -139,7 +138,7 @@ var Polygon = new Class({ this.updateDisplayOrigin(); return this.updateData(); - }, + } /** * Internal method that updates the data and path values. @@ -150,7 +149,7 @@ var Polygon = new Class({ * * @return {this} This Game Object instance. */ - updateData: function () + updateData() { var path = []; var points = this.geom.points; @@ -168,6 +167,6 @@ var Polygon = new Class({ return this; } -}); +}; module.exports = Polygon; diff --git a/src/gameobjects/shape/rectangle/Rectangle.js b/src/gameobjects/shape/rectangle/Rectangle.js index 8ccce9a874..00d47b109c 100644 --- a/src/gameobjects/shape/rectangle/Rectangle.js +++ b/src/gameobjects/shape/rectangle/Rectangle.js @@ -35,24 +35,23 @@ var RectangleRender = require('./RectangleRender'); * @param {number} [fillColor] - The color the rectangle will be filled with, i.e. 0xff0000 for red. * @param {number} [fillAlpha] - The alpha the rectangle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ -var Rectangle = new Class({ +var Rectangle = class extends Shape { - Extends: Shape, - - Mixins: [ - RectangleRender - ], - - initialize: + static + { + Class.mixin(this, [ + RectangleRender + ], false); + } - function Rectangle (scene, x, y, width, height, fillColor, fillAlpha) + constructor(scene, x, y, width, height, fillColor, fillAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = 128; } if (height === undefined) { height = 128; } - Shape.call(this, scene, 'Rectangle', new GeomRectangle(0, 0, width, height)); + super(scene, 'Rectangle', new GeomRectangle(0, 0, width, height)); /** * The radius of the rectangle if this is set to use rounded corners. @@ -90,7 +89,7 @@ var Rectangle = new Class({ this.updateDisplayOrigin(); this.updateData(); - }, + } /** * Sets this rectangle to have rounded corners by specifying the radius of the corner. @@ -106,7 +105,7 @@ var Rectangle = new Class({ * * @return {this} This Game Object instance. */ - setRounded: function (radius) + setRounded(radius) { if (radius === undefined) { radius = 16; } @@ -114,7 +113,7 @@ var Rectangle = new Class({ this.isRounded = radius > 0; return this.updateRoundedData(); - }, + } /** * Sets the internal size of this Rectangle, as used for frame or physics body creation. @@ -130,7 +129,7 @@ var Rectangle = new Class({ * * @return {this} This Game Object instance. */ - setSize: function (width, height) + setSize(width, height) { this.width = width; this.height = height; @@ -150,7 +149,7 @@ var Rectangle = new Class({ } return this; - }, + } /** * Internal method that updates the data and path values. @@ -161,7 +160,7 @@ var Rectangle = new Class({ * * @return {this} This Game Object instance. */ - updateData: function () + updateData() { if (this.isRounded) { @@ -191,7 +190,7 @@ var Rectangle = new Class({ this.pathData = path; return this; - }, + } /** * Internal method that updates the data and path values when this rectangle is rounded. @@ -202,7 +201,7 @@ var Rectangle = new Class({ * * @return {this} This Game Object instance. */ - updateRoundedData: function () + updateRoundedData() { var path = []; var halfWidth = this.width / 2; @@ -245,7 +244,7 @@ var Rectangle = new Class({ this.pathData = path; return this; - }, + } /** * Internal method placing points around the circumference of a circle for the rounded corners. @@ -264,7 +263,7 @@ var Rectangle = new Class({ * * @return {this} This Game Object instance. */ - arcTo: function (path, centerX, centerY, radius, startAngle, endAngle, segments) + arcTo(path, centerX, centerY, radius, startAngle, endAngle, segments) { var angleInc = (endAngle - startAngle) / segments; @@ -279,6 +278,6 @@ var Rectangle = new Class({ } } -}); +}; module.exports = Rectangle; diff --git a/src/gameobjects/shape/star/Star.js b/src/gameobjects/shape/star/Star.js index bedbb939b7..0e19d268b7 100644 --- a/src/gameobjects/shape/star/Star.js +++ b/src/gameobjects/shape/star/Star.js @@ -41,17 +41,16 @@ var Shape = require('../Shape'); * @param {number} [fillColor] - The color the star will be filled with, i.e. 0xff0000 for red. * @param {number} [fillAlpha] - The alpha the star will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ -var Star = new Class({ +var Star = class extends Shape { - Extends: Shape, - - Mixins: [ - StarRender - ], - - initialize: + static + { + Class.mixin(this, [ + StarRender + ], false); + } - function Star (scene, x, y, points, innerRadius, outerRadius, fillColor, fillAlpha) + constructor(scene, x, y, points, innerRadius, outerRadius, fillColor, fillAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -59,7 +58,7 @@ var Star = new Class({ if (innerRadius === undefined) { innerRadius = 32; } if (outerRadius === undefined) { outerRadius = 64; } - Shape.call(this, scene, 'Star', null); + super(scene, 'Star', null); /** * Private internal value. @@ -104,7 +103,7 @@ var Star = new Class({ this.updateDisplayOrigin(); this.updateData(); - }, + } /** * Sets the number of points that make up the Star shape. @@ -117,12 +116,12 @@ var Star = new Class({ * * @return {this} This Game Object instance. */ - setPoints: function (value) + setPoints(value) { this._points = value; return this.updateData(); - }, + } /** * Sets the inner radius of the Star shape. @@ -135,12 +134,12 @@ var Star = new Class({ * * @return {this} This Game Object instance. */ - setInnerRadius: function (value) + setInnerRadius(value) { this._innerRadius = value; return this.updateData(); - }, + } /** * Sets the outer radius of the Star shape. @@ -153,12 +152,12 @@ var Star = new Class({ * * @return {this} This Game Object instance. */ - setOuterRadius: function (value) + setOuterRadius(value) { this._outerRadius = value; return this.updateData(); - }, + } /** * The number of points that make up the Star shape. @@ -168,21 +167,18 @@ var Star = new Class({ * @default 5 * @since 3.13.0 */ - points: { - - get: function () - { - return this._points; - }, - set: function (value) - { - this._points = value; + get points() + { + return this._points; + } - this.updateData(); - } + set points(value) + { + this._points = value; - }, + this.updateData(); + } /** * The inner radius of the Star shape. @@ -192,21 +188,18 @@ var Star = new Class({ * @default 32 * @since 3.13.0 */ - innerRadius: { - - get: function () - { - return this._innerRadius; - }, - set: function (value) - { - this._innerRadius = value; + get innerRadius() + { + return this._innerRadius; + } - this.updateData(); - } + set innerRadius(value) + { + this._innerRadius = value; - }, + this.updateData(); + } /** * The outer radius of the Star shape. @@ -216,21 +209,18 @@ var Star = new Class({ * @default 64 * @since 3.13.0 */ - outerRadius: { - get: function () - { - return this._outerRadius; - }, - - set: function (value) - { - this._outerRadius = value; + get outerRadius() + { + return this._outerRadius; + } - this.updateData(); - } + set outerRadius(value) + { + this._outerRadius = value; - }, + this.updateData(); + } /** * Internal method that updates the data and path values. @@ -241,7 +231,7 @@ var Star = new Class({ * * @return {this} This Game Object instance. */ - updateData: function () + updateData() { var path = []; @@ -277,6 +267,6 @@ var Star = new Class({ return this; } -}); +}; module.exports = Star; diff --git a/src/gameobjects/shape/triangle/Triangle.js b/src/gameobjects/shape/triangle/Triangle.js index ab594666db..0abbf824b0 100644 --- a/src/gameobjects/shape/triangle/Triangle.js +++ b/src/gameobjects/shape/triangle/Triangle.js @@ -40,17 +40,16 @@ var TriangleRender = require('./TriangleRender'); * @param {number} [fillColor] - The color the triangle will be filled with, i.e. 0xff0000 for red. * @param {number} [fillAlpha] - The alpha the triangle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ -var Triangle = new Class({ +var Triangle = class extends Shape { - Extends: Shape, - - Mixins: [ - TriangleRender - ], - - initialize: + static + { + Class.mixin(this, [ + TriangleRender + ], false); + } - function Triangle (scene, x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha) + constructor(scene, x, y, x1, y1, x2, y2, x3, y3, fillColor, fillAlpha) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -61,7 +60,7 @@ var Triangle = new Class({ if (x3 === undefined) { x3 = 128; } if (y3 === undefined) { y3 = 128; } - Shape.call(this, scene, 'Triangle', new GeomTriangle(x1, y1, x2, y2, x3, y3)); + super(scene, 'Triangle', new GeomTriangle(x1, y1, x2, y2, x3, y3)); var width = this.geom.right - this.geom.left; var height = this.geom.bottom - this.geom.top; @@ -76,7 +75,7 @@ var Triangle = new Class({ this.updateDisplayOrigin(); this.updateData(); - }, + } /** * Sets the data for the lines that make up this Triangle shape. @@ -93,12 +92,12 @@ var Triangle = new Class({ * * @return {this} This Game Object instance. */ - setTo: function (x1, y1, x2, y2, x3, y3) + setTo(x1, y1, x2, y2, x3, y3) { this.geom.setTo(x1, y1, x2, y2, x3, y3); return this.updateData(); - }, + } /** * Internal method that updates the data and path values. @@ -109,7 +108,7 @@ var Triangle = new Class({ * * @return {this} This Game Object instance. */ - updateData: function () + updateData() { var path = []; var tri = this.geom; @@ -132,6 +131,6 @@ var Triangle = new Class({ return this; } -}); +}; module.exports = Triangle; diff --git a/src/gameobjects/sprite/Sprite.js b/src/gameobjects/sprite/Sprite.js index 5ce9e26b87..f70f88dc3b 100644 --- a/src/gameobjects/sprite/Sprite.js +++ b/src/gameobjects/sprite/Sprite.js @@ -51,34 +51,33 @@ var SpriteRender = require('./SpriteRender'); * @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with. */ -var Sprite = new Class({ +var Sprite = class extends GameObject { - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.Depth, - Components.Flip, - Components.GetBounds, - Components.Lighting, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.ScrollFactor, - Components.Size, - Components.TextureCrop, - Components.Tint, - Components.Transform, - Components.Visible, - SpriteRender - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.Depth, + Components.Flip, + Components.GetBounds, + Components.Lighting, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.ScrollFactor, + Components.Size, + Components.TextureCrop, + Components.Tint, + Components.Transform, + Components.Visible, + SpriteRender + ], false); + } - function Sprite (scene, x, y, texture, frame) + constructor(scene, x, y, texture, frame) { - GameObject.call(this, scene, 'Sprite'); + super(scene, 'Sprite'); /** * The internal crop data object, as used by `setCrop` and passed to the `Frame.setCropUVs` method. @@ -108,7 +107,7 @@ var Sprite = new Class({ this.setSizeToFrame(); this.setOriginFromFrame(); this.initRenderNodes(this._defaultRenderNodesMap); - }, + } /** * The default render nodes for this Game Object. @@ -120,24 +119,23 @@ var Sprite = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultImageNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultImageNodes; + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } /** * Update this Sprite's animations. @@ -149,10 +147,10 @@ var Sprite = new Class({ * @param {number} time - The current timestamp. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ - preUpdate: function (time, delta) + preUpdate(time, delta) { this.anims.update(time, delta); - }, + } /** * Start playing the given animation on this Sprite. @@ -214,10 +212,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - play: function (key, ignoreIfPlaying) + play(key, ignoreIfPlaying) { return this.anims.play(key, ignoreIfPlaying); - }, + } /** * Start playing the given animation on this Sprite, in reverse. @@ -279,10 +277,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - playReverse: function (key, ignoreIfPlaying) + playReverse(key, ignoreIfPlaying) { return this.anims.playReverse(key, ignoreIfPlaying); - }, + } /** * Waits for the specified delay, in milliseconds, then starts playback of the given animation. @@ -309,10 +307,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - playAfterDelay: function (key, delay) + playAfterDelay(key, delay) { return this.anims.playAfterDelay(key, delay); - }, + } /** * Waits for the current animation to complete the `repeatCount` number of repeat cycles, then starts playback @@ -336,10 +334,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - playAfterRepeat: function (key, repeatCount) + playAfterRepeat(key, repeatCount) { return this.anims.playAfterRepeat(key, repeatCount); - }, + } /** * Sets an animation, or an array of animations, to be played immediately after the current one completes or stops. @@ -368,10 +366,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - chain: function (key) + chain(key) { return this.anims.chain(key); - }, + } /** * Immediately stops the current animation from playing and dispatches the `ANIMATION_STOP` events. @@ -386,10 +384,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - stop: function () + stop() { return this.anims.stop(); - }, + } /** * Stops the current animation from playing after the specified time delay, given in milliseconds. @@ -409,10 +407,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - stopAfterDelay: function (delay) + stopAfterDelay(delay) { return this.anims.stopAfterDelay(delay); - }, + } /** * Stops the current animation from playing after the given number of repeats. @@ -432,10 +430,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - stopAfterRepeat: function (repeatCount) + stopAfterRepeat(repeatCount) { return this.anims.stopAfterRepeat(repeatCount); - }, + } /** * Stops the current animation from playing when it next sets the given frame. @@ -456,10 +454,10 @@ var Sprite = new Class({ * * @return {this} This Game Object. */ - stopOnFrame: function (frame) + stopOnFrame(frame) { return this.anims.stopOnFrame(frame); - }, + } /** * Build a JSON representation of this Sprite. @@ -469,10 +467,10 @@ var Sprite = new Class({ * * @return {Phaser.Types.GameObjects.JSONGameObject} A JSON representation of the Game Object. */ - toJSON: function () + toJSON() { return Components.ToJSON(this); - }, + } /** * Handles the pre-destroy step for the Sprite, which removes the Animation component. @@ -481,13 +479,13 @@ var Sprite = new Class({ * @private * @since 3.14.0 */ - preDestroy: function () + preDestroy() { this.anims.destroy(); this.anims = undefined; } -}); +}; module.exports = Sprite; diff --git a/src/gameobjects/spritegpulayer/SpriteGPULayer.js b/src/gameobjects/spritegpulayer/SpriteGPULayer.js index f85018a336..b61d5897f8 100644 --- a/src/gameobjects/spritegpulayer/SpriteGPULayer.js +++ b/src/gameobjects/spritegpulayer/SpriteGPULayer.js @@ -122,25 +122,27 @@ var getTint = Utils.getTintAppendFloatAlpha; * @param {Phaser.Textures.Texture} texture - The texture that will be used to render the SpriteGPULayer. This must be sourced from a single image; a multi atlas will not work. * @param {number} size - The maximum number of quads that this SpriteGPULayer will hold. This can be increased later if necessary. */ -var SpriteGPULayer = new Class({ - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.Depth, - Components.ElapseTimer, - Components.Lighting, - Components.Mask, - Components.RenderNodes, - Components.TextureCrop, - Components.Visible, - SpriteGPULayerRender - ], - - initialize: function SpriteGPULayer (scene, texture, size) +var SpriteGPULayer = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.Depth, + Components.ElapseTimer, + Components.Lighting, + Components.Mask, + Components.RenderNodes, + Components.TextureCrop, + Components.Visible, + SpriteGPULayerRender + ], false); + } + + constructor(scene, texture, size) { - GameObject.call(this, scene, 'SpriteGPULayer'); + super(scene, 'SpriteGPULayer'); /** * The number of quad members in the SpriteGPULayer. @@ -409,24 +411,24 @@ var SpriteGPULayer = new Class({ * @since 4.0.0 */ this.nextMemberU32 = new Uint32Array(this.nextMember); - }, + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } - preUpdate: function (time, delta) + preUpdate(time, delta) { this.updateTimer(time, delta); - }, + } /** * Get the number of bytes used to define a member. @@ -436,10 +438,10 @@ var SpriteGPULayer = new Class({ * @method Phaser.GameObjects.SpriteGPULayer#getDataByteSize * @returns {number} The number of bytes used for each member. */ - getDataByteSize: function () + getDataByteSize() { return this.submitterNode.instanceBufferLayout.layout.stride; - }, + } /** * Return a list of features to enable in the shader program. @@ -449,7 +451,7 @@ var SpriteGPULayer = new Class({ * @since 4.0.0 * @return {string[]} An array of features to enable in the shader program. */ - getShaderFeatures: function () + getShaderFeatures() { var features = []; @@ -465,7 +467,7 @@ var SpriteGPULayer = new Class({ } return features; - }, + } /** * Set the animations available to the SpriteGPULayer. @@ -487,7 +489,7 @@ var SpriteGPULayer = new Class({ * @param {Phaser.Animations.Animation[]|Phaser.Types.GameObjects.SpriteGPULayer.SetAnimation[]} animations - An array of animations to set. * @returns {this} This SpriteGPULayer object. */ - setAnimations: function (animations) + setAnimations(animations) { var animLen = animations.length; @@ -527,7 +529,7 @@ var SpriteGPULayer = new Class({ this.generateFrameDataTexture(); return this; - }, + } /** * Generate `frameDataTexture` for the SpriteGPULayer. @@ -536,7 +538,7 @@ var SpriteGPULayer = new Class({ * @method Phaser.GameObjects.SpriteGPULayer#generateFrameDataTexture * @since 4.0.0 */ - generateFrameDataTexture: function () + generateFrameDataTexture() { // Get the frame data. var texture = this.texture; @@ -629,7 +631,7 @@ var SpriteGPULayer = new Class({ this.frameDataTexture.destroy(); } this.frameDataTexture = this.scene.renderer.createUint8ArrayTexture(u8, width, height, false, false); - }, + } /** * Resizes the SpriteGPULayer buffer to a new size. @@ -644,7 +646,7 @@ var SpriteGPULayer = new Class({ * @param {boolean} [clear=false] - Whether to clear the buffer. * @returns {this} This SpriteGPULayer object. */ - resize: function (count, clear) + resize(count, clear) { var layout = this.submitterNode.instanceBufferLayout; var buffer = layout.buffer; @@ -671,7 +673,7 @@ var SpriteGPULayer = new Class({ this.setAllSegmentsNeedUpdate(); return this; - }, + } /** * Sets a segment of the buffer to require an update. @@ -680,7 +682,7 @@ var SpriteGPULayer = new Class({ * @since 4.0.0 * @param {number} index - The index at which an update occurred, which requires the segment to be updated. */ - setSegmentNeedsUpdate: function (index) + setSegmentNeedsUpdate(index) { if ( index < 0 || @@ -692,7 +694,7 @@ var SpriteGPULayer = new Class({ } var segment = Math.floor(index / this.bufferUpdateSegmentSize); this.bufferUpdateSegments |= (1 << segment); - }, + } /** * Sets all segments of the buffer to require an update. @@ -700,10 +702,10 @@ var SpriteGPULayer = new Class({ * @method Phaser.GameObjects.SpriteGPULayer#setAllSegmentsNeedUpdate * @since 4.0.0 */ - setAllSegmentsNeedUpdate: function () + setAllSegmentsNeedUpdate() { this.bufferUpdateSegments = this.MAX_BUFFER_UPDATE_SEGMENTS_FULL; - }, + } /** * Clears all segments of the buffer that require an update. @@ -711,10 +713,10 @@ var SpriteGPULayer = new Class({ * @method Phaser.GameObjects.SpriteGPULayer#clearAllSegmentsNeedUpdate * @since 4.0.0 */ - clearAllSegmentsNeedUpdate: function () + clearAllSegmentsNeedUpdate() { this.bufferUpdateSegments = 0; - }, + } /** * Adds data to the SpriteGPULayer buffer. @@ -737,7 +739,7 @@ var SpriteGPULayer = new Class({ * @param {Float32Array} member - The raw data to add to the buffer. * @returns {this} This SpriteGPULayer object. */ - addData: function (member) + addData(member) { if (this.memberCount >= this.size) { @@ -754,7 +756,7 @@ var SpriteGPULayer = new Class({ this.memberCount++; return this; - }, + } /** * Adds a member to the SpriteGPULayer. @@ -767,7 +769,7 @@ var SpriteGPULayer = new Class({ * @param {Partial} [member] - The member to add to the SpriteGPULayer. * @returns {this} This SpriteGPULayer object. */ - addMember: function (member) + addMember(member) { if (this.memberCount >= this.size) { @@ -935,7 +937,7 @@ var SpriteGPULayer = new Class({ this.addData(this.nextMemberF32); return this; - }, + } /** * Edits a member of the SpriteGPULayer. @@ -948,7 +950,7 @@ var SpriteGPULayer = new Class({ * @param {Partial} member - The new member data. * @returns {this} This SpriteGPULayer object. */ - editMember: function (index, member) + editMember(index, member) { if (index < 0 || index >= this.memberCount) { @@ -961,7 +963,7 @@ var SpriteGPULayer = new Class({ this.memberCount = currentMemberCount; return this; - }, + } /** * Update a member of the SpriteGPULayer with raw data. @@ -984,7 +986,7 @@ var SpriteGPULayer = new Class({ * @param {Uint32Array} member - The new member data. * @param {number[]} [mask] - The mask to apply to the member data. A value of 1 will update the member data, a value of 0 will keep the existing member data. */ - patchMember: function (index, member, mask) + patchMember(index, member, mask) { if (index < 0 || index >= this.memberCount) { @@ -1015,7 +1017,7 @@ var SpriteGPULayer = new Class({ } this.setSegmentNeedsUpdate(index); - }, + } /** * Returns a member of the SpriteGPULayer. @@ -1037,7 +1039,7 @@ var SpriteGPULayer = new Class({ * @param {number} index - The index of the member to get. * @returns {?Phaser.Types.GameObjects.SpriteGPULayer.Member} The member data, or null if the index is out of bounds. */ - getMember: function (index) + getMember(index) { if (index < 0 || index >= this.memberCount) { @@ -1123,7 +1125,7 @@ var SpriteGPULayer = new Class({ member.scrollFactorY = f32[offset++]; return member; - }, + } /** * Returns the raw data of a member of the SpriteGPULayer. @@ -1186,7 +1188,7 @@ var SpriteGPULayer = new Class({ * @param {Uint32Array} [out] - An optional array to copy the data to. If not provided, `this.nextMember` will be populated, and `nextMemberU32` will be returned. * @returns {?Uint32Array} The member data, or null if the index is out of bounds. */ - getMemberData: function (index, out) + getMemberData(index, out) { if (index < 0 || index >= this.memberCount) { @@ -1209,7 +1211,7 @@ var SpriteGPULayer = new Class({ out.set(viewU32.subarray(byteOffset / bytesPerElement, byteOffset / bytesPerElement + stride / bytesPerElement)); return out; - }, + } /** * Removes a member or a number of members from the SpriteGPULayer. @@ -1224,7 +1226,7 @@ var SpriteGPULayer = new Class({ * @param {number} [count=1] - The number of members to remove, default 1. * @returns {this} This SpriteGPULayer object. */ - removeMembers: function (index, count) + removeMembers(index, count) { if (index < 0 || index >= this.memberCount) { @@ -1256,7 +1258,7 @@ var SpriteGPULayer = new Class({ this.memberCount -= count; return this; - }, + } /** * Inserts members into the SpriteGPULayer. @@ -1270,7 +1272,7 @@ var SpriteGPULayer = new Class({ * @param {Phaser.Types.GameObjects.SpriteGPULayer.Member|Phaser.Types.GameObjects.SpriteGPULayer.Member[]} members - The members to insert. * @returns {this} This SpriteGPULayer object. */ - insertMembers: function (index, members) + insertMembers(index, members) { if (index < 0 || index > this.memberCount) { @@ -1317,7 +1319,7 @@ var SpriteGPULayer = new Class({ } return this; - }, + } /** * Inserts raw data into the SpriteGPULayer. @@ -1346,7 +1348,7 @@ var SpriteGPULayer = new Class({ * @param {Uint32Array} data - The members to insert. * @returns {this} This SpriteGPULayer object. */ - insertMembersData: function (index, data) + insertMembersData(index, data) { if (index < 0 || index > this.memberCount) { @@ -1383,7 +1385,7 @@ var SpriteGPULayer = new Class({ } return this; - }, + } /** * Sets the values of an animation for a member of this SpriteGPULayer. @@ -1396,7 +1398,7 @@ var SpriteGPULayer = new Class({ * @param {number} index - The offset in `nextMember` to write to. * @param {number} [defaultValue=0] - A default value to use if `value` is undefined. */ - _setAnimatedValue: function (value, index, defaultValue) + _setAnimatedValue(value, index, defaultValue) { var f32 = this.nextMemberF32; @@ -1498,7 +1500,7 @@ var SpriteGPULayer = new Class({ f32[index++] = duration; f32[index] = delay; } - }, + } /** * Return the values of an animation for a member of this SpriteGPULayer @@ -1510,7 +1512,7 @@ var SpriteGPULayer = new Class({ * @param {number} index - The index where the animation begins in the buffer. * @returns {number|Phaser.Types.GameObjects.SpriteGPULayer.MemberAnimation} The animation values. */ - _getAnimatedValue: function (index) + _getAnimatedValue(index) { var f32 = this.submitterNode.instanceBufferLayout.buffer.viewF32; @@ -1569,7 +1571,7 @@ var SpriteGPULayer = new Class({ delay: delay, yoyo: yoyo }; - }, + } /** * Set the enabled state of an animation. @@ -1591,12 +1593,12 @@ var SpriteGPULayer = new Class({ * @param {boolean} enabled - Whether to enable or disable the animation. * @returns {this} This SpriteGPULayer object */ - setAnimationEnabled: function (name, enabled) + setAnimationEnabled(name, enabled) { this._animationsEnabled[name] = !!enabled; return this; - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -1605,12 +1607,12 @@ var SpriteGPULayer = new Class({ * @protected * @since 4.0.0 */ - preDestroy: function () + preDestroy() { this.frameDataTexture.destroy(); // TODO: Destroy the Submitter RenderNode. } -}); +}; module.exports = SpriteGPULayer; diff --git a/src/gameobjects/stamp/Stamp.js b/src/gameobjects/stamp/Stamp.js index 1b81ef536c..7f652c59c8 100644 --- a/src/gameobjects/stamp/Stamp.js +++ b/src/gameobjects/stamp/Stamp.js @@ -47,26 +47,27 @@ var StampRender = require('./StampRender'); * @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with. */ -var Stamp = new Class({ - Extends: Image, +var Stamp = class extends Image { - Mixins: [ - StampRender - ], + static + { + Class.mixin(this, [ + StampRender + ], false); + } - initialize: function Stamp (scene, x, y, texture, frame) + constructor(scene, x, y, texture, frame) { - Image.call(this, scene, x, y, texture, frame); + super(scene, x, y, texture, frame); this.type = 'Stamp'; - }, + } - _defaultRenderNodesMap: { - get: function () - { - return DefaultStampNodes; - } + + get _defaultRenderNodesMap() + { + return DefaultStampNodes; } -}); +}; module.exports = Stamp; diff --git a/src/gameobjects/text/Text.js b/src/gameobjects/text/Text.js index c1e7ea0664..614af3e4cf 100644 --- a/src/gameobjects/text/Text.js +++ b/src/gameobjects/text/Text.js @@ -83,37 +83,36 @@ var UUID = require('../../utils/string/UUID'); * * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#Valid_family_names */ -var Text = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.ComputedSize, - Components.Crop, - Components.Depth, - Components.Flip, - Components.GetBounds, - Components.Lighting, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.ScrollFactor, - Components.Tint, - Components.Transform, - Components.Visible, - TextRender - ], - - initialize: - - function Text (scene, x, y, text, style) +var Text = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.ComputedSize, + Components.Crop, + Components.Depth, + Components.Flip, + Components.GetBounds, + Components.Lighting, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.ScrollFactor, + Components.Tint, + Components.Transform, + Components.Visible, + TextRender + ], false); + } + + constructor(scene, x, y, text, style) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } - GameObject.call(this, scene, 'Text'); + super(scene, 'Text'); /** * The renderer in use by this Text object. @@ -309,7 +308,7 @@ var Text = new Class({ { this.setLetterSpacing(style.letterSpacing); } - }, + } /** * The default render nodes for this Game Object. @@ -321,12 +320,11 @@ var Text = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultImageNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultImageNodes; + } /** * Initialize right to left text. @@ -334,7 +332,7 @@ var Text = new Class({ * @method Phaser.GameObjects.Text#initRTL * @since 3.0.0 */ - initRTL: function () + initRTL() { if (!this.style.rtl) { @@ -360,7 +358,7 @@ var Text = new Class({ // 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 @@ -373,7 +371,7 @@ var Text = new Class({ * * @return {string} The text after wrapping has been applied. */ - runWordWrap: function (text) + runWordWrap(text) { var style = this.style; @@ -403,7 +401,7 @@ var Text = new Class({ { return text; } - }, + } /** * Advanced wrapping algorithm that will wrap words as the line grows longer than its horizontal @@ -420,7 +418,7 @@ var Text = new Class({ * * @return {string} The wrapped text. */ - advancedWordWrap: function (text, context, wordWrapWidth) + advancedWordWrap(text, context, wordWrapWidth) { var output = ''; @@ -527,7 +525,7 @@ var Text = new Class({ output = output.replace(/[\s|\n]*$/gi, ''); return output; - }, + } /** * Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal @@ -542,7 +540,7 @@ var Text = new Class({ * * @return {string} The wrapped text. */ - basicWordWrap: function (text, context, wordWrapWidth) + basicWordWrap(text, context, wordWrapWidth) { var result = ''; var lines = text.split(this.splitRegExp); @@ -598,7 +596,7 @@ var Text = new Class({ } return result; - }, + } /** * Runs the given text through this Text objects word wrapping and returns the results as an @@ -611,7 +609,7 @@ var Text = new Class({ * * @return {string[]} An array of strings with the pieces of wrapped text. */ - getWrappedText: function (text) + getWrappedText(text) { if (text === undefined) { text = this._text; } @@ -620,7 +618,7 @@ var Text = new Class({ var wrappedLines = this.runWordWrap(text); return wrappedLines.split(this.splitRegExp); - }, + } /** * Set the text to display. @@ -634,7 +632,7 @@ var Text = new Class({ * * @return {this} This Text object. */ - setText: function (value) + setText(value) { if (!value && value !== 0) { @@ -654,7 +652,7 @@ var Text = new Class({ } return this; - }, + } /** * Appends the given text to the content already being displayed by this Text object. @@ -669,7 +667,7 @@ var Text = new Class({ * * @return {this} This Text object. */ - appendText: function (value, addCR) + appendText(value, addCR) { if (addCR === undefined) { addCR = true; } @@ -695,7 +693,7 @@ var Text = new Class({ } return this; - }, + } /** * Set the text style. @@ -716,10 +714,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setStyle: function (style) + setStyle(style) { return this.style.setStyle(style); - }, + } /** * Set the font. @@ -752,10 +750,10 @@ var Text = new Class({ * * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#Valid_family_names */ - setFont: function (font) + setFont(font) { return this.style.setFont(font); - }, + } /** * Set the font family. @@ -783,10 +781,10 @@ var Text = new Class({ * * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#Valid_family_names */ - setFontFamily: function (family) + setFontFamily(family) { return this.style.setFontFamily(family); - }, + } /** * Set the font size. Can be a string with a valid CSS unit, i.e. `16px`, or a number. @@ -798,10 +796,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setFontSize: function (size) + setFontSize(size) { return this.style.setFontSize(size); - }, + } /** * Set the font style. @@ -813,10 +811,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setFontStyle: function (style) + setFontStyle(style) { return this.style.setFontStyle(style); - }, + } /** * Set a fixed width and height for the text. @@ -831,10 +829,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setFixedSize: function (width, height) + setFixedSize(width, height) { return this.style.setFixedSize(width, height); - }, + } /** * Set the background color. @@ -846,10 +844,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setBackgroundColor: function (color) + setBackgroundColor(color) { return this.style.setBackgroundColor(color); - }, + } /** * Set the fill style to be used by the Text object. @@ -866,10 +864,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setFill: function (fillStyle) + setFill(fillStyle) { return this.style.setFill(fillStyle); - }, + } /** * Set the text fill color. @@ -881,10 +879,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setColor: function (color) + setColor(color) { return this.style.setColor(color); - }, + } /** * Set the stroke settings. @@ -897,10 +895,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setStroke: function (color, thickness) + setStroke(color, thickness) { return this.style.setStroke(color, thickness); - }, + } /** * Set the shadow settings. @@ -917,10 +915,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setShadow: function (x, y, color, blur, shadowStroke, shadowFill) + setShadow(x, y, color, blur, shadowStroke, shadowFill) { return this.style.setShadow(x, y, color, blur, shadowStroke, shadowFill); - }, + } /** * Set the shadow offset. @@ -933,10 +931,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setShadowOffset: function (x, y) + setShadowOffset(x, y) { return this.style.setShadowOffset(x, y); - }, + } /** * Set the shadow color. @@ -948,10 +946,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setShadowColor: function (color) + setShadowColor(color) { return this.style.setShadowColor(color); - }, + } /** * Set the shadow blur radius. @@ -963,10 +961,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setShadowBlur: function (blur) + setShadowBlur(blur) { return this.style.setShadowBlur(blur); - }, + } /** * Enable or disable shadow stroke. @@ -978,10 +976,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setShadowStroke: function (enabled) + setShadowStroke(enabled) { return this.style.setShadowStroke(enabled); - }, + } /** * Enable or disable shadow fill. @@ -993,10 +991,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setShadowFill: function (enabled) + setShadowFill(enabled) { return this.style.setShadowFill(enabled); - }, + } /** * Set the width (in pixels) to use for wrapping lines. Pass in null to remove wrapping by width. @@ -1011,10 +1009,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setWordWrapWidth: function (width, useAdvancedWrap) + setWordWrapWidth(width, useAdvancedWrap) { return this.style.setWordWrapWidth(width, useAdvancedWrap); - }, + } /** * Set a custom callback for wrapping lines. Pass in null to remove wrapping by callback. @@ -1030,10 +1028,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setWordWrapCallback: function (callback, scope) + setWordWrapCallback(callback, scope) { return this.style.setWordWrapCallback(callback, scope); - }, + } /** * Set the alignment of the text in this Text object. @@ -1049,10 +1047,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setAlign: function (align) + setAlign(align) { return this.style.setAlign(align); - }, + } /** * Set the resolution used by this Text object. @@ -1069,10 +1067,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setResolution: function (value) + setResolution(value) { return this.style.setResolution(value); - }, + } /** * Sets the line spacing value. @@ -1087,12 +1085,12 @@ var Text = new Class({ * * @return {this} This Text object. */ - setLineSpacing: function (value) + setLineSpacing(value) { this.lineSpacing = value; return this.updateText(); - }, + } /** * Sets the letter spacing value. @@ -1113,12 +1111,12 @@ var Text = new Class({ * * @return {this} This Text object. */ - setLetterSpacing: function (value) + setLetterSpacing(value) { this.letterSpacing = value; return this.updateText(); - }, + } /** * Set the text padding. @@ -1137,7 +1135,7 @@ var Text = new Class({ * * @return {this} This Text object. */ - setPadding: function (left, top, right, bottom) + setPadding(left, top, right, bottom) { if (typeof left === 'object') { @@ -1184,7 +1182,7 @@ var Text = new Class({ this.padding.bottom = bottom; return this.updateText(); - }, + } /** * Set the maximum number of lines to draw. @@ -1196,10 +1194,10 @@ var Text = new Class({ * * @return {this} This Text object. */ - setMaxLines: function (max) + setMaxLines(max) { return this.style.setMaxLines(max); - }, + } /** * Render text from right-to-left or left-to-right. @@ -1211,7 +1209,7 @@ var Text = new Class({ * * @return {this} This Text object. */ - setRTL: function (rtl) + setRTL(rtl) { if (rtl === undefined) { rtl = true; } @@ -1248,7 +1246,7 @@ var Text = new Class({ } return this; - }, + } /** * Update the displayed text. @@ -1258,7 +1256,7 @@ var Text = new Class({ * * @return {this} This Text object. */ - updateText: function () + updateText() { var canvas = this.canvas; var context = this.context; @@ -1492,7 +1490,7 @@ var Text = new Class({ } return this; - }, + } /** * Get the current text metrics. @@ -1502,10 +1500,10 @@ var Text = new Class({ * * @return {Phaser.Types.GameObjects.Text.TextMetrics} The text metrics. */ - getTextMetrics: function () + getTextMetrics() { return this.style.getTextMetrics(); - }, + } /** * The text string being rendered by this Text Game Object. @@ -1514,19 +1512,16 @@ var Text = new Class({ * @type {string} * @since 3.0.0 */ - text: { - get: function () - { - return this._text; - }, - - set: function (value) - { - this.setText(value); - } + get text() + { + return this._text; + } - }, + set text(value) + { + this.setText(value); + } /** * Build a JSON representation of the Text object. @@ -1536,7 +1531,7 @@ var Text = new Class({ * * @return {Phaser.Types.GameObjects.JSONGameObject} A JSON representation of the Text object. */ - toJSON: function () + toJSON() { var out = Components.ToJSON(this); @@ -1557,7 +1552,7 @@ var Text = new Class({ out.data = data; return out; - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -1566,7 +1561,7 @@ var Text = new Class({ * @protected * @since 3.0.0 */ - preDestroy: function () + preDestroy() { RemoveFromDOM(this.canvas); @@ -1604,6 +1599,6 @@ var Text = new Class({ * @since 3.0.0 */ -}); +}; module.exports = Text; diff --git a/src/gameobjects/text/TextStyle.js b/src/gameobjects/text/TextStyle.js index 5f9af249dc..0bc5bab59a 100644 --- a/src/gameobjects/text/TextStyle.js +++ b/src/gameobjects/text/TextStyle.js @@ -56,11 +56,9 @@ var propertyMap = { * @param {Phaser.GameObjects.Text} text - The Text object that this TextStyle is styling. * @param {Phaser.Types.GameObjects.Text.TextStyle} style - The style settings to set. */ -var TextStyle = new Class({ +var TextStyle = class { - initialize: - - function TextStyle (text, style) + constructor(text, style) { /** * The Text object that this TextStyle is styling. @@ -358,7 +356,7 @@ var TextStyle = new Class({ // Set to defaults + user style this.setStyle(style, false, true); - }, + } /** * Set the text style. @@ -381,7 +379,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setStyle: function (style, updateText, setDefaults) + setStyle(style, updateText, setDefaults) { if (updateText === undefined) { updateText = true; } if (setDefaults === undefined) { setDefaults = false; } @@ -448,7 +446,7 @@ var TextStyle = new Class({ { return this.parent; } - }, + } /** * Synchronize the font settings to the given Canvas Rendering Context. @@ -459,10 +457,10 @@ var TextStyle = new Class({ * @param {HTMLCanvasElement} canvas - The Canvas Element. * @param {CanvasRenderingContext2D} context - The Canvas Rendering Context. */ - syncFont: function (canvas, context) + syncFont(canvas, context) { context.font = this._font; - }, + } /** * Synchronize the text style settings to the given Canvas Rendering Context. @@ -473,7 +471,7 @@ var TextStyle = new Class({ * @param {HTMLCanvasElement} canvas - The Canvas Element. * @param {CanvasRenderingContext2D} context - The Canvas Rendering Context. */ - syncStyle: function (canvas, context) + syncStyle(canvas, context) { context.textBaseline = 'alphabetic'; @@ -483,7 +481,7 @@ var TextStyle = new Class({ context.lineWidth = this.strokeThickness; context.lineCap = 'round'; context.lineJoin = 'round'; - }, + } /** * Synchronize the shadow settings to the given Canvas Rendering Context. @@ -494,7 +492,7 @@ var TextStyle = new Class({ * @param {CanvasRenderingContext2D} context - The Canvas Rendering Context. * @param {boolean} enabled - Whether shadows are enabled or not. */ - syncShadow: function (context, enabled) + syncShadow(context, enabled) { if (enabled) { @@ -510,7 +508,7 @@ var TextStyle = new Class({ context.shadowColor = 0; context.shadowBlur = 0; } - }, + } /** * Update the style settings for the parent Text object. @@ -522,7 +520,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - update: function (recalculateMetrics) + update(recalculateMetrics) { if (recalculateMetrics) { @@ -532,7 +530,7 @@ var TextStyle = new Class({ } return this.parent.updateText(); - }, + } /** * Set the font. @@ -550,7 +548,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setFont: function (font, updateText) + setFont(font, updateText) { if (updateText === undefined) { updateText = true; } @@ -588,7 +586,7 @@ var TextStyle = new Class({ } return this.parent; - }, + } /** * Set the font family. @@ -600,7 +598,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setFontFamily: function (family) + setFontFamily(family) { if (this.fontFamily !== family) { @@ -610,7 +608,7 @@ var TextStyle = new Class({ } return this.parent; - }, + } /** * Set the font style. @@ -622,7 +620,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setFontStyle: function (style) + setFontStyle(style) { if (this.fontStyle !== style) { @@ -632,7 +630,7 @@ var TextStyle = new Class({ } return this.parent; - }, + } /** * Set the font size. Can be a string with a valid CSS unit, i.e. `16px`, or a number. @@ -644,7 +642,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setFontSize: function (size) + setFontSize(size) { if (typeof size === 'number') { @@ -659,7 +657,7 @@ var TextStyle = new Class({ } return this.parent; - }, + } /** * Set the test string to use when measuring the font. @@ -671,12 +669,12 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setTestString: function (string) + setTestString(string) { this.testString = string; return this.update(true); - }, + } /** * Set a fixed width and height for the text. @@ -691,7 +689,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setFixedSize: function (width, height) + setFixedSize(width, height) { this.fixedWidth = width; this.fixedHeight = height; @@ -707,7 +705,7 @@ var TextStyle = new Class({ } return this.update(false); - }, + } /** * Set the background color. @@ -719,12 +717,12 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setBackgroundColor: function (color) + setBackgroundColor(color) { this.backgroundColor = color; return this.update(false); - }, + } /** * Set the text fill color. @@ -736,12 +734,12 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setFill: function (color) + setFill(color) { this.color = color; return this.update(false); - }, + } /** * Set the text fill color. @@ -753,12 +751,12 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setColor: function (color) + setColor(color) { this.color = color; return this.update(false); - }, + } /** * Set the resolution used by the Text object. @@ -775,12 +773,12 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setResolution: function (value) + setResolution(value) { this.resolution = value; return this.update(false); - }, + } /** * Set the stroke settings. @@ -793,7 +791,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setStroke: function (color, thickness) + setStroke(color, thickness) { if (thickness === undefined) { thickness = this.strokeThickness; } @@ -813,7 +811,7 @@ var TextStyle = new Class({ } return this.parent; - }, + } /** * Set the shadow settings. @@ -833,7 +831,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setShadow: function (x, y, color, blur, shadowStroke, shadowFill) + setShadow(x, y, color, blur, shadowStroke, shadowFill) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -850,7 +848,7 @@ var TextStyle = new Class({ this.shadowFill = shadowFill; return this.update(false); - }, + } /** * Set the shadow offset. @@ -863,7 +861,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setShadowOffset: function (x, y) + setShadowOffset(x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = x; } @@ -872,7 +870,7 @@ var TextStyle = new Class({ this.shadowOffsetY = y; return this.update(false); - }, + } /** * Set the shadow color. @@ -884,14 +882,14 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setShadowColor: function (color) + setShadowColor(color) { if (color === undefined) { color = '#000'; } this.shadowColor = color; return this.update(false); - }, + } /** * Set the shadow blur radius. @@ -903,14 +901,14 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setShadowBlur: function (blur) + setShadowBlur(blur) { if (blur === undefined) { blur = 0; } this.shadowBlur = blur; return this.update(false); - }, + } /** * Enable or disable shadow stroke. @@ -922,12 +920,12 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setShadowStroke: function (enabled) + setShadowStroke(enabled) { this.shadowStroke = enabled; return this.update(false); - }, + } /** * Enable or disable shadow fill. @@ -939,12 +937,12 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setShadowFill: function (enabled) + setShadowFill(enabled) { this.shadowFill = enabled; return this.update(false); - }, + } /** * Set the width (in pixels) to use for wrapping lines. @@ -961,7 +959,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setWordWrapWidth: function (width, useAdvancedWrap) + setWordWrapWidth(width, useAdvancedWrap) { if (useAdvancedWrap === undefined) { useAdvancedWrap = false; } @@ -969,7 +967,7 @@ var TextStyle = new Class({ this.wordWrapUseAdvanced = useAdvancedWrap; return this.update(false); - }, + } /** * Set a custom callback for wrapping lines. @@ -987,7 +985,7 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setWordWrapCallback: function (callback, scope) + setWordWrapCallback(callback, scope) { if (scope === undefined) { scope = null; } @@ -995,7 +993,7 @@ var TextStyle = new Class({ this.wordWrapCallbackScope = scope; return this.update(false); - }, + } /** * Set the alignment of the text in this Text object. @@ -1011,14 +1009,14 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setAlign: function (align) + setAlign(align) { if (align === undefined) { align = 'left'; } this.align = align; return this.update(false); - }, + } /** * Set the maximum number of lines to draw. @@ -1030,14 +1028,14 @@ var TextStyle = new Class({ * * @return {Phaser.GameObjects.Text} The parent Text object. */ - setMaxLines: function (max) + setMaxLines(max) { if (max === undefined) { max = 0; } this.maxLines = max; return this.update(false); - }, + } /** * Get the current text metrics. @@ -1047,7 +1045,7 @@ var TextStyle = new Class({ * * @return {Phaser.Types.GameObjects.Text.TextMetrics} The text metrics. */ - getTextMetrics: function () + getTextMetrics() { var metrics = this.metrics; @@ -1056,7 +1054,7 @@ var TextStyle = new Class({ descent: metrics.descent, fontSize: metrics.fontSize }; - }, + } /** * Build a JSON representation of this Text Style. @@ -1066,7 +1064,7 @@ var TextStyle = new Class({ * * @return {object} A JSON representation of this Text Style. */ - toJSON: function () + toJSON() { var output = {}; @@ -1078,7 +1076,7 @@ var TextStyle = new Class({ output.metrics = this.getTextMetrics(); return output; - }, + } /** * Destroy this Text Style. @@ -1086,11 +1084,11 @@ var TextStyle = new Class({ * @method Phaser.GameObjects.TextStyle#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.parent = undefined; } -}); +}; module.exports = TextStyle; diff --git a/src/gameobjects/tilesprite/TileSprite.js b/src/gameobjects/tilesprite/TileSprite.js index 05be6d4500..a59f23298f 100644 --- a/src/gameobjects/tilesprite/TileSprite.js +++ b/src/gameobjects/tilesprite/TileSprite.js @@ -69,39 +69,38 @@ var _FLAG = 8; // 1000 * @param {string} textureKey - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. Cannot be a DynamicTexture. * @param {(string|number)} [frameKey] - An optional frame from the Texture this Game Object is rendering with. */ -var TileSprite = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.ComputedSize, - Components.Crop, - Components.Depth, - Components.Flip, - Components.GetBounds, - Components.Lighting, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.ScrollFactor, - Components.TextureCrop, - Components.Tint, - Components.Transform, - Components.Visible, - TileSpriteRender - ], - - initialize: - - function TileSprite (scene, x, y, width, height, textureKey, frameKey) +var TileSprite = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.ComputedSize, + Components.Crop, + Components.Depth, + Components.Flip, + Components.GetBounds, + Components.Lighting, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.ScrollFactor, + Components.TextureCrop, + Components.Tint, + Components.Transform, + Components.Visible, + TileSpriteRender + ], false); + } + + constructor(scene, x, y, width, height, textureKey, frameKey) { var renderer = scene.sys.renderer; var isCanvas = renderer && !renderer.gl; - GameObject.call(this, scene, 'TileSprite'); + super(scene, 'TileSprite'); var displayTexture = scene.sys.textures.get(textureKey); var displayFrame = displayTexture.get(frameKey); @@ -270,7 +269,7 @@ var TileSprite = new Class({ this.setSize(width, height); this.setOrigin(0.5, 0.5); this.initRenderNodes(this._defaultRenderNodesMap); - }, + } /** * The default render nodes for this Game Object. @@ -282,24 +281,23 @@ var TileSprite = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultTileSpriteNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultTileSpriteNodes; + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } /** * Update this TileSprite's animations. @@ -311,10 +309,10 @@ var TileSprite = new Class({ * @param {number} time - The current timestamp. * @param {number} delta - The delta time, in ms, elapsed since the last frame. */ - preUpdate: function (time, delta) + preUpdate(time, delta) { this.anims.update(time, delta); - }, + } /** * Sets the frame this Game Object will use to render with. @@ -330,7 +328,7 @@ var TileSprite = new Class({ * * @return {this} This Game Object instance. */ - setFrame: function (frame) + setFrame(frame) { var newFrame = this.texture.get(frame); @@ -348,7 +346,7 @@ var TileSprite = new Class({ this.dirty = true; return this; - }, + } /** * No-op method for compatibility with Animation. @@ -357,10 +355,10 @@ var TileSprite = new Class({ * @since 4.0.0 * @return {this} This Tile Sprite instance. */ - setSizeToFrame: function () + setSizeToFrame() { return this; - }, + } /** * Sets {@link Phaser.GameObjects.TileSprite#tilePositionX} and {@link Phaser.GameObjects.TileSprite#tilePositionY}. @@ -373,7 +371,7 @@ var TileSprite = new Class({ * * @return {this} This Tile Sprite instance. */ - setTilePosition: function (x, y) + setTilePosition(x, y) { if (x !== undefined) { @@ -386,7 +384,7 @@ var TileSprite = new Class({ } return this; - }, + } /** * Sets {@link Phaser.GameObjects.TileSprite#tileRotation}. @@ -396,14 +394,14 @@ var TileSprite = new Class({ * * @param {number} [radians=0] - The rotation of the tiling texture, in radians. */ - setTileRotation: function (radians) + setTileRotation(radians) { if (radians === undefined) { radians = 0; } this.tileRotation = radians; return this; - }, + } /** * Sets {@link Phaser.GameObjects.TileSprite#tileScaleX} and {@link Phaser.GameObjects.TileSprite#tileScaleY}. @@ -416,7 +414,7 @@ var TileSprite = new Class({ * * @return {this} This Tile Sprite instance. */ - setTileScale: function (x, y) + setTileScale(x, y) { if (x === undefined) { x = this.tileScaleX; } if (y === undefined) { y = x; } @@ -425,7 +423,7 @@ var TileSprite = new Class({ this.tileScaleY = y; return this; - }, + } /** * Render the tile texture if it is dirty, or if the frame has changed. @@ -437,7 +435,7 @@ var TileSprite = new Class({ * @private * @since 3.0.0 */ - updateTileTexture: function () + updateTileTexture() { if (!this.renderer || this.renderer.gl) { @@ -470,7 +468,7 @@ var TileSprite = new Class({ this.fillPattern = ctx.createPattern(canvas, 'repeat'); this.currentFrame = frame; - }, + } /** * Draw the fill pattern to the internal canvas. @@ -482,7 +480,7 @@ var TileSprite = new Class({ * @private * @since 3.12.0 */ - updateCanvas: function () + updateCanvas() { var canvas = this.canvas; var width = this.width; @@ -551,7 +549,7 @@ var TileSprite = new Class({ ctx.restore(); this.dirty = false; - }, + } /** * Internal destroy handler, called as part of the destroy process. @@ -560,7 +558,7 @@ var TileSprite = new Class({ * @protected * @since 3.9.0 */ - preDestroy: function () + preDestroy() { if (this.canvas) { @@ -583,7 +581,7 @@ var TileSprite = new Class({ this.anims.destroy(); this.anims = undefined; - }, + } /** * The horizontal scroll position of the Tile Sprite. @@ -593,20 +591,17 @@ var TileSprite = new Class({ * @default 0 * @since 3.0.0 */ - tilePositionX: { - - get: function () - { - return this._tilePosition.x; - }, - set: function (value) - { - this._tilePosition.x = value; - this.dirty = true; - } + get tilePositionX() + { + return this._tilePosition.x; + } - }, + set tilePositionX(value) + { + this._tilePosition.x = value; + this.dirty = true; + } /** * The vertical scroll position of the Tile Sprite. @@ -616,20 +611,17 @@ var TileSprite = new Class({ * @default 0 * @since 3.0.0 */ - tilePositionY: { - get: function () - { - return this._tilePosition.y; - }, - - set: function (value) - { - this._tilePosition.y = value; - this.dirty = true; - } + get tilePositionY() + { + return this._tilePosition.y; + } - }, + set tilePositionY(value) + { + this._tilePosition.y = value; + this.dirty = true; + } /** * The rotation of the Tile Sprite texture, in radians. @@ -639,18 +631,17 @@ var TileSprite = new Class({ * @default 0 * @since 4.0.0 */ - tileRotation: { - get: function () - { - return this._tileRotation; - }, - set: function (radians) - { - this._tileRotation = radians; - this.dirty = true; - } - }, + get tileRotation() + { + return this._tileRotation; + } + + set tileRotation(radians) + { + this._tileRotation = radians; + this.dirty = true; + } /** * The horizontal scale of the Tile Sprite texture. @@ -660,20 +651,17 @@ var TileSprite = new Class({ * @default 1 * @since 3.11.0 */ - tileScaleX: { - - get: function () - { - return this._tileScale.x; - }, - set: function (value) - { - this._tileScale.x = value; - this.dirty = true; - } + get tileScaleX() + { + return this._tileScale.x; + } - }, + set tileScaleX(value) + { + this._tileScale.x = value; + this.dirty = true; + } /** * The vertical scale of the Tile Sprite texture. @@ -683,21 +671,18 @@ var TileSprite = new Class({ * @default 1 * @since 3.11.0 */ - tileScaleY: { - get: function () - { - return this._tileScale.y; - }, - - set: function (value) - { - this._tileScale.y = value; - this.dirty = true; - } + get tileScaleY() + { + return this._tileScale.y; + } + set tileScaleY(value) + { + this._tileScale.y = value; + this.dirty = true; } -}); +}; module.exports = TileSprite; diff --git a/src/gameobjects/video/Video.js b/src/gameobjects/video/Video.js index f2a01fd608..6d08406f1b 100644 --- a/src/gameobjects/video/Video.js +++ b/src/gameobjects/video/Video.js @@ -122,34 +122,33 @@ var VideoRender = require('./VideoRender'); * @param {number} y - The vertical position of this Game Object in the world. * @param {string} [key] - Optional key of the Video this Game Object will play, as stored in the Video Cache. */ -var Video = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.ComputedSize, - Components.Depth, - Components.Flip, - Components.GetBounds, - Components.Lighting, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.ScrollFactor, - Components.TextureCrop, - Components.Tint, - Components.Transform, - Components.Visible, - VideoRender - ], - - initialize: - - function Video (scene, x, y, key) +var Video = class extends GameObject { + + static { - GameObject.call(this, scene, 'Video'); + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.ComputedSize, + Components.Depth, + Components.Flip, + Components.GetBounds, + Components.Lighting, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.ScrollFactor, + Components.TextureCrop, + Components.Tint, + Components.Transform, + Components.Visible, + VideoRender + ], false); + } + + constructor(scene, x, y, key) + { + super(scene, 'Video'); /** * A reference to the HTML Video Element this Video Game Object is playing. @@ -549,7 +548,7 @@ var Video = new Class({ { this.load(key); } - }, + } /** * The default render node map for this Game Object. @@ -561,24 +560,23 @@ var Video = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultImageNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultImageNodes; + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } /** * Loads a Video from the Video Cache, ready for playback with the `Video.play` method. @@ -597,7 +595,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - load: function (key) + load(key) { var video = this.scene.sys.cache.video.get(key); @@ -613,7 +611,7 @@ var Video = new Class({ } return this; - }, + } /** * This method allows you to change the source of the current video element. It works by first stopping the @@ -635,7 +633,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - changeSource: function (key, autoplay, loop, markerIn, markerOut) + changeSource(key, autoplay, loop, markerIn, markerOut) { if (autoplay === undefined) { autoplay = true; } if (loop === undefined) { loop = false; } @@ -649,7 +647,7 @@ var Video = new Class({ this.play(loop, markerIn, markerOut); } } - }, + } /** * Returns the key of the currently played video, as stored in the Video Cache. @@ -661,10 +659,10 @@ var Video = new Class({ * * @return {string} The key of the video being played from the Video Cache, if any. */ - getVideoKey: function () + getVideoKey() { return this.cacheKey; - }, + } /** * Loads a Video from the given URL, ready for playback with the `Video.play` method. @@ -685,7 +683,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - loadURL: function (urls, noAudio, crossOrigin) + loadURL(urls, noAudio, crossOrigin) { if (noAudio === undefined) { noAudio = false; } @@ -703,7 +701,7 @@ var Video = new Class({ } return this; - }, + } /** * Loads a Video from the given MediaStream object, ready for playback with the `Video.play` method. @@ -717,10 +715,10 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - loadMediaStream: function (stream, noAudio, crossOrigin) + loadMediaStream(stream, noAudio, crossOrigin) { return this.loadHandler(null, noAudio, crossOrigin, stream); - }, + } /** * Internal method that loads a Video from the given URL, ready for playback with the @@ -742,7 +740,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - loadHandler: function (url, noAudio, crossOrigin, stream) + loadHandler(url, noAudio, crossOrigin, stream) { if (!noAudio) { noAudio = false; } @@ -833,7 +831,7 @@ var Video = new Class({ this.setTexture(texture); return this; - }, + } /** * This method handles the Request Video Frame callback. @@ -857,7 +855,7 @@ var Video = new Class({ * @param {DOMHighResTimeStamp} now - The current time in milliseconds. * @param {VideoFrameCallbackMetadata} metadata - Useful metadata about the video frame that was most recently presented for composition. See https://wicg.github.io/video-rvfc/#video-frame-metadata-callback */ - requestVideoFrame: function (now, metadata) + requestVideoFrame(now, metadata) { var video = this.video; @@ -970,7 +968,7 @@ var Video = new Class({ { this._rfvCallbackId = this.video.requestVideoFrameCallback(this.requestVideoFrame.bind(this)); } - }, + } /** * Starts this video playing. @@ -1006,7 +1004,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - play: function (loop, markerIn, markerOut) + play(loop, markerIn, markerOut) { if (markerIn === undefined) { markerIn = -1; } if (markerOut === undefined) { markerOut = MATH_CONST.MAX_SAFE_INTEGER; } @@ -1047,7 +1045,7 @@ var Video = new Class({ } return this; - }, + } /** * Attempts to get the first frame of the video by running the `requestVideoFrame` callback once, @@ -1061,7 +1059,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - getFirstFrame: function () + getFirstFrame() { var video = this.video; @@ -1085,7 +1083,7 @@ var Video = new Class({ } return this; - }, + } /** * Adds the loading specific event handlers to the video element. @@ -1093,7 +1091,7 @@ var Video = new Class({ * @method Phaser.GameObjects.Video#addLoadEventHandlers * @since 3.60.0 */ - addLoadEventHandlers: function () + addLoadEventHandlers() { var video = this.video; @@ -1103,7 +1101,7 @@ var Video = new Class({ video.addEventListener('abort', this._loadCallbackHandler); video.addEventListener('loadedmetadata', this._metadataCallbackHandler); } - }, + } /** * Removes the loading specific event handlers from the video element. @@ -1111,7 +1109,7 @@ var Video = new Class({ * @method Phaser.GameObjects.Video#removeLoadEventHandlers * @since 3.60.0 */ - removeLoadEventHandlers: function () + removeLoadEventHandlers() { var video = this.video; @@ -1120,7 +1118,7 @@ var Video = new Class({ video.removeEventListener('error', this._loadCallbackHandler); video.removeEventListener('abort', this._loadCallbackHandler); } - }, + } /** * Adds the playback specific event handlers to the video element. @@ -1128,7 +1126,7 @@ var Video = new Class({ * @method Phaser.GameObjects.Video#addEventHandlers * @since 3.60.0 */ - addEventHandlers: function () + addEventHandlers() { var video = this.video; @@ -1144,7 +1142,7 @@ var Video = new Class({ video.addEventListener(callback, callbacks[callback]); } } - }, + } /** * Removes the playback specific event handlers from the video element. @@ -1152,7 +1150,7 @@ var Video = new Class({ * @method Phaser.GameObjects.Video#removeEventHandlers * @since 3.60.0 */ - removeEventHandlers: function () + removeEventHandlers() { var video = this.video; @@ -1165,7 +1163,7 @@ var Video = new Class({ video.removeEventListener(callback, callbacks[callback]); } } - }, + } /** * Creates the video.play promise and adds the success and error handlers to it. @@ -1180,7 +1178,7 @@ var Video = new Class({ * * @param {boolean} [catchError=true] - Should the error be caught and the video marked as failed to play? */ - createPlayPromise: function (catchError) + createPlayPromise(catchError) { if (catchError === undefined) { catchError = true; } @@ -1215,7 +1213,7 @@ var Video = new Class({ this.failedPlayAttempts++; } } - }, + } /** * Adds a sequence marker to this video. @@ -1238,7 +1236,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - addMarker: function (key, markerIn, markerOut) + addMarker(key, markerIn, markerOut) { if (!isNaN(markerIn) && markerIn >= 0 && !isNaN(markerOut) && markerOut > markerIn) { @@ -1246,7 +1244,7 @@ var Video = new Class({ } return this; - }, + } /** * Plays a pre-defined sequence in this video. @@ -1267,7 +1265,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - playMarker: function (key, loop) + playMarker(key, loop) { var marker = this.markers[key]; @@ -1277,7 +1275,7 @@ var Video = new Class({ } return this; - }, + } /** * Removes a previously set marker from this video. @@ -1291,12 +1289,12 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - removeMarker: function (key) + removeMarker(key) { delete this.markers[key]; return this; - }, + } /** * Takes a snapshot of the current frame of the video and renders it to a CanvasTexture object, @@ -1313,13 +1311,13 @@ var Video = new Class({ * * @return {Phaser.Textures.CanvasTexture} */ - snapshot: function (width, height) + snapshot(width, height) { if (width === undefined) { width = this.width; } if (height === undefined) { height = this.height; } return this.snapshotArea(0, 0, this.width, this.height, width, height); - }, + } /** * Takes a snapshot of the specified area of the current frame of the video and renders it to a CanvasTexture object, @@ -1340,7 +1338,7 @@ var Video = new Class({ * * @return {Phaser.Textures.CanvasTexture} */ - snapshotArea: function (x, y, srcWidth, srcHeight, destWidth, destHeight) + snapshotArea(x, y, srcWidth, srcHeight, destWidth, destHeight) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -1374,7 +1372,7 @@ var Video = new Class({ } return snap.update(); - }, + } /** * Stores a copy of this Videos `snapshotTexture` in the Texture Manager using the given key. @@ -1410,7 +1408,7 @@ var Video = new Class({ * * @return {Phaser.Textures.CanvasTexture} The Texture that was saved. */ - saveSnapshotTexture: function (key) + saveSnapshotTexture(key) { if (this.snapshotTexture) { @@ -1422,7 +1420,7 @@ var Video = new Class({ } return this.snapshotTexture; - }, + } /** * This internal method is called automatically if the playback Promise resolves successfully. @@ -1431,7 +1429,7 @@ var Video = new Class({ * @fires Phaser.GameObjects.Events#VIDEO_UNLOCKED * @since 3.60.0 */ - playSuccess: function () + playSuccess() { if (!this._playCalled) { @@ -1463,7 +1461,7 @@ var Video = new Class({ { this.video.currentTime = this._markerIn; } - }, + } /** * This internal method is called automatically if the playback Promise fails to resolve. @@ -1476,7 +1474,7 @@ var Video = new Class({ * * @param {DOMException} error - The Promise DOM Exception error. */ - playError: function (error) + playError(error) { var name = error.name; @@ -1500,7 +1498,7 @@ var Video = new Class({ this.emit(Events.VIDEO_ERROR, this, error); } - }, + } /** * Called when the video emits a `playing` event. @@ -1510,7 +1508,7 @@ var Video = new Class({ * @method Phaser.GameObjects.Video#legacyPlayHandler * @since 3.60.0 */ - legacyPlayHandler: function () + legacyPlayHandler() { var video = this.video; @@ -1520,7 +1518,7 @@ var Video = new Class({ video.removeEventListener('playing', this._callbacks.legacy); } - }, + } /** * Called when the video emits a `playing` event. @@ -1529,12 +1527,12 @@ var Video = new Class({ * @fires Phaser.GameObjects.Events#VIDEO_PLAYING * @since 3.60.0 */ - playingHandler: function () + playingHandler() { this.isStalled = false; this.emit(Events.VIDEO_PLAYING, this); - }, + } /** * This internal method is called automatically if the video fails to load. @@ -1545,12 +1543,12 @@ var Video = new Class({ * * @param {Event} event - The error Event. */ - loadErrorHandler: function (event) + loadErrorHandler(event) { this.stop(false); this.emit(Events.VIDEO_ERROR, this, event); - }, + } /** * This internal method is called automatically when the video metadata is available. @@ -1561,10 +1559,10 @@ var Video = new Class({ * * @param {Event} event - The loadedmetadata Event. */ - metadataHandler: function (event) + metadataHandler(event) { this.emit(Events.VIDEO_METADATA, this, event); - }, + } /** * Sets the size of this Game Object to be that of the given Frame. @@ -1584,7 +1582,7 @@ var Video = new Class({ * * @return {this} This Game Object instance. */ - setSizeToFrame: function (frame) + setSizeToFrame(frame) { if (!frame) { frame = this.frame; } @@ -1610,7 +1608,7 @@ var Video = new Class({ } return this; - }, + } /** * This internal method is called automatically if the video stalls, for whatever reason. @@ -1621,12 +1619,12 @@ var Video = new Class({ * * @param {Event} event - The error Event. */ - stalledHandler: function (event) + stalledHandler(event) { this.isStalled = true; this.emit(Events.VIDEO_STALLED, this, event); - }, + } /** * Called when the video completes playback, i.e. reaches an `ended` state. @@ -1637,12 +1635,12 @@ var Video = new Class({ * @fires Phaser.GameObjects.Events#VIDEO_COMPLETE * @since 3.20.0 */ - completeHandler: function () + completeHandler() { this._playCalled = false; this.emit(Events.VIDEO_COMPLETE, this); - }, + } /** * The internal update step. @@ -1654,7 +1652,7 @@ var Video = new Class({ * @param {number} time - The current timestamp. * @param {number} delta - The delta time in ms since the last frame. */ - preUpdate: function (time, delta) + preUpdate(time, delta) { var video = this.video; @@ -1674,7 +1672,7 @@ var Video = new Class({ this.retry = 0; } } - }, + } /** * Seeks to a given point in the video. The value is given as a float between 0 and 1, @@ -1697,7 +1695,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - seekTo: function (value) + seekTo(value) { var video = this.video; @@ -1714,7 +1712,7 @@ var Video = new Class({ } return this; - }, + } /** * A double-precision floating-point value indicating the current playback time in seconds. @@ -1728,10 +1726,10 @@ var Video = new Class({ * * @return {number} A double-precision floating-point value indicating the current playback time in seconds. */ - getCurrentTime: function () + getCurrentTime() { return (this.video) ? this.video.currentTime : 0; - }, + } /** * Seeks to a given playback time in the video. The value is given in _seconds_ or as a string. @@ -1753,7 +1751,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - setCurrentTime: function (value) + setCurrentTime(value) { var video = this.video; @@ -1778,7 +1776,7 @@ var Video = new Class({ } return this; - }, + } /** * Internal seeking handler. @@ -1788,12 +1786,12 @@ var Video = new Class({ * @private * @since 3.20.0 */ - seekingHandler: function () + seekingHandler() { this.isSeeking = true; this.emit(Events.VIDEO_SEEKING, this); - }, + } /** * Internal seeked handler. @@ -1803,12 +1801,12 @@ var Video = new Class({ * @private * @since 3.20.0 */ - seekedHandler: function () + seekedHandler() { this.isSeeking = false; this.emit(Events.VIDEO_SEEKED, this); - }, + } /** * Returns the current progress of the video as a float. @@ -1824,7 +1822,7 @@ var Video = new Class({ * * @return {number} The current progress of playback. If the video has no duration, will always return -1. */ - getProgress: function () + getProgress() { var video = this.video; @@ -1839,7 +1837,7 @@ var Video = new Class({ } return -1; - }, + } /** * A double-precision floating-point value which indicates the duration (total length) of the media in seconds, @@ -1855,10 +1853,10 @@ var Video = new Class({ * * @return {number} A double-precision floating-point value indicating the duration of the media in seconds. */ - getDuration: function () + getDuration() { return (this.video) ? this.video.duration : 0; - }, + } /** * Sets the muted state of the currently playing video, if one is loaded. @@ -1870,7 +1868,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - setMute: function (value) + setMute(value) { if (value === undefined) { value = true; } @@ -1884,7 +1882,7 @@ var Video = new Class({ } return this; - }, + } /** * Returns a boolean indicating if this Video is currently muted. @@ -1894,10 +1892,10 @@ var Video = new Class({ * * @return {boolean} A boolean indicating if this Video is currently muted, or not. */ - isMuted: function () + isMuted() { return this._codeMuted; - }, + } /** * Internal global mute handler. Will mute the video, if playing, if the global sound system mutes. @@ -1909,7 +1907,7 @@ var Video = new Class({ * @param {(Phaser.Sound.WebAudioSoundManager|Phaser.Sound.HTML5AudioSoundManager)} soundManager - A reference to the Sound Manager that emitted the event. * @param {boolean} mute - The mute value. `true` if the Sound Manager is now muted, otherwise `false`. */ - globalMute: function (soundManager, value) + globalMute(soundManager, value) { this._systemMuted = value; @@ -1919,7 +1917,7 @@ var Video = new Class({ { video.muted = (this._codeMuted) ? true : value; } - }, + } /** * Internal global pause handler. Will pause the video if the Game itself pauses. @@ -1928,7 +1926,7 @@ var Video = new Class({ * @private * @since 3.20.0 */ - globalPause: function () + globalPause() { this._systemPaused = true; @@ -1938,7 +1936,7 @@ var Video = new Class({ this.video.pause(); } - }, + } /** * Internal global resume handler. Will resume a paused video if the Game itself resumes. @@ -1947,7 +1945,7 @@ var Video = new Class({ * @private * @since 3.20.0 */ - globalResume: function () + globalResume() { this._systemPaused = false; @@ -1955,7 +1953,7 @@ var Video = new Class({ { this.createPlayPromise(); } - }, + } /** * Sets the paused state of the currently loaded video. @@ -1976,7 +1974,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - setPaused: function (value) + setPaused(value) { if (value === undefined) { value = true; } @@ -2009,7 +2007,7 @@ var Video = new Class({ } return this; - }, + } /** * Pauses the current Video, if one is playing. @@ -2023,10 +2021,10 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - pause: function () + pause() { return this.setPaused(true); - }, + } /** * Resumes the current Video, if one was previously playing and has been paused. @@ -2040,10 +2038,10 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - resume: function () + resume() { return this.setPaused(false); - }, + } /** * Returns a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). @@ -2053,10 +2051,10 @@ var Video = new Class({ * * @return {number} A double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). */ - getVolume: function () + getVolume() { return (this.video) ? this.video.volume : 1; - }, + } /** * Sets the volume of the currently playing video. @@ -2070,7 +2068,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - setVolume: function (value) + setVolume(value) { if (value === undefined) { value = 1; } @@ -2080,7 +2078,7 @@ var Video = new Class({ } return this; - }, + } /** * Returns a double that indicates the rate at which the media is being played back. @@ -2090,10 +2088,10 @@ var Video = new Class({ * * @return {number} A double that indicates the rate at which the media is being played back. */ - getPlaybackRate: function () + getPlaybackRate() { return (this.video) ? this.video.playbackRate : 1; - }, + } /** * Sets the playback rate of the current video. @@ -2107,7 +2105,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - setPlaybackRate: function (rate) + setPlaybackRate(rate) { if (this.video) { @@ -2115,7 +2113,7 @@ var Video = new Class({ } return this; - }, + } /** * Returns a boolean which indicates whether the media element should start over when it reaches the end. @@ -2125,10 +2123,10 @@ var Video = new Class({ * * @return {boolean} A boolean which indicates whether the media element will start over when it reaches the end. */ - getLoop: function () + getLoop() { return (this.video) ? this.video.loop : false; - }, + } /** * Sets the loop state of the current video. @@ -2146,7 +2144,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - setLoop: function (value) + setLoop(value) { if (value === undefined) { value = true; } @@ -2156,7 +2154,7 @@ var Video = new Class({ } return this; - }, + } /** * Returns a boolean which indicates whether the video is currently playing. @@ -2166,10 +2164,10 @@ var Video = new Class({ * * @return {boolean} A boolean which indicates whether the video is playing, or not. */ - isPlaying: function () + isPlaying() { return (this.video) ? !(this.video.paused || this.video.ended) : false; - }, + } /** * Returns a boolean which indicates whether the video is currently paused. @@ -2179,10 +2177,10 @@ var Video = new Class({ * * @return {boolean} A boolean which indicates whether the video is paused, or not. */ - isPaused: function () + isPaused() { return ((this.video && this._playCalled && this.video.paused) || this._codePaused || this._systemPaused); - }, + } /** * Stores this Video in the Texture Manager using the given key as a dynamic texture, @@ -2235,7 +2233,7 @@ var Video = new Class({ * * @return {boolean} Returns `true` if the texture is available immediately, otherwise returns `false` and you should listen for the `TEXTURE_READY` event. */ - saveTexture: function (key, flipY) + saveTexture(key, flipY) { if (flipY === undefined) { flipY = true; } @@ -2249,7 +2247,7 @@ var Video = new Class({ this.glFlipY = flipY; return (this.videoTexture) ? true : false; - }, + } /** * Stops the video playing and clears all internal event listeners. @@ -2267,7 +2265,7 @@ var Video = new Class({ * * @return {this} This Video Game Object for method chaining. */ - stop: function (emitStopEvent) + stop(emitStopEvent) { if (emitStopEvent === undefined) { emitStopEvent = true; } @@ -2291,7 +2289,7 @@ var Video = new Class({ } return this; - }, + } /** * Removes the Video element from the DOM by calling parentNode.removeChild on itself. @@ -2307,7 +2305,7 @@ var Video = new Class({ * @method Phaser.GameObjects.Video#removeVideoElement * @since 3.20.0 */ - removeVideoElement: function () + removeVideoElement() { var video = this.video; @@ -2330,7 +2328,7 @@ var Video = new Class({ video.removeAttribute('src'); this.video = null; - }, + } /** * Handles the pre-destroy step for the Video object. @@ -2343,7 +2341,7 @@ var Video = new Class({ * @private * @since 3.21.0 */ - preDestroy: function () + preDestroy() { this.stop(false); @@ -2364,6 +2362,6 @@ var Video = new Class({ } } -}); +}; module.exports = Video; diff --git a/src/gameobjects/zone/Zone.js b/src/gameobjects/zone/Zone.js index d3a6961fca..27b309b043 100644 --- a/src/gameobjects/zone/Zone.js +++ b/src/gameobjects/zone/Zone.js @@ -46,27 +46,26 @@ var RectangleContains = require('../../geom/rectangle/Contains'); * @param {number} [width=1] - The width of the Game Object. * @param {number} [height=1] - The height of the Game Object. */ -var Zone = new Class({ +var Zone = class extends GameObject { - Extends: GameObject, - - Mixins: [ - Components.Depth, - Components.GetBounds, - Components.Origin, - Components.Transform, - Components.ScrollFactor, - Components.Visible - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Depth, + Components.GetBounds, + Components.Origin, + Components.Transform, + Components.ScrollFactor, + Components.Visible + ], false); + } - function Zone (scene, x, y, width, height) + constructor(scene, x, y, width, height) { if (width === undefined) { width = 1; } if (height === undefined) { height = width; } - GameObject.call(this, scene, 'Zone'); + super(scene, 'Zone'); this.setPosition(x, y); @@ -100,7 +99,7 @@ var Zone = new Class({ this.blendMode = BlendModes.NORMAL; this.updateDisplayOrigin(); - }, + } /** * The displayed width of this Game Object. @@ -110,19 +109,16 @@ var Zone = new Class({ * @type {number} * @since 3.0.0 */ - displayWidth: { - - get: function () - { - return this.scaleX * this.width; - }, - set: function (value) - { - this.scaleX = value / this.width; - } + get displayWidth() + { + return this.scaleX * this.width; + } - }, + set displayWidth(value) + { + this.scaleX = value / this.width; + } /** * The displayed height of this Game Object. @@ -132,19 +128,16 @@ var Zone = new Class({ * @type {number} * @since 3.0.0 */ - displayHeight: { - - get: function () - { - return this.scaleY * this.height; - }, - set: function (value) - { - this.scaleY = value / this.height; - } + get displayHeight() + { + return this.scaleY * this.height; + } - }, + set displayHeight(value) + { + this.scaleY = value / this.height; + } /** * Sets the size of this Game Object. @@ -158,7 +151,7 @@ var Zone = new Class({ * * @return {this} This Game Object. */ - setSize: function (width, height, resizeInput) + setSize(width, height, resizeInput) { if (resizeInput === undefined) { resizeInput = true; } @@ -176,7 +169,7 @@ var Zone = new Class({ } return this; - }, + } /** * Sets the display size of this Game Object. @@ -190,13 +183,13 @@ var Zone = new Class({ * * @return {this} This Game Object. */ - setDisplaySize: function (width, height) + setDisplaySize(width, height) { this.displayWidth = width; this.displayHeight = height; return this; - }, + } /** * Sets this Zone to be a Circular Drop Zone. @@ -209,10 +202,10 @@ var Zone = new Class({ * * @return {this} This Game Object. */ - setCircleDropZone: function (radius) + setCircleDropZone(radius) { return this.setDropZone(new Circle(0, 0, radius), CircleContains); - }, + } /** * Sets this Zone to be a Rectangle Drop Zone. @@ -226,10 +219,10 @@ var Zone = new Class({ * * @return {this} This Game Object. */ - setRectangleDropZone: function (width, height) + setRectangleDropZone(width, height) { return this.setDropZone(new Rectangle(0, 0, width, height), RectangleContains); - }, + } /** * Allows you to define your own Geometry shape to be used as a Drop Zone. @@ -242,7 +235,7 @@ var Zone = new Class({ * * @return {this} This Game Object. */ - setDropZone: function (hitArea, hitAreaCallback) + setDropZone(hitArea, hitAreaCallback) { if (!this.input) { @@ -250,7 +243,7 @@ var Zone = new Class({ } return this; - }, + } /** * A NOOP method so you can pass a Zone to a Container. @@ -260,9 +253,9 @@ var Zone = new Class({ * @private * @since 3.11.0 */ - setAlpha: function () + setAlpha() { - }, + } /** * A NOOP method so you can pass a Zone to a Container in Canvas. @@ -272,9 +265,9 @@ var Zone = new Class({ * @private * @since 3.16.2 */ - setBlendMode: function () + setBlendMode() { - }, + } /** * A Zone does not render. @@ -288,10 +281,10 @@ var Zone = new Class({ * @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 */ - renderCanvas: function (renderer, src, camera) + renderCanvas(renderer, src, camera) { camera.addToRenderList(src); - }, + } /** * A Zone does not render. @@ -304,11 +297,11 @@ var Zone = new Class({ * @param {Phaser.GameObjects.Image} src - The Game Object being rendered in this call. * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. */ - renderWebGL: function (renderer, src, drawingContext) + renderWebGL(renderer, src, drawingContext) { drawingContext.camera.addToRenderList(src); } -}); +}; module.exports = Zone; diff --git a/src/geom/circle/Circle.js b/src/geom/circle/Circle.js index 40d217758c..dc17dff619 100644 --- a/src/geom/circle/Circle.js +++ b/src/geom/circle/Circle.js @@ -28,11 +28,9 @@ var Random = require('./Random'); * @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({ +var Circle = class { - initialize: - - function Circle (x, y, radius) + constructor(x, y, radius) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -88,7 +86,7 @@ var Circle = new Class({ * @since 3.0.0 */ this._diameter = radius * 2; - }, + } /** * Check to see if the Circle contains the given x / y coordinates. @@ -101,10 +99,10 @@ var Circle = new Class({ * * @return {boolean} True if the coordinates are within the circle, otherwise false. */ - contains: function (x, y) + contains(x, y) { return Contains(this, x, y); - }, + } /** * Returns a Point object containing the coordinates of a point on the circumference of the Circle @@ -121,10 +119,10 @@ var Circle = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 containing the coordinates of the point around the circle. */ - getPoint: function (position, out) + getPoint(position, out) { return GetPoint(this, position, out); - }, + } /** * Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, @@ -141,10 +139,10 @@ var Circle = new Class({ * * @return {Phaser.Math.Vector2[]} An array of Vector2 objects pertaining to the points around the circumference of the circle. */ - getPoints: function (quantity, stepRate, output) + getPoints(quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); - }, + } /** * Returns a uniformly distributed random point from anywhere within the Circle. @@ -158,10 +156,10 @@ var Circle = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 object with the random values set in the `x` and `y` properties. */ - getRandomPoint: function (vec) + getRandomPoint(vec) { return Random(this, vec); - }, + } /** * Sets the x, y and radius of this circle. @@ -175,7 +173,7 @@ var Circle = new Class({ * * @return {this} This Circle object. */ - setTo: function (x, y, radius) + setTo(x, y, radius) { this.x = x; this.y = y; @@ -183,7 +181,7 @@ var Circle = new Class({ this._diameter = radius * 2; return this; - }, + } /** * Sets this Circle to be empty with a radius of zero. @@ -194,13 +192,13 @@ var Circle = new Class({ * * @return {this} This Circle object. */ - setEmpty: function () + setEmpty() { this._radius = 0; this._diameter = 0; return this; - }, + } /** * Sets the position of this Circle. @@ -213,7 +211,7 @@ var Circle = new Class({ * * @return {this} This Circle object. */ - setPosition: function (x, y) + setPosition(x, y) { if (y === undefined) { y = x; } @@ -221,7 +219,7 @@ var Circle = new Class({ this.y = y; return this; - }, + } /** * Checks to see if the Circle is empty: has a radius of zero. @@ -231,10 +229,10 @@ var Circle = new Class({ * * @return {boolean} True if the Circle is empty, otherwise false. */ - isEmpty: function () + isEmpty() { return (this._radius <= 0); - }, + } /** * The radius of the Circle. @@ -243,20 +241,17 @@ var Circle = new Class({ * @type {number} * @since 3.0.0 */ - radius: { - get: function () - { - return this._radius; - }, - - set: function (value) - { - this._radius = value; - this._diameter = value * 2; - } + get radius() + { + return this._radius; + } - }, + set radius(value) + { + this._radius = value; + this._diameter = value * 2; + } /** * The diameter of the Circle. @@ -265,20 +260,17 @@ var Circle = new Class({ * @type {number} * @since 3.0.0 */ - diameter: { - get: function () - { - return this._diameter; - }, - - set: function (value) - { - this._diameter = value; - this._radius = value * 0.5; - } + get diameter() + { + return this._diameter; + } - }, + set diameter(value) + { + this._diameter = value; + this._radius = value * 0.5; + } /** * The left position of the Circle. @@ -287,19 +279,16 @@ var Circle = new Class({ * @type {number} * @since 3.0.0 */ - left: { - get: function () - { - return this.x - this._radius; - }, - - set: function (value) - { - this.x = value + this._radius; - } + get left() + { + return this.x - this._radius; + } - }, + set left(value) + { + this.x = value + this._radius; + } /** * The right position of the Circle. @@ -308,19 +297,16 @@ var Circle = new Class({ * @type {number} * @since 3.0.0 */ - right: { - get: function () - { - return this.x + this._radius; - }, - - set: function (value) - { - this.x = value - this._radius; - } + get right() + { + return this.x + this._radius; + } - }, + set right(value) + { + this.x = value - this._radius; + } /** * The top position of the Circle. @@ -329,19 +315,16 @@ var Circle = new Class({ * @type {number} * @since 3.0.0 */ - top: { - get: function () - { - return this.y - this._radius; - }, - - set: function (value) - { - this.y = value + this._radius; - } + get top() + { + return this.y - this._radius; + } - }, + set top(value) + { + this.y = value + this._radius; + } /** * The bottom position of the Circle. @@ -350,20 +333,17 @@ var Circle = new Class({ * @type {number} * @since 3.0.0 */ - bottom: { - get: function () - { - return this.y + this._radius; - }, - - set: function (value) - { - this.y = value - this._radius; - } + get bottom() + { + return this.y + this._radius; + } + set bottom(value) + { + this.y = value - this._radius; } -}); +}; module.exports = Circle; diff --git a/src/geom/ellipse/Ellipse.js b/src/geom/ellipse/Ellipse.js index 5380f5d2ec..3226c8a511 100644 --- a/src/geom/ellipse/Ellipse.js +++ b/src/geom/ellipse/Ellipse.js @@ -29,11 +29,9 @@ var Random = require('./Random'); * @param {number} [width=0] - The width of the ellipse. * @param {number} [height=0] - The height of the ellipse. */ -var Ellipse = new Class({ +var Ellipse = class { - initialize: - - function Ellipse (x, y, width, height) + constructor(x, y, width, height) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -90,7 +88,7 @@ var Ellipse = new Class({ * @since 3.0.0 */ this.height = height; - }, + } /** * Check to see if the Ellipse contains the given x / y coordinates. @@ -103,10 +101,10 @@ var Ellipse = new Class({ * * @return {boolean} True if the coordinates are within the ellipse, otherwise false. */ - contains: function (x, y) + contains(x, y) { return Contains(this, x, y); - }, + } /** * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse @@ -123,10 +121,10 @@ var Ellipse = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 instance containing the coordinates of the point around the ellipse. */ - getPoint: function (position, point) + getPoint(position, point) { return GetPoint(this, position, point); - }, + } /** * Returns an array of Vector2 objects containing the coordinates of the points around the circumference of the Ellipse, @@ -143,10 +141,10 @@ var Ellipse = new Class({ * * @return {Phaser.Math.Vector2[]} An array of Vector2 objects pertaining to the points around the circumference of the ellipse. */ - getPoints: function (quantity, stepRate, output) + getPoints(quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); - }, + } /** * Returns a uniformly distributed random point from anywhere within the given Ellipse. @@ -160,10 +158,10 @@ var Ellipse = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 object with the random values set in the `x` and `y` properties. */ - getRandomPoint: function (vec) + getRandomPoint(vec) { return Random(this, vec); - }, + } /** * Sets the x, y, width and height of this ellipse. @@ -178,7 +176,7 @@ var Ellipse = new Class({ * * @return {this} This Ellipse object. */ - setTo: function (x, y, width, height) + setTo(x, y, width, height) { this.x = x; this.y = y; @@ -186,7 +184,7 @@ var Ellipse = new Class({ this.height = height; return this; - }, + } /** * Sets this Ellipse to be empty with a width and height of zero. @@ -197,13 +195,13 @@ var Ellipse = new Class({ * * @return {this} This Ellipse object. */ - setEmpty: function () + setEmpty() { this.width = 0; this.height = 0; return this; - }, + } /** * Sets the position of this Ellipse. @@ -216,7 +214,7 @@ var Ellipse = new Class({ * * @return {this} This Ellipse object. */ - setPosition: function (x, y) + setPosition(x, y) { if (y === undefined) { y = x; } @@ -224,7 +222,7 @@ var Ellipse = new Class({ this.y = y; return this; - }, + } /** * Sets the size of this Ellipse. @@ -238,7 +236,7 @@ var Ellipse = new Class({ * * @return {this} This Ellipse object. */ - setSize: function (width, height) + setSize(width, height) { if (height === undefined) { height = width; } @@ -246,7 +244,7 @@ var Ellipse = new Class({ this.height = height; return this; - }, + } /** * Checks to see if the Ellipse is empty: has a width or height equal to zero. @@ -256,10 +254,10 @@ var Ellipse = new Class({ * * @return {boolean} True if the Ellipse is empty, otherwise false. */ - isEmpty: function () + isEmpty() { return (this.width <= 0 || this.height <= 0); - }, + } /** * Returns the minor radius of the ellipse. Also known as the Semi Minor Axis. @@ -269,10 +267,10 @@ var Ellipse = new Class({ * * @return {number} The minor radius. */ - getMinorRadius: function () + getMinorRadius() { return Math.min(this.width, this.height) / 2; - }, + } /** * Returns the major radius of the ellipse. Also known as the Semi Major Axis. @@ -282,10 +280,10 @@ var Ellipse = new Class({ * * @return {number} The major radius. */ - getMajorRadius: function () + getMajorRadius() { return Math.max(this.width, this.height) / 2; - }, + } /** * The left position of the Ellipse. @@ -294,19 +292,16 @@ var Ellipse = new Class({ * @type {number} * @since 3.0.0 */ - left: { - - get: function () - { - return this.x - (this.width / 2); - }, - set: function (value) - { - this.x = value + (this.width / 2); - } + get left() + { + return this.x - (this.width / 2); + } - }, + set left(value) + { + this.x = value + (this.width / 2); + } /** * The right position of the Ellipse. @@ -315,19 +310,16 @@ var Ellipse = new Class({ * @type {number} * @since 3.0.0 */ - right: { - get: function () - { - return this.x + (this.width / 2); - }, - - set: function (value) - { - this.x = value - (this.width / 2); - } + get right() + { + return this.x + (this.width / 2); + } - }, + set right(value) + { + this.x = value - (this.width / 2); + } /** * The top position of the Ellipse. @@ -336,19 +328,16 @@ var Ellipse = new Class({ * @type {number} * @since 3.0.0 */ - top: { - - get: function () - { - return this.y - (this.height / 2); - }, - set: function (value) - { - this.y = value + (this.height / 2); - } + get top() + { + return this.y - (this.height / 2); + } - }, + set top(value) + { + this.y = value + (this.height / 2); + } /** * The bottom position of the Ellipse. @@ -357,20 +346,17 @@ var Ellipse = new Class({ * @type {number} * @since 3.0.0 */ - bottom: { - get: function () - { - return this.y + (this.height / 2); - }, - - set: function (value) - { - this.y = value - (this.height / 2); - } + get bottom() + { + return this.y + (this.height / 2); + } + set bottom(value) + { + this.y = value - (this.height / 2); } -}); +}; module.exports = Ellipse; diff --git a/src/geom/line/Line.js b/src/geom/line/Line.js index d32ffc230d..26110358b4 100644 --- a/src/geom/line/Line.js +++ b/src/geom/line/Line.js @@ -25,11 +25,9 @@ var Vector2 = require('../../math/Vector2'); * @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({ +var Line = class { - initialize: - - function Line (x1, y1, x2, y2) + constructor(x1, y1, x2, y2) { if (x1 === undefined) { x1 = 0; } if (y1 === undefined) { y1 = 0; } @@ -82,7 +80,7 @@ var Line = new Class({ * @since 3.0.0 */ this.y2 = y2; - }, + } /** * Get a point on a line that's a given percentage along its length. @@ -97,10 +95,10 @@ var Line = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 object containing the coordinates of the point on the line. */ - getPoint: function (position, output) + getPoint(position, output) { return GetPoint(this, position, output); - }, + } /** * Get a number of points along a line's length. @@ -121,10 +119,10 @@ var Line = new Class({ * * @return {Phaser.Math.Vector2[]} An array of Vector2 objects containing the coordinates of the points on the line. */ - getPoints: function (quantity, stepRate, output) + getPoints(quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); - }, + } /** * Get a random Point on the Line. @@ -138,10 +136,10 @@ var Line = new Class({ * * @return {Phaser.Math.Vector2} A random point on the Line. */ - getRandomPoint: function (point) + getRandomPoint(point) { return Random(this, point); - }, + } /** * Set new coordinates for the line endpoints. @@ -156,7 +154,7 @@ var Line = new Class({ * * @return {this} This Line object. */ - setTo: function (x1, y1, x2, y2) + setTo(x1, y1, x2, y2) { if (x1 === undefined) { x1 = 0; } if (y1 === undefined) { y1 = 0; } @@ -170,7 +168,7 @@ var Line = new Class({ this.y2 = y2; return this; - }, + } /** * Sets this Line to match the x/y coordinates of the two given Vector2Like objects. @@ -183,7 +181,7 @@ var Line = new Class({ * * @return {this} This Line object. */ - setFromObjects: function (start, end) + setFromObjects(start, end) { this.x1 = start.x; this.y1 = start.y; @@ -192,7 +190,7 @@ var Line = new Class({ this.y2 = end.y; return this; - }, + } /** * Returns a Vector2 object that corresponds to the start of this Line. @@ -206,14 +204,14 @@ var Line = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 object that corresponds to the start of this Line. */ - getPointA: function (vec2) + getPointA(vec2) { if (vec2 === undefined) { vec2 = new Vector2(); } vec2.set(this.x1, this.y1); return vec2; - }, + } /** * Returns a Vector2 object that corresponds to the end of this Line. @@ -227,14 +225,14 @@ var Line = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 object that corresponds to the end of this Line. */ - getPointB: function (vec2) + getPointB(vec2) { if (vec2 === undefined) { vec2 = new Vector2(); } vec2.set(this.x2, this.y2); return vec2; - }, + } /** * The left position of the Line. @@ -243,26 +241,23 @@ var Line = new Class({ * @type {number} * @since 3.0.0 */ - left: { - get: function () - { - return Math.min(this.x1, this.x2); - }, + get left() + { + return Math.min(this.x1, this.x2); + } - set: function (value) + set left(value) + { + if (this.x1 <= this.x2) { - if (this.x1 <= this.x2) - { - this.x1 = value; - } - else - { - this.x2 = value; - } + this.x1 = value; } - - }, + else + { + this.x2 = value; + } + } /** * The right position of the Line. @@ -271,26 +266,23 @@ var Line = new Class({ * @type {number} * @since 3.0.0 */ - right: { - get: function () - { - return Math.max(this.x1, this.x2); - }, + get right() + { + return Math.max(this.x1, this.x2); + } - set: function (value) + set right(value) + { + if (this.x1 > this.x2) { - if (this.x1 > this.x2) - { - this.x1 = value; - } - else - { - this.x2 = value; - } + this.x1 = value; } - - }, + else + { + this.x2 = value; + } + } /** * The top position of the Line. @@ -299,26 +291,23 @@ var Line = new Class({ * @type {number} * @since 3.0.0 */ - top: { - get: function () - { - return Math.min(this.y1, this.y2); - }, + get top() + { + return Math.min(this.y1, this.y2); + } - set: function (value) + set top(value) + { + if (this.y1 <= this.y2) { - if (this.y1 <= this.y2) - { - this.y1 = value; - } - else - { - this.y2 = value; - } + this.y1 = value; } - - }, + else + { + this.y2 = value; + } + } /** * The bottom position of the Line. @@ -327,27 +316,24 @@ var Line = new Class({ * @type {number} * @since 3.0.0 */ - bottom: { - get: function () - { - return Math.max(this.y1, this.y2); - }, + get bottom() + { + return Math.max(this.y1, this.y2); + } - set: function (value) + set bottom(value) + { + if (this.y1 > this.y2) { - if (this.y1 > this.y2) - { - this.y1 = value; - } - else - { - this.y2 = value; - } + this.y1 = value; + } + else + { + this.y2 = value; } - } -}); +}; module.exports = Line; diff --git a/src/geom/polygon/Polygon.js b/src/geom/polygon/Polygon.js index 4f2188927c..4abd82997a 100644 --- a/src/geom/polygon/Polygon.js +++ b/src/geom/polygon/Polygon.js @@ -31,11 +31,9 @@ var GEOM_CONST = require('../const'); * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` * - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]` */ -var Polygon = new Class({ +var Polygon = class { - initialize: - - function Polygon (points) + constructor(points) { /** * The geometry constant type of this object: `GEOM_CONST.POLYGON`. @@ -71,7 +69,7 @@ var Polygon = new Class({ { this.setTo(points); } - }, + } /** * Check to see if the Polygon contains the given x / y coordinates. @@ -84,10 +82,10 @@ var Polygon = new Class({ * * @return {boolean} `true` if the coordinates are within the polygon, otherwise `false`. */ - contains: function (x, y) + contains(x, y) { return Contains(this, x, y); - }, + } /** * Sets this Polygon to the given points. @@ -109,7 +107,7 @@ var Polygon = new Class({ * * @return {this} This Polygon object. */ - setTo: function (points) + setTo(points) { this.area = 0; this.points = []; @@ -155,7 +153,7 @@ var Polygon = new Class({ this.calculateArea(); return this; - }, + } /** * Calculates the area of the Polygon. This is available in the property Polygon.area @@ -165,7 +163,7 @@ var Polygon = new Class({ * * @return {number} The area of the polygon. */ - calculateArea: function () + calculateArea() { if (this.points.length < 3) { @@ -194,7 +192,7 @@ var Polygon = new Class({ this.area = -sum * 0.5; return this.area; - }, + } /** * Returns an array of Vector2 objects containing the coordinates of the points around the perimeter of the Polygon, @@ -211,11 +209,11 @@ var Polygon = new Class({ * * @return {Phaser.Math.Vector2[]} An array of Vector2 objects pertaining to the points around the perimeter of the Polygon. */ - getPoints: function (quantity, step, output) + getPoints(quantity, step, output) { return GetPoints(this, quantity, step, output); } -}); +}; module.exports = Polygon; diff --git a/src/geom/rectangle/Rectangle.js b/src/geom/rectangle/Rectangle.js index a804ccab02..40daebd9c5 100644 --- a/src/geom/rectangle/Rectangle.js +++ b/src/geom/rectangle/Rectangle.js @@ -26,11 +26,9 @@ var Random = require('./Random'); * @param {number} [width=0] - The width of the Rectangle. * @param {number} [height=0] - The height of the Rectangle. */ -var Rectangle = new Class({ +var Rectangle = class { - initialize: - - function Rectangle (x, y, width, height) + constructor(x, y, width, height) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -87,7 +85,7 @@ var Rectangle = new Class({ * @since 3.0.0 */ this.height = height; - }, + } /** * Checks if the given point is inside the Rectangle's bounds. @@ -100,10 +98,10 @@ var Rectangle = new Class({ * * @return {boolean} `true` if the point is within the Rectangle's bounds, otherwise `false`. */ - contains: function (x, y) + contains(x, y) { return Contains(this, x, y); - }, + } /** * Calculates the coordinates of a point at a certain `position` on the Rectangle's perimeter. @@ -122,10 +120,10 @@ var Rectangle = new Class({ * * @return {Phaser.Math.Vector2} The updated `output` object, or a new Vector2 if no `output` object was given. */ - getPoint: function (position, output) + getPoint(position, output) { return GetPoint(this, position, output); - }, + } /** * Returns an array of points from the perimeter of the Rectangle, each spaced out based on the quantity or step required. @@ -141,10 +139,10 @@ var Rectangle = new Class({ * * @return {Phaser.Math.Vector2[]} The modified `output` array, or a new array if none was provided. */ - getPoints: function (quantity, stepRate, output) + getPoints(quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); - }, + } /** * Returns a random point within the Rectangle's bounds. @@ -158,10 +156,10 @@ var Rectangle = new Class({ * * @return {Phaser.Math.Vector2} The updated `vec`, or a new Vector2 if none was provided. */ - getRandomPoint: function (vec) + getRandomPoint(vec) { return Random(this, vec); - }, + } /** * Sets the position, width, and height of the Rectangle. @@ -176,7 +174,7 @@ var Rectangle = new Class({ * * @return {this} This Rectangle object. */ - setTo: function (x, y, width, height) + setTo(x, y, width, height) { this.x = x; this.y = y; @@ -184,7 +182,7 @@ var Rectangle = new Class({ this.height = height; return this; - }, + } /** * Resets the position, width, and height of the Rectangle to 0. @@ -194,10 +192,10 @@ var Rectangle = new Class({ * * @return {this} This Rectangle object. */ - setEmpty: function () + setEmpty() { return this.setTo(0, 0, 0, 0); - }, + } /** * Sets the position of the Rectangle. @@ -210,7 +208,7 @@ var Rectangle = new Class({ * * @return {this} This Rectangle object. */ - setPosition: function (x, y) + setPosition(x, y) { if (y === undefined) { y = x; } @@ -218,7 +216,7 @@ var Rectangle = new Class({ this.y = y; return this; - }, + } /** * Sets the width and height of the Rectangle. @@ -231,7 +229,7 @@ var Rectangle = new Class({ * * @return {this} This Rectangle object. */ - setSize: function (width, height) + setSize(width, height) { if (height === undefined) { height = width; } @@ -239,7 +237,7 @@ var Rectangle = new Class({ this.height = height; return this; - }, + } /** * Determines if the Rectangle is empty. A Rectangle is empty if its width or height is less than or equal to 0. @@ -249,10 +247,10 @@ var Rectangle = new Class({ * * @return {boolean} `true` if the Rectangle is empty. A Rectangle object is empty if its width or height is less than or equal to 0. */ - isEmpty: function () + isEmpty() { return (this.width <= 0 || this.height <= 0); - }, + } /** * Returns a Line object that corresponds to the top of this Rectangle. @@ -266,14 +264,14 @@ var Rectangle = new Class({ * * @return {Phaser.Geom.Line} A Line object that corresponds to the top of this Rectangle. */ - getLineA: function (line) + getLineA(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. @@ -287,14 +285,14 @@ var Rectangle = new Class({ * * @return {Phaser.Geom.Line} A Line object that corresponds to the right of this Rectangle. */ - getLineB: function (line) + getLineB(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. @@ -308,14 +306,14 @@ var Rectangle = new Class({ * * @return {Phaser.Geom.Line} A Line object that corresponds to the bottom of this Rectangle. */ - getLineC: function (line) + getLineC(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. @@ -329,14 +327,14 @@ var Rectangle = new Class({ * * @return {Phaser.Geom.Line} A Line object that corresponds to the left of this Rectangle. */ - getLineD: function (line) + getLineD(line) { if (line === undefined) { line = new Line(); } line.setTo(this.x, this.bottom, this.x, this.y); return line; - }, + } /** * The x coordinate of the left of the Rectangle. @@ -346,28 +344,25 @@ var Rectangle = new Class({ * @type {number} * @since 3.0.0 */ - left: { - get: function () - { - return this.x; - }, + get left() + { + return this.x; + } - set: function (value) + set left(value) + { + if (value >= this.right) { - if (value >= this.right) - { - this.width = 0; - } - else - { - this.width = this.right - value; - } - - this.x = value; + this.width = 0; + } + else + { + this.width = this.right - value; } - }, + this.x = value; + } /** * The sum of the x and width properties. @@ -377,26 +372,23 @@ var Rectangle = new Class({ * @type {number} * @since 3.0.0 */ - right: { - get: function () - { - return this.x + this.width; - }, + get right() + { + return this.x + this.width; + } - set: function (value) + set right(value) + { + if (value <= this.x) { - if (value <= this.x) - { - this.width = 0; - } - else - { - this.width = value - this.x; - } + this.width = 0; } - - }, + else + { + this.width = value - this.x; + } + } /** * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. @@ -406,28 +398,25 @@ var Rectangle = new Class({ * @type {number} * @since 3.0.0 */ - top: { - get: function () - { - return this.y; - }, + get top() + { + return this.y; + } - set: function (value) + set top(value) + { + if (value >= this.bottom) { - if (value >= this.bottom) - { - this.height = 0; - } - else - { - this.height = (this.bottom - value); - } - - this.y = value; + this.height = 0; + } + else + { + this.height = (this.bottom - value); } - }, + this.y = value; + } /** * The sum of the y and height properties. @@ -437,26 +426,23 @@ var Rectangle = new Class({ * @type {number} * @since 3.0.0 */ - bottom: { - get: function () - { - return this.y + this.height; - }, + get bottom() + { + return this.y + this.height; + } - set: function (value) + set bottom(value) + { + if (value <= this.y) { - if (value <= this.y) - { - this.height = 0; - } - else - { - this.height = value - this.y; - } + this.height = 0; } - - }, + else + { + this.height = value - this.y; + } + } /** * The x coordinate of the center of the Rectangle. @@ -465,19 +451,16 @@ var Rectangle = new Class({ * @type {number} * @since 3.0.0 */ - centerX: { - get: function () - { - return this.x + (this.width / 2); - }, - - set: function (value) - { - this.x = value - (this.width / 2); - } + get centerX() + { + return this.x + (this.width / 2); + } - }, + set centerX(value) + { + this.x = value - (this.width / 2); + } /** * The y coordinate of the center of the Rectangle. @@ -486,20 +469,17 @@ var Rectangle = new Class({ * @type {number} * @since 3.0.0 */ - centerY: { - get: function () - { - return this.y + (this.height / 2); - }, - - set: function (value) - { - this.y = value - (this.height / 2); - } + get centerY() + { + return this.y + (this.height / 2); + } + set centerY(value) + { + this.y = value - (this.height / 2); } -}); +}; module.exports = Rectangle; diff --git a/src/geom/triangle/Triangle.js b/src/geom/triangle/Triangle.js index 5f28dc8322..81775f5f59 100644 --- a/src/geom/triangle/Triangle.js +++ b/src/geom/triangle/Triangle.js @@ -30,11 +30,9 @@ var Random = require('./Random'); * @param {number} [x3=0] - `x` coordinate of the third point. * @param {number} [y3=0] - `y` coordinate of the third point. */ -var Triangle = new Class({ +var Triangle = class { - initialize: - - function Triangle (x1, y1, x2, y2, x3, y3) + constructor(x1, y1, x2, y2, x3, y3) { if (x1 === undefined) { x1 = 0; } if (y1 === undefined) { y1 = 0; } @@ -113,7 +111,7 @@ var Triangle = new Class({ * @since 3.0.0 */ this.y3 = y3; - }, + } /** * Checks whether a given points lies within the triangle. @@ -126,10 +124,10 @@ var Triangle = new Class({ * * @return {boolean} `true` if the coordinate pair is within the triangle, otherwise `false`. */ - contains: function (x, y) + contains(x, y) { return Contains(this, x, y); - }, + } /** * Returns a specific point on the triangle. @@ -144,10 +142,10 @@ var Triangle = new Class({ * * @return {Phaser.Math.Vector2} Calculated Vetor2 that represents the requested position. It is the same as `output` when this parameter has been given. */ - getPoint: function (position, output) + getPoint(position, output) { return GetPoint(this, position, output); - }, + } /** * Calculates a list of evenly distributed points on the triangle. It is either possible to pass an amount of points to be generated (`quantity`) or the distance between two points (`stepRate`). @@ -163,10 +161,10 @@ var Triangle = new Class({ * * @return {Phaser.Math.Vector2[]} Returns a list of calculated `Vector2` instances or the filled array passed as parameter `output`. */ - getPoints: function (quantity, stepRate, output) + getPoints(quantity, stepRate, output) { return GetPoints(this, quantity, stepRate, output); - }, + } /** * Returns a random point along the triangle. @@ -180,10 +178,10 @@ var Triangle = new Class({ * * @return {Phaser.Math.Vector2} Random Vector2. When parameter `vec` has been provided it will be returned. */ - getRandomPoint: function (vec) + getRandomPoint(vec) { return Random(this, vec); - }, + } /** * Sets all three points of the triangle. Leaving out any coordinate sets it to be `0`. @@ -200,7 +198,7 @@ var Triangle = new Class({ * * @return {this} This Triangle object. */ - setTo: function (x1, y1, x2, y2, x3, y3) + setTo(x1, y1, x2, y2, x3, y3) { if (x1 === undefined) { x1 = 0; } if (y1 === undefined) { y1 = 0; } @@ -219,7 +217,7 @@ var Triangle = new Class({ this.y3 = y3; return this; - }, + } /** * Returns a Line object that corresponds to Line A of this Triangle. @@ -233,14 +231,14 @@ var Triangle = new Class({ * * @return {Phaser.Geom.Line} A Line object that corresponds to line A of this Triangle. */ - getLineA: function (line) + getLineA(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. @@ -254,14 +252,14 @@ var Triangle = new Class({ * * @return {Phaser.Geom.Line} A Line object that corresponds to line B of this Triangle. */ - getLineB: function (line) + getLineB(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. @@ -275,14 +273,14 @@ var Triangle = new Class({ * * @return {Phaser.Geom.Line} A Line object that corresponds to line C of this Triangle. */ - getLineC: function (line) + getLineC(line) { if (line === undefined) { line = new Line(); } line.setTo(this.x3, this.y3, this.x1, this.y1); return line; - }, + } /** * Left most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly. @@ -291,36 +289,33 @@ var Triangle = new Class({ * @type {number} * @since 3.0.0 */ - left: { - get: function () - { - return Math.min(this.x1, this.x2, this.x3); - }, + get left() + { + return Math.min(this.x1, this.x2, this.x3); + } - set: function (value) + set left(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 { - 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; + diff = this.x3 - value; } - }, + this.x1 -= diff; + this.x2 -= diff; + this.x3 -= diff; + } /** * Right most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly. @@ -329,36 +324,33 @@ var Triangle = new Class({ * @type {number} * @since 3.0.0 */ - right: { - get: function () - { - return Math.max(this.x1, this.x2, this.x3); - }, + get right() + { + return Math.max(this.x1, this.x2, this.x3); + } + + set right(value) + { + var diff = 0; - set: function (value) + if (this.x1 >= this.x2 && this.x1 >= this.x3) { - 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; + 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; + } /** * Top most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly. @@ -367,36 +359,33 @@ var Triangle = new Class({ * @type {number} * @since 3.0.0 */ - top: { - get: function () - { - return Math.min(this.y1, this.y2, this.y3); - }, + get top() + { + return Math.min(this.y1, this.y2, this.y3); + } + + set top(value) + { + var diff = 0; - set: function (value) + if (this.y1 <= this.y2 && this.y1 <= this.y3) + { + diff = this.y1 - value; + } + else if (this.y2 <= this.y1 && this.y2 <= this.y3) { - 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; + diff = this.y2 - value; + } + else + { + diff = this.y3 - value; } - }, + this.y1 -= diff; + this.y2 -= diff; + this.y3 -= diff; + } /** * Bottom most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly. @@ -405,37 +394,34 @@ var Triangle = new Class({ * @type {number} * @since 3.0.0 */ - bottom: { - get: function () - { - return Math.max(this.y1, this.y2, this.y3); - }, + get bottom() + { + return Math.max(this.y1, this.y2, this.y3); + } - set: function (value) + set bottom(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 { - 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; + diff = this.y3 - value; } + this.y1 -= diff; + this.y2 -= diff; + this.y3 -= diff; } -}); +}; module.exports = Triangle; diff --git a/src/input/InputManager.js b/src/input/InputManager.js index a2f94ff586..70fc427e38 100644 --- a/src/input/InputManager.js +++ b/src/input/InputManager.js @@ -38,11 +38,9 @@ var TransformXY = require('../math/TransformXY'); * @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({ +var InputManager = class { - initialize: - - function InputManager (game, config) + constructor(game, config) { /** * The Game instance that owns the Input Manager. @@ -297,7 +295,7 @@ var InputManager = new Class({ this.mousePointerContainer = [ this.mousePointer ]; game.events.once(GameEvents.BOOT, this.boot, this); - }, + } /** * The Boot handler is called by Phaser.Game when it first starts up. @@ -308,7 +306,7 @@ var InputManager = new Class({ * @fires Phaser.Input.Events#MANAGER_BOOT * @since 3.0.0 */ - boot: function () + boot() { var game = this.game; var events = game.events; @@ -322,7 +320,7 @@ var InputManager = new Class({ events.on(GameEvents.PRE_RENDER, this.preRender, this); events.once(GameEvents.DESTROY, this.destroy, this); - }, + } /** * Internal canvas state change, called automatically by the Mouse Manager. @@ -334,12 +332,12 @@ var InputManager = new Class({ * * @param {(MouseEvent|TouchEvent)} event - The DOM Event. */ - setCanvasOver: function (event) + setCanvasOver(event) { this.isOver = true; this.events.emit(Events.GAME_OVER, event); - }, + } /** * Internal canvas state change, called automatically by the Mouse Manager. @@ -351,12 +349,12 @@ var InputManager = new Class({ * * @param {(MouseEvent|TouchEvent)} event - The DOM Event. */ - setCanvasOut: function (event) + setCanvasOut(event) { this.isOver = false; this.events.emit(Events.GAME_OUT, event); - }, + } /** * Internal update, called automatically by the Game Step right at the start. @@ -365,7 +363,7 @@ var InputManager = new Class({ * @private * @since 3.18.0 */ - preRender: function () + preRender() { var time = this.game.loop.now; var delta = this.game.loop.delta; @@ -385,7 +383,7 @@ var InputManager = new Class({ return; } } - }, + } /** * Tells the Input system to set a custom cursor. @@ -412,7 +410,7 @@ var InputManager = new Class({ * * @param {string} cursor - The CSS to be used when setting the default cursor. */ - setDefaultCursor: function (cursor) + setDefaultCursor(cursor) { this.defaultCursor = cursor; @@ -420,7 +418,7 @@ var InputManager = new Class({ { this.canvas.style.cursor = cursor; } - }, + } /** * Called by the InputPlugin when processing over and out events. @@ -435,13 +433,13 @@ var InputManager = new Class({ * * @param {Phaser.Types.Input.InteractiveObject} interactiveObject - The Interactive Object that called this method. */ - setCursor: function (interactiveObject) + setCursor(interactiveObject) { if (interactiveObject.cursor) { this.canvas.style.cursor = interactiveObject.cursor; } - }, + } /** * Called by the InputPlugin when processing over and out events. @@ -455,13 +453,13 @@ var InputManager = new Class({ * @param {Phaser.Types.Input.InteractiveObject} interactiveObject - The Interactive Object that called this method. Pass `null` if you just want to set the force value. * @param {boolean} [forceReset=false] - Should the reset happen regardless of the object's cursor state? Default false. */ - resetCursor: function (interactiveObject, forceReset) + resetCursor(interactiveObject, forceReset) { if ((forceReset || (interactiveObject && interactiveObject.cursor)) && this.canvas) { this.canvas.style.cursor = this.defaultCursor; } - }, + } /** * Adds new Pointer objects to the Input Manager. @@ -481,7 +479,7 @@ var InputManager = new Class({ * * @return {Phaser.Input.Pointer[]} An array containing all of the new Pointer objects that were created. */ - addPointer: function (quantity) + addPointer(quantity) { if (quantity === undefined) { quantity = 1; } @@ -508,7 +506,7 @@ var InputManager = new Class({ } return output; - }, + } /** * Internal method that gets a list of all the active Input Plugins in the game @@ -521,7 +519,7 @@ var InputManager = new Class({ * @param {number} type - The type of event to process. * @param {Phaser.Input.Pointer[]} pointers - An array of Pointers on which the event occurred. */ - updateInputPlugins: function (type, pointers) + updateInputPlugins(type, pointers) { var scenes = this.game.scene.getScenes(false, true); @@ -542,7 +540,7 @@ var InputManager = new Class({ } } } - }, + } // 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 @@ -557,7 +555,7 @@ var InputManager = new Class({ * * @param {TouchEvent} event - The native DOM Touch event. */ - onTouchStart: function (event) + onTouchStart(event) { var pointers = this.pointers; var changed = []; @@ -584,7 +582,7 @@ var InputManager = new Class({ } this.updateInputPlugins(CONST.TOUCH_START, changed); - }, + } /** * Processes a touch move event, as passed in by the TouchManager. @@ -595,7 +593,7 @@ var InputManager = new Class({ * * @param {TouchEvent} event - The native DOM Touch event. */ - onTouchMove: function (event) + onTouchMove(event) { var pointers = this.pointers; var changed = []; @@ -637,7 +635,7 @@ var InputManager = new Class({ } this.updateInputPlugins(CONST.TOUCH_MOVE, changed); - }, + } // 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 @@ -652,7 +650,7 @@ var InputManager = new Class({ * * @param {TouchEvent} event - The native DOM Touch event. */ - onTouchEnd: function (event) + onTouchEnd(event) { var pointers = this.pointers; var changed = []; @@ -677,7 +675,7 @@ var InputManager = new Class({ } this.updateInputPlugins(CONST.TOUCH_END, changed); - }, + } /** * Processes a touch cancel event, as passed in by the TouchManager. @@ -688,7 +686,7 @@ var InputManager = new Class({ * * @param {TouchEvent} event - The native DOM Touch event. */ - onTouchCancel: function (event) + onTouchCancel(event) { var pointers = this.pointers; var changed = []; @@ -713,7 +711,7 @@ var InputManager = new Class({ } this.updateInputPlugins(CONST.TOUCH_CANCEL, changed); - }, + } /** * Processes a mouse down event, as passed in by the MouseManager. @@ -724,7 +722,7 @@ var InputManager = new Class({ * * @param {MouseEvent} event - The native DOM Mouse event. */ - onMouseDown: function (event) + onMouseDown(event) { var mousePointer = this.mousePointer; @@ -735,7 +733,7 @@ var InputManager = new Class({ this.activePointer = mousePointer; this.updateInputPlugins(CONST.MOUSE_DOWN, this.mousePointerContainer); - }, + } /** * Processes a mouse move event, as passed in by the MouseManager. @@ -746,7 +744,7 @@ var InputManager = new Class({ * * @param {MouseEvent} event - The native DOM Mouse event. */ - onMouseMove: function (event) + onMouseMove(event) { var mousePointer = this.mousePointer; @@ -757,7 +755,7 @@ var InputManager = new Class({ this.activePointer = mousePointer; this.updateInputPlugins(CONST.MOUSE_MOVE, this.mousePointerContainer); - }, + } /** * Processes a mouse up event, as passed in by the MouseManager. @@ -768,7 +766,7 @@ var InputManager = new Class({ * * @param {MouseEvent} event - The native DOM Mouse event. */ - onMouseUp: function (event) + onMouseUp(event) { var mousePointer = this.mousePointer; @@ -779,7 +777,7 @@ var InputManager = new Class({ this.activePointer = mousePointer; this.updateInputPlugins(CONST.MOUSE_UP, this.mousePointerContainer); - }, + } /** * Processes a mouse wheel event, as passed in by the MouseManager. @@ -790,7 +788,7 @@ var InputManager = new Class({ * * @param {WheelEvent} event - The native DOM Wheel event. */ - onMouseWheel: function (event) + onMouseWheel(event) { var mousePointer = this.mousePointer; @@ -799,7 +797,7 @@ var InputManager = new Class({ this.activePointer = mousePointer; this.updateInputPlugins(CONST.MOUSE_WHEEL, this.mousePointerContainer); - }, + } /** * Processes a pointer lock change event, as passed in by the MouseManager. @@ -811,14 +809,14 @@ var InputManager = new Class({ * * @param {MouseEvent} event - The native DOM Mouse event. */ - onPointerLockChange: function (event) + onPointerLockChange(event) { var isLocked = this.mouse.locked; this.mousePointer.locked = isLocked; this.events.emit(Events.POINTERLOCK_CHANGE, event, isLocked); - }, + } /** * Checks if the given Game Object should be considered as a candidate for input or not. @@ -835,7 +833,7 @@ var InputManager = new Class({ * * @return {boolean} `true` if the Game Object should be considered for input, otherwise `false`. */ - inputCandidate: function (gameObject, camera) + inputCandidate(gameObject, camera) { var input = gameObject.input; @@ -863,7 +861,7 @@ var InputManager = new Class({ } return visible; - }, + } /** * Performs a hit test using the given Pointer and camera, against an array of interactive Game Objects. @@ -885,7 +883,7 @@ var InputManager = new Class({ * * @return {array} An array of the Game Objects that were hit during this hit test. */ - hitTest: function (pointer, gameObjects, camera, output) + hitTest(pointer, gameObjects, camera, output) { if (output === undefined) { output = this._tempHitTest; } @@ -942,7 +940,7 @@ var InputManager = new Class({ } return output; - }, + } /** * Checks if the given x and y coordinate are within the hit area of the Game Object. @@ -960,7 +958,7 @@ var InputManager = new Class({ * * @return {boolean} `true` if the coordinates were inside the Game Objects hit area, otherwise `false`. */ - pointWithinHitArea: function (gameObject, x, y) + pointWithinHitArea(gameObject, x, y) { // Normalize the origin x += gameObject.displayOriginX; @@ -979,7 +977,7 @@ var InputManager = new Class({ { return false; } - }, + } /** * Checks if the given x and y coordinate are within the hit area of the Interactive Object. @@ -997,7 +995,7 @@ var InputManager = new Class({ * * @return {boolean} `true` if the coordinates were inside the Game Objects hit area, otherwise `false`. */ - pointWithinInteractiveObject: function (object, x, y) + pointWithinInteractiveObject(object, x, y) { if (!object.hitArea) { @@ -1012,7 +1010,7 @@ var InputManager = new Class({ 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. @@ -1025,7 +1023,7 @@ var InputManager = new Class({ * @param {number} pageY - The Page Y value. * @param {boolean} wasMove - Are we transforming the Pointer from a move event, or an up / down event? */ - transformPointer: function (pointer, pageX, pageY, wasMove) + transformPointer(pointer, pageX, pageY, wasMove) { var p0 = pointer.position; var p1 = pointer.prevPosition; @@ -1052,7 +1050,7 @@ var InputManager = new Class({ p0.x = x * a + p1.x * (1 - a); p0.y = y * a + p1.y * (1 - a); } - }, + } /** * Destroys the Input Manager and all of its systems. @@ -1062,7 +1060,7 @@ var InputManager = new Class({ * @method Phaser.Input.InputManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.events.removeAllListeners(); @@ -1095,6 +1093,6 @@ var InputManager = new Class({ this.game = null; } -}); +}; module.exports = InputManager; diff --git a/src/input/InputPlugin.js b/src/input/InputPlugin.js index a2ac85676b..3ed96083b3 100644 --- a/src/input/InputPlugin.js +++ b/src/input/InputPlugin.js @@ -71,15 +71,11 @@ var TriangleContains = require('../geom/triangle/Contains'); * * @param {Phaser.Scene} scene - A reference to the Scene that this Input Plugin is responsible for. */ -var InputPlugin = new Class({ +var InputPlugin = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function InputPlugin (scene) + constructor(scene) { - EventEmitter.call(this); + super(); /** * A reference to the Scene that this Input Plugin is responsible for. @@ -388,7 +384,7 @@ var InputPlugin = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -399,7 +395,7 @@ var InputPlugin = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.cameras = this.systems.cameras; @@ -409,7 +405,7 @@ var InputPlugin = new Class({ // Registered input plugins listen for this this.pluginEvents.emit(Events.BOOT); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -421,7 +417,7 @@ var InputPlugin = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { var eventEmitter = this.systems.events; @@ -441,7 +437,7 @@ var InputPlugin = new Class({ // Registered input plugins listen for this this.pluginEvents.emit(Events.START); - }, + } /** * Game Over handler. @@ -451,13 +447,13 @@ var InputPlugin = new Class({ * @private * @since 3.16.2 */ - onGameOver: function (event) + onGameOver(event) { if (this.isActive()) { this.emit(Events.GAME_OVER, event.timeStamp, event); } - }, + } /** * Game Out handler. @@ -467,13 +463,13 @@ var InputPlugin = new Class({ * @private * @since 3.16.2 */ - onGameOut: function (event) + onGameOut(event) { if (this.isActive()) { this.emit(Events.GAME_OUT, event.timeStamp, event); } - }, + } /** * The pre-update handler is responsible for checking the pending removal and insertion lists and @@ -484,7 +480,7 @@ var InputPlugin = new Class({ * @fires Phaser.Input.Events#PRE_UPDATE * @since 3.0.0 */ - preUpdate: function () + preUpdate() { // Registered input plugins listen for this this.pluginEvents.emit(Events.PRE_UPDATE); @@ -523,7 +519,7 @@ var InputPlugin = new Class({ // Move pendingInsertion to list (also clears pendingInsertion at the same time) this._list = current.concat(insertList.splice(0)); - }, + } /** * Checks to see if the Input Manager, this plugin and the Scene to which it belongs are all active and input enabled. @@ -533,10 +529,10 @@ var InputPlugin = new Class({ * * @return {boolean} `true` if the plugin and the Scene it belongs to is active. */ - isActive: function () + isActive() { return (this.manager && this.manager.enabled && this.enabled && this.scene.sys.canInput()); - }, + } /** * Sets a custom cursor on the parent canvas element of the game, based on the `cursor` @@ -551,13 +547,13 @@ var InputPlugin = new Class({ * * @param {Phaser.Types.Input.InteractiveObject} interactiveObject - The Interactive Object that will set the cursor on the canvas. */ - setCursor: function (interactiveObject) + setCursor(interactiveObject) { if (this.manager) { this.manager.setCursor(interactiveObject); } - }, + } /** * Forces the Input Manager to clear the custom or hand cursor, regardless of the @@ -566,13 +562,13 @@ var InputPlugin = new Class({ * @method Phaser.Input.InputPlugin#resetCursor * @since 3.85.0 */ - resetCursor: function () + resetCursor() { if (this.manager) { this.manager.resetCursor(null, true); } - }, + } /** * This is called automatically by the Input Manager. @@ -586,7 +582,7 @@ var InputPlugin = new Class({ * * @return {boolean} `true` if the plugin and the Scene it belongs to is active. */ - updatePoll: function (time, delta) + updatePoll(time, delta) { if (!this.isActive()) { @@ -690,7 +686,7 @@ var InputPlugin = new Class({ } return captured; - }, + } /** * This method is called when a DOM Event is received by the Input Manager. It handles dispatching the events @@ -706,7 +702,7 @@ var InputPlugin = new Class({ * * @return {boolean} `true` if this Scene has captured the input events from all other Scenes, otherwise `false`. */ - update: function (type, pointers) + update(type, pointers) { if (!this.isActive()) { @@ -792,7 +788,7 @@ var InputPlugin = new Class({ this._updatedThisFrame = true; return captured; - }, + } /** * Clears a Game Object so it no longer has an Interactive Object associated with it. @@ -806,7 +802,7 @@ var InputPlugin = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object that had its Interactive Object removed. */ - clear: function (gameObject, skipQueue) + clear(gameObject, skipQueue) { if (skipQueue === undefined) { skipQueue = false; } @@ -842,7 +838,7 @@ var InputPlugin = new Class({ } return gameObject; - }, + } /** * Disables Input on a single Game Object. @@ -858,7 +854,7 @@ var InputPlugin = new Class({ * * @return {this} This Input Plugin. */ - disable: function (gameObject, resetCursor) + disable(gameObject, resetCursor) { if (resetCursor === undefined) { resetCursor = false; } @@ -898,7 +894,7 @@ var InputPlugin = new Class({ } return this; - }, + } /** * Enable a Game Object for interaction. @@ -927,7 +923,7 @@ var InputPlugin = new Class({ * * @return {this} This Input Plugin. */ - enable: function (gameObject, hitArea, hitAreaCallback, dropZone) + enable(gameObject, hitArea, hitAreaCallback, dropZone) { if (dropZone === undefined) { dropZone = false; } @@ -948,7 +944,7 @@ var InputPlugin = new Class({ } return this; - }, + } /** * Takes the given Pointer and performs a hit test against it, to see which interactive Game Objects @@ -964,7 +960,7 @@ var InputPlugin = new Class({ * * @return {Phaser.GameObjects.GameObject[]} An array of all the interactive Game Objects the Pointer was above. */ - hitTestPointer: function (pointer) + hitTestPointer(pointer) { var cameras = this.cameras.getCamerasBelowPointer(pointer); @@ -1001,7 +997,7 @@ var InputPlugin = new Class({ pointer.camera = cameras[0]; return []; - }, + } /** * An internal method that handles the Pointer down event. @@ -1018,7 +1014,7 @@ var InputPlugin = new Class({ * * @return {number} The total number of objects interacted with. */ - processDownEvents: function (pointer) + processDownEvents(pointer) { var total = 0; var currentlyOver = this._temp; @@ -1080,7 +1076,7 @@ var InputPlugin = new Class({ } return total; - }, + } /** * Returns the drag state of the given Pointer for this Input Plugin. @@ -1101,10 +1097,10 @@ var InputPlugin = new Class({ * * @return {number} The drag state of the given Pointer. */ - getDragState: function (pointer) + getDragState(pointer) { return this._dragState[pointer.id]; - }, + } /** * Sets the drag state of the given Pointer for this Input Plugin. @@ -1124,10 +1120,10 @@ var InputPlugin = new Class({ * @param {Phaser.Input.Pointer} pointer - The Pointer to set the drag state for. * @param {number} state - The drag state value. An integer between 0 and 5. */ - setDragState: function (pointer, state) + setDragState(pointer, state) { this._dragState[pointer.id] = state; - }, + } /** * Checks to see if a Pointer is ready to drag the objects below it, based on either a distance @@ -1140,7 +1136,7 @@ var InputPlugin = new Class({ * @param {Phaser.Input.Pointer} pointer - The Pointer to check the drag thresholds on. * @param {number} time - The current time. */ - processDragThresholdEvent: function (pointer, time) + processDragThresholdEvent(pointer, time) { var passed = false; var timeThreshold = this.dragTimeThreshold; @@ -1163,7 +1159,7 @@ var InputPlugin = new Class({ return this.processDragStartList(pointer); } - }, + } /** * Processes the drag list for the given pointer and dispatches the start events for each object on it. @@ -1178,7 +1174,7 @@ var InputPlugin = new Class({ * * @return {number} The number of items that DRAG_START was called on. */ - processDragStartList: function (pointer) + processDragStartList(pointer) { // 3 = Pointer meets criteria and is freshly down, notify the draglist if (this.getDragState(pointer) !== 3) @@ -1220,7 +1216,7 @@ var InputPlugin = new Class({ this.setDragState(pointer, 4); return list.length; - }, + } /** * Processes a 'drag down' event for the given pointer. Checks the pointer state, builds-up the drag list @@ -1234,7 +1230,7 @@ var InputPlugin = new Class({ * * @return {number} The number of items that were collected on the drag list. */ - processDragDownEvent: function (pointer) + processDragDownEvent(pointer) { var currentlyOver = this._temp; @@ -1293,7 +1289,7 @@ var InputPlugin = new Class({ return 0; } - }, + } /** * Processes a 'drag move' event for the given pointer. @@ -1314,7 +1310,7 @@ var InputPlugin = new Class({ * * @return {number} The number of items that were updated by this drag event. */ - processDragMoveEvent: function (pointer) + processDragMoveEvent(pointer) { // 2 = Pointer being checked if meets drag criteria if (this.getDragState(pointer) === 2) @@ -1443,7 +1439,7 @@ var InputPlugin = new Class({ } return list.length; - }, + } /** * Processes a 'drag down' event for the given pointer. Checks the pointer state, builds-up the drag list @@ -1461,7 +1457,7 @@ var InputPlugin = new Class({ * * @return {number} The number of items that were updated by this drag event. */ - processDragUpEvent: function (pointer) + processDragUpEvent(pointer) { // 5 = Pointer was actively dragging but has been released, notify draglist var list = this._drag[pointer.id]; @@ -1517,7 +1513,7 @@ var InputPlugin = new Class({ list.splice(0); return 0; - }, + } /** * An internal method that handles the Pointer movement event. @@ -1533,7 +1529,7 @@ var InputPlugin = new Class({ * * @return {number} The total number of objects interacted with. */ - processMoveEvents: function (pointer) + processMoveEvents(pointer) { var total = 0; var currentlyOver = this._temp; @@ -1587,7 +1583,7 @@ var InputPlugin = new Class({ } return total; - }, + } /** * An internal method that handles a mouse wheel event. @@ -1603,7 +1599,7 @@ var InputPlugin = new Class({ * * @return {number} The total number of objects interacted with. */ - processWheelEvent: function (pointer) + processWheelEvent(pointer) { var total = 0; var currentlyOver = this._temp; @@ -1656,7 +1652,7 @@ var InputPlugin = new Class({ } return total; - }, + } /** * An internal method that handles the Pointer over events. @@ -1673,7 +1669,7 @@ var InputPlugin = new Class({ * * @return {number} The total number of objects interacted with. */ - processOverEvents: function (pointer) + processOverEvents(pointer) { var currentlyOver = this._temp; @@ -1738,7 +1734,7 @@ var InputPlugin = new Class({ this._over[pointer.id] = justOver; return totalInteracted; - }, + } /** * An internal method that handles the Pointer out events. @@ -1755,7 +1751,7 @@ var InputPlugin = new Class({ * * @return {number} The total number of objects interacted with. */ - processOutEvents: function (pointer) + processOutEvents(pointer) { var previouslyOver = this._over[pointer.id]; @@ -1819,7 +1815,7 @@ var InputPlugin = new Class({ } return totalInteracted; - }, + } /** * An internal method that handles the Pointer over and out events. @@ -1838,7 +1834,7 @@ var InputPlugin = new Class({ * * @return {number} The total number of objects interacted with. */ - processOverOutEvents: function (pointer) + processOverOutEvents(pointer) { var currentlyOver = this._temp; @@ -2001,7 +1997,7 @@ var InputPlugin = new Class({ this._over[pointer.id] = this.sortGameObjects(previouslyOver, pointer); return totalInteracted; - }, + } /** * An internal method that handles the Pointer up events. @@ -2018,7 +2014,7 @@ var InputPlugin = new Class({ * * @return {number} The total number of objects interacted with. */ - processUpEvents: function (pointer) + processUpEvents(pointer) { var currentlyOver = this._temp; @@ -2075,7 +2071,7 @@ var InputPlugin = new Class({ } return currentlyOver.length; - }, + } /** * This method will force the given Game Object into the 'down' input state. @@ -2095,10 +2091,10 @@ var InputPlugin = new Class({ * @param {Phaser.Input.Pointer} pointer - The pointer to use when setting the state. * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to have its state set. */ - forceDownState: function (pointer, gameObject) + forceDownState(pointer, gameObject) { this.forceState(pointer, gameObject, Events.GAMEOBJECT_POINTER_DOWN, Events.GAMEOBJECT_DOWN, false); - }, + } /** * This method will force the given Game Object into the 'up' input state. @@ -2118,10 +2114,10 @@ var InputPlugin = new Class({ * @param {Phaser.Input.Pointer} pointer - The pointer to use when setting the state. * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to have its state set. */ - forceUpState: function (pointer, gameObject) + forceUpState(pointer, gameObject) { this.forceState(pointer, gameObject, Events.GAMEOBJECT_POINTER_UP, Events.GAMEOBJECT_UP, false); - }, + } /** * This method will force the given Game Object into the 'over' input state. @@ -2141,10 +2137,10 @@ var InputPlugin = new Class({ * @param {Phaser.Input.Pointer} pointer - The pointer to use when setting the state. * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to have its state set. */ - forceOverState: function (pointer, gameObject) + forceOverState(pointer, gameObject) { this.forceState(pointer, gameObject, Events.GAMEOBJECT_POINTER_OVER, Events.GAMEOBJECT_OVER, true); - }, + } /** * This method will force the given Game Object into the 'out' input state. @@ -2164,10 +2160,10 @@ var InputPlugin = new Class({ * @param {Phaser.Input.Pointer} pointer - The pointer to use when setting the state. * @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to have its state set. */ - forceOutState: function (pointer, gameObject) + forceOutState(pointer, gameObject) { this.forceState(pointer, gameObject, Events.GAMEOBJECT_POINTER_OUT, Events.GAMEOBJECT_OUT, false); - }, + } /** * This method will force the given Game Object into the given input state. @@ -2181,7 +2177,7 @@ var InputPlugin = new Class({ * @param {string} inputPluginEvent - The event to emit on the Input Plugin. * @param {boolean} [setCursor=false] - Should the cursor be set to the Game Object's cursor? */ - forceState: function (pointer, gameObject, gameObjectEvent, inputPluginEvent, setCursor) + forceState(pointer, gameObject, gameObjectEvent, inputPluginEvent, setCursor) { var _eventData = this._eventData; var _eventContainer = this._eventContainer; @@ -2202,7 +2198,7 @@ var InputPlugin = new Class({ this.emit(inputPluginEvent, pointer, gameObject, _eventContainer); } } - }, + } /** * Queues a Game Object for insertion into this Input Plugin on the next update. @@ -2215,7 +2211,7 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - queueForInsertion: function (child) + queueForInsertion(child) { if (this._pendingInsertion.indexOf(child) === -1 && this._list.indexOf(child) === -1) { @@ -2223,7 +2219,7 @@ var InputPlugin = new Class({ } return this; - }, + } /** * Queues a Game Object for removal from this Input Plugin on the next update. @@ -2236,12 +2232,12 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - queueForRemoval: function (child) + queueForRemoval(child) { this._pendingRemoval.push(child); return this; - }, + } /** * Sets the draggable state of the given array of Game Objects. @@ -2258,7 +2254,7 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setDraggable: function (gameObjects, value) + setDraggable(gameObjects, value) { if (value === undefined) { value = true; } @@ -2286,7 +2282,7 @@ var InputPlugin = new Class({ } return this; - }, + } /** * Creates a function that can be passed to `setInteractive`, `enable` or `setHitArea` that will handle @@ -2321,14 +2317,14 @@ var InputPlugin = new Class({ * * @return {function} A Pixel Perfect Handler for use as a hitArea shape callback. */ - makePixelPerfect: function (alphaTolerance) + makePixelPerfect(alphaTolerance) { if (alphaTolerance === undefined) { alphaTolerance = 1; } var textureManager = this.systems.textures; return CreatePixelPerfectHandler(textureManager, alphaTolerance); - }, + } /** * Sets the hit area for the given array of Game Objects. @@ -2354,7 +2350,7 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setHitArea: function (gameObjects, hitArea, hitAreaCallback) + setHitArea(gameObjects, hitArea, hitAreaCallback) { if (hitArea === undefined) { @@ -2435,7 +2431,7 @@ var InputPlugin = new Class({ } return this; - }, + } /** * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Circle` shape, using @@ -2452,14 +2448,14 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setHitAreaCircle: function (gameObjects, x, y, radius, callback) + setHitAreaCircle(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 @@ -2477,14 +2473,14 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setHitAreaEllipse: function (gameObjects, x, y, width, height, callback) + setHitAreaEllipse(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 @@ -2498,7 +2494,7 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setHitAreaFromTexture: function (gameObjects, callback) + setHitAreaFromTexture(gameObjects, callback) { if (callback === undefined) { callback = RectangleContains; } @@ -2542,7 +2538,7 @@ var InputPlugin = new Class({ } return this; - }, + } /** * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Rectangle` shape, using @@ -2560,14 +2556,14 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setHitAreaRectangle: function (gameObjects, x, y, width, height, callback) + setHitAreaRectangle(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 @@ -2587,14 +2583,14 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setHitAreaTriangle: function (gameObjects, x1, y1, x2, y2, x3, y3, callback) + setHitAreaTriangle(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); - }, + } /** * Creates an Input Debug Shape for the given Game Object. @@ -2629,7 +2625,7 @@ var InputPlugin = new Class({ * * @return {this} This Input Plugin. */ - enableDebug: function (gameObject, color) + enableDebug(gameObject, color) { if (color === undefined) { color = 0x00ff00; } @@ -2734,7 +2730,7 @@ var InputPlugin = new Class({ } return this; - }, + } /** * Removes an Input Debug Shape from the given Game Object. @@ -2748,7 +2744,7 @@ var InputPlugin = new Class({ * * @return {this} This Input Plugin. */ - removeDebug: function (gameObject) + removeDebug(gameObject) { var input = gameObject.input; @@ -2763,7 +2759,7 @@ var InputPlugin = new Class({ } return this; - }, + } /** * Sets the Pointers to always poll. @@ -2780,10 +2776,10 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setPollAlways: function () + setPollAlways() { return this.setPollRate(0); - }, + } /** * Sets the Pointers to only poll when they are moved or updated. @@ -2796,10 +2792,10 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setPollOnMove: function () + setPollOnMove() { return this.setPollRate(-1); - }, + } /** * Sets the poll rate value. This is the amount of time that should have elapsed before a pointer @@ -2812,13 +2808,13 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setPollRate: function (value) + setPollRate(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 @@ -2832,12 +2828,12 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setGlobalTopOnly: function (value) + setGlobalTopOnly(value) { this.manager.globalTopOnly = value; return this; - }, + } /** * When set to `true` this Input Plugin will emulate DOM behavior by only emitting events from @@ -2852,12 +2848,12 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - setTopOnly: function (value) + setTopOnly(value) { this.topOnly = value; return this; - }, + } /** * Given an array of Game Objects and a Pointer, sort the array and return it, @@ -2871,7 +2867,7 @@ var InputPlugin = new Class({ * * @return {Phaser.GameObjects.GameObject[]} The sorted array of Game Objects. */ - sortGameObjects: function (gameObjects, pointer) + sortGameObjects(gameObjects, pointer) { if (gameObjects.length < 2 || !pointer.camera) { @@ -2887,7 +2883,7 @@ var InputPlugin = new Class({ return indexB - indexA; }); - }, + } /** * Given an array of Drop Zone Game Objects, sort the array and return it, @@ -2900,7 +2896,7 @@ var InputPlugin = new Class({ * * @return {Phaser.GameObjects.GameObject[]} The sorted array of Game Objects. */ - sortDropZones: function (gameObjects) + sortDropZones(gameObjects) { if (gameObjects.length < 2) { @@ -2910,7 +2906,7 @@ var InputPlugin = new Class({ this.scene.sys.depthSort(); return gameObjects.sort(this.sortDropZoneHandler.bind(this)); - }, + } /** * Return the child lowest down the display list (with the smallest index) @@ -2927,7 +2923,7 @@ var InputPlugin = new Class({ * * @return {number} Returns either a negative or positive integer, or zero if they match. */ - sortDropZoneHandler: function (childA, childB) + sortDropZoneHandler(childA, childB) { if (!childA.parentContainer && !childB.parentContainer) { @@ -2979,7 +2975,7 @@ var InputPlugin = new Class({ // Technically this shouldn't happen, but ... // eslint-disable-next-line no-unreachable return 0; - }, + } /** * This method should be called from within an input event handler, such as `pointerdown`. @@ -2992,12 +2988,12 @@ var InputPlugin = new Class({ * * @return {this} This InputPlugin object. */ - stopPropagation: function () + stopPropagation() { this.manager._tempSkip = true; return this; - }, + } /** * Adds new Pointer objects to the Input Manager. @@ -3017,10 +3013,10 @@ var InputPlugin = new Class({ * * @return {Phaser.Input.Pointer[]} An array containing all of the new Pointer objects that were created. */ - addPointer: function (quantity) + addPointer(quantity) { return this.manager.addPointer(quantity); - }, + } /** * Tells the Input system to set a custom cursor. @@ -3049,12 +3045,12 @@ var InputPlugin = new Class({ * * @return {this} This Input instance. */ - setDefaultCursor: function (cursor) + setDefaultCursor(cursor) { this.manager.setDefaultCursor(cursor); return this; - }, + } /** * The Scene that owns this plugin is transitioning in. @@ -3063,10 +3059,10 @@ var InputPlugin = new Class({ * @private * @since 3.5.0 */ - transitionIn: function () + transitionIn() { this.enabled = this.settings.transitionAllowInput; - }, + } /** * The Scene that owns this plugin has finished transitioning in. @@ -3075,13 +3071,13 @@ var InputPlugin = new Class({ * @private * @since 3.5.0 */ - transitionComplete: function () + transitionComplete() { if (!this.settings.transitionAllowInput) { this.enabled = true; } - }, + } /** * The Scene that owns this plugin is transitioning out. @@ -3090,10 +3086,10 @@ var InputPlugin = new Class({ * @private * @since 3.5.0 */ - transitionOut: function () + transitionOut() { this.enabled = this.settings.transitionAllowInput; - }, + } /** * The Scene that owns this plugin is shutting down. @@ -3104,7 +3100,7 @@ var InputPlugin = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { // Registered input plugins listen for this this.pluginEvents.emit(Events.SHUTDOWN); @@ -3139,7 +3135,7 @@ var InputPlugin = new Class({ manager.events.off(Events.GAME_OVER, this.onGameOver, this); eventEmitter.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * Loops through all of the Input Manager Pointer instances and calls `reset` on them. @@ -3150,7 +3146,7 @@ var InputPlugin = new Class({ * @method Phaser.Input.InputPlugin#resetPointers * @since 3.60.0 */ - resetPointers: function () + resetPointers() { var pointers = this.manager.pointers; @@ -3158,7 +3154,7 @@ var InputPlugin = new Class({ { pointers[i].reset(); } - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -3169,7 +3165,7 @@ var InputPlugin = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -3185,7 +3181,7 @@ var InputPlugin = new Class({ this.manager = null; this.events = null; this.mouse = null; - }, + } /** * The x coordinates of the ActivePointer based on the first camera in the camera list. @@ -3196,14 +3192,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.0.0 */ - x: { - - get: function () - { - return this.manager.activePointer.x; - } - }, + get x() + { + return this.manager.activePointer.x; + } /** * The y coordinates of the ActivePointer based on the first camera in the camera list. @@ -3214,14 +3207,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.0.0 */ - y: { - get: function () - { - return this.manager.activePointer.y; - } - - }, + get y() + { + return this.manager.activePointer.y; + } /** * Are any mouse or touch pointers currently over the game canvas? @@ -3231,14 +3221,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.16.0 */ - isOver: { - get: function () - { - return this.manager.isOver; - } - - }, + get isOver() + { + return this.manager.isOver; + } /** * The mouse has its own unique Pointer object, which you can reference directly if making a _desktop specific game_. @@ -3250,14 +3237,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - mousePointer: { - get: function () - { - return this.manager.mousePointer; - } - - }, + get mousePointer() + { + return this.manager.mousePointer; + } /** * The current active input Pointer. @@ -3267,14 +3251,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.0.0 */ - activePointer: { - - get: function () - { - return this.manager.activePointer; - } - }, + get activePointer() + { + return this.manager.activePointer; + } /** * A touch-based Pointer object. @@ -3285,14 +3266,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer1: { - - get: function () - { - return this.manager.pointers[1]; - } - }, + get pointer1() + { + return this.manager.pointers[1]; + } /** * A touch-based Pointer object. @@ -3303,14 +3281,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer2: { - get: function () - { - return this.manager.pointers[2]; - } - - }, + get pointer2() + { + return this.manager.pointers[2]; + } /** * A touch-based Pointer object. @@ -3321,14 +3296,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer3: { - - get: function () - { - return this.manager.pointers[3]; - } - }, + get pointer3() + { + return this.manager.pointers[3]; + } /** * A touch-based Pointer object. @@ -3339,14 +3311,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer4: { - get: function () - { - return this.manager.pointers[4]; - } - - }, + get pointer4() + { + return this.manager.pointers[4]; + } /** * A touch-based Pointer object. @@ -3357,14 +3326,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer5: { - get: function () - { - return this.manager.pointers[5]; - } - - }, + get pointer5() + { + return this.manager.pointers[5]; + } /** * A touch-based Pointer object. @@ -3375,14 +3341,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer6: { - - get: function () - { - return this.manager.pointers[6]; - } - }, + get pointer6() + { + return this.manager.pointers[6]; + } /** * A touch-based Pointer object. @@ -3393,14 +3356,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer7: { - - get: function () - { - return this.manager.pointers[7]; - } - }, + get pointer7() + { + return this.manager.pointers[7]; + } /** * A touch-based Pointer object. @@ -3411,14 +3371,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer8: { - get: function () - { - return this.manager.pointers[8]; - } - - }, + get pointer8() + { + return this.manager.pointers[8]; + } /** * A touch-based Pointer object. @@ -3429,14 +3386,11 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer9: { - get: function () - { - return this.manager.pointers[9]; - } - - }, + get pointer9() + { + return this.manager.pointers[9]; + } /** * A touch-based Pointer object. @@ -3447,16 +3401,13 @@ var InputPlugin = new Class({ * @readonly * @since 3.10.0 */ - pointer10: { - - get: function () - { - return this.manager.pointers[10]; - } + get pointer10() + { + return this.manager.pointers[10]; } -}); +}; PluginCache.register('InputPlugin', InputPlugin, 'input'); diff --git a/src/input/Pointer.js b/src/input/Pointer.js index b8bceded9b..e48bbb7918 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -35,11 +35,9 @@ var OS = require('../device/OS'); * @param {Phaser.Input.InputManager} manager - A reference to the Input Manager. * @param {number} id - The internal ID of this Pointer. */ -var Pointer = new Class({ +var Pointer = class { - initialize: - - function Pointer (manager, id) + constructor(manager, id) { /** * A reference to the Input Manager. @@ -491,7 +489,7 @@ var Pointer = new Class({ * @since 3.18.0 */ this.deltaZ = 0; - }, + } /** * Takes a Camera and updates this Pointer's `worldX` and `worldY` values so they are @@ -507,7 +505,7 @@ var Pointer = new Class({ * * @return {this} This Pointer object. */ - updateWorldPoint: function (camera) + updateWorldPoint(camera) { // Stores the world point inside of tempPoint var temp = camera.getWorldPoint(this.x, this.y); @@ -516,7 +514,7 @@ var Pointer = new Class({ this.worldY = temp.y; return this; - }, + } /** * Takes a Camera and returns a Vector2 containing the translated position of this Pointer @@ -530,10 +528,10 @@ var Pointer = new Class({ * * @return {(Phaser.Math.Vector2|object)} A Vector2 containing the translated coordinates of this Pointer, based on the given camera. */ - positionToCamera: function (camera, output) + positionToCamera(camera, output) { return camera.getWorldPoint(this.x, this.y, output); - }, + } /** * Calculates the motion of this Pointer, including its velocity and angle of movement. @@ -543,7 +541,7 @@ var Pointer = new Class({ * @private * @since 3.16.0 */ - updateMotion: function () + updateMotion() { var cx = this.position.x; var cy = this.position.y; @@ -581,7 +579,7 @@ var Pointer = new Class({ this.angle = Angle(vx, vy, cx, cy); this.distance = Math.sqrt(dx * dx + dy * dy); - }, + } /** * Internal method to handle a Mouse Up Event. @@ -592,7 +590,7 @@ var Pointer = new Class({ * * @param {MouseEvent} event - The Mouse Event to process. */ - up: function (event) + up(event) { if ('buttons' in event) { @@ -625,7 +623,7 @@ var Pointer = new Class({ this.wasTouch = false; } - }, + } /** * Internal method to handle a Mouse Down Event. @@ -636,7 +634,7 @@ var Pointer = new Class({ * * @param {MouseEvent} event - The Mouse Event to process. */ - down: function (event) + down(event) { if ('buttons' in event) { @@ -675,7 +673,7 @@ var Pointer = new Class({ } this.wasTouch = false; - }, + } /** * Internal method to handle a Mouse Move Event. @@ -686,7 +684,7 @@ var Pointer = new Class({ * * @param {MouseEvent} event - The Mouse Event to process. */ - move: function (event) + move(event) { if ('buttons' in event) { @@ -708,7 +706,7 @@ var Pointer = new Class({ this.moveTime = event.timeStamp; this.wasTouch = false; - }, + } /** * Internal method to handle a Mouse Wheel Event. @@ -719,7 +717,7 @@ var Pointer = new Class({ * * @param {WheelEvent} event - The Wheel Event to process. */ - wheel: function (event) + wheel(event) { if ('buttons' in event) { @@ -736,7 +734,7 @@ var Pointer = new Class({ this.deltaZ = event.deltaZ; this.wasTouch = false; - }, + } /** * Internal method to handle a Touch Start Event. @@ -748,7 +746,7 @@ var Pointer = new Class({ * @param {Touch} touch - The Changed Touch from the Touch Event. * @param {TouchEvent} event - The full Touch Event. */ - touchstart: function (touch, event) + touchstart(touch, event) { if (touch['pointerId']) { @@ -779,7 +777,7 @@ var Pointer = new Class({ this.wasCanceled = false; this.updateMotion(); - }, + } /** * Internal method to handle a Touch Move Event. @@ -791,7 +789,7 @@ var Pointer = new Class({ * @param {Touch} touch - The Changed Touch from the Touch Event. * @param {TouchEvent} event - The full Touch Event. */ - touchmove: function (touch, event) + touchmove(touch, event) { this.event = event; @@ -803,7 +801,7 @@ var Pointer = new Class({ this.wasTouch = true; this.updateMotion(); - }, + } /** * Internal method to handle a Touch End Event. @@ -815,7 +813,7 @@ var Pointer = new Class({ * @param {Touch} touch - The Changed Touch from the Touch Event. * @param {TouchEvent} event - The full Touch Event. */ - touchend: function (touch, event) + touchend(touch, event) { this.buttons = 0; @@ -839,7 +837,7 @@ var Pointer = new Class({ this.active = false; this.updateMotion(); - }, + } /** * Internal method to handle a Touch Cancel Event. @@ -851,7 +849,7 @@ var Pointer = new Class({ * @param {Touch} touch - The Changed Touch from the Touch Event. * @param {TouchEvent} event - The full Touch Event. */ - touchcancel: function (touch, event) + touchcancel(touch, event) { this.buttons = 0; @@ -873,7 +871,7 @@ var Pointer = new Class({ this.wasCanceled = true; this.active = false; - }, + } /** * Checks to see if any buttons are being held down on this Pointer. @@ -883,10 +881,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if no buttons are being held down. */ - noButtonDown: function () + noButtonDown() { return (this.buttons === 0); - }, + } /** * Checks to see if the left button is being held down on this Pointer. @@ -896,10 +894,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the left button is being held down. */ - leftButtonDown: function () + leftButtonDown() { return (this.buttons & 1) ? true : false; - }, + } /** * Checks to see if the right button is being held down on this Pointer. @@ -909,10 +907,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the right button is being held down. */ - rightButtonDown: function () + rightButtonDown() { return (this.buttons & 2) ? true : false; - }, + } /** * Checks to see if the middle button is being held down on this Pointer. @@ -922,10 +920,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the middle button is being held down. */ - middleButtonDown: function () + middleButtonDown() { return (this.buttons & 4) ? true : false; - }, + } /** * Checks to see if the back button is being held down on this Pointer. @@ -935,10 +933,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the back button is being held down. */ - backButtonDown: function () + backButtonDown() { return (this.buttons & 8) ? true : false; - }, + } /** * Checks to see if the forward button is being held down on this Pointer. @@ -948,10 +946,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the forward button is being held down. */ - forwardButtonDown: function () + forwardButtonDown() { return (this.buttons & 16) ? true : false; - }, + } /** * Checks to see if the release of the left button was the most recent activity on this Pointer. @@ -961,10 +959,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the release of the left button was the most recent activity on this Pointer. */ - leftButtonReleased: function () + leftButtonReleased() { return this.buttons === 0 ? (this.button === 0 && !this.isDown) : this.button === 0; - }, + } /** * Checks to see if the release of the right button was the most recent activity on this Pointer. @@ -974,10 +972,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the release of the right button was the most recent activity on this Pointer. */ - rightButtonReleased: function () + rightButtonReleased() { return this.buttons === 0 ? (this.button === 2 && !this.isDown) : this.button === 2; - }, + } /** * Checks to see if the release of the middle button was the most recent activity on this Pointer. @@ -987,10 +985,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the release of the middle button was the most recent activity on this Pointer. */ - middleButtonReleased: function () + middleButtonReleased() { return this.buttons === 0 ? (this.button === 1 && !this.isDown) : this.button === 1; - }, + } /** * Checks to see if the release of the back button was the most recent activity on this Pointer. @@ -1000,10 +998,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the release of the back button was the most recent activity on this Pointer. */ - backButtonReleased: function () + backButtonReleased() { return this.buttons === 0 ? (this.button === 3 && !this.isDown) : this.button === 3; - }, + } /** * Checks to see if the release of the forward button was the most recent activity on this Pointer. @@ -1013,10 +1011,10 @@ var Pointer = new Class({ * * @return {boolean} `true` if the release of the forward button was the most recent activity on this Pointer. */ - forwardButtonReleased: function () + forwardButtonReleased() { return this.buttons === 0 ? (this.button === 4 && !this.isDown) : this.button === 4; - }, + } /** * If the Pointer has a button pressed down at the time this method is called, it will return the @@ -1033,7 +1031,7 @@ var Pointer = new Class({ * * @return {number} The distance the Pointer moved. */ - getDistance: function () + getDistance() { if (this.isDown) { @@ -1043,7 +1041,7 @@ var Pointer = new Class({ { return Distance(this.downX, this.downY, this.upX, this.upY); } - }, + } /** * If the Pointer has a button pressed down at the time this method is called, it will return the @@ -1057,7 +1055,7 @@ var Pointer = new Class({ * * @return {number} The horizontal distance the Pointer moved. */ - getDistanceX: function () + getDistanceX() { if (this.isDown) { @@ -1067,7 +1065,7 @@ var Pointer = new Class({ { return Math.abs(this.downX - this.upX); } - }, + } /** * If the Pointer has a button pressed down at the time this method is called, it will return the @@ -1081,7 +1079,7 @@ var Pointer = new Class({ * * @return {number} The vertical distance the Pointer moved. */ - getDistanceY: function () + getDistanceY() { if (this.isDown) { @@ -1091,7 +1089,7 @@ var Pointer = new Class({ { return Math.abs(this.downY - this.upY); } - }, + } /** * If the Pointer has a button pressed down at the time this method is called, it will return the @@ -1105,7 +1103,7 @@ var Pointer = new Class({ * * @return {number} The duration the Pointer was held down for in milliseconds. */ - getDuration: function () + getDuration() { if (this.isDown) { @@ -1115,7 +1113,7 @@ var Pointer = new Class({ { return (this.upTime - this.downTime); } - }, + } /** * If the Pointer has a button pressed down at the time this method is called, it will return the @@ -1134,7 +1132,7 @@ var Pointer = new Class({ * * @return {number} The angle between the Pointer's coordinates in radians. */ - getAngle: function () + getAngle() { if (this.isDown) { @@ -1144,7 +1142,7 @@ var Pointer = new Class({ { return Angle(this.downX, this.downY, this.upX, this.upY); } - }, + } /** * Takes the previous and current Pointer positions and then generates an array of interpolated values between @@ -1176,7 +1174,7 @@ var Pointer = new Class({ * * @return {array} An array of interpolated values. */ - getInterpolatedPosition: function (steps, out) + getInterpolatedPosition(steps, out) { if (steps === undefined) { steps = 10; } if (out === undefined) { out = []; } @@ -1195,7 +1193,7 @@ var Pointer = new Class({ } return out; - }, + } /** * Fully reset this Pointer back to its unitialized state. @@ -1203,7 +1201,7 @@ var Pointer = new Class({ * @method Phaser.Input.Pointer#reset * @since 3.60.0 */ - reset: function () + reset() { this.event = null; this.downElement = null; @@ -1240,7 +1238,7 @@ var Pointer = new Class({ this.deltaZ = 0; this.active = (this.id === 0) ? true : false; - }, + } /** * Destroys this Pointer instance and resets its external references. @@ -1248,12 +1246,12 @@ var Pointer = new Class({ * @method Phaser.Input.Pointer#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.camera = null; this.manager = null; this.position = null; - }, + } /** * The x position of this Pointer. @@ -1264,19 +1262,16 @@ var Pointer = new Class({ * @type {number} * @since 3.0.0 */ - x: { - get: function () - { - return this.position.x; - }, - - set: function (value) - { - this.position.x = value; - } + get x() + { + return this.position.x; + } - }, + set x(value) + { + this.position.x = value; + } /** * The y position of this Pointer. @@ -1287,19 +1282,16 @@ var Pointer = new Class({ * @type {number} * @since 3.0.0 */ - y: { - - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.position.y = value; - } + get y() + { + return this.position.y; + } - }, + set y(value) + { + this.position.y = value; + } /** * Time when this Pointer was most recently updated by a DOM Event. @@ -1311,15 +1303,12 @@ var Pointer = new Class({ * @readonly * @since 3.16.0 */ - time: { - - get: function () - { - return (this.event) ? this.event.timeStamp : 0; - } + get time() + { + return (this.event) ? this.event.timeStamp : 0; } -}); +}; module.exports = Pointer; diff --git a/src/input/gamepad/Axis.js b/src/input/gamepad/Axis.js index 161b7c9ae4..ca708dbace 100644 --- a/src/input/gamepad/Axis.js +++ b/src/input/gamepad/Axis.js @@ -19,11 +19,9 @@ var Class = require('../../utils/Class'); * @param {Phaser.Input.Gamepad.Gamepad} pad - A reference to the Gamepad that this Axis belongs to. * @param {number} index - The index of this Axis. */ -var Axis = new Class({ +var Axis = class { - initialize: - - function Axis (pad, index) + constructor(pad, index) { /** * A reference to the Gamepad that this Axis belongs to. @@ -72,7 +70,7 @@ var Axis = new Class({ * @since 3.0.0 */ this.threshold = 0.1; - }, + } /** * Internal update handler for this Axis. @@ -84,10 +82,10 @@ var Axis = new Class({ * * @param {number} value - The value of the axis movement. */ - update: function (value) + update(value) { this.value = value; - }, + } /** * Applies the `threshold` value to the axis and returns it. @@ -97,10 +95,10 @@ var Axis = new Class({ * * @return {number} The axis value, adjusted for the movement threshold. */ - getValue: function () + getValue() { return (Math.abs(this.value) < this.threshold) ? 0 : this.value; - }, + } /** * Destroys this Axis instance and releases external references it holds. @@ -108,12 +106,12 @@ var Axis = new Class({ * @method Phaser.Input.Gamepad.Axis#destroy * @since 3.10.0 */ - destroy: function () + destroy() { this.pad = null; this.events = null; } -}); +}; module.exports = Axis; diff --git a/src/input/gamepad/Button.js b/src/input/gamepad/Button.js index 41ddf79ca0..3154a068ed 100644 --- a/src/input/gamepad/Button.js +++ b/src/input/gamepad/Button.js @@ -20,11 +20,9 @@ var Events = require('./events'); * @param {Phaser.Input.Gamepad.Gamepad} pad - A reference to the Gamepad that this Button belongs to. * @param {number} index - The index of this Button. */ -var Button = new Class({ +var Button = class { - initialize: - - function Button (pad, index) + constructor(pad, index) { /** * A reference to the Gamepad that this Button belongs to. @@ -83,7 +81,7 @@ var Button = new Class({ * @since 3.0.0 */ this.pressed = false; - }, + } /** * Internal update handler for this Button. @@ -99,7 +97,7 @@ var Button = new Class({ * * @param {number} value - The value of the button. Between 0 and 1. */ - update: function (value) + update(value) { this.value = value; @@ -121,7 +119,7 @@ var Button = new Class({ this.events.emit(Events.BUTTON_UP, pad, this, value); this.pad.emit(Events.GAMEPAD_BUTTON_UP, index, value, this); } - }, + } /** * Destroys this Button instance and releases external references it holds. @@ -129,12 +127,12 @@ var Button = new Class({ * @method Phaser.Input.Gamepad.Button#destroy * @since 3.10.0 */ - destroy: function () + destroy() { this.pad = null; this.events = null; } -}); +}; module.exports = Button; diff --git a/src/input/gamepad/Gamepad.js b/src/input/gamepad/Gamepad.js index 3c7f64649d..2b78c1771b 100644 --- a/src/input/gamepad/Gamepad.js +++ b/src/input/gamepad/Gamepad.js @@ -25,15 +25,11 @@ var Vector2 = require('../../math/Vector2'); * @param {Phaser.Input.Gamepad.GamepadPlugin} manager - A reference to the Gamepad Plugin. * @param {Phaser.Types.Input.Gamepad.Pad} pad - The Gamepad object, as extracted from GamepadEvent. */ -var Gamepad = new Class({ +var Gamepad = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function Gamepad (manager, pad) + constructor(manager, pad) { - EventEmitter.call(this); + super(); /** * A reference to the Gamepad Plugin. @@ -323,7 +319,7 @@ var Gamepad = new Class({ * @since 3.50.0 */ this._created = performance.now(); - }, + } /** * Gets the total number of axis this Gamepad claims to support. @@ -333,10 +329,10 @@ var Gamepad = new Class({ * * @return {number} The total number of axes this Gamepad claims to support. */ - getAxisTotal: function () + getAxisTotal() { return this.axes.length; - }, + } /** * Gets the value of an axis based on the given index. @@ -350,10 +346,10 @@ var Gamepad = new Class({ * * @return {number} The value of the axis, between 0 and 1. */ - getAxisValue: function (index) + getAxisValue(index) { return this.axes[index].getValue(); - }, + } /** * Sets the threshold value of all axis on this Gamepad. @@ -364,13 +360,13 @@ var Gamepad = new Class({ * * @param {number} value - A value between 0 and 1. */ - setAxisThreshold: function (value) + setAxisThreshold(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. @@ -380,10 +376,10 @@ var Gamepad = new Class({ * * @return {number} The total number of buttons this Gamepad claims to have. */ - getButtonTotal: function () + getButtonTotal() { return this.buttons.length; - }, + } /** * Gets the value of a button based on the given index. @@ -399,10 +395,10 @@ var Gamepad = new Class({ * * @return {number} The value of the button, between 0 and 1. */ - getButtonValue: function (index) + getButtonValue(index) { return this.buttons[index].value; - }, + } /** * Returns if the button is pressed down or not. @@ -415,10 +411,10 @@ var Gamepad = new Class({ * * @return {boolean} `true` if the button is considered as being pressed down, otherwise `false`. */ - isButtonDown: function (index) + isButtonDown(index) { return this.buttons[index].pressed; - }, + } /** * Internal update handler for this Gamepad. @@ -428,7 +424,7 @@ var Gamepad = new Class({ * @private * @since 3.0.0 */ - update: function (pad) + update(pad) { if (pad.timestamp < this._created) { @@ -470,7 +466,7 @@ var Gamepad = new Class({ this.rightStick.set(localAxes[2].getValue(), localAxes[3].getValue()); } } - }, + } /** * Destroys this Gamepad instance, its buttons and axes, and releases external references it holds. @@ -478,7 +474,7 @@ var Gamepad = new Class({ * @method Phaser.Input.Gamepad.Gamepad#destroy * @since 3.10.0 */ - destroy: function () + destroy() { this.removeAllListeners(); @@ -499,7 +495,7 @@ var Gamepad = new Class({ this.buttons = []; this.axes = []; - }, + } /** * Is this Gamepad currently connected or not? @@ -509,14 +505,11 @@ var Gamepad = new Class({ * @default true * @since 3.0.0 */ - connected: { - get: function () - { - return this.pad.connected; - } - - }, + get connected() + { + return this.pad.connected; + } /** * A timestamp containing the most recent time this Gamepad was updated. @@ -525,14 +518,11 @@ var Gamepad = new Class({ * @type {number} * @since 3.0.0 */ - timestamp: { - get: function () - { - return this.pad.timestamp; - } - - }, + get timestamp() + { + return this.pad.timestamp; + } /** * Is the Gamepad's Left button being pressed? @@ -543,14 +533,11 @@ var Gamepad = new Class({ * @type {boolean} * @since 3.10.0 */ - left: { - get: function () - { - return this._LCLeft.pressed; - } - - }, + get left() + { + return this._LCLeft.pressed; + } /** * Is the Gamepad's Right button being pressed? @@ -561,14 +548,11 @@ var Gamepad = new Class({ * @type {boolean} * @since 3.10.0 */ - right: { - get: function () - { - return this._LCRight.pressed; - } - - }, + get right() + { + return this._LCRight.pressed; + } /** * Is the Gamepad's Up button being pressed? @@ -579,14 +563,11 @@ var Gamepad = new Class({ * @type {boolean} * @since 3.10.0 */ - up: { - get: function () - { - return this._LCTop.pressed; - } - - }, + get up() + { + return this._LCTop.pressed; + } /** * Is the Gamepad's Down button being pressed? @@ -597,14 +578,11 @@ var Gamepad = new Class({ * @type {boolean} * @since 3.10.0 */ - down: { - get: function () - { - return this._LCBottom.pressed; - } - - }, + get down() + { + return this._LCBottom.pressed; + } /** * Is the Gamepad's bottom button in the right button cluster being pressed? @@ -616,14 +594,11 @@ var Gamepad = new Class({ * @type {boolean} * @since 3.10.0 */ - A: { - get: function () - { - return this._RCBottom.pressed; - } - - }, + get A() + { + return this._RCBottom.pressed; + } /** * Is the Gamepad's top button in the right button cluster being pressed? @@ -635,14 +610,11 @@ var Gamepad = new Class({ * @type {boolean} * @since 3.10.0 */ - Y: { - get: function () - { - return this._RCTop.pressed; - } - - }, + get Y() + { + return this._RCTop.pressed; + } /** * Is the Gamepad's left button in the right button cluster being pressed? @@ -654,14 +626,11 @@ var Gamepad = new Class({ * @type {boolean} * @since 3.10.0 */ - X: { - get: function () - { - return this._RCLeft.pressed; - } - - }, + get X() + { + return this._RCLeft.pressed; + } /** * Is the Gamepad's right button in the right button cluster being pressed? @@ -673,14 +642,11 @@ var Gamepad = new Class({ * @type {boolean} * @since 3.10.0 */ - B: { - get: function () - { - return this._RCRight.pressed; - } - - }, + get B() + { + return this._RCRight.pressed; + } /** * Returns the value of the Gamepad's top left shoulder button. @@ -693,14 +659,11 @@ var Gamepad = new Class({ * @type {number} * @since 3.10.0 */ - L1: { - get: function () - { - return this._FBLeftTop.value; - } - - }, + get L1() + { + return this._FBLeftTop.value; + } /** * Returns the value of the Gamepad's bottom left shoulder button. @@ -713,14 +676,11 @@ var Gamepad = new Class({ * @type {number} * @since 3.10.0 */ - L2: { - get: function () - { - return this._FBLeftBottom.value; - } - - }, + get L2() + { + return this._FBLeftBottom.value; + } /** * Returns the value of the Gamepad's top right shoulder button. @@ -733,14 +693,11 @@ var Gamepad = new Class({ * @type {number} * @since 3.10.0 */ - R1: { - get: function () - { - return this._FBRightTop.value; - } - - }, + get R1() + { + return this._FBRightTop.value; + } /** * Returns the value of the Gamepad's bottom right shoulder button. @@ -753,15 +710,12 @@ var Gamepad = new Class({ * @type {number} * @since 3.10.0 */ - R2: { - - get: function () - { - return this._FBRightBottom.value; - } + get R2() + { + return this._FBRightBottom.value; } -}); +}; module.exports = Gamepad; diff --git a/src/input/gamepad/GamepadPlugin.js b/src/input/gamepad/GamepadPlugin.js index dd14c4a517..21b0cabe6e 100644 --- a/src/input/gamepad/GamepadPlugin.js +++ b/src/input/gamepad/GamepadPlugin.js @@ -58,15 +58,11 @@ var InputEvents = require('../events'); * * @param {Phaser.Input.InputPlugin} sceneInputPlugin - A reference to the Scene Input Plugin that the KeyboardPlugin belongs to. */ -var GamepadPlugin = new Class({ +var GamepadPlugin = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function GamepadPlugin (sceneInputPlugin) + constructor(sceneInputPlugin) { - EventEmitter.call(this); + super(); /** * A reference to the Scene that this Input Plugin is responsible for. @@ -188,7 +184,7 @@ var GamepadPlugin = new Class({ sceneInputPlugin.pluginEvents.once(InputEvents.BOOT, this.boot, this); sceneInputPlugin.pluginEvents.on(InputEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -198,7 +194,7 @@ var GamepadPlugin = new Class({ * @private * @since 3.10.0 */ - boot: function () + boot() { var game = this.scene.sys.game; var settings = this.settings.input; @@ -208,7 +204,7 @@ var GamepadPlugin = new Class({ this.target = GetValue(settings, 'gamepad.target', config.inputGamepadEventTarget); this.sceneInputPlugin.pluginEvents.once(InputEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -219,7 +215,7 @@ var GamepadPlugin = new Class({ * @private * @since 3.10.0 */ - start: function () + start() { if (this.enabled) { @@ -229,7 +225,7 @@ var GamepadPlugin = new Class({ } this.sceneInputPlugin.pluginEvents.once(InputEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * Checks to see if both this plugin and the Scene to which it belongs is active. @@ -239,10 +235,10 @@ var GamepadPlugin = new Class({ * * @return {boolean} `true` if the plugin and the Scene it belongs to is active. */ - isActive: function () + isActive() { return (this.enabled && this.scene.sys.isActive()); - }, + } /** * Starts the Gamepad Event listeners running. @@ -252,7 +248,7 @@ var GamepadPlugin = new Class({ * @private * @since 3.10.0 */ - startListeners: function () + startListeners() { var _this = this; var target = this.target; @@ -281,7 +277,7 @@ var GamepadPlugin = new Class({ // Finally, listen for an update event from the Input Plugin this.sceneInputPlugin.pluginEvents.on(InputEvents.UPDATE, this.update, this); - }, + } /** * Stops the Gamepad Event listeners. @@ -291,7 +287,7 @@ var GamepadPlugin = new Class({ * @private * @since 3.10.0 */ - stopListeners: function () + stopListeners() { this.target.removeEventListener('gamepadconnected', this.onGamepadHandler); this.target.removeEventListener('gamepaddisconnected', this.onGamepadHandler); @@ -302,7 +298,7 @@ var GamepadPlugin = new Class({ { this.gamepads[i].removeAllListeners(); } - }, + } /** * Disconnects all current Gamepads. @@ -310,13 +306,13 @@ var GamepadPlugin = new Class({ * @method Phaser.Input.Gamepad.GamepadPlugin#disconnectAll * @since 3.10.0 */ - disconnectAll: function () + disconnectAll() { for (var i = 0; i < this.gamepads.length; i++) { this.gamepads[i].pad.connected = false; } - }, + } /** * Refreshes the list of connected Gamepads. @@ -328,7 +324,7 @@ var GamepadPlugin = new Class({ * @private * @since 3.10.0 */ - refreshPads: function () + refreshPads() { var connectedPads = navigator.getGamepads(); @@ -392,7 +388,7 @@ var GamepadPlugin = new Class({ } } } - }, + } /** * Returns an array of all currently connected Gamepads. @@ -402,7 +398,7 @@ var GamepadPlugin = new Class({ * * @return {Phaser.Input.Gamepad.Gamepad[]} An array of all currently connected Gamepads. */ - getAll: function () + getAll() { var out = []; var pads = this.gamepads; @@ -416,7 +412,7 @@ var GamepadPlugin = new Class({ } return out; - }, + } /** * Looks-up a single Gamepad based on the given index value. @@ -428,7 +424,7 @@ var GamepadPlugin = new Class({ * * @return {Phaser.Input.Gamepad.Gamepad} The Gamepad matching the given index, or undefined if none were found. */ - getPad: function (index) + getPad(index) { var pads = this.gamepads; @@ -439,7 +435,7 @@ var GamepadPlugin = new Class({ return pads[i]; } } - }, + } /** * The internal update loop. Refreshes all connected gamepads and processes their events. @@ -452,7 +448,7 @@ var GamepadPlugin = new Class({ * @fires Phaser.Input.Gamepad.Events#DISCONNECTED * @since 3.10.0 */ - update: function () + update() { if (!this.enabled) { @@ -485,7 +481,7 @@ var GamepadPlugin = new Class({ this.emit(Events.DISCONNECTED, pad, event); } } - }, + } /** * Shuts the Gamepad Plugin down. @@ -495,12 +491,12 @@ var GamepadPlugin = new Class({ * @private * @since 3.10.0 */ - shutdown: function () + shutdown() { this.stopListeners(); this.removeAllListeners(); - }, + } /** * Destroys this Gamepad Plugin, disconnecting all Gamepads and releasing internal references. @@ -509,7 +505,7 @@ var GamepadPlugin = new Class({ * @private * @since 3.10.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -527,7 +523,7 @@ var GamepadPlugin = new Class({ this.settings = null; this.sceneInputPlugin = null; this.target = null; - }, + } /** * The total number of connected game pads. @@ -536,14 +532,11 @@ var GamepadPlugin = new Class({ * @type {number} * @since 3.10.0 */ - total: { - get: function () - { - return this.gamepads.length; - } - - }, + get total() + { + return this.gamepads.length; + } /** * A reference to the first connected Gamepad. @@ -556,14 +549,11 @@ var GamepadPlugin = new Class({ * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.10.0 */ - pad1: { - get: function () - { - return this._pad1; - } - - }, + get pad1() + { + return this._pad1; + } /** * A reference to the second connected Gamepad. @@ -576,14 +566,11 @@ var GamepadPlugin = new Class({ * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.10.0 */ - pad2: { - get: function () - { - return this._pad2; - } - - }, + get pad2() + { + return this._pad2; + } /** * A reference to the third connected Gamepad. @@ -596,14 +583,11 @@ var GamepadPlugin = new Class({ * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.10.0 */ - pad3: { - get: function () - { - return this._pad3; - } - - }, + get pad3() + { + return this._pad3; + } /** * A reference to the fourth connected Gamepad. @@ -616,16 +600,13 @@ var GamepadPlugin = new Class({ * @type {Phaser.Input.Gamepad.Gamepad} * @since 3.10.0 */ - pad4: { - - get: function () - { - return this._pad4; - } + get pad4() + { + return this._pad4; } -}); +}; /** * An instance of the Gamepad Plugin class, if enabled via the `input.gamepad` Scene or Game Config property. diff --git a/src/input/keyboard/KeyboardManager.js b/src/input/keyboard/KeyboardManager.js index 95e6278050..f94fb24268 100644 --- a/src/input/keyboard/KeyboardManager.js +++ b/src/input/keyboard/KeyboardManager.js @@ -27,11 +27,9 @@ var NOOP = require('../../utils/NOOP'); * * @param {Phaser.Input.InputManager} inputManager - A reference to the Input Manager. */ -var KeyboardManager = new Class({ +var KeyboardManager = class { - initialize: - - function KeyboardManager (inputManager) + constructor(inputManager) { /** * A reference to the Input Manager. @@ -141,7 +139,7 @@ var KeyboardManager = new Class({ this.onKeyUp = NOOP; inputManager.events.once(InputEvents.MANAGER_BOOT, this.boot, this); - }, + } /** * The Keyboard Manager boot process. @@ -150,7 +148,7 @@ var KeyboardManager = new Class({ * @private * @since 3.16.0 */ - boot: function () + boot() { var config = this.manager.config; @@ -170,7 +168,7 @@ var KeyboardManager = new Class({ } this.manager.game.events.on(GameEvents.POST_STEP, this.postUpdate, this); - }, + } /** * Starts the Keyboard Event listeners running. @@ -179,7 +177,7 @@ var KeyboardManager = new Class({ * @method Phaser.Input.Keyboard.KeyboardManager#startListeners * @since 3.16.0 */ - startListeners: function () + startListeners() { var _this = this; @@ -232,7 +230,7 @@ var KeyboardManager = new Class({ this.enabled = true; } - }, + } /** * Stops the Key Event listeners. @@ -241,7 +239,7 @@ var KeyboardManager = new Class({ * @method Phaser.Input.Keyboard.KeyboardManager#stopListeners * @since 3.16.0 */ - stopListeners: function () + stopListeners() { var target = this.target; @@ -249,7 +247,7 @@ var KeyboardManager = new Class({ target.removeEventListener('keyup', this.onKeyUp, false); this.enabled = false; - }, + } /** * Clears the event queue. @@ -259,10 +257,10 @@ var KeyboardManager = new Class({ * @private * @since 3.16.0 */ - postUpdate: function () + postUpdate() { this.queue = []; - }, + } /** * By default when a key is pressed Phaser will not stop the event from propagating up to the browser. @@ -303,7 +301,7 @@ var KeyboardManager = new Class({ * * @param {(string|number|number[]|any[])} keycode - The Key Codes to enable capture for, preventing them reaching the browser. */ - addCapture: function (keycode) + addCapture(keycode) { if (typeof keycode === 'string') { @@ -333,7 +331,7 @@ var KeyboardManager = new Class({ } this.preventDefault = captures.length > 0; - }, + } /** * Removes an existing key capture. @@ -370,7 +368,7 @@ var KeyboardManager = new Class({ * * @param {(string|number|number[]|any[])} keycode - The Key Codes to disable capture for, allowing them reaching the browser again. */ - removeCapture: function (keycode) + removeCapture(keycode) { if (typeof keycode === 'string') { @@ -397,7 +395,7 @@ var KeyboardManager = new Class({ } this.preventDefault = captures.length > 0; - }, + } /** * Removes all keyboard captures and sets the `preventDefault` property to `false`. @@ -405,12 +403,12 @@ var KeyboardManager = new Class({ * @method Phaser.Input.Keyboard.KeyboardManager#clearCaptures * @since 3.16.0 */ - clearCaptures: function () + clearCaptures() { this.captures = []; this.preventDefault = false; - }, + } /** * Destroys this Keyboard Manager instance. @@ -418,7 +416,7 @@ var KeyboardManager = new Class({ * @method Phaser.Input.Keyboard.KeyboardManager#destroy * @since 3.16.0 */ - destroy: function () + destroy() { this.stopListeners(); @@ -433,6 +431,6 @@ var KeyboardManager = new Class({ this.manager = null; } -}); +}; module.exports = KeyboardManager; diff --git a/src/input/keyboard/KeyboardPlugin.js b/src/input/keyboard/KeyboardPlugin.js index 5893c56644..01e961c496 100644 --- a/src/input/keyboard/KeyboardPlugin.js +++ b/src/input/keyboard/KeyboardPlugin.js @@ -64,15 +64,11 @@ var SnapFloor = require('../../math/snap/SnapFloor'); * * @param {Phaser.Input.InputPlugin} sceneInputPlugin - A reference to the Scene Input Plugin that the KeyboardPlugin belongs to. */ -var KeyboardPlugin = new Class({ +var KeyboardPlugin = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function KeyboardPlugin (sceneInputPlugin) + constructor(sceneInputPlugin) { - EventEmitter.call(this); + super(); /** * A reference to the core game, so we can listen for visibility events. @@ -180,7 +176,7 @@ var KeyboardPlugin = new Class({ sceneInputPlugin.pluginEvents.once(InputEvents.BOOT, this.boot, this); sceneInputPlugin.pluginEvents.on(InputEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -190,7 +186,7 @@ var KeyboardPlugin = new Class({ * @private * @since 3.10.0 */ - boot: function () + boot() { var settings = this.settings.input; @@ -204,7 +200,7 @@ var KeyboardPlugin = new Class({ } this.sceneInputPlugin.pluginEvents.once(InputEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -215,7 +211,7 @@ var KeyboardPlugin = new Class({ * @private * @since 3.10.0 */ - start: function () + start() { this.sceneInputPlugin.manager.events.on(InputEvents.MANAGER_PROCESS, this.update, this); @@ -225,7 +221,7 @@ var KeyboardPlugin = new Class({ this.scene.sys.events.on(SceneEvents.PAUSE, this.resetKeys, this); this.scene.sys.events.on(SceneEvents.SLEEP, this.resetKeys, this); - }, + } /** * Checks to see if both this plugin and the Scene to which it belongs is active. @@ -235,10 +231,10 @@ var KeyboardPlugin = new Class({ * * @return {boolean} `true` if the plugin and the Scene it belongs to is active. */ - isActive: function () + isActive() { return (this.enabled && this.scene.sys.canInput()); - }, + } /** * By default when a key is pressed Phaser will not stop the event from propagating up to the browser. @@ -279,12 +275,12 @@ var KeyboardPlugin = new Class({ * * @return {this} This KeyboardPlugin object. */ - addCapture: function (keycode) + addCapture(keycode) { this.manager.addCapture(keycode); return this; - }, + } /** * Removes an existing key capture. @@ -321,12 +317,12 @@ var KeyboardPlugin = new Class({ * * @return {this} This KeyboardPlugin object. */ - removeCapture: function (keycode) + removeCapture(keycode) { this.manager.removeCapture(keycode); return this; - }, + } /** * Returns an array that contains all of the keyboard captures currently enabled. @@ -336,10 +332,10 @@ var KeyboardPlugin = new Class({ * * @return {number[]} An array of all the currently capturing key codes. */ - getCaptures: function () + getCaptures() { return this.manager.captures; - }, + } /** * Allows Phaser to prevent any key captures you may have defined from bubbling up the browser. @@ -350,12 +346,12 @@ var KeyboardPlugin = new Class({ * * @return {this} This KeyboardPlugin object. */ - enableGlobalCapture: function () + enableGlobalCapture() { this.manager.preventDefault = true; return this; - }, + } /** * Disables Phaser from preventing any key captures you may have defined, without actually removing them. @@ -366,12 +362,12 @@ var KeyboardPlugin = new Class({ * * @return {this} This KeyboardPlugin object. */ - disableGlobalCapture: function () + disableGlobalCapture() { this.manager.preventDefault = false; return this; - }, + } /** * Removes all keyboard captures. @@ -383,12 +379,12 @@ var KeyboardPlugin = new Class({ * * @return {this} This KeyboardPlugin object. */ - clearCaptures: function () + clearCaptures() { this.manager.clearCaptures(); return this; - }, + } /** * Creates and returns an object containing 4 hotkeys for Up, Down, Left and Right, and also Space Bar and shift. @@ -398,7 +394,7 @@ var KeyboardPlugin = new Class({ * * @return {Phaser.Types.Input.Keyboard.CursorKeys} An object containing the properties: `up`, `down`, `left`, `right`, `space` and `shift`. */ - createCursorKeys: function () + createCursorKeys() { return this.addKeys({ up: KeyCodes.UP, @@ -408,7 +404,7 @@ var KeyboardPlugin = new Class({ space: KeyCodes.SPACE, shift: KeyCodes.SHIFT }); - }, + } /** * A practical way to create an object containing user selected hotkeys. @@ -440,7 +436,7 @@ var KeyboardPlugin = new Class({ * * @return {object} An object containing Key objects mapped to the input properties. */ - addKeys: function (keys, enableCapture, emitOnRepeat) + addKeys(keys, enableCapture, emitOnRepeat) { if (enableCapture === undefined) { enableCapture = true; } if (emitOnRepeat === undefined) { emitOnRepeat = false; } @@ -470,7 +466,7 @@ var KeyboardPlugin = new Class({ } return output; - }, + } /** * Adds a Key object to this Keyboard Plugin. @@ -488,7 +484,7 @@ var KeyboardPlugin = new Class({ * * @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, enableCapture, emitOnRepeat) + addKey(key, enableCapture, emitOnRepeat) { if (enableCapture === undefined) { enableCapture = true; } if (emitOnRepeat === undefined) { emitOnRepeat = false; } @@ -536,7 +532,7 @@ var KeyboardPlugin = new Class({ } return keys[key]; - }, + } /** * Removes a Key object from this Keyboard Plugin. @@ -552,7 +548,7 @@ var KeyboardPlugin = new Class({ * * @return {this} This KeyboardPlugin object. */ - removeKey: function (key, destroy, removeCapture) + removeKey(key, destroy, removeCapture) { if (destroy === undefined) { destroy = false; } if (removeCapture === undefined) { removeCapture = false; } @@ -599,7 +595,7 @@ var KeyboardPlugin = new Class({ } return this; - }, + } /** * Removes all Key objects created by _this_ Keyboard Plugin. @@ -612,7 +608,7 @@ var KeyboardPlugin = new Class({ * * @return {this} This KeyboardPlugin object. */ - removeAllKeys: function (destroy, removeCapture) + removeAllKeys(destroy, removeCapture) { if (destroy === undefined) { destroy = false; } if (removeCapture === undefined) { removeCapture = false; } @@ -640,7 +636,7 @@ var KeyboardPlugin = new Class({ } return this; - }, + } /** * Creates a new KeyCombo. @@ -679,10 +675,10 @@ var KeyboardPlugin = new Class({ * * @return {Phaser.Input.Keyboard.KeyCombo} The new KeyCombo object. */ - createCombo: function (keys, config) + createCombo(keys, config) { return new KeyCombo(this, keys, config); - }, + } /** * Checks if the given Key object is currently being held down. @@ -702,7 +698,7 @@ var KeyboardPlugin = new Class({ * * @return {boolean} `true` if the Key is down within the duration specified, otherwise `false`. */ - checkDown: function (key, duration) + checkDown(key, duration) { if (duration === undefined) { duration = 0; } @@ -719,7 +715,7 @@ var KeyboardPlugin = new Class({ } return false; - }, + } /** * Internal update handler called by the Input Plugin, which is in turn invoked by the Game step. @@ -728,7 +724,7 @@ var KeyboardPlugin = new Class({ * @private * @since 3.10.0 */ - update: function () + update() { var queue = this.manager.queue; var len = queue.length; @@ -835,7 +831,7 @@ var KeyboardPlugin = new Class({ event.cancelled = 0; } } - }, + } /** * Resets all Key objects created by _this_ Keyboard Plugin back to their default un-pressed states. @@ -850,7 +846,7 @@ var KeyboardPlugin = new Class({ * * @return {this} This KeyboardPlugin object. */ - resetKeys: function () + resetKeys() { var keys = this.keys; @@ -864,7 +860,7 @@ var KeyboardPlugin = new Class({ } return this; - }, + } /** * Shuts this Keyboard Plugin down. This performs the following tasks: @@ -877,7 +873,7 @@ var KeyboardPlugin = new Class({ * @private * @since 3.10.0 */ - shutdown: function () + shutdown() { this.removeAllKeys(true); this.removeAllListeners(); @@ -890,7 +886,7 @@ var KeyboardPlugin = new Class({ this.scene.sys.events.off(SceneEvents.SLEEP, this.resetKeys, this); this.queue = []; - }, + } /** * Destroys this Keyboard Plugin instance and all references it holds, plus clears out local arrays. @@ -899,7 +895,7 @@ var KeyboardPlugin = new Class({ * @private * @since 3.10.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -922,7 +918,7 @@ var KeyboardPlugin = new Class({ this.settings = null; this.sceneInputPlugin = null; this.manager = null; - }, + } /** * Internal time value. @@ -932,16 +928,13 @@ var KeyboardPlugin = new Class({ * @private * @since 3.11.0 */ - time: { - - get: function () - { - return this.sceneInputPlugin.manager.time; - } + get time() + { + return this.sceneInputPlugin.manager.time; } -}); +}; /** * An instance of the Keyboard Plugin class, if enabled via the `input.keyboard` Scene or Game Config property. diff --git a/src/input/keyboard/combo/KeyCombo.js b/src/input/keyboard/combo/KeyCombo.js index c50d6acd8f..531a1535c2 100644 --- a/src/input/keyboard/combo/KeyCombo.js +++ b/src/input/keyboard/combo/KeyCombo.js @@ -48,11 +48,9 @@ var ResetKeyCombo = require('./ResetKeyCombo'); * @param {(string|number[]|object[])} keys - The keys that comprise this combo. * @param {Phaser.Types.Input.Keyboard.KeyComboConfig} [config] - A Key Combo configuration object. */ -var KeyCombo = new Class({ +var KeyCombo = class { - initialize: - - function KeyCombo (keyboardPlugin, keys, config) + constructor(keyboardPlugin, keys, config) { if (config === undefined) { config = {}; } @@ -247,7 +245,7 @@ var KeyCombo = new Class({ this.onKeyDown = onKeyDownHandler; this.manager.on(Events.ANY_KEY_DOWN, this.onKeyDown); - }, + } /** * How far complete is this combo? A value between 0 and 1. @@ -257,14 +255,11 @@ var KeyCombo = new Class({ * @readonly * @since 3.0.0 */ - progress: { - get: function () - { - return this.index / this.size; - } - - }, + get progress() + { + return this.index / this.size; + } /** * Destroys this Key Combo and all of its references. @@ -272,7 +267,7 @@ var KeyCombo = new Class({ * @method Phaser.Input.Keyboard.KeyCombo#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.enabled = false; this.keyCodes = []; @@ -282,6 +277,6 @@ var KeyCombo = new Class({ this.manager = null; } -}); +}; module.exports = KeyCombo; diff --git a/src/input/keyboard/keys/Key.js b/src/input/keyboard/keys/Key.js index 288f042de1..7141edbf5f 100644 --- a/src/input/keyboard/keys/Key.js +++ b/src/input/keyboard/keys/Key.js @@ -22,15 +22,11 @@ var Events = require('../events'); * @param {Phaser.Input.Keyboard.KeyboardPlugin} plugin - The Keyboard Plugin instance that owns this Key object. * @param {number} keyCode - The keycode of this key. */ -var Key = new Class({ +var Key = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function Key (plugin, keyCode) + constructor(plugin, keyCode) { - EventEmitter.call(this); + super(); /** * The Keyboard Plugin instance that owns this Key object. @@ -226,7 +222,7 @@ var Key = new Class({ * @since 3.11.0 */ this._tick = -1; - }, + } /** * Controls if this Key will continuously emit a `down` event while being held down (true), @@ -239,12 +235,12 @@ var Key = new Class({ * * @return {this} This Key instance. */ - setEmitOnRepeat: function (value) + setEmitOnRepeat(value) { this.emitOnRepeat = value; return this; - }, + } /** * Processes the Key Down action for this Key. @@ -256,7 +252,7 @@ var Key = new Class({ * * @param {KeyboardEvent} event - The native DOM Keyboard event. */ - onDown: function (event) + onDown(event) { this.originalEvent = event; @@ -288,7 +284,7 @@ var Key = new Class({ { this.emit(Events.DOWN, this, event); } - }, + } /** * Processes the Key Up action for this Key. @@ -300,7 +296,7 @@ var Key = new Class({ * * @param {KeyboardEvent} event - The native DOM Keyboard event. */ - onUp: function (event) + onUp(event) { this.originalEvent = event; @@ -320,7 +316,7 @@ var Key = new Class({ this._tick = -1; this.emit(Events.UP, this, event); - }, + } /** * Resets this Key object back to its default un-pressed state. @@ -332,7 +328,7 @@ var Key = new Class({ * * @return {this} This Key instance. */ - reset: function () + reset() { this.isDown = false; this.isUp = true; @@ -349,7 +345,7 @@ var Key = new Class({ this._tick = -1; return this; - }, + } /** * Returns the duration, in ms, that the Key has been held down for. @@ -364,7 +360,7 @@ var Key = new Class({ * * @return {number} The duration, in ms, that the Key has been held down for if currently down. */ - getDuration: function () + getDuration() { if (this.isDown) { @@ -374,7 +370,7 @@ var Key = new Class({ { return 0; } - }, + } /** * Removes any bound event handlers and removes local references. @@ -382,7 +378,7 @@ var Key = new Class({ * @method Phaser.Input.Keyboard.Key#destroy * @since 3.16.0 */ - destroy: function () + destroy() { this.removeAllListeners(); @@ -391,6 +387,6 @@ var Key = new Class({ this.plugin = null; } -}); +}; module.exports = Key; diff --git a/src/input/mouse/MouseManager.js b/src/input/mouse/MouseManager.js index c080e78e2c..4fb6e3f7bf 100644 --- a/src/input/mouse/MouseManager.js +++ b/src/input/mouse/MouseManager.js @@ -27,11 +27,9 @@ var NOOP = require('../../utils/NOOP'); * * @param {Phaser.Input.InputManager} inputManager - A reference to the Input Manager. */ -var MouseManager = new Class({ +var MouseManager = class { - initialize: - - function MouseManager (inputManager) + constructor(inputManager) { /** * A reference to the Input Manager. @@ -227,7 +225,7 @@ var MouseManager = new Class({ this.isTop = true; inputManager.events.once(InputEvents.MANAGER_BOOT, this.boot, this); - }, + } /** * The Touch Manager boot process. @@ -236,7 +234,7 @@ var MouseManager = new Class({ * @private * @since 3.0.0 */ - boot: function () + boot() { var config = this.manager.config; @@ -267,7 +265,7 @@ var MouseManager = new Class({ { this.startListeners(); } - }, + } /** * Attempts to disable the context menu from appearing if you right-click on the game canvas, or specified input target. @@ -282,7 +280,7 @@ var MouseManager = new Class({ * * @return {this} This Mouse Manager instance. */ - disableContextMenu: function () + disableContextMenu() { this.target.addEventListener('contextmenu', function (event) { @@ -291,7 +289,7 @@ var MouseManager = new Class({ }); return this; - }, + } /** * If the browser supports it, you can request that the pointer be locked to the browser window. @@ -314,7 +312,7 @@ var MouseManager = new Class({ * @method Phaser.Input.Mouse.MouseManager#requestPointerLock * @since 3.0.0 */ - requestPointerLock: function () + requestPointerLock() { if (Features.pointerLock) { @@ -324,7 +322,7 @@ var MouseManager = new Class({ element.requestPointerLock(); } - }, + } /** * If the browser supports pointer lock, this will request that the pointer lock is released. If @@ -334,14 +332,14 @@ var MouseManager = new Class({ * @method Phaser.Input.Mouse.MouseManager#releasePointerLock * @since 3.0.0 */ - releasePointerLock: function () + releasePointerLock() { if (Features.pointerLock) { document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock; document.exitPointerLock(); } - }, + } /** * Starts the Mouse Event listeners running. @@ -350,7 +348,7 @@ var MouseManager = new Class({ * @method Phaser.Input.Mouse.MouseManager#startListeners * @since 3.0.0 */ - startListeners: function () + startListeners() { var target = this.target; @@ -515,7 +513,7 @@ var MouseManager = new Class({ } this.enabled = true; - }, + } /** * Stops the Mouse Event listeners. @@ -524,7 +522,7 @@ var MouseManager = new Class({ * @method Phaser.Input.Mouse.MouseManager#stopListeners * @since 3.0.0 */ - stopListeners: function () + stopListeners() { var target = this.target; @@ -548,7 +546,7 @@ var MouseManager = new Class({ document.removeEventListener('mozpointerlockchange', this.pointerLockChange, true); document.removeEventListener('webkitpointerlockchange', this.pointerLockChange, true); } - }, + } /** * Destroys this Mouse Manager instance. @@ -556,7 +554,7 @@ var MouseManager = new Class({ * @method Phaser.Input.Mouse.MouseManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.stopListeners(); @@ -565,6 +563,6 @@ var MouseManager = new Class({ this.manager = null; } -}); +}; module.exports = MouseManager; diff --git a/src/input/touch/TouchManager.js b/src/input/touch/TouchManager.js index 59b5711387..a19adab436 100644 --- a/src/input/touch/TouchManager.js +++ b/src/input/touch/TouchManager.js @@ -27,11 +27,9 @@ var NOOP = require('../../utils/NOOP'); * * @param {Phaser.Input.InputManager} inputManager - A reference to the Input Manager. */ -var TouchManager = new Class({ +var TouchManager = class { - initialize: - - function TouchManager (inputManager) + constructor(inputManager) { /** * A reference to the Input Manager. @@ -158,7 +156,7 @@ var TouchManager = new Class({ this.isTop = true; inputManager.events.once(InputEvents.MANAGER_BOOT, this.boot, this); - }, + } /** * The Touch Manager boot process. @@ -167,7 +165,7 @@ var TouchManager = new Class({ * @private * @since 3.0.0 */ - boot: function () + boot() { var config = this.manager.config; @@ -193,7 +191,7 @@ var TouchManager = new Class({ { this.startListeners(); } - }, + } /** * Attempts to disable the context menu from appearing if you touch-hold on the browser. @@ -207,7 +205,7 @@ var TouchManager = new Class({ * * @return {this} This Touch Manager instance. */ - disableContextMenu: function () + disableContextMenu() { this.target.addEventListener('contextmenu', function (event) { @@ -216,7 +214,7 @@ var TouchManager = new Class({ }); return this; - }, + } /** * Starts the Touch Event listeners running as long as an input target is set. @@ -228,7 +226,7 @@ var TouchManager = new Class({ * @method Phaser.Input.Touch.TouchManager#startListeners * @since 3.0.0 */ - startListeners: function () + startListeners() { var target = this.target; @@ -353,7 +351,7 @@ var TouchManager = new Class({ } this.enabled = true; - }, + } /** * Stops the Touch Event listeners. @@ -362,7 +360,7 @@ var TouchManager = new Class({ * @method Phaser.Input.Touch.TouchManager#stopListeners * @since 3.0.0 */ - stopListeners: function () + stopListeners() { var target = this.target; @@ -379,7 +377,7 @@ var TouchManager = new Class({ target.removeEventListener('touchend', this.onTouchEndWindow); target.removeEventListener('touchcancel', this.onTouchCancelWindow); } - }, + } /** * Destroys this Touch Manager instance. @@ -387,7 +385,7 @@ var TouchManager = new Class({ * @method Phaser.Input.Touch.TouchManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.stopListeners(); @@ -396,6 +394,6 @@ var TouchManager = new Class({ this.manager = null; } -}); +}; module.exports = TouchManager; diff --git a/src/loader/File.js b/src/loader/File.js index 6446cda57d..16830e7285 100644 --- a/src/loader/File.js +++ b/src/loader/File.js @@ -26,11 +26,9 @@ var XHRSettings = require('./XHRSettings'); * @param {Phaser.Loader.LoaderPlugin} loader - The Loader that is going to load this File. * @param {Phaser.Types.Loader.FileConfig} fileConfig - The file configuration object, as created by the file type. */ -var File = new Class({ +var File = class { - initialize: - - function File (loader, fileConfig) + constructor(loader, fileConfig) { /** * A reference to the Loader that is going to load this file. @@ -260,7 +258,7 @@ var File = new Class({ * @since 3.85.0 */ this.retryAttempts = GetFastValue(fileConfig, 'maxRetries', loader.maxRetries); - }, + } /** * Links this File with another, so they depend upon each other for loading and processing. @@ -270,12 +268,12 @@ var File = new Class({ * * @param {Phaser.Loader.File} fileB - The file to link to this one. */ - setLink: function (fileB) + setLink(fileB) { this.linkFile = fileB; fileB.linkFile = this; - }, + } /** * Resets the XHRLoader instance this file is using. @@ -283,7 +281,7 @@ var File = new Class({ * @method Phaser.Loader.File#resetXHR * @since 3.0.0 */ - resetXHR: function () + resetXHR() { if (this.xhrLoader) { @@ -291,7 +289,7 @@ var File = new Class({ this.xhrLoader.onerror = undefined; this.xhrLoader.onprogress = undefined; } - }, + } /** * Called by the Loader, starts the actual file downloading. @@ -301,7 +299,7 @@ var File = new Class({ * @method Phaser.Loader.File#load * @since 3.0.0 */ - load: function () + load() { if (this.state === CONST.FILE_POPULATED) { @@ -326,7 +324,7 @@ var File = new Class({ this.xhrLoader = XHRLoader(this, this.loader.xhr); } - }, + } /** * Called when the file finishes loading, is sent a DOM ProgressEvent. @@ -337,7 +335,7 @@ var File = new Class({ * @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) + onLoad(xhr, event) { var isLocalFile = xhr.responseURL && this.loader.localSchemes.some(function (scheme) { @@ -359,7 +357,7 @@ var File = new Class({ this.resetXHR(); this.loader.nextFile(this, success); - }, + } /** * Called by the XHRLoader if it was given a File with base64 data to load. @@ -369,7 +367,7 @@ var File = new Class({ * * @param {XMLHttpRequest} xhr - The FakeXHR object containing the decoded base64 data. */ - onBase64Load: function (xhr) + onBase64Load(xhr) { this.xhrLoader = xhr; @@ -380,7 +378,7 @@ var File = new Class({ this.loader.emit(Events.FILE_PROGRESS, this, this.percentComplete); this.loader.nextFile(this, true); - }, + } /** * Called if the file errors while loading, is sent a DOM ProgressEvent. @@ -391,7 +389,7 @@ var File = new Class({ * @param {XMLHttpRequest} xhr - The XMLHttpRequest that caused this onload event. * @param {ProgressEvent} event - The DOM ProgressEvent that resulted from this error. */ - onError: function () + onError() { this.resetXHR(); @@ -405,7 +403,7 @@ var File = new Class({ { this.loader.nextFile(this, false); } - }, + } /** * Called during the file load progress. Is sent a DOM ProgressEvent. @@ -416,7 +414,7 @@ var File = new Class({ * * @param {ProgressEvent} event - The DOM ProgressEvent. */ - onProgress: function (event) + onProgress(event) { if (event.lengthComputable) { @@ -427,7 +425,7 @@ var File = new Class({ this.loader.emit(Events.FILE_PROGRESS, this, this.percentComplete); } - }, + } /** * Usually overridden by the FileTypes and is called by Loader.nextFile. @@ -436,12 +434,12 @@ var File = new Class({ * @method Phaser.Loader.File#onProcess * @since 3.0.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; this.onProcessComplete(); - }, + } /** * Called when the File has completed processing. @@ -450,7 +448,7 @@ var File = new Class({ * @method Phaser.Loader.File#onProcessComplete * @since 3.7.0 */ - onProcessComplete: function () + onProcessComplete() { this.state = CONST.FILE_COMPLETE; @@ -460,7 +458,7 @@ var File = new Class({ } this.loader.fileProcessComplete(this); - }, + } /** * Called when the File has completed processing but it generated an error. @@ -469,7 +467,7 @@ var File = new Class({ * @method Phaser.Loader.File#onProcessError * @since 3.7.0 */ - onProcessError: function () + onProcessError() { // eslint-disable-next-line no-console console.error('Failed to process file: %s "%s"', this.type, this.key); @@ -482,7 +480,7 @@ var File = new Class({ } this.loader.fileProcessComplete(this); - }, + } /** * Checks if a key matching the one used by this file exists in the target Cache or not. @@ -494,10 +492,10 @@ var File = new Class({ * * @return {boolean} `true` if adding this file will cause a conflict, otherwise `false`. */ - hasCacheConflict: function () + hasCacheConflict() { return (this.cache && this.cache.exists(this.key)); - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -506,13 +504,13 @@ var File = new Class({ * @method Phaser.Loader.File#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { if (this.cache && this.data) { this.cache.add(this.key, this.data); } - }, + } /** * Called once the file has been added to its cache and is now ready for deletion from the Loader. @@ -523,7 +521,7 @@ var File = new Class({ * @fires Phaser.Loader.Events#FILE_KEY_COMPLETE * @since 3.7.0 */ - pendingDestroy: function (data) + pendingDestroy(data) { if (this.state === CONST.FILE_PENDING_DESTROY) { @@ -541,7 +539,7 @@ var File = new Class({ this.loader.flagForRemoval(this); this.state = CONST.FILE_PENDING_DESTROY; - }, + } /** * Destroy this File and any references it holds. @@ -549,7 +547,7 @@ var File = new Class({ * @method Phaser.Loader.File#destroy * @since 3.7.0 */ - destroy: function () + destroy() { this.loader = null; this.cache = null; @@ -559,7 +557,7 @@ var File = new Class({ this.data = null; } -}); +}; /** * Static method for creating object URL using URL API and setting it as image 'src' attribute. diff --git a/src/loader/LoaderPlugin.js b/src/loader/LoaderPlugin.js index 7e40c1b405..36243c0e03 100644 --- a/src/loader/LoaderPlugin.js +++ b/src/loader/LoaderPlugin.js @@ -50,15 +50,11 @@ var XHRSettings = require('./XHRSettings'); * * @param {Phaser.Scene} scene - The Scene which owns this Loader instance. */ -var LoaderPlugin = new Class({ +var LoaderPlugin = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function LoaderPlugin (scene) + constructor(scene) { - EventEmitter.call(this); + super(); var gameConfig = scene.sys.game.config; var sceneConfig = scene.sys.settings.loader; @@ -366,7 +362,7 @@ var LoaderPlugin = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.pluginStart, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -376,10 +372,10 @@ var LoaderPlugin = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.systems.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -390,10 +386,10 @@ var LoaderPlugin = new Class({ * @private * @since 3.5.1 */ - pluginStart: function () + pluginStart() { this.systems.events.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * If you want to append a URL before the path of any asset you can set this here. @@ -410,7 +406,7 @@ var LoaderPlugin = new Class({ * * @return {this} This Loader object. */ - setBaseURL: function (url) + setBaseURL(url) { if (url === undefined) { url = ''; } @@ -422,7 +418,7 @@ var LoaderPlugin = new Class({ this.baseURL = url; return this; - }, + } /** * The value of `path`, if set, is placed before any _relative_ file path given. For example: @@ -450,7 +446,7 @@ var LoaderPlugin = new Class({ * * @return {this} This Loader object. */ - setPath: function (path) + setPath(path) { if (path === undefined) { path = ''; } @@ -462,7 +458,7 @@ var LoaderPlugin = new Class({ this.path = path; return this; - }, + } /** * An optional prefix that is automatically prepended to the start of every file key. @@ -479,14 +475,14 @@ var LoaderPlugin = new Class({ * * @return {this} This Loader object. */ - setPrefix: function (prefix) + setPrefix(prefix) { if (prefix === undefined) { prefix = ''; } this.prefix = prefix; return this; - }, + } /** * Sets the Cross Origin Resource Sharing value used when loading files. @@ -505,12 +501,12 @@ var LoaderPlugin = new Class({ * * @return {this} This Loader object. */ - setCORS: function (crossOrigin) + setCORS(crossOrigin) { this.crossOrigin = crossOrigin; return this; - }, + } /** * Adds a file, or array of files, into the load queue. @@ -529,7 +525,7 @@ var LoaderPlugin = new Class({ * * @param {(Phaser.Loader.File|Phaser.Loader.File[])} file - The file, or array of files, to be added to the load queue. */ - addFile: function (file) + addFile(file) { if (!Array.isArray(file)) { @@ -555,7 +551,7 @@ var LoaderPlugin = new Class({ } } } - }, + } /** * Checks the key and type of the given file to see if it will conflict with anything already @@ -568,7 +564,7 @@ var LoaderPlugin = new Class({ * * @return {boolean} `true` if adding this file will cause a cache or queue conflict, otherwise `false`. */ - keyExists: function (file) + keyExists(file) { var keyConflict = file.hasCacheConflict(); @@ -612,7 +608,7 @@ var LoaderPlugin = new Class({ } return keyConflict; - }, + } /** * Takes a well formed, fully parsed pack file object and adds its entries into the load queue. Usually you do not call @@ -631,7 +627,7 @@ var LoaderPlugin = new Class({ * * @return {boolean} `true` if any files were added to the queue, otherwise `false`. */ - addPack: function (pack, packKey) + addPack(pack, packKey) { // if no packKey provided we'll add everything to the queue if (typeof(packKey) === 'string') @@ -694,7 +690,7 @@ var LoaderPlugin = new Class({ this.setPrefix(currentPrefix); return (total > 0); - }, + } /** * Remove the resources listed in an Asset Pack. @@ -709,7 +705,7 @@ var LoaderPlugin = new Class({ * @param {(string|object)} packKey - The key of an Asset Pack in the JSON cache, or a Pack File data. * @param {string} [dataKey] - A key in the Pack data, if you want to process only a section of it. */ - removePack: function (packKey, dataKey) + removePack(packKey, dataKey) { var animationManager = this.systems.anims; var cacheManager = this.cacheManager; @@ -868,7 +864,7 @@ var LoaderPlugin = new Class({ } } } - }, + } /** * Is the Loader actively loading, or processing loaded files? @@ -878,10 +874,10 @@ var LoaderPlugin = new Class({ * * @return {boolean} `true` if the Loader is busy loading or processing, otherwise `false`. */ - isLoading: function () + isLoading() { return (this.state === CONST.LOADER_LOADING || this.state === CONST.LOADER_PROCESSING); - }, + } /** * Is the Loader ready to start a new load? @@ -891,10 +887,10 @@ var LoaderPlugin = new Class({ * * @return {boolean} `true` if the Loader is ready to start a new load, otherwise `false`. */ - isReady: function () + isReady() { return (this.state === CONST.LOADER_IDLE || this.state === CONST.LOADER_COMPLETE); - }, + } /** * Starts the Loader running. This will reset the progress and totals and then emit a `start` event. @@ -911,7 +907,7 @@ var LoaderPlugin = new Class({ * @fires Phaser.Loader.Events#START * @since 3.0.0 */ - start: function () + start() { if (!this.isReady()) { @@ -943,7 +939,7 @@ var LoaderPlugin = new Class({ this.systems.events.on(SceneEvents.UPDATE, this.update, this); } - }, + } /** * Called automatically during the load process. @@ -954,12 +950,12 @@ var LoaderPlugin = new Class({ * @fires Phaser.Loader.Events#PROGRESS * @since 3.0.0 */ - updateProgress: function () + updateProgress() { this.progress = 1 - ((this.list.size + this.inflight.size) / this.totalToLoad); this.emit(Events.PROGRESS, this.progress); - }, + } /** * Called automatically during the load process. @@ -967,13 +963,13 @@ var LoaderPlugin = new Class({ * @method Phaser.Loader.LoaderPlugin#update * @since 3.10.0 */ - update: function () + update() { if (this.state === CONST.LOADER_LOADING && this.list.size > 0 && this.inflight.size < this.maxParallelDownloads) { this.checkLoadQueue(); } - }, + } /** * An internal method called by the Loader. @@ -987,7 +983,7 @@ var LoaderPlugin = new Class({ * @private * @since 3.7.0 */ - checkLoadQueue: function () + checkLoadQueue() { this.list.forEach(function (file) { @@ -1013,7 +1009,7 @@ var LoaderPlugin = new Class({ } }, this); - }, + } /** * An internal method called automatically by the XHRLoader belonging to a File. @@ -1029,7 +1025,7 @@ var LoaderPlugin = new Class({ * @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) + nextFile(file, success) { // Has the game been destroyed during load? If so, bail out now. if (!this.inflight) @@ -1061,7 +1057,7 @@ var LoaderPlugin = new Class({ this.fileProcessComplete(file); } - }, + } /** * An internal method that is called automatically by the File when it has finished processing. @@ -1075,7 +1071,7 @@ var LoaderPlugin = new Class({ * * @param {Phaser.Loader.File} file - The file that has finished processing. */ - fileProcessComplete: function (file) + fileProcessComplete(file) { // Has the game been destroyed during load? If so, bail out now. if (!this.scene || !this.systems || !this.systems.game || this.systems.game.pendingDestroy) @@ -1119,7 +1115,7 @@ var LoaderPlugin = new Class({ { this.loadComplete(); } - }, + } /** * Called at the end when the load queue is exhausted and all files have either loaded or errored. @@ -1132,7 +1128,7 @@ var LoaderPlugin = new Class({ * @fires Phaser.Loader.Events#POST_PROCESS * @since 3.7.0 */ - loadComplete: function () + loadComplete() { this.emit(Events.POST_PROCESS, this); @@ -1155,7 +1151,7 @@ var LoaderPlugin = new Class({ this._deleteQueue.clear(); this.emit(Events.COMPLETE, this, this.totalComplete, this.totalFailed); - }, + } /** * Adds a File into the pending-deletion queue. @@ -1165,10 +1161,10 @@ var LoaderPlugin = new Class({ * * @param {Phaser.Loader.File} file - The File to be queued for deletion when the Loader completes. */ - flagForRemoval: function (file) + flagForRemoval(file) { this._deleteQueue.add(file); - }, + } /** * Converts the given JSON data into a file that the browser then prompts you to download so you can save it locally. @@ -1183,10 +1179,10 @@ var LoaderPlugin = new Class({ * * @return {this} This Loader plugin. */ - saveJSON: function (data, filename) + saveJSON(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. @@ -1203,7 +1199,7 @@ var LoaderPlugin = new Class({ * * @return {this} This Loader plugin. */ - save: function (data, filename, filetype) + save(data, filename, filetype) { if (filename === undefined) { filename = 'file.json'; } if (filetype === undefined) { filetype = 'application/json'; } @@ -1220,7 +1216,7 @@ var LoaderPlugin = new Class({ a.click(); return this; - }, + } /** * Resets the Loader. @@ -1232,7 +1228,7 @@ var LoaderPlugin = new Class({ * @method Phaser.Loader.LoaderPlugin#reset * @since 3.0.0 */ - reset: function () + reset() { this.list.clear(); this.inflight.clear(); @@ -1246,7 +1242,7 @@ var LoaderPlugin = new Class({ this.setPrefix(GetFastValue(sceneConfig, 'prefix', gameConfig.loaderPrefix)); this.state = CONST.LOADER_IDLE; - }, + } /** * The Scene that owns this plugin is shutting down. @@ -1256,7 +1252,7 @@ var LoaderPlugin = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { this.reset(); @@ -1266,7 +1262,7 @@ var LoaderPlugin = new Class({ this.systems.events.off(SceneEvents.UPDATE, this.update, this); this.systems.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -1276,7 +1272,7 @@ var LoaderPlugin = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -1296,7 +1292,7 @@ var LoaderPlugin = new Class({ this.sceneManager = null; } -}); +}; PluginCache.register('Loader', LoaderPlugin, 'load'); diff --git a/src/loader/MultiFile.js b/src/loader/MultiFile.js index 28b1217bf8..29353287b1 100644 --- a/src/loader/MultiFile.js +++ b/src/loader/MultiFile.js @@ -25,11 +25,9 @@ var Events = require('./events'); * @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({ +var MultiFile = class { - initialize: - - function MultiFile (loader, type, key, files) + constructor(loader, type, key, files) { var finalFiles = []; @@ -178,7 +176,7 @@ var MultiFile = new Class({ { finalFiles[i].multiFile = this; } - }, + } /** * Checks if this MultiFile is ready to process its children or not. @@ -188,10 +186,10 @@ var MultiFile = new Class({ * * @return {boolean} `true` if all children of this MultiFile have loaded, otherwise `false`. */ - isReadyToProcess: function () + isReadyToProcess() { return (this.pending === 0 && this.failed === 0 && !this.complete); - }, + } /** * Adds another child to this MultiFile, increases the pending count and resets the completion status. @@ -203,7 +201,7 @@ var MultiFile = new Class({ * * @return {Phaser.Loader.MultiFile} This MultiFile instance. */ - addToMultiFile: function (file) + addToMultiFile(file) { this.files.push(file); @@ -214,7 +212,7 @@ var MultiFile = new Class({ this.complete = false; return this; - }, + } /** * Called by each File when it finishes loading. @@ -224,7 +222,7 @@ var MultiFile = new Class({ * * @param {Phaser.Loader.File} file - The File that has completed processing. */ - onFileComplete: function (file) + onFileComplete(file) { var index = this.files.indexOf(file); @@ -232,7 +230,7 @@ var MultiFile = new Class({ { this.pending--; } - }, + } /** * Called by each File that fails to load. @@ -242,7 +240,7 @@ var MultiFile = new Class({ * * @param {Phaser.Loader.File} file - The File that has failed to load. */ - onFileFailed: function (file) + onFileFailed(file) { var index = this.files.indexOf(file); @@ -253,7 +251,7 @@ var MultiFile = new Class({ // eslint-disable-next-line no-console console.error('File failed: %s "%s" (via %s "%s")', this.type, this.key, file.type, file.key); } - }, + } /** * Called once all children of this multi file have been added to their caches and is now @@ -266,7 +264,7 @@ var MultiFile = new Class({ * @fires Phaser.Loader.Events#FILE_KEY_COMPLETE * @since 3.60.0 */ - pendingDestroy: function () + pendingDestroy() { if (this.state === CONST.FILE_PENDING_DESTROY) { @@ -287,7 +285,7 @@ var MultiFile = new Class({ } this.state = CONST.FILE_PENDING_DESTROY; - }, + } /** * Destroy this Multi File and any references it holds. @@ -295,13 +293,13 @@ var MultiFile = new Class({ * @method Phaser.Loader.MultiFile#destroy * @since 3.60.0 */ - destroy: function () + destroy() { this.loader = null; this.files = null; this.config = null; } -}); +}; module.exports = MultiFile; diff --git a/src/loader/filetypes/AnimationJSONFile.js b/src/loader/filetypes/AnimationJSONFile.js index caea21a126..5b4e66208e 100644 --- a/src/loader/filetypes/AnimationJSONFile.js +++ b/src/loader/filetypes/AnimationJSONFile.js @@ -29,20 +29,16 @@ var LoaderEvents = require('../events'); * @param {Phaser.Types.Loader.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, +var AnimationJSONFile = class extends JSONFile { // 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 - initialize: - - function AnimationJSONFile (loader, key, url, xhrSettings, dataKey) + constructor(loader, key, url, xhrSettings, dataKey) { - JSONFile.call(this, loader, key, url, xhrSettings, dataKey); + super(loader, key, url, xhrSettings, dataKey); this.type = 'animationJSON'; - }, + } /** * Called automatically by Loader.nextFile. @@ -51,14 +47,14 @@ var AnimationJSONFile = new Class({ * @method Phaser.Loader.FileTypes.AnimationJSONFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { // We need to hook into this event: this.loader.once(LoaderEvents.POST_PROCESS, 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. @@ -66,12 +62,12 @@ var AnimationJSONFile = new Class({ * @method Phaser.Loader.FileTypes.AnimationJSONFile#onLoadComplete * @since 3.7.0 */ - onLoadComplete: function () + onLoadComplete() { this.loader.systems.anims.fromJSON(this.data); } -}); +}; /** * Adds an Animation JSON Data file, or array of Animation JSON files, to the current load queue. diff --git a/src/loader/filetypes/AsepriteFile.js b/src/loader/filetypes/AsepriteFile.js index 795c7155a6..fee9d4d61b 100644 --- a/src/loader/filetypes/AsepriteFile.js +++ b/src/loader/filetypes/AsepriteFile.js @@ -35,13 +35,9 @@ var MultiFile = require('../MultiFile'); * @param {Phaser.Types.Loader.XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. * @param {Phaser.Types.Loader.XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. */ -var AsepriteFile = new Class({ +var AsepriteFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function AsepriteFile (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) + constructor(loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) { var image; var data; @@ -76,13 +72,13 @@ var AsepriteFile = new Class({ if (image.linkFile) { // Image has a normal map - MultiFile.call(this, loader, 'atlasjson', key, [ image, data, image.linkFile ]); + super(loader, 'atlasjson', key, [ image, data, image.linkFile ]); } else { - MultiFile.call(this, loader, 'atlasjson', key, [ image, data ]); + super(loader, 'atlasjson', key, [ image, data ]); } - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -90,7 +86,7 @@ var AsepriteFile = new Class({ * @method Phaser.Loader.FileTypes.AsepriteFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { if (this.isReadyToProcess()) { @@ -106,7 +102,7 @@ var AsepriteFile = new Class({ } } -}); +}; /** * Aseprite is a powerful animated sprite editor and pixel art tool. diff --git a/src/loader/filetypes/AtlasJSONFile.js b/src/loader/filetypes/AtlasJSONFile.js index 9d3ac9e842..18d67e1f59 100644 --- a/src/loader/filetypes/AtlasJSONFile.js +++ b/src/loader/filetypes/AtlasJSONFile.js @@ -35,13 +35,9 @@ var MultiFile = require('../MultiFile'); * @param {Phaser.Types.Loader.XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. * @param {Phaser.Types.Loader.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({ +var AtlasJSONFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function AtlasJSONFile (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) + constructor(loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) { var image; var data; @@ -76,13 +72,13 @@ var AtlasJSONFile = new Class({ if (image.linkFile) { // Image has a normal map - MultiFile.call(this, loader, 'atlasjson', key, [ image, data, image.linkFile ]); + super(loader, 'atlasjson', key, [ image, data, image.linkFile ]); } else { - MultiFile.call(this, loader, 'atlasjson', key, [ image, data ]); + super(loader, 'atlasjson', key, [ image, data ]); } - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -90,7 +86,7 @@ var AtlasJSONFile = new Class({ * @method Phaser.Loader.FileTypes.AtlasJSONFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { if (this.isReadyToProcess()) { @@ -104,7 +100,7 @@ var AtlasJSONFile = new Class({ } } -}); +}; /** * Adds a JSON based Texture Atlas, or array of atlases, to the current load queue. diff --git a/src/loader/filetypes/AtlasXMLFile.js b/src/loader/filetypes/AtlasXMLFile.js index d86114e23e..98efb36f27 100644 --- a/src/loader/filetypes/AtlasXMLFile.js +++ b/src/loader/filetypes/AtlasXMLFile.js @@ -33,13 +33,9 @@ var XMLFile = require('./XMLFile'); * @param {Phaser.Types.Loader.XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. * @param {Phaser.Types.Loader.XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the atlas xml file. Used in replacement of the Loaders default XHR Settings. */ -var AtlasXMLFile = new Class({ +var AtlasXMLFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function AtlasXMLFile (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) + constructor(loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) { var image; var data; @@ -74,13 +70,13 @@ var AtlasXMLFile = new Class({ if (image.linkFile) { // Image has a normal map - MultiFile.call(this, loader, 'atlasxml', key, [ image, data, image.linkFile ]); + super(loader, 'atlasxml', key, [ image, data, image.linkFile ]); } else { - MultiFile.call(this, loader, 'atlasxml', key, [ image, data ]); + super(loader, 'atlasxml', key, [ image, data ]); } - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -88,7 +84,7 @@ var AtlasXMLFile = new Class({ * @method Phaser.Loader.FileTypes.AtlasXMLFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { if (this.isReadyToProcess()) { @@ -102,7 +98,7 @@ var AtlasXMLFile = new Class({ } } -}); +}; /** * Adds an XML based Texture Atlas, or array of atlases, to the current load queue. diff --git a/src/loader/filetypes/AudioFile.js b/src/loader/filetypes/AudioFile.js index 179993621b..8db98bb4d0 100644 --- a/src/loader/filetypes/AudioFile.js +++ b/src/loader/filetypes/AudioFile.js @@ -32,14 +32,10 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {Phaser.Types.Loader.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, +var AudioFile = class extends File { // URL is an object created by AudioFile.findAudioURL - initialize: - - function AudioFile (loader, key, urlConfig, xhrSettings, audioContext) + constructor(loader, key, urlConfig, xhrSettings, audioContext) { if (IsPlainObject(key)) { @@ -61,8 +57,8 @@ var AudioFile = new Class({ config: { context: audioContext } }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -71,7 +67,7 @@ var AudioFile = new Class({ * @method Phaser.Loader.FileTypes.AudioFile#onProcess * @since 3.0.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -97,7 +93,7 @@ var AudioFile = new Class({ this.config.context = null; } -}); +}; AudioFile.create = function (loader, key, urls, config, xhrSettings) { diff --git a/src/loader/filetypes/AudioSpriteFile.js b/src/loader/filetypes/AudioSpriteFile.js index f53b6c2071..4b20158d7a 100644 --- a/src/loader/filetypes/AudioSpriteFile.js +++ b/src/loader/filetypes/AudioSpriteFile.js @@ -34,13 +34,9 @@ var MultiFile = require('../MultiFile'); * @param {Phaser.Types.Loader.XHRSettingsObject} [audioXhrSettings] - An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings. * @param {Phaser.Types.Loader.XHRSettingsObject} [jsonXhrSettings] - An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings. */ -var AudioSpriteFile = new Class({ +var AudioSpriteFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function AudioSpriteFile (loader, key, jsonURL, audioURL, audioConfig, audioXhrSettings, jsonXhrSettings) + constructor(loader, key, jsonURL, audioURL, audioConfig, audioXhrSettings, jsonXhrSettings) { if (IsPlainObject(key)) { @@ -61,7 +57,7 @@ var AudioSpriteFile = new Class({ { data = new JSONFile(loader, key, jsonURL, jsonXhrSettings); - MultiFile.call(this, loader, 'audiosprite', key, [ data ]); + super(loader, 'audiosprite', key, [ data ]); this.config.resourceLoad = true; this.config.audioConfig = audioConfig; @@ -75,12 +71,12 @@ var AudioSpriteFile = new Class({ { data = new JSONFile(loader, key, jsonURL, jsonXhrSettings); - MultiFile.call(this, loader, 'audiosprite', key, [ audio, data ]); + super(loader, 'audiosprite', key, [ audio, data ]); this.config.resourceLoad = false; } } - }, + } /** * Called by each File when it finishes loading. @@ -90,7 +86,7 @@ var AudioSpriteFile = new Class({ * * @param {Phaser.Loader.File} file - The File that has completed processing. */ - onFileComplete: function (file) + onFileComplete(file) { var index = this.files.indexOf(file); @@ -116,7 +112,7 @@ var AudioSpriteFile = new Class({ } } } - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -124,7 +120,7 @@ var AudioSpriteFile = new Class({ * @method Phaser.Loader.FileTypes.AudioSpriteFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { if (this.isReadyToProcess()) { @@ -138,7 +134,7 @@ var AudioSpriteFile = new Class({ } } -}); +}; /** * Adds a JSON based Audio Sprite, or array of audio sprites, to the current load queue. diff --git a/src/loader/filetypes/BinaryFile.js b/src/loader/filetypes/BinaryFile.js index 7d6e4a455b..2ecd29ae5f 100644 --- a/src/loader/filetypes/BinaryFile.js +++ b/src/loader/filetypes/BinaryFile.js @@ -31,13 +31,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. * @param {any} [dataType] - Optional type to cast the binary file to once loaded. For example, `Uint8Array`. */ -var BinaryFile = new Class({ +var BinaryFile = class extends File { - Extends: File, - - initialize: - - function BinaryFile (loader, key, url, xhrSettings, dataType) + constructor(loader, key, url, xhrSettings, dataType) { var extension = 'bin'; @@ -63,8 +59,8 @@ var BinaryFile = new Class({ config: { dataType: dataType } }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -73,7 +69,7 @@ var BinaryFile = new Class({ * @method Phaser.Loader.FileTypes.BinaryFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -84,7 +80,7 @@ var BinaryFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds a Binary file, or array of Binary files, to the current load queue. diff --git a/src/loader/filetypes/BitmapFontFile.js b/src/loader/filetypes/BitmapFontFile.js index 1184a6c204..240181440d 100644 --- a/src/loader/filetypes/BitmapFontFile.js +++ b/src/loader/filetypes/BitmapFontFile.js @@ -34,13 +34,9 @@ var XMLFile = require('./XMLFile'); * @param {Phaser.Types.Loader.XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the font image file. Used in replacement of the Loaders default XHR Settings. * @param {Phaser.Types.Loader.XHRSettingsObject} [fontDataXhrSettings] - An XHR Settings configuration object for the font data xml file. Used in replacement of the Loaders default XHR Settings. */ -var BitmapFontFile = new Class({ +var BitmapFontFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function BitmapFontFile (loader, key, textureURL, fontDataURL, textureXhrSettings, fontDataXhrSettings) + constructor(loader, key, textureURL, fontDataURL, textureXhrSettings, fontDataXhrSettings) { var image; var data; @@ -75,13 +71,13 @@ var BitmapFontFile = new Class({ if (image.linkFile) { // Image has a normal map - MultiFile.call(this, loader, 'bitmapfont', key, [ image, data, image.linkFile ]); + super(loader, 'bitmapfont', key, [ image, data, image.linkFile ]); } else { - MultiFile.call(this, loader, 'bitmapfont', key, [ image, data ]); + super(loader, 'bitmapfont', key, [ image, data ]); } - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -89,7 +85,7 @@ var BitmapFontFile = new Class({ * @method Phaser.Loader.FileTypes.BitmapFontFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { if (this.isReadyToProcess()) { @@ -108,7 +104,7 @@ var BitmapFontFile = new Class({ } } -}); +}; /** * Adds an XML based Bitmap Font, or array of fonts, to the current load queue. diff --git a/src/loader/filetypes/CSSFile.js b/src/loader/filetypes/CSSFile.js index b70c5b73c8..7cc261d01b 100644 --- a/src/loader/filetypes/CSSFile.js +++ b/src/loader/filetypes/CSSFile.js @@ -30,13 +30,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @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 {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var CSSFile = new Class({ +var CSSFile = class extends File { - Extends: File, - - initialize: - - function CSSFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { var extension = 'css'; @@ -60,8 +56,8 @@ var CSSFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -70,7 +66,7 @@ var CSSFile = new Class({ * @method Phaser.Loader.FileTypes.CSSFile#onProcess * @since 3.17.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -83,7 +79,7 @@ var CSSFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds a CSS file, or array of CSS files, to the current load queue. diff --git a/src/loader/filetypes/CompressedTextureFile.js b/src/loader/filetypes/CompressedTextureFile.js index 95b0892159..21429fc621 100644 --- a/src/loader/filetypes/CompressedTextureFile.js +++ b/src/loader/filetypes/CompressedTextureFile.js @@ -38,13 +38,9 @@ var verifyCompressedTexture = require('../../textures/parsers/VerifyCompressedTe * @param {Phaser.Types.Loader.FileTypes.CompressedTextureFileEntry} entry - The compressed texture file entry to load. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var CompressedTextureFile = new Class({ +var CompressedTextureFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function CompressedTextureFile (loader, key, entry, xhrSettings) + constructor(loader, key, entry, xhrSettings) { if (entry.multiAtlasURL) { @@ -55,7 +51,7 @@ var CompressedTextureFile = new Class({ config: entry }); - MultiFile.call(this, loader, 'texture', key, [ multi ]); + super(loader, 'texture', key, [ multi ]); } else { @@ -83,16 +79,16 @@ var CompressedTextureFile = new Class({ config: entry }); - MultiFile.call(this, loader, 'texture', key, [ image, data ]); + super(loader, 'texture', key, [ image, data ]); } else { - MultiFile.call(this, loader, 'texture', key, [ image ]); + super(loader, 'texture', key, [ image ]); } } this.config = entry; - }, + } /** * Called by each File when it finishes loading. @@ -102,7 +98,7 @@ var CompressedTextureFile = new Class({ * * @param {Phaser.Loader.File} file - The File that has completed processing. */ - onFileComplete: function (file) + onFileComplete(file) { var index = this.files.indexOf(file); @@ -181,7 +177,7 @@ var CompressedTextureFile = new Class({ loader.setPrefix(currentPrefix); } } - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -189,7 +185,7 @@ var CompressedTextureFile = new Class({ * @method Phaser.Loader.FileTypes.CompressedTextureFile#addToCache * @since 3.60.0 */ - addToCache: function () + addToCache() { function compressionWarning (message) { @@ -252,7 +248,7 @@ var CompressedTextureFile = new Class({ this.complete = true; } - }, + } /** * Adds all of the multi-file entties to their target caches upon successful loading and processing. @@ -260,7 +256,7 @@ var CompressedTextureFile = new Class({ * @method Phaser.Loader.FileTypes.CompressedTextureFile#addMultiToCache * @since 3.60.0 */ - addMultiToCache: function () + addMultiToCache() { var entry = this.config; var json = this.files[0]; @@ -332,7 +328,7 @@ var CompressedTextureFile = new Class({ this.complete = true; } -}); +}; /** * Adds a Compressed Texture file to the current load queue. This feature is WebGL only. diff --git a/src/loader/filetypes/FontFile.js b/src/loader/filetypes/FontFile.js index 5faa21f5a7..087f988d75 100644 --- a/src/loader/filetypes/FontFile.js +++ b/src/loader/filetypes/FontFile.js @@ -33,13 +33,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {object} [descriptors] - An optional object containing font descriptors for the Font Face. See https://developer.mozilla.org/en-US/docs/Web/API/FontFace/FontFace#descriptors for more details. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var FontFile = new Class({ +var FontFile = class extends File { - Extends: File, - - initialize: - - function FontFile (loader, key, url, format, descriptors, xhrSettings) + constructor(loader, key, url, format, descriptors, xhrSettings) { var extension = 'ttf'; @@ -69,7 +65,7 @@ var FontFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); + super(loader, fileConfig); this.data = { format: format, @@ -77,7 +73,7 @@ var FontFile = new Class({ }; this.state = CONST.FILE_POPULATED; - }, + } /** * Called automatically by Loader.nextFile. @@ -86,7 +82,7 @@ var FontFile = new Class({ * @method Phaser.Loader.FileTypes.FontFile#onProcess * @since 3.87.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -122,7 +118,7 @@ var FontFile = new Class({ }); } -}); +}; /** * Adds a Font file, or array of Font files, to the current load queue. diff --git a/src/loader/filetypes/GLSLFile.js b/src/loader/filetypes/GLSLFile.js index 977c0ce5a6..4866ea27a3 100644 --- a/src/loader/filetypes/GLSLFile.js +++ b/src/loader/filetypes/GLSLFile.js @@ -31,13 +31,9 @@ var Shader = require('../../display/shader/BaseShader'); * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.glsl`, i.e. if `key` was "alien" then the URL will be "alien.glsl". * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var GLSLFile = new Class({ +var GLSLFile = class extends File { - Extends: File, - - initialize: - - function GLSLFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { var extension = 'glsl'; @@ -61,8 +57,8 @@ var GLSLFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -71,14 +67,14 @@ var GLSLFile = new Class({ * @method Phaser.Loader.FileTypes.GLSLFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; this.data = this.xhrLoader.responseText; this.onProcessComplete(); - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -86,11 +82,11 @@ var GLSLFile = new Class({ * @method Phaser.Loader.FileTypes.GLSLFile#addToCache * @since 3.17.0 */ - addToCache: function () + addToCache() { this.cache.add(this.key, new Shader(this.key, this.data)); } -}); +}; /** * Adds a GLSL file, or array of GLSL files, to the current load queue. diff --git a/src/loader/filetypes/HTML5AudioFile.js b/src/loader/filetypes/HTML5AudioFile.js index bff4ca60ca..936a1fd2df 100644 --- a/src/loader/filetypes/HTML5AudioFile.js +++ b/src/loader/filetypes/HTML5AudioFile.js @@ -30,13 +30,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {string} [urlConfig] - The absolute or relative URL to load this file from. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var HTML5AudioFile = new Class({ +var HTML5AudioFile = class extends File { - Extends: File, - - initialize: - - function HTML5AudioFile (loader, key, urlConfig, audioConfig) + constructor(loader, key, urlConfig, audioConfig) { if (IsPlainObject(key)) { @@ -55,14 +51,14 @@ var HTML5AudioFile = new Class({ config: audioConfig }; - File.call(this, loader, fileConfig); + super(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. @@ -70,7 +66,7 @@ var HTML5AudioFile = new Class({ * @method Phaser.Loader.FileTypes.HTML5AudioFile#onLoad * @since 3.0.0 */ - onLoad: function () + onLoad() { if (this.loaded) { @@ -80,7 +76,7 @@ var HTML5AudioFile = new Class({ this.loaded = true; this.loader.nextFile(this, true); - }, + } /** * Called if the file errors while loading. @@ -88,7 +84,7 @@ var HTML5AudioFile = new Class({ * @method Phaser.Loader.FileTypes.HTML5AudioFile#onError * @since 3.0.0 */ - onError: function () + onError() { for (var i = 0; i < this.data.length; i++) { @@ -99,7 +95,7 @@ var HTML5AudioFile = new Class({ } this.loader.nextFile(this, false); - }, + } /** * Called during the file load progress. Is sent a DOM ProgressEvent. @@ -108,7 +104,7 @@ var HTML5AudioFile = new Class({ * @fires Phaser.Loader.Events#FILE_PROGRESS * @since 3.0.0 */ - onProgress: function (event) + onProgress(event) { var audio = event.target; @@ -125,7 +121,7 @@ var HTML5AudioFile = new Class({ { this.onLoad(); } - }, + } /** * Called by the Loader, starts the actual file downloading. @@ -135,7 +131,7 @@ var HTML5AudioFile = new Class({ * @method Phaser.Loader.FileTypes.HTML5AudioFile#load * @since 3.0.0 */ - load: function () + load() { this.data = []; @@ -192,6 +188,6 @@ var HTML5AudioFile = new Class({ } } -}); +}; module.exports = HTML5AudioFile; diff --git a/src/loader/filetypes/HTMLFile.js b/src/loader/filetypes/HTMLFile.js index c6d112a69a..9dcc662358 100644 --- a/src/loader/filetypes/HTMLFile.js +++ b/src/loader/filetypes/HTMLFile.js @@ -30,13 +30,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.html`, i.e. if `key` was "alien" then the URL will be "alien.html". * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var HTMLFile = new Class({ +var HTMLFile = class extends File { - Extends: File, - - initialize: - - function HTMLFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { var extension = 'html'; @@ -60,8 +56,8 @@ var HTMLFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -70,7 +66,7 @@ var HTMLFile = new Class({ * @method Phaser.Loader.FileTypes.HTMLFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -79,7 +75,7 @@ var HTMLFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds an HTML file, or array of HTML files, to the current load queue. diff --git a/src/loader/filetypes/HTMLTextureFile.js b/src/loader/filetypes/HTMLTextureFile.js index a19293a2bd..63cf088746 100644 --- a/src/loader/filetypes/HTMLTextureFile.js +++ b/src/loader/filetypes/HTMLTextureFile.js @@ -32,13 +32,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {number} [height] - The height of the texture the HTML will be rendered to. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var HTMLTextureFile = new Class({ +var HTMLTextureFile = class extends File { - Extends: File, - - initialize: - - function HTMLTextureFile (loader, key, url, width, height, xhrSettings) + constructor(loader, key, url, width, height, xhrSettings) { if (width === undefined) { width = 512; } if (height === undefined) { height = 512; } @@ -71,8 +67,8 @@ var HTMLTextureFile = new Class({ } }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -81,7 +77,7 @@ var HTMLTextureFile = new Class({ * @method Phaser.Loader.FileTypes.HTMLTextureFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -133,7 +129,7 @@ var HTMLTextureFile = new Class({ }; File.createObjectURL(this.data, blob, 'image/svg+xml'); - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -141,12 +137,12 @@ var HTMLTextureFile = new Class({ * @method Phaser.Loader.FileTypes.HTMLTextureFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { this.cache.addImage(this.key, this.data); } -}); +}; /** * Adds an HTML File, or array of HTML Files, to the current load queue. When the files are loaded they diff --git a/src/loader/filetypes/ImageFile.js b/src/loader/filetypes/ImageFile.js index 229509061a..92ee7cc605 100644 --- a/src/loader/filetypes/ImageFile.js +++ b/src/loader/filetypes/ImageFile.js @@ -32,13 +32,9 @@ var GetURL = require('../GetURL'); * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. * @param {Phaser.Types.Loader.FileTypes.ImageFrameConfig} [frameConfig] - The frame configuration object. Only provided for, and used by, Sprite Sheets. */ -var ImageFile = new Class({ +var ImageFile = class extends File { - Extends: File, - - initialize: - - function ImageFile (loader, key, url, xhrSettings, frameConfig) + constructor(loader, key, url, xhrSettings, frameConfig) { var extension = 'png'; var normalMapURL; @@ -72,7 +68,7 @@ var ImageFile = new Class({ config: frameConfig }; - File.call(this, loader, fileConfig); + super(loader, fileConfig); // Do we have a normal map to load as well? if (normalMapURL) @@ -93,7 +89,7 @@ var ImageFile = new Class({ this.load = this.loadImage; this.onProcess = this.onProcessImage; } - }, + } /** * Called automatically by Loader.nextFile. @@ -102,7 +98,7 @@ var ImageFile = new Class({ * @method Phaser.Loader.FileTypes.ImageFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -127,7 +123,7 @@ var ImageFile = new Class({ }; File.createObjectURL(this.data, this.xhrLoader.response, 'image/png'); - }, + } /** * Handles image load processing. @@ -136,7 +132,7 @@ var ImageFile = new Class({ * @private * @since 3.60.0 */ - onProcessImage: function () + onProcessImage() { var result = this.state; @@ -150,7 +146,7 @@ var ImageFile = new Class({ { this.onProcessError(); } - }, + } /** * Loads the image using either XHR or an Image tag. @@ -159,7 +155,7 @@ var ImageFile = new Class({ * @private * @since 3.60.0 */ - loadImage: function () + loadImage() { this.state = CONST.FILE_LOADING; @@ -184,7 +180,7 @@ var ImageFile = new Class({ }; this.data.src = this.src; - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -192,7 +188,7 @@ var ImageFile = new Class({ * @method Phaser.Loader.FileTypes.ImageFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { // Check if we have a linked normal map var linkFile = this.linkFile; @@ -229,7 +225,7 @@ var ImageFile = new Class({ } } -}); +}; /** * Adds an Image, or array of Images, to the current load queue. diff --git a/src/loader/filetypes/JSONFile.js b/src/loader/filetypes/JSONFile.js index c7574a75b8..d047eff73d 100644 --- a/src/loader/filetypes/JSONFile.js +++ b/src/loader/filetypes/JSONFile.js @@ -32,15 +32,11 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {Phaser.Types.Loader.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, +var JSONFile = class extends File { // 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 - initialize: - - function JSONFile (loader, key, url, xhrSettings, dataKey) + constructor(loader, key, url, xhrSettings, dataKey) { var extension = 'json'; @@ -66,7 +62,7 @@ var JSONFile = new Class({ config: dataKey }; - File.call(this, loader, fileConfig); + super(loader, fileConfig); // A JSON object has been provided (instead of a URL), so we'll use it directly as the File.data. No need to load it. if (IsPlainObject(url)) @@ -82,7 +78,7 @@ var JSONFile = new Class({ this.state = CONST.FILE_POPULATED; } - }, + } /** * Called automatically by Loader.nextFile. @@ -91,7 +87,7 @@ var JSONFile = new Class({ * @method Phaser.Loader.FileTypes.JSONFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { if (this.state !== CONST.FILE_POPULATED) { @@ -123,7 +119,7 @@ var JSONFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds a JSON file, or array of JSON files, to the current load queue. diff --git a/src/loader/filetypes/MultiAtlasFile.js b/src/loader/filetypes/MultiAtlasFile.js index 602f84fc75..1f47e8c86b 100644 --- a/src/loader/filetypes/MultiAtlasFile.js +++ b/src/loader/filetypes/MultiAtlasFile.js @@ -34,13 +34,9 @@ var MultiFile = require('../MultiFile'); * @param {Phaser.Types.Loader.XHRSettingsObject} [atlasXhrSettings] - Extra XHR Settings specifically for the atlas json file. * @param {Phaser.Types.Loader.XHRSettingsObject} [textureXhrSettings] - Extra XHR Settings specifically for the texture files. */ -var MultiAtlasFile = new Class({ +var MultiAtlasFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function MultiAtlasFile (loader, key, atlasURL, path, baseURL, atlasXhrSettings, textureXhrSettings) + constructor(loader, key, atlasURL, path, baseURL, atlasXhrSettings, textureXhrSettings) { if (IsPlainObject(key)) { @@ -65,12 +61,12 @@ var MultiAtlasFile = new Class({ var data = new JSONFile(loader, key, atlasURL, atlasXhrSettings); - MultiFile.call(this, loader, 'multiatlas', key, [ data ]); + super(loader, 'multiatlas', key, [ data ]); this.config.path = path; this.config.baseURL = baseURL; this.config.textureXhrSettings = textureXhrSettings; - }, + } /** * Called by each File when it finishes loading. @@ -80,7 +76,7 @@ var MultiAtlasFile = new Class({ * * @param {Phaser.Loader.File} file - The File that has completed processing. */ - onFileComplete: function (file) + onFileComplete(file) { var index = this.files.indexOf(file); @@ -143,7 +139,7 @@ var MultiAtlasFile = new Class({ loader.setPrefix(currentPrefix); } } - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -151,7 +147,7 @@ var MultiAtlasFile = new Class({ * @method Phaser.Loader.FileTypes.MultiAtlasFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { if (this.isReadyToProcess()) { @@ -207,7 +203,7 @@ var MultiAtlasFile = new Class({ } } -}); +}; /** * Adds a Multi Texture Atlas, or array of multi atlases, to the current load queue. diff --git a/src/loader/filetypes/MultiScriptFile.js b/src/loader/filetypes/MultiScriptFile.js index 9ef4fc586b..80576689f4 100644 --- a/src/loader/filetypes/MultiScriptFile.js +++ b/src/loader/filetypes/MultiScriptFile.js @@ -30,13 +30,9 @@ var ScriptFile = require('./ScriptFile'); * @param {string[]} [url] - An array of absolute or relative URLs to load the script files from. They are processed in the order given in the array. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object for the script files. Used in replacement of the Loaders default XHR Settings. */ -var MultiScriptFile = new Class({ +var MultiScriptFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function MultiScriptFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { var extension = 'js'; var files = []; @@ -74,8 +70,8 @@ var MultiScriptFile = new Class({ files.push(scriptFile); } - MultiFile.call(this, loader, 'scripts', key, files); - }, + super(loader, 'scripts', key, files); + } /** * Adds this file to its target cache upon successful loading and processing. @@ -83,7 +79,7 @@ var MultiScriptFile = new Class({ * @method Phaser.Loader.FileTypes.MultiScriptFile#addToCache * @since 3.17.0 */ - addToCache: function () + addToCache() { if (this.isReadyToProcess()) { @@ -104,7 +100,7 @@ var MultiScriptFile = new Class({ } } -}); +}; /** * Adds an array of Script files to the current load queue. diff --git a/src/loader/filetypes/PackFile.js b/src/loader/filetypes/PackFile.js index 21c70ccd65..44084747ab 100644 --- a/src/loader/filetypes/PackFile.js +++ b/src/loader/filetypes/PackFile.js @@ -29,20 +29,16 @@ var JSONFile = require('./JSONFile'); * @param {Phaser.Types.Loader.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 PackFile = new Class({ - - Extends: JSONFile, +var PackFile = class extends JSONFile { // 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 - initialize: - - function PackFile (loader, key, url, xhrSettings, dataKey) + constructor(loader, key, url, xhrSettings, dataKey) { - JSONFile.call(this, loader, key, url, xhrSettings, dataKey); + super(loader, key, url, xhrSettings, dataKey); this.type = 'packfile'; - }, + } /** * Called automatically by Loader.nextFile. @@ -51,7 +47,7 @@ var PackFile = new Class({ * @method Phaser.Loader.FileTypes.PackFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { if (this.state !== CONST.FILE_POPULATED) { @@ -75,7 +71,7 @@ var PackFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds a JSON File Pack, or array of packs, to the current load queue. diff --git a/src/loader/filetypes/PluginFile.js b/src/loader/filetypes/PluginFile.js index 848b54792c..866e24db5b 100644 --- a/src/loader/filetypes/PluginFile.js +++ b/src/loader/filetypes/PluginFile.js @@ -32,13 +32,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {string} [mapping] - If this plugin is to be injected into the Scene, this is the property key used. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var PluginFile = new Class({ +var PluginFile = class extends File { - Extends: File, - - initialize: - - function PluginFile (loader, key, url, start, mapping, xhrSettings) + constructor(loader, key, url, start, mapping, xhrSettings) { var extension = 'js'; @@ -68,7 +64,7 @@ var PluginFile = new Class({ } }; - File.call(this, loader, fileConfig); + super(loader, fileConfig); // If the url variable refers to a class, add the plugin directly if (typeof url === 'function') @@ -77,7 +73,7 @@ var PluginFile = new Class({ this.state = CONST.FILE_POPULATED; } - }, + } /** * Called automatically by Loader.nextFile. @@ -86,7 +82,7 @@ var PluginFile = new Class({ * @method Phaser.Loader.FileTypes.PluginFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { var pluginManager = this.loader.systems.plugins; var config = this.config; @@ -124,7 +120,7 @@ var PluginFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds a Plugin Script file, or array of plugin files, to the current load queue. diff --git a/src/loader/filetypes/SVGFile.js b/src/loader/filetypes/SVGFile.js index 0e4ec229f0..5b54488c1c 100644 --- a/src/loader/filetypes/SVGFile.js +++ b/src/loader/filetypes/SVGFile.js @@ -31,13 +31,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {Phaser.Types.Loader.FileTypes.SVGSizeConfig} [svgConfig] - The svg size configuration object. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var SVGFile = new Class({ +var SVGFile = class extends File { - Extends: File, - - initialize: - - function SVGFile (loader, key, url, svgConfig, xhrSettings) + constructor(loader, key, url, svgConfig, xhrSettings) { var extension = 'svg'; @@ -67,8 +63,8 @@ var SVGFile = new Class({ } }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -77,7 +73,7 @@ var SVGFile = new Class({ * @method Phaser.Loader.FileTypes.SVGFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -177,7 +173,7 @@ var SVGFile = new Class({ }; File.createObjectURL(this.data, blob, 'image/svg+xml'); - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -185,12 +181,12 @@ var SVGFile = new Class({ * @method Phaser.Loader.FileTypes.SVGFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { this.cache.addImage(this.key, this.data); } -}); +}; /** * Adds an SVG File, or array of SVG Files, to the current load queue. When the files are loaded they diff --git a/src/loader/filetypes/SceneFile.js b/src/loader/filetypes/SceneFile.js index adc193f502..ee35956701 100644 --- a/src/loader/filetypes/SceneFile.js +++ b/src/loader/filetypes/SceneFile.js @@ -30,13 +30,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @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 {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var SceneFile = new Class({ +var SceneFile = class extends File { - Extends: File, - - initialize: - - function SceneFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { var extension = 'js'; @@ -59,8 +55,8 @@ var SceneFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -69,14 +65,14 @@ var SceneFile = new Class({ * @method Phaser.Loader.FileTypes.SceneFile#onProcess * @since 3.16.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; this.data = this.xhrLoader.responseText; this.onProcessComplete(); - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -84,7 +80,7 @@ var SceneFile = new Class({ * @method Phaser.Loader.FileTypes.SceneFile#addToCache * @since 3.16.0 */ - addToCache: function () + addToCache() { var code = this.data.concat('(function(){\n' + 'return new ' + this.key + '();\n' + '}).call(this);'); @@ -96,7 +92,7 @@ var SceneFile = new Class({ this.complete = true; } -}); +}; /** * Adds an external Scene file, or array of Scene files, to the current load queue. diff --git a/src/loader/filetypes/ScenePluginFile.js b/src/loader/filetypes/ScenePluginFile.js index 5ee50e3fa3..b3dc84d2de 100644 --- a/src/loader/filetypes/ScenePluginFile.js +++ b/src/loader/filetypes/ScenePluginFile.js @@ -32,13 +32,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {string} [sceneKey] - If this plugin is to be added to the Scene, this is the property key for it. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var ScenePluginFile = new Class({ +var ScenePluginFile = class extends File { - Extends: File, - - initialize: - - function ScenePluginFile (loader, key, url, systemKey, sceneKey, xhrSettings) + constructor(loader, key, url, systemKey, sceneKey, xhrSettings) { var extension = 'js'; @@ -68,7 +64,7 @@ var ScenePluginFile = new Class({ } }; - File.call(this, loader, fileConfig); + super(loader, fileConfig); // If the url variable refers to a class, add the plugin directly if (typeof url === 'function') @@ -77,7 +73,7 @@ var ScenePluginFile = new Class({ this.state = CONST.FILE_POPULATED; } - }, + } /** * Called automatically by Loader.nextFile. @@ -86,7 +82,7 @@ var ScenePluginFile = new Class({ * @method Phaser.Loader.FileTypes.ScenePluginFile#onProcess * @since 3.8.0 */ - onProcess: function () + onProcess() { var pluginManager = this.loader.systems.plugins; var config = this.config; @@ -118,7 +114,7 @@ var ScenePluginFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds a Scene Plugin Script file, or array of plugin files, to the current load queue. diff --git a/src/loader/filetypes/ScriptFile.js b/src/loader/filetypes/ScriptFile.js index 15916b7470..0a3ad5469a 100644 --- a/src/loader/filetypes/ScriptFile.js +++ b/src/loader/filetypes/ScriptFile.js @@ -31,13 +31,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {string} [type='script'] - The script type. Should be either 'script' for classic JavaScript, or 'module' if the file contains an exported module. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var ScriptFile = new Class({ +var ScriptFile = class extends File { - Extends: File, - - initialize: - - function ScriptFile (loader, key, url, type, xhrSettings) + constructor(loader, key, url, type, xhrSettings) { var extension = 'js'; @@ -66,8 +62,8 @@ var ScriptFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -76,7 +72,7 @@ var ScriptFile = new Class({ * @method Phaser.Loader.FileTypes.ScriptFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -91,7 +87,7 @@ var ScriptFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds a Script file, or array of Script files, to the current load queue. diff --git a/src/loader/filetypes/SpriteSheetFile.js b/src/loader/filetypes/SpriteSheetFile.js index c453e309f9..2eb838461c 100644 --- a/src/loader/filetypes/SpriteSheetFile.js +++ b/src/loader/filetypes/SpriteSheetFile.js @@ -29,18 +29,14 @@ var ImageFile = require('./ImageFile'); * @param {Phaser.Types.Loader.FileTypes.ImageFrameConfig} [frameConfig] - The frame configuration object. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var SpriteSheetFile = new Class({ +var SpriteSheetFile = class extends ImageFile { - Extends: ImageFile, - - initialize: - - function SpriteSheetFile (loader, key, url, frameConfig, xhrSettings) + constructor(loader, key, url, frameConfig, xhrSettings) { - ImageFile.call(this, loader, key, url, xhrSettings, frameConfig); + super(loader, key, url, xhrSettings, frameConfig); this.type = 'spritesheet'; - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -48,7 +44,7 @@ var SpriteSheetFile = new Class({ * @method Phaser.Loader.FileTypes.SpriteSheetFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { // Check if we have a linked normal map var linkFile = this.linkFile; @@ -82,7 +78,7 @@ var SpriteSheetFile = new Class({ } } -}); +}; /** * Adds a Sprite Sheet Image, or array of Sprite Sheet Images, to the current load queue. diff --git a/src/loader/filetypes/TextFile.js b/src/loader/filetypes/TextFile.js index 3138939794..5c18a1d559 100644 --- a/src/loader/filetypes/TextFile.js +++ b/src/loader/filetypes/TextFile.js @@ -30,13 +30,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @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 {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var TextFile = new Class({ +var TextFile = class extends File { - Extends: File, - - initialize: - - function TextFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { var type = 'text'; var extension = 'txt'; @@ -64,8 +60,8 @@ var TextFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -74,7 +70,7 @@ var TextFile = new Class({ * @method Phaser.Loader.FileTypes.TextFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -83,7 +79,7 @@ var TextFile = new Class({ this.onProcessComplete(); } -}); +}; /** * Adds a Text file, or array of Text files, to the current load queue. diff --git a/src/loader/filetypes/TilemapCSVFile.js b/src/loader/filetypes/TilemapCSVFile.js index ff06e892ab..4958f8c847 100644 --- a/src/loader/filetypes/TilemapCSVFile.js +++ b/src/loader/filetypes/TilemapCSVFile.js @@ -31,13 +31,9 @@ var TILEMAP_FORMATS = require('../../tilemaps/Formats'); * @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.csv`, i.e. if `key` was "alien" then the URL will be "alien.csv". * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var TilemapCSVFile = new Class({ +var TilemapCSVFile = class extends File { - Extends: File, - - initialize: - - function TilemapCSVFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { var extension = 'csv'; @@ -61,10 +57,10 @@ var TilemapCSVFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); + super(loader, fileConfig); this.tilemapFormat = TILEMAP_FORMATS.CSV; - }, + } /** * Called automatically by Loader.nextFile. @@ -73,14 +69,14 @@ var TilemapCSVFile = new Class({ * @method Phaser.Loader.FileTypes.TilemapCSVFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; this.data = this.xhrLoader.responseText; this.onProcessComplete(); - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -88,14 +84,14 @@ var TilemapCSVFile = new Class({ * @method Phaser.Loader.FileTypes.TilemapCSVFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { var tiledata = { format: this.tilemapFormat, data: this.data }; this.cache.add(this.key, tiledata); } -}); +}; /** * Adds a CSV Tilemap file, or array of CSV files, to the current load queue. diff --git a/src/loader/filetypes/TilemapImpactFile.js b/src/loader/filetypes/TilemapImpactFile.js index e3ea4efbf6..8e893155b6 100644 --- a/src/loader/filetypes/TilemapImpactFile.js +++ b/src/loader/filetypes/TilemapImpactFile.js @@ -28,20 +28,16 @@ var TILEMAP_FORMATS = require('../../tilemaps/Formats'); * @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 {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var TilemapImpactFile = new Class({ +var TilemapImpactFile = class extends JSONFile { - Extends: JSONFile, - - initialize: - - function TilemapImpactFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { - JSONFile.call(this, loader, key, url, xhrSettings); + super(loader, key, url, xhrSettings); this.type = 'tilemapJSON'; this.cache = loader.cacheManager.tilemap; - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -49,14 +45,14 @@ var TilemapImpactFile = new Class({ * @method Phaser.Loader.FileTypes.TilemapImpactFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { var tiledata = { format: TILEMAP_FORMATS.WELTMEISTER, data: this.data }; this.cache.add(this.key, tiledata); } -}); +}; /** * Adds an Impact.js Tilemap file, or array of map files, to the current load queue. diff --git a/src/loader/filetypes/TilemapJSONFile.js b/src/loader/filetypes/TilemapJSONFile.js index fccdaa508f..9f1f38d5d8 100644 --- a/src/loader/filetypes/TilemapJSONFile.js +++ b/src/loader/filetypes/TilemapJSONFile.js @@ -28,20 +28,16 @@ var TILEMAP_FORMATS = require('../../tilemaps/Formats'); * @param {object|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". Or, a well formed JSON object. * @param {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var TilemapJSONFile = new Class({ +var TilemapJSONFile = class extends JSONFile { - Extends: JSONFile, - - initialize: - - function TilemapJSONFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { - JSONFile.call(this, loader, key, url, xhrSettings); + super(loader, key, url, xhrSettings); this.type = 'tilemapJSON'; this.cache = loader.cacheManager.tilemap; - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -49,14 +45,14 @@ var TilemapJSONFile = new Class({ * @method Phaser.Loader.FileTypes.TilemapJSONFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { var tiledata = { format: TILEMAP_FORMATS.TILED_JSON, data: this.data }; this.cache.add(this.key, tiledata); } -}); +}; /** * Adds a Tiled JSON Tilemap file, or array of map files, to the current load queue. diff --git a/src/loader/filetypes/UnityAtlasFile.js b/src/loader/filetypes/UnityAtlasFile.js index 3ef0598224..1f7c481d64 100644 --- a/src/loader/filetypes/UnityAtlasFile.js +++ b/src/loader/filetypes/UnityAtlasFile.js @@ -33,13 +33,9 @@ var TextFile = require('./TextFile'); * @param {Phaser.Types.Loader.XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. * @param {Phaser.Types.Loader.XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the atlas data file. Used in replacement of the Loaders default XHR Settings. */ -var UnityAtlasFile = new Class({ +var UnityAtlasFile = class extends MultiFile { - Extends: MultiFile, - - initialize: - - function UnityAtlasFile (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) + constructor(loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings) { var image; var data; @@ -74,13 +70,13 @@ var UnityAtlasFile = new Class({ if (image.linkFile) { // Image has a normal map - MultiFile.call(this, loader, 'unityatlas', key, [ image, data, image.linkFile ]); + super(loader, 'unityatlas', key, [ image, data, image.linkFile ]); } else { - MultiFile.call(this, loader, 'unityatlas', key, [ image, data ]); + super(loader, 'unityatlas', key, [ image, data ]); } - }, + } /** * Adds this file to its target cache upon successful loading and processing. @@ -88,7 +84,7 @@ var UnityAtlasFile = new Class({ * @method Phaser.Loader.FileTypes.UnityAtlasFile#addToCache * @since 3.7.0 */ - addToCache: function () + addToCache() { if (this.isReadyToProcess()) { @@ -102,7 +98,7 @@ var UnityAtlasFile = new Class({ } } -}); +}; /** * Adds a Unity YAML based Texture Atlas, or array of atlases, to the current load queue. diff --git a/src/loader/filetypes/VideoFile.js b/src/loader/filetypes/VideoFile.js index bb4075370f..0fe71800d2 100644 --- a/src/loader/filetypes/VideoFile.js +++ b/src/loader/filetypes/VideoFile.js @@ -31,13 +31,9 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {(string|string[]|Phaser.Types.Loader.FileTypes.VideoFileURLConfig|Phaser.Types.Loader.FileTypes.VideoFileURLConfig[])} [urls] - The absolute or relative URL to load the video files from. * @param {boolean} [noAudio=false] - Does the video have an audio track? If not you can enable auto-playing on it. */ -var VideoFile = new Class({ +var VideoFile = class extends File { - Extends: File, - - initialize: - - function VideoFile (loader, key, url, noAudio) + constructor(loader, key, url, noAudio) { if (noAudio === undefined) { noAudio = false; } @@ -68,8 +64,8 @@ var VideoFile = new Class({ } }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -78,7 +74,7 @@ var VideoFile = new Class({ * @method Phaser.Loader.FileTypes.VideoFile#onProcess * @since 3.20.0 */ - onProcess: function () + onProcess() { this.data = { url: this.src, @@ -87,7 +83,7 @@ var VideoFile = new Class({ }; this.onProcessComplete(); - }, + } /** * Called by the Loader, starts the actual file downloading. @@ -97,7 +93,7 @@ var VideoFile = new Class({ * @method Phaser.Loader.FileTypes.VideoFile#load * @since 3.20.0 */ - load: function () + load() { // We set these, but we don't actually load anything (the Video Game Object does that) @@ -108,7 +104,7 @@ var VideoFile = new Class({ this.loader.nextFile(this, true); } -}); +}; /** * Adds a Video file, or array of video files, to the current load queue. diff --git a/src/loader/filetypes/XMLFile.js b/src/loader/filetypes/XMLFile.js index e354ff0ce4..e5a0db9bf8 100644 --- a/src/loader/filetypes/XMLFile.js +++ b/src/loader/filetypes/XMLFile.js @@ -31,13 +31,9 @@ var ParseXML = require('../../dom/ParseXML'); * @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 {Phaser.Types.Loader.XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file. */ -var XMLFile = new Class({ +var XMLFile = class extends File { - Extends: File, - - initialize: - - function XMLFile (loader, key, url, xhrSettings) + constructor(loader, key, url, xhrSettings) { var extension = 'xml'; @@ -61,8 +57,8 @@ var XMLFile = new Class({ xhrSettings: xhrSettings }; - File.call(this, loader, fileConfig); - }, + super(loader, fileConfig); + } /** * Called automatically by Loader.nextFile. @@ -71,7 +67,7 @@ var XMLFile = new Class({ * @method Phaser.Loader.FileTypes.XMLFile#onProcess * @since 3.7.0 */ - onProcess: function () + onProcess() { this.state = CONST.FILE_PROCESSING; @@ -87,7 +83,7 @@ var XMLFile = new Class({ } } -}); +}; /** * Adds an XML file, or array of XML files, to the current load queue. diff --git a/src/math/Euler.js b/src/math/Euler.js index e11f24bf2b..7eb89e287c 100644 --- a/src/math/Euler.js +++ b/src/math/Euler.js @@ -23,11 +23,9 @@ var tempMatrix = new Matrix4(); * @param {number} [y] - The y component. * @param {number} [z] - The z component. */ -var Euler = new Class({ +var Euler = class { - initialize: - - function Euler (x, y, z, order) + constructor(x, y, z, order) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -40,65 +38,61 @@ var Euler = new Class({ this._order = order; this.onChangeCallback = NOOP; - }, + } - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - this._x = value; + get x() + { + return this._x; + } - this.onChangeCallback(this); - } - }, + set x(value) + { + this._x = value; - y: { - get: function () - { - return this._y; - }, + this.onChangeCallback(this); + } - set: function (value) - { - this._y = value; - this.onChangeCallback(this); - } - }, + get y() + { + return this._y; + } - z: { - get: function () - { - return this._z; - }, + set y(value) + { + this._y = value; - set: function (value) - { - this._z = value; + this.onChangeCallback(this); + } - this.onChangeCallback(this); - } - }, - order: { - get: function () - { - return this._order; - }, + get z() + { + return this._z; + } - set: function (value) - { - this._order = value; + set z(value) + { + this._z = value; + + this.onChangeCallback(this); + } - this.onChangeCallback(this); - } - }, - set: function (x, y, z, order) + get order() + { + return this._order; + } + + set order(value) + { + this._order = value; + + this.onChangeCallback(this); + } + + set(x, y, z, order) { if (order === undefined) { order = this._order; } @@ -110,14 +104,14 @@ var Euler = new Class({ this.onChangeCallback(this); return this; - }, + } - copy: function (euler) + copy(euler) { return this.set(euler.x, euler.y, euler.z, euler.order); - }, + } - setFromQuaternion: function (quaternion, order, update) + setFromQuaternion(quaternion, order, update) { if (order === undefined) { order = this._order; } if (update === undefined) { update = false; } @@ -125,9 +119,9 @@ var Euler = new Class({ tempMatrix.fromQuat(quaternion); return this.setFromRotationMatrix(tempMatrix, order, update); - }, + } - setFromRotationMatrix: function (matrix, order, update) + setFromRotationMatrix(matrix, order, update) { if (order === undefined) { order = this._order; } if (update === undefined) { update = false; } @@ -268,7 +262,7 @@ var Euler = new Class({ return this; } -}); +}; Euler.RotationOrders = [ 'XYZ', 'YXZ', 'ZXY', 'ZYX', 'YZX', 'XZY' ]; diff --git a/src/math/Matrix3.js b/src/math/Matrix3.js index 16dda4f46f..6f5f9bda2c 100644 --- a/src/math/Matrix3.js +++ b/src/math/Matrix3.js @@ -22,11 +22,9 @@ var Class = require('../utils/Class'); * * @param {Phaser.Math.Matrix3} [m] - Optional Matrix3 to copy values from. */ -var Matrix3 = new Class({ +var Matrix3 = class { - initialize: - - function Matrix3 (m) + constructor(m) { /** * The matrix values. @@ -47,7 +45,7 @@ var Matrix3 = new Class({ // Default to identity this.identity(); } - }, + } /** * Make a clone of this Matrix3. @@ -57,10 +55,10 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} A clone of this Matrix3. */ - clone: function () + clone() { return new Matrix3(this); - }, + } /** * This method is an alias for `Matrix3.copy`. @@ -72,10 +70,10 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - set: function (src) + set(src) { return this.copy(src); - }, + } /** * Copy the values of a given Matrix into this Matrix. @@ -87,7 +85,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - copy: function (src) + copy(src) { var out = this.val; var a = src.val; @@ -103,7 +101,7 @@ var Matrix3 = new Class({ out[8] = a[8]; return this; - }, + } /** * Copy the values of a given Matrix4 into this Matrix3. @@ -115,7 +113,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - fromMat4: function (m) + fromMat4(m) { var a = m.val; var out = this.val; @@ -131,7 +129,7 @@ var Matrix3 = new Class({ out[8] = a[10]; return this; - }, + } /** * Set the values of this Matrix from the given array. @@ -143,7 +141,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - fromArray: function (a) + fromArray(a) { var out = this.val; @@ -158,7 +156,7 @@ var Matrix3 = new Class({ out[8] = a[8]; return this; - }, + } /** * Reset this Matrix to an identity (default) matrix. @@ -168,7 +166,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - identity: function () + identity() { var out = this.val; @@ -183,7 +181,7 @@ var Matrix3 = new Class({ out[8] = 1; return this; - }, + } /** * Transpose this Matrix. @@ -193,7 +191,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - transpose: function () + transpose() { var a = this.val; var a01 = a[1]; @@ -208,7 +206,7 @@ var Matrix3 = new Class({ a[7] = a12; return this; - }, + } /** * Invert this Matrix. @@ -218,7 +216,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - invert: function () + invert() { var a = this.val; @@ -257,7 +255,7 @@ var Matrix3 = new Class({ a[8] = (a11 * a00 - a01 * a10) * det; return this; - }, + } /** * Calculate the adjoint, or adjugate, of this Matrix. @@ -267,7 +265,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - adjoint: function () + adjoint() { var a = this.val; @@ -292,7 +290,7 @@ var Matrix3 = new Class({ a[8] = (a00 * a11 - a01 * a10); return this; - }, + } /** * Calculate the determinant of this Matrix. @@ -302,7 +300,7 @@ var Matrix3 = new Class({ * * @return {number} The determinant of this Matrix. */ - determinant: function () + determinant() { var a = this.val; @@ -317,7 +315,7 @@ var Matrix3 = new Class({ var a22 = a[8]; return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); - }, + } /** * Multiply this Matrix by the given Matrix. @@ -329,7 +327,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - multiply: function (src) + multiply(src) { var a = this.val; @@ -368,7 +366,7 @@ var Matrix3 = new Class({ a[8] = b20 * a02 + b21 * a12 + b22 * a22; return this; - }, + } /** * Translate this Matrix using the given Vector. @@ -380,7 +378,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - translate: function (v) + translate(v) { var a = this.val; var x = v.x; @@ -391,7 +389,7 @@ var Matrix3 = new Class({ a[8] = x * a[2] + y * a[5] + a[8]; return this; - }, + } /** * Apply a rotation transformation to this Matrix. @@ -403,7 +401,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - rotate: function (rad) + rotate(rad) { var a = this.val; @@ -426,7 +424,7 @@ var Matrix3 = new Class({ a[5] = c * a12 - s * a02; return this; - }, + } /** * Apply a scale transformation to this Matrix. @@ -440,7 +438,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - scale: function (v) + scale(v) { var a = this.val; var x = v.x; @@ -455,7 +453,7 @@ var Matrix3 = new Class({ a[5] = y * a[5]; return this; - }, + } /** * Set the values of this Matrix from the given Quaternion. @@ -467,7 +465,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - fromQuat: function (q) + fromQuat(q) { var x = q.x; var y = q.y; @@ -505,7 +503,7 @@ var Matrix3 = new Class({ out[8] = 1 - (xx + yy); return this; - }, + } /** * Set the values of this Matrix3 to be normalized from the given Matrix4. @@ -517,7 +515,7 @@ var Matrix3 = new Class({ * * @return {Phaser.Math.Matrix3} This Matrix3. */ - normalFromMat4: function (m) + normalFromMat4(m) { var a = m.val; var out = this.val; @@ -582,6 +580,6 @@ var Matrix3 = new Class({ return this; } -}); +}; module.exports = Matrix3; diff --git a/src/math/Matrix4.js b/src/math/Matrix4.js index 8c7a0f9922..fe4dfa9532 100644 --- a/src/math/Matrix4.js +++ b/src/math/Matrix4.js @@ -26,11 +26,9 @@ var EPSILON = 0.000001; * * @param {Phaser.Math.Matrix4} [m] - Optional Matrix4 to copy values from. */ -var Matrix4 = new Class({ +var Matrix4 = class { - initialize: - - function Matrix4 (m) + constructor(m) { /** * The matrix values. @@ -51,7 +49,7 @@ var Matrix4 = new Class({ // Default to identity this.identity(); } - }, + } /** * Make a clone of this Matrix4. @@ -61,10 +59,10 @@ var Matrix4 = new Class({ * * @return {Phaser.Math.Matrix4} A clone of this Matrix4. */ - clone: function () + clone() { return new Matrix4(this); - }, + } /** * This method is an alias for `Matrix4.copy`. @@ -76,10 +74,10 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - set: function (src) + set(src) { return this.copy(src); - }, + } /** * Sets all values of this Matrix4. @@ -106,7 +104,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4 instance. */ - setValues: function (m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) + setValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) { var out = this.val; @@ -128,7 +126,7 @@ var Matrix4 = new Class({ out[15] = m33; return this; - }, + } /** * Copy the values of a given Matrix into this Matrix. @@ -140,12 +138,12 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - copy: function (src) + copy(src) { var a = src.val; return this.setValues(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]); - }, + } /** * Set the values of this Matrix from the given array. @@ -157,10 +155,10 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - fromArray: function (a) + fromArray(a) { return this.setValues(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]); - }, + } /** * Reset this Matrix. @@ -172,10 +170,10 @@ var Matrix4 = new Class({ * * @return {Phaser.Math.Matrix4} This Matrix4. */ - zero: function () + zero() { return this.setValues(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - }, + } /** * Generates a transform matrix based on the given position, scale and rotation. @@ -189,7 +187,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - transform: function (position, scale, rotation) + transform(position, scale, rotation) { var rotMatrix = _tempMat1.fromQuat(rotation); @@ -220,7 +218,7 @@ var Matrix4 = new Class({ position.z, 1 ); - }, + } /** * Set the `x`, `y` and `z` values of this Matrix. @@ -234,7 +232,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - xyz: function (x, y, z) + xyz(x, y, z) { this.identity(); @@ -245,7 +243,7 @@ var Matrix4 = new Class({ out[14] = z; return this; - }, + } /** * Set the scaling values of this Matrix. @@ -259,7 +257,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - scaling: function (x, y, z) + scaling(x, y, z) { this.zero(); @@ -271,7 +269,7 @@ var Matrix4 = new Class({ out[15] = 1; return this; - }, + } /** * Reset this Matrix to an identity (default) matrix. @@ -281,10 +279,10 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - identity: function () + identity() { return this.setValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); - }, + } /** * Transpose this Matrix. @@ -294,7 +292,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - transpose: function () + transpose() { var a = this.val; @@ -319,7 +317,7 @@ var Matrix4 = new Class({ a[14] = a23; return this; - }, + } /** * Copies the given Matrix4 into this Matrix and then inverses it. @@ -331,12 +329,12 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - getInverse: function (m) + getInverse(m) { this.copy(m); return this.invert(); - }, + } /** * Invert this Matrix. @@ -346,7 +344,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - invert: function () + invert() { var a = this.val; @@ -413,7 +411,7 @@ var Matrix4 = new Class({ (a31 * b01 - a30 * b03 - a32 * b00) * det, (a20 * b03 - a21 * b01 + a22 * b00) * det ); - }, + } /** * Calculate the adjoint, or adjugate, of this Matrix. @@ -423,7 +421,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - adjoint: function () + adjoint() { var a = this.val; @@ -465,7 +463,7 @@ var Matrix4 = new Class({ -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11)), (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11)) ); - }, + } /** * Calculate the determinant of this Matrix. @@ -475,7 +473,7 @@ var Matrix4 = new Class({ * * @return {number} The determinant of this Matrix. */ - determinant: function () + determinant() { var a = this.val; @@ -514,7 +512,7 @@ var Matrix4 = new Class({ // Calculate the determinant return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; - }, + } /** * Multiply this Matrix by the given Matrix. @@ -526,7 +524,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - multiply: function (src) + multiply(src) { var a = this.val; @@ -594,7 +592,7 @@ var Matrix4 = new Class({ a[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33; return this; - }, + } /** * Multiply the values of this Matrix4 by those given in the `src` argument. @@ -606,7 +604,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - multiplyLocal: function (src) + multiplyLocal(src) { var a = this.val; var b = src.val; @@ -632,7 +630,7 @@ var Matrix4 = new Class({ a[12] * b[2] + a[13] * b[6] + a[14] * b[10] + a[15] * b[14], a[12] * b[3] + a[13] * b[7] + a[14] * b[11] + a[15] * b[15] ); - }, + } /** * Multiplies the given Matrix4 object with this Matrix. @@ -646,10 +644,10 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - premultiply: function (m) + premultiply(m) { return this.multiplyMatrices(m, this); - }, + } /** * Multiplies the two given Matrix4 objects and stores the results in this Matrix. @@ -662,7 +660,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - multiplyMatrices: function (a, b) + multiplyMatrices(a, b) { var am = a.val; var bm = b.val; @@ -719,7 +717,7 @@ var Matrix4 = new Class({ a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44, a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44 ); - }, + } /** * Translate this Matrix using the given Vector. @@ -731,10 +729,10 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - translate: function (v) + translate(v) { return this.translateXYZ(v.x, v.y, v.z); - }, + } /** * Translate this Matrix using the given values. @@ -748,7 +746,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - translateXYZ: function (x, y, z) + translateXYZ(x, y, z) { var a = this.val; @@ -758,7 +756,7 @@ var Matrix4 = new Class({ a[15] = a[3] * x + a[7] * y + a[11] * z + a[15]; return this; - }, + } /** * Apply a scale transformation to this Matrix. @@ -772,10 +770,10 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - scale: function (v) + scale(v) { return this.scaleXYZ(v.x, v.y, v.z); - }, + } /** * Apply a scale transformation to this Matrix. @@ -789,7 +787,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - scaleXYZ: function (x, y, z) + scaleXYZ(x, y, z) { var a = this.val; @@ -809,7 +807,7 @@ var Matrix4 = new Class({ a[11] = a[11] * z; return this; - }, + } /** * Derive a rotation matrix around the given axis. @@ -822,7 +820,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - makeRotationAxis: function (axis, angle) + makeRotationAxis(axis, angle) { // Based on http://www.gamedev.net/reference/articles/article1199.asp @@ -841,7 +839,7 @@ var Matrix4 = new Class({ tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1 ); - }, + } /** * Apply a rotation transformation to this Matrix. @@ -854,7 +852,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - rotate: function (rad, axis) + rotate(rad, axis) { var a = this.val; var x = axis.x; @@ -925,7 +923,7 @@ var Matrix4 = new Class({ a03 * b20 + a13 * b21 + a23 * b22, a30, a31, a32, a33 ); - }, + } /** * Rotate this matrix on its X axis. @@ -937,7 +935,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - rotateX: function (rad) + rotateX(rad) { var a = this.val; var s = Math.sin(rad); @@ -964,7 +962,7 @@ var Matrix4 = new Class({ a[11] = a23 * c - a13 * s; return this; - }, + } /** * Rotate this matrix on its Y axis. @@ -976,7 +974,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - rotateY: function (rad) + rotateY(rad) { var a = this.val; var s = Math.sin(rad); @@ -1003,7 +1001,7 @@ var Matrix4 = new Class({ a[11] = a03 * s + a23 * c; return this; - }, + } /** * Rotate this matrix on its Z axis. @@ -1015,7 +1013,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - rotateZ: function (rad) + rotateZ(rad) { var a = this.val; var s = Math.sin(rad); @@ -1042,7 +1040,7 @@ var Matrix4 = new Class({ a[7] = a13 * c - a03 * s; return this; - }, + } /** * Set the values of this Matrix from the given rotation Quaternion and translation Vector. @@ -1055,7 +1053,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - fromRotationTranslation: function (q, v) + fromRotationTranslation(q, v) { // Quaternion math var x = q.x; @@ -1100,7 +1098,7 @@ var Matrix4 = new Class({ v.z, 1 ); - }, + } /** * Set the values of this Matrix from the given Quaternion. @@ -1112,7 +1110,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - fromQuat: function (q) + fromQuat(q) { var x = q.x; var y = q.y; @@ -1156,7 +1154,7 @@ var Matrix4 = new Class({ 0, 1 ); - }, + } /** * Generate a frustum matrix with the given bounds. @@ -1173,7 +1171,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - frustum: function (left, right, bottom, top, near, far) + frustum(left, right, bottom, top, near, far) { var rl = 1 / (right - left); var tb = 1 / (top - bottom); @@ -1200,7 +1198,7 @@ var Matrix4 = new Class({ (far * near * 2) * nf, 0 ); - }, + } /** * Generate a perspective projection matrix with the given bounds. @@ -1215,7 +1213,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - perspective: function (fovy, aspect, near, far) + perspective(fovy, aspect, near, far) { var f = 1.0 / Math.tan(fovy / 2); var nf = 1 / (near - far); @@ -1241,7 +1239,7 @@ var Matrix4 = new Class({ (2 * far * near) * nf, 0 ); - }, + } /** * Generate a perspective projection matrix with the given bounds. @@ -1256,7 +1254,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - perspectiveLH: function (width, height, near, far) + perspectiveLH(width, height, near, far) { return this.setValues( (2 * near) / width, @@ -1279,7 +1277,7 @@ var Matrix4 = new Class({ (near * far) / (near - far), 0 ); - }, + } /** * Generate an orthogonal projection matrix with the given bounds. @@ -1296,7 +1294,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - ortho: function (left, right, bottom, top, near, far) + ortho(left, right, bottom, top, near, far) { var lr = left - right; var bt = bottom - top; @@ -1328,7 +1326,7 @@ var Matrix4 = new Class({ (far + near) * nf, 1 ); - }, + } /** * Generate a right-handed look-at matrix with the given eye position, target and up axis. @@ -1342,7 +1340,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - lookAtRH: function (eye, target, up) + lookAtRH(eye, target, up) { var m = this.val; @@ -1388,7 +1386,7 @@ var Matrix4 = new Class({ m[10] = _z.z; return this; - }, + } /** * Generate a look-at matrix with the given eye position, focal point, and up axis. @@ -1402,7 +1400,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - lookAt: function (eye, center, up) + lookAt(eye, center, up) { var eyex = eye.x; var eyey = eye.y; @@ -1494,7 +1492,7 @@ var Matrix4 = new Class({ -(z0 * eyex + z1 * eyey + z2 * eyez), 1 ); - }, + } /** * Set the values of this matrix from the given `yaw`, `pitch` and `roll` values. @@ -1508,7 +1506,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - yawPitchRoll: function (yaw, pitch, roll) + yawPitchRoll(yaw, pitch, roll) { this.zero(); _tempMat1.zero(); @@ -1555,7 +1553,7 @@ var Matrix4 = new Class({ this.multiplyLocal(_tempMat2); return this; - }, + } /** * Generate a world matrix from the given rotation, position, scale, view matrix and projection matrix. @@ -1571,7 +1569,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - setWorldMatrix: function (rotation, position, scale, viewMatrix, projectionMatrix) + setWorldMatrix(rotation, position, scale, viewMatrix, projectionMatrix) { this.yawPitchRoll(rotation.y, rotation.x, rotation.z); @@ -1592,7 +1590,7 @@ var Matrix4 = new Class({ } return this; - }, + } /** * Multiplies this Matrix4 by the given `src` Matrix4 and stores the results in the `out` Matrix4. @@ -1605,7 +1603,7 @@ var Matrix4 = new Class({ * * @return {Phaser.Math.Matrix4} This `out` Matrix4. */ - multiplyToMat4: function (src, out) + multiplyToMat4(src, out) { var a = this.val; var b = src.val; @@ -1665,7 +1663,7 @@ var Matrix4 = new Class({ b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32, b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33 ); - }, + } /** * Takes the rotation and position vectors and builds this Matrix4 from them. @@ -1679,7 +1677,7 @@ var Matrix4 = new Class({ * * @return {this} This Matrix4. */ - fromRotationXYTranslation: function (rotation, position, translateFirst) + fromRotationXYTranslation(rotation, position, translateFirst) { var x = position.x; var y = position.y; @@ -1736,7 +1734,7 @@ var Matrix4 = new Class({ a32, 1 ); - }, + } /** * Returns the maximum axis scale from this Matrix4. @@ -1746,7 +1744,7 @@ var Matrix4 = new Class({ * * @return {number} The maximum axis scale. */ - getMaxScaleOnAxis: function () + getMaxScaleOnAxis() { var m = this.val; @@ -1757,7 +1755,7 @@ var Matrix4 = new Class({ return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq)); } -}); +}; /** * @ignore diff --git a/src/math/Quaternion.js b/src/math/Quaternion.js index 7413cecc53..5e1259ea2a 100644 --- a/src/math/Quaternion.js +++ b/src/math/Quaternion.js @@ -38,11 +38,9 @@ var tmpMat3 = new Matrix3(); * @param {number} [z=0] - The z component. * @param {number} [w=1] - The w component. */ -var Quaternion = new Class({ +var Quaternion = class { - initialize: - - function Quaternion (x, y, z, w) + constructor(x, y, z, w) { /** * The x component of this Quaternion. @@ -95,7 +93,7 @@ var Quaternion = new Class({ this.onChangeCallback = NOOP; this.set(x, y, z, w); - }, + } /** * The x component of this Quaternion. @@ -105,19 +103,18 @@ var Quaternion = new Class({ * @default 0 * @since 3.0.0 */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - this._x = value; + get x() + { + return this._x; + } - this.onChangeCallback(this); - } - }, + set x(value) + { + this._x = value; + + this.onChangeCallback(this); + } /** * The y component of this Quaternion. @@ -127,19 +124,18 @@ var Quaternion = new Class({ * @default 0 * @since 3.0.0 */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - this._y = value; + get y() + { + return this._y; + } - this.onChangeCallback(this); - } - }, + set y(value) + { + this._y = value; + + this.onChangeCallback(this); + } /** * The z component of this Quaternion. @@ -149,19 +145,18 @@ var Quaternion = new Class({ * @default 0 * @since 3.0.0 */ - z: { - get: function () - { - return this._z; - }, - set: function (value) - { - this._z = value; + get z() + { + return this._z; + } - this.onChangeCallback(this); - } - }, + set z(value) + { + this._z = value; + + this.onChangeCallback(this); + } /** * The w component of this Quaternion. @@ -171,19 +166,18 @@ var Quaternion = new Class({ * @default 0 * @since 3.0.0 */ - w: { - get: function () - { - return this._w; - }, - set: function (value) - { - this._w = value; + get w() + { + return this._w; + } - this.onChangeCallback(this); - } - }, + set w(value) + { + this._w = value; + + this.onChangeCallback(this); + } /** * Copy the components of a given Quaternion or Vector into this Quaternion. @@ -195,10 +189,10 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - copy: function (src) + copy(src) { return this.set(src); - }, + } /** * Set the components of this Quaternion and optionally call the `onChangeCallback`. @@ -214,7 +208,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - set: function (x, y, z, w, update) + set(x, y, z, w, update) { if (update === undefined) { update = true; } @@ -239,7 +233,7 @@ var Quaternion = new Class({ } return this; - }, + } /** * Add a given Quaternion or Vector to this Quaternion. Addition is component-wise. @@ -251,7 +245,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - add: function (v) + add(v) { this._x += v.x; this._y += v.y; @@ -261,7 +255,7 @@ var Quaternion = new Class({ this.onChangeCallback(this); return this; - }, + } /** * Subtract a given Quaternion or Vector from this Quaternion. Subtraction is component-wise. @@ -273,7 +267,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - subtract: function (v) + subtract(v) { this._x -= v.x; this._y -= v.y; @@ -283,7 +277,7 @@ var Quaternion = new Class({ this.onChangeCallback(this); return this; - }, + } /** * Scale this Quaternion by the given value. @@ -295,7 +289,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - scale: function (scale) + scale(scale) { this._x *= scale; this._y *= scale; @@ -305,7 +299,7 @@ var Quaternion = new Class({ this.onChangeCallback(this); return this; - }, + } /** * Calculate the length of this Quaternion. @@ -315,7 +309,7 @@ var Quaternion = new Class({ * * @return {number} The length of this Quaternion. */ - length: function () + length() { var x = this.x; var y = this.y; @@ -323,7 +317,7 @@ var Quaternion = new Class({ var w = this.w; return Math.sqrt(x * x + y * y + z * z + w * w); - }, + } /** * Calculate the length of this Quaternion squared. @@ -333,7 +327,7 @@ var Quaternion = new Class({ * * @return {number} The length of this Quaternion, squared. */ - lengthSq: function () + lengthSq() { var x = this.x; var y = this.y; @@ -341,7 +335,7 @@ var Quaternion = new Class({ var w = this.w; return x * x + y * y + z * z + w * w; - }, + } /** * Normalize this Quaternion. @@ -351,7 +345,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - normalize: function () + normalize() { var x = this.x; var y = this.y; @@ -372,7 +366,7 @@ var Quaternion = new Class({ this.onChangeCallback(this); return this; - }, + } /** * Calculate the dot product of this Quaternion and the given Quaternion or Vector. @@ -384,10 +378,10 @@ var Quaternion = new Class({ * * @return {number} The dot product of this Quaternion and the given Quaternion or Vector. */ - dot: function (v) + dot(v) { return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; - }, + } /** * Linearly interpolate this Quaternion towards the given Quaternion or Vector. @@ -400,7 +394,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - lerp: function (v, t) + lerp(v, t) { if (t === undefined) { t = 0; } @@ -415,7 +409,7 @@ var Quaternion = new Class({ az + t * (v.z - az), aw + t * (v.w - aw) ); - }, + } /** * Rotates this Quaternion based on the two given vectors. @@ -428,7 +422,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - rotationTo: function (a, b) + rotationTo(a, b) { var dot = a.x * b.x + a.y * b.y + a.z * b.z; @@ -459,7 +453,7 @@ var Quaternion = new Class({ return this.normalize(); } - }, + } /** * Set the axes of this Quaternion. @@ -473,7 +467,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - setAxes: function (view, right, up) + setAxes(view, right, up) { var m = tmpMat3.val; @@ -490,7 +484,7 @@ var Quaternion = new Class({ m[8] = -view.z; return this.fromMat3(tmpMat3).normalize(); - }, + } /** * Reset this Matrix to an identity (default) Quaternion. @@ -500,10 +494,10 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - identity: function () + identity() { return this.set(0, 0, 0, 1); - }, + } /** * Set the axis angle of this Quaternion. @@ -516,7 +510,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - setAxisAngle: function (axis, rad) + setAxisAngle(axis, rad) { rad = rad * 0.5; @@ -528,7 +522,7 @@ var Quaternion = new Class({ s * axis.z, Math.cos(rad) ); - }, + } /** * Multiply this Quaternion by the given Quaternion or Vector. @@ -540,7 +534,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - multiply: function (b) + multiply(b) { var ax = this.x; var ay = this.y; @@ -558,7 +552,7 @@ var Quaternion = new Class({ az * bw + aw * bz + ax * by - ay * bx, aw * bw - ax * bx - ay * by - az * bz ); - }, + } /** * Smoothly linearly interpolate this Quaternion towards the given Quaternion or Vector. @@ -571,7 +565,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - slerp: function (b, t) + slerp(b, t) { // benchmarks: http://jsperf.com/quaternion-slerp-implementations @@ -621,7 +615,7 @@ var Quaternion = new Class({ scale0 * az + scale1 * bz, scale0 * aw + scale1 * bw ); - }, + } /** * Invert this Quaternion. @@ -631,7 +625,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - invert: function () + invert() { var a0 = this.x; var a1 = this.y; @@ -647,7 +641,7 @@ var Quaternion = new Class({ -a2 * invDot, a3 * invDot ); - }, + } /** * Convert this Quaternion into its conjugate. @@ -659,7 +653,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - conjugate: function () + conjugate() { this._x = -this.x; this._y = -this.y; @@ -668,7 +662,7 @@ var Quaternion = new Class({ this.onChangeCallback(this); return this; - }, + } /** * Rotate this Quaternion on the X axis. @@ -680,7 +674,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - rotateX: function (rad) + rotateX(rad) { rad *= 0.5; @@ -698,7 +692,7 @@ var Quaternion = new Class({ az * bw - ay * bx, aw * bw - ax * bx ); - }, + } /** * Rotate this Quaternion on the Y axis. @@ -710,7 +704,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - rotateY: function (rad) + rotateY(rad) { rad *= 0.5; @@ -728,7 +722,7 @@ var Quaternion = new Class({ az * bw + ax * by, aw * bw - ay * by ); - }, + } /** * Rotate this Quaternion on the Z axis. @@ -740,7 +734,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - rotateZ: function (rad) + rotateZ(rad) { rad *= 0.5; @@ -758,7 +752,7 @@ var Quaternion = new Class({ az * bw + aw * bz, aw * bw - az * bz ); - }, + } /** * Create a unit (or rotation) Quaternion from its x, y, and z components. @@ -770,7 +764,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - calculateW: function () + calculateW() { var x = this.x; var y = this.y; @@ -779,7 +773,7 @@ var Quaternion = new Class({ this.w = -Math.sqrt(1.0 - x * x - y * y - z * z); return this; - }, + } /** * Set this Quaternion from the given Euler, based on Euler order. @@ -792,7 +786,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - setFromEuler: function (euler, update) + setFromEuler(euler, update) { var x = euler.x / 2; var y = euler.y / 2; @@ -888,7 +882,7 @@ var Quaternion = new Class({ } return this; - }, + } /** * Sets the rotation of this Quaternion from the given Matrix4. @@ -900,7 +894,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - setFromRotationMatrix: function (mat4) + setFromRotationMatrix(mat4) { var m = mat4.val; @@ -963,7 +957,7 @@ var Quaternion = new Class({ } return this; - }, + } /** * Convert the given Matrix into this Quaternion. @@ -975,7 +969,7 @@ var Quaternion = new Class({ * * @return {Phaser.Math.Quaternion} This Quaternion. */ - fromMat3: function (mat) + fromMat3(mat) { // benchmarks: // http://jsperf.com/typed-array-access-speed @@ -1038,6 +1032,6 @@ var Quaternion = new Class({ return this; } -}); +}; module.exports = Quaternion; diff --git a/src/math/Vector2.js b/src/math/Vector2.js index 3428e7629b..2a8fcd3308 100644 --- a/src/math/Vector2.js +++ b/src/math/Vector2.js @@ -24,11 +24,9 @@ var FuzzyEqual = require('../math/fuzzy/Equal'); * @param {number|Phaser.Types.Math.Vector2Like} [x=0] - The x component, or an object with `x` and `y` properties. * @param {number} [y=x] - The y component. */ -var Vector2 = new Class({ +var Vector2 = class { - initialize: - - function Vector2 (x, y) + constructor(x, y) { /** * The x component of this Vector. @@ -62,7 +60,7 @@ var Vector2 = new Class({ this.x = x || 0; this.y = y || 0; } - }, + } /** * Make a clone of this Vector2. @@ -72,10 +70,10 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} A clone of this Vector2. */ - clone: function () + clone() { return new Vector2(this.x, this.y); - }, + } /** * Copy the components of a given Vector into this Vector. @@ -87,13 +85,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - copy: function (src) + copy(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. @@ -105,13 +103,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - setFromObject: function (obj) + setFromObject(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. @@ -124,7 +122,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - set: function (x, y) + set(x, y) { if (y === undefined) { y = x; } @@ -132,7 +130,7 @@ var Vector2 = new Class({ this.y = y; return this; - }, + } /** * This method is an alias for `Vector2.set`. @@ -145,10 +143,10 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - setTo: function (x, y) + setTo(x, y) { return this.set(x, y); - }, + } /** * Runs the x and y components of this Vector2 through Math.ceil and then sets them. @@ -158,13 +156,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - ceil: function () + ceil() { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); return this; - }, + } /** * Runs the x and y components of this Vector2 through Math.floor and then sets them. @@ -174,13 +172,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - floor: function () + floor() { this.x = Math.floor(this.x); this.y = Math.floor(this.y); return this; - }, + } /** * Swaps the x and y components of this Vector2. @@ -190,10 +188,10 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - invert: function () + invert() { return this.set(this.y, this.x); - }, + } /** * Sets the `x` and `y` values of this object from a given polar coordinate. @@ -206,7 +204,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - setToPolar: function (azimuth, radius) + setToPolar(azimuth, radius) { if (radius == null) { radius = 1; } @@ -214,7 +212,7 @@ var Vector2 = new Class({ this.y = Math.sin(azimuth) * radius; return this; - }, + } /** * Check whether this Vector is equal to a given Vector. @@ -228,10 +226,10 @@ var Vector2 = new Class({ * * @return {boolean} Whether the given Vector is equal to this Vector. */ - equals: function (v) + equals(v) { return ((this.x === v.x) && (this.y === v.y)); - }, + } /** * Check whether this Vector is approximately equal to a given Vector. @@ -244,10 +242,10 @@ var Vector2 = new Class({ * * @return {boolean} Whether both absolute differences of the x and y components are smaller than `epsilon`. */ - fuzzyEquals: function (v, epsilon) + fuzzyEquals(v, epsilon) { return (FuzzyEqual(this.x, v.x, epsilon) && FuzzyEqual(this.y, v.y, epsilon)); - }, + } /** * Calculate the angle between this Vector and the positive x-axis, in radians. @@ -257,7 +255,7 @@ var Vector2 = new Class({ * * @return {number} The angle between this Vector, and the positive x-axis, given in radians. */ - angle: function () + angle() { // computes the angle in radians with respect to the positive x-axis @@ -269,7 +267,7 @@ var Vector2 = new Class({ } return angle; - }, + } /** * Set the angle of this Vector. @@ -281,10 +279,10 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - setAngle: function (angle) + setAngle(angle) { return this.setToPolar(angle, this.length()); - }, + } /** * Add a given Vector to this Vector. Addition is component-wise. @@ -296,13 +294,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - add: function (src) + add(src) { this.x += src.x; this.y += src.y; return this; - }, + } /** * Subtract the given Vector from this Vector. Subtraction is component-wise. @@ -314,13 +312,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - subtract: function (src) + subtract(src) { this.x -= src.x; this.y -= src.y; return this; - }, + } /** * Perform a component-wise multiplication between this Vector and the given Vector. @@ -334,13 +332,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - multiply: function (src) + multiply(src) { this.x *= src.x; this.y *= src.y; return this; - }, + } /** * Scale this Vector by the given value. @@ -352,7 +350,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - scale: function (value) + scale(value) { if (isFinite(value)) { @@ -366,7 +364,7 @@ var Vector2 = new Class({ } return this; - }, + } /** * Perform a component-wise division between this Vector and the given Vector. @@ -380,13 +378,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - divide: function (src) + divide(src) { this.x /= src.x; this.y /= src.y; return this; - }, + } /** * Negate the `x` and `y` components of this Vector. @@ -396,13 +394,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - negate: function () + negate() { this.x = -this.x; this.y = -this.y; return this; - }, + } /** * Calculate the distance between this Vector and the given Vector. @@ -414,13 +412,13 @@ var Vector2 = new Class({ * * @return {number} The distance from this Vector to the given Vector. */ - distance: function (src) + distance(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. @@ -432,13 +430,13 @@ var Vector2 = new Class({ * * @return {number} The distance from this Vector to the given Vector, squared. */ - distanceSq: function (src) + distanceSq(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. @@ -448,13 +446,13 @@ var Vector2 = new Class({ * * @return {number} The length of this Vector. */ - length: function () + length() { var x = this.x; var y = this.y; return Math.sqrt(x * x + y * y); - }, + } /** * Set the length (or magnitude) of this Vector. @@ -466,10 +464,10 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - setLength: function (length) + setLength(length) { return this.normalize().scale(length); - }, + } /** * Calculate the length of this Vector squared. @@ -479,13 +477,13 @@ var Vector2 = new Class({ * * @return {number} The length of this Vector, squared. */ - lengthSq: function () + lengthSq() { var x = this.x; var y = this.y; return x * x + y * y; - }, + } /** * Normalize this Vector. @@ -497,7 +495,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - normalize: function () + normalize() { var x = this.x; var y = this.y; @@ -512,7 +510,7 @@ var Vector2 = new Class({ } return this; - }, + } /** * Rotate this Vector to its perpendicular, in the positive direction. @@ -522,7 +520,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - normalizeRightHand: function () + normalizeRightHand() { var x = this.x; @@ -530,7 +528,7 @@ var Vector2 = new Class({ this.y = x; return this; - }, + } /** * Rotate this Vector to its perpendicular, in the negative direction. @@ -540,7 +538,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - normalizeLeftHand: function () + normalizeLeftHand() { var x = this.x; @@ -548,7 +546,7 @@ var Vector2 = new Class({ this.y = x * -1; return this; - }, + } /** * Calculate the dot product of this Vector and the given Vector. @@ -560,10 +558,10 @@ var Vector2 = new Class({ * * @return {number} The dot product of this Vector and the given Vector. */ - dot: function (src) + dot(src) { return this.x * src.x + this.y * src.y; - }, + } /** * Calculate the cross product of this Vector and the given Vector. @@ -575,10 +573,10 @@ var Vector2 = new Class({ * * @return {number} The cross product of this Vector and the given Vector. */ - cross: function (src) + cross(src) { return this.x * src.y - this.y * src.x; - }, + } /** * Linearly interpolate between this Vector and the given Vector. @@ -593,7 +591,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - lerp: function (src, t) + lerp(src, t) { if (t === undefined) { t = 0; } @@ -604,7 +602,7 @@ var Vector2 = new Class({ this.y = ay + t * (src.y - ay); return this; - }, + } /** * Transform this Vector with the given Matrix. @@ -616,7 +614,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - transformMat3: function (mat) + transformMat3(mat) { var x = this.x; var y = this.y; @@ -626,7 +624,7 @@ var Vector2 = new Class({ this.y = m[1] * x + m[4] * y + m[7]; return this; - }, + } /** * Transform this Vector with the given Matrix. @@ -638,7 +636,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - transformMat4: function (mat) + transformMat4(mat) { var x = this.x; var y = this.y; @@ -648,7 +646,7 @@ var Vector2 = new Class({ this.y = m[1] * x + m[5] * y + m[13]; return this; - }, + } /** * Make this Vector the zero vector (0, 0). @@ -658,13 +656,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - reset: function () + reset() { this.x = 0; this.y = 0; return this; - }, + } /** * Limit the length (or magnitude) of this Vector. @@ -676,7 +674,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - limit: function (max) + limit(max) { var len = this.length(); @@ -686,7 +684,7 @@ var Vector2 = new Class({ } return this; - }, + } /** * Reflect this Vector off a line defined by a normal. @@ -698,12 +696,12 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - reflect: function (normal) + reflect(normal) { normal = normal.clone().normalize(); return this.subtract(normal.scale(2 * this.dot(normal))); - }, + } /** * Reflect this Vector across another. @@ -715,10 +713,10 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - mirror: function (axis) + mirror(axis) { return this.reflect(axis).negate(); - }, + } /** * Rotate this Vector by an angle amount. @@ -730,13 +728,13 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - rotate: function (delta) + rotate(delta) { var cos = Math.cos(delta); var sin = Math.sin(delta); return this.set(cos * this.x - sin * this.y, sin * this.x + cos * this.y); - }, + } /** * Project this Vector onto another. @@ -748,12 +746,12 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - project: function (src) + project(src) { var scalar = this.dot(src) / src.dot(src); return this.copy(src).scale(scalar); - }, + } /** * Calculates the vector projection of this Vector2 onto the non-zero `vecB`. This is the @@ -767,7 +765,7 @@ var Vector2 = new Class({ * * @return {Phaser.Math.Vector2} This Vector2. */ - projectUnit: function (vecB, out) + projectUnit(vecB, out) { if (out === undefined) { out = new Vector2(); } @@ -782,7 +780,7 @@ var Vector2 = new Class({ return out; } -}); +}; /** * A static zero Vector2 for use by reference. diff --git a/src/math/Vector3.js b/src/math/Vector3.js index 529cd0ff60..942accac9f 100644 --- a/src/math/Vector3.js +++ b/src/math/Vector3.js @@ -24,11 +24,9 @@ var Class = require('../utils/Class'); * @param {number} [y] - The y component. * @param {number} [z] - The z component. */ -var Vector3 = new Class({ +var Vector3 = class { - initialize: - - function Vector3 (x, y, z) + constructor(x, y, z) { /** * The x component of this Vector. @@ -72,7 +70,7 @@ var Vector3 = new Class({ this.y = y || 0; this.z = z || 0; } - }, + } /** * Set this Vector to point up. @@ -84,14 +82,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - up: function () + up() { this.x = 0; this.y = 1; this.z = 0; return this; - }, + } /** * Sets the components of this Vector to be the `Math.min` result from the given vector. @@ -103,14 +101,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - min: function (v) + min(v) { this.x = Math.min(this.x, v.x); this.y = Math.min(this.y, v.y); this.z = Math.min(this.z, v.z); return this; - }, + } /** * Sets the components of this Vector to be the `Math.max` result from the given vector. @@ -122,14 +120,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - max: function (v) + max(v) { this.x = Math.max(this.x, v.x); this.y = Math.max(this.y, v.y); this.z = Math.max(this.z, v.z); return this; - }, + } /** * Make a clone of this Vector3. @@ -139,10 +137,10 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} A new Vector3 object containing this Vectors values. */ - clone: function () + clone() { return new Vector3(this.x, this.y, this.z); - }, + } /** * Adds the two given Vector3s and sets the results into this Vector3. @@ -155,14 +153,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - addVectors: function (a, b) + addVectors(a, b) { this.x = a.x + b.x; this.y = a.y + b.y; this.z = a.z + b.z; return this; - }, + } /** * Subtracts the two given Vector3s and sets the results into this Vector3. @@ -175,14 +173,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - subVectors: function (a, b) + subVectors(a, b) { this.x = a.x - b.x; this.y = a.y - b.y; this.z = a.z - b.z; return this; - }, + } /** * Calculate the cross (vector) product of two given Vectors. @@ -195,7 +193,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - crossVectors: function (a, b) + crossVectors(a, b) { var ax = a.x; var ay = a.y; @@ -209,7 +207,7 @@ var Vector3 = new Class({ this.z = ax * by - ay * bx; return this; - }, + } /** * Check whether this Vector is equal to a given Vector. @@ -223,10 +221,10 @@ var Vector3 = new Class({ * * @return {boolean} True if the two vectors strictly match, otherwise false. */ - equals: function (v) + equals(v) { return ((this.x === v.x) && (this.y === v.y) && (this.z === v.z)); - }, + } /** * Copy the components of a given Vector into this Vector. @@ -238,14 +236,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - copy: function (src) + copy(src) { this.x = src.x; this.y = src.y; this.z = src.z || 0; return this; - }, + } /** * Set the `x`, `y`, and `z` components of this Vector to the given `x`, `y`, and `z` values. @@ -259,7 +257,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - set: function (x, y, z) + set(x, y, z) { if (typeof x === 'object') { @@ -275,7 +273,7 @@ var Vector3 = new Class({ } return this; - }, + } /** * Sets the components of this Vector3 from the position of the given Matrix4. @@ -287,10 +285,10 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - setFromMatrixPosition: function (m) + setFromMatrixPosition(m) { return this.fromArray(m.val, 12); - }, + } /** * Sets the components of this Vector3 from the Matrix4 column specified. @@ -303,10 +301,10 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - setFromMatrixColumn: function (mat4, index) + setFromMatrixColumn(mat4, index) { return this.fromArray(mat4.val, index * 4); - }, + } /** * Sets the components of this Vector3 from the given array, based on the offset. @@ -323,7 +321,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - fromArray: function (array, offset) + fromArray(array, offset) { if (offset === undefined) { offset = 0; } @@ -332,7 +330,7 @@ var Vector3 = new Class({ this.z = array[offset + 2]; return this; - }, + } /** * Add a given Vector to this Vector. Addition is component-wise. @@ -344,14 +342,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - add: function (v) + add(v) { this.x += v.x; this.y += v.y; this.z += v.z || 0; return this; - }, + } /** * Add the given value to each component of this Vector. @@ -363,14 +361,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - addScalar: function (s) + addScalar(s) { this.x += s; this.y += s; this.z += s; return this; - }, + } /** * Add and scale a given Vector to this Vector. Addition is component-wise. @@ -383,14 +381,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - addScale: function (v, scale) + addScale(v, scale) { this.x += v.x * scale; this.y += v.y * scale; this.z += v.z * scale || 0; return this; - }, + } /** * Subtract the given Vector from this Vector. Subtraction is component-wise. @@ -402,14 +400,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - subtract: function (v) + subtract(v) { this.x -= v.x; this.y -= v.y; this.z -= v.z || 0; return this; - }, + } /** * Perform a component-wise multiplication between this Vector and the given Vector. @@ -423,14 +421,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - multiply: function (v) + multiply(v) { this.x *= v.x; this.y *= v.y; this.z *= v.z || 1; return this; - }, + } /** * Scale this Vector by the given value. @@ -442,7 +440,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - scale: function (scale) + scale(scale) { if (isFinite(scale)) { @@ -458,7 +456,7 @@ var Vector3 = new Class({ } return this; - }, + } /** * Perform a component-wise division between this Vector and the given Vector. @@ -472,14 +470,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - divide: function (v) + divide(v) { this.x /= v.x; this.y /= v.y; this.z /= v.z || 1; return this; - }, + } /** * Negate the `x`, `y` and `z` components of this Vector. @@ -489,14 +487,14 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - negate: function () + negate() { this.x = -this.x; this.y = -this.y; this.z = -this.z; return this; - }, + } /** * Calculate the distance between this Vector and the given Vector. @@ -508,14 +506,14 @@ var Vector3 = new Class({ * * @return {number} The distance from this Vector to the given Vector. */ - distance: function (v) + distance(v) { var dx = v.x - this.x; var dy = v.y - this.y; var dz = v.z - this.z || 0; return Math.sqrt(dx * dx + dy * dy + dz * dz); - }, + } /** * Calculate the distance between this Vector and the given Vector, squared. @@ -527,14 +525,14 @@ var Vector3 = new Class({ * * @return {number} The distance from this Vector to the given Vector, squared. */ - distanceSq: function (v) + distanceSq(v) { var dx = v.x - this.x; var dy = v.y - this.y; var dz = v.z - this.z || 0; return dx * dx + dy * dy + dz * dz; - }, + } /** * Calculate the length (or magnitude) of this Vector. @@ -544,14 +542,14 @@ var Vector3 = new Class({ * * @return {number} The length of this Vector. */ - length: function () + length() { var x = this.x; var y = this.y; var z = this.z; return Math.sqrt(x * x + y * y + z * z); - }, + } /** * Calculate the length of this Vector squared. @@ -561,14 +559,14 @@ var Vector3 = new Class({ * * @return {number} The length of this Vector, squared. */ - lengthSq: function () + lengthSq() { var x = this.x; var y = this.y; var z = this.z; return x * x + y * y + z * z; - }, + } /** * Normalize this Vector. @@ -580,7 +578,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - normalize: function () + normalize() { var x = this.x; var y = this.y; @@ -597,7 +595,7 @@ var Vector3 = new Class({ } return this; - }, + } /** * Calculate the dot product of this Vector and the given Vector. @@ -609,10 +607,10 @@ var Vector3 = new Class({ * * @return {number} The dot product of this Vector and `v`. */ - dot: function (v) + dot(v) { return this.x * v.x + this.y * v.y + this.z * v.z; - }, + } /** * Calculate the cross (vector) product of this Vector (which will be modified) and the given Vector. @@ -624,7 +622,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - cross: function (v) + cross(v) { var ax = this.x; var ay = this.y; @@ -638,7 +636,7 @@ var Vector3 = new Class({ this.z = ax * by - ay * bx; return this; - }, + } /** * Linearly interpolate between this Vector and the given Vector. @@ -653,7 +651,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - lerp: function (v, t) + lerp(v, t) { if (t === undefined) { t = 0; } @@ -666,7 +664,7 @@ var Vector3 = new Class({ this.z = az + t * (v.z - az); return this; - }, + } /** * Takes a Matrix3 and applies it to this Vector3. @@ -678,7 +676,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - applyMatrix3: function (mat3) + applyMatrix3(mat3) { var x = this.x; var y = this.y; @@ -690,7 +688,7 @@ var Vector3 = new Class({ this.z = m[2] * x + m[5] * y + m[8] * z; return this; - }, + } /** * Takes a Matrix4 and applies it to this Vector3. @@ -702,7 +700,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - applyMatrix4: function (mat4) + applyMatrix4(mat4) { var x = this.x; var y = this.y; @@ -716,7 +714,7 @@ var Vector3 = new Class({ this.z = (m[2] * x + m[6] * y + m[10] * z + m[14]) * w; return this; - }, + } /** * Transform this Vector with the given Matrix. @@ -728,7 +726,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - transformMat3: function (mat) + transformMat3(mat) { var x = this.x; var y = this.y; @@ -740,7 +738,7 @@ var Vector3 = new Class({ this.z = x * m[2] + y * m[5] + z * m[8]; return this; - }, + } /** * Transform this Vector with the given Matrix4. @@ -752,7 +750,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - transformMat4: function (mat) + transformMat4(mat) { var x = this.x; var y = this.y; @@ -764,7 +762,7 @@ var Vector3 = new Class({ this.z = m[2] * x + m[6] * y + m[10] * z + m[14]; return this; - }, + } /** * Transforms the coordinates of this Vector3 with the given Matrix4. @@ -776,7 +774,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - transformCoordinates: function (mat) + transformCoordinates(mat) { var x = this.x; var y = this.y; @@ -793,7 +791,7 @@ var Vector3 = new Class({ this.z = tz / tw; return this; - }, + } /** * Transform this Vector with the given Quaternion. @@ -805,7 +803,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - transformQuat: function (q) + transformQuat(q) { // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations var x = this.x; @@ -828,7 +826,7 @@ var Vector3 = new Class({ this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx; return this; - }, + } /** * Multiplies this Vector3 by the specified matrix, applying a W divide. This is useful for projection, @@ -841,7 +839,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - project: function (mat) + project(mat) { var x = this.x; var y = this.y; @@ -872,7 +870,7 @@ var Vector3 = new Class({ this.z = (x * a02 + y * a12 + z * a22 + a32) * lw; return this; - }, + } /** * Multiplies this Vector3 by the given view and projection matrices. @@ -885,10 +883,10 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - projectViewMatrix: function (viewMatrix, projectionMatrix) + projectViewMatrix(viewMatrix, projectionMatrix) { return this.applyMatrix4(viewMatrix).applyMatrix4(projectionMatrix); - }, + } /** * Multiplies this Vector3 by the given inversed projection matrix and world matrix. @@ -901,10 +899,10 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - unprojectViewMatrix: function (projectionMatrix, worldMatrix) + unprojectViewMatrix(projectionMatrix, worldMatrix) { return this.applyMatrix4(projectionMatrix).applyMatrix4(worldMatrix); - }, + } /** * Unproject this point from 2D space to 3D space. @@ -924,7 +922,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - unproject: function (viewport, invProjectionView) + unproject(viewport, invProjectionView) { var viewX = viewport.x; var viewY = viewport.y; @@ -940,7 +938,7 @@ var Vector3 = new Class({ this.z = 2 * z - 1; return this.project(invProjectionView); - }, + } /** * Make this Vector the zero vector (0, 0, 0). @@ -950,7 +948,7 @@ var Vector3 = new Class({ * * @return {Phaser.Math.Vector3} This Vector3. */ - reset: function () + reset() { this.x = 0; this.y = 0; @@ -959,7 +957,7 @@ var Vector3 = new Class({ return this; } -}); +}; /** * A static zero Vector3 for use by reference. diff --git a/src/math/Vector4.js b/src/math/Vector4.js index f5296f38bd..0dc19c7166 100644 --- a/src/math/Vector4.js +++ b/src/math/Vector4.js @@ -25,11 +25,9 @@ var Class = require('../utils/Class'); * @param {number} [z] - The z component. * @param {number} [w] - The w component. */ -var Vector4 = new Class({ +var Vector4 = class { - initialize: - - function Vector4 (x, y, z, w) + constructor(x, y, z, w) { /** * The x component of this Vector. @@ -85,7 +83,7 @@ var Vector4 = new Class({ this.z = z || 0; this.w = w || 0; } - }, + } /** * Make a clone of this Vector4. @@ -95,10 +93,10 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} A clone of this Vector4. */ - clone: function () + clone() { return new Vector4(this.x, this.y, this.z, this.w); - }, + } /** * Copy the components of a given Vector into this Vector. @@ -110,7 +108,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - copy: function (src) + copy(src) { this.x = src.x; this.y = src.y; @@ -118,7 +116,7 @@ var Vector4 = new Class({ this.w = src.w || 0; return this; - }, + } /** * Check whether this Vector is equal to a given Vector. @@ -132,10 +130,10 @@ var Vector4 = new Class({ * * @return {boolean} A boolean indicating whether the two Vectors are equal or not. */ - equals: function (v) + equals(v) { return ((this.x === v.x) && (this.y === v.y) && (this.z === v.z) && (this.w === v.w)); - }, + } /** * Set the `x`, `y`, `z` and `w` components of the this Vector to the given `x`, `y`, `z` and `w` values. @@ -150,7 +148,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - set: function (x, y, z, w) + set(x, y, z, w) { if (typeof x === 'object') { @@ -168,7 +166,7 @@ var Vector4 = new Class({ } return this; - }, + } /** * Add a given Vector to this Vector. Addition is component-wise. @@ -180,7 +178,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - add: function (v) + add(v) { this.x += v.x; this.y += v.y; @@ -188,7 +186,7 @@ var Vector4 = new Class({ this.w += v.w || 0; return this; - }, + } /** * Subtract the given Vector from this Vector. Subtraction is component-wise. @@ -200,7 +198,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - subtract: function (v) + subtract(v) { this.x -= v.x; this.y -= v.y; @@ -208,7 +206,7 @@ var Vector4 = new Class({ this.w -= v.w || 0; return this; - }, + } /** * Scale this Vector by the given value. @@ -220,7 +218,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - scale: function (scale) + scale(scale) { this.x *= scale; this.y *= scale; @@ -228,7 +226,7 @@ var Vector4 = new Class({ this.w *= scale; return this; - }, + } /** * Calculate the length (or magnitude) of this Vector. @@ -238,7 +236,7 @@ var Vector4 = new Class({ * * @return {number} The length of this Vector. */ - length: function () + length() { var x = this.x; var y = this.y; @@ -246,7 +244,7 @@ var Vector4 = new Class({ var w = this.w; return Math.sqrt(x * x + y * y + z * z + w * w); - }, + } /** * Calculate the length of this Vector squared. @@ -256,7 +254,7 @@ var Vector4 = new Class({ * * @return {number} The length of this Vector, squared. */ - lengthSq: function () + lengthSq() { var x = this.x; var y = this.y; @@ -264,7 +262,7 @@ var Vector4 = new Class({ var w = this.w; return x * x + y * y + z * z + w * w; - }, + } /** * Normalize this Vector. @@ -276,7 +274,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - normalize: function () + normalize() { var x = this.x; var y = this.y; @@ -295,7 +293,7 @@ var Vector4 = new Class({ } return this; - }, + } /** * Calculate the dot product of this Vector and the given Vector. @@ -307,10 +305,10 @@ var Vector4 = new Class({ * * @return {number} The dot product of this Vector and the given Vector. */ - dot: function (v) + dot(v) { return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; - }, + } /** * Linearly interpolate between this Vector and the given Vector. @@ -325,7 +323,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - lerp: function (v, t) + lerp(v, t) { if (t === undefined) { t = 0; } @@ -340,7 +338,7 @@ var Vector4 = new Class({ this.w = aw + t * (v.w - aw); return this; - }, + } /** * Perform a component-wise multiplication between this Vector and the given Vector. @@ -354,7 +352,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - multiply: function (v) + multiply(v) { this.x *= v.x; this.y *= v.y; @@ -362,7 +360,7 @@ var Vector4 = new Class({ this.w *= v.w || 1; return this; - }, + } /** * Perform a component-wise division between this Vector and the given Vector. @@ -376,7 +374,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - divide: function (v) + divide(v) { this.x /= v.x; this.y /= v.y; @@ -384,7 +382,7 @@ var Vector4 = new Class({ this.w /= v.w || 1; return this; - }, + } /** * Calculate the distance between this Vector and the given Vector. @@ -396,7 +394,7 @@ var Vector4 = new Class({ * * @return {number} The distance from this Vector to the given Vector. */ - distance: function (v) + distance(v) { var dx = v.x - this.x; var dy = v.y - this.y; @@ -404,7 +402,7 @@ var Vector4 = new Class({ var dw = v.w - this.w || 0; return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw); - }, + } /** * Calculate the distance between this Vector and the given Vector, squared. @@ -416,7 +414,7 @@ var Vector4 = new Class({ * * @return {number} The distance from this Vector to the given Vector, squared. */ - distanceSq: function (v) + distanceSq(v) { var dx = v.x - this.x; var dy = v.y - this.y; @@ -424,7 +422,7 @@ var Vector4 = new Class({ var dw = v.w - this.w || 0; return dx * dx + dy * dy + dz * dz + dw * dw; - }, + } /** * Negate the `x`, `y`, `z` and `w` components of this Vector. @@ -434,7 +432,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - negate: function () + negate() { this.x = -this.x; this.y = -this.y; @@ -442,7 +440,7 @@ var Vector4 = new Class({ this.w = -this.w; return this; - }, + } /** * Transform this Vector with the given Matrix. @@ -454,7 +452,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - transformMat4: function (mat) + transformMat4(mat) { var x = this.x; var y = this.y; @@ -468,7 +466,7 @@ var Vector4 = new Class({ this.w = m[3] * x + m[7] * y + m[11] * z + m[15] * w; return this; - }, + } /** * Transform this Vector with the given Quaternion. @@ -480,7 +478,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - transformQuat: function (q) + transformQuat(q) { var x = this.x; var y = this.y; @@ -502,7 +500,7 @@ var Vector4 = new Class({ this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx; return this; - }, + } /** * Make this Vector the zero vector (0, 0, 0, 0). @@ -512,7 +510,7 @@ var Vector4 = new Class({ * * @return {Phaser.Math.Vector4} This Vector4. */ - reset: function () + reset() { this.x = 0; this.y = 0; @@ -522,7 +520,7 @@ var Vector4 = new Class({ return this; } -}); +}; Vector4.prototype.sub = Vector4.prototype.subtract; Vector4.prototype.mul = Vector4.prototype.multiply; diff --git a/src/math/random-data-generator/RandomDataGenerator.js b/src/math/random-data-generator/RandomDataGenerator.js index 4ecfe605a5..3d72c33f23 100644 --- a/src/math/random-data-generator/RandomDataGenerator.js +++ b/src/math/random-data-generator/RandomDataGenerator.js @@ -26,11 +26,9 @@ var Class = require('../../utils/Class'); * * @param {(string|string[])} [seeds] - The seeds to use for the random number generator. */ -var RandomDataGenerator = new Class({ +var RandomDataGenerator = class { - initialize: - - function RandomDataGenerator (seeds) + constructor(seeds) { if (seeds === undefined) { seeds = [ (Date.now() * Math.random()).toString() ]; } @@ -102,7 +100,7 @@ var RandomDataGenerator = new Class({ { this.init(seeds); } - }, + } /** * Private random helper. @@ -113,7 +111,7 @@ var RandomDataGenerator = new Class({ * * @return {number} A random number. */ - rnd: function () + rnd() { var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32 @@ -123,7 +121,7 @@ var RandomDataGenerator = new Class({ this.s2 = t - this.c; return this.s2; - }, + } /** * Internal method that creates a seed hash. @@ -136,7 +134,7 @@ var RandomDataGenerator = new Class({ * * @return {number} The hashed value. */ - hash: function (data) + hash(data) { var h; var n = this.n; @@ -158,7 +156,7 @@ var RandomDataGenerator = new Class({ this.n = n; return (n >>> 0) * 2.3283064365386963e-10;// 2^-32 - }, + } /** * Initialize the state of the random data generator. @@ -168,7 +166,7 @@ var RandomDataGenerator = new Class({ * * @param {(string|string[])} seeds - The seeds to initialize the random data generator with. */ - init: function (seeds) + init(seeds) { if (typeof seeds === 'string') { @@ -178,7 +176,7 @@ var RandomDataGenerator = new Class({ { this.sow(seeds); } - }, + } /** * Reset the seed of the random data generator. @@ -190,7 +188,7 @@ var RandomDataGenerator = new Class({ * * @param {string[]} seeds - The array of seeds: the `toString()` of each value is used. */ - sow: function (seeds) + sow(seeds) { // Always reset to default seed this.n = 0xefc8249d; @@ -216,7 +214,7 @@ var RandomDataGenerator = new Class({ this.s2 -= this.hash(seed); this.s2 += ~~(this.s2 < 0); } - }, + } /** * Returns a random integer between 0 and 2^32. @@ -226,11 +224,11 @@ var RandomDataGenerator = new Class({ * * @return {number} A random integer between 0 and 2^32. */ - integer: function () + integer() { // 2^32 return this.rnd() * 0x100000000; - }, + } /** * Returns a random real number between 0 and 1. @@ -240,11 +238,11 @@ var RandomDataGenerator = new Class({ * * @return {number} A random real number between 0 and 1. */ - frac: function () + frac() { // 2^-53 return this.rnd() + (this.rnd() * 0x200000 | 0) * 1.1102230246251565e-16; - }, + } /** * Returns a random real number between 0 and 2^32. @@ -254,10 +252,10 @@ var RandomDataGenerator = new Class({ * * @return {number} A random real number between 0 and 2^32. */ - real: function () + real() { return this.integer() + this.frac(); - }, + } /** * Returns a random integer between and including min and max. @@ -270,10 +268,10 @@ var RandomDataGenerator = new Class({ * * @return {number} A random number between min and max. */ - integerInRange: function (min, max) + integerInRange(min, max) { return Math.floor(this.realInRange(0, max - min + 1) + min); - }, + } /** * Returns a random integer between and including min and max. @@ -287,10 +285,10 @@ var RandomDataGenerator = new Class({ * * @return {number} A random number between min and max. */ - between: function (min, max) + between(min, max) { return Math.floor(this.realInRange(0, max - min + 1) + min); - }, + } /** * Returns a random real number between min and max. @@ -303,10 +301,10 @@ var RandomDataGenerator = new Class({ * * @return {number} A random number between min and max. */ - realInRange: function (min, max) + realInRange(min, max) { return this.frac() * (max - min) + min; - }, + } /** * Returns a random real number between -1 and 1. @@ -316,10 +314,10 @@ var RandomDataGenerator = new Class({ * * @return {number} A random real number between -1 and 1. */ - normal: function () + normal() { return 1 - (2 * this.frac()); - }, + } /** * Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368 @@ -329,7 +327,7 @@ var RandomDataGenerator = new Class({ * * @return {string} A valid RFC4122 version4 ID hex string */ - uuid: function () + uuid() { var a = ''; var b = ''; @@ -340,7 +338,7 @@ var RandomDataGenerator = new Class({ } return b; - }, + } /** * Returns a random element from within the given array. @@ -356,10 +354,10 @@ var RandomDataGenerator = new Class({ * * @return {T} A random member of the array. */ - pick: function (array) + pick(array) { return array[this.integerInRange(0, array.length - 1)]; - }, + } /** * Returns a sign to be used with multiplication operator. @@ -369,10 +367,10 @@ var RandomDataGenerator = new Class({ * * @return {number} -1 or +1. */ - sign: function () + sign() { return this.pick(this.signs); - }, + } /** * Returns a random element from within the given array, favoring the earlier entries. @@ -388,10 +386,10 @@ var RandomDataGenerator = new Class({ * * @return {T} A random member of the array. */ - weightedPick: function (array) + weightedPick(array) { return array[~~(Math.pow(this.frac(), 2) * (array.length - 0.5) + 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. @@ -404,10 +402,10 @@ var RandomDataGenerator = new Class({ * * @return {number} A random timestamp between min and max. */ - timestamp: function (min, max) + timestamp(min, max) { return this.realInRange(min || 946684800000, max || 1577862000000); - }, + } /** * Returns a random angle between -180 and 180. @@ -417,10 +415,10 @@ var RandomDataGenerator = new Class({ * * @return {number} A random number between -180 and 180. */ - angle: function () + angle() { return this.integerInRange(-180, 180); - }, + } /** * Returns a random rotation in radians, between -3.141 and 3.141 @@ -430,10 +428,10 @@ var RandomDataGenerator = new Class({ * * @return {number} A random number between -3.141 and 3.141 */ - rotation: function () + rotation() { return this.realInRange(-3.1415926, 3.1415926); - }, + } /** * Gets or Sets the state of the generator. This allows you to retain the values @@ -455,7 +453,7 @@ var RandomDataGenerator = new Class({ * * @return {string} The current state of the generator. */ - state: function (state) + state(state) { if (typeof state === 'string' && state.match(/^!rnd/)) { @@ -468,7 +466,7 @@ var RandomDataGenerator = new Class({ } return [ '!rnd', this.c, this.s0, this.s1, this.s2 ].join(','); - }, + } /** * Shuffles the given array, using the current seed. @@ -483,7 +481,7 @@ var RandomDataGenerator = new Class({ * * @return {T[]} The shuffled array. */ - shuffle: function (array) + shuffle(array) { var len = array.length - 1; @@ -499,6 +497,6 @@ var RandomDataGenerator = new Class({ return array; } -}); +}; module.exports = RandomDataGenerator; diff --git a/src/physics/arcade/ArcadeImage.js b/src/physics/arcade/ArcadeImage.js index 80a8b8eb8f..4c09951e5c 100644 --- a/src/physics/arcade/ArcadeImage.js +++ b/src/physics/arcade/ArcadeImage.js @@ -55,32 +55,31 @@ var Image = require('../../gameobjects/image/Image'); * @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with. */ -var ArcadeImage = new Class({ +var ArcadeImage = class extends Image { - Extends: Image, - - Mixins: [ - Components.Acceleration, - Components.Angular, - Components.Bounce, - Components.Collision, - Components.Debug, - Components.Drag, - Components.Enable, - Components.Friction, - Components.Gravity, - Components.Immovable, - Components.Mass, - Components.Pushable, - Components.Size, - Components.Velocity - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Acceleration, + Components.Angular, + Components.Bounce, + Components.Collision, + Components.Debug, + Components.Drag, + Components.Enable, + Components.Friction, + Components.Gravity, + Components.Immovable, + Components.Mass, + Components.Pushable, + Components.Size, + Components.Velocity + ], false); + } - function ArcadeImage (scene, x, y, texture, frame) + constructor(scene, x, y, texture, frame) { - Image.call(this, scene, x, y, texture, frame); + super(scene, x, y, texture, frame); /** * This Game Object's Physics Body. @@ -93,6 +92,6 @@ var ArcadeImage = new Class({ this.body = null; } -}); +}; module.exports = ArcadeImage; diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js index fb1e70c0d8..cb4bb563a1 100644 --- a/src/physics/arcade/ArcadePhysics.js +++ b/src/physics/arcade/ArcadePhysics.js @@ -37,11 +37,9 @@ var World = require('./World'); * * @param {Phaser.Scene} scene - The Scene that this Plugin belongs to. */ -var ArcadePhysics = new Class({ +var ArcadePhysics = class { - initialize: - - function ArcadePhysics (scene) + constructor(scene) { /** * The Scene that this Plugin belongs to. @@ -100,7 +98,7 @@ var ArcadePhysics = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -110,13 +108,13 @@ var ArcadePhysics = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.world = new World(this.scene, this.config); this.add = new Factory(this.world); this.systems.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -127,7 +125,7 @@ var ArcadePhysics = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { if (!this.world) { @@ -144,7 +142,7 @@ var ArcadePhysics = new Class({ eventEmitter.on(SceneEvents.POST_UPDATE, this.world.postUpdate, this.world); eventEmitter.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * Causes `World.update` to be automatically called each time the Scene @@ -154,10 +152,10 @@ var ArcadePhysics = new Class({ * @method Phaser.Physics.Arcade.ArcadePhysics#enableUpdate * @since 3.50.0 */ - enableUpdate: function () + enableUpdate() { this.systems.events.on(SceneEvents.UPDATE, this.world.update, this.world); - }, + } /** * Causes `World.update` to **not** be automatically called each time the Scene @@ -173,10 +171,10 @@ var ArcadePhysics = new Class({ * @method Phaser.Physics.Arcade.ArcadePhysics#disableUpdate * @since 3.50.0 */ - disableUpdate: function () + disableUpdate() { this.systems.events.off(SceneEvents.UPDATE, this.world.update, this.world); - }, + } /** * Creates the physics configuration for the current Scene. @@ -186,7 +184,7 @@ var ArcadePhysics = new Class({ * * @return {Phaser.Types.Physics.Arcade.ArcadeWorldConfig} The physics configuration. */ - getConfig: function () + getConfig() { var gameConfig = this.systems.game.config.physics; var sceneConfig = this.systems.settings.physics; @@ -197,7 +195,7 @@ var ArcadePhysics = new Class({ ); return config; - }, + } /** * Returns the next available collision category. @@ -214,12 +212,12 @@ var ArcadePhysics = new Class({ * * @return {number} The next collision category. */ - nextCategory: function () + nextCategory() { this._category = this._category << 1; return this._category; - }, + } /** * Tests if Game Objects overlap. See {@link Phaser.Physics.Arcade.World#overlap} @@ -237,14 +235,14 @@ var ArcadePhysics = new Class({ * * @see Phaser.Physics.Arcade.World#overlap */ - overlap: function (object1, object2, overlapCallback, processCallback, callbackContext) + overlap(object1, object2, overlapCallback, processCallback, callbackContext) { if (overlapCallback === undefined) { overlapCallback = null; } if (processCallback === undefined) { processCallback = null; } if (callbackContext === undefined) { callbackContext = overlapCallback; } return this.world.collideObjects(object1, object2, overlapCallback, processCallback, callbackContext, true); - }, + } /** * Performs a collision check and separation between the two physics enabled objects given, which can be single @@ -279,14 +277,14 @@ var ArcadePhysics = new Class({ * * @see Phaser.Physics.Arcade.World#collide */ - collide: function (object1, object2, collideCallback, processCallback, callbackContext) + collide(object1, object2, collideCallback, processCallback, callbackContext) { if (collideCallback === undefined) { collideCallback = null; } if (processCallback === undefined) { processCallback = null; } if (callbackContext === undefined) { callbackContext = collideCallback; } return this.world.collideObjects(object1, object2, collideCallback, processCallback, callbackContext, false); - }, + } /** * This advanced method is specifically for testing for collision between a single Sprite and an array of Tile objects. @@ -316,10 +314,10 @@ var ArcadePhysics = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideTiles: function (sprite, tiles, collideCallback, processCallback, callbackContext) + collideTiles(sprite, tiles, collideCallback, processCallback, callbackContext) { return this.world.collideTiles(sprite, tiles, collideCallback, processCallback, callbackContext); - }, + } /** * This advanced method is specifically for testing for overlaps between a single Sprite and an array of Tile objects. @@ -344,10 +342,10 @@ var ArcadePhysics = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - overlapTiles: function (sprite, tiles, overlapCallback, processCallback, callbackContext) + overlapTiles(sprite, tiles, overlapCallback, processCallback, callbackContext) { return this.world.overlapTiles(sprite, tiles, overlapCallback, processCallback, callbackContext); - }, + } /** * Pauses the simulation. @@ -357,10 +355,10 @@ var ArcadePhysics = new Class({ * * @return {Phaser.Physics.Arcade.World} The simulation. */ - pause: function () + pause() { return this.world.pause(); - }, + } /** * Resumes the simulation (if paused). @@ -370,10 +368,10 @@ var ArcadePhysics = new Class({ * * @return {Phaser.Physics.Arcade.World} The simulation. */ - resume: function () + resume() { return this.world.resume(); - }, + } /** * Sets the acceleration.x/y property on the game object so it will move towards the x/y coordinates at the given rate (in pixels per second squared) @@ -395,7 +393,7 @@ var ArcadePhysics = new Class({ * * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity. */ - accelerateTo: function (gameObject, x, y, speed, xSpeedMax, ySpeedMax) + accelerateTo(gameObject, x, y, speed, xSpeedMax, ySpeedMax) { if (speed === undefined) { speed = 60; } @@ -409,7 +407,7 @@ var ArcadePhysics = new Class({ } return angle; - }, + } /** * Sets the acceleration.x/y property on the game object so it will move towards the x/y coordinates at the given rate (in pixels per second squared) @@ -430,10 +428,10 @@ var ArcadePhysics = new Class({ * * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity. */ - accelerateToObject: function (gameObject, destination, speed, xSpeedMax, ySpeedMax) + accelerateToObject(gameObject, destination, speed, xSpeedMax, ySpeedMax) { return this.accelerateTo(gameObject, destination.x, destination.y, speed, xSpeedMax, ySpeedMax); - }, + } /** * Finds the Body or Game Object closest to a source point or object. @@ -455,7 +453,7 @@ var ArcadePhysics = new Class({ * * @return {Target|null} The target closest to the given source point. */ - closest: function (source, targets) + closest(source, targets) { if (!targets) { @@ -488,7 +486,7 @@ var ArcadePhysics = new Class({ } return closest; - }, + } /** * Finds the Body or Game Object farthest from a source point or object. @@ -509,7 +507,7 @@ var ArcadePhysics = new Class({ * * @return {?(Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody|Phaser.GameObjects.GameObject)} The target farthest from the given source point. */ - furthest: function (source, targets) + furthest(source, targets) { if (!targets) { @@ -543,7 +541,7 @@ var ArcadePhysics = new Class({ } return farthest; - }, + } /** * Move the given display object towards the x/y coordinates at a steady velocity. @@ -564,7 +562,7 @@ var ArcadePhysics = new Class({ * * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity. */ - moveTo: function (gameObject, x, y, speed, maxTime) + moveTo(gameObject, x, y, speed, maxTime) { if (speed === undefined) { speed = 60; } if (maxTime === undefined) { maxTime = 0; } @@ -580,7 +578,7 @@ var ArcadePhysics = new Class({ gameObject.body.velocity.setToPolar(angle, speed); return angle; - }, + } /** * Move the given display object towards the destination object at a steady velocity. @@ -600,10 +598,10 @@ var ArcadePhysics = new Class({ * * @return {number} The angle (in radians) that the object should be visually set to in order to match its new velocity. */ - moveToObject: function (gameObject, destination, speed, maxTime) + moveToObject(gameObject, destination, speed, maxTime) { return this.moveTo(gameObject, destination.x, destination.y, speed, maxTime); - }, + } /** * Given the angle (in degrees) and speed calculate the velocity and return it as a vector, or set it to the given vector object. @@ -618,13 +616,13 @@ var ArcadePhysics = new Class({ * * @return {Phaser.Math.Vector2} The Vector2 that stores the velocity. */ - velocityFromAngle: function (angle, speed, vec2) + velocityFromAngle(angle, speed, vec2) { if (speed === undefined) { speed = 60; } if (vec2 === undefined) { vec2 = new Vector2(); } return vec2.setToPolar(DegToRad(angle), speed); - }, + } /** * Given the rotation (in radians) and speed calculate the velocity and return it as a vector, or set it to the given vector object. @@ -639,13 +637,13 @@ var ArcadePhysics = new Class({ * * @return {Phaser.Math.Vector2} The Vector2 that stores the velocity. */ - velocityFromRotation: function (rotation, speed, vec2) + velocityFromRotation(rotation, speed, vec2) { if (speed === undefined) { speed = 60; } if (vec2 === undefined) { vec2 = new Vector2(); } return vec2.setToPolar(rotation, speed); - }, + } /** * This method will search the given rectangular area and return an array of all physics bodies that @@ -669,10 +667,10 @@ var ArcadePhysics = new Class({ * * @return {(Phaser.Physics.Arcade.Body[]|Phaser.Physics.Arcade.StaticBody[])} An array of bodies that overlap with the given area. */ - overlapRect: function (x, y, width, height, includeDynamic, includeStatic) + overlapRect(x, y, width, height, includeDynamic, includeStatic) { return OverlapRect(this.world, x, y, width, height, includeDynamic, includeStatic); - }, + } /** * This method will search the given circular area and return an array of all physics bodies that @@ -695,10 +693,10 @@ var ArcadePhysics = new Class({ * * @return {(Phaser.Physics.Arcade.Body[]|Phaser.Physics.Arcade.StaticBody[])} An array of bodies that overlap with the given area. */ - overlapCirc: function (x, y, radius, includeDynamic, includeStatic) + overlapCirc(x, y, radius, includeDynamic, includeStatic) { return OverlapCirc(this.world, x, y, radius, includeDynamic, includeStatic); - }, + } /** * The Scene that owns this plugin is shutting down. @@ -707,7 +705,7 @@ var ArcadePhysics = new Class({ * @method Phaser.Physics.Arcade.ArcadePhysics#shutdown * @since 3.0.0 */ - shutdown: function () + shutdown() { if (!this.world) { @@ -727,7 +725,7 @@ var ArcadePhysics = new Class({ this.add = null; this.world = null; this._category = 1; - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -736,7 +734,7 @@ var ArcadePhysics = new Class({ * @method Phaser.Physics.Arcade.ArcadePhysics#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -746,7 +744,7 @@ var ArcadePhysics = new Class({ this.systems = null; } -}); +}; PluginCache.register('ArcadePhysics', ArcadePhysics, 'arcadePhysics'); diff --git a/src/physics/arcade/ArcadeSprite.js b/src/physics/arcade/ArcadeSprite.js index c76fdb09cb..974d46ced1 100644 --- a/src/physics/arcade/ArcadeSprite.js +++ b/src/physics/arcade/ArcadeSprite.js @@ -56,32 +56,31 @@ var Sprite = require('../../gameobjects/sprite/Sprite'); * @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with. */ -var ArcadeSprite = new Class({ +var ArcadeSprite = class extends Sprite { - Extends: Sprite, - - Mixins: [ - Components.Acceleration, - Components.Angular, - Components.Bounce, - Components.Collision, - Components.Debug, - Components.Drag, - Components.Enable, - Components.Friction, - Components.Gravity, - Components.Immovable, - Components.Mass, - Components.Pushable, - Components.Size, - Components.Velocity - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Acceleration, + Components.Angular, + Components.Bounce, + Components.Collision, + Components.Debug, + Components.Drag, + Components.Enable, + Components.Friction, + Components.Gravity, + Components.Immovable, + Components.Mass, + Components.Pushable, + Components.Size, + Components.Velocity + ], false); + } - function ArcadeSprite (scene, x, y, texture, frame) + constructor(scene, x, y, texture, frame) { - Sprite.call(this, scene, x, y, texture, frame); + super(scene, x, y, texture, frame); /** * This Game Object's Physics Body. @@ -94,6 +93,6 @@ var ArcadeSprite = new Class({ this.body = null; } -}); +}; module.exports = ArcadeSprite; diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index bbe3150180..e7cfaa531d 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -30,15 +30,16 @@ var Vector2 = require('../../math/Vector2'); * @param {Phaser.Physics.Arcade.World} world - The Arcade Physics simulation this Body belongs to. * @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object this Body belongs to. As of Phaser 3.60 this is now optional. */ -var Body = new Class({ +var Body = class { - Mixins: [ - CollisionComponent - ], - - initialize: + static + { + Class.mixin(this, [ + CollisionComponent + ], false); + } - function Body (world, gameObject) + constructor(world, gameObject) { var width = 64; var height = 64; @@ -955,7 +956,7 @@ var Body = new Class({ * @since 3.70.0 */ this.autoFrame = this.position.clone(); - }, + } /** * Updates the Body's `transform`, `width`, `height`, and `center` from its Game Object. @@ -964,7 +965,7 @@ var Body = new Class({ * @method Phaser.Physics.Arcade.Body#updateBounds * @since 3.0.0 */ - updateBounds: function () + updateBounds() { var sprite = this.gameObject; @@ -1026,7 +1027,7 @@ var Body = new Class({ this.halfHeight = Math.floor(this.height / 2); this.updateCenter(); } - }, + } /** * Updates the Body's `center` from its `position`, `width`, and `height`. @@ -1034,10 +1035,10 @@ var Body = new Class({ * @method Phaser.Physics.Arcade.Body#updateCenter * @since 3.0.0 */ - updateCenter: function () + updateCenter() { this.center.set(this.position.x + this.halfWidth, this.position.y + this.halfHeight); - }, + } /** * Updates the Body's `position`, `width`, `height`, and `center` from its Game Object and `offset`. @@ -1051,7 +1052,7 @@ var Body = new Class({ * @method Phaser.Physics.Arcade.Body#updateFromGameObject * @since 3.24.0 */ - updateFromGameObject: function () + updateFromGameObject() { this.updateBounds(); @@ -1061,7 +1062,7 @@ var Body = new Class({ this.position.y = transform.y + transform.scaleY * (this.offset.y - transform.displayOriginY); this.updateCenter(); - }, + } /** * Prepares the Body for a physics step by resetting the `wasTouching`, `touching` and `blocked` states. @@ -1073,7 +1074,7 @@ var Body = new Class({ * * @param {boolean} [clear=false] - Set the `wasTouching` values to their defaults. */ - resetFlags: function (clear) + resetFlags(clear) { if (clear === undefined) { @@ -1106,7 +1107,7 @@ var Body = new Class({ this.overlapY = 0; this.embedded = false; - }, + } /** * Syncs the position body position with the parent Game Object. @@ -1119,7 +1120,7 @@ var Body = new Class({ * @param {boolean} willStep - Will this Body run an update as well? * @param {number} delta - The delta time, in seconds, elapsed since the last frame. */ - preUpdate: function (willStep, delta) + preUpdate(willStep, delta) { if (willStep) { @@ -1149,7 +1150,7 @@ var Body = new Class({ { this.update(delta); } - }, + } /** * Performs a single physics step and updates the body velocity, angle, speed and other properties. @@ -1164,7 +1165,7 @@ var Body = new Class({ * * @param {number} delta - The delta time, in seconds, elapsed since the last frame. */ - update: function (delta) + update(delta) { var prev = this.prev; var pos = this.position; @@ -1223,7 +1224,7 @@ var Body = new Class({ this.world.emit(Events.WORLD_BOUNDS, this, blocked.up, blocked.down, blocked.left, blocked.right); } - }, + } /** * Feeds the Body results back into the parent Game Object. @@ -1233,7 +1234,7 @@ var Body = new Class({ * @method Phaser.Physics.Arcade.Body#postUpdate * @since 3.0.0 */ - postUpdate: function () + postUpdate() { var pos = this.position; @@ -1305,7 +1306,7 @@ var Body = new Class({ this._ty = dy; this.autoFrame.set(pos.x, pos.y); - }, + } /** * Sets a custom collision boundary rectangle. Use if you want to have a custom @@ -1318,12 +1319,12 @@ var Body = new Class({ * * @return {this} This Body object. */ - setBoundsRectangle: function (bounds) + setBoundsRectangle(bounds) { this.customBoundsRectangle = (!bounds) ? this.world.bounds : bounds; return this; - }, + } /** * Checks for collisions between this Body and the world boundary and separates them. @@ -1333,7 +1334,7 @@ var Body = new Class({ * * @return {boolean} True if this Body is colliding with the world boundary. */ - checkWorldBounds: function () + checkWorldBounds() { var pos = this.position; var vel = this.velocity; @@ -1383,7 +1384,7 @@ var Body = new Class({ } return wasSet; - }, + } /** * Sets the offset of the Body's position from its Game Object's position. @@ -1397,14 +1398,14 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setOffset: function (x, y) + setOffset(x, y) { if (y === undefined) { y = x; } this.offset.set(x, y); return this; - }, + } /** * Assign this Body to a new Game Object. @@ -1424,7 +1425,7 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setGameObject: function (gameObject, enable) + setGameObject(gameObject, enable) { if (enable === undefined) { enable = true; } @@ -1460,7 +1461,7 @@ var Body = new Class({ this.enable = enable; return this; - }, + } /** * Sizes and positions this Body, as a rectangle. @@ -1476,7 +1477,7 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setSize: function (width, height, center) + setSize(width, height, center) { if (center === undefined) { center = true; } @@ -1518,7 +1519,7 @@ var Body = new Class({ this.radius = 0; return this; - }, + } /** * Sizes and positions this Body, as a circle. @@ -1532,7 +1533,7 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setCircle: function (radius, offsetX, offsetY) + setCircle(radius, offsetX, offsetY) { if (offsetX === undefined) { offsetX = this.offset.x; } if (offsetY === undefined) { offsetY = this.offset.y; } @@ -1561,7 +1562,7 @@ var Body = new Class({ } return this; - }, + } /** * Sets this Body's parent Game Object to the given coordinates and resets this Body at the new coordinates. @@ -1573,7 +1574,7 @@ var Body = new Class({ * @param {number} x - The horizontal position to place the Game Object. * @param {number} y - The vertical position to place the Game Object. */ - reset: function (x, y) + reset(x, y) { this.stop(); @@ -1615,7 +1616,7 @@ var Body = new Class({ } this.resetFlags(true); - }, + } /** * Sets acceleration, velocity, and speed to zero. @@ -1625,7 +1626,7 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - stop: function () + stop() { this.velocity.set(0); this.acceleration.set(0); @@ -1634,7 +1635,7 @@ var Body = new Class({ this.angularAcceleration = 0; return this; - }, + } /** * Copies the coordinates of this Body's edges into an object. @@ -1646,7 +1647,7 @@ var Body = new Class({ * * @return {Phaser.Types.Physics.Arcade.ArcadeBodyBounds} - An object with {x, y, right, bottom}. */ - getBounds: function (obj) + getBounds(obj) { obj.x = this.x; obj.y = this.y; @@ -1654,7 +1655,7 @@ var Body = new Class({ obj.bottom = this.bottom; return obj; - }, + } /** * Tests if the coordinates are within this Body. @@ -1667,7 +1668,7 @@ var Body = new Class({ * * @return {boolean} True if (x, y) is within this Body. */ - hitTest: function (x, y) + hitTest(x, y) { if (!this.isCircle) { @@ -1684,7 +1685,7 @@ var Body = new Class({ } return false; - }, + } /** * Whether this Body is touching a tile or the world boundary while moving down. @@ -1695,10 +1696,10 @@ var Body = new Class({ * * @return {boolean} True if touching. */ - onFloor: function () + onFloor() { return this.blocked.down; - }, + } /** * Whether this Body is touching a tile or the world boundary while moving up. @@ -1709,10 +1710,10 @@ var Body = new Class({ * * @return {boolean} True if touching. */ - onCeiling: function () + onCeiling() { return this.blocked.up; - }, + } /** * Whether this Body is touching a tile or the world boundary while moving left or right. @@ -1723,10 +1724,10 @@ var Body = new Class({ * * @return {boolean} True if touching. */ - onWall: function () + onWall() { return (this.blocked.left || this.blocked.right); - }, + } /** * The absolute (non-negative) change in this Body's horizontal position from the previous step. @@ -1736,10 +1737,10 @@ var Body = new Class({ * * @return {number} The delta value. */ - deltaAbsX: function () + deltaAbsX() { return (this._dx > 0) ? this._dx : -this._dx; - }, + } /** * The absolute (non-negative) change in this Body's vertical position from the previous step. @@ -1749,10 +1750,10 @@ var Body = new Class({ * * @return {number} The delta value. */ - deltaAbsY: function () + deltaAbsY() { return (this._dy > 0) ? this._dy : -this._dy; - }, + } /** * The change in this Body's horizontal position from the previous step. @@ -1766,10 +1767,10 @@ var Body = new Class({ * * @return {number} The delta value. */ - deltaX: function () + deltaX() { return this._dx; - }, + } /** * The change in this Body's vertical position from the previous step. @@ -1783,10 +1784,10 @@ var Body = new Class({ * * @return {number} The delta value. */ - deltaY: function () + deltaY() { return this._dy; - }, + } /** * The change in this Body's horizontal position from the previous game update. @@ -1804,10 +1805,10 @@ var Body = new Class({ * * @return {number} The final delta x value. */ - deltaXFinal: function () + deltaXFinal() { return this._tx; - }, + } /** * The change in this Body's vertical position from the previous game update. @@ -1825,10 +1826,10 @@ var Body = new Class({ * * @return {number} The final delta y value. */ - deltaYFinal: function () + deltaYFinal() { return this._ty; - }, + } /** * The change in this Body's rotation from the previous step, in degrees. @@ -1838,10 +1839,10 @@ var Body = new Class({ * * @return {number} The delta value. */ - deltaZ: function () + deltaZ() { return this.rotation - this.preRotation; - }, + } /** * Disables this Body and marks it for deletion by the simulation. @@ -1849,7 +1850,7 @@ var Body = new Class({ * @method Phaser.Physics.Arcade.Body#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.enable = false; @@ -1857,7 +1858,7 @@ var Body = new Class({ { this.world.pendingDestroy.add(this); } - }, + } /** * Draws this Body and its velocity, if enabled. @@ -1867,7 +1868,7 @@ var Body = new Class({ * * @param {Phaser.GameObjects.Graphics} graphic - The Graphics object to draw on. */ - drawDebug: function (graphic) + drawDebug(graphic) { var pos = this.position; @@ -1912,7 +1913,7 @@ var Body = new Class({ graphic.lineStyle(graphic.defaultStrokeWidth, this.world.defaults.velocityDebugColor, 1); graphic.lineBetween(x, y, x + this.velocity.x / 2, y + this.velocity.y / 2); } - }, + } /** * Whether this Body will be drawn to the debug display. @@ -1922,10 +1923,10 @@ var Body = new Class({ * * @return {boolean} True if either `debugShowBody` or `debugShowVelocity` are enabled. */ - willDrawDebug: function () + willDrawDebug() { return (this.debugShowBody || this.debugShowVelocity); - }, + } /** * Sets whether this Body should calculate its velocity based on its change in @@ -1942,14 +1943,14 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setDirectControl: function (value) + setDirectControl(value) { if (value === undefined) { value = true; } this.directControl = value; return this; - }, + } /** * Sets whether this Body collides with the world boundary. @@ -1966,7 +1967,7 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setCollideWorldBounds: function (value, bounceX, bounceY, onWorldBounds) + setCollideWorldBounds(value, bounceX, bounceY, onWorldBounds) { if (value === undefined) { value = true; } @@ -1999,7 +2000,7 @@ var Body = new Class({ } return this; - }, + } /** * Sets the Body's velocity. @@ -2012,7 +2013,7 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setVelocity: function (x, y) + setVelocity(x, y) { this.velocity.set(x, y); @@ -2022,7 +2023,7 @@ var Body = new Class({ this.speed = Math.sqrt(x * x + y * y); return this; - }, + } /** * Sets the Body's horizontal velocity. @@ -2034,10 +2035,10 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setVelocityX: function (value) + setVelocityX(value) { return this.setVelocity(value, this.velocity.y); - }, + } /** * Sets the Body's vertical velocity. @@ -2049,10 +2050,10 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setVelocityY: function (value) + setVelocityY(value) { return this.setVelocity(this.velocity.x, value); - }, + } /** * Sets the Body's maximum velocity. @@ -2065,12 +2066,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setMaxVelocity: function (x, y) + setMaxVelocity(x, y) { this.maxVelocity.set(x, y); return this; - }, + } /** * Sets the Body's maximum horizontal velocity. @@ -2082,12 +2083,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setMaxVelocityX: function (value) + setMaxVelocityX(value) { this.maxVelocity.x = value; return this; - }, + } /** * Sets the Body's maximum vertical velocity. @@ -2099,12 +2100,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setMaxVelocityY: function (value) + setMaxVelocityY(value) { this.maxVelocity.y = value; return this; - }, + } /** * Sets the maximum speed the Body can move. @@ -2116,12 +2117,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setMaxSpeed: function (value) + setMaxSpeed(value) { this.maxSpeed = value; return this; - }, + } /** * Sets the Slide Factor of this Body. @@ -2149,12 +2150,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setSlideFactor: function (x, y) + setSlideFactor(x, y) { this.slideFactor.set(x, y); return this; - }, + } /** * Sets the Body's bounce. @@ -2167,12 +2168,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setBounce: function (x, y) + setBounce(x, y) { this.bounce.set(x, y); return this; - }, + } /** * Sets the Body's horizontal bounce. @@ -2184,12 +2185,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setBounceX: function (value) + setBounceX(value) { this.bounce.x = value; return this; - }, + } /** * Sets the Body's vertical bounce. @@ -2201,12 +2202,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setBounceY: function (value) + setBounceY(value) { this.bounce.y = value; return this; - }, + } /** * Sets the Body's acceleration. @@ -2219,12 +2220,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAcceleration: function (x, y) + setAcceleration(x, y) { this.acceleration.set(x, y); return this; - }, + } /** * Sets the Body's horizontal acceleration. @@ -2236,12 +2237,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAccelerationX: function (value) + setAccelerationX(value) { this.acceleration.x = value; return this; - }, + } /** * Sets the Body's vertical acceleration. @@ -2253,12 +2254,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAccelerationY: function (value) + setAccelerationY(value) { this.acceleration.y = value; return this; - }, + } /** * Enables or disables drag. @@ -2271,14 +2272,14 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAllowDrag: function (value) + setAllowDrag(value) { if (value === undefined) { value = true; } this.allowDrag = value; return this; - }, + } /** * Enables or disables gravity's effect on this Body. @@ -2291,14 +2292,14 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAllowGravity: function (value) + setAllowGravity(value) { if (value === undefined) { value = true; } this.allowGravity = value; return this; - }, + } /** * Enables or disables rotation. @@ -2311,14 +2312,14 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAllowRotation: function (value) + setAllowRotation(value) { if (value === undefined) { value = true; } this.allowRotation = value; return this; - }, + } /** * Sets the Body's drag. @@ -2331,12 +2332,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setDrag: function (x, y) + setDrag(x, y) { this.drag.set(x, y); return this; - }, + } /** * If this Body is using `drag` for deceleration this property controls how the drag is applied. @@ -2356,12 +2357,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setDamping: function (value) + setDamping(value) { this.useDamping = value; return this; - }, + } /** * Sets the Body's horizontal drag. @@ -2373,12 +2374,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setDragX: function (value) + setDragX(value) { this.drag.x = value; return this; - }, + } /** * Sets the Body's vertical drag. @@ -2390,12 +2391,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setDragY: function (value) + setDragY(value) { this.drag.y = value; return this; - }, + } /** * Sets the Body's gravity. @@ -2408,12 +2409,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setGravity: function (x, y) + setGravity(x, y) { this.gravity.set(x, y); return this; - }, + } /** * Sets the Body's horizontal gravity. @@ -2425,12 +2426,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setGravityX: function (value) + setGravityX(value) { this.gravity.x = value; return this; - }, + } /** * Sets the Body's vertical gravity. @@ -2442,12 +2443,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setGravityY: function (value) + setGravityY(value) { this.gravity.y = value; return this; - }, + } /** * Sets the Body's friction. @@ -2460,12 +2461,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setFriction: function (x, y) + setFriction(x, y) { this.friction.set(x, y); return this; - }, + } /** * Sets the Body's horizontal friction. @@ -2477,12 +2478,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setFrictionX: function (value) + setFrictionX(value) { this.friction.x = value; return this; - }, + } /** * Sets the Body's vertical friction. @@ -2494,12 +2495,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setFrictionY: function (value) + setFrictionY(value) { this.friction.y = value; return this; - }, + } /** * Sets the Body's angular velocity. @@ -2511,12 +2512,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAngularVelocity: function (value) + setAngularVelocity(value) { this.angularVelocity = value; return this; - }, + } /** * Sets the Body's angular acceleration. @@ -2528,12 +2529,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAngularAcceleration: function (value) + setAngularAcceleration(value) { this.angularAcceleration = value; return this; - }, + } /** * Sets the Body's angular drag. @@ -2545,12 +2546,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setAngularDrag: function (value) + setAngularDrag(value) { this.angularDrag = value; return this; - }, + } /** * Sets the Body's mass. @@ -2562,12 +2563,12 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setMass: function (value) + setMass(value) { this.mass = value; return this; - }, + } /** * Sets the Body's `immovable` property. @@ -2579,14 +2580,14 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setImmovable: function (value) + setImmovable(value) { if (value === undefined) { value = true; } this.immovable = value; return this; - }, + } /** * Sets the Body's `enable` property. @@ -2598,14 +2599,14 @@ var Body = new Class({ * * @return {Phaser.Physics.Arcade.Body} This Body object. */ - setEnable: function (value) + setEnable(value) { if (value === undefined) { value = true; } this.enable = value; return this; - }, + } /** * This is an internal handler, called by the `ProcessX` function as part @@ -2619,7 +2620,7 @@ var Body = new Class({ * @param {boolean} [left] - Set the blocked.left value? * @param {boolean} [right] - Set the blocked.right value? */ - processX: function (x, vx, left, right) + processX(x, vx, left, right) { this.x += x; @@ -2643,7 +2644,7 @@ var Body = new Class({ blocked.right = true; blocked.none = false; } - }, + } /** * This is an internal handler, called by the `ProcessY` function as part @@ -2657,7 +2658,7 @@ var Body = new Class({ * @param {boolean} [up] - Set the blocked.up value? * @param {boolean} [down] - Set the blocked.down value? */ - processY: function (y, vy, up, down) + processY(y, vy, up, down) { this.y += y; @@ -2681,7 +2682,7 @@ var Body = new Class({ blocked.down = true; blocked.none = false; } - }, + } /** * The Bodys horizontal position (left edge). @@ -2690,19 +2691,16 @@ var Body = new Class({ * @type {number} * @since 3.0.0 */ - x: { - get: function () - { - return this.position.x; - }, - - set: function (value) - { - this.position.x = value; - } + get x() + { + return this.position.x; + } - }, + set x(value) + { + this.position.x = value; + } /** * The Bodys vertical position (top edge). @@ -2711,19 +2709,16 @@ var Body = new Class({ * @type {number} * @since 3.0.0 */ - y: { - get: function () - { - return this.position.y; - }, - - set: function (value) - { - this.position.y = value; - } + get y() + { + return this.position.y; + } - }, + set y(value) + { + this.position.y = value; + } /** * The left edge of the Body. Identical to x. @@ -2733,14 +2728,11 @@ var Body = new Class({ * @readonly * @since 3.0.0 */ - left: { - get: function () - { - return this.position.x; - } - - }, + get left() + { + return this.position.x; + } /** * The right edge of the Body. @@ -2750,14 +2742,11 @@ var Body = new Class({ * @readonly * @since 3.0.0 */ - right: { - - get: function () - { - return this.position.x + this.width; - } - }, + get right() + { + return this.position.x + this.width; + } /** * The top edge of the Body. Identical to y. @@ -2767,14 +2756,11 @@ var Body = new Class({ * @readonly * @since 3.0.0 */ - top: { - - get: function () - { - return this.position.y; - } - }, + get top() + { + return this.position.y; + } /** * The bottom edge of this Body. @@ -2784,15 +2770,12 @@ var Body = new Class({ * @readonly * @since 3.0.0 */ - bottom: { - - get: function () - { - return this.position.y + this.height; - } + get bottom() + { + return this.position.y + this.height; } -}); +}; module.exports = Body; diff --git a/src/physics/arcade/Collider.js b/src/physics/arcade/Collider.js index a547a03f6e..070c38c768 100644 --- a/src/physics/arcade/Collider.js +++ b/src/physics/arcade/Collider.js @@ -27,11 +27,9 @@ var Class = require('../../utils/Class'); * @param {Phaser.Types.Physics.Arcade.ArcadePhysicsCallback} processCallback - The callback to invoke when the two objects collide. Must return a boolean. * @param {any} callbackContext - The scope in which to call the callbacks. */ -var Collider = new Class({ +var Collider = class { - initialize: - - function Collider (world, overlapOnly, object1, object2, collideCallback, processCallback, callbackContext) + constructor(world, overlapOnly, object1, object2, collideCallback, processCallback, callbackContext) { /** * The world in which the bodies will collide. @@ -114,7 +112,7 @@ var Collider = new Class({ * @since 3.0.0 */ this.callbackContext = callbackContext; - }, + } /** * A name for the Collider. @@ -128,12 +126,12 @@ var Collider = new Class({ * * @return {Phaser.Physics.Arcade.Collider} This Collider instance. */ - setName: function (name) + setName(name) { this.name = name; return this; - }, + } /** * Called by World as part of its step processing, initial operation of collision checking. @@ -141,7 +139,7 @@ var Collider = new Class({ * @method Phaser.Physics.Arcade.Collider#update * @since 3.0.0 */ - update: function () + update() { this.world.collideObjects( this.object1, @@ -151,7 +149,7 @@ var Collider = new Class({ this.callbackContext, this.overlapOnly ); - }, + } /** * Removes Collider from World and disposes of its resources. @@ -159,7 +157,7 @@ var Collider = new Class({ * @method Phaser.Physics.Arcade.Collider#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.world.removeCollider(this); @@ -175,6 +173,6 @@ var Collider = new Class({ this.callbackContext = null; } -}); +}; module.exports = Collider; diff --git a/src/physics/arcade/Factory.js b/src/physics/arcade/Factory.js index 29dea25784..05b86e7258 100644 --- a/src/physics/arcade/Factory.js +++ b/src/physics/arcade/Factory.js @@ -25,11 +25,9 @@ var StaticPhysicsGroup = require('./StaticPhysicsGroup'); * * @param {Phaser.Physics.Arcade.World} world - The Arcade Physics World instance. */ -var Factory = new Class({ +var Factory = class { - initialize: - - function Factory (world) + constructor(world) { /** * A reference to the Arcade Physics World. @@ -57,7 +55,7 @@ var Factory = new Class({ * @since 3.0.0 */ this.sys = world.scene.sys; - }, + } /** * Creates a new Arcade Physics Collider object. @@ -73,10 +71,10 @@ var Factory = new Class({ * * @return {Phaser.Physics.Arcade.Collider} The Collider that was created. */ - collider: function (object1, object2, collideCallback, processCallback, callbackContext) + collider(object1, object2, collideCallback, processCallback, callbackContext) { return this.world.addCollider(object1, object2, collideCallback, processCallback, callbackContext); - }, + } /** * Creates a new Arcade Physics Collider Overlap object. @@ -92,10 +90,10 @@ var Factory = new Class({ * * @return {Phaser.Physics.Arcade.Collider} The Collider that was created. */ - overlap: function (object1, object2, collideCallback, processCallback, callbackContext) + overlap(object1, object2, collideCallback, processCallback, callbackContext) { return this.world.addOverlap(object1, object2, collideCallback, processCallback, callbackContext); - }, + } /** * Adds an Arcade Physics Body to the given Game Object. @@ -110,14 +108,14 @@ var Factory = new Class({ * * @return {Phaser.Types.Physics.Arcade.GameObjectWithBody} The Game Object. */ - existing: function (gameObject, isStatic) + existing(gameObject, isStatic) { var type = (isStatic) ? CONST.STATIC_BODY : CONST.DYNAMIC_BODY; this.world.enableBody(gameObject, type); return gameObject; - }, + } /** * Creates a new Arcade Image object with a Static body. @@ -132,7 +130,7 @@ var Factory = new Class({ * * @return {Phaser.Types.Physics.Arcade.ImageWithStaticBody} The Image object that was created. */ - staticImage: function (x, y, key, frame) + staticImage(x, y, key, frame) { var image = new ArcadeImage(this.scene, x, y, key, frame); @@ -141,7 +139,7 @@ var Factory = new Class({ this.world.enableBody(image, CONST.STATIC_BODY); return image; - }, + } /** * Creates a new Arcade Image object with a Dynamic body. @@ -156,7 +154,7 @@ var Factory = new Class({ * * @return {Phaser.Types.Physics.Arcade.ImageWithDynamicBody} The Image object that was created. */ - image: function (x, y, key, frame) + image(x, y, key, frame) { var image = new ArcadeImage(this.scene, x, y, key, frame); @@ -165,7 +163,7 @@ var Factory = new Class({ this.world.enableBody(image, CONST.DYNAMIC_BODY); return image; - }, + } /** * Creates a new Arcade Sprite object with a Static body. @@ -180,7 +178,7 @@ var Factory = new Class({ * * @return {Phaser.Types.Physics.Arcade.SpriteWithStaticBody} The Sprite object that was created. */ - staticSprite: function (x, y, key, frame) + staticSprite(x, y, key, frame) { var sprite = new ArcadeSprite(this.scene, x, y, key, frame); @@ -190,7 +188,7 @@ var Factory = new Class({ this.world.enableBody(sprite, CONST.STATIC_BODY); return sprite; - }, + } /** * Creates a new Arcade Sprite object with a Dynamic body. @@ -205,7 +203,7 @@ var Factory = new Class({ * * @return {Phaser.Types.Physics.Arcade.SpriteWithDynamicBody} The Sprite object that was created. */ - sprite: function (x, y, key, frame) + sprite(x, y, key, frame) { var sprite = new ArcadeSprite(this.scene, x, y, key, frame); @@ -215,7 +213,7 @@ var Factory = new Class({ this.world.enableBody(sprite, CONST.DYNAMIC_BODY); return sprite; - }, + } /** * Creates a Static Physics Group object. @@ -229,10 +227,10 @@ var Factory = new Class({ * * @return {Phaser.Physics.Arcade.StaticGroup} The Static Group object that was created. */ - staticGroup: function (children, config) + staticGroup(children, config) { return this.sys.updateList.add(new StaticPhysicsGroup(this.world, this.world.scene, children, config)); - }, + } /** * Creates a Physics Group object. @@ -246,10 +244,10 @@ var Factory = new Class({ * * @return {Phaser.Physics.Arcade.Group} The Group object that was created. */ - group: function (children, config) + group(children, config) { return this.sys.updateList.add(new PhysicsGroup(this.world, this.world.scene, children, config)); - }, + } /** * Creates a new physics Body with the given position and size. @@ -267,7 +265,7 @@ var Factory = new Class({ * * @return {Phaser.Physics.Arcade.Body} The Body that was created. */ - body: function (x, y, width, height) + body(x, y, width, height) { var body = new Body(this.world); @@ -281,7 +279,7 @@ var Factory = new Class({ this.world.add(body, CONST.DYNAMIC_BODY); return body; - }, + } /** * Creates a new static physics Body with the given position and size. @@ -299,7 +297,7 @@ var Factory = new Class({ * * @return {Phaser.Physics.Arcade.StaticBody} The Static Body that was created. */ - staticBody: function (x, y, width, height) + staticBody(x, y, width, height) { var body = new StaticBody(this.world); @@ -313,7 +311,7 @@ var Factory = new Class({ this.world.add(body, CONST.STATIC_BODY); return body; - }, + } /** * Destroys this Factory. @@ -321,13 +319,13 @@ var Factory = new Class({ * @method Phaser.Physics.Arcade.Factory#destroy * @since 3.5.0 */ - destroy: function () + destroy() { this.world = null; this.scene = null; this.sys = null; } -}); +}; module.exports = Factory; diff --git a/src/physics/arcade/PhysicsGroup.js b/src/physics/arcade/PhysicsGroup.js index f6b3b492f8..2745ae4551 100644 --- a/src/physics/arcade/PhysicsGroup.js +++ b/src/physics/arcade/PhysicsGroup.js @@ -43,17 +43,16 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {(Phaser.GameObjects.GameObject[]|Phaser.Types.Physics.Arcade.PhysicsGroupConfig|Phaser.Types.GameObjects.Group.GroupCreateConfig)} [children] - Game Objects to add to this group; or the `config` argument. * @param {Phaser.Types.Physics.Arcade.PhysicsGroupConfig|Phaser.Types.GameObjects.Group.GroupCreateConfig} [config] - Settings for this group. */ -var PhysicsGroup = new Class({ +var PhysicsGroup = class extends Group { - Extends: Group, - - Mixins: [ - CollisionComponent - ], - - initialize: + static + { + Class.mixin(this, [ + CollisionComponent + ], false); + } - function PhysicsGroup (world, scene, children, config) + constructor(world, scene, children, config) { if (!children && !config) { @@ -192,7 +191,7 @@ var PhysicsGroup = new Class({ setImmovable: GetFastValue(config, 'immovable', false) }; - Group.call(this, scene, children, config); + super(scene, children, config); /** * A textual representation of this Game Object. @@ -204,7 +203,7 @@ var PhysicsGroup = new Class({ * @since 3.21.0 */ this.type = 'PhysicsGroup'; - }, + } /** * Enables a Game Object's Body and assigns `defaults`. Called when a Group member is added or created. @@ -214,7 +213,7 @@ var PhysicsGroup = new Class({ * * @param {Phaser.GameObjects.GameObject} child - The Game Object being added. */ - createCallbackHandler: function (child) + createCallbackHandler(child) { if (!child.body) { @@ -227,7 +226,7 @@ var PhysicsGroup = new Class({ { body[key](this.defaults[key]); } - }, + } /** * Disables a Game Object's Body. Called when a Group member is removed. @@ -237,13 +236,13 @@ var PhysicsGroup = new Class({ * * @param {Phaser.GameObjects.GameObject} child - The Game Object being removed. */ - removeCallbackHandler: function (child) + removeCallbackHandler(child) { if (child.body) { this.world.disableBody(child); } - }, + } /** * Sets the velocity of each Group member. @@ -257,7 +256,7 @@ var PhysicsGroup = new Class({ * * @return {Phaser.Physics.Arcade.Group} This Physics Group object. */ - setVelocity: function (x, y, step) + setVelocity(x, y, step) { if (step === undefined) { step = 0; } @@ -269,7 +268,7 @@ var PhysicsGroup = new Class({ } return this; - }, + } /** * Sets the horizontal velocity of each Group member. @@ -282,7 +281,7 @@ var PhysicsGroup = new Class({ * * @return {Phaser.Physics.Arcade.Group} This Physics Group object. */ - setVelocityX: function (value, step) + setVelocityX(value, step) { if (step === undefined) { step = 0; } @@ -294,7 +293,7 @@ var PhysicsGroup = new Class({ } return this; - }, + } /** * Sets the vertical velocity of each Group member. @@ -307,7 +306,7 @@ var PhysicsGroup = new Class({ * * @return {Phaser.Physics.Arcade.Group} This Physics Group object. */ - setVelocityY: function (value, step) + setVelocityY(value, step) { if (step === undefined) { step = 0; } @@ -321,6 +320,6 @@ var PhysicsGroup = new Class({ return this; } -}); +}; module.exports = PhysicsGroup; diff --git a/src/physics/arcade/StaticBody.js b/src/physics/arcade/StaticBody.js index 23d5890197..ef42657d14 100644 --- a/src/physics/arcade/StaticBody.js +++ b/src/physics/arcade/StaticBody.js @@ -33,15 +33,16 @@ var Vector2 = require('../../math/Vector2'); * @param {Phaser.Physics.Arcade.World} world - The Arcade Physics simulation this Static Body belongs to. * @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object this Body belongs to. As of Phaser 3.60 this is now optional. */ -var StaticBody = new Class({ +var StaticBody = class { - Mixins: [ - CollisionComponent - ], - - initialize: + static + { + Class.mixin(this, [ + CollisionComponent + ], false); + } - function StaticBody (world, gameObject) + constructor(world, gameObject) { var width = 64; var height = 64; @@ -503,7 +504,7 @@ var StaticBody = new Class({ * @since 3.10.0 */ this._dy = 0; - }, + } /** * Changes the Game Object this Body is bound to. @@ -524,7 +525,7 @@ var StaticBody = new Class({ * * @see Phaser.Physics.Arcade.StaticBody#updateFromGameObject */ - setGameObject: function (gameObject, update, enable) + setGameObject(gameObject, update, enable) { if (update === undefined) { update = true; } if (enable === undefined) { enable = true; } @@ -566,7 +567,7 @@ var StaticBody = new Class({ this.enable = enable; return this; - }, + } /** * Syncs the Static Body's position and size with its parent Game Object. @@ -576,7 +577,7 @@ var StaticBody = new Class({ * * @return {Phaser.Physics.Arcade.StaticBody} This Static Body object. */ - updateFromGameObject: function () + updateFromGameObject() { this.world.staticTree.remove(this); @@ -595,7 +596,7 @@ var StaticBody = new Class({ this.world.staticTree.insert(this); return this; - }, + } /** * Positions the Static Body at an offset from its Game Object. @@ -608,7 +609,7 @@ var StaticBody = new Class({ * * @return {Phaser.Physics.Arcade.StaticBody} This Static Body object. */ - setOffset: function (x, y) + setOffset(x, y) { if (y === undefined) { y = x; } @@ -627,7 +628,7 @@ var StaticBody = new Class({ this.world.staticTree.insert(this); return this; - }, + } /** * Sets the size of the Static Body. @@ -643,7 +644,7 @@ var StaticBody = new Class({ * * @return {Phaser.Physics.Arcade.StaticBody} This Static Body object. */ - setSize: function (width, height, center) + setSize(width, height, center) { if (center === undefined) { center = true; } @@ -692,7 +693,7 @@ var StaticBody = new Class({ this.world.staticTree.insert(this); return this; - }, + } /** * Sets this Static Body to have a circular body and sets its size and position. @@ -706,7 +707,7 @@ var StaticBody = new Class({ * * @return {Phaser.Physics.Arcade.StaticBody} This Static Body object. */ - setCircle: function (radius, offsetX, offsetY) + setCircle(radius, offsetX, offsetY) { if (offsetX === undefined) { offsetX = this.offset.x; } if (offsetY === undefined) { offsetY = this.offset.y; } @@ -737,7 +738,7 @@ var StaticBody = new Class({ } return this; - }, + } /** * Updates the StaticBody's `center` from its `position` and dimensions. @@ -745,10 +746,10 @@ var StaticBody = new Class({ * @method Phaser.Physics.Arcade.StaticBody#updateCenter * @since 3.0.0 */ - updateCenter: function () + updateCenter() { this.center.set(this.position.x + this.halfWidth, this.position.y + this.halfHeight); - }, + } /** * Resets this Static Body to its parent Game Object's position. @@ -762,7 +763,7 @@ var StaticBody = new Class({ * @param {number} [x] - The x coordinate to reset the body to. If not given will use the parent Game Object's coordinate. * @param {number} [y] - The y coordinate to reset the body to. If not given will use the parent Game Object's coordinate. */ - reset: function (x, y) + reset(x, y) { var gameObject = this.gameObject; @@ -781,7 +782,7 @@ var StaticBody = new Class({ this.updateCenter(); this.world.staticTree.insert(this); - }, + } /** * NOOP function. A Static Body cannot be stopped. @@ -791,10 +792,10 @@ var StaticBody = new Class({ * * @return {Phaser.Physics.Arcade.StaticBody} This Static Body object. */ - stop: function () + stop() { return this; - }, + } /** * Returns the x and y coordinates of the top left and bottom right points of the StaticBody. @@ -806,7 +807,7 @@ var StaticBody = new Class({ * * @return {Phaser.Types.Physics.Arcade.ArcadeBodyBounds} The same object that was passed with `x`, `y`, `right` and `bottom` values matching the respective values of the StaticBody. */ - getBounds: function (obj) + getBounds(obj) { obj.x = this.x; obj.y = this.y; @@ -814,7 +815,7 @@ var StaticBody = new Class({ obj.bottom = this.bottom; return obj; - }, + } /** * Checks to see if a given x,y coordinate is colliding with this Static Body. @@ -827,10 +828,10 @@ var StaticBody = new Class({ * * @return {boolean} `true` if the given coordinate lies within this body, otherwise `false`. */ - hitTest: function (x, y) + hitTest(x, y) { return (this.isCircle) ? CircleContains(this, x, y) : RectangleContains(this, x, y); - }, + } /** * NOOP @@ -838,9 +839,9 @@ var StaticBody = new Class({ * @method Phaser.Physics.Arcade.StaticBody#postUpdate * @since 3.12.0 */ - postUpdate: function () + postUpdate() { - }, + } /** * The absolute (non-negative) change in this StaticBody's horizontal position from the previous step. Always zero. @@ -850,10 +851,10 @@ var StaticBody = new Class({ * * @return {number} Always zero for a Static Body. */ - deltaAbsX: function () + deltaAbsX() { return 0; - }, + } /** * The absolute (non-negative) change in this StaticBody's vertical position from the previous step. Always zero. @@ -863,10 +864,10 @@ var StaticBody = new Class({ * * @return {number} Always zero for a Static Body. */ - deltaAbsY: function () + deltaAbsY() { return 0; - }, + } /** * The change in this StaticBody's horizontal position from the previous step. Always zero. @@ -876,10 +877,10 @@ var StaticBody = new Class({ * * @return {number} The change in this StaticBody's velocity from the previous step. Always zero. */ - deltaX: function () + deltaX() { return 0; - }, + } /** * The change in this StaticBody's vertical position from the previous step. Always zero. @@ -889,10 +890,10 @@ var StaticBody = new Class({ * * @return {number} The change in this StaticBody's velocity from the previous step. Always zero. */ - deltaY: function () + deltaY() { return 0; - }, + } /** * The change in this StaticBody's rotation from the previous step. Always zero. @@ -902,10 +903,10 @@ var StaticBody = new Class({ * * @return {number} The change in this StaticBody's rotation from the previous step. Always zero. */ - deltaZ: function () + deltaZ() { return 0; - }, + } /** * Disables this Body and marks it for destruction during the next step. @@ -913,12 +914,12 @@ var StaticBody = new Class({ * @method Phaser.Physics.Arcade.StaticBody#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.enable = false; this.world.pendingDestroy.add(this); - }, + } /** * Draws a graphical representation of the StaticBody for visual debugging purposes. @@ -928,7 +929,7 @@ var StaticBody = new Class({ * * @param {Phaser.GameObjects.Graphics} graphic - The Graphics object to use for the debug drawing of the StaticBody. */ - drawDebug: function (graphic) + drawDebug(graphic) { var pos = this.position; @@ -949,7 +950,7 @@ var StaticBody = new Class({ } } - }, + } /** * Indicates whether the StaticBody is going to be showing a debug visualization during postUpdate. @@ -959,10 +960,10 @@ var StaticBody = new Class({ * * @return {boolean} Whether or not the StaticBody is going to show the debug visualization during postUpdate. */ - willDrawDebug: function () + willDrawDebug() { return this.debugShowBody; - }, + } /** * Sets the Mass of the StaticBody. Will set the Mass to 0.1 if the value passed is less than or equal to zero. @@ -974,7 +975,7 @@ var StaticBody = new Class({ * * @return {Phaser.Physics.Arcade.StaticBody} This Static Body object. */ - setMass: function (value) + setMass(value) { if (value <= 0) { @@ -985,7 +986,7 @@ var StaticBody = new Class({ this.mass = value; return this; - }, + } /** * The x coordinate of the StaticBody. @@ -994,23 +995,20 @@ var StaticBody = new Class({ * @type {number} * @since 3.0.0 */ - x: { - - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.world.staticTree.remove(this); + get x() + { + return this.position.x; + } - this.position.x = value; + set x(value) + { + this.world.staticTree.remove(this); - this.world.staticTree.insert(this); - } + this.position.x = value; - }, + this.world.staticTree.insert(this); + } /** * The y coordinate of the StaticBody. @@ -1019,23 +1017,20 @@ var StaticBody = new Class({ * @type {number} * @since 3.0.0 */ - y: { - get: function () - { - return this.position.y; - }, - - set: function (value) - { - this.world.staticTree.remove(this); + get y() + { + return this.position.y; + } - this.position.y = value; + set y(value) + { + this.world.staticTree.remove(this); - this.world.staticTree.insert(this); - } + this.position.y = value; - }, + this.world.staticTree.insert(this); + } /** * Returns the left-most x coordinate of the area of the StaticBody. @@ -1045,14 +1040,11 @@ var StaticBody = new Class({ * @readonly * @since 3.0.0 */ - left: { - - get: function () - { - return this.position.x; - } - }, + get left() + { + return this.position.x; + } /** * The right-most x coordinate of the area of the StaticBody. @@ -1062,14 +1054,11 @@ var StaticBody = new Class({ * @readonly * @since 3.0.0 */ - right: { - - get: function () - { - return this.position.x + this.width; - } - }, + get right() + { + return this.position.x + this.width; + } /** * The highest y coordinate of the area of the StaticBody. @@ -1079,14 +1068,11 @@ var StaticBody = new Class({ * @readonly * @since 3.0.0 */ - top: { - - get: function () - { - return this.position.y; - } - }, + get top() + { + return this.position.y; + } /** * The lowest y coordinate of the area of the StaticBody. (y + height) @@ -1096,15 +1082,12 @@ var StaticBody = new Class({ * @readonly * @since 3.0.0 */ - bottom: { - - get: function () - { - return this.position.y + this.height; - } + get bottom() + { + return this.position.y + this.height; } -}); +}; module.exports = StaticBody; diff --git a/src/physics/arcade/StaticPhysicsGroup.js b/src/physics/arcade/StaticPhysicsGroup.js index 279c3ba51b..505451e9ee 100644 --- a/src/physics/arcade/StaticPhysicsGroup.js +++ b/src/physics/arcade/StaticPhysicsGroup.js @@ -33,17 +33,16 @@ var IsPlainObject = require('../../utils/object/IsPlainObject'); * @param {(Phaser.GameObjects.GameObject[]|Phaser.Types.GameObjects.Group.GroupConfig|Phaser.Types.GameObjects.Group.GroupCreateConfig)} [children] - Game Objects to add to this group; or the `config` argument. * @param {Phaser.Types.GameObjects.Group.GroupConfig|Phaser.Types.GameObjects.Group.GroupCreateConfig} [config] - Settings for this group. */ -var StaticPhysicsGroup = new Class({ +var StaticPhysicsGroup = class extends Group { - Extends: Group, - - Mixins: [ - CollisionComponent - ], - - initialize: + static + { + Class.mixin(this, [ + CollisionComponent + ], false); + } - function StaticPhysicsGroup (world, scene, children, config) + constructor(world, scene, children, config) { if (!children && !config) { @@ -131,7 +130,7 @@ var StaticPhysicsGroup = new Class({ */ this.collisionMask = 1; - Group.call(this, scene, children, config); + super(scene, children, config); /** * A textual representation of this Game Object. @@ -143,7 +142,7 @@ var StaticPhysicsGroup = new Class({ * @since 3.21.0 */ this.type = 'StaticPhysicsGroup'; - }, + } /** * Adds a static physics body to the new group member (if it lacks one) and adds it to the simulation. @@ -155,13 +154,13 @@ var StaticPhysicsGroup = new Class({ * * @see Phaser.Physics.Arcade.World#enableBody */ - createCallbackHandler: function (child) + createCallbackHandler(child) { if (!child.body) { this.world.enableBody(child, CONST.STATIC_BODY); } - }, + } /** * Disables the group member's physics body, removing it from the simulation. @@ -173,13 +172,13 @@ var StaticPhysicsGroup = new Class({ * * @see Phaser.Physics.Arcade.World#disableBody */ - removeCallbackHandler: function (child) + removeCallbackHandler(child) { if (child.body) { this.world.disableBody(child); } - }, + } /** * Refreshes the group. @@ -191,10 +190,10 @@ var StaticPhysicsGroup = new Class({ * * @see Phaser.Physics.Arcade.StaticGroup#refresh */ - createMultipleCallbackHandler: function () + createMultipleCallbackHandler() { this.refresh(); - }, + } /** * Resets each Body to the position of its parent Game Object. @@ -207,7 +206,7 @@ var StaticPhysicsGroup = new Class({ * * @see Phaser.Physics.Arcade.StaticBody#reset */ - refresh: function () + refresh() { var children = Array.from(this.children); @@ -219,6 +218,6 @@ var StaticPhysicsGroup = new Class({ return this; } -}); +}; module.exports = StaticPhysicsGroup; diff --git a/src/physics/arcade/World.js b/src/physics/arcade/World.js index 7d70bf7b1a..9a6851e8ad 100644 --- a/src/physics/arcade/World.js +++ b/src/physics/arcade/World.js @@ -52,15 +52,11 @@ var Wrap = require('../../math/Wrap'); * @param {Phaser.Scene} scene - The Scene to which this World instance belongs. * @param {Phaser.Types.Physics.Arcade.ArcadeWorldConfig} config - An Arcade Physics Configuration object. */ -var World = new Class({ +var World = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function World (scene, config) + constructor(scene, config) { - EventEmitter.call(this); + super(); /** * The Scene this simulation belongs to. @@ -412,7 +408,7 @@ var World = new Class({ { this.createDebugGraphic(); } - }, + } /** * Adds an Arcade Physics Body to a Game Object, an array of Game Objects, or the children of a Group. @@ -443,7 +439,7 @@ var World = new Class({ * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]|Phaser.GameObjects.Group|Phaser.GameObjects.Group[])} object - The object, or objects, on which to create the bodies. * @param {number} [bodyType] - The type of Body to create. Either `DYNAMIC_BODY` or `STATIC_BODY`. */ - enable: function (object, bodyType) + enable(object, bodyType) { if (bodyType === undefined) { bodyType = CONST.DYNAMIC_BODY; } @@ -480,7 +476,7 @@ var World = new Class({ this.enableBody(entry, bodyType); } } - }, + } /** * Creates an Arcade Physics Body on a single Game Object. @@ -512,7 +508,7 @@ var World = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object on which the body was created. */ - enableBody: function (object, bodyType) + enableBody(object, bodyType) { if (bodyType === undefined) { bodyType = CONST.DYNAMIC_BODY; } @@ -534,7 +530,7 @@ var World = new Class({ } return object; - }, + } /** * Adds an existing Arcade Physics Body or StaticBody to the simulation. @@ -548,7 +544,7 @@ var World = new Class({ * * @return {(Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody)} The Body that was added to the simulation. */ - add: function (body) + add(body) { if (body.physicsType === CONST.DYNAMIC_BODY) { @@ -564,7 +560,7 @@ var World = new Class({ body.enable = true; return body; - }, + } /** * Disables the Arcade Physics Body of a Game Object, an array of Game Objects, or the children of a Group. @@ -580,7 +576,7 @@ var World = new Class({ * * @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]|Phaser.GameObjects.Group|Phaser.GameObjects.Group[])} object - The object, or objects, on which to disable the bodies. */ - disable: function (object) + disable(object) { if (!Array.isArray(object)) { @@ -615,7 +611,7 @@ var World = new Class({ this.disableBody(entry.body); } } - }, + } /** * Disables an existing Arcade Physics Body or StaticBody and removes it from the simulation. @@ -630,12 +626,12 @@ var World = new Class({ * * @param {(Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody)} body - The Body to be disabled. */ - disableBody: function (body) + disableBody(body) { this.remove(body); body.enable = false; - }, + } /** * Removes an existing Arcade Physics Body or StaticBody from the simulation. @@ -650,7 +646,7 @@ var World = new Class({ * * @param {(Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody)} body - The body to be removed from the simulation. */ - remove: function (body) + remove(body) { if (body.physicsType === CONST.DYNAMIC_BODY) { @@ -662,7 +658,7 @@ var World = new Class({ this.staticBodies.delete(body); this.staticTree.remove(body); } - }, + } /** * Creates a Graphics Game Object that the world will use to render the debug display to. @@ -681,7 +677,7 @@ var World = new Class({ * * @return {Phaser.GameObjects.Graphics} The Graphics object that was created for use by the World. */ - createDebugGraphic: function () + createDebugGraphic() { var graphic = this.scene.sys.add.graphics({ x: 0, y: 0 }); @@ -692,7 +688,7 @@ var World = new Class({ this.drawDebug = true; return graphic; - }, + } /** * Sets the position, size and properties of the World boundary. @@ -716,7 +712,7 @@ var World = new Class({ * * @return {Phaser.Physics.Arcade.World} This World object. */ - setBounds: function (x, y, width, height, checkLeft, checkRight, checkUp, checkDown) + setBounds(x, y, width, height, checkLeft, checkRight, checkUp, checkDown) { this.bounds.setTo(x, y, width, height); @@ -726,7 +722,7 @@ var World = new Class({ } return this; - }, + } /** * Enables or disables collisions on each edge of the World boundary. @@ -741,7 +737,7 @@ var World = new Class({ * * @return {Phaser.Physics.Arcade.World} This World object. */ - setBoundsCollision: function (left, right, up, down) + setBoundsCollision(left, right, up, down) { if (left === undefined) { left = true; } if (right === undefined) { right = true; } @@ -754,7 +750,7 @@ var World = new Class({ this.checkCollision.down = down; return this; - }, + } /** * Pauses the simulation. @@ -770,14 +766,14 @@ var World = new Class({ * * @return {Phaser.Physics.Arcade.World} This World object. */ - pause: function () + pause() { this.isPaused = true; this.emit(Events.PAUSE); return this; - }, + } /** * Resumes the simulation, if paused. @@ -788,14 +784,14 @@ var World = new Class({ * * @return {Phaser.Physics.Arcade.World} This World object. */ - resume: function () + resume() { this.isPaused = false; this.emit(Events.RESUME); return this; - }, + } /** * Creates a new Collider object and adds it to the simulation. @@ -820,7 +816,7 @@ var World = new Class({ * * @return {Phaser.Physics.Arcade.Collider} The Collider that was created. */ - addCollider: function (object1, object2, collideCallback, processCallback, callbackContext) + addCollider(object1, object2, collideCallback, processCallback, callbackContext) { if (collideCallback === undefined) { collideCallback = null; } if (processCallback === undefined) { processCallback = null; } @@ -831,7 +827,7 @@ var World = new Class({ this.colliders.add(collider); return collider; - }, + } /** * Creates a new Overlap Collider object and adds it to the simulation. @@ -855,7 +851,7 @@ var World = new Class({ * * @return {Phaser.Physics.Arcade.Collider} The Collider that was created. */ - addOverlap: function (object1, object2, collideCallback, processCallback, callbackContext) + addOverlap(object1, object2, collideCallback, processCallback, callbackContext) { if (collideCallback === undefined) { collideCallback = null; } if (processCallback === undefined) { processCallback = null; } @@ -866,7 +862,7 @@ var World = new Class({ this.colliders.add(collider); return collider; - }, + } /** * Removes a Collider from the simulation so it is no longer processed. @@ -885,12 +881,12 @@ var World = new Class({ * * @return {Phaser.Physics.Arcade.World} This World object. */ - removeCollider: function (collider) + removeCollider(collider) { this.colliders.remove(collider); return this; - }, + } /** * Sets the frame rate to run the simulation at. @@ -911,14 +907,14 @@ var World = new Class({ * * @return {this} This World object. */ - setFPS: function (framerate) + setFPS(framerate) { this.fps = framerate; this._frameTime = 1 / this.fps; this._frameTimeMS = 1000 * this._frameTime; return this; - }, + } /** * Advances the simulation based on the elapsed time and fps rate. @@ -932,7 +928,7 @@ var World = new Class({ * @param {number} 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) + update(time, delta) { if (this.isPaused || this.bodies.size === 0) { @@ -1003,7 +999,7 @@ var World = new Class({ this.step(fixedDelta); } - }, + } /** * Advances the simulation by a time increment. @@ -1014,7 +1010,7 @@ var World = new Class({ * * @param {number} delta - The delta time amount, in seconds, by which to advance the simulation. */ - step: function (delta) + step(delta) { // Update all active bodies var bodies = this.bodies; @@ -1050,7 +1046,7 @@ var World = new Class({ this.emit(Events.WORLD_STEP, delta); this.stepsLastFrame++; - }, + } /** * Advances the simulation by a single step. @@ -1059,12 +1055,12 @@ var World = new Class({ * @fires Phaser.Physics.Arcade.Events#WORLD_STEP * @since 3.70.0 */ - singleStep: function () + singleStep() { this.update(0, this._frameTimeMS); this.postUpdate(); - }, + } /** * Updates bodies, draws the debug display, and handles pending queue operations. @@ -1072,7 +1068,7 @@ var World = new Class({ * @method Phaser.Physics.Arcade.World#postUpdate * @since 3.0.0 */ - postUpdate: function () + postUpdate() { var dynamic = this.bodies; var staticBodies = this.staticBodies; @@ -1140,7 +1136,7 @@ var World = new Class({ pending.clear(); } - }, + } /** * Calculates a Body's velocity and updates its position. @@ -1151,7 +1147,7 @@ var World = new Class({ * @param {Phaser.Physics.Arcade.Body} body - The Body to be updated. * @param {number} delta - The delta value to be used in the motion calculations, in seconds. */ - updateMotion: function (body, delta) + updateMotion(body, delta) { if (body.allowRotation) { @@ -1159,7 +1155,7 @@ var World = new Class({ } this.computeVelocity(body, delta); - }, + } /** * Calculates a Body's angular velocity. @@ -1170,7 +1166,7 @@ var World = new Class({ * @param {Phaser.Physics.Arcade.Body} body - The Body to compute the velocity for. * @param {number} delta - The delta value to be used in the calculation, in seconds. */ - computeAngularVelocity: function (body, delta) + computeAngularVelocity(body, delta) { var velocity = body.angularVelocity; var acceleration = body.angularAcceleration; @@ -1205,7 +1201,7 @@ var World = new Class({ body.angularVelocity += velocityDelta; body.rotation += (body.angularVelocity * delta); - }, + } /** * Calculates a Body's per-axis velocity. @@ -1216,7 +1212,7 @@ var World = new Class({ * @param {Phaser.Physics.Arcade.Body} body - The Body to compute the velocity for. * @param {number} delta - The delta value to be used in the calculation, in seconds. */ - computeVelocity: function (body, delta) + computeVelocity(body, delta) { var velocityX = body.velocity.x; var accelerationX = body.acceleration.x; @@ -1331,7 +1327,7 @@ var World = new Class({ } body.speed = speed; - }, + } /** * Separates two Bodies. @@ -1349,7 +1345,7 @@ var World = new Class({ * * @return {boolean} True if separation occurred, otherwise false. */ - separate: function (body1, body2, processCallback, callbackContext, overlapOnly) + separate(body1, body2, processCallback, callbackContext, overlapOnly) { var overlapX; var overlapY; @@ -1446,7 +1442,7 @@ var World = new Class({ } return result; - }, + } /** * Separates two Bodies, when both are circular. @@ -1462,7 +1458,7 @@ var World = new Class({ * * @return {boolean} True if separation occurred, otherwise false. */ - separateCircle: function (body1, body2, overlapOnly) + separateCircle(body1, body2, overlapOnly) { // Set the AABB overlap, blocked and touching values into the bodies (we don't use the return values here) GetOverlapX(body1, body2, false, 0); @@ -1653,7 +1649,7 @@ var World = new Class({ } return results; - }, + } /** * Checks to see if two Bodies intersect at all. @@ -1666,7 +1662,7 @@ var World = new Class({ * * @return {boolean} True if the two bodies intersect, otherwise false. */ - intersects: function (body1, body2) + intersects(body1, body2) { if (body1 === body2) { @@ -1701,7 +1697,7 @@ var World = new Class({ // Rect vs. Circle return this.circleBodyIntersects(body2, body1); } - }, + } /** * Tests if a circular Body intersects with another Body. @@ -1714,7 +1710,7 @@ var World = new Class({ * * @return {boolean} True if the two bodies intersect, otherwise false. */ - circleBodyIntersects: function (circle, body) + circleBodyIntersects(circle, body) { var x = Clamp(circle.center.x, body.left, body.right); var y = Clamp(circle.center.y, body.top, body.bottom); @@ -1723,7 +1719,7 @@ var World = new Class({ var dy = (circle.center.y - y) * (circle.center.y - y); return (dx + dy) <= (circle.halfWidth * circle.halfWidth); - }, + } /** * Tests if Game Objects overlap. @@ -1743,14 +1739,14 @@ var World = new Class({ * * @see Phaser.Physics.Arcade.World#collide */ - overlap: function (object1, object2, overlapCallback, processCallback, callbackContext) + overlap(object1, object2, overlapCallback, processCallback, callbackContext) { if (overlapCallback === undefined) { overlapCallback = null; } if (processCallback === undefined) { processCallback = null; } if (callbackContext === undefined) { callbackContext = overlapCallback; } return this.collideObjects(object1, object2, overlapCallback, processCallback, callbackContext, true); - }, + } /** * Performs a collision check and separation between the two physics enabled objects given, which can be single @@ -1784,14 +1780,14 @@ var World = new Class({ * * @return {boolean} `true` if any overlapping Game Objects were separated, otherwise `false`. */ - collide: function (object1, object2, collideCallback, processCallback, callbackContext) + collide(object1, object2, collideCallback, processCallback, callbackContext) { if (collideCallback === undefined) { collideCallback = null; } if (processCallback === undefined) { processCallback = null; } if (callbackContext === undefined) { callbackContext = collideCallback; } return this.collideObjects(object1, object2, collideCallback, processCallback, callbackContext, false); - }, + } /** * Internal helper function. Please use Phaser.Physics.Arcade.World#collide instead. @@ -1809,7 +1805,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideObjects: function (object1, object2, collideCallback, processCallback, callbackContext, overlapOnly) + collideObjects(object1, object2, collideCallback, processCallback, callbackContext, overlapOnly) { var i; var j; @@ -1884,7 +1880,7 @@ var World = new Class({ } return (this._total > 0); - }, + } /** * Internal helper function. Please use Phaser.Physics.Arcade.World#collide and Phaser.Physics.Arcade.World#overlap instead. @@ -1902,7 +1898,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideHandler: function (object1, object2, collideCallback, processCallback, callbackContext, overlapOnly) + collideHandler(object1, object2, collideCallback, processCallback, callbackContext, overlapOnly) { // Collide Group with Self // Only collide valid objects @@ -1963,7 +1959,7 @@ var World = new Class({ return this.collideGroupVsTilemapLayer(object2, object1, collideCallback, processCallback, callbackContext, overlapOnly); } } - }, + } /** * Checks if the two given Arcade Physics bodies will collide, or not, @@ -1977,14 +1973,14 @@ var World = new Class({ * * @return {boolean} True if the two bodies will collide, otherwise false. */ - canCollide: function (body1, body2) + canCollide(body1, body2) { return ( (body1 && body2) && (body1.collisionMask & body2.collisionCategory) !== 0 && (body2.collisionMask & body1.collisionCategory) !== 0 ); - }, + } /** * Internal handler for Sprite vs. Sprite collisions. @@ -2003,7 +1999,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideSpriteVsSprite: function (sprite1, sprite2, collideCallback, processCallback, callbackContext, overlapOnly) + collideSpriteVsSprite(sprite1, sprite2, collideCallback, processCallback, callbackContext, overlapOnly) { var body1 = (sprite1.isBody) ? sprite1 : sprite1.body; var body2 = (sprite2.isBody) ? sprite2 : sprite2.body; @@ -2024,7 +2020,7 @@ var World = new Class({ } return true; - }, + } /** * Internal handler for Sprite vs. Group collisions. @@ -2041,7 +2037,7 @@ var World = new Class({ * @param {any} callbackContext - The scope in which to call the callbacks. * @param {boolean} overlapOnly - Whether this is a collision or overlap check. */ - collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext, overlapOnly) + collideSpriteVsGroup(sprite, group, collideCallback, processCallback, callbackContext, overlapOnly) { var bodyA = (sprite.isBody) ? sprite : sprite.body; @@ -2117,7 +2113,7 @@ var World = new Class({ } } } - }, + } /** * Internal handler for Group vs. Tilemap collisions. @@ -2136,7 +2132,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) + collideGroupVsTilemapLayer(group, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) { if (!this.canCollide(group, tilemapLayer)) { @@ -2164,7 +2160,7 @@ var World = new Class({ } return didCollide; - }, + } /** * This advanced method is specifically for testing for collision between a single Sprite and an array of Tile objects. @@ -2196,7 +2192,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideTiles: function (sprite, tiles, collideCallback, processCallback, callbackContext) + collideTiles(sprite, tiles, collideCallback, processCallback, callbackContext) { if (tiles.length === 0 || (sprite.body && !sprite.body.enable) || (sprite.isBody && !sprite.enable)) { @@ -2206,7 +2202,7 @@ var World = new Class({ { return this.collideSpriteVsTilesHandler(sprite, tiles, collideCallback, processCallback, callbackContext, false, false); } - }, + } /** * This advanced method is specifically for testing for overlaps between a single Sprite and an array of Tile objects. @@ -2233,7 +2229,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - overlapTiles: function (sprite, tiles, overlapCallback, processCallback, callbackContext) + overlapTiles(sprite, tiles, overlapCallback, processCallback, callbackContext) { if (tiles.length === 0 || (sprite.body && !sprite.body.enable) || (sprite.isBody && !sprite.enable)) { @@ -2243,7 +2239,7 @@ var World = new Class({ { return this.collideSpriteVsTilesHandler(sprite, tiles, overlapCallback, processCallback, callbackContext, true, false); } - }, + } /** * Internal handler for Sprite vs. Tilemap collisions. @@ -2263,7 +2259,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) + collideSpriteVsTilemapLayer(sprite, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) { var body = (sprite.isBody) ? sprite : sprite.body; @@ -2294,7 +2290,7 @@ var World = new Class({ { return this.collideSpriteVsTilesHandler(sprite, mapData, collideCallback, processCallback, callbackContext, overlapOnly, true); } - }, + } /** * Internal handler for Sprite vs. Tilemap collisions. @@ -2316,7 +2312,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideSpriteVsTilesHandler: function (sprite, tiles, collideCallback, processCallback, callbackContext, overlapOnly, isLayer) + collideSpriteVsTilesHandler(sprite, tiles, collideCallback, processCallback, callbackContext, overlapOnly, isLayer) { var body = (sprite.isBody) ? sprite : sprite.body; @@ -2366,7 +2362,7 @@ var World = new Class({ } return collision; - }, + } /** * Internal helper for Group vs. Group collisions. @@ -2385,7 +2381,7 @@ var World = new Class({ * * @return {boolean} True if any objects overlap (with `overlapOnly`); or true if any overlapping objects were separated. */ - collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext, overlapOnly) + collideGroupVsGroup(group1, group2, collideCallback, processCallback, callbackContext, overlapOnly) { if (group1.getLength() === 0 || group2.getLength() === 0 || !this.canCollide(group1, group2)) { @@ -2398,7 +2394,7 @@ var World = new Class({ { this.collideSpriteVsGroup(children[i], group2, collideCallback, processCallback, callbackContext, overlapOnly); } - }, + } /** * Wrap an object's coordinates (or several objects' coordinates) within {@link Phaser.Physics.Arcade.World#bounds}. @@ -2411,7 +2407,7 @@ var World = new Class({ * @param {any} object - A Game Object, a Group, an object with `x` and `y` coordinates, or an array of such objects. * @param {number} [padding=0] - An amount added to each boundary edge during the operation. */ - wrap: function (object, padding) + wrap(object, padding) { if (object.body) { @@ -2429,7 +2425,7 @@ var World = new Class({ { this.wrapObject(object, padding); } - }, + } /** * Wrap each object's coordinates within {@link Phaser.Physics.Arcade.World#bounds}. @@ -2440,13 +2436,13 @@ var World = new Class({ * @param {Array.<*>} objects - An array of objects to be wrapped. * @param {number} [padding=0] - An amount added to the boundary. */ - wrapArray: function (objects, padding) + wrapArray(objects, padding) { for (var i = 0; i < objects.length; i++) { this.wrapObject(objects[i], padding); } - }, + } /** * Wrap an object's coordinates within {@link Phaser.Physics.Arcade.World#bounds}. @@ -2457,13 +2453,13 @@ var World = new Class({ * @param {*} object - A Game Object, a Physics Body, or any object with `x` and `y` coordinates * @param {number} [padding=0] - An amount added to the boundary. */ - wrapObject: function (object, padding) + wrapObject(object, padding) { if (padding === undefined) { padding = 0; } object.x = Wrap(object.x, this.bounds.left - padding, this.bounds.right + padding); object.y = Wrap(object.y, this.bounds.top - padding, this.bounds.bottom + padding); - }, + } /** * Shuts down the simulation, clearing physics data and removing listeners. @@ -2471,7 +2467,7 @@ var World = new Class({ * @method Phaser.Physics.Arcade.World#shutdown * @since 3.0.0 */ - shutdown: function () + shutdown() { this.tree.clear(); this.staticTree.clear(); @@ -2480,7 +2476,7 @@ var World = new Class({ this.colliders.destroy(); this.removeAllListeners(); - }, + } /** * Shuts down the simulation and disconnects it from the current scene. @@ -2488,7 +2484,7 @@ var World = new Class({ * @method Phaser.Physics.Arcade.World#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -2501,6 +2497,6 @@ var World = new Class({ } } -}); +}; module.exports = World; diff --git a/src/physics/matter-js/BodyBounds.js b/src/physics/matter-js/BodyBounds.js index 8592aec11d..81fd9bb59f 100644 --- a/src/physics/matter-js/BodyBounds.js +++ b/src/physics/matter-js/BodyBounds.js @@ -27,11 +27,9 @@ var Vector2 = require('../../math/Vector2'); * @constructor * @since 3.22.0 */ -var BodyBounds = new Class({ +var BodyBounds = class { - initialize: - - function BodyBounds () + constructor() { /** * A Vector2 that stores the temporary bounds center value during calculations by methods in this class. @@ -50,7 +48,7 @@ var BodyBounds = new Class({ * @since 3.22.0 */ this.centerDiff = new Vector2(); - }, + } /** * Parses the given body to get the bounds diff values from it. @@ -66,7 +64,7 @@ var BodyBounds = new Class({ * * @return {boolean} `true` if it was able to get the bounds, otherwise `false`. */ - parseBody: function (body) + parseBody(body) { body = (body.hasOwnProperty('body')) ? body.body : body; @@ -88,7 +86,7 @@ var BodyBounds = new Class({ centerDiff.set(bodyCenterX - boundsCenter.x, bodyCenterY - boundsCenter.y); return true; - }, + } /** * Takes a Body and returns the world coordinates of the top-left of its _bounds_. @@ -105,7 +103,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getTopLeft: function (body, x, y) + getTopLeft(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -122,7 +120,7 @@ var BodyBounds = new Class({ } return false; - }, + } /** * Takes a Body and returns the world coordinates of the top-center of its _bounds_. @@ -139,7 +137,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getTopCenter: function (body, x, y) + getTopCenter(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -156,7 +154,7 @@ var BodyBounds = new Class({ } return false; - }, + } /** * Takes a Body and returns the world coordinates of the top-right of its _bounds_. @@ -173,7 +171,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getTopRight: function (body, x, y) + getTopRight(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -190,7 +188,7 @@ var BodyBounds = new Class({ } return false; - }, + } /** * Takes a Body and returns the world coordinates of the left-center of its _bounds_. @@ -207,7 +205,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getLeftCenter: function (body, x, y) + getLeftCenter(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -224,7 +222,7 @@ var BodyBounds = new Class({ } return false; - }, + } /** * Takes a Body and returns the world coordinates of the center of its _bounds_. @@ -241,7 +239,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getCenter: function (body, x, y) + getCenter(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -257,7 +255,7 @@ var BodyBounds = new Class({ } return false; - }, + } /** * Takes a Body and returns the world coordinates of the right-center of its _bounds_. @@ -274,7 +272,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getRightCenter: function (body, x, y) + getRightCenter(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -291,7 +289,7 @@ var BodyBounds = new Class({ } return false; - }, + } /** * Takes a Body and returns the world coordinates of the bottom-left of its _bounds_. @@ -308,7 +306,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getBottomLeft: function (body, x, y) + getBottomLeft(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -325,7 +323,7 @@ var BodyBounds = new Class({ } return false; - }, + } /** * Takes a Body and returns the world coordinates of the bottom-center of its _bounds_. @@ -342,7 +340,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getBottomCenter: function (body, x, y) + getBottomCenter(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -359,7 +357,7 @@ var BodyBounds = new Class({ } return false; - }, + } /** * Takes a Body and returns the world coordinates of the bottom-right of its _bounds_. @@ -376,7 +374,7 @@ var BodyBounds = new Class({ * * @return {(Phaser.Math.Vector2|false)} A Vector2 containing the coordinates, or `false` if it was unable to parse the body. */ - getBottomRight: function (body, x, y) + getBottomRight(body, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -395,6 +393,6 @@ var BodyBounds = new Class({ return false; } -}); +}; module.exports = BodyBounds; diff --git a/src/physics/matter-js/Factory.js b/src/physics/matter-js/Factory.js index bc2913a2f2..bc596c7dd0 100644 --- a/src/physics/matter-js/Factory.js +++ b/src/physics/matter-js/Factory.js @@ -40,11 +40,9 @@ var Vertices = require('./lib/geometry/Vertices'); * * @param {Phaser.Physics.Matter.World} world - The Matter World which this Factory adds to. */ -var Factory = new Class({ +var Factory = class { - initialize: - - function Factory (world) + constructor(world) { /** * The Matter World which this Factory adds to. @@ -72,7 +70,7 @@ var Factory = new Class({ * @since 3.0.0 */ this.sys = world.scene.sys; - }, + } /** * Creates a new rigid rectangular Body and adds it to the World. @@ -88,14 +86,14 @@ var Factory = new Class({ * * @return {MatterJS.BodyType} A Matter JS Body. */ - rectangle: function (x, y, width, height, options) + rectangle(x, y, width, height, options) { var body = Bodies.rectangle(x, y, width, height, options); this.world.add(body); return body; - }, + } /** * Creates a new rigid trapezoidal Body and adds it to the World. @@ -112,14 +110,14 @@ var Factory = new Class({ * * @return {MatterJS.BodyType} A Matter JS Body. */ - trapezoid: function (x, y, width, height, slope, options) + trapezoid(x, y, width, height, slope, options) { var body = Bodies.trapezoid(x, y, width, height, slope, options); this.world.add(body); return body; - }, + } /** * Creates a new rigid circular Body and adds it to the World. @@ -135,14 +133,14 @@ var Factory = new Class({ * * @return {MatterJS.BodyType} A Matter JS Body. */ - circle: function (x, y, radius, options, maxSides) + circle(x, y, radius, options, maxSides) { var body = Bodies.circle(x, y, radius, options, maxSides); this.world.add(body); return body; - }, + } /** * Creates a new rigid polygonal Body and adds it to the World. @@ -158,14 +156,14 @@ var Factory = new Class({ * * @return {MatterJS.BodyType} A Matter JS Body. */ - polygon: function (x, y, sides, radius, options) + polygon(x, y, sides, radius, options) { var body = Bodies.polygon(x, y, sides, radius, options); this.world.add(body); return body; - }, + } /** * Creates a body using the supplied vertices (or an array containing multiple sets of vertices) and adds it to the World. @@ -184,7 +182,7 @@ var Factory = new Class({ * * @return {MatterJS.BodyType} A Matter JS Body. */ - fromVertices: function (x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea) + fromVertices(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea) { if (typeof vertexSets === 'string') { @@ -196,7 +194,7 @@ var Factory = new Class({ this.world.add(body); return body; - }, + } /** * Creates a body using data exported from the application PhysicsEditor (https://www.codeandweb.com/physicseditor) @@ -231,7 +229,7 @@ var Factory = new Class({ * * @return {MatterJS.BodyType} A Matter JS Body. */ - fromPhysicsEditor: function (x, y, config, options, addToWorld) + fromPhysicsEditor(x, y, config, options, addToWorld) { if (addToWorld === undefined) { addToWorld = true; } @@ -243,7 +241,7 @@ var Factory = new Class({ } return body; - }, + } /** * Creates a body using the path data from an SVG file. @@ -277,7 +275,7 @@ var Factory = new Class({ * * @return {MatterJS.BodyType} A Matter JS Body. */ - fromSVG: function (x, y, xml, scale, options, addToWorld) + fromSVG(x, y, xml, scale, options, addToWorld) { if (scale === undefined) { scale = 1; } if (options === undefined) { options = {}; } @@ -306,7 +304,7 @@ var Factory = new Class({ } return body; - }, + } /** * Creates a body using the supplied physics data, as provided by a JSON file. @@ -357,7 +355,7 @@ var Factory = new Class({ * * @return {MatterJS.BodyType} A Matter JS Body. */ - fromJSON: function (x, y, config, options, addToWorld) + fromJSON(x, y, config, options, addToWorld) { if (options === undefined) { options = {}; } if (addToWorld === undefined) { addToWorld = true; } @@ -370,7 +368,7 @@ var Factory = new Class({ } return body; - }, + } /** * Create a new composite containing Matter Image objects created in a grid arrangement. @@ -391,7 +389,7 @@ var Factory = new Class({ * * @return {MatterJS.CompositeType} A Matter JS Composite Stack. */ - imageStack: function (key, frame, x, y, columns, rows, columnGap, rowGap, options) + imageStack(key, frame, x, y, columns, rows, columnGap, rowGap, options) { if (columnGap === undefined) { columnGap = 0; } if (rowGap === undefined) { rowGap = 0; } @@ -414,7 +412,7 @@ var Factory = new Class({ world.add(stack); return stack; - }, + } /** * Create a new composite containing bodies created in the callback in a grid arrangement. @@ -434,14 +432,14 @@ var Factory = new Class({ * * @return {MatterJS.CompositeType} A new composite containing objects created in the callback. */ - stack: function (x, y, columns, rows, columnGap, rowGap, callback) + stack(x, y, columns, rows, columnGap, rowGap, callback) { var stack = Composites.stack(x, y, columns, rows, columnGap, rowGap, callback); this.world.add(stack); return stack; - }, + } /** * Create a new composite containing bodies created in the callback in a pyramid arrangement. @@ -460,14 +458,14 @@ var Factory = new Class({ * * @return {MatterJS.CompositeType} A Matter JS Composite pyramid. */ - pyramid: function (x, y, columns, rows, columnGap, rowGap, callback) + pyramid(x, y, columns, rows, columnGap, rowGap, callback) { var stack = Composites.pyramid(x, y, columns, rows, columnGap, rowGap, callback); this.world.add(stack); return stack; - }, + } /** * Chains all bodies in the given composite together using constraints. @@ -484,10 +482,10 @@ var Factory = new Class({ * * @return {MatterJS.CompositeType} The original composite that was passed to this method. */ - chain: function (composite, xOffsetA, yOffsetA, xOffsetB, yOffsetB, options) + chain(composite, xOffsetA, yOffsetA, xOffsetB, yOffsetB, options) { return Composites.chain(composite, xOffsetA, yOffsetA, xOffsetB, yOffsetB, options); - }, + } /** * Connects bodies in the composite with constraints in a grid pattern, with optional cross braces. @@ -503,10 +501,10 @@ var Factory = new Class({ * * @return {MatterJS.CompositeType} The original composite that was passed to this method. */ - mesh: function (composite, columns, rows, crossBrace, options) + mesh(composite, columns, rows, crossBrace, options) { return Composites.mesh(composite, columns, rows, crossBrace, options); - }, + } /** * Creates a composite with a Newton's Cradle setup of bodies and constraints. @@ -522,14 +520,14 @@ var Factory = new Class({ * * @return {MatterJS.CompositeType} A Newton's cradle composite. */ - newtonsCradle: function (x, y, number, size, length) + newtonsCradle(x, y, number, size, length) { var composite = Composites.newtonsCradle(x, y, number, size, length); this.world.add(composite); return composite; - }, + } /** * Creates a composite with simple car setup of bodies and constraints. @@ -545,14 +543,14 @@ var Factory = new Class({ * * @return {MatterJS.CompositeType} A new composite car body. */ - car: function (x, y, width, height, wheelSize) + car(x, y, width, height, wheelSize) { var composite = Composites.car(x, y, width, height, wheelSize); this.world.add(composite); return composite; - }, + } /** * Creates a simple soft body like object. @@ -573,14 +571,14 @@ var Factory = new Class({ * * @return {MatterJS.CompositeType} A new composite simple soft body. */ - softBody: function (x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) + softBody(x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) { var composite = Composites.softBody(x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions); this.world.add(composite); return composite; - }, + } /** * This method is an alias for `Factory.constraint`. @@ -609,10 +607,10 @@ var Factory = new Class({ * * @return {MatterJS.ConstraintType} A Matter JS Constraint. */ - joint: function (bodyA, bodyB, length, stiffness, options) + joint(bodyA, bodyB, length, stiffness, options) { return this.constraint(bodyA, bodyB, length, stiffness, options); - }, + } /** * This method is an alias for `Factory.constraint`. @@ -641,10 +639,10 @@ var Factory = new Class({ * * @return {MatterJS.ConstraintType} A Matter JS Constraint. */ - spring: function (bodyA, bodyB, length, stiffness, options) + spring(bodyA, bodyB, length, stiffness, options) { return this.constraint(bodyA, bodyB, length, stiffness, options); - }, + } /** * Constraints (or joints) are used for specifying that a fixed distance must be maintained @@ -671,7 +669,7 @@ var Factory = new Class({ * * @return {MatterJS.ConstraintType} A Matter JS Constraint. */ - constraint: function (bodyA, bodyB, length, stiffness, options) + constraint(bodyA, bodyB, length, stiffness, options) { if (stiffness === undefined) { stiffness = 1; } if (options === undefined) { options = {}; } @@ -691,7 +689,7 @@ var Factory = new Class({ this.world.add(constraint); return constraint; - }, + } /** * Constraints (or joints) are used for specifying that a fixed distance must be maintained @@ -720,7 +718,7 @@ var Factory = new Class({ * * @return {MatterJS.ConstraintType} A Matter JS Constraint. */ - worldConstraint: function (body, length, stiffness, options) + worldConstraint(body, length, stiffness, options) { if (stiffness === undefined) { stiffness = 1; } if (options === undefined) { options = {}; } @@ -739,7 +737,7 @@ var Factory = new Class({ this.world.add(constraint); return constraint; - }, + } /** * This method is an alias for `Factory.pointerConstraint`. @@ -760,10 +758,10 @@ var Factory = new Class({ * * @return {MatterJS.ConstraintType} A Matter JS Constraint. */ - mouseSpring: function (options) + mouseSpring(options) { return this.pointerConstraint(options); - }, + } /** * A Pointer Constraint is a special type of constraint that allows you to click @@ -782,7 +780,7 @@ var Factory = new Class({ * * @return {MatterJS.ConstraintType} A Matter JS Constraint. */ - pointerConstraint: function (options) + pointerConstraint(options) { if (options === undefined) { options = {}; } @@ -796,7 +794,7 @@ var Factory = new Class({ this.world.add(pointerConstraint.constraint); return pointerConstraint; - }, + } /** * Creates a Matter Physics Image Game Object. @@ -817,14 +815,14 @@ var Factory = new Class({ * * @return {Phaser.Physics.Matter.Image} The Matter Image Game Object. */ - image: function (x, y, key, frame, options) + image(x, y, key, frame, options) { var image = new MatterImage(this.world, x, y, key, frame, options); this.sys.displayList.add(image); return image; - }, + } /** * Creates a wrapper around a Tile that provides access to a corresponding Matter body. A tile can only @@ -846,10 +844,10 @@ var Factory = new Class({ * * @return {Phaser.Physics.Matter.TileBody} The Matter Tile Body Game Object. */ - tileBody: function (tile, options) + tileBody(tile, options) { return new MatterTileBody(this.world, tile, options); - }, + } /** * Creates a Matter Physics Sprite Game Object. @@ -873,7 +871,7 @@ var Factory = new Class({ * * @return {Phaser.Physics.Matter.Sprite} The Matter Sprite Game Object. */ - sprite: function (x, y, key, frame, options) + sprite(x, y, key, frame, options) { var sprite = new MatterSprite(this.world, x, y, key, frame, options); @@ -881,7 +879,7 @@ var Factory = new Class({ this.sys.updateList.add(sprite); return sprite; - }, + } /** * Takes an existing Game Object and injects all of the Matter Components into it. @@ -901,10 +899,10 @@ var Factory = new Class({ * * @return {(Phaser.Physics.Matter.Image|Phaser.Physics.Matter.Sprite|Phaser.GameObjects.GameObject)} The Game Object that had the Matter Components injected into it. */ - gameObject: function (gameObject, options, addToWorld) + gameObject(gameObject, options, addToWorld) { return MatterGameObject(this.world, gameObject, options, addToWorld); - }, + } /** * Destroys this Factory. @@ -912,13 +910,13 @@ var Factory = new Class({ * @method Phaser.Physics.Matter.Factory#destroy * @since 3.5.0 */ - destroy: function () + destroy() { this.world = null; this.scene = null; this.sys = null; } -}); +}; module.exports = Factory; diff --git a/src/physics/matter-js/MatterImage.js b/src/physics/matter-js/MatterImage.js index 46d6646b44..590c420aa7 100644 --- a/src/physics/matter-js/MatterImage.js +++ b/src/physics/matter-js/MatterImage.js @@ -59,28 +59,27 @@ var Vector2 = require('../../math/Vector2'); * @param {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with. * @param {Phaser.Types.Physics.Matter.MatterBodyConfig} [options] - An optional Body configuration object that is used to set initial Body properties on creation. */ -var MatterImage = new Class({ +var MatterImage = class extends Image { - Extends: Image, - - Mixins: [ - Components.Bounce, - Components.Collision, - Components.Force, - Components.Friction, - Components.Gravity, - Components.Mass, - Components.Sensor, - Components.SetBody, - Components.Sleep, - Components.Static, - Components.Transform, - Components.Velocity - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Bounce, + Components.Collision, + Components.Force, + Components.Friction, + Components.Gravity, + Components.Mass, + Components.Sensor, + Components.SetBody, + Components.Sleep, + Components.Static, + Components.Transform, + Components.Velocity + ], false); + } - function MatterImage (world, x, y, texture, frame, options) + constructor(world, x, y, texture, frame, options) { GameObject.call(this, world.scene, 'Image'); @@ -132,6 +131,6 @@ var MatterImage = new Class({ this.setPosition(x, y); } -}); +}; module.exports = MatterImage; diff --git a/src/physics/matter-js/MatterPhysics.js b/src/physics/matter-js/MatterPhysics.js index 238554e78b..583d13ad6a 100644 --- a/src/physics/matter-js/MatterPhysics.js +++ b/src/physics/matter-js/MatterPhysics.js @@ -92,11 +92,9 @@ Common.setDecomp(require('./poly-decomp')); * * @param {Phaser.Scene} scene - The Phaser Scene that owns this Matter Physics instance. */ -var MatterPhysics = new Class({ +var MatterPhysics = class { - initialize: - - function MatterPhysics (scene) + constructor(scene) { /** * The Phaser Scene that owns this Matter Physics instance @@ -393,7 +391,7 @@ var MatterPhysics = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -403,14 +401,14 @@ var MatterPhysics = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.world = new World(this.scene, this.config); this.add = new Factory(this.world); this.bodyBounds = new BodyBounds(); this.systems.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -421,7 +419,7 @@ var MatterPhysics = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { if (!this.world) { @@ -434,7 +432,7 @@ var MatterPhysics = new Class({ eventEmitter.on(SceneEvents.UPDATE, this.world.update, this.world); eventEmitter.on(SceneEvents.POST_UPDATE, this.world.postUpdate, this.world); eventEmitter.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * This internal method is called when this class starts and retrieves the final Matter World Config. @@ -444,7 +442,7 @@ var MatterPhysics = new Class({ * * @return {Phaser.Types.Physics.Matter.MatterWorldConfig} The Matter World Config. */ - getConfig: function () + getConfig() { var gameConfig = this.systems.game.config.physics; var sceneConfig = this.systems.settings.physics; @@ -455,7 +453,7 @@ var MatterPhysics = new Class({ ); return config; - }, + } /** * Pauses the Matter World instance and sets `enabled` to `false`. @@ -468,10 +466,10 @@ var MatterPhysics = new Class({ * * @return {Phaser.Physics.Matter.World} The Matter World object. */ - pause: function () + pause() { return this.world.pause(); - }, + } /** * Resumes this Matter World instance from a paused state and sets `enabled` to `true`. @@ -481,10 +479,10 @@ var MatterPhysics = new Class({ * * @return {Phaser.Physics.Matter.World} The Matter World object. */ - resume: function () + resume() { return this.world.resume(); - }, + } /** * Sets the Matter Engine to run at fixed timestep of 60Hz and enables `autoUpdate`. @@ -495,13 +493,13 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - set60Hz: function () + set60Hz() { this.world.getDelta = this.world.update60Hz; this.world.autoUpdate = true; return this; - }, + } /** * Sets the Matter Engine to run at fixed timestep of 30Hz and enables `autoUpdate`. @@ -512,13 +510,13 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - set30Hz: function () + set30Hz() { this.world.getDelta = this.world.update30Hz; this.world.autoUpdate = true; return this; - }, + } /** * Manually advances the physics simulation by one iteration. @@ -547,10 +545,10 @@ var MatterPhysics = new Class({ * @param {number} [delta=16.666] - The delta value. * @param {number} [correction=1] - Optional delta correction value. */ - step: function (delta, correction) + step(delta, correction) { this.world.step(delta, correction); - }, + } /** * Checks if the vertices of the given body, or an array of bodies, contains the given point, or not. @@ -572,7 +570,7 @@ var MatterPhysics = new Class({ * * @return {boolean} `true` if the point is within one of the bodies given, otherwise `false`. */ - containsPoint: function (body, x, y) + containsPoint(body, x, y) { body = this.getMatterBodies(body); @@ -581,7 +579,7 @@ var MatterPhysics = new Class({ var result = Query.point(body, position); return (result.length > 0) ? true : false; - }, + } /** * Checks the given coordinates to see if any vertices of the given bodies contain it. @@ -601,7 +599,7 @@ var MatterPhysics = new Class({ * * @return {Phaser.Types.Physics.Matter.MatterBody[]} An array of bodies which contain the given point. */ - intersectPoint: function (x, y, bodies) + intersectPoint(x, y, bodies) { bodies = this.getMatterBodies(bodies); @@ -620,7 +618,7 @@ var MatterPhysics = new Class({ }); return output; - }, + } /** * Checks the given rectangular area to see if any vertices of the given bodies intersect with it. @@ -641,7 +639,7 @@ var MatterPhysics = new Class({ * * @return {Phaser.Types.Physics.Matter.MatterBody[]} An array of bodies that intersect with the given area. */ - intersectRect: function (x, y, width, height, outside, bodies) + intersectRect(x, y, width, height, outside, bodies) { if (outside === undefined) { outside = false; } @@ -665,7 +663,7 @@ var MatterPhysics = new Class({ }); return output; - }, + } /** * Checks the given ray segment to see if any vertices of the given bodies intersect with it. @@ -686,7 +684,7 @@ var MatterPhysics = new Class({ * * @return {Phaser.Types.Physics.Matter.MatterBody[]} An array of bodies whos vertices intersect with the ray segment. */ - intersectRay: function (x1, y1, x2, y2, rayWidth, bodies) + intersectRay(x1, y1, x2, y2, rayWidth, bodies) { if (rayWidth === undefined) { rayWidth = 1; } @@ -701,7 +699,7 @@ var MatterPhysics = new Class({ } return result; - }, + } /** * Checks the given Matter Body to see if it intersects with any of the given bodies. @@ -716,7 +714,7 @@ var MatterPhysics = new Class({ * * @return {Phaser.Types.Physics.Matter.MatterBody[]} An array of bodies whos vertices intersect with target body. */ - intersectBody: function (body, bodies) + intersectBody(body, bodies) { bodies = this.getMatterBodies(bodies); @@ -738,7 +736,7 @@ var MatterPhysics = new Class({ } return result; - }, + } /** * Checks to see if the target body, or an array of target bodies, intersects with any of the given bodies. @@ -769,7 +767,7 @@ var MatterPhysics = new Class({ * * @return {boolean} `true` if the target body intersects with _any_ of the bodies given, otherwise `false`. */ - overlap: function (target, bodies, overlapCallback, processCallback, callbackContext) + overlap(target, bodies, overlapCallback, processCallback, callbackContext) { if (overlapCallback === undefined) { overlapCallback = null; } if (processCallback === undefined) { processCallback = null; } @@ -814,7 +812,7 @@ var MatterPhysics = new Class({ } return match; - }, + } /** * Sets the collision filter category of all given Matter Bodies to the given value. @@ -832,7 +830,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - setCollisionCategory: function (bodies, value) + setCollisionCategory(bodies, value) { bodies = this.getMatterBodies(bodies); @@ -842,7 +840,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Sets the collision filter group of all given Matter Bodies to the given value. @@ -861,7 +859,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - setCollisionGroup: function (bodies, value) + setCollisionGroup(bodies, value) { bodies = this.getMatterBodies(bodies); @@ -871,7 +869,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Sets the collision filter mask of all given Matter Bodies to the given value. @@ -888,7 +886,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - setCollidesWith: function (bodies, categories) + setCollidesWith(bodies, categories) { bodies = this.getMatterBodies(bodies); @@ -912,7 +910,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Takes an array and returns a new array made from all of the Matter Bodies found in the original array. @@ -929,7 +927,7 @@ var MatterPhysics = new Class({ * * @return {MatterJS.BodyType[]} An array of native Matter Body objects. */ - getMatterBodies: function (bodies) + getMatterBodies(bodies) { if (!bodies) { @@ -951,7 +949,7 @@ var MatterPhysics = new Class({ } return output; - }, + } /** * Sets both the horizontal and vertical linear velocity of the physics bodies. @@ -965,7 +963,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - setVelocity: function (bodies, x, y) + setVelocity(bodies, x, y) { bodies = this.getMatterBodies(bodies); @@ -980,7 +978,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Sets just the horizontal linear velocity of the physics bodies. @@ -994,7 +992,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - setVelocityX: function (bodies, x) + setVelocityX(bodies, x) { bodies = this.getMatterBodies(bodies); @@ -1009,7 +1007,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Sets just the vertical linear velocity of the physics bodies. @@ -1023,7 +1021,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - setVelocityY: function (bodies, y) + setVelocityY(bodies, y) { bodies = this.getMatterBodies(bodies); @@ -1038,7 +1036,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Sets the angular velocity of the bodies instantly. @@ -1052,7 +1050,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - setAngularVelocity: function (bodies, value) + setAngularVelocity(bodies, value) { bodies = this.getMatterBodies(bodies); @@ -1062,7 +1060,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Applies a force to a body, at the bodies current position, including resulting torque. @@ -1075,7 +1073,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - applyForce: function (bodies, force) + applyForce(bodies, force) { bodies = this.getMatterBodies(bodies); @@ -1090,7 +1088,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Applies a force to a body, from the given world position, including resulting torque. @@ -1108,7 +1106,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - applyForceFromPosition: function (bodies, position, speed, angle) + applyForceFromPosition(bodies, position, speed, angle) { bodies = this.getMatterBodies(bodies); @@ -1128,7 +1126,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Apply a force to a body based on the given angle and speed. @@ -1145,7 +1143,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - applyForceFromAngle: function (bodies, speed, angle) + applyForceFromAngle(bodies, speed, angle) { bodies = this.getMatterBodies(bodies); @@ -1165,7 +1163,7 @@ var MatterPhysics = new Class({ }); return this; - }, + } /** * Returns the length of the given constraint, which is the distance between the two points. @@ -1177,7 +1175,7 @@ var MatterPhysics = new Class({ * * @return {number} The length of the constraint. */ - getConstraintLength: function (constraint) + getConstraintLength(constraint) { var aX = constraint.pointA.x; var aY = constraint.pointA.y; @@ -1197,7 +1195,7 @@ var MatterPhysics = new Class({ } return DistanceBetween(aX, aY, bX, bY); - }, + } /** * Aligns a Body, or Matter Game Object, against the given coordinates. @@ -1230,7 +1228,7 @@ var MatterPhysics = new Class({ * * @return {this} This Matter Physics instance. */ - alignBody: function (body, x, y, align) + alignBody(body, x, y, align) { body = (body.hasOwnProperty('body')) ? body.body : body; @@ -1285,7 +1283,7 @@ var MatterPhysics = new Class({ } return this; - }, + } /** * The Scene that owns this plugin is shutting down. @@ -1295,7 +1293,7 @@ var MatterPhysics = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { var eventEmitter = this.systems.events; @@ -1319,7 +1317,7 @@ var MatterPhysics = new Class({ this.add = null; this.world = null; - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -1329,7 +1327,7 @@ var MatterPhysics = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -1339,7 +1337,7 @@ var MatterPhysics = new Class({ this.systems = null; } -}); +}; PluginCache.register('MatterPhysics', MatterPhysics, 'matterPhysics'); diff --git a/src/physics/matter-js/MatterSprite.js b/src/physics/matter-js/MatterSprite.js index 2e9f07c682..12e517fdd4 100644 --- a/src/physics/matter-js/MatterSprite.js +++ b/src/physics/matter-js/MatterSprite.js @@ -63,28 +63,27 @@ var Vector2 = require('../../math/Vector2'); * @param {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with. * @param {Phaser.Types.Physics.Matter.MatterBodyConfig} [options] - An optional Body configuration object that is used to set initial Body properties on creation. */ -var MatterSprite = new Class({ +var MatterSprite = class extends Sprite { - Extends: Sprite, - - Mixins: [ - Components.Bounce, - Components.Collision, - Components.Force, - Components.Friction, - Components.Gravity, - Components.Mass, - Components.Sensor, - Components.SetBody, - Components.Sleep, - Components.Static, - Components.Transform, - Components.Velocity - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Bounce, + Components.Collision, + Components.Force, + Components.Friction, + Components.Gravity, + Components.Mass, + Components.Sensor, + Components.SetBody, + Components.Sleep, + Components.Static, + Components.Transform, + Components.Velocity + ], false); + } - function MatterSprite (world, x, y, texture, frame, options) + constructor(world, x, y, texture, frame, options) { GameObject.call(this, world.scene, 'Sprite'); @@ -138,6 +137,6 @@ var MatterSprite = new Class({ this.setPosition(x, y); } -}); +}; module.exports = MatterSprite; diff --git a/src/physics/matter-js/MatterTileBody.js b/src/physics/matter-js/MatterTileBody.js index 602a211111..f4ad6c9e16 100644 --- a/src/physics/matter-js/MatterTileBody.js +++ b/src/physics/matter-js/MatterTileBody.js @@ -46,26 +46,25 @@ var Vertices = require('./lib/geometry/Vertices'); * @param {Phaser.Tilemaps.Tile} tile - The target tile that should have a Matter body. * @param {Phaser.Types.Physics.Matter.MatterTileOptions} [options] - Options to be used when creating the Matter body. */ -var MatterTileBody = new Class({ +var MatterTileBody = class extends EventEmitter { - Extends: EventEmitter, - - Mixins: [ - Components.Bounce, - Components.Collision, - Components.Friction, - Components.Gravity, - Components.Mass, - Components.Sensor, - Components.Sleep, - Components.Static - ], - - initialize: + static + { + Class.mixin(this, [ + Components.Bounce, + Components.Collision, + Components.Friction, + Components.Gravity, + Components.Mass, + Components.Sensor, + Components.Sleep, + Components.Static + ], false); + } - function MatterTileBody (world, tile, options) + constructor(world, tile, options) { - EventEmitter.call(this); + super(); /** * The tile object the body is associated with. @@ -127,7 +126,7 @@ var MatterTileBody = new Class({ Body.scale(body, scaleX, scaleY, rotationPoint); } - }, + } /** * Sets the current body to a rectangle that matches the bounds of the tile. @@ -139,7 +138,7 @@ var MatterTileBody = new Class({ * * @return {Phaser.Physics.Matter.TileBody} This TileBody object. */ - setFromTileRectangle: function (options) + setFromTileRectangle(options) { if (options === undefined) { options = {}; } if (!HasValue(options, 'isStatic')) { options.isStatic = true; } @@ -153,7 +152,7 @@ var MatterTileBody = new Class({ this.setBody(body, options.addToWorld); return this; - }, + } /** * Sets the current body from the collision group associated with the Tile. This is typically @@ -173,7 +172,7 @@ var MatterTileBody = new Class({ * * @return {Phaser.Physics.Matter.TileBody} This TileBody object. */ - setFromTileCollision: function (options) + setFromTileCollision(options) { if (options === undefined) { options = {}; } if (!HasValue(options, 'isStatic')) { options.isStatic = true; } @@ -253,7 +252,7 @@ var MatterTileBody = new Class({ } return this; - }, + } /** * Sets the current body to the given body. This will remove the previous body, if one already @@ -267,7 +266,7 @@ var MatterTileBody = new Class({ * * @return {Phaser.Physics.Matter.TileBody} This TileBody object. */ - setBody: function (body, addToWorld) + setBody(body, addToWorld) { if (addToWorld === undefined) { addToWorld = true; } @@ -285,7 +284,7 @@ var MatterTileBody = new Class({ } return this; - }, + } /** * Removes the current body from the TileBody and from the Matter world @@ -295,7 +294,7 @@ var MatterTileBody = new Class({ * * @return {Phaser.Physics.Matter.TileBody} This TileBody object. */ - removeBody: function () + removeBody() { if (this.body) { @@ -305,7 +304,7 @@ var MatterTileBody = new Class({ } return this; - }, + } /** * Removes the current body from the tile and the world. @@ -315,13 +314,13 @@ var MatterTileBody = new Class({ * * @return {Phaser.Physics.Matter.TileBody} This TileBody object. */ - destroy: function () + destroy() { this.removeBody(); this.tile.physics.matterBody = undefined; this.removeAllListeners(); } -}); +}; module.exports = MatterTileBody; diff --git a/src/physics/matter-js/PointerConstraint.js b/src/physics/matter-js/PointerConstraint.js index 3d667f6b60..12ac62df7d 100644 --- a/src/physics/matter-js/PointerConstraint.js +++ b/src/physics/matter-js/PointerConstraint.js @@ -36,11 +36,9 @@ var Vertices = require('./lib/geometry/Vertices'); * @param {Phaser.Physics.Matter.World} world - A reference to the Matter World instance to which this Constraint belongs. * @param {object} [options] - A Constraint configuration object. */ -var PointerConstraint = new Class({ +var PointerConstraint = class { - initialize: - - function PointerConstraint (scene, world, options) + constructor(scene, world, options) { if (options === undefined) { options = {}; } @@ -152,7 +150,7 @@ var PointerConstraint = new Class({ scene.sys.input.on(InputEvents.POINTER_DOWN, this.onDown, this); scene.sys.input.on(InputEvents.POINTER_UP, this.onUp, this); - }, + } /** * A Pointer has been pressed down onto the Scene. @@ -166,14 +164,14 @@ var PointerConstraint = new Class({ * * @param {Phaser.Input.Pointer} pointer - A reference to the Pointer that was pressed. */ - onDown: function (pointer) + onDown(pointer) { if (!this.pointer) { this.pointer = pointer; this.camera = pointer.camera; } - }, + } /** * A Pointer has been released from the Scene. If it was the one this constraint was using, it's cleared. @@ -183,13 +181,13 @@ var PointerConstraint = new Class({ * * @param {Phaser.Input.Pointer} pointer - A reference to the Pointer that was pressed. */ - onUp: function (pointer) + onUp(pointer) { if (pointer === this.pointer) { this.pointer = null; } - }, + } /** * Scans all active bodies in the current Matter World to see if any of them @@ -202,7 +200,7 @@ var PointerConstraint = new Class({ * * @return {boolean} `true` if a body was found and set, otherwise `false`. */ - getBody: function (pointer) + getBody(pointer) { var pos = this.position; var constraint = this.constraint; @@ -229,7 +227,7 @@ var PointerConstraint = new Class({ } return false; - }, + } /** * Scans the current body to determine if a part of it was clicked on. @@ -244,7 +242,7 @@ var PointerConstraint = new Class({ * * @return {boolean} `true` if a part of the body was hit, otherwise `false`. */ - hitTestBody: function (body, position) + hitTestBody(body, position) { var constraint = this.constraint; var partsLength = body.parts.length; @@ -273,7 +271,7 @@ var PointerConstraint = new Class({ } return false; - }, + } /** * Internal update handler. Called in the Matter BEFORE_UPDATE step. @@ -282,7 +280,7 @@ var PointerConstraint = new Class({ * @fires Phaser.Physics.Matter.Events#DRAG * @since 3.0.0 */ - update: function () + update() { var pointer = this.pointer; var body = this.body; @@ -325,7 +323,7 @@ var PointerConstraint = new Class({ this.world.emit(Events.DRAG, body, this); } - }, + } /** * Stops the Pointer Constraint from dragging the body any further. @@ -338,7 +336,7 @@ var PointerConstraint = new Class({ * @fires Phaser.Physics.Matter.Events#DRAG_END * @since 3.16.2 */ - stopDrag: function () + stopDrag() { var body = this.body; var constraint = this.constraint; @@ -354,7 +352,7 @@ var PointerConstraint = new Class({ { this.world.emit(Events.DRAG_END, body, this); } - }, + } /** * Destroys this Pointer Constraint instance and all of its references. @@ -362,7 +360,7 @@ var PointerConstraint = new Class({ * @method Phaser.Physics.Matter.PointerConstraint#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.world.removeConstraint(this.constraint); @@ -377,6 +375,6 @@ var PointerConstraint = new Class({ this.scene.sys.input.off(InputEvents.POINTER_UP, this.onUp, this); } -}); +}; module.exports = PointerConstraint; diff --git a/src/physics/matter-js/World.js b/src/physics/matter-js/World.js index 209aadf555..9c7df5383b 100644 --- a/src/physics/matter-js/World.js +++ b/src/physics/matter-js/World.js @@ -44,15 +44,11 @@ var Vector = require('./lib/geometry/Vector'); * @param {Phaser.Scene} scene - The Scene to which this Matter World instance belongs. * @param {Phaser.Types.Physics.Matter.MatterWorldConfig} config - The Matter World configuration object. */ -var World = new Class({ +var World = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function World (scene, config) + constructor(scene, config) { - EventEmitter.call(this); + super(); /** * The Scene to which this Matter World instance belongs. @@ -309,7 +305,7 @@ var World = new Class({ this.setBounds(x, y, width, height, thickness, left, right, top, bottom); } } - }, + } /** * Sets the debug render style for the children of the given Matter Composite. @@ -325,7 +321,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - setCompositeRenderStyle: function (composite) + setCompositeRenderStyle(composite) { var bodies = composite.bodies; var constraints = composite.constraints; @@ -359,7 +355,7 @@ var World = new Class({ } return this; - }, + } /** * Sets the debug render style for the given Matter Body. @@ -384,7 +380,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - setBodyRenderStyle: function (body, lineColor, lineOpacity, lineThickness, fillColor, fillOpacity) + setBodyRenderStyle(body, lineColor, lineOpacity, lineThickness, fillColor, fillOpacity) { var render = body.render; var config = this.debugConfig; @@ -445,7 +441,7 @@ var World = new Class({ } return this; - }, + } /** * Sets the debug render style for the given Matter Constraint. @@ -471,7 +467,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - setConstraintRenderStyle: function (constraint, lineColor, lineOpacity, lineThickness, pinSize, anchorColor, anchorSize) + setConstraintRenderStyle(constraint, lineColor, lineOpacity, lineThickness, pinSize, anchorColor, anchorSize) { var render = constraint.render; var config = this.debugConfig; @@ -556,7 +552,7 @@ var World = new Class({ } return this; - }, + } /** * This internal method acts as a proxy between all of the Matter JS events and then re-emits them @@ -565,7 +561,7 @@ var World = new Class({ * @method Phaser.Physics.Matter.World#setEventsProxy * @since 3.0.0 */ - setEventsProxy: function () + setEventsProxy() { var _this = this; var engine = this.engine; @@ -767,7 +763,7 @@ var World = new Class({ _this.emit(Events.COLLISION_END, event, bodyA, bodyB); }); - }, + } /** * Sets the bounds of the Physics world to match the given world pixel dimensions. @@ -793,7 +789,7 @@ var World = new Class({ * * @return {Phaser.Physics.Matter.World} This Matter World object. */ - setBounds: function (x, y, width, height, thickness, left, right, top, bottom) + setBounds(x, y, width, height, thickness, left, right, top, bottom) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -811,7 +807,7 @@ var World = new Class({ this.updateWall(bottom, 'bottom', x, y + height, width, thickness); return this; - }, + } /** * Updates the 4 rectangle bodies that were created, if `setBounds` was set in the Matter config, to use @@ -827,7 +823,7 @@ var World = new Class({ * @param {number} [width] - The width of the walls, in pixels. Only optional if `add` is `false`. * @param {number} [height] - The height of the walls, in pixels. Only optional if `add` is `false`. */ - updateWall: function (add, position, x, y, width, height) + updateWall(add, position, x, y, width, height) { var wall = this.walls[position]; @@ -853,7 +849,7 @@ var World = new Class({ this.walls[position] = null; } - }, + } /** * Creates a Phaser.GameObjects.Graphics object that is used to render all of the debug bodies and joints to. @@ -870,7 +866,7 @@ var World = new Class({ * * @return {Phaser.GameObjects.Graphics} The newly created Graphics object. */ - createDebugGraphic: function () + createDebugGraphic() { var graphic = this.scene.sys.add.graphics({ x: 0, y: 0 }); @@ -881,7 +877,7 @@ var World = new Class({ this.drawDebug = true; return graphic; - }, + } /** * Sets the world gravity and gravity scale to 0. @@ -891,14 +887,14 @@ var World = new Class({ * * @return {this} This Matter World object. */ - disableGravity: function () + disableGravity() { this.localWorld.gravity.x = 0; this.localWorld.gravity.y = 0; this.localWorld.gravity.scale = 0; return this; - }, + } /** * Sets the worlds gravity to the values given. @@ -914,7 +910,7 @@ var World = new Class({ * * @return {this} This Matter World object. */ - setGravity: function (x, y, scale) + setGravity(x, y, scale) { if (x === undefined) { x = 0; } if (y === undefined) { y = 1; } @@ -925,7 +921,7 @@ var World = new Class({ this.localWorld.gravity.scale = scale; return this; - }, + } /** * Creates a rectangle Matter body and adds it to the world. @@ -941,14 +937,14 @@ var World = new Class({ * * @return {MatterJS.BodyType} The Matter.js body that was created. */ - create: function (x, y, width, height, options) + create(x, y, width, height, options) { var body = Bodies.rectangle(x, y, width, height, options); MatterWorld.add(this.localWorld, body); return body; - }, + } /** * Adds a Matter JS object, or array of objects, to the world. @@ -964,12 +960,12 @@ var World = new Class({ * * @return {this} This Matter World object. */ - add: function (object) + add(object) { MatterWorld.add(this.localWorld, object); return this; - }, + } /** * Removes a Matter JS object, or array of objects, from the world. @@ -986,7 +982,7 @@ var World = new Class({ * * @return {this} This Matter World object. */ - remove: function (object, deep) + remove(object, deep) { if (!Array.isArray(object)) { @@ -1003,7 +999,7 @@ var World = new Class({ } return this; - }, + } /** * Removes a Matter JS constraint, or array of constraints, from the world. @@ -1018,12 +1014,12 @@ var World = new Class({ * * @return {this} This Matter World object. */ - removeConstraint: function (constraint, deep) + removeConstraint(constraint, deep) { Composite.remove(this.localWorld, constraint, deep); return this; - }, + } /** * Adds `MatterTileBody` instances for all the colliding tiles within the given tilemap layer. @@ -1042,7 +1038,7 @@ var World = new Class({ * * @return {this} This Matter World object. */ - convertTilemapLayer: function (tilemapLayer, options) + convertTilemapLayer(tilemapLayer, options) { var layerData = tilemapLayer.layer; var tiles = tilemapLayer.getTilesWithin(0, 0, layerData.width, layerData.height, { isColliding: true }); @@ -1050,7 +1046,7 @@ var World = new Class({ this.convertTiles(tiles, options); return this; - }, + } /** * Creates `MatterTileBody` instances for all of the given tiles. This creates bodies regardless of whether the @@ -1066,7 +1062,7 @@ var World = new Class({ * * @return {this} This Matter World object. */ - convertTiles: function (tiles, options) + convertTiles(tiles, options) { if (tiles.length === 0) { @@ -1079,7 +1075,7 @@ var World = new Class({ } return this; - }, + } /** * Returns the next unique group index for which bodies will collide. @@ -1092,10 +1088,10 @@ var World = new Class({ * * @return {number} Unique category bitfield */ - nextGroup: function (isNonColliding) + nextGroup(isNonColliding) { return MatterBody.nextGroup(isNonColliding); - }, + } /** * Returns the next unique category bitfield (starting after the initial default category 0x0001). @@ -1106,10 +1102,10 @@ var World = new Class({ * * @return {number} Unique category bitfield */ - nextCategory: function () + nextCategory() { return MatterBody.nextCategory(); - }, + } /** * Pauses this Matter World instance and sets `enabled` to `false`. @@ -1122,14 +1118,14 @@ var World = new Class({ * * @return {this} This Matter World object. */ - pause: function () + pause() { this.enabled = false; this.emit(Events.PAUSE); return this; - }, + } /** * Resumes this Matter World instance from a paused state and sets `enabled` to `true`. @@ -1140,7 +1136,7 @@ var World = new Class({ * * @return {this} This Matter World object. */ - resume: function () + resume() { this.enabled = true; @@ -1149,7 +1145,7 @@ var World = new Class({ this.emit(Events.RESUME); return this; - }, + } /** * The internal update method. This is called automatically by the parent Scene. @@ -1171,7 +1167,7 @@ var World = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - update: function (time) + update(time) { if (!this.enabled || !this.autoUpdate) { @@ -1263,7 +1259,7 @@ var World = new Class({ break; } } - }, + } /** * Manually advances the physics simulation by one iteration. @@ -1291,10 +1287,10 @@ var World = new Class({ * * @param {number} [delta=16.666] - The delta value. */ - step: function (delta) + step(delta) { Engine.update(this.engine, delta); - }, + } /** * Runs the Matter Engine.update at a fixed timestep of 60Hz. @@ -1304,10 +1300,10 @@ var World = new Class({ * * @return {number} The delta value to be passed to Engine.update. */ - update60Hz: function () + update60Hz() { return 1000 / 60; - }, + } /** * Runs the Matter Engine.update at a fixed timestep of 30Hz. @@ -1317,10 +1313,10 @@ var World = new Class({ * * @return {number} The delta value to be passed to Engine.update. */ - update30Hz: function () + update30Hz() { return 1000 / 30; - }, + } /** * Returns `true` if the given body can be found within the World. @@ -1332,12 +1328,12 @@ var World = new Class({ * * @return {MatterJS.BodyType[]} An array of all the Matter JS Bodies in this World. */ - has: function (body) + has(body) { var src = (body.hasOwnProperty('body')) ? body.body : body; return (Composite.get(this.localWorld, src.id, src.type) !== null); - }, + } /** * Returns all the bodies in the Matter World, including all bodies in children, recursively. @@ -1347,10 +1343,10 @@ var World = new Class({ * * @return {MatterJS.BodyType[]} An array of all the Matter JS Bodies in this World. */ - getAllBodies: function () + getAllBodies() { return Composite.allBodies(this.localWorld); - }, + } /** * Returns all the constraints in the Matter World, including all constraints in children, recursively. @@ -1360,10 +1356,10 @@ var World = new Class({ * * @return {MatterJS.ConstraintType[]} An array of all the Matter JS Constraints in this World. */ - getAllConstraints: function () + getAllConstraints() { return Composite.allConstraints(this.localWorld); - }, + } /** * Returns all the composites in the Matter World, including all composites in children, recursively. @@ -1373,10 +1369,10 @@ var World = new Class({ * * @return {MatterJS.CompositeType[]} An array of all the Matter JS Composites in this World. */ - getAllComposites: function () + getAllComposites() { return Composite.allComposites(this.localWorld); - }, + } /** * Handles the rendering of bodies and debug information to the debug Graphics object, if enabled. @@ -1387,7 +1383,7 @@ var World = new Class({ * @private * @since 3.0.0 */ - postUpdate: function () + postUpdate() { if (!this.drawDebug) { @@ -1441,7 +1437,7 @@ var World = new Class({ { this.renderCollisions(engine.pairs.list, graphics, config.collisionColor); } - }, + } /** * Renders the Engine Broadphase Controller Grid to the given Graphics instance. @@ -1461,7 +1457,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - renderGrid: function (grid, graphics, lineColor, lineOpacity) + renderGrid(grid, graphics, lineColor, lineOpacity) { graphics.lineStyle(1, lineColor, lineOpacity); @@ -1487,7 +1483,7 @@ var World = new Class({ } return this; - }, + } /** * Renders the list of Pair separations to the given Graphics instance. @@ -1506,7 +1502,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - renderSeparations: function (pairs, graphics, lineColor) + renderSeparations(pairs, graphics, lineColor) { graphics.lineStyle(1, lineColor, 1); @@ -1556,7 +1552,7 @@ var World = new Class({ } return this; - }, + } /** * Renders the list of collision points and normals to the given Graphics instance. @@ -1575,7 +1571,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - renderCollisions: function (pairs, graphics, lineColor) + renderCollisions(pairs, graphics, lineColor) { graphics.lineStyle(1, lineColor, 0.5); graphics.fillStyle(lineColor, 1); @@ -1653,7 +1649,7 @@ var World = new Class({ } return this; - }, + } /** * Renders the bounds of an array of Bodies to the given Graphics instance. @@ -1673,7 +1669,7 @@ var World = new Class({ * @param {number} lineColor - The line color. * @param {number} lineOpacity - The line opacity, between 0 and 1. */ - renderBodyBounds: function (bodies, graphics, lineColor, lineOpacity) + renderBodyBounds(bodies, graphics, lineColor, lineOpacity) { graphics.lineStyle(1, lineColor, lineOpacity); @@ -1717,7 +1713,7 @@ var World = new Class({ } return this; - }, + } /** * Renders either all axes, or a single axis indicator, for an array of Bodies, to the given Graphics instance. @@ -1736,7 +1732,7 @@ var World = new Class({ * @param {number} lineColor - The line color. * @param {number} lineOpacity - The line opacity, between 0 and 1. */ - renderBodyAxes: function (bodies, graphics, showAxes, lineColor, lineOpacity) + renderBodyAxes(bodies, graphics, showAxes, lineColor, lineOpacity) { graphics.lineStyle(1, lineColor, lineOpacity); @@ -1794,7 +1790,7 @@ var World = new Class({ } return this; - }, + } /** * Renders a velocity indicator for an array of Bodies, to the given Graphics instance. @@ -1813,7 +1809,7 @@ var World = new Class({ * @param {number} lineOpacity - The line opacity, between 0 and 1. * @param {number} lineThickness - The line thickness. */ - renderBodyVelocity: function (bodies, graphics, lineColor, lineOpacity, lineThickness) + renderBodyVelocity(bodies, graphics, lineColor, lineOpacity, lineThickness) { graphics.lineStyle(lineThickness, lineColor, lineOpacity); @@ -1836,7 +1832,7 @@ var World = new Class({ } return this; - }, + } /** * Renders the given array of Bodies to the debug graphics instance. @@ -1849,7 +1845,7 @@ var World = new Class({ * * @param {array} bodies - An array of bodies from the localWorld. */ - renderBodies: function (bodies) + renderBodies(bodies) { var graphics = this.debugGraphic; @@ -1926,7 +1922,7 @@ var World = new Class({ this.renderConvexHull(body, graphics, hullColor, lineThickness); } } - }, + } /** * Renders a single Matter Body to the given Phaser Graphics Game Object. @@ -1951,7 +1947,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - renderBody: function (body, graphics, showInternalEdges, lineColor, lineOpacity, lineThickness, fillColor, fillOpacity) + renderBody(body, graphics, showInternalEdges, lineColor, lineOpacity, lineThickness, fillColor, fillOpacity) { if (lineColor === undefined) { lineColor = null; } if (lineOpacity === undefined) { lineOpacity = null; } @@ -2066,7 +2062,7 @@ var World = new Class({ } return this; - }, + } /** * Renders the Convex Hull for a single Matter Body to the given Phaser Graphics Game Object. @@ -2084,7 +2080,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - renderConvexHull: function (body, graphics, hullColor, lineThickness) + renderConvexHull(body, graphics, hullColor, lineThickness) { if (lineThickness === undefined) { lineThickness = 1; } @@ -2113,7 +2109,7 @@ var World = new Class({ } return this; - }, + } /** * Renders all of the constraints in the world (unless they are specifically set to invisible). @@ -2124,7 +2120,7 @@ var World = new Class({ * @private * @since 3.14.0 */ - renderJoints: function () + renderJoints() { var graphics = this.debugGraphic; @@ -2144,7 +2140,7 @@ var World = new Class({ this.renderConstraint(constraints[i], graphics, lineColor, lineOpacity, lineThickness, pinSize, anchorColor, anchorSize); } - }, + } /** * Renders a single Matter Constraint, such as a Pin or a Spring, to the given Phaser Graphics Game Object. @@ -2166,7 +2162,7 @@ var World = new Class({ * * @return {this} This Matter World instance for method chaining. */ - renderConstraint: function (constraint, graphics, lineColor, lineOpacity, lineThickness, pinSize, anchorColor, anchorSize) + renderConstraint(constraint, graphics, lineColor, lineOpacity, lineThickness, pinSize, anchorColor, anchorSize) { var render = constraint.render; @@ -2240,7 +2236,7 @@ var World = new Class({ } return this; - }, + } /** * Resets the internal collision IDs that Matter.JS uses for Body collision groups. @@ -2253,14 +2249,14 @@ var World = new Class({ * @method Phaser.Physics.Matter.World#resetCollisionIDs * @since 3.17.0 */ - resetCollisionIDs: function () + resetCollisionIDs() { Body._nextCollidingGroupId = 1; Body._nextNonCollidingGroupId = -1; Body._nextCategory = 0x0001; return this; - }, + } /** * Will remove all Matter physics event listeners and clear the matter physics world, @@ -2269,7 +2265,7 @@ var World = new Class({ * @method Phaser.Physics.Matter.World#shutdown * @since 3.0.0 */ - shutdown: function () + shutdown() { MatterEvents.off(this.engine); @@ -2283,7 +2279,7 @@ var World = new Class({ { this.debugGraphic.destroy(); } - }, + } /** * Will remove all Matter physics event listeners and clear the matter physics world, @@ -2294,11 +2290,11 @@ var World = new Class({ * @method Phaser.Physics.Matter.World#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); } -}); +}; module.exports = World; diff --git a/src/plugins/BasePlugin.js b/src/plugins/BasePlugin.js index 6cda850853..96daf4283a 100644 --- a/src/plugins/BasePlugin.js +++ b/src/plugins/BasePlugin.js @@ -18,11 +18,9 @@ var Class = require('../utils/Class'); * * @param {Phaser.Plugins.PluginManager} pluginManager - A reference to the Plugin Manager. */ -var BasePlugin = new Class({ +var BasePlugin = class { - initialize: - - function BasePlugin (pluginManager) + constructor(pluginManager) { /** * A handy reference to the Plugin Manager that is responsible for this plugin. @@ -44,7 +42,7 @@ var BasePlugin = new Class({ * @since 3.8.0 */ this.game = pluginManager.game; - }, + } /** * The PluginManager calls this method on a Global Plugin when the plugin is first instantiated. @@ -58,9 +56,9 @@ var BasePlugin = new Class({ * * @param {?any} [data] - A value specified by the user, if any, from the `data` property of the plugin's configuration object (if started at game boot) or passed in the PluginManager's `install` method (if started manually). */ - init: function () + init() { - }, + } /** * The PluginManager calls this method on a Global Plugin when the plugin is started. @@ -71,7 +69,7 @@ var BasePlugin = new Class({ * @method Phaser.Plugins.BasePlugin#start * @since 3.8.0 */ - start: function () + start() { // 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. @@ -87,7 +85,7 @@ var BasePlugin = new Class({ // eventEmitter.on('poststep', this.gamePostStep, this); // eventEmitter.on('prerender', this.gamePreRender, this); // eventEmitter.on('postrender', this.gamePostRender, this); - }, + } /** * The PluginManager calls this method on a Global Plugin when the plugin is stopped. @@ -100,9 +98,9 @@ var BasePlugin = new Class({ * @method Phaser.Plugins.BasePlugin#stop * @since 3.8.0 */ - stop: function () + stop() { - }, + } /** * Game instance has been destroyed. @@ -111,7 +109,7 @@ var BasePlugin = new Class({ * @method Phaser.Plugins.BasePlugin#destroy * @since 3.8.0 */ - destroy: function () + destroy() { this.pluginManager = null; this.game = null; @@ -119,6 +117,6 @@ var BasePlugin = new Class({ this.systems = null; } -}); +}; module.exports = BasePlugin; diff --git a/src/plugins/PluginManager.js b/src/plugins/PluginManager.js index 9b84bbd81b..b15a121fd7 100644 --- a/src/plugins/PluginManager.js +++ b/src/plugins/PluginManager.js @@ -56,15 +56,11 @@ var CONST = require('../const'); * * @param {Phaser.Game} game - The game instance that owns this Plugin Manager. */ -var PluginManager = new Class({ +var PluginManager = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function PluginManager (game) + constructor(game) { - EventEmitter.call(this); + super(); /** * The game instance that owns this Plugin Manager. @@ -122,7 +118,7 @@ var PluginManager = new Class({ { game.events.once(GameEvents.BOOT, this.boot, this); } - }, + } /** * Runs once the game has booted and installs all of the plugins configured in the Game Config. @@ -131,7 +127,7 @@ var PluginManager = new Class({ * @protected * @since 3.0.0 */ - boot: function () + boot() { var i; var entry; @@ -207,7 +203,7 @@ var PluginManager = new Class({ this._pendingScene = []; this.game.events.once(GameEvents.DESTROY, this.destroy, this); - }, + } /** * Called by the Scene Systems class. Tells the plugin manager to install all Scene plugins into it. @@ -224,7 +220,7 @@ var PluginManager = new Class({ * @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) + addToScene(sys, globalPlugins, scenePlugins) { var i; var pluginKey; @@ -306,7 +302,7 @@ var PluginManager = new Class({ scene[entry.mapping] = entry.plugin; } } - }, + } /** * Called by the Scene Systems class. Returns a list of plugins to be installed. @@ -317,7 +313,7 @@ var PluginManager = new Class({ * * @return {string[]} A list keys of all the Scene Plugins to install. */ - getDefaultScenePlugins: function () + getDefaultScenePlugins() { var list = this.game.config.defaultPlugins; @@ -325,7 +321,7 @@ var PluginManager = new Class({ list = list.concat(this.scenePlugins); return list; - }, + } /** * Installs a new Scene Plugin into the Plugin Manager and optionally adds it @@ -356,7 +352,7 @@ var PluginManager = new Class({ * @param {Phaser.Scene} [addToScene] - Optionally automatically add this plugin to the given Scene. * @param {boolean} [fromLoader=false] - Is this being called by the Loader? */ - installScenePlugin: function (key, plugin, mapping, addToScene, fromLoader) + installScenePlugin(key, plugin, mapping, addToScene, fromLoader) { if (fromLoader === undefined) { fromLoader = false; } @@ -396,7 +392,7 @@ var PluginManager = new Class({ instance.boot(); } - }, + } /** * Installs a new Global Plugin into the Plugin Manager and optionally starts it running. @@ -429,7 +425,7 @@ var PluginManager = new Class({ * * @return {?Phaser.Plugins.BasePlugin} The plugin that was started, or `null` if `start` was false, or game isn't yet booted. */ - install: function (key, plugin, start, mapping, data) + install(key, plugin, start, mapping, data) { if (start === undefined) { start = false; } if (mapping === undefined) { mapping = null; } @@ -468,7 +464,7 @@ var PluginManager = new Class({ } return null; - }, + } /** * Gets an index of a global plugin based on the given key. @@ -481,7 +477,7 @@ var PluginManager = new Class({ * * @return {number} The index of the plugin within the plugins array. */ - getIndex: function (key) + getIndex(key) { var list = this.plugins; @@ -496,7 +492,7 @@ var PluginManager = new Class({ } return -1; - }, + } /** * Gets a global plugin based on the given key. @@ -509,7 +505,7 @@ var PluginManager = new Class({ * * @return {Phaser.Types.Plugins.GlobalPlugin} The plugin entry. */ - getEntry: function (key) + getEntry(key) { var idx = this.getIndex(key); @@ -517,7 +513,7 @@ var PluginManager = new Class({ { return this.plugins[idx]; } - }, + } /** * Checks if the given global plugin, based on its key, is active or not. @@ -529,12 +525,12 @@ var PluginManager = new Class({ * * @return {boolean} `true` if the plugin is active, otherwise `false`. */ - isActive: function (key) + isActive(key) { var entry = this.getEntry(key); return (entry && entry.active); - }, + } /** * Starts a global plugin running. @@ -555,7 +551,7 @@ var PluginManager = new Class({ * * @return {?Phaser.Plugins.BasePlugin} The plugin that was started, or `null` if invalid key given or plugin is already stopped. */ - start: function (key, runAs) + start(key, runAs) { if (runAs === undefined) { runAs = key; } @@ -574,7 +570,7 @@ var PluginManager = new Class({ } return (entry) ? entry.plugin : null; - }, + } /** * Creates a new instance of a global plugin, adds an entry into the plugins array and returns it. @@ -588,7 +584,7 @@ var PluginManager = new Class({ * * @return {?Phaser.Plugins.BasePlugin} The plugin that was started, or `null` if invalid key given. */ - createEntry: function (key, runAs) + createEntry(key, runAs) { var entry = PluginCache.getCustom(key); @@ -611,7 +607,7 @@ var PluginManager = new Class({ } return entry; - }, + } /** * Stops a global plugin from running. @@ -628,7 +624,7 @@ var PluginManager = new Class({ * * @return {this} The Plugin Manager. */ - stop: function (key) + stop(key) { var entry = this.getEntry(key); @@ -639,7 +635,7 @@ var PluginManager = new Class({ } return this; - }, + } /** * Gets a global plugin from the Plugin Manager based on the given key and returns it. @@ -655,7 +651,7 @@ var PluginManager = new Class({ * * @return {?(Phaser.Plugins.BasePlugin|function)} The plugin, or `null` if no plugin was found matching the key. */ - get: function (key, autoStart) + get(key, autoStart) { if (autoStart === undefined) { autoStart = true; } @@ -682,7 +678,7 @@ var PluginManager = new Class({ } return null; - }, + } /** * Returns the plugin class from the cache. @@ -695,10 +691,10 @@ var PluginManager = new Class({ * * @return {Phaser.Plugins.BasePlugin} A Plugin object */ - getClass: function (key) + getClass(key) { return PluginCache.getCustomClass(key); - }, + } /** * Removes a global plugin from the Plugin Manager and Plugin Cache. @@ -710,7 +706,7 @@ var PluginManager = new Class({ * * @param {string} key - The key of the plugin to remove. */ - removeGlobalPlugin: function (key) + removeGlobalPlugin(key) { var entry = this.getEntry(key); @@ -720,7 +716,7 @@ var PluginManager = new Class({ } PluginCache.removeCustom(key); - }, + } /** * Removes a scene plugin from the Plugin Manager and Plugin Cache. @@ -734,12 +730,12 @@ var PluginManager = new Class({ * * @param {string} key - The key of the plugin to remove. */ - removeScenePlugin: function (key) + removeScenePlugin(key) { Remove(this.scenePlugins, key); PluginCache.remove(key); - }, + } /** * Registers a new type of Game Object with the global Game Object Factory and / or Creator. @@ -775,7 +771,7 @@ var PluginManager = new Class({ * @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) + registerGameObject(key, factoryCallback, creatorCallback) { if (factoryCallback) { @@ -788,7 +784,7 @@ var PluginManager = new Class({ } return this; - }, + } /** * Removes a previously registered Game Object from the global Game Object Factory and / or Creator. @@ -801,7 +797,7 @@ var PluginManager = new Class({ * @param {boolean} [removeFromFactory=true] - Should the Game Object be removed from the Game Object Factory? * @param {boolean} [removeFromCreator=true] - Should the Game Object be removed from the Game Object Creator? */ - removeGameObject: function (key, removeFromFactory, removeFromCreator) + removeGameObject(key, removeFromFactory, removeFromCreator) { if (removeFromFactory === undefined) { removeFromFactory = true; } if (removeFromCreator === undefined) { removeFromCreator = true; } @@ -817,7 +813,7 @@ var PluginManager = new Class({ } return this; - }, + } /** * Registers a new file type with the global File Types Manager, making it available to all Loader @@ -853,7 +849,7 @@ var PluginManager = new Class({ * @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) + registerFileType(key, callback, addToScene) { FileTypesManager.register(key, callback); @@ -861,7 +857,7 @@ var PluginManager = new Class({ { addToScene.sys.load[key] = callback; } - }, + } /** * Destroys this Plugin Manager and all associated plugins. @@ -872,7 +868,7 @@ var PluginManager = new Class({ * @method Phaser.Plugins.PluginManager#destroy * @since 3.8.0 */ - destroy: function () + destroy() { for (var i = 0; i < this.plugins.length; i++) { @@ -891,7 +887,7 @@ var PluginManager = new Class({ this.scenePlugins = []; } -}); +}; /* * "Sometimes, the elegant implementation is just a function. diff --git a/src/plugins/ScenePlugin.js b/src/plugins/ScenePlugin.js index e62d6acbd2..f8adf82ccf 100644 --- a/src/plugins/ScenePlugin.js +++ b/src/plugins/ScenePlugin.js @@ -24,15 +24,11 @@ var SceneEvents = require('../scene/events'); * @param {Phaser.Plugins.PluginManager} pluginManager - A reference to the Plugin Manager. * @param {string} pluginKey - The key under which this plugin has been installed into the Scene Systems. */ -var ScenePlugin = new Class({ +var ScenePlugin = class extends BasePlugin { - Extends: BasePlugin, - - initialize: - - function ScenePlugin (scene, pluginManager, pluginKey) + constructor(scene, pluginManager, pluginKey) { - BasePlugin.call(this, pluginManager); + super(pluginManager); /** * A reference to the Scene that has installed this plugin. @@ -74,7 +70,7 @@ var ScenePlugin = new Class({ this.pluginKey = pluginKey; scene.sys.events.once(SceneEvents.BOOT, this.boot, this); - }, + } /** * This method is called when the Scene boots. It is only ever called once. @@ -111,9 +107,9 @@ var ScenePlugin = new Class({ * @method Phaser.Plugins.ScenePlugin#boot * @since 3.8.0 */ - boot: function () + boot() { - }, + } /** * Game instance has been destroyed. @@ -123,7 +119,7 @@ var ScenePlugin = new Class({ * @method Phaser.Plugins.ScenePlugin#destroy * @since 3.8.0 */ - destroy: function () + destroy() { this.pluginManager = null; this.game = null; @@ -131,6 +127,6 @@ var ScenePlugin = new Class({ this.systems = null; } -}); +}; module.exports = ScenePlugin; diff --git a/src/renderer/canvas/CanvasRenderer.js b/src/renderer/canvas/CanvasRenderer.js index a42472e6bb..f7b0f797cf 100644 --- a/src/renderer/canvas/CanvasRenderer.js +++ b/src/renderer/canvas/CanvasRenderer.js @@ -32,15 +32,11 @@ var TransformMatrix = require('../../gameobjects/components/TransformMatrix'); * * @param {Phaser.Game} game - The Phaser Game instance that owns this renderer. */ -var CanvasRenderer = new Class({ +var CanvasRenderer = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function CanvasRenderer (game) + constructor(game) { - EventEmitter.call(this); + super(); var gameConfig = game.config; @@ -218,7 +214,7 @@ var CanvasRenderer = new Class({ this.isBooted = false; this.init(); - }, + } /** * Prepares the game canvas for rendering. @@ -226,7 +222,7 @@ var CanvasRenderer = new Class({ * @method Phaser.Renderer.Canvas.CanvasRenderer#init * @since 3.0.0 */ - init: function () + init() { var game = this.game; @@ -246,7 +242,7 @@ var CanvasRenderer = new Class({ }, this); game.textures.once(TextureEvents.READY, this.boot, this); - }, + } /** * Internal boot handler. @@ -255,7 +251,7 @@ var CanvasRenderer = new Class({ * @private * @since 3.50.0 */ - boot: function () + boot() { var game = this.game; @@ -269,7 +265,7 @@ var CanvasRenderer = new Class({ game.scale.on(ScaleEvents.RESIZE, this.onResize, this); this.resize(baseSize.width, baseSize.height); - }, + } /** * The event handler that manages the `resize` event dispatched by the Scale Manager. @@ -280,14 +276,14 @@ var CanvasRenderer = new Class({ * @param {Phaser.Structs.Size} gameSize - The default Game Size object. This is the un-modified game dimensions. * @param {Phaser.Structs.Size} baseSize - The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this. */ - onResize: function (gameSize, baseSize) + onResize(gameSize, baseSize) { // Has the underlying canvas size changed? if (baseSize.width !== this.width || baseSize.height !== this.height) { this.resize(baseSize.width, baseSize.height); } - }, + } /** * Resize the main game canvas. @@ -299,13 +295,13 @@ var CanvasRenderer = new Class({ * @param {number} [width] - The new width of the renderer. * @param {number} [height] - The new height of the renderer. */ - resize: function (width, height) + resize(width, height) { this.width = width; this.height = height; this.emit(Events.RESIZE, width, height); - }, + } /** * Resets the transformation matrix of the current context to the identity matrix, thus resetting any transformation. @@ -313,10 +309,10 @@ var CanvasRenderer = new Class({ * @method Phaser.Renderer.Canvas.CanvasRenderer#resetTransform * @since 3.0.0 */ - resetTransform: function () + resetTransform() { this.currentContext.setTransform(1, 0, 0, 1, 0, 0); - }, + } /** * Sets the blend mode (compositing operation) of the current context. @@ -328,12 +324,12 @@ var CanvasRenderer = new Class({ * * @return {this} This CanvasRenderer object. */ - setBlendMode: function (blendMode) + setBlendMode(blendMode) { this.currentContext.globalCompositeOperation = blendMode; return this; - }, + } /** * Changes the Canvas Rendering Context that all draw operations are performed against. @@ -345,12 +341,12 @@ var CanvasRenderer = new Class({ * * @return {this} The Canvas Renderer instance. */ - setContext: function (ctx) + setContext(ctx) { this.currentContext = (ctx) ? ctx : this.gameContext; return this; - }, + } /** * Sets the global alpha of the current context. @@ -362,12 +358,12 @@ var CanvasRenderer = new Class({ * * @return {this} This CanvasRenderer object. */ - setAlpha: function (alpha) + setAlpha(alpha) { this.currentContext.globalAlpha = alpha; return this; - }, + } /** * Called at the start of the render loop. @@ -377,7 +373,7 @@ var CanvasRenderer = new Class({ * @fires Phaser.Renderer.Events#PRE_RENDER * @since 3.0.0 */ - preRender: function () + preRender() { var ctx = this.gameContext; var config = this.config; @@ -407,7 +403,7 @@ var CanvasRenderer = new Class({ this.drawCount = 0; this.emit(Events.PRE_RENDER); - }, + } /** * The core render step for a Scene Camera. @@ -427,7 +423,7 @@ var CanvasRenderer = new Class({ * @param {Phaser.GameObjects.GameObject[]} children - An array of filtered Game Objects that can be rendered by the given Camera. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Scene Camera to render with. */ - render: function (scene, children, camera) + render(scene, children, camera) { var childCount = children.length; @@ -525,7 +521,7 @@ var CanvasRenderer = new Class({ } camera.emit(CameraEvents.POST_RENDER, camera); - }, + } /** * Restores the game context's global settings and takes a snapshot if one is scheduled. @@ -536,7 +532,7 @@ var CanvasRenderer = new Class({ * @fires Phaser.Renderer.Events#POST_RENDER * @since 3.0.0 */ - postRender: function () + postRender() { var ctx = this.gameContext; @@ -552,7 +548,7 @@ var CanvasRenderer = new Class({ state.callback = null; } - }, + } /** * Takes a snapshot of the given area of the given canvas. @@ -577,7 +573,7 @@ var CanvasRenderer = new Class({ * * @return {this} This Canvas Renderer. */ - snapshotCanvas: function (canvas, callback, getPixel, x, y, width, height, type, encoderOptions) + snapshotCanvas(canvas, callback, getPixel, x, y, width, height, type, encoderOptions) { if (getPixel === undefined) { getPixel = false; } @@ -592,7 +588,7 @@ var CanvasRenderer = new Class({ state.callback = null; return this; - }, + } /** * Schedules a snapshot of the entire game viewport to be taken after the current frame is rendered. @@ -614,10 +610,10 @@ var CanvasRenderer = new Class({ * * @return {this} This WebGL Renderer. */ - snapshot: function (callback, type, encoderOptions) + snapshot(callback, type, encoderOptions) { return this.snapshotArea(0, 0, this.gameCanvas.width, this.gameCanvas.height, callback, type, encoderOptions); - }, + } /** * Schedules a snapshot of the given area of the game viewport to be taken after the current frame is rendered. @@ -643,7 +639,7 @@ var CanvasRenderer = new Class({ * * @return {this} This WebGL Renderer. */ - snapshotArea: function (x, y, width, height, callback, type, encoderOptions) + snapshotArea(x, y, width, height, callback, type, encoderOptions) { var state = this.snapshotState; @@ -657,7 +653,7 @@ var CanvasRenderer = new Class({ state.height = Math.min(height, this.gameCanvas.height); return this; - }, + } /** * Schedules a snapshot of the given pixel from the game viewport to be taken after the current frame is rendered. @@ -680,14 +676,14 @@ var CanvasRenderer = new Class({ * * @return {this} This WebGL Renderer. */ - snapshotPixel: function (x, y, callback) + snapshotPixel(x, y, callback) { this.snapshotArea(x, y, 1, 1, callback); this.snapshotState.getPixel = true; return this; - }, + } /** * Takes a Sprite Game Object, or any object that extends it, and draws it to the current context. @@ -700,7 +696,7 @@ var CanvasRenderer = new Class({ * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to use for the rendering transform. * @param {Phaser.GameObjects.Components.TransformMatrix} [parentTransformMatrix] - The transform matrix of the parent container, if set. */ - batchSprite: function (sprite, frame, camera, parentTransformMatrix) + batchSprite(sprite, frame, camera, parentTransformMatrix) { var alpha = camera.alpha * sprite.alpha; @@ -872,7 +868,7 @@ var CanvasRenderer = new Class({ } ctx.restore(); - }, + } /** * Destroys all object references in the Canvas Renderer. @@ -880,7 +876,7 @@ var CanvasRenderer = new Class({ * @method Phaser.Renderer.Canvas.CanvasRenderer#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.removeAllListeners(); @@ -889,6 +885,6 @@ var CanvasRenderer = new Class({ this.gameContext = null; } -}); +}; module.exports = CanvasRenderer; diff --git a/src/renderer/webgl/DrawingContext.js b/src/renderer/webgl/DrawingContext.js index da175225a5..37bf0a799c 100644 --- a/src/renderer/webgl/DrawingContext.js +++ b/src/renderer/webgl/DrawingContext.js @@ -32,10 +32,8 @@ var Class = require('../../utils/Class'); * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this context. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.DrawingContextOptions} [options] - The options for this context. */ -var DrawingContext = new Class({ - initialize: - - function DrawingContext (renderer, options) +var DrawingContext = class { + constructor(renderer, options) { if (options === undefined) { options = {}; } @@ -215,7 +213,7 @@ var DrawingContext = new Class({ options.height || renderer.height ); } - }, + } /** * Resize the DrawingContext. @@ -227,7 +225,7 @@ var DrawingContext = new Class({ * @param {number} width - The new width of the framebuffer. * @param {number} height - The new height of the framebuffer. */ - resize: function (width, height) + resize(width, height) { width = Math.round(width); height = Math.round(height); @@ -269,7 +267,7 @@ var DrawingContext = new Class({ this.state.scissor.box = [ 0, 0, width, height ]; this.state.viewport = [ 0, 0, width, height ]; - }, + } /** * Copy the state of another DrawingContext. @@ -278,7 +276,7 @@ var DrawingContext = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} source - The DrawingContext to copy from. */ - copy: function (source) + copy(source) { var state = source.state; var blend = state.blend; @@ -311,7 +309,7 @@ var DrawingContext = new Class({ }, viewport: state.viewport.slice() }; - }, + } /** * Create a clone of the DrawingContext. This is intended to be mutated @@ -326,7 +324,7 @@ var DrawingContext = new Class({ * @param {boolean} [preserveAutoClear=false] - Whether to preserve the autoClear setting. * @return {Phaser.Renderer.WebGL.DrawingContext} The cloned DrawingContext. */ - getClone: function (preserveAutoClear) + getClone(preserveAutoClear) { var context = new DrawingContext(this.renderer, { copyFrom: this }); @@ -336,7 +334,7 @@ var DrawingContext = new Class({ } return context; - }, + } /** * Set the buffers to clear when the DrawingContext comes into use. @@ -347,7 +345,7 @@ var DrawingContext = new Class({ * @param {boolean} depth - Whether to clear the depth buffer. * @param {boolean} stencil - Whether to clear the stencil buffer. */ - setAutoClear: function (color, depth, stencil) + setAutoClear(color, depth, stencil) { var autoClear = 0; var gl = this.renderer.gl; @@ -355,7 +353,7 @@ var DrawingContext = new Class({ if (depth) { autoClear |= gl.DEPTH_BUFFER_BIT; } if (stencil) { autoClear |= gl.STENCIL_BUFFER_BIT; } this.autoClear = autoClear; - }, + } /** * Set the blend mode for the DrawingContext. @@ -365,7 +363,7 @@ var DrawingContext = new Class({ * @param {number} blendMode - The blend mode to set. * @param {number[]} [blendColor] - The blend color to set. This is an array of 4 values: red, green, blue, alpha. */ - setBlendMode: function (blendMode, blendColor) + setBlendMode(blendMode, blendColor) { if (blendMode === this.blendMode) { return; } @@ -386,7 +384,7 @@ var DrawingContext = new Class({ } this.blendMode = blendMode; - }, + } /** * Set the camera for the DrawingContext. @@ -395,10 +393,10 @@ var DrawingContext = new Class({ * @since 4.0.0 * @param {Phaser.Cameras.Scene2D.Camera} camera - The camera to set. */ - setCamera: function (camera) + setCamera(camera) { this.camera = camera; - }, + } /** * Set the clear color for the DrawingContext. @@ -411,7 +409,7 @@ var DrawingContext = new Class({ * @param {number} b - The blue component of the color to clear with. * @param {number} a - The alpha component of the color to clear with. */ - setClearColor: function (r, g, b, a) + setClearColor(r, g, b, a) { var colorClearValue = this.state.colorClearValue; if ( @@ -422,7 +420,7 @@ var DrawingContext = new Class({ ) { return; } this.state.colorClearValue = [ r, g, b, a ]; - }, + } /** * Set the scissor box for the DrawingContext. @@ -434,13 +432,13 @@ var DrawingContext = new Class({ * @param {number} width - The width of the scissor box. * @param {number} height - The height of the scissor box. */ - setScissorBox: function (x, y, width, height) + setScissorBox(x, y, width, height) { // Convert Y coordinate to WebGL space. y = this.height - y - height; this.state.scissor.box = [ x, y, width, height ]; - }, + } /** * Enable or disable the scissor box for the DrawingContext. @@ -449,10 +447,10 @@ var DrawingContext = new Class({ * @since 4.0.0 * @param {boolean} enable - Whether to enable the scissor box. */ - setScissorEnable: function (enable) + setScissorEnable(enable) { this.state.scissor.enable = enable; - }, + } /** * Begin using the DrawingContext. @@ -461,7 +459,7 @@ var DrawingContext = new Class({ * @method Phaser.Renderer.WebGL.DrawingContext#use * @since 4.0.0 */ - use: function () + use() { this.renderer.renderNodes.finishBatch(); @@ -469,7 +467,7 @@ var DrawingContext = new Class({ { this.clear(); } - }, + } /** * End using the DrawingContext. This marks the context as not in use, @@ -482,7 +480,7 @@ var DrawingContext = new Class({ * @method Phaser.Renderer.WebGL.DrawingContext#release * @since 4.0.0 */ - release: function () + release() { if (this.pool && this._locks.length === 0) { @@ -491,7 +489,7 @@ var DrawingContext = new Class({ } this.renderer.renderNodes.finishBatch(); - }, + } /** * Lock the DrawingContext to be in use. @@ -504,14 +502,14 @@ var DrawingContext = new Class({ * @since 4.0.0 * @param {any} key - The key to lock the DrawingContext with. */ - lock: function (key) + lock(key) { if (this._locks.indexOf(key) !== -1) { return; } this._locks.push(key); - }, + } /** * Unlock the DrawingContext. @@ -522,7 +520,7 @@ var DrawingContext = new Class({ * @param {any} key - The key to unlock the DrawingContext with. This must be the same key used to lock it. * @param {boolean} [release] - Whether to release the DrawingContext immediately. This will only happen if there are no other locks on it. */ - unlock: function (key, release) + unlock(key, release) { var index = this._locks.indexOf(key); if (index !== -1) @@ -534,7 +532,7 @@ var DrawingContext = new Class({ { this.release(); } - }, + } /** * Check whether the DrawingContext is locked. @@ -543,10 +541,10 @@ var DrawingContext = new Class({ * @since 4.0.0 * @return {boolean} Whether the DrawingContext is locked. */ - isLocked: function () + isLocked() { return this._locks.length > 0; - }, + } /** * Begin drawing with the DrawingContext. @@ -557,10 +555,10 @@ var DrawingContext = new Class({ * @method Phaser.Renderer.WebGL.DrawingContext#beginDraw * @since 4.0.0 */ - beginDraw: function () + beginDraw() { this.renderer.glWrapper.update(this.state); - }, + } /** * Clear the framebuffer. This will bind the framebuffer. @@ -568,7 +566,7 @@ var DrawingContext = new Class({ * @method Phaser.Renderer.WebGL.DrawingContext#clear * @since 4.0.0 */ - clear: function (bits) + clear(bits) { this.beginDraw(); @@ -580,7 +578,7 @@ var DrawingContext = new Class({ this.renderer.renderNodes.finishBatch(); this.renderer.gl.clear(bits); - }, + } /** * Destroys the DrawingContext and its resources. @@ -588,7 +586,7 @@ var DrawingContext = new Class({ * @method Phaser.Renderer.WebGL.DrawingContext#destroy * @since 4.0.0 */ - destroy: function () + destroy() { this.renderer.deleteTexture(this.texture); this.renderer.deleteFramebuffer(this.state.bindings.framebuffer); @@ -599,6 +597,6 @@ var DrawingContext = new Class({ this.framebuffer = null; this.texture = null; } -}); +}; module.exports = DrawingContext; diff --git a/src/renderer/webgl/DrawingContextPool.js b/src/renderer/webgl/DrawingContextPool.js index dbfbd4dc21..780096f697 100644 --- a/src/renderer/webgl/DrawingContextPool.js +++ b/src/renderer/webgl/DrawingContextPool.js @@ -31,8 +31,8 @@ var DrawingContext = require('./DrawingContext'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this DrawingContextPool. */ -var DrawingContextPool = new Class({ - initialize: function DrawingContextPool (renderer, maxAge, maxPoolSize) +var DrawingContextPool = class { + constructor(renderer, maxAge, maxPoolSize) { /** * The renderer that owns this DrawingContextPool. @@ -84,7 +84,7 @@ var DrawingContextPool = new Class({ * @since 4.0.0 */ this.sizePool = {}; - }, + } /** * Adds a DrawingContext to the pool. @@ -94,7 +94,7 @@ var DrawingContextPool = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The DrawingContext to add to the pool. */ - add: function (drawingContext) + add(drawingContext) { if (this.agePool.indexOf(drawingContext) !== -1) { @@ -113,7 +113,7 @@ var DrawingContextPool = new Class({ } this.agePool.push(drawingContext); - }, + } /** * Returns a DrawingContext of the given dimensions. @@ -124,7 +124,7 @@ var DrawingContextPool = new Class({ * @param {number} [height] - The height of the DrawingContext. * @return {Phaser.Renderer.WebGL.DrawingContext} The DrawingContext. */ - get: function (width, height) + get(width, height) { var drawingContext; @@ -218,7 +218,7 @@ var DrawingContextPool = new Class({ }); return drawingContext; - }, + } /** * Sets the maximum age of a DrawingContext in milliseconds. @@ -227,10 +227,10 @@ var DrawingContextPool = new Class({ * @since 4.0.0 * @param {number} maxAge - The maximum age of a DrawingContext in milliseconds. */ - setMaxAge: function (maxAge) + setMaxAge(maxAge) { this.maxAge = maxAge; - }, + } /** * Sets the maximum number of DrawingContexts to store. @@ -239,10 +239,10 @@ var DrawingContextPool = new Class({ * @since 4.0.0 * @param {number} maxPoolSize - The maximum number of DrawingContexts to store. */ - setMaxPoolSize: function (maxPoolSize) + setMaxPoolSize(maxPoolSize) { this.maxPoolSize = maxPoolSize; - }, + } /** * Clears the DrawingContextPool. This will not destroy any DrawingContexts @@ -251,7 +251,7 @@ var DrawingContextPool = new Class({ * @method Phaser.Renderer.WebGL.DrawingContextPool#clear * @since 4.0.0 */ - clear: function () + clear() { for (var i = 0; i < this.agePool.length; i++) { @@ -260,7 +260,7 @@ var DrawingContextPool = new Class({ this.sizePool = {}; this.agePool.length = 0; - }, + } /** * Prunes the DrawingContextPool down to the maximum pool size. @@ -270,7 +270,7 @@ var DrawingContextPool = new Class({ * @method Phaser.Renderer.WebGL.DrawingContextPool#prune * @since 4.0.0 */ - prune: function () + prune() { var sizePool = this.sizePool; var agePool = this.agePool; @@ -291,6 +291,6 @@ var DrawingContextPool = new Class({ } } } -}); +}; module.exports = DrawingContextPool; diff --git a/src/renderer/webgl/ProgramManager.js b/src/renderer/webgl/ProgramManager.js index 0e4cc76d4b..37be529adf 100644 --- a/src/renderer/webgl/ProgramManager.js +++ b/src/renderer/webgl/ProgramManager.js @@ -23,8 +23,8 @@ var DeepCopy = require('../../utils/object/DeepCopy'); * @param {Phaser.Types.Renderer.WebGL.WebGLAttributeBufferLayout[]} attributeBufferLayouts - The attribute buffer layouts to use in the program. * @param {Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper} [indexBuffer] - The index buffer to use in the program, if any. */ -var ProgramManager = new Class({ - initialize: function ProgramManager (renderer, attributeBufferLayouts, indexBuffer) +var ProgramManager = class { + constructor(renderer, attributeBufferLayouts, indexBuffer) { /** * The current WebGLRenderer instance. @@ -105,7 +105,7 @@ var ProgramManager = new Class({ * @since 4.0.0 */ this.uniforms = {}; - }, + } /** * Returns a program suite based on the current configuration. @@ -125,7 +125,7 @@ var ProgramManager = new Class({ * @since 4.0.0 * @return {?{ program: Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper, vao: Phaser.Renderer.WebGL.Wrappers.WebGLVAOWrapper, config: object }} The program suite, or `null` if the program is not available. */ - getCurrentProgramSuite: function () + getCurrentProgramSuite() { var config = this.currentConfig; var renderer = this.renderer; @@ -157,7 +157,7 @@ var ProgramManager = new Class({ } return this.programs[key] || null; - }, + } /** * Resets the current configuration object. @@ -165,13 +165,13 @@ var ProgramManager = new Class({ * @method Phaser.Renderer.WebGL.ProgramManager#resetCurrentConfig * @since 4.0.0 */ - resetCurrentConfig: function () + resetCurrentConfig() { this.currentConfig.base.vertexShader = ''; this.currentConfig.base.fragmentShader = ''; this.currentConfig.additions.length = 0; this.currentConfig.features.length = 0; - }, + } /** * Set the value of a uniform, @@ -182,10 +182,10 @@ var ProgramManager = new Class({ * @param {string} name - The name of the uniform. * @param {any} value - The value of the uniform. */ - setUniform: function (name, value) + setUniform(name, value) { this.uniforms[name] = value; - }, + } /** * Delete a uniform value. While unused uniforms are not harmful, @@ -195,10 +195,10 @@ var ProgramManager = new Class({ * @since 4.0.0 * @param {string} name - The name of the uniform. */ - removeUniform: function (name) + removeUniform(name) { delete this.uniforms[name]; - }, + } /** * Remove all uniforms. @@ -206,10 +206,10 @@ var ProgramManager = new Class({ * @method Phaser.Renderer.WebGL.ProgramManager#clearUniforms * @since 4.0.0 */ - clearUniforms: function () + clearUniforms() { this.uniforms.length = 0; - }, + } /** * Set the stored uniforms on a shader program. @@ -217,7 +217,7 @@ var ProgramManager = new Class({ * @method Phaser.Renderer.WebGL.ProgramManager#applyUniforms * @since 4.0.0 */ - applyUniforms: function (program) + applyUniforms(program) { var uniforms = this.uniforms; @@ -225,7 +225,7 @@ var ProgramManager = new Class({ { program.setUniform(name, uniforms[name]); } - }, + } /** * Set the base shader for the current configuration. @@ -236,13 +236,13 @@ var ProgramManager = new Class({ * @param {string} vertexShader - The vertex shader source code. * @param {string} fragmentShader - The fragment shader source code. */ - setBaseShader: function (name, vertexShader, fragmentShader) + setBaseShader(name, vertexShader, fragmentShader) { var base = this.currentConfig.base; base.name = name; base.vertexShader = vertexShader; base.fragmentShader = fragmentShader; - }, + } /** * Add a shader addition to the current configuration. @@ -252,7 +252,7 @@ var ProgramManager = new Class({ * @param {Phaser.Types.Renderer.WebGL.ShaderAdditionConfig} addition - The shader addition to add. * @param {number} [index] - The index at which to insert the addition. If not specified, it will be added at the end. */ - addAddition: function (addition, index) + addAddition(addition, index) { if (index === undefined) { @@ -262,7 +262,7 @@ var ProgramManager = new Class({ { this.currentConfig.additions.splice(index, 0, addition); } - }, + } /** * Returns the addition with the given name. @@ -272,7 +272,7 @@ var ProgramManager = new Class({ * @param {string} name - The name to find. * @returns {?Phaser.Types.Renderer.WebGL.ShaderAdditionConfig} The addition, or `null` if it was not found. */ - getAddition: function (name) + getAddition(name) { var additions = this.currentConfig.additions; for (var i = 0; i < additions.length; i++) @@ -284,7 +284,7 @@ var ProgramManager = new Class({ } } return null; - }, + } /** * Returns a list of shader additions in the current config @@ -295,7 +295,7 @@ var ProgramManager = new Class({ * @param {string} tag - The tag to filter by. * @returns {Phaser.Types.Renderer.WebGL.ShaderAdditionConfig[]} The shader additions with the tag. */ - getAdditionsByTag: function (tag) + getAdditionsByTag(tag) { return this.currentConfig.additions.filter(function (addition) { @@ -305,7 +305,7 @@ var ProgramManager = new Class({ } return addition.tags.includes(tag); }); - }, + } /** * Returns the index of a shader addition with the given name. @@ -315,13 +315,13 @@ var ProgramManager = new Class({ * @param {string} name - The name to find. * @returns {number} The index of the addition, or `-1` if it was not found. */ - getAdditionIndex: function (name) + getAdditionIndex(name) { return this.currentConfig.additions.findIndex(function (addition) { return addition.name === name; }); - }, + } /** * Remove a shader addition from the current configuration. @@ -330,13 +330,13 @@ var ProgramManager = new Class({ * @since 4.0.0 * @param {string} name - The name of the shader addition to remove. */ - removeAddition: function (name) + removeAddition(name) { this.currentConfig.additions = this.currentConfig.additions.filter(function (addition) { return addition.name !== name; }); - }, + } /** * Replace a shader addition in the current configuration. @@ -346,7 +346,7 @@ var ProgramManager = new Class({ * @param {string} name - The name of the shader addition to replace. * @param {Phaser.Types.Renderer.WebGL.ShaderAdditionConfig} addition - The new shader addition. */ - replaceAddition: function (name, addition) + replaceAddition(name, addition) { var index = this.currentConfig.additions.findIndex(function (a) { @@ -357,7 +357,7 @@ var ProgramManager = new Class({ { this.currentConfig.additions[index] = addition; } - }, + } /** * Add a feature to the current configuration. @@ -366,13 +366,13 @@ var ProgramManager = new Class({ * @since 4.0.0 * @param {string} feature - The feature to add. */ - addFeature: function (feature) + addFeature(feature) { if (this.currentConfig.features.indexOf(feature) === -1) { this.currentConfig.features.push(feature); } - }, + } /** * Remove a feature from the current configuration. @@ -381,13 +381,13 @@ var ProgramManager = new Class({ * @since 4.0.0 * @param {string} feature - The feature to remove. */ - removeFeature: function (feature) + removeFeature(feature) { this.currentConfig.features = this.currentConfig.features.filter(function (f) { return f !== feature; }); - }, + } /** * Clear all features from the current configuration. @@ -395,10 +395,10 @@ var ProgramManager = new Class({ * @method Phaser.Renderer.WebGL.ProgramManager#clearFeatures * @since 4.0.0 */ - clearFeatures: function () + clearFeatures() { this.currentConfig.features.length = 0; } -}); +}; module.exports = ProgramManager; diff --git a/src/renderer/webgl/ShaderProgramFactory.js b/src/renderer/webgl/ShaderProgramFactory.js index 9540db4988..356eee96be 100644 --- a/src/renderer/webgl/ShaderProgramFactory.js +++ b/src/renderer/webgl/ShaderProgramFactory.js @@ -26,8 +26,8 @@ var Class = require('../../utils/Class'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The WebGLRenderer that owns this ShaderProgramFactory. */ -var ShaderProgramFactory = new Class({ - initialize: function ShaderProgramFactory (renderer) +var ShaderProgramFactory = class { + constructor(renderer) { /** * The WebGLRenderer that owns this ShaderProgramFactory. @@ -52,7 +52,7 @@ var ShaderProgramFactory = new Class({ * @since 4.0.0 */ this.programs = {}; - }, + } /** * Checks if a shader program exists based on the given configuration settings. @@ -61,10 +61,10 @@ var ShaderProgramFactory = new Class({ * @since 4.0.0 * @param {string} key - The unique key of the shader program. */ - has: function (key) + has(key) { return this.programs[key] !== undefined; - }, + } /** * Returns a shader program based on the given configuration settings. @@ -75,7 +75,7 @@ var ShaderProgramFactory = new Class({ * @param {Phaser.Types.Renderer.WebGL.ShaderAdditionConfig[]} [additions] - An array of shader addition configurations. * @param {string[]} [features] - An array of enabled shader feature keys. */ - getShaderProgram: function (base, additions, features) + getShaderProgram(base, additions, features) { var key = this.getKey(base, additions, features); @@ -87,7 +87,7 @@ var ShaderProgramFactory = new Class({ } return program; - }, + } /** * Returns a unique key for a shader program based on the given configuration settings. @@ -104,7 +104,7 @@ var ShaderProgramFactory = new Class({ * @param {Phaser.Types.Renderer.WebGL.ShaderAdditionConfig[]} [additions] - An array of shader addition configurations. * @param {string[]} [features] - An array of enabled shader feature keys. */ - getKey: function (base, additions, features) + getKey(base, additions, features) { var key = base.name; @@ -128,7 +128,7 @@ var ShaderProgramFactory = new Class({ } return key; - }, + } /** * Creates a shader program based on the given configuration settings. @@ -140,7 +140,7 @@ var ShaderProgramFactory = new Class({ * @param {Phaser.Types.Renderer.WebGL.ShaderAdditionConfig[]} [additions] - An array of shader addition configurations. * @param {string[]} [features] - An array of enabled shader feature keys. */ - createShaderProgram: function (name, base, additions, features) + createShaderProgram(name, base, additions, features) { var vertexSource = base.vertexShader; var fragmentSource = base.fragmentShader; @@ -219,6 +219,6 @@ var ShaderProgramFactory = new Class({ return program; } -}); +}; module.exports = ShaderProgramFactory; diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index 41fc02dedc..cd8f248464 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -78,15 +78,11 @@ if (typeof WEBGL_DEBUG) * * @param {Phaser.Game} game - The Game instance which owns this WebGL Renderer. */ -var WebGLRenderer = new Class({ +var WebGLRenderer = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function WebGLRenderer (game) + constructor(game) { - EventEmitter.call(this); + super(); var gameConfig = game.config; @@ -695,7 +691,7 @@ var WebGLRenderer = new Class({ this._debugCapture = false; this.init(this.config); - }, + } /** * Creates a new WebGLRenderingContext and initializes all internal state. @@ -707,7 +703,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - init: function (config) + init(config) { var gl; var game = this.game; @@ -809,7 +805,7 @@ var WebGLRenderer = new Class({ game.textures.once(TextureEvents.READY, this.boot, this); return this; - }, + } /** * Internal boot handler. @@ -818,7 +814,7 @@ var WebGLRenderer = new Class({ * @private * @since 3.11.0 */ - boot: function () + boot() { var game = this.game; var gl = this.gl; @@ -884,7 +880,7 @@ var WebGLRenderer = new Class({ game.scale.on(ScaleEvents.RESIZE, this.onResize, this); this.resize(width, height); - }, + } /** * Queries the GL context to get the supported extensions. @@ -896,7 +892,7 @@ var WebGLRenderer = new Class({ * @method Phaser.Renderer.WebGL.WebGLRenderer#setExtensions * @since 3.85.2 */ - setExtensions: function () + setExtensions() { var gl = this.gl; var game = this.game; @@ -932,7 +928,7 @@ var WebGLRenderer = new Class({ this.standardDerivativesExtension = (exts.indexOf(stdDerivativesString) > -1) ? gl.getExtension(stdDerivativesString) : null; } - }, + } /** * Sets the handlers that are called when WebGL context is lost or restored by the browser. @@ -950,7 +946,7 @@ var WebGLRenderer = new Class({ * * @param {function} [contextLost] - Custom handler for responding to the WebGL context lost event. Set as `undefined` to use the default handler. * @param {function} [contextRestored] - Custom handler for responding to the WebGL context restored event. Set as `undefined` to use the default handler. */ - setContextHandlers: function (contextLost, contextRestored) + setContextHandlers(contextLost, contextRestored) { if (this.previousContextLostHandler) { @@ -984,7 +980,7 @@ var WebGLRenderer = new Class({ this.previousContextLostHandler = this.contextLostHandler; this.previousContextRestoredHandler = this.contextRestoredHandler; - }, + } /** * This method is called when the WebGL context is lost. By default this is bound to the property `WebGLRenderer.contextLostHandler`. @@ -995,7 +991,7 @@ var WebGLRenderer = new Class({ * * @param {WebGLContextEvent } event - The WebGL context lost Event. */ - dispatchContextLost: function (event) + dispatchContextLost(event) { this.contextLost = true; @@ -1007,7 +1003,7 @@ var WebGLRenderer = new Class({ this.emit(Events.LOSE_WEBGL, this); event.preventDefault(); - }, + } /** * This method is called when the WebGL context is restored. By default this is bound to the property `WebGLRenderer.contextRestoredHandler`. @@ -1019,7 +1015,7 @@ var WebGLRenderer = new Class({ * @param {WebGLContextEvent } event - The WebGL context restored Event. */ - dispatchContextRestored: function (event) + dispatchContextRestored(event) { var gl = this.gl; @@ -1073,7 +1069,7 @@ var WebGLRenderer = new Class({ this.emit(Events.RESTORE_WEBGL, this); event.preventDefault(); - }, + } /** * This method is only available in the Debug Build of Phaser, or a build with the @@ -1095,7 +1091,7 @@ var WebGLRenderer = new Class({ * @param {boolean} [quickCapture=false] - If `true` thumbnails are not captured in order to speed up the capture. * @param {boolean} [fullCapture=false] - If `true` all details are captured. */ - captureFrame: function (quickCapture, fullCapture) + captureFrame(quickCapture, fullCapture) { if (quickCapture === undefined) { quickCapture = false; } if (fullCapture === undefined) { fullCapture = false; } @@ -1106,7 +1102,7 @@ var WebGLRenderer = new Class({ this._debugCapture = true; } - }, + } /** * This method is only available in the Debug Build of Phaser, or a build with the @@ -1125,7 +1121,7 @@ var WebGLRenderer = new Class({ * @method Phaser.Renderer.WebGL.WebGLRenderer#captureNextFrame * @since 3.60.0 */ - captureNextFrame: function () + captureNextFrame() { if (DEBUG && this.spector && !this._debugCapture) { @@ -1133,7 +1129,7 @@ var WebGLRenderer = new Class({ this.spector.captureNextFrame(this.canvas); } - }, + } /** * This method is only available in the Debug Build of Phaser, or a build with the @@ -1154,13 +1150,13 @@ var WebGLRenderer = new Class({ * * @return {number} The current FPS of the WebGL canvas. */ - getFps: function () + getFps() { if (DEBUG && this.spector) { return this.spector.getFps(); } - }, + } /** * This method is only available in the Debug Build of Phaser, or a build with the @@ -1184,7 +1180,7 @@ var WebGLRenderer = new Class({ * * @return {string} The current log. */ - log: function () + log() { if (DEBUG && this.spector) { @@ -1192,7 +1188,7 @@ var WebGLRenderer = new Class({ return this.spector.log(t); } - }, + } /** * This method is only available in the Debug Build of Phaser, or a build with the @@ -1217,7 +1213,7 @@ var WebGLRenderer = new Class({ * @param {boolean} [quickCapture=false] - If `true` thumbnails are not captured in order to speed up the capture. * @param {boolean} [fullCapture=false] - If `true` all details are captured. */ - startCapture: function (commandCount, quickCapture, fullCapture) + startCapture(commandCount, quickCapture, fullCapture) { if (commandCount === undefined) { commandCount = 0; } if (quickCapture === undefined) { quickCapture = false; } @@ -1229,7 +1225,7 @@ var WebGLRenderer = new Class({ this._debugCapture = true; } - }, + } /** * This method is only available in the Debug Build of Phaser, or a build with the @@ -1252,13 +1248,13 @@ var WebGLRenderer = new Class({ * * @return {object} The current capture. */ - stopCapture: function () + stopCapture() { if (DEBUG && this.spector && this._debugCapture) { return this.spector.stopCapture(); } - }, + } /** * This method is only available in the Debug Build of Phaser, or a build with the @@ -1272,7 +1268,7 @@ var WebGLRenderer = new Class({ * * @param {object} capture - The capture data. */ - onCapture: function (capture) + onCapture(capture) { if (DEBUG) { @@ -1282,7 +1278,7 @@ var WebGLRenderer = new Class({ this._debugCapture = false; } - }, + } /** * The event handler that manages the `resize` event dispatched by the Scale Manager. @@ -1293,14 +1289,14 @@ var WebGLRenderer = new Class({ * @param {Phaser.Structs.Size} gameSize - The default Game Size object. This is the un-modified game dimensions. * @param {Phaser.Structs.Size} baseSize - The base Size object. The game dimensions. The canvas width / height values match this. */ - onResize: function (gameSize, baseSize) + onResize(gameSize, baseSize) { // Has the underlying canvas size changed? if (baseSize.width !== this.width || baseSize.height !== this.height) { this.resize(baseSize.width, baseSize.height); } - }, + } /** * Resizes the drawing buffer to match that required by the Scale Manager. @@ -1314,7 +1310,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - resize: function (width, height) + resize(width, height) { var gl = this.gl; @@ -1335,7 +1331,7 @@ var WebGLRenderer = new Class({ this.emit(Events.RESIZE, width, height); return this; - }, + } /** * Determines which compressed texture formats this browser and device supports. @@ -1348,7 +1344,7 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Types.Renderer.WebGL.WebGLTextureCompression} The compression object. */ - getCompressedTextures: function () + getCompressedTextures() { var extString = 'WEBGL_compressed_texture_'; var wkExtString = 'WEBKIT_' + extString; @@ -1385,7 +1381,7 @@ var WebGLRenderer = new Class({ S3TCSRGB: hasExt(gl, 's3tc_srgb'), IMG: true }; - }, + } /** * Returns a compressed texture format GLenum name based on the given format. @@ -1398,7 +1394,7 @@ var WebGLRenderer = new Class({ * * @return {string} The compressed texture format name, as a string. */ - getCompressedTextureName: function (baseFormat, format) + getCompressedTextureName(baseFormat, format) { var supportedFormats = this.compression[baseFormat.toUpperCase()]; @@ -1406,7 +1402,7 @@ var WebGLRenderer = new Class({ { return supportedFormats[format]; } - }, + } /** * Checks if the given compressed texture format is supported, or not. @@ -1419,7 +1415,7 @@ var WebGLRenderer = new Class({ * * @return {boolean} True if the format is supported, otherwise false. */ - supportsCompressedTexture: function (baseFormat, format) + supportsCompressedTexture(baseFormat, format) { var supportedFormats = this.compression[baseFormat.toUpperCase()]; @@ -1436,7 +1432,7 @@ var WebGLRenderer = new Class({ } return false; - }, + } /** * Gets the aspect ratio of the WebGLRenderer dimensions. @@ -1446,10 +1442,10 @@ var WebGLRenderer = new Class({ * * @return {number} The aspect ratio of the WebGLRenderer dimensions. */ - getAspectRatio: function () + getAspectRatio() { return this.width / this.height; - }, + } /** * Sets the Projection Matrix of this renderer to the given dimensions. @@ -1463,7 +1459,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - setProjectionMatrix: function (width, height, flipY) + setProjectionMatrix(width, height, flipY) { if (width !== this.projectionWidth || height !== this.projectionHeight || flipY !== this.projectionFlipY) { @@ -1482,7 +1478,7 @@ var WebGLRenderer = new Class({ } return this; - }, + } /** * Sets the Projection Matrix of this renderer to match the given drawing context. @@ -1494,14 +1490,14 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - setProjectionMatrixFromDrawingContext: function (drawingContext) + setProjectionMatrixFromDrawingContext(drawingContext) { return this.setProjectionMatrix( drawingContext.width, drawingContext.height, false ); - }, + } /** * Resets the Projection Matrix back to this renderers width and height. @@ -1514,10 +1510,10 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - resetProjectionMatrix: function () + resetProjectionMatrix() { return this.setProjectionMatrix(this.width, this.height); - }, + } /** * Checks if a WebGL extension is supported @@ -1529,10 +1525,10 @@ var WebGLRenderer = new Class({ * * @return {boolean} `true` if the extension is supported, otherwise `false`. */ - hasExtension: function (extensionName) + hasExtension(extensionName) { return this.supportedExtensions ? this.supportedExtensions.indexOf(extensionName) : false; - }, + } /** * Loads a WebGL extension @@ -1544,7 +1540,7 @@ var WebGLRenderer = new Class({ * * @return {object} WebGL extension if the extension is supported */ - getExtension: function (extensionName) + getExtension(extensionName) { if (!this.hasExtension(extensionName)) { return null; } @@ -1554,7 +1550,7 @@ var WebGLRenderer = new Class({ } return this.extensions[extensionName]; - }, + } /** * Creates a new custom blend mode for the renderer. @@ -1569,12 +1565,12 @@ var WebGLRenderer = new Class({ * * @return {number} The index of the new blend mode, used for referencing it in the future. */ - addBlendMode: function (func, equation) + addBlendMode(func, equation) { var index = this.blendModes.push(WebGLBlendParametersFactory.createCombined(this, true, undefined, equation, func[0], func[1])) - 1; return index - 1; - }, + } /** * Updates the function bound to a given custom blend mode. @@ -1588,7 +1584,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - updateBlendMode: function (index, func, equation) + updateBlendMode(index, func, equation) { if (index > 17 && this.blendModes[index]) { @@ -1613,7 +1609,7 @@ var WebGLRenderer = new Class({ } return this; - }, + } /** * Removes a custom blend mode from the renderer. @@ -1626,7 +1622,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - removeBlendMode: function (index) + removeBlendMode(index) { if (index > 17 && this.blendModes[index]) { @@ -1634,7 +1630,7 @@ var WebGLRenderer = new Class({ } return this; - }, + } /** * Clear the current framebuffer to the given color. @@ -1645,7 +1641,7 @@ var WebGLRenderer = new Class({ * @param {number} [stencil] - The stencil value to clear to. * @param {number} [depth] - The depth value to clear to. Currently, this is not set, and only determines whether the depth buffer is cleared. */ - clearFramebuffer: function (color, stencil, depth) + clearFramebuffer(color, stencil, depth) { var gl = this.gl; var bits = 0; @@ -1664,7 +1660,7 @@ var WebGLRenderer = new Class({ bits = bits | gl.DEPTH_BUFFER_BIT; } gl.clear(bits); - }, + } /** * Creates a texture from an image source. If the source is not valid it creates an empty texture. @@ -1681,7 +1677,7 @@ var WebGLRenderer = new Class({ * * @return {?Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The WebGLTextureWrapper that was created, or `null` if it couldn't be created. */ - createTextureFromSource: function (source, width, height, scaleMode, forceClamp, flipY) + createTextureFromSource(source, width, height, scaleMode, forceClamp, flipY) { if (forceClamp === undefined) { forceClamp = false; } @@ -1724,7 +1720,7 @@ var WebGLRenderer = new Class({ } return texture; - }, + } /** * A wrapper for creating a WebGLTextureWrapper. If no pixel data is passed it will create an empty texture. @@ -1747,7 +1743,7 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The WebGLTextureWrapper that was created. */ - createTexture2D: function (mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma, forceSize, flipY) + createTexture2D(mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma, forceSize, flipY) { if (typeof width !== 'number') { width = pixels ? pixels.width : 1; } if (typeof height !== 'number') { height = pixels ? pixels.height : 1; } @@ -1757,7 +1753,7 @@ var WebGLRenderer = new Class({ this.glTextureWrappers.push(texture); return texture; - }, + } /** * Creates a WebGL Framebuffer object and optionally binds a depth stencil render buffer. @@ -1773,7 +1769,7 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLFramebufferWrapper} Wrapped framebuffer which is safe to use with the renderer. */ - createFramebuffer: function (renderTexture, addStencilBuffer, addDepthBuffer) + createFramebuffer(renderTexture, addStencilBuffer, addDepthBuffer) { if (!Array.isArray(renderTexture) && renderTexture !== null) { @@ -1789,7 +1785,7 @@ var WebGLRenderer = new Class({ this.glFramebufferWrappers.push(framebuffer); return framebuffer; - }, + } /** * Creates a WebGLProgram instance based on the given vertex and fragment shader source. @@ -1804,12 +1800,12 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper} The wrapped, linked WebGLProgram created from the given shader source. */ - createProgram: function (vertexShader, fragmentShader) + createProgram(vertexShader, fragmentShader) { var wrapper = new WebGLProgramWrapper(this, vertexShader, fragmentShader); this.glProgramWrappers.push(wrapper); return wrapper; - }, + } /** * Wrapper for creating a vertex buffer. @@ -1822,13 +1818,13 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper} Wrapped vertex buffer */ - createVertexBuffer: function (initialDataOrSize, bufferUsage) + createVertexBuffer(initialDataOrSize, bufferUsage) { var gl = this.gl; var vertexBuffer = new WebGLBufferWrapper(this, initialDataOrSize, gl.ARRAY_BUFFER, bufferUsage); this.glBufferWrappers.push(vertexBuffer); return vertexBuffer; - }, + } /** * Wrapper for creating a vertex buffer. @@ -1841,13 +1837,13 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper} Wrapped index buffer */ - createIndexBuffer: function (initialDataOrSize, bufferUsage) + createIndexBuffer(initialDataOrSize, bufferUsage) { var gl = this.gl; var indexBuffer = new WebGLBufferWrapper(this, initialDataOrSize, gl.ELEMENT_ARRAY_BUFFER, bufferUsage); this.glBufferWrappers.push(indexBuffer); return indexBuffer; - }, + } /** * Wrapper for creating a vertex array object. @@ -1859,12 +1855,12 @@ var WebGLRenderer = new Class({ * @param {Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper} indexBuffer - The index buffer. * @param {Phaser.Types.Renderer.WebGL.WebGLAttributeBufferLayout[]} attributeBufferLayouts - The attribute buffer layouts. */ - createVAO: function (program, indexBuffer, attributeBufferLayouts) + createVAO(program, indexBuffer, attributeBufferLayouts) { var vao = new WebGLVAOWrapper(this, program, indexBuffer, attributeBufferLayouts); this.glVAOWrappers.push(vao); return vao; - }, + } /** * Removes a texture from the GPU. @@ -1876,7 +1872,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - deleteTexture: function (texture) + deleteTexture(texture) { if (!texture) { @@ -1885,7 +1881,7 @@ var WebGLRenderer = new Class({ ArrayRemove(this.glTextureWrappers, texture); texture.destroy(); return this; - }, + } /** * Deletes a Framebuffer from the GL instance. @@ -1897,7 +1893,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - deleteFramebuffer: function (framebuffer) + deleteFramebuffer(framebuffer) { if (!framebuffer) { @@ -1906,7 +1902,7 @@ var WebGLRenderer = new Class({ ArrayRemove(this.glFramebufferWrappers, framebuffer); framebuffer.destroy(); return this; - }, + } /** * Deletes a WebGLProgram from the GL instance. @@ -1918,7 +1914,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - deleteProgram: function (program) + deleteProgram(program) { if (program) { @@ -1927,7 +1923,7 @@ var WebGLRenderer = new Class({ } return this; - }, + } /** * Deletes a WebGLBuffer from the GL instance. @@ -1939,13 +1935,13 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGLRenderer instance. */ - deleteBuffer: function (buffer) + deleteBuffer(buffer) { if (!buffer) { return this; } ArrayRemove(this.glBufferWrappers, buffer); buffer.destroy(); return this; - }, + } /** * Clears the base DrawingContext and readies it for use. @@ -1955,7 +1951,7 @@ var WebGLRenderer = new Class({ * @fires Phaser.Renderer.Events#PRE_RENDER * @since 3.0.0 */ - preRender: function () + preRender() { if (this.contextLost) { return; } @@ -1982,7 +1978,7 @@ var WebGLRenderer = new Class({ baseDrawingContext.use(); this.emit(Events.PRE_RENDER); - }, + } /** * The core render step for a Scene Camera. @@ -2002,7 +1998,7 @@ var WebGLRenderer = new Class({ * @param {Phaser.GameObjects.GameObject[]} children - An array of filtered Game Objects that can be rendered by the given Camera. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Scene Camera to render with. */ - render: function (scene, children, camera) + render(scene, children, camera) { if (this.contextLost) { return; } @@ -2013,7 +2009,7 @@ var WebGLRenderer = new Class({ this.cameraRenderNode.run(this.baseDrawingContext, children, camera); this.currentViewCamera = null; - }, + } /** * The post-render step happens after all Cameras in all Scenes have been rendered. @@ -2022,7 +2018,7 @@ var WebGLRenderer = new Class({ * @fires Phaser.Renderer.Events#POST_RENDER * @since 3.0.0 */ - postRender: function () + postRender() { this.baseDrawingContext.release(); @@ -2038,7 +2034,7 @@ var WebGLRenderer = new Class({ state.callback = null; } - }, + } /** * Draw a number of vertices to a drawing context. @@ -2063,7 +2059,7 @@ var WebGLRenderer = new Class({ * @param {number} offset - The offset to start drawing from in the index buffer. This is in bytes, and should be a multiple of 2 (for 16-bit `UNSIGNED_SHORT` indices). * @param {number} topology - The type of primitives to render. Defaults to `TRIANGLE_STRIP`. */ - drawElements: function (drawingContext, textures, program, vao, count, offset, topology) + drawElements(drawingContext, textures, program, vao, count, offset, topology) { var gl = this.gl; @@ -2076,7 +2072,7 @@ var WebGLRenderer = new Class({ this.glTextureUnits.bindUnits(textures); gl.drawElements(topology || gl.TRIANGLE_STRIP, count, gl.UNSIGNED_SHORT, offset); - }, + } /** * Draw a number of instances to a drawing context. @@ -2098,7 +2094,7 @@ var WebGLRenderer = new Class({ * @param {number} count - The number of vertices to draw. * @param {number} instanceCount - The number of instances to render. */ - drawInstancedArrays: function (drawingContext, textures, program, vao, first, count, instanceCount, topology) + drawInstancedArrays(drawingContext, textures, program, vao, first, count, instanceCount, topology) { var gl = this.gl; @@ -2111,7 +2107,7 @@ var WebGLRenderer = new Class({ this.glTextureUnits.bindUnits(textures); this.instancedArraysExtension.drawArraysInstancedANGLE(topology || gl.TRIANGLE_STRIP, first, count, instanceCount); - }, + } /** * Schedules a snapshot of the entire game viewport to be taken after the current frame is rendered. @@ -2135,10 +2131,10 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGL Renderer. */ - snapshot: function (callback, type, encoderOptions) + snapshot(callback, type, encoderOptions) { return this.snapshotArea(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight, callback, type, encoderOptions); - }, + } /** * Schedules a snapshot of the given area of the game viewport to be taken after the current frame is rendered. @@ -2166,7 +2162,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGL Renderer. */ - snapshotArea: function (x, y, width, height, callback, type, encoderOptions) + snapshotArea(x, y, width, height, callback, type, encoderOptions) { var state = this.snapshotState; @@ -2181,7 +2177,7 @@ var WebGLRenderer = new Class({ state.unpremultiplyAlpha = this.game.config.premultipliedAlpha; return this; - }, + } /** * Schedules a snapshot of the given pixel from the game viewport to be taken after the current frame is rendered. @@ -2204,14 +2200,14 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGL Renderer. */ - snapshotPixel: function (x, y, callback) + snapshotPixel(x, y, callback) { this.snapshotArea(x, y, 1, 1, callback); this.snapshotState.getPixel = true; return this; - }, + } /** * Takes a snapshot of the given area of the given frame buffer. @@ -2240,7 +2236,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGL Renderer. */ - snapshotFramebuffer: function (framebuffer, bufferWidth, bufferHeight, callback, getPixel, x, y, width, height, type, encoderOptions) + snapshotFramebuffer(framebuffer, bufferWidth, bufferHeight, callback, getPixel, x, y, width, height, type, encoderOptions) { if (getPixel === undefined) { getPixel = false; } if (x === undefined) { x = 0; } @@ -2279,7 +2275,7 @@ var WebGLRenderer = new Class({ state.isFramebuffer = false; return this; - }, + } /** * Creates a new WebGL Texture based on the given Canvas Element. @@ -2296,7 +2292,7 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The newly created, or updated, WebGLTextureWrapper. */ - canvasToTexture: function (srcCanvas, dstTexture, noRepeat, flipY) + canvasToTexture(srcCanvas, dstTexture, noRepeat, flipY) { if (noRepeat === undefined) { noRepeat = false; } if (flipY === undefined) { flipY = true; } @@ -2333,7 +2329,7 @@ var WebGLRenderer = new Class({ return dstTexture; } - }, + } /** * Creates a new WebGL Texture based on the given Canvas Element. @@ -2347,13 +2343,13 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The newly created WebGLTextureWrapper. */ - createCanvasTexture: function (srcCanvas, noRepeat, flipY) + createCanvasTexture(srcCanvas, noRepeat, flipY) { if (noRepeat === undefined) { noRepeat = false; } if (flipY === undefined) { flipY = true; } return this.canvasToTexture(srcCanvas, null, noRepeat, flipY); - }, + } /** * Updates a WebGL Texture based on the given Canvas Element. @@ -2368,13 +2364,13 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The updated WebGLTextureWrapper. This is the same wrapper object as `dstTexture`. */ - updateCanvasTexture: function (srcCanvas, dstTexture, flipY, noRepeat) + updateCanvasTexture(srcCanvas, dstTexture, flipY, noRepeat) { if (flipY === undefined) { flipY = true; } if (noRepeat === undefined) { noRepeat = false; } return this.canvasToTexture(srcCanvas, dstTexture, noRepeat, flipY); - }, + } /** * Creates or updates a WebGL Texture based on the given HTML Video Element. @@ -2391,7 +2387,7 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The newly created, or updated, WebGLTextureWrapper. */ - videoToTexture: function (srcVideo, dstTexture, noRepeat, flipY) + videoToTexture(srcVideo, dstTexture, noRepeat, flipY) { if (noRepeat === undefined) { noRepeat = false; } if (flipY === undefined) { flipY = true; } @@ -2428,7 +2424,7 @@ var WebGLRenderer = new Class({ return dstTexture; } - }, + } /** * Creates a new WebGL Texture based on the given HTML Video Element. @@ -2442,13 +2438,13 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The newly created WebGLTextureWrapper. */ - createVideoTexture: function (srcVideo, noRepeat, flipY) + createVideoTexture(srcVideo, noRepeat, flipY) { if (noRepeat === undefined) { noRepeat = false; } if (flipY === undefined) { flipY = true; } return this.videoToTexture(srcVideo, null, noRepeat, flipY); - }, + } /** * Updates a WebGL Texture based on the given HTML Video Element. @@ -2463,13 +2459,13 @@ var WebGLRenderer = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The updated WebGLTextureWrapper. This is the same wrapper object as `dstTexture`. */ - updateVideoTexture: function (srcVideo, dstTexture, flipY, noRepeat) + updateVideoTexture(srcVideo, dstTexture, flipY, noRepeat) { if (flipY === undefined) { flipY = true; } if (noRepeat === undefined) { noRepeat = false; } return this.videoToTexture(srcVideo, dstTexture, noRepeat, flipY); - }, + } /** * Create a WebGLTexture from a Uint8Array. @@ -2487,7 +2483,7 @@ var WebGLRenderer = new Class({ * @param {boolean} [flipY = true] - Should the WebGL Texture set `UNPACK_MULTIPLY_FLIP_Y`? * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The newly created WebGLTextureWrapper. */ - createUint8ArrayTexture: function (data, width, height, pma, flipY) + createUint8ArrayTexture(data, width, height, pma, flipY) { var gl = this.gl; var minFilter = gl.NEAREST; @@ -2505,7 +2501,7 @@ var WebGLRenderer = new Class({ if (flipY === undefined) { flipY = true; } return this.createTexture2D(0, minFilter, magFilter, wrap, wrap, gl.RGBA, data, width, height, pma, false, flipY); - }, + } /** * Sets the minification and magnification filter for a texture. @@ -2518,7 +2514,7 @@ var WebGLRenderer = new Class({ * * @return {this} This WebGL Renderer instance. */ - setTextureFilter: function (texture, filter) + setTextureFilter(texture, filter) { var gl = this.gl; var glFilter = (filter === 0) ? gl.LINEAR : gl.NEAREST; @@ -2543,7 +2539,7 @@ var WebGLRenderer = new Class({ } return this; - }, + } /** * Returns the largest texture size (either width or height) that can be created. @@ -2555,10 +2551,10 @@ var WebGLRenderer = new Class({ * * @return {number} The maximum supported texture size. */ - getMaxTextureSize: function () + getMaxTextureSize() { return this.config.maxTextureSize; - }, + } /** * Destroy this WebGLRenderer, cleaning up all related resources such as wrappers, native textures, etc. @@ -2566,7 +2562,7 @@ var WebGLRenderer = new Class({ * @method Phaser.Renderer.WebGL.WebGLRenderer#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.off(Events.RESIZE, this.baseDrawingContext.resize, this.baseDrawingContext); @@ -2597,6 +2593,6 @@ var WebGLRenderer = new Class({ this.spector = null; } } -}); +}; module.exports = WebGLRenderer; diff --git a/src/renderer/webgl/renderNodes/BatchHandler.js b/src/renderer/webgl/renderNodes/BatchHandler.js index a9e5c45f24..9096d7319c 100644 --- a/src/renderer/webgl/renderNodes/BatchHandler.js +++ b/src/renderer/webgl/renderNodes/BatchHandler.js @@ -31,10 +31,9 @@ var Renderer = require('../../../renderer'); * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} defaultConfig - The default configuration object for this RenderNode. This is used to ensure all required properties are present, so it must be complete. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this RenderNode. */ -var BatchHandler = new Class({ - Extends: RenderNode, +var BatchHandler = class extends RenderNode { - initialize: function BatchHandler (manager, defaultConfig, config) + constructor(manager, defaultConfig, config) { var renderer = manager.renderer; var gl = renderer.gl; @@ -47,7 +46,7 @@ var BatchHandler = new Class({ throw new Error('BatchHandler must have a name'); } - RenderNode.call(this, name, manager); + super(name, manager); /** * The number of instances per batch, used to determine the size of the @@ -259,7 +258,7 @@ var BatchHandler = new Class({ // Set the dimension-related uniforms and listen for resize events. this.resize(renderer.width, renderer.height); renderer.on(Renderer.Events.RESIZE, this.resize, this); - }, + } /** * Copy and complete the configuration object. @@ -275,7 +274,7 @@ var BatchHandler = new Class({ * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} config - The configuration object. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} defaultConfig - The default configuration object. */ - _copyAndCompleteConfig: function (manager, config, defaultConfig) + _copyAndCompleteConfig(manager, config, defaultConfig) { var newConfig = {}; @@ -333,7 +332,7 @@ var BatchHandler = new Class({ } return newConfig; - }, + } /** * Generate element indices for the instance vertices. @@ -346,11 +345,11 @@ var BatchHandler = new Class({ * @param {number} instances - The number of instances to define. * @return {ArrayBuffer} The index buffer data. */ - _generateElementIndices: function (instances) + _generateElementIndices(instances) { // This is empty and should be overridden by subclasses. return new ArrayBuffer(instances * this.bytesPerInstance); - }, + } /** * Set new dimensions for the renderer. @@ -363,9 +362,9 @@ var BatchHandler = new Class({ * @param {number} width - The new width of the renderer. * @param {number} height - The new height of the renderer. */ - resize: function (width, height) + resize(width, height) { - }, + } /** * Update the number of draw calls per batch. @@ -379,9 +378,9 @@ var BatchHandler = new Class({ * @since 4.0.0 * @param {number} [count] - The new number of draw calls per batch. If undefined, the maximum number of texture units is used. */ - updateTextureCount: function (count) + updateTextureCount(count) { - }, + } /** * Draw then empty the current batch. @@ -396,9 +395,9 @@ var BatchHandler = new Class({ * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. * @param {...*} [args] - Additional arguments to pass to the batch handler. */ - run: function (drawingContext) + run(drawingContext) { - }, + } /** * Add an instance to the batch. Game objects call this method to add @@ -408,9 +407,9 @@ var BatchHandler = new Class({ * @param {...*} [args] - Arguments to pass to the batch handler. These will vary depending on the handler. * @since 4.0.0 */ - batch: function () + batch() { } -}); +}; module.exports = BatchHandler; diff --git a/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js b/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js index c22cd2d321..6323947847 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js @@ -21,13 +21,11 @@ var BatchHandler = require('./BatchHandler'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this handler. */ -var BatchHandlerPointLight = new Class({ +var BatchHandlerPointLight = class extends BatchHandler { - Extends: BatchHandler, - - initialize: function BatchHandlerPointLight (manager, config) + constructor(manager, config) { - BatchHandler.call(this, manager, this.defaultConfig, config); + super(manager, this.defaultConfig, config); /** * An empty texture array used internally. @@ -40,7 +38,7 @@ var BatchHandlerPointLight = new Class({ * @readonly */ this._emptyTextures = []; - }, + } /** * The default configuration for this handler. @@ -82,7 +80,7 @@ var BatchHandlerPointLight = new Class({ } ] } - }, + } /** * Generate element indices for the instance vertices. @@ -100,7 +98,7 @@ var BatchHandlerPointLight = new Class({ * @param {number} instances - The number of instances to define. * @return {ArrayBuffer} The index buffer data. */ - _generateElementIndices: function (instances) + _generateElementIndices(instances) { var buffer = new ArrayBuffer(instances * 6 * 2); var indices = new Uint16Array(buffer); @@ -116,7 +114,7 @@ var BatchHandlerPointLight = new Class({ indices[offset++] = index + 3; } return buffer; - }, + } /** * Update the uniforms for the current shader program. @@ -127,7 +125,7 @@ var BatchHandlerPointLight = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. */ - setupUniforms: function (drawingContext) + setupUniforms(drawingContext) { var programManager = this.programManager; var width = drawingContext.width; @@ -148,7 +146,7 @@ var BatchHandlerPointLight = new Class({ 'uProjectionMatrix', drawingContext.renderer.projectionMatrix.val ); - }, + } /** * Draw then empty the current batch. @@ -160,7 +158,7 @@ var BatchHandlerPointLight = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. */ - run: function (drawingContext) + run(drawingContext) { var instanceCount = this.instanceCount; @@ -199,7 +197,7 @@ var BatchHandlerPointLight = new Class({ this.instanceCount = 0; this.onRunEnd(drawingContext); - }, + } /** * Add a light to the batch. @@ -217,7 +215,7 @@ var BatchHandlerPointLight = new Class({ * @param {number} xBR - The bottom-right x-coordinate of the light. * @param {number} yBR - The bottom-right y-coordinate of the light. */ - batch: function (drawingContext, light, xTL, yTL, xBL, yBL, xTR, yTR, xBR, yBR, lightX, lightY) + batch(drawingContext, light, xTL, yTL, xBL, yBL, xTR, yTR, xBR, yBR, lightX, lightY) { if (this.instanceCount === 0) { @@ -299,6 +297,6 @@ var BatchHandlerPointLight = new Class({ // Now the batch is empty. } } -}); +}; module.exports = BatchHandlerPointLight; diff --git a/src/renderer/webgl/renderNodes/BatchHandlerQuad.js b/src/renderer/webgl/renderNodes/BatchHandlerQuad.js index 1ae23c6cc3..8c98a46934 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerQuad.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerQuad.js @@ -35,10 +35,9 @@ var BatchHandler = require('./BatchHandler'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this handler. */ -var BatchHandlerQuad = new Class({ - Extends: BatchHandler, +var BatchHandlerQuad = class extends BatchHandler { - initialize: function BatchHandlerQuad (manager, config) + constructor(manager, config) { // Placed before super call because the constructor needs it. /** @@ -60,7 +59,7 @@ var BatchHandlerQuad = new Class({ roundPixels: false }; - BatchHandler.call(this, manager, this.defaultConfig, config); + super(manager, this.defaultConfig, config); // Main sampler will never change after initialization, // because it addresses texture units, not textures. @@ -97,7 +96,7 @@ var BatchHandlerQuad = new Class({ * @since 4.0.0 */ this._lightVector = new Vector2(); - }, + } /** * The default configuration object for this handler. @@ -152,7 +151,7 @@ var BatchHandlerQuad = new Class({ } ] } - }, + } /** * Generate element indices for the instance vertices. @@ -170,7 +169,7 @@ var BatchHandlerQuad = new Class({ * @param {number} instances - The number of instances to define. * @return {ArrayBuffer} The index buffer data. */ - _generateElementIndices: function (instances) + _generateElementIndices(instances) { var buffer = new ArrayBuffer(instances * 6 * 2); var indices = new Uint16Array(buffer); @@ -186,7 +185,7 @@ var BatchHandlerQuad = new Class({ indices[offset++] = index + 3; } return buffer; - }, + } /** * Update the number of draw calls per batch. @@ -207,7 +206,7 @@ var BatchHandlerQuad = new Class({ * @since 4.0.0 * @param {number} [count] - The new number of draw calls per batch. If undefined, the maximum number of texture units is used. */ - updateTextureCount: function (count) + updateTextureCount(count) { var renderer = this.manager.renderer; @@ -249,7 +248,7 @@ var BatchHandlerQuad = new Class({ } this.resize(renderer.width, renderer.height); - }, + } /** * Update the uniforms for the current shader program. @@ -260,7 +259,7 @@ var BatchHandlerQuad = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. */ - setupUniforms: function (drawingContext) + setupUniforms(drawingContext) { var programManager = this.programManager; var renderOptions = this.renderOptions; @@ -297,7 +296,7 @@ var BatchHandlerQuad = new Class({ renderOptions.selfShadowPenumbra ); } - }, + } /** * Update the texture uniforms for the current shader program. @@ -308,7 +307,7 @@ var BatchHandlerQuad = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper[]} textures - The textures to render. */ - setupTextureUniforms: function (textures) + setupTextureUniforms(textures) { var programManager = this.programManager; @@ -335,7 +334,7 @@ var BatchHandlerQuad = new Class({ ); } - }, + } /** * Update the render options for the current shader program. @@ -344,7 +343,7 @@ var BatchHandlerQuad = new Class({ * @since 4.0.0 * @param {object} renderOptions - The new render options. */ - updateRenderOptions: function (renderOptions) + updateRenderOptions(renderOptions) { var newRenderOptions = this.nextRenderOptions; var oldRenderOptions = this.renderOptions; @@ -401,7 +400,7 @@ var BatchHandlerQuad = new Class({ } this._renderOptionsChanged = changed; - }, + } /** * Update the shader configuration based on render options. @@ -410,7 +409,7 @@ var BatchHandlerQuad = new Class({ * @method Phaser.Renderer.WebGL.RenderNodes.BatchHandlerQuad#updateShaderConfig * @since 4.0.0 */ - updateShaderConfig: function () + updateShaderConfig() { var programManager = this.programManager; var oldRenderOptions = this.renderOptions; @@ -503,7 +502,7 @@ var BatchHandlerQuad = new Class({ // Do not update the shader; this will be set as a uniform. } - }, + } /** * Draw then empty the current batch. @@ -515,7 +514,7 @@ var BatchHandlerQuad = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. */ - run: function (drawingContext) + run(drawingContext) { if (this.instanceCount === 0) { return; } @@ -574,7 +573,7 @@ var BatchHandlerQuad = new Class({ this.batchEntries.length = 0; this.onRunEnd(drawingContext); - }, + } /** * Add a quad to the batch. @@ -611,7 +610,7 @@ var BatchHandlerQuad = new Class({ * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerQuadRenderOptions} renderOptions - Optional render features. * @param {...*} [args] - Additional arguments for subclasses. */ - batch: function ( + batch( currentContext, glTexture, x0, y0, @@ -695,7 +694,7 @@ var BatchHandlerQuad = new Class({ // Now the batch is empty. } - }, + } /** * Process textures for batching. @@ -711,7 +710,7 @@ var BatchHandlerQuad = new Class({ * @param {object} renderOptions - The current render options. * @return {number} The texture datum. */ - batchTextures: function (glTexture, renderOptions) + batchTextures(glTexture, renderOptions) { var newRenderOptions = this.renderOptions; @@ -783,7 +782,7 @@ var BatchHandlerQuad = new Class({ } return textureDatum; - }, + } /** * Push the current batch entry to the batch entry list, @@ -792,7 +791,7 @@ var BatchHandlerQuad = new Class({ * @method Phaser.Renderer.WebGL.RenderNodes.BatchHandlerQuad#pushCurrentBatchEntry * @since 4.0.0 */ - pushCurrentBatchEntry: function () + pushCurrentBatchEntry() { if (this.currentBatchEntry.count < 1) { @@ -815,6 +814,6 @@ var BatchHandlerQuad = new Class({ texture: [] }; } -}); +}; module.exports = BatchHandlerQuad; diff --git a/src/renderer/webgl/renderNodes/BatchHandlerStrip.js b/src/renderer/webgl/renderNodes/BatchHandlerStrip.js index 64b158bcb0..fb344eac36 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerStrip.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerStrip.js @@ -36,16 +36,15 @@ var getTint = Utils.getTintAppendFloatAlpha; * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} config - The configuration object for this handler. */ -var BatchHandlerStrip = new Class({ - Extends: BatchHandlerQuad, +var BatchHandlerStrip = class extends BatchHandlerQuad { - initialize: function BatchHandlerStrip (manager, config) + constructor(manager, config) { - BatchHandlerQuad.call(this, manager, config); + super(manager, config); // We do not expect to use extra textures. this.renderOptions.multiTexturing = true; - }, + } /** * The default configuration object for this handler. @@ -95,7 +94,7 @@ var BatchHandlerStrip = new Class({ } ] } - }, + } /** * Generate element indices for the instance vertices. @@ -113,7 +112,7 @@ var BatchHandlerStrip = new Class({ * @param {number} instances - The number of instances to define. * @return {ArrayBuffer} The index buffer data. */ - _generateElementIndices: function (instances) + _generateElementIndices(instances) { var buffer = new ArrayBuffer(instances * 2 * 2); var indices = new Uint16Array(buffer); @@ -123,7 +122,7 @@ var BatchHandlerStrip = new Class({ indices[i] = i; } return buffer; - }, + } /** * Add a strip to the batch. @@ -146,7 +145,7 @@ var BatchHandlerStrip = new Class({ * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerQuadRenderOptions} renderOptions - Optional render features. Strip rendering should always set `multiTexturing` to false. It can use `smoothPixelArt`. Other options are ignored. * @param {function} [debugCallback] - The debug callback, called with an array consisting of alternating x,y values of the transformed vertices. */ - batchStrip: function ( + batchStrip( drawingContext, src, calcMatrix, @@ -282,6 +281,6 @@ var BatchHandlerStrip = new Class({ debugCallback.call(src, src, meshVerticesLength, debugVerts); } } -}); +}; module.exports = BatchHandlerStrip; diff --git a/src/renderer/webgl/renderNodes/BatchHandlerTileSprite.js b/src/renderer/webgl/renderNodes/BatchHandlerTileSprite.js index b279e7edc8..92acb7352d 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerTileSprite.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerTileSprite.js @@ -37,13 +37,12 @@ var BatchHandlerQuad = require('./BatchHandlerQuad'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this handler. */ -var BatchHandlerTileSprite = new Class({ - Extends: BatchHandlerQuad, +var BatchHandlerTileSprite = class extends BatchHandlerQuad { - initialize: function BatchHandlerTileSprite (manager, config) + constructor(manager, config) { - BatchHandlerQuad.call(this, manager, config); - }, + super(manager, config); + } defaultConfig: { name: 'BatchHandlerTileSprite', @@ -97,9 +96,9 @@ var BatchHandlerTileSprite = new Class({ } ] } - }, + } - updateRenderOptions: function (renderOptions) + updateRenderOptions(renderOptions) { BatchHandlerQuad.prototype.updateRenderOptions.call(this, renderOptions); @@ -130,9 +129,9 @@ var BatchHandlerTileSprite = new Class({ { this._renderOptionsChanged = true; } - }, + } - updateShaderConfig: function () + updateShaderConfig() { BatchHandlerQuad.prototype.updateShaderConfig.call(this); @@ -157,7 +156,7 @@ var BatchHandlerTileSprite = new Class({ var wrapAddition = programManager.getAddition('TexCoordFrameWrap'); wrapAddition.disable = !wrapFrame; } - }, + } /** * Add a quad to the batch. @@ -193,7 +192,7 @@ var BatchHandlerTileSprite = new Class({ * @param {number} u3 - The u coordinate of the distorted bottom-right corner. * @param {number} v3 - The v coordinate of the distorted bottom-right corner. */ - batch: function ( + batch( drawingContext, glTexture, x0, y0, @@ -295,6 +294,6 @@ var BatchHandlerTileSprite = new Class({ // Now the batch is empty. } } -}); +}; module.exports = BatchHandlerTileSprite; diff --git a/src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js b/src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js index 78408b371c..3d4c9ae8e2 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js @@ -26,12 +26,11 @@ var BatchHandler = require('./BatchHandler'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this handler. */ -var BatchHandlerTriFlat = new Class({ - Extends: BatchHandler, +var BatchHandlerTriFlat = class extends BatchHandler { - initialize: function BatchHandlerTriFlat (manager, config) + constructor(manager, config) { - BatchHandler.call(this, manager, this.defaultConfig, config); + super(manager, this.defaultConfig, config); /** * An empty array. This is an internal space filler. @@ -96,7 +95,7 @@ var BatchHandlerTriFlat = new Class({ * @since 4.0.0 */ this._renderOptionsChanged = false; - }, + } defaultConfig: { name: 'BatchHandlerTriFlat', @@ -126,7 +125,7 @@ var BatchHandlerTriFlat = new Class({ } ] } - }, + } /** * Generate element indices for the instance vertices. @@ -138,10 +137,10 @@ var BatchHandlerTriFlat = new Class({ * @param {number} instances - The number of instances to define. * @return {ArrayBuffer} The index buffer data. */ - _generateElementIndices: function (instances) + _generateElementIndices(instances) { return new ArrayBuffer(instances * 3 * 2); - }, + } /** * Update the uniforms for the current shader program. @@ -152,7 +151,7 @@ var BatchHandlerTriFlat = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. */ - setupUniforms: function (drawingContext) + setupUniforms(drawingContext) { var programManager = this.programManager; @@ -179,9 +178,9 @@ var BatchHandlerTriFlat = new Class({ [ drawingContext.width, drawingContext.height ] ); } - }, + } - updateRenderOptions: function (lighting) + updateRenderOptions(lighting) { var newRenderOptions = this.nextRenderOptions; var oldRenderOptions = this.renderOptions; @@ -194,9 +193,9 @@ var BatchHandlerTriFlat = new Class({ } this._renderOptionsChanged = changed; - }, + } - updateShaderConfig: function () + updateShaderConfig() { var programManager = this.programManager; var renderOptions = this.renderOptions; @@ -223,7 +222,7 @@ var BatchHandlerTriFlat = new Class({ } } } - }, + } /** * Draw then empty the current batch. @@ -235,7 +234,7 @@ var BatchHandlerTriFlat = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. */ - run: function (drawingContext) + run(drawingContext) { if (this.instanceCount === 0) { return; } @@ -286,7 +285,7 @@ var BatchHandlerTriFlat = new Class({ this.vertexCount = 0; this.onRunEnd(drawingContext); - }, + } /** * Add data to the batch. @@ -302,7 +301,7 @@ var BatchHandlerTriFlat = new Class({ * @param {number[]} colors - The color data. Each vertex has a color as a Uint32 value. * @param {boolean} [lighting=false] - Should this batch use lighting? */ - batch: function (currentContext, indexes, vertices, colors, lighting) + batch(currentContext, indexes, vertices, colors, lighting) { if (this.instanceCount === 0) { @@ -397,6 +396,6 @@ var BatchHandlerTriFlat = new Class({ } } } -}); +}; module.exports = BatchHandlerTriFlat; diff --git a/src/renderer/webgl/renderNodes/Camera.js b/src/renderer/webgl/renderNodes/Camera.js index ba5cdf5cf9..95a845145a 100644 --- a/src/renderer/webgl/renderNodes/Camera.js +++ b/src/renderer/webgl/renderNodes/Camera.js @@ -26,12 +26,11 @@ function getAlphaTint (alpha) * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var Camera = new Class({ - Extends: RenderNode, +var Camera = class extends RenderNode { - initialize: function Camera (manager) + constructor(manager) { - RenderNode.call(this, 'Camera', manager); + super('Camera', manager); /** * The RenderNode that handles batching quads. @@ -74,7 +73,7 @@ var Camera = new Class({ * @since 4.0.0 */ this._parentTransformMatrix = new TransformMatrix(); - }, + } /** * Renders the children through this camera. @@ -88,7 +87,7 @@ var Camera = new Class({ * @param {boolean} [forceFramebuffer=false] - Should the camera always draw to a new framebuffer? This will also be activated if the camera has filters enabled. * @param {number} [renderStep=0] - Which step of the rendering process is this? This is the index of the currently running function in a list of functions. */ - run: function ( + run( drawingContext, children, camera, @@ -415,6 +414,6 @@ var Camera = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = Camera; diff --git a/src/renderer/webgl/renderNodes/DrawLine.js b/src/renderer/webgl/renderNodes/DrawLine.js index 3d4ebe6e2d..44375150ce 100644 --- a/src/renderer/webgl/renderNodes/DrawLine.js +++ b/src/renderer/webgl/renderNodes/DrawLine.js @@ -18,13 +18,12 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var DrawLine = new Class({ - Extends: RenderNode, +var DrawLine = class extends RenderNode { - initialize: function DrawLine (manager) + constructor(manager) { - RenderNode.call(this, 'DrawLine', manager); - }, + super('DrawLine', manager); + } /** * Get the transformed vertices of a line segment as a quad. @@ -42,7 +41,7 @@ var DrawLine = new Class({ * @param {number} bLineWidth - The width of the line at the end. * @param {number[]} vertices - The list to which the vertices are assigned. */ - run: function (drawingContext, currentMatrix, ax, ay, bx, by, aLineWidth, bLineWidth, vertices) + run(drawingContext, currentMatrix, ax, ay, bx, by, aLineWidth, bLineWidth, vertices) { this.onRunBegin(drawingContext); @@ -94,6 +93,6 @@ var DrawLine = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = DrawLine; diff --git a/src/renderer/webgl/renderNodes/DynamicTextureHandler.js b/src/renderer/webgl/renderNodes/DynamicTextureHandler.js index f9c5437cab..7abd4461f5 100644 --- a/src/renderer/webgl/renderNodes/DynamicTextureHandler.js +++ b/src/renderer/webgl/renderNodes/DynamicTextureHandler.js @@ -21,12 +21,11 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var DynamicTextureHandler = new Class({ - Extends: RenderNode, +var DynamicTextureHandler = class extends RenderNode { - initialize: function DynamicTextureHandler (manager) + constructor(manager) { - RenderNode.call(this, 'DynamicTextureHandler', manager); + super('DynamicTextureHandler', manager); /** * The RenderNode that draws a filled rectangle. @@ -36,7 +35,7 @@ var DynamicTextureHandler = new Class({ * @since 4.0.0 */ this.fillRectNode = this.manager.getNode('FillRect'); - }, + } /** * Renders the DynamicTexture. @@ -45,7 +44,7 @@ var DynamicTextureHandler = new Class({ * @since 4.0.0 * @param {Phaser.Textures.DynamicTexture} dynamicTexture - The DynamicTexture to render. */ - run: function (dynamicTexture) + run(dynamicTexture) { var drawingContext = dynamicTexture.drawingContext; var camera = drawingContext.camera; @@ -323,7 +322,7 @@ var DynamicTextureHandler = new Class({ camera.emit(CameraEvents.POST_RENDER, camera); this.onRunEnd(drawingContext); - }, + } /** * Draw an object to the DynamicTexture, handling blend modes. @@ -341,7 +340,7 @@ var DynamicTextureHandler = new Class({ * * @return {Phaser.Renderer.WebGL.DrawingContext} The new current drawing context. */ - _draw: function (renderer, object, currentContext, drawingContext, eraseContext, parentMatrix) + _draw(renderer, object, currentContext, drawingContext, eraseContext, parentMatrix) { // Handle blend mode. if ( @@ -371,6 +370,6 @@ var DynamicTextureHandler = new Class({ return currentContext; } -}); +}; module.exports = DynamicTextureHandler; diff --git a/src/renderer/webgl/renderNodes/FillCamera.js b/src/renderer/webgl/renderNodes/FillCamera.js index 346b870cf4..b1e76593d3 100644 --- a/src/renderer/webgl/renderNodes/FillCamera.js +++ b/src/renderer/webgl/renderNodes/FillCamera.js @@ -18,12 +18,11 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FillCamera = new Class({ - Extends: RenderNode, +var FillCamera = class extends RenderNode { - initialize: function FillCamera (manager) + constructor(manager) { - RenderNode.call(this, 'FillCamera', manager); + super('FillCamera', manager); /** * The RenderNode that draws a filled rectangle. @@ -33,7 +32,7 @@ var FillCamera = new Class({ * @since 4.0.0 */ this.fillRectNode = this.manager.getNode('FillRect'); - }, + } /** * Fills the camera with a color. @@ -45,7 +44,7 @@ var FillCamera = new Class({ * @param {number} color - The color to fill the camera with. * @param {boolean} [isFramebufferCamera] - Is this camera rendering to a framebuffer? If so, the camera position will not be applied, on the assumption that the camera position will be used to position the framebuffer in the external context. */ - run: function (drawingContext, color, isFramebufferCamera) + run(drawingContext, color, isFramebufferCamera) { this.onRunBegin(drawingContext); @@ -59,6 +58,6 @@ var FillCamera = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = FillCamera; diff --git a/src/renderer/webgl/renderNodes/FillPath.js b/src/renderer/webgl/renderNodes/FillPath.js index 639a83ac6f..02d0a84c38 100644 --- a/src/renderer/webgl/renderNodes/FillPath.js +++ b/src/renderer/webgl/renderNodes/FillPath.js @@ -25,13 +25,12 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FillPath = new Class({ - Extends: RenderNode, +var FillPath = class extends RenderNode { - initialize: function FillPath (manager) + constructor(manager) { - RenderNode.call(this, 'FillPath', manager); - }, + super('FillPath', manager); + } /** * Render the path using Earcut. @@ -48,7 +47,7 @@ var FillPath = new Class({ * @param {number} detail - The level of detail to use when filling the path. Points which are only this far apart in screen space are combined. It is ignored if the entire path is equal to or shorter than this distance. * @param {boolean} lighting - Whether to apply lighting effects to the path. */ - run: function (drawingContext, currentMatrix, submitterNode, path, tintTL, tintTR, tintBL, detail, lighting) + run(drawingContext, currentMatrix, submitterNode, path, tintTL, tintTR, tintBL, detail, lighting) { this.onRunBegin(drawingContext); @@ -156,6 +155,6 @@ var FillPath = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = FillPath; diff --git a/src/renderer/webgl/renderNodes/FillRect.js b/src/renderer/webgl/renderNodes/FillRect.js index c267a2230c..6c250b6d0a 100644 --- a/src/renderer/webgl/renderNodes/FillRect.js +++ b/src/renderer/webgl/renderNodes/FillRect.js @@ -20,12 +20,11 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FillRect = new Class({ - Extends: RenderNode, +var FillRect = class extends RenderNode { - initialize: function FillRect (manager) + constructor(manager) { - RenderNode.call(this, 'FillRect', manager); + super('FillRect', manager); /** * The fallback batch handler for this node. @@ -62,7 +61,7 @@ var FillRect = new Class({ 0, 1, 2, 2, 3, 0 ]; - }, + } /** * Render the rectangle. @@ -82,7 +81,7 @@ var FillRect = new Class({ * @param {number} tintBR - The bottom-right tint color. * @param {boolean} lighting - Whether to apply lighting effects to the rectangle. */ - run: function (drawingContext, currentMatrix, submitterNode, x, y, width, height, tintTL, tintTR, tintBL, tintBR, lighting) + run(drawingContext, currentMatrix, submitterNode, x, y, width, height, tintTL, tintTR, tintBL, tintBR, lighting) { this.onRunBegin(drawingContext); @@ -110,6 +109,6 @@ var FillRect = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = FillRect; diff --git a/src/renderer/webgl/renderNodes/FillTri.js b/src/renderer/webgl/renderNodes/FillTri.js index fb9bb5cb15..d964d0d253 100644 --- a/src/renderer/webgl/renderNodes/FillTri.js +++ b/src/renderer/webgl/renderNodes/FillTri.js @@ -18,12 +18,11 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FillTri = new Class({ - Extends: RenderNode, +var FillTri = class extends RenderNode { - initialize: function FillTri (manager) + constructor(manager) { - RenderNode.call(this, 'FillTri', manager); + super('FillTri', manager); /** * Vertex indices for the triangle. @@ -38,7 +37,7 @@ var FillTri = new Class({ this._indexedTriangles = [ 0, 1, 2 ]; - }, + } /** * Render the triangle. @@ -59,7 +58,7 @@ var FillTri = new Class({ * @param {number} tintC - The tint color of the third vertex. * @param {boolean} lighting - Whether to apply lighting effects to the triangle. */ - run: function (drawingContext, currentMatrix, submitterNode, xA, yA, xB, yB, xC, yC, tintA, tintB, tintC, lighting) + run(drawingContext, currentMatrix, submitterNode, xA, yA, xB, yB, xC, yC, tintA, tintB, tintC, lighting) { this.onRunBegin(drawingContext); @@ -108,6 +107,6 @@ var FillTri = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = FillTri; diff --git a/src/renderer/webgl/renderNodes/ListCompositor.js b/src/renderer/webgl/renderNodes/ListCompositor.js index cb248c677a..b55f8dfaa4 100644 --- a/src/renderer/webgl/renderNodes/ListCompositor.js +++ b/src/renderer/webgl/renderNodes/ListCompositor.js @@ -18,13 +18,12 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var ListCompositor = new Class({ - Extends: RenderNode, +var ListCompositor = class extends RenderNode { - initialize: function ListCompositor (manager) + constructor(manager) { - RenderNode.call(this, 'ListCompositor', manager); - }, + super('ListCompositor', manager); + } /** * Render each child in the display list. @@ -39,7 +38,7 @@ var ListCompositor = new Class({ * @param {Phaser.GameObjects.Components.TransformMatrix} [parentTransformMatrix] - This transform matrix is defined if the game object is nested * @param {number} [renderStep=0] - Which step of the rendering process is this? This is the index of the currently running function in a list of functions. */ - run: function ( + run( displayContext, children, parentTransformMatrix, @@ -96,6 +95,6 @@ var ListCompositor = new Class({ this.onRunEnd(displayContext); } -}); +}; module.exports = ListCompositor; diff --git a/src/renderer/webgl/renderNodes/RebindContext.js b/src/renderer/webgl/renderNodes/RebindContext.js index 50bf8c743f..c02364453c 100644 --- a/src/renderer/webgl/renderNodes/RebindContext.js +++ b/src/renderer/webgl/renderNodes/RebindContext.js @@ -24,12 +24,11 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var RebindContext = new Class({ - Extends: RenderNode, +var RebindContext = class extends RenderNode { - initialize: function RebindContext (manager) + constructor(manager) { - RenderNode.call(this, 'RebindContext', manager); + super('RebindContext', manager); /** * The WebGL state to set when this node is run. @@ -52,9 +51,9 @@ var RebindContext = new Class({ }, vao: null }; - }, + } - run: function (displayContext) + run(displayContext) { this.onRunBegin(displayContext); @@ -76,6 +75,6 @@ var RebindContext = new Class({ this.onRunEnd(displayContext); } -}); +}; module.exports = RebindContext; diff --git a/src/renderer/webgl/renderNodes/RenderNode.js b/src/renderer/webgl/renderNodes/RenderNode.js index f4263a1b0a..72a82517d7 100644 --- a/src/renderer/webgl/renderNodes/RenderNode.js +++ b/src/renderer/webgl/renderNodes/RenderNode.js @@ -18,11 +18,9 @@ var Class = require('../../../utils/Class'); * @param {string} name - The name of the RenderNode. * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var RenderNode = new Class({ +var RenderNode = class { - initialize: - - function RenderNode (name, manager) + constructor(name, manager) { /** * The name of the RenderNode. @@ -53,7 +51,7 @@ var RenderNode = new Class({ * @default null */ this._run = null; - }, + } /** * Run the RenderNode. @@ -66,10 +64,10 @@ var RenderNode = new Class({ * @param {...*} [args] - Arguments to pass to the node. These will vary depending on the node. * @since 4.0.0 */ - run: function () + run() { // Insert code here. - }, + } /** * By default this is an empty method hook that you can override and use in your own custom render nodes. @@ -81,9 +79,9 @@ var RenderNode = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The context currently in use. */ - onRunBegin: function (drawingContext) + onRunBegin(drawingContext) { - }, + } /** * By default this is an empty method hook that you can override and use in your own custom render nodes. @@ -95,9 +93,9 @@ var RenderNode = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The context currently in use. */ - onRunEnd: function (drawingContext) + onRunEnd(drawingContext) { - }, + } /** * Set whether the node should report debug information. @@ -107,7 +105,7 @@ var RenderNode = new Class({ * @since 4.0.0 * @param {boolean} debug - Whether to report debug information. */ - setDebug: function (debug) + setDebug(debug) { if (debug) { @@ -131,6 +129,6 @@ var RenderNode = new Class({ this._run = null; } } -}); +}; module.exports = RenderNode; diff --git a/src/renderer/webgl/renderNodes/RenderNodeManager.js b/src/renderer/webgl/renderNodes/RenderNodeManager.js index f8bf84e5ef..6a8b58bb9e 100644 --- a/src/renderer/webgl/renderNodes/RenderNodeManager.js +++ b/src/renderer/webgl/renderNodes/RenderNodeManager.js @@ -73,12 +73,11 @@ var YieldContext = require('./YieldContext'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer that owns this manager. */ -var RenderNodeManager = new Class({ - Extends: EventEmitter, +var RenderNodeManager = class extends EventEmitter { - initialize: function RenderNodeManager (renderer) + constructor(renderer) { - EventEmitter.call(this); + super(); /** * The renderer that owns this manager. @@ -250,7 +249,7 @@ var RenderNodeManager = new Class({ * @default null */ this.currentDebugNode = null; - }, + } /** * Add a node to the manager. @@ -261,7 +260,7 @@ var RenderNodeManager = new Class({ * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNode} node - The node to add. * @throws {Error} Will throw an error if the node already exists. */ - addNode: function (name, node) + addNode(name, node) { if (this._nodes[name]) { @@ -275,7 +274,7 @@ var RenderNodeManager = new Class({ { node.setDebug(true); } - }, + } /** * Add a constructor for a node to the manager. @@ -287,14 +286,14 @@ var RenderNodeManager = new Class({ * @param {function} constructor - The constructor for the node. * @throws {Error} Will throw an error if the node constructor already exists. */ - addNodeConstructor: function (name, constructor) + addNodeConstructor(name, constructor) { if (this._nodeConstructors[name]) { throw new Error('node constructor ' + name + ' already exists.'); } this._nodeConstructors[name] = constructor; - }, + } /** * Get a node from the manager. @@ -308,7 +307,7 @@ var RenderNodeManager = new Class({ * @param {string} name - The name of the node. * @return {?Phaser.Renderer.WebGL.RenderNodes.RenderNode} The node, or null if it does not exist. */ - getNode: function (name) + getNode(name) { if (this._nodes[name]) { @@ -321,7 +320,7 @@ var RenderNodeManager = new Class({ return node; } return null; - }, + } /** * Check if a node exists in the manager. @@ -336,10 +335,10 @@ var RenderNodeManager = new Class({ * @param {boolean} [constructed=false] - Whether the node must be constructed to be considered to exist. * @return {boolean} Whether the node exists. */ - hasNode: function (name, constructed) + hasNode(name, constructed) { return !!this._nodes[name] || (!constructed && !!this._nodeConstructors[name]); - }, + } /** * Set the current batch node. If a batch node is already in progress, @@ -350,7 +349,7 @@ var RenderNodeManager = new Class({ * @param {?Phaser.Renderer.WebGL.RenderNodes.BatchHandler} node - The node to set, or null to clear the current node. * @param {Phaser.Renderer.WebGL.DrawingContext} [drawingContext] - The drawing context. Only used if `node` is defined. */ - setCurrentBatchNode: function (node, drawingContext) + setCurrentBatchNode(node, drawingContext) { if (this.currentBatchNode !== node) { @@ -365,7 +364,7 @@ var RenderNodeManager = new Class({ this.currentBatchDrawingContext = node ? drawingContext : null; } - }, + } /** * Set `maxParallelTextureUnits` to a new value. @@ -379,12 +378,12 @@ var RenderNodeManager = new Class({ * @param {number} [value] - The new value for `maxParallelTextureUnits`. If not provided, it will be set to the renderer's `maxTextures`. * @fires Phaser.Renderer.Events#SET_PARALLEL_TEXTURE_UNITS */ - setMaxParallelTextureUnits: function (value) + setMaxParallelTextureUnits(value) { this.maxParallelTextureUnits = Math.max(1, Math.min(value, this.renderer.maxTextures)); this.emit(Events.SET_PARALLEL_TEXTURE_UNITS, this.maxParallelTextureUnits); - }, + } /** * Finish rendering the current batch. @@ -393,13 +392,13 @@ var RenderNodeManager = new Class({ * @method Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager#finishBatch * @since 4.0.0 */ - finishBatch: function () + finishBatch() { if (this.currentBatchNode !== null) { this.setCurrentBatchNode(null); } - }, + } /** * Start a standalone render (SAR), which is not part of a batch. @@ -408,10 +407,10 @@ var RenderNodeManager = new Class({ * @method Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager#startStandAloneRender * @since 4.0.0 */ - startStandAloneRender: function () + startStandAloneRender() { this.finishBatch(); - }, + } /** * Set whether nodes should record their run method for debugging. @@ -422,7 +421,7 @@ var RenderNodeManager = new Class({ * @since 4.0.0 * @param {boolean} value - Whether nodes should record their run method for debugging. */ - setDebug: function (value) + setDebug(value) { this.debug = value; @@ -448,7 +447,7 @@ var RenderNodeManager = new Class({ this ); } - }, + } /** * Record a newly run RenderNode in the debug graph. @@ -457,7 +456,7 @@ var RenderNodeManager = new Class({ * @since 4.0.0 * @param {string} name - The name of the node. */ - pushDebug: function (name) + pushDebug(name) { if (!this.debug) { @@ -480,7 +479,7 @@ var RenderNodeManager = new Class({ } this.currentDebugNode = node; - }, + } /** * Pop the last recorded RenderNode from the debug graph. @@ -488,7 +487,7 @@ var RenderNodeManager = new Class({ * @method Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager#popDebug * @since 4.0.0 */ - popDebug: function () + popDebug() { if (!this.debug) { @@ -503,7 +502,7 @@ var RenderNodeManager = new Class({ { this.currentDebugNode = null; } - }, + } /** * Format the current debug graph as an indented string. @@ -512,7 +511,7 @@ var RenderNodeManager = new Class({ * @since 4.0.0 * @return {string} The formatted debug graph. */ - debugToString: function () + debugToString() { var output = ''; var indent = 0; @@ -539,6 +538,6 @@ var RenderNodeManager = new Class({ return output; } -}); +}; module.exports = RenderNodeManager; diff --git a/src/renderer/webgl/renderNodes/ShaderQuad.js b/src/renderer/webgl/renderNodes/ShaderQuad.js index fdd959541f..c47f2f0f16 100644 --- a/src/renderer/webgl/renderNodes/ShaderQuad.js +++ b/src/renderer/webgl/renderNodes/ShaderQuad.js @@ -25,12 +25,11 @@ var ShaderSourceFS = require('../shaders/ShaderQuad-frag'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.GameObjects.Shader.ShaderQuadConfig} config - The configuration object for this RenderNode. */ -var ShaderQuad = new Class({ - Extends: RenderNode, +var ShaderQuad = class extends RenderNode { - initialize: function ShaderQuad (manager, config) + constructor(manager, config) { - RenderNode.call(this, 'ShaderQuad', manager); + super('ShaderQuad', manager); var renderer = manager.renderer; @@ -132,7 +131,7 @@ var ShaderQuad = new Class({ frame: { realWidth: 1, realHeight: 1 }, uvSource: { x: 0, y: 0 } }; - }, + } /** * Completes the configuration for this RenderNode. @@ -144,7 +143,7 @@ var ShaderQuad = new Class({ * @param {object} config - The configuration object for this RenderNode. * @return {object} The completed configuration object. */ - _completeConfig: function (config) + _completeConfig(config) { var gl = this.renderer.gl; @@ -209,9 +208,9 @@ var ShaderQuad = new Class({ ] } }; - }, + } - run: function (drawingContext, gameObject, parentMatrix) + run(drawingContext, gameObject, parentMatrix) { var manager = this.manager; var renderer = this.renderer; @@ -324,9 +323,9 @@ var ShaderQuad = new Class({ } this.onRunEnd(drawingContext); - }, + } - setupTextures: function (gameObject) + setupTextures(gameObject) { var textures = gameObject.textures; var glTextures = []; @@ -339,7 +338,7 @@ var ShaderQuad = new Class({ } return glTextures; - }, + } /** * Updates the shader configuration for the current render pass. @@ -354,10 +353,10 @@ var ShaderQuad = new Class({ * @param {Phaser.GameObjects.GameObject} gameObject - The GameObject being rendered. * @param {Phaser.Renderer.WebGL.RenderNodes.ShaderQuad} renderNode - The RenderNode being rendered. */ - updateShaderConfig: function (drawingContext, gameObject, renderNode) + updateShaderConfig(drawingContext, gameObject, renderNode) { // NOOP. } -}); +}; module.exports = ShaderQuad; diff --git a/src/renderer/webgl/renderNodes/StrokePath.js b/src/renderer/webgl/renderNodes/StrokePath.js index c70bda9d37..f0ea886b8f 100644 --- a/src/renderer/webgl/renderNodes/StrokePath.js +++ b/src/renderer/webgl/renderNodes/StrokePath.js @@ -19,12 +19,11 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var StrokePath = new Class({ - Extends: RenderNode, +var StrokePath = class extends RenderNode { - initialize: function StrokePath (manager) + constructor(manager) { - RenderNode.call(this, 'StrokePath', manager); + super('StrokePath', manager); /** * The RenderNode that generates a line segment. @@ -34,7 +33,7 @@ var StrokePath = new Class({ * @since 4.0.0 */ this.drawLineNode = this.manager.getNode('DrawLine'); - }, + } /** * Render a stroke path consisting of several line segments. @@ -54,7 +53,7 @@ var StrokePath = new Class({ * @param {number} detail - The level of detail to use when rendering the stroke. Points which are only this far apart in screen space are combined. It is ignored if the entire path is equal to or shorter than this distance. * @param {boolean} lighting - Whether to apply lighting effects to the stroke. */ - run: function (drawingContext, submitterNode, path, lineWidth, open, currentMatrix, tintTL, tintTR, tintBL, tintBR, detail, lighting) + run(drawingContext, submitterNode, path, lineWidth, open, currentMatrix, tintTL, tintTR, tintBL, tintBR, detail, lighting) { this.onRunBegin(drawingContext); @@ -193,6 +192,6 @@ var StrokePath = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = StrokePath; diff --git a/src/renderer/webgl/renderNodes/YieldContext.js b/src/renderer/webgl/renderNodes/YieldContext.js index e59de67cbc..ec46cdd5d9 100644 --- a/src/renderer/webgl/renderNodes/YieldContext.js +++ b/src/renderer/webgl/renderNodes/YieldContext.js @@ -22,12 +22,11 @@ var RenderNode = require('./RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var YieldContext = new Class({ - Extends: RenderNode, +var YieldContext = class extends RenderNode { - initialize: function YieldContext (manager) + constructor(manager) { - RenderNode.call(this, 'YieldContext', manager); + super('YieldContext', manager); /** * The WebGL state to set when this node is run. @@ -43,7 +42,7 @@ var YieldContext = new Class({ blend: this.manager.renderer.blendModes[0], vao: null }; - }, + } /** * Sets the WebGL context to a default state. @@ -54,7 +53,7 @@ var YieldContext = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} displayContext - The context currently in use. */ - run: function (displayContext) + run(displayContext) { this.onRunBegin(displayContext); @@ -69,6 +68,6 @@ var YieldContext = new Class({ this.onRunEnd(displayContext); } -}); +}; module.exports = YieldContext; diff --git a/src/renderer/webgl/renderNodes/filters/BaseFilter.js b/src/renderer/webgl/renderNodes/filters/BaseFilter.js index 427fdc8dcd..1d86975c2b 100644 --- a/src/renderer/webgl/renderNodes/filters/BaseFilter.js +++ b/src/renderer/webgl/renderNodes/filters/BaseFilter.js @@ -21,13 +21,12 @@ var RenderNode = require('../RenderNode'); * @param {string} name - The name of the filter. * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this filter. */ -var BaseFilter = new Class({ - Extends: RenderNode, +var BaseFilter = class extends RenderNode { - initialize: function BaseFilter (name, manager) + constructor(name, manager) { - RenderNode.call(this, name, manager); - }, + super(name, manager); + } /** * Run the filter. It returns a drawing context containing the output texture. @@ -40,10 +39,10 @@ var BaseFilter = new Class({ * @param {Phaser.Geom.Rectangle} [padding] - The padding to add to the input texture to create the output texture. If not specified, the controller is used to get the padding. This should be undefined for internal filters, so the controller will expand textures as needed; and defined as the negative padding of the previous filter for external filters, so the texture will shrink to the correct size. * @returns {Phaser.Renderer.WebGL.DrawingContext} The drawing context containing the output texture. */ - run: function (controller, inputDrawingContext, outputDrawingContext, padding) + run(controller, inputDrawingContext, outputDrawingContext, padding) { // This is the base run method that all filters should override } -}); +}; module.exports = BaseFilter; diff --git a/src/renderer/webgl/renderNodes/filters/BaseFilterShader.js b/src/renderer/webgl/renderNodes/filters/BaseFilterShader.js index a5b7a32b03..1ffa949afb 100644 --- a/src/renderer/webgl/renderNodes/filters/BaseFilterShader.js +++ b/src/renderer/webgl/renderNodes/filters/BaseFilterShader.js @@ -44,10 +44,9 @@ var BaseFilter = require('./BaseFilter'); * @param {string} [fragmentShaderSource] - The fragment shader source. * @param {?Phaser.Types.Renderer.WebGL.ShaderAdditionConfig[]} [shaderAdditions] - An array of shader additions to apply to the shader program. */ -var BaseFilterShader = new Class({ - Extends: BaseFilter, +var BaseFilterShader = class extends BaseFilter { - initialize: function BaseFilterShader (name, manager, fragmentShaderKey, fragmentShaderSource, shaderAdditions) + constructor(name, manager, fragmentShaderKey, fragmentShaderSource, shaderAdditions) { if (!fragmentShaderSource) { @@ -59,7 +58,7 @@ var BaseFilterShader = new Class({ fragmentShaderSource = baseShader.glsl; } - BaseFilter.call(this, name, manager); + super(name, manager); var renderer = manager.renderer; var gl = renderer.gl; @@ -146,9 +145,9 @@ var BaseFilterShader = new Class({ // Set the shader program to use texture unit 0. this.programManager.setUniform('uMainSampler', 0); - }, + } - run: function (controller, inputDrawingContext, outputDrawingContext, padding) + run(controller, inputDrawingContext, outputDrawingContext, padding) { var manager = this.manager; var renderer = manager.renderer; @@ -281,7 +280,7 @@ var BaseFilterShader = new Class({ this.onRunEnd(outputDrawingContext); return outputDrawingContext; - }, + } /** * Set up the shader configuration for this shader. @@ -292,10 +291,10 @@ var BaseFilterShader = new Class({ * @param {Phaser.Filters.Controller} controller - The filter controller. * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The drawing context in use. */ - updateShaderConfig: function (controller, drawingContext) + updateShaderConfig(controller, drawingContext) { // NOOP - }, + } /** * Run any necessary modifications on the textures array. @@ -307,10 +306,10 @@ var BaseFilterShader = new Class({ * @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper[]} textures - The array of textures to modify in-place. * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The drawing context in use. */ - setupTextures: function (controller, textures, drawingContext) + setupTextures(controller, textures, drawingContext) { // NOOP - }, + } /** * Set up the uniforms for this shader, based on the controller. @@ -320,11 +319,11 @@ var BaseFilterShader = new Class({ * @param {Phaser.Filters.Controller} controller - The filter controller. * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The drawing context in use. */ - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { // This is the base setupUniforms method that all filters should override } -}); +}; function remapCoord (coord, low, high) { diff --git a/src/renderer/webgl/renderNodes/filters/FilterBarrel.js b/src/renderer/webgl/renderNodes/filters/FilterBarrel.js index ee42c293ed..69bc5c52cc 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterBarrel.js +++ b/src/renderer/webgl/renderNodes/filters/FilterBarrel.js @@ -21,20 +21,19 @@ var ShaderSourceFS = require('../../shaders/FilterBarrel-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterBarrel = new Class({ - Extends: BaseFilterShader, +var FilterBarrel = class extends BaseFilterShader { - initialize: function FilterBarrel (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterBarrel', manager, null, ShaderSourceFS); - }, + super('FilterBarrel', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; programManager.setUniform('amount', controller.amount); } -}); +}; module.exports = FilterBarrel; diff --git a/src/renderer/webgl/renderNodes/filters/FilterBlend.js b/src/renderer/webgl/renderNodes/filters/FilterBlend.js index d79821b828..73e7c46da3 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterBlend.js +++ b/src/renderer/webgl/renderNodes/filters/FilterBlend.js @@ -23,10 +23,9 @@ var ShaderSourceFS = require('../../shaders/FilterBlend-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterBlend = new Class({ - Extends: BaseFilterShader, +var FilterBlend = class extends BaseFilterShader { - initialize: function FilterBlend (manager) + constructor(manager) { /** * A map from blend mode integers to their string names. @@ -56,10 +55,10 @@ var FilterBlend = new Class({ } ]; - BaseFilterShader.call(this, 'FilterBlend', manager, null, ShaderSourceFS, additions); - }, + super('FilterBlend', manager, null, ShaderSourceFS, additions); + } - updateShaderConfig: function (controller, drawingContext) + updateShaderConfig(controller, drawingContext) { var blendMode = controller.blendMode; if (blendMode === BlendModes.SKIP_CHECK) @@ -71,15 +70,15 @@ var FilterBlend = new Class({ var blendModeAddition = this.programManager.getAdditionsByTag('blendmode')[0]; blendModeAddition.name = name; blendModeAddition.additions.fragmentHeader = '#define BLEND ' + name; - }, + } - setupTextures: function (controller, textures, drawingContext) + setupTextures(controller, textures, drawingContext) { // Blend texture. textures[1] = controller.glTexture; - }, + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; @@ -87,6 +86,6 @@ var FilterBlend = new Class({ programManager.setUniform('amount', controller.amount); programManager.setUniform('color', controller.color); } -}); +}; module.exports = FilterBlend; diff --git a/src/renderer/webgl/renderNodes/filters/FilterBlur.js b/src/renderer/webgl/renderNodes/filters/FilterBlur.js index f85af25c4a..d32e20ab98 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterBlur.js +++ b/src/renderer/webgl/renderNodes/filters/FilterBlur.js @@ -23,15 +23,14 @@ var BaseFilter = require('./BaseFilter'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterBlur = new Class({ - Extends: BaseFilter, +var FilterBlur = class extends BaseFilter { - initialize: function FilterBlur (manager) + constructor(manager) { - BaseFilter.call(this, 'FilterBlur', manager); - }, + super('FilterBlur', manager); + } - run: function (controller, inputDrawingContext, outputDrawingContext, padding) + run(controller, inputDrawingContext, outputDrawingContext, padding) { this.onRunBegin(outputDrawingContext); @@ -109,6 +108,6 @@ var FilterBlur = new Class({ return outputDrawingContext; } -}); +}; module.exports = FilterBlur; diff --git a/src/renderer/webgl/renderNodes/filters/FilterBlurHigh.js b/src/renderer/webgl/renderNodes/filters/FilterBlurHigh.js index 6f2994fa4b..45936292fe 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterBlurHigh.js +++ b/src/renderer/webgl/renderNodes/filters/FilterBlurHigh.js @@ -24,15 +24,14 @@ var ShaderSourceFS = require('../../shaders/FilterBlurHigh-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterBlurHigh = new Class({ - Extends: BaseFilterShader, +var FilterBlurHigh = class extends BaseFilterShader { - initialize: function FilterBlurHigh (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterBlurHigh', manager, null, ShaderSourceFS); - }, + super('FilterBlurHigh', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; @@ -41,6 +40,6 @@ var FilterBlurHigh = new Class({ programManager.setUniform('color', controller.color); programManager.setUniform('offset', [ controller.x, controller.y ]); } -}); +}; module.exports = FilterBlurHigh; diff --git a/src/renderer/webgl/renderNodes/filters/FilterBlurLow.js b/src/renderer/webgl/renderNodes/filters/FilterBlurLow.js index bf10875907..b4b6b40fcc 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterBlurLow.js +++ b/src/renderer/webgl/renderNodes/filters/FilterBlurLow.js @@ -24,15 +24,14 @@ var ShaderSourceFS = require('../../shaders/FilterBlurLow-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterBlurLow = new Class({ - Extends: BaseFilterShader, +var FilterBlurLow = class extends BaseFilterShader { - initialize: function FilterBlurLow (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterBlurLow', manager, null, ShaderSourceFS); - }, + super('FilterBlurLow', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; @@ -41,6 +40,6 @@ var FilterBlurLow = new Class({ programManager.setUniform('color', controller.color); programManager.setUniform('offset', [ controller.x, controller.y ]); } -}); +}; module.exports = FilterBlurLow; diff --git a/src/renderer/webgl/renderNodes/filters/FilterBlurMed.js b/src/renderer/webgl/renderNodes/filters/FilterBlurMed.js index ae2bc6fdc0..74b037a100 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterBlurMed.js +++ b/src/renderer/webgl/renderNodes/filters/FilterBlurMed.js @@ -24,15 +24,14 @@ var ShaderSourceFS = require('../../shaders/FilterBlurMed-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterBlurMed = new Class({ - Extends: BaseFilterShader, +var FilterBlurMed = class extends BaseFilterShader { - initialize: function FilterBlurMed (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterBlurMed', manager, null, ShaderSourceFS); - }, + super('FilterBlurMed', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; @@ -41,6 +40,6 @@ var FilterBlurMed = new Class({ programManager.setUniform('color', controller.color); programManager.setUniform('offset', [ controller.x, controller.y ]); } -}); +}; module.exports = FilterBlurMed; diff --git a/src/renderer/webgl/renderNodes/filters/FilterBokeh.js b/src/renderer/webgl/renderNodes/filters/FilterBokeh.js index 74a7de54a0..011adb3747 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterBokeh.js +++ b/src/renderer/webgl/renderNodes/filters/FilterBokeh.js @@ -21,15 +21,14 @@ var ShaderSourceFS = require('../../shaders/FilterBokeh-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterBokeh = new Class({ - Extends: BaseFilterShader, +var FilterBokeh = class extends BaseFilterShader { - initialize: function FilterBokeh (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterBokeh', manager, null, ShaderSourceFS); - }, + super('FilterBokeh', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; @@ -41,6 +40,6 @@ var FilterBokeh = new Class({ programManager.setUniform('isTiltShift', controller.isTiltShift); programManager.setUniform('resolution', [ drawingContext.width, drawingContext.height ]); } -}); +}; module.exports = FilterBokeh; diff --git a/src/renderer/webgl/renderNodes/filters/FilterColorMatrix.js b/src/renderer/webgl/renderNodes/filters/FilterColorMatrix.js index d0bbc570f8..d3467b6e5f 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterColorMatrix.js +++ b/src/renderer/webgl/renderNodes/filters/FilterColorMatrix.js @@ -21,21 +21,20 @@ var ShaderSourceFS = require('../../shaders/FilterColorMatrix-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterColorMatrix = new Class({ - Extends: BaseFilterShader, +var FilterColorMatrix = class extends BaseFilterShader { - initialize: function FilterColorMatrix (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterColorMatrix', manager, null, ShaderSourceFS); - }, + super('FilterColorMatrix', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; programManager.setUniform('uColorMatrix[0]', controller.colorMatrix.getData()); programManager.setUniform('uAlpha', controller.colorMatrix.alpha); } -}); +}; module.exports = FilterColorMatrix; diff --git a/src/renderer/webgl/renderNodes/filters/FilterDisplacement.js b/src/renderer/webgl/renderNodes/filters/FilterDisplacement.js index 90796bc167..f8034cbe8f 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterDisplacement.js +++ b/src/renderer/webgl/renderNodes/filters/FilterDisplacement.js @@ -21,27 +21,26 @@ var ShaderSourceFS = require('../../shaders/FilterDisplacement-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterDisplacement = new Class({ - Extends: BaseFilterShader, +var FilterDisplacement = class extends BaseFilterShader { - initialize: function FilterDisplacement (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterDisplacement', manager, null, ShaderSourceFS); - }, + super('FilterDisplacement', manager, null, ShaderSourceFS); + } - setupTextures: function (controller, textures) + setupTextures(controller, textures) { // Displacement texture. textures[1] = controller.glTexture; - }, + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; programManager.setUniform('uDisplacementSampler', 1); programManager.setUniform('amount', [ controller.x, controller.y ]); } -}); +}; module.exports = FilterDisplacement; diff --git a/src/renderer/webgl/renderNodes/filters/FilterGlow.js b/src/renderer/webgl/renderNodes/filters/FilterGlow.js index afc818702e..c0268999b4 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterGlow.js +++ b/src/renderer/webgl/renderNodes/filters/FilterGlow.js @@ -21,10 +21,9 @@ var ShaderSourceFS = require('../../shaders/FilterGlow-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterGlow = new Class({ - Extends: BaseFilterShader, +var FilterGlow = class extends BaseFilterShader { - initialize: function FilterGlow (manager) + constructor(manager) { var shaderAdditions = [ { @@ -43,10 +42,10 @@ var FilterGlow = new Class({ } ]; - BaseFilterShader.call(this, 'FilterGlow', manager, null, ShaderSourceFS, shaderAdditions); - }, + super('FilterGlow', manager, null, ShaderSourceFS, shaderAdditions); + } - updateShaderConfig: function (controller, drawingContext) + updateShaderConfig(controller, drawingContext) { var programManager = this.programManager; @@ -59,9 +58,9 @@ var FilterGlow = new Class({ var qualityAddition = programManager.getAdditionsByTag('quality')[0]; qualityAddition.name = 'quality_' + quality; qualityAddition.additions.fragmentDefine = '#undef QUALITY\n#define QUALITY ' + quality; - }, + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; @@ -72,6 +71,6 @@ var FilterGlow = new Class({ programManager.setUniform('scale', controller.scale); programManager.setUniform('knockout', controller.knockout); } -}); +}; module.exports = FilterGlow; diff --git a/src/renderer/webgl/renderNodes/filters/FilterMask.js b/src/renderer/webgl/renderNodes/filters/FilterMask.js index b0c323f83e..be1f880e31 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterMask.js +++ b/src/renderer/webgl/renderNodes/filters/FilterMask.js @@ -21,15 +21,14 @@ var ShaderSourceFS = require('../../shaders/FilterMask-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterMask = new Class({ - Extends: BaseFilterShader, +var FilterMask = class extends BaseFilterShader { - initialize: function FilterMask (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterMask', manager, null, ShaderSourceFS); - }, + super('FilterMask', manager, null, ShaderSourceFS); + } - setupTextures: function (controller, textures, drawingContext) + setupTextures(controller, textures, drawingContext) { // Update dynamic texture if necessary. if (controller.maskGameObject && (controller.needsUpdate || controller.autoUpdate)) @@ -39,15 +38,15 @@ var FilterMask = new Class({ // Mask texture. textures[1] = controller.glTexture; - }, + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; programManager.setUniform('uMaskSampler', 1); programManager.setUniform('invert', controller.invert); } -}); +}; module.exports = FilterMask; diff --git a/src/renderer/webgl/renderNodes/filters/FilterParallelFilters.js b/src/renderer/webgl/renderNodes/filters/FilterParallelFilters.js index 3d6a9096a2..f031d99c15 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterParallelFilters.js +++ b/src/renderer/webgl/renderNodes/filters/FilterParallelFilters.js @@ -23,15 +23,14 @@ var BaseFilter = require('./BaseFilter'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterParallelFilters = new Class({ - Extends: BaseFilter, +var FilterParallelFilters = class extends BaseFilter { - initialize: function FilterParallelFilters (manager) + constructor(manager) { - BaseFilter.call(this, 'FilterParallelFilters', manager); - }, + super('FilterParallelFilters', manager); + } - run: function (controller, inputDrawingContext, outputDrawingContext, padding) + run(controller, inputDrawingContext, outputDrawingContext, padding) { this.onRunBegin(outputDrawingContext); @@ -138,6 +137,6 @@ var FilterParallelFilters = new Class({ return outputDrawingContext; } -}); +}; module.exports = FilterParallelFilters; diff --git a/src/renderer/webgl/renderNodes/filters/FilterPixelate.js b/src/renderer/webgl/renderNodes/filters/FilterPixelate.js index 9029370a0e..e7570d647b 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterPixelate.js +++ b/src/renderer/webgl/renderNodes/filters/FilterPixelate.js @@ -21,21 +21,20 @@ var ShaderSourceFS = require('../../shaders/FilterPixelate-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterPixelate = new Class({ - Extends: BaseFilterShader, +var FilterPixelate = class extends BaseFilterShader { - initialize: function FilterPixelate (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterPixelate', manager, null, ShaderSourceFS); - }, + super('FilterPixelate', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; programManager.setUniform('amount', controller.amount); programManager.setUniform('resolution', [ drawingContext.width, drawingContext.height ]); } -}); +}; module.exports = FilterPixelate; diff --git a/src/renderer/webgl/renderNodes/filters/FilterSampler.js b/src/renderer/webgl/renderNodes/filters/FilterSampler.js index f2b2e92b42..62737d93c2 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterSampler.js +++ b/src/renderer/webgl/renderNodes/filters/FilterSampler.js @@ -21,15 +21,14 @@ var BaseFilter = require('./BaseFilter'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterSampler = new Class({ - Extends: BaseFilter, +var FilterSampler = class extends BaseFilter { - initialize: function FilterSampler (manager) + constructor(manager) { - BaseFilter.call(this, 'FilterSampler', manager); - }, + super('FilterSampler', manager); + } - run: function (controller, inputDrawingContext, outputDrawingContext, padding) + run(controller, inputDrawingContext, outputDrawingContext, padding) { this.onRunBegin(inputDrawingContext); @@ -79,6 +78,6 @@ var FilterSampler = new Class({ return inputDrawingContext; } -}); +}; module.exports = FilterSampler; diff --git a/src/renderer/webgl/renderNodes/filters/FilterShadow.js b/src/renderer/webgl/renderNodes/filters/FilterShadow.js index 9384a7cb5a..78c014509d 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterShadow.js +++ b/src/renderer/webgl/renderNodes/filters/FilterShadow.js @@ -21,15 +21,14 @@ var ShaderSourceFS = require('../../shaders/FilterShadow-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterShadow = new Class({ - Extends: BaseFilterShader, +var FilterShadow = class extends BaseFilterShader { - initialize: function FilterShadow (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterShadow', manager, null, ShaderSourceFS); - }, + super('FilterShadow', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; var samples = controller.samples; @@ -41,6 +40,6 @@ var FilterShadow = new Class({ programManager.setUniform('samples', samples); programManager.setUniform('intensity', controller.intensity); } -}); +}; module.exports = FilterShadow; diff --git a/src/renderer/webgl/renderNodes/filters/FilterThreshold.js b/src/renderer/webgl/renderNodes/filters/FilterThreshold.js index 38f941b747..ed2376971f 100644 --- a/src/renderer/webgl/renderNodes/filters/FilterThreshold.js +++ b/src/renderer/webgl/renderNodes/filters/FilterThreshold.js @@ -21,15 +21,14 @@ var ShaderSourceFS = require('../../shaders/FilterThreshold-frag.js'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var FilterThreshold = new Class({ - Extends: BaseFilterShader, +var FilterThreshold = class extends BaseFilterShader { - initialize: function FilterThreshold (manager) + constructor(manager) { - BaseFilterShader.call(this, 'FilterThreshold', manager, null, ShaderSourceFS); - }, + super('FilterThreshold', manager, null, ShaderSourceFS); + } - setupUniforms: function (controller, drawingContext) + setupUniforms(controller, drawingContext) { var programManager = this.programManager; @@ -37,6 +36,6 @@ var FilterThreshold = new Class({ programManager.setUniform('edge2', controller.edge2); programManager.setUniform('invert', controller.invert); } -}); +}; module.exports = FilterThreshold; diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js b/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js index 534e2c94d5..19bc2c9c54 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js @@ -31,14 +31,13 @@ var getTint = Utils.getTintAppendFloatAlpha; * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} [config] - The configuration object for this RenderNode. */ -var SubmitterQuad = new Class({ - Extends: RenderNode, +var SubmitterQuad = class extends RenderNode { - initialize: function SubmitterQuad (manager, config) + constructor(manager, config) { config = Merge(config || {}, this.defaultConfig); - RenderNode.call(this, config.name, manager); + super(config.name, manager); /** * The key of the RenderNode used to render data. @@ -81,7 +80,7 @@ var SubmitterQuad = new Class({ diffuseFlatThreshold: 0 } }; - }, + } /** * The default configuration for this RenderNode. @@ -93,7 +92,7 @@ var SubmitterQuad = new Class({ name: 'SubmitterQuad', role: 'Submitter', batchHandler: 'BatchHandler' - }, + } /** * Submit data for rendering. @@ -110,7 +109,7 @@ var SubmitterQuad = new Class({ * @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} [normalMap] - The normal map texture to use for lighting. If omitted, the normal map texture of the GameObject will be used, or the default normal map texture of the renderer. * @param {number} [normalMapRotation] - The rotation of the normal map texture. If omitted, the rotation of the GameObject will be used. */ - run: function ( + run( drawingContext, gameObject, parentMatrix, @@ -195,9 +194,9 @@ var SubmitterQuad = new Class({ ); this.onRunEnd(drawingContext); - }, + } - setRenderOptions: function (gameObject, normalMap, normalMapRotation) + setRenderOptions(gameObject, normalMap, normalMapRotation) { var renderOptions = this._renderOptions; var baseTexture, sourceIndex; @@ -288,6 +287,6 @@ var SubmitterQuad = new Class({ } renderOptions.smoothPixelArt = smoothPixelArt; } -}); +}; module.exports = SubmitterQuad; diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterSpriteGPULayer.js b/src/renderer/webgl/renderNodes/submitter/SubmitterSpriteGPULayer.js index 84bdae823e..efd37e5e45 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterSpriteGPULayer.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterSpriteGPULayer.js @@ -46,10 +46,9 @@ var ShaderSourceVS = require('../../shaders/SpriteGPULayer-vert'); * @param {string} [config.vertexSource] - The vertex shader source. * @param {string} [config.fragmentSource] - The fragment shader source. */ -var SubmitterSpriteGPULayer = new Class({ - Extends: RenderNode, +var SubmitterSpriteGPULayer = class extends RenderNode { - initialize: function SubmitterSpriteGPULayer (manager, config, gameObject) + constructor(manager, config, gameObject) { var renderer = manager.renderer; @@ -57,7 +56,7 @@ var SubmitterSpriteGPULayer = new Class({ var name = finalConfig.name; this._completeLayout(finalConfig); - RenderNode.call(this, name, manager); + super(name, manager); /** * The completed configuration object for this RenderNode. @@ -172,7 +171,7 @@ var SubmitterSpriteGPULayer = new Class({ * @private */ this._lightVector = new Vector2(); - }, + } /** * Default configuration of this RenderNode. @@ -284,7 +283,7 @@ var SubmitterSpriteGPULayer = new Class({ } ] } - }, + } /** * Fill out the configuration object with default values where needed. @@ -293,7 +292,7 @@ var SubmitterSpriteGPULayer = new Class({ * @since 4.0.0 * @param {object} config - The configuration object to complete. */ - _completeLayout: function (config) + _completeLayout(config) { // Set up vertex buffer layout. var layoutSource = config.vertexBufferLayout; @@ -370,9 +369,9 @@ var SubmitterSpriteGPULayer = new Class({ }); } } - }, + } - setupUniforms: function (drawingContext) + setupUniforms(drawingContext) { var camera = drawingContext.camera; var programManager = this.programManager; @@ -458,9 +457,9 @@ var SubmitterSpriteGPULayer = new Class({ layer.selfShadow.diffuseFlatThreshold, layer.selfShadow.penumbra ); - }, + } - updateRenderOptions: function () + updateRenderOptions() { var programManager = this.programManager; @@ -505,7 +504,7 @@ var SubmitterSpriteGPULayer = new Class({ { programManager.addFeature('SELFSHADOW'); } - }, + } /** * Render a SpriteGPULayer object. @@ -514,7 +513,7 @@ var SubmitterSpriteGPULayer = new Class({ * @since 4.0.0 * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. */ - run: function (drawingContext) + run(drawingContext) { var i; var layer = this.gameObject; @@ -623,6 +622,6 @@ var SubmitterSpriteGPULayer = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = SubmitterSpriteGPULayer; diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterTile.js b/src/renderer/webgl/renderNodes/submitter/SubmitterTile.js index c16034c88c..d989d95160 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterTile.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterTile.js @@ -19,15 +19,14 @@ var SubmitterQuad = require('./SubmitterQuad'); * @param {Phaser.Renderer.WebGL.WebGLRenderer} manager - The WebGLRenderer that owns this Submitter. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} [config] - The configuration object for this Submitter. This is a SubmitterQuad configuration object with the `name` defaulting to `SubmitterTile`. */ -var SubmitterTile = new Class({ - Extends: SubmitterQuad, +var SubmitterTile = class extends SubmitterQuad { - initialize: function SubmitterTile (manager, config) + constructor(manager, config) { - SubmitterQuad.call(this, manager, config); + super(manager, config); this._renderOptions.clampFrame = true; - }, + } /** * The default configuration for this RenderNode. @@ -39,7 +38,7 @@ var SubmitterTile = new Class({ name: 'SubmitterTile', role: 'Submitter', batchHandler: 'BatchHandler' - }, + } /** * Submit data for rendering. @@ -56,7 +55,7 @@ var SubmitterTile = new Class({ * @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} [normalMap] - The normal map texture to use for lighting. If omitted, the normal map texture of the GameObject will be used, or the default normal map texture of the renderer. * @param {number} [normalMapRotation] - The rotation of the normal map texture. If omitted, the rotation of the GameObject will be used. */ - run: function ( + run( drawingContext, gameObject, parentMatrix, @@ -150,6 +149,6 @@ var SubmitterTile = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = SubmitterTile; diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterTileSprite.js b/src/renderer/webgl/renderNodes/submitter/SubmitterTileSprite.js index c20a950437..bc39eb5f6f 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterTileSprite.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterTileSprite.js @@ -30,15 +30,14 @@ var getTint = Utils.getTintAppendFloatAlpha; * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} [config] - The configuration object for this Submitter. This is a SubmitterQuad configuration object with the `name` defaulting to `SubmitterTileSprite`. */ -var SubmitterTileSprite = new Class({ - Extends: SubmitterQuad, +var SubmitterTileSprite = class extends SubmitterQuad { - initialize: function SubmitterTileSprite (manager, config) + constructor(manager, config) { - SubmitterQuad.call(this, manager, config); + super(manager, config); this._renderOptions.wrapFrame = true; - }, + } /** * The default configuration for this RenderNode. @@ -50,7 +49,7 @@ var SubmitterTileSprite = new Class({ name: 'SubmitterTileSprite', role: 'Submitter', batchHandler: 'BatchHandler' - }, + } /** * Submit data for rendering. @@ -67,7 +66,7 @@ var SubmitterTileSprite = new Class({ * @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} [normalMap] - The normal map texture to use for lighting. If omitted, the normal map texture of the GameObject will be used, or the default normal map texture of the renderer. * @param {number} [normalMapRotation] - The rotation of the normal map texture. If omitted, the rotation of the GameObject will be used. */ - run: function ( + run( drawingContext, gameObject, parentMatrix, @@ -164,6 +163,6 @@ var SubmitterTileSprite = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = SubmitterTileSprite; diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterTilemapGPULayer.js b/src/renderer/webgl/renderNodes/submitter/SubmitterTilemapGPULayer.js index 758cd2f2e2..a215b8dcfc 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterTilemapGPULayer.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterTilemapGPULayer.js @@ -35,10 +35,9 @@ var Utils = require('../../Utils'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} [config] - The configuration object for this handler. */ -var SubmitterTilemapGPULayer = new Class({ - Extends: RenderNode, +var SubmitterTilemapGPULayer = class extends RenderNode { - initialize: function SubmitterTilemapGPULayer (manager, config) + constructor(manager, config) { var renderer = manager.renderer; @@ -46,7 +45,7 @@ var SubmitterTilemapGPULayer = new Class({ var name = finalConfig.name; this._completeLayout(finalConfig); - RenderNode.call(this, name, manager); + super(name, manager); /** * The completed configuration object for this RenderNode. @@ -158,7 +157,7 @@ var SubmitterTilemapGPULayer = new Class({ * @private */ this._quad = new Float32Array(8); - }, + } /** * Default configuration of this RenderNode. @@ -196,7 +195,7 @@ var SubmitterTilemapGPULayer = new Class({ } ] } - }, + } /** * Fill out the configuration object with default values where needed. @@ -205,7 +204,7 @@ var SubmitterTilemapGPULayer = new Class({ * @since 4.0.0 * @param {object} config - The configuration object to complete. */ - _completeLayout: function (config) + _completeLayout(config) { // Set up vertex buffer layout. var layoutSource = config.vertexBufferLayout; @@ -243,7 +242,7 @@ var SubmitterTilemapGPULayer = new Class({ }); } } - }, + } /** * Set up uniforms for rendering. @@ -253,7 +252,7 @@ var SubmitterTilemapGPULayer = new Class({ * @param {Phaser.Renderer.WebGL.DrawingContext} drawingContext - The current drawing context. * @param {Phaser.Tilemaps.TilemapGPULayer} tilemapLayer - The TilemapGPULayer being rendered. */ - setupUniforms: function (drawingContext, tilemapLayer) + setupUniforms(drawingContext, tilemapLayer) { var camera = drawingContext.camera; var programManager = this.programManager; @@ -339,7 +338,7 @@ var SubmitterTilemapGPULayer = new Class({ tilemapLayer.selfShadow.diffuseFlatThreshold, tilemapLayer.selfShadow.penumbra ); - }, + } /** * Update render options for a TilemapGPULayer object. @@ -350,7 +349,7 @@ var SubmitterTilemapGPULayer = new Class({ * @since 4.0.0 * @param {Phaser.Tilemaps.TilemapGPULayer} gameObject - The TilemapGPULayer being rendered. */ - updateRenderOptions: function (gameObject) + updateRenderOptions(gameObject) { var programManager = this.programManager; var texture = gameObject.tileset.image; @@ -428,7 +427,7 @@ var SubmitterTilemapGPULayer = new Class({ { programManager.removeFeature('BORDERFILTER'); } - }, + } /** * Render a TilemapGPULayer object. @@ -439,7 +438,7 @@ var SubmitterTilemapGPULayer = new Class({ * @param {Phaser.Tilemaps.TilemapGPULayer} tilemapLayer - The TilemapGPULayer being rendered. * @param {Phaser.GameObjects.Components.TransformMatrix} [parentMatrix] - The parent matrix describing the game object's context. */ - run: function ( + run( drawingContext, tilemapLayer, parentMatrix @@ -580,6 +579,6 @@ var SubmitterTilemapGPULayer = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = SubmitterTilemapGPULayer; diff --git a/src/renderer/webgl/renderNodes/texturer/TexturerImage.js b/src/renderer/webgl/renderNodes/texturer/TexturerImage.js index 5a114787a6..ae974f6097 100644 --- a/src/renderer/webgl/renderNodes/texturer/TexturerImage.js +++ b/src/renderer/webgl/renderNodes/texturer/TexturerImage.js @@ -21,12 +21,11 @@ var RenderNode = require('../RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var TexturerImage = new Class({ - Extends: RenderNode, +var TexturerImage = class extends RenderNode { - initialize: function TexturerImage (manager) + constructor(manager) { - RenderNode.call(this, 'TexturerImage', manager); + super('TexturerImage', manager); /** * The frame data of the GameObject being rendered. @@ -66,7 +65,7 @@ var TexturerImage = new Class({ * @since 4.0.0 */ this.uvSource = null; - }, + } /** * Set this RenderNode to temporarily store the texture data for the given @@ -78,7 +77,7 @@ var TexturerImage = new Class({ * @param {Phaser.GameObjects.Image} gameObject - The GameObject being rendered. * @param {object} [element] - The specific element within the game object. This is used for objects that consist of multiple quads. It is unused here. */ - run: function (drawingContext, gameObject, element) + run(drawingContext, gameObject, element) { this.onRunBegin(drawingContext); @@ -110,6 +109,6 @@ var TexturerImage = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = TexturerImage; diff --git a/src/renderer/webgl/renderNodes/texturer/TexturerTileSprite.js b/src/renderer/webgl/renderNodes/texturer/TexturerTileSprite.js index 1ffad52ea9..df56179573 100644 --- a/src/renderer/webgl/renderNodes/texturer/TexturerTileSprite.js +++ b/src/renderer/webgl/renderNodes/texturer/TexturerTileSprite.js @@ -22,12 +22,11 @@ var RenderNode = require('../RenderNode'); * @extends Phaser.Renderer.WebGL.RenderNodes.RenderNode * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. */ -var TexturerTileSprite = new Class({ - Extends: RenderNode, +var TexturerTileSprite = class extends RenderNode { - initialize: function TexturerTileSprite (manager) + constructor(manager) { - RenderNode.call(this, 'TexturerTileSprite', manager); + super('TexturerTileSprite', manager); /** * The frame data of the GameObject being rendered. @@ -46,7 +45,7 @@ var TexturerTileSprite = new Class({ * @since 4.0.0 */ this.uvMatrix = new TransformMatrix(); - }, + } /** * Set this RenderNode to temporarily store the texture data for the given @@ -58,7 +57,7 @@ var TexturerTileSprite = new Class({ * @param {Phaser.GameObjects.Image} gameObject - The GameObject being rendered. * @param {object} [element] - The specific element within the game object. This is used for objects that consist of multiple quads. It is unused here. */ - run: function (drawingContext, gameObject, element) + run(drawingContext, gameObject, element) { this.onRunBegin(drawingContext); @@ -95,6 +94,6 @@ var TexturerTileSprite = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = TexturerTileSprite; diff --git a/src/renderer/webgl/renderNodes/transformer/TransformerImage.js b/src/renderer/webgl/renderNodes/transformer/TransformerImage.js index bd7e3a0448..f8e33ec199 100644 --- a/src/renderer/webgl/renderNodes/transformer/TransformerImage.js +++ b/src/renderer/webgl/renderNodes/transformer/TransformerImage.js @@ -21,14 +21,13 @@ var RenderNode = require('../RenderNode'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {object} [config] - The configuration object for this RenderNode. */ -var TransformerImage = new Class({ - Extends: RenderNode, +var TransformerImage = class extends RenderNode { - initialize: function TransformerImage (manager, config) + constructor(manager, config) { config = Merge(config || {}, this.defaultConfig); - RenderNode.call(this, config.name, manager); + super(config.name, manager); /** * The matrix used to store the final quad data for rendering. @@ -67,12 +66,12 @@ var TransformerImage = new Class({ * @private */ this._calcMatrix = new TransformMatrix(); - }, + } defaultConfig: { name: 'TransformerImage', role: 'Transformer' - }, + } /** * Stores the transform data for rendering. @@ -85,7 +84,7 @@ var TransformerImage = new Class({ * @param {Phaser.GameObjects.Components.TransformMatrix} [parentMatrix] - This transform matrix is defined if the game object is nested. * @param {object} [element] - The specific element within the game object. This is used for objects that consist of multiple quads. It is unused here. */ - run: function (drawingContext, gameObject, texturerNode, parentMatrix, element) + run(drawingContext, gameObject, texturerNode, parentMatrix, element) { this.onRunBegin(drawingContext); @@ -163,6 +162,6 @@ var TransformerImage = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = TransformerImage; diff --git a/src/renderer/webgl/renderNodes/transformer/TransformerStamp.js b/src/renderer/webgl/renderNodes/transformer/TransformerStamp.js index 693d4ced48..19cc25a7a3 100644 --- a/src/renderer/webgl/renderNodes/transformer/TransformerStamp.js +++ b/src/renderer/webgl/renderNodes/transformer/TransformerStamp.js @@ -24,15 +24,13 @@ var RenderNode = require('../RenderNode'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {object} [config] - The configuration object for this RenderNode. */ -var TransformerStamp = new Class({ +var TransformerStamp = class extends RenderNode { - Extends: RenderNode, - - initialize: function TransformerStamp (manager, config) + constructor(manager, config) { config = Merge(config || {}, this.defaultConfig); - RenderNode.call(this, config.name, manager); + super(config.name, manager); /** * The matrix used internally to compute sprite transforms. @@ -61,12 +59,12 @@ var TransformerStamp = new Class({ * @since 4.0.0 */ this.onlyTranslate = false; - }, + } defaultConfig: { name: 'TransformerStamp', role: 'Transformer' - }, + } /** * Stores the transform data for rendering. @@ -79,7 +77,7 @@ var TransformerStamp = new Class({ * @param {Phaser.GameObjects.Components.TransformMatrix} [parentMatrix] - This transform matrix is defined if the game object is nested. It is unused here. * @param {object} [element] - The specific element within the game object. This is used for objects that consist of multiple quads. It is unused here. */ - run: function (drawingContext, gameObject, texturerNode, parentMatrix, element) + run(drawingContext, gameObject, texturerNode, parentMatrix, element) { this.onRunBegin(drawingContext); @@ -141,6 +139,6 @@ var TransformerStamp = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = TransformerStamp; diff --git a/src/renderer/webgl/renderNodes/transformer/TransformerTile.js b/src/renderer/webgl/renderNodes/transformer/TransformerTile.js index 81fe13fc50..a1fc5dd3bf 100644 --- a/src/renderer/webgl/renderNodes/transformer/TransformerTile.js +++ b/src/renderer/webgl/renderNodes/transformer/TransformerTile.js @@ -19,18 +19,17 @@ var TransformerImage = require('./TransformerImage'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {object} [config] - The configuration object for this RenderNode. */ -var TransformerTile = new Class({ - Extends: TransformerImage, +var TransformerTile = class extends TransformerImage { - initialize: function TransformerTile (manager, config) + constructor(manager, config) { - TransformerImage.call(this, manager, config); - }, + super(manager, config); + } defaultConfig: { name: 'TransformerTile', role: 'Transformer' - }, + } /** * Stores the transform data for rendering. @@ -43,7 +42,7 @@ var TransformerTile = new Class({ * @param {Phaser.GameObjects.Components.TransformMatrix} [parentMatrix] - This transform matrix is defined if the game object is nested. * @param {object} [element] - The specific element within the game object. This is used for objects that consist of multiple quads. It is unused here. */ - run: function (drawingContext, gameObject, texturerNode, parentMatrix, element) + run(drawingContext, gameObject, texturerNode, parentMatrix, element) { this.onRunBegin(drawingContext); @@ -125,6 +124,6 @@ var TransformerTile = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = TransformerTile; diff --git a/src/renderer/webgl/renderNodes/transformer/TransformerTileSprite.js b/src/renderer/webgl/renderNodes/transformer/TransformerTileSprite.js index 4f6ad6decd..a1a70fa004 100644 --- a/src/renderer/webgl/renderNodes/transformer/TransformerTileSprite.js +++ b/src/renderer/webgl/renderNodes/transformer/TransformerTileSprite.js @@ -19,18 +19,17 @@ var TransformerImage = require('./TransformerImage.js'); * @param {Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager} manager - The manager that owns this RenderNode. * @param {object} [config] - The configuration object for this RenderNode. */ -var TransformerTileSprite = new Class({ - Extends: TransformerImage, +var TransformerTileSprite = class extends TransformerImage { - initialize: function TransformerTileSprite (manager, config) + constructor(manager, config) { - TransformerImage.call(this, manager, config); - }, + super(manager, config); + } defaultConfig: { name: 'TransformerTileSprite', role: 'Transformer' - }, + } /** * Stores the transform data for rendering. @@ -43,7 +42,7 @@ var TransformerTileSprite = new Class({ * @param {Phaser.GameObjects.Components.TransformMatrix} [parentMatrix] - This transform matrix is defined if the game object is nested. * @param {object} [element] - The specific element within the game object. This is used for objects that consist of multiple quads. It is unused here. */ - run: function (drawingContext, gameObject, texturerNode, parentMatrix, element) + run(drawingContext, gameObject, texturerNode, parentMatrix, element) { this.onRunBegin(drawingContext); @@ -117,6 +116,6 @@ var TransformerTileSprite = new Class({ this.onRunEnd(drawingContext); } -}); +}; module.exports = TransformerTileSprite; diff --git a/src/renderer/webgl/wrappers/WebGLBufferWrapper.js b/src/renderer/webgl/wrappers/WebGLBufferWrapper.js index faffd7fe13..3c65d00459 100644 --- a/src/renderer/webgl/wrappers/WebGLBufferWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLBufferWrapper.js @@ -25,11 +25,9 @@ var Class = require('../../../utils/Class'); * @param {GLenum} bufferType - The type of the buffer being created. * @param {GLenum} bufferUsage - The usage of the buffer being created. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW. */ -var WebGLBufferWrapper = new Class({ +var WebGLBufferWrapper = class { - initialize: - - function WebGLBufferWrapper (renderer, dataBuffer, bufferType, bufferUsage) + constructor(renderer, dataBuffer, bufferType, bufferUsage) { /** * The WebGLRenderer instance that owns this wrapper. @@ -134,7 +132,7 @@ var WebGLBufferWrapper = new Class({ this.createViews(); this.createResource(); - }, + } /** * Creates a WebGLBuffer for this WebGLBufferWrapper. @@ -145,7 +143,7 @@ var WebGLBufferWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper#createResource * @since 3.80.0 */ - createResource: function () + createResource() { var gl = this.renderer.gl; @@ -157,7 +155,7 @@ var WebGLBufferWrapper = new Class({ this.bind(); gl.bufferData(bufferType, this.dataBuffer, this.bufferUsage); this.bind(true); - }, + } /** * Binds this WebGLBufferWrapper to the current WebGLRenderingContext. @@ -167,7 +165,7 @@ var WebGLBufferWrapper = new Class({ * @since 4.0.0 * @param {boolean} [unbind=false] - Whether to unbind the buffer instead. */ - bind: function (unbind) + bind(unbind) { var gl = this.renderer.gl; var bufferType = this.bufferType; @@ -185,7 +183,7 @@ var WebGLBufferWrapper = new Class({ bindings: { elementArrayBuffer: buffer } }); } - }, + } /** * Updates the data in this WebGLBufferWrapper. @@ -197,7 +195,7 @@ var WebGLBufferWrapper = new Class({ * @param {number} [bytes] - The number of bytes to update in the buffer. If not specified, the entire buffer will be updated. * @param {number} [offset=0] - The offset into the buffer to start updating data at. */ - update: function (bytes, offset) + update(bytes, offset) { var gl = this.renderer.gl; @@ -224,7 +222,7 @@ var WebGLBufferWrapper = new Class({ this.viewU8.subarray(offset, offset + bytes) ); } - }, + } /** * Resizes the dataBuffer of this WebGLBufferWrapper. @@ -236,7 +234,7 @@ var WebGLBufferWrapper = new Class({ * @since 4.0.0 * @param {number} bytes - The new size of the buffer in bytes. */ - resize: function (bytes) + resize(bytes) { var gl = this.renderer.gl; @@ -246,7 +244,7 @@ var WebGLBufferWrapper = new Class({ this.bind(); gl.bufferData(this.bufferType, this.dataBuffer, this.bufferUsage); - }, + } /** * Creates the views into the dataBuffer. @@ -256,7 +254,7 @@ var WebGLBufferWrapper = new Class({ * @since 4.0.0 * @private */ - createViews: function () + createViews() { var dataBuffer = this.dataBuffer; @@ -279,7 +277,7 @@ var WebGLBufferWrapper = new Class({ { this.viewU32 = new Uint32Array(dataBuffer); } - }, + } /** * Remove this WebGLBufferWrapper from the GL context. @@ -287,7 +285,7 @@ var WebGLBufferWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper#destroy * @since 3.80.0 */ - destroy: function () + destroy() { this.renderer.gl.deleteBuffer(this.webGLBuffer); this.webGLBuffer = null; @@ -298,6 +296,6 @@ var WebGLBufferWrapper = new Class({ this.viewU32 = null; this.renderer = null; } -}); +}; module.exports = WebGLBufferWrapper; diff --git a/src/renderer/webgl/wrappers/WebGLFramebufferWrapper.js b/src/renderer/webgl/wrappers/WebGLFramebufferWrapper.js index 71c4cd37ca..fb0fc0f054 100644 --- a/src/renderer/webgl/wrappers/WebGLFramebufferWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLFramebufferWrapper.js @@ -47,11 +47,9 @@ var errors = { * @param {boolean} [addStencilBuffer=false] - Whether to add a stencil buffer to the framebuffer. If the canvas is used as the color attachment, this will be ignored. * @param {boolean} [addDepthBuffer=false] - Whether to add a depth buffer to the framebuffer. If depth and stencil are both provided, they will be combined into a single depth-stencil buffer. If the canvas is used as the color attachment, this will be ignored. */ -var WebGLFramebufferWrapper = new Class({ +var WebGLFramebufferWrapper = class { - initialize: - - function WebGLFramebufferWrapper (renderer, colorAttachments, addStencilBuffer, addDepthBuffer) + constructor(renderer, colorAttachments, addStencilBuffer, addDepthBuffer) { var gl = renderer.gl; @@ -187,7 +185,7 @@ var WebGLFramebufferWrapper = new Class({ } this.createResource(); - }, + } /** * Creates a WebGLFramebuffer from the given parameters. @@ -198,7 +196,7 @@ var WebGLFramebufferWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLFramebufferWrapper#createResource * @since 3.80.0 */ - createResource: function () + createResource() { if (this.useCanvas) { return; } @@ -271,7 +269,7 @@ var WebGLFramebufferWrapper = new Class({ attachment.renderbuffer = renderbuffer; } } - }, + } /** * Resizes the attachments of this WebGLFramebufferWrapper. @@ -281,7 +279,7 @@ var WebGLFramebufferWrapper = new Class({ * @param {number} width - The new width of the framebuffer. * @param {number} height - The new height of the framebuffer. */ - resize: function (width, height) + resize(width, height) { if (this.useCanvas) { @@ -294,7 +292,7 @@ var WebGLFramebufferWrapper = new Class({ this.renderTexture.resize(width, height); this.createResource(); - }, + } /** * Destroys this WebGLFramebufferWrapper. @@ -302,7 +300,7 @@ var WebGLFramebufferWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLFramebufferWrapper#destroy * @since 3.80.0 */ - destroy: function () + destroy() { if (this.renderer === null) { @@ -348,6 +346,6 @@ var WebGLFramebufferWrapper = new Class({ this.webGLFramebuffer = null; this.renderer = null; } -}); +}; module.exports = WebGLFramebufferWrapper; diff --git a/src/renderer/webgl/wrappers/WebGLGlobalWrapper.js b/src/renderer/webgl/wrappers/WebGLGlobalWrapper.js index 3d083838c9..ee16347da2 100644 --- a/src/renderer/webgl/wrappers/WebGLGlobalWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLGlobalWrapper.js @@ -18,11 +18,9 @@ var WebGLGlobalParametersFactory = require('../parameters/WebGLGlobalParametersF * * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The WebGLRenderer to create the WebGLGlobalWrapper for. */ -var WebGLGlobalWrapper = new Class({ +var WebGLGlobalWrapper = class { - initialize: - - function WebGLGlobalWrapper (renderer) + constructor(renderer) { /** * The WebGLRenderer this WebGLGlobalWrapper is associated with. @@ -41,7 +39,7 @@ var WebGLGlobalWrapper = new Class({ * @since 4.0.0 */ this.state = WebGLGlobalParametersFactory.getDefault(renderer); - }, + } /** * Sets the global WebGL state. Parameters are updated on the @@ -62,7 +60,7 @@ var WebGLGlobalWrapper = new Class({ * Otherwise, it will be set first. This is useful when performing state * changes that will affect a VAO, such as `bindings.elementArrayBuffer`. */ - update: function (state, force, vaoLast) + update(state, force, vaoLast) { if (state === undefined) { @@ -124,7 +122,7 @@ var WebGLGlobalWrapper = new Class({ { this.updateVAO(state, force); } - }, + } /** * Updates the bindings state. @@ -134,7 +132,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBindings: function (state, force) + updateBindings(state, force) { var bindings = state.bindings; @@ -162,7 +160,7 @@ var WebGLGlobalWrapper = new Class({ { this.updateBindingsRenderbuffer(state, force); } - }, + } /** * Updates the active texture unit state. @@ -172,7 +170,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBindingsActiveTexture: function (state, force) + updateBindingsActiveTexture(state, force) { var activeTexture = state.bindings.activeTexture; @@ -187,7 +185,7 @@ var WebGLGlobalWrapper = new Class({ var gl = this.renderer.gl; gl.activeTexture(gl.TEXTURE0 + activeTexture); } - }, + } /** * Updates the vertex array buffer state. @@ -197,7 +195,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBindingsArrayBuffer: function (state, force) + updateBindingsArrayBuffer(state, force) { var arrayBuffer = state.bindings.arrayBuffer; var gl = this.renderer.gl; @@ -220,7 +218,7 @@ var WebGLGlobalWrapper = new Class({ var webGLBuffer = arrayBuffer ? arrayBuffer.webGLBuffer : null; gl.bindBuffer(gl.ARRAY_BUFFER, webGLBuffer); } - }, + } /** * Updates the index array buffer state. @@ -230,7 +228,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBindingsElementArrayBuffer: function (state, force) + updateBindingsElementArrayBuffer(state, force) { var elementArrayBuffer = state.bindings.elementArrayBuffer; var gl = this.renderer.gl; @@ -253,7 +251,7 @@ var WebGLGlobalWrapper = new Class({ var webGLBuffer = elementArrayBuffer ? elementArrayBuffer.webGLBuffer : null; gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, webGLBuffer); } - }, + } /** * Updates the framebuffer state. @@ -263,7 +261,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBindingsFramebuffer: function (state, force) + updateBindingsFramebuffer(state, force) { var framebuffer = state.bindings.framebuffer; @@ -279,7 +277,7 @@ var WebGLGlobalWrapper = new Class({ var webGLFramebuffer = framebuffer ? framebuffer.webGLFramebuffer : null; gl.bindFramebuffer(gl.FRAMEBUFFER, webGLFramebuffer); } - }, + } /** * Updates the program state. @@ -289,7 +287,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBindingsProgram: function (state, force) + updateBindingsProgram(state, force) { var program = state.bindings.program; @@ -304,7 +302,7 @@ var WebGLGlobalWrapper = new Class({ var webGLProgram = program ? program.webGLProgram : null; this.renderer.gl.useProgram(webGLProgram); } - }, + } /** * Updates the renderbuffer state. @@ -314,7 +312,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBindingsRenderbuffer: function (state, force) + updateBindingsRenderbuffer(state, force) { var renderbuffer = state.bindings.renderbuffer; @@ -330,7 +328,7 @@ var WebGLGlobalWrapper = new Class({ var webGLRenderbuffer = renderbuffer || null; gl.bindRenderbuffer(gl.RENDERBUFFER, webGLRenderbuffer); } - }, + } /** * Updates the blend state. @@ -340,7 +338,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBlend: function (state, force) + updateBlend(state, force) { var blend = state.blend; if (blend.enabled !== undefined) @@ -359,7 +357,7 @@ var WebGLGlobalWrapper = new Class({ { this.updateBlendFunc(state, force); } - }, + } /** * Updates the blend color. @@ -369,7 +367,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBlendColor: function (state, force) + updateBlendColor(state, force) { var color = state.blend.color; var r = color[0]; @@ -390,7 +388,7 @@ var WebGLGlobalWrapper = new Class({ { this.renderer.gl.blendColor(r, g, b, a); } - }, + } /** * Updates the blend enabled state. @@ -400,7 +398,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBlendEnabled: function (state, force) + updateBlendEnabled(state, force) { var enabled = state.blend.enabled; @@ -422,7 +420,7 @@ var WebGLGlobalWrapper = new Class({ gl.disable(gl.BLEND); } } - }, + } /** * Updates the blend equation state. @@ -434,7 +432,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBlendEquation: function (state, force) + updateBlendEquation(state, force) { var equation = state.blend.equation; @@ -449,7 +447,7 @@ var WebGLGlobalWrapper = new Class({ { this.renderer.gl.blendEquationSeparate(equation[0], equation[1]); } - }, + } /** * Updates the blend function state. @@ -461,7 +459,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateBlendFunc: function (state, force) + updateBlendFunc(state, force) { var func = state.blend.func; @@ -479,7 +477,7 @@ var WebGLGlobalWrapper = new Class({ { this.renderer.gl.blendFuncSeparate(func[0], func[1], func[2], func[3]); } - }, + } /** * Updates the color clear value. @@ -489,7 +487,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateColorClearValue: function (state, force) + updateColorClearValue(state, force) { var colorClearValue = state.colorClearValue; var r = colorClearValue[0]; @@ -511,7 +509,7 @@ var WebGLGlobalWrapper = new Class({ { this.renderer.gl.clearColor(r, g, b, a); } - }, + } /** * Updates the color writemask. @@ -521,7 +519,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateColorWritemask: function (state, force) + updateColorWritemask(state, force) { var colorWritemask = state.colorWritemask; var r = colorWritemask[0]; @@ -542,7 +540,7 @@ var WebGLGlobalWrapper = new Class({ { this.renderer.gl.colorMask(r, g, b, a); } - }, + } /** * Updates the cull face state. @@ -552,7 +550,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateCullFace: function (state, force) + updateCullFace(state, force) { var cullFace = !!state.cullFace; @@ -574,7 +572,7 @@ var WebGLGlobalWrapper = new Class({ gl.disable(gl.CULL_FACE); } } - }, + } /** * Updates the depth test state. @@ -584,7 +582,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateDepthTest: function (state, force) + updateDepthTest(state, force) { var depthTest = !!state.depthTest; @@ -606,7 +604,7 @@ var WebGLGlobalWrapper = new Class({ gl.disable(gl.DEPTH_TEST); } } - }, + } /** * Updates the scissor state. @@ -616,7 +614,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateScissor: function (state, force) + updateScissor(state, force) { var scissor = state.scissor; if (scissor.enable !== undefined) @@ -627,7 +625,7 @@ var WebGLGlobalWrapper = new Class({ { this.updateScissorBox(state, force); } - }, + } /** * Updates the scissor enabled state. @@ -637,7 +635,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateScissorEnabled: function (state, force) + updateScissorEnabled(state, force) { var enable = state.scissor.enable; @@ -659,7 +657,7 @@ var WebGLGlobalWrapper = new Class({ gl.disable(gl.SCISSOR_TEST); } } - }, + } /** * Updates the scissor box state. @@ -669,7 +667,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateScissorBox: function (state, force) + updateScissorBox(state, force) { var scissorBox = state.scissor.box; var x = scissorBox[0]; @@ -695,7 +693,7 @@ var WebGLGlobalWrapper = new Class({ height ); } - }, + } /** * Updates the stencil state. @@ -705,7 +703,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateStencil: function (state, force) + updateStencil(state, force) { var stencil = state.stencil; if (stencil.clear !== undefined) @@ -724,7 +722,7 @@ var WebGLGlobalWrapper = new Class({ { this.updateStencilOp(state, force); } - }, + } /** * Updates the stencil clear state. @@ -734,7 +732,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateStencilClear: function (state, force) + updateStencilClear(state, force) { var clear = state.stencil.clear; @@ -748,7 +746,7 @@ var WebGLGlobalWrapper = new Class({ { this.renderer.gl.clearStencil(clear); } - }, + } /** * Updates the stencil enabled state. @@ -758,7 +756,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateStencilEnabled: function (state, force) + updateStencilEnabled(state, force) { var enabled = state.stencil.enabled; @@ -780,7 +778,7 @@ var WebGLGlobalWrapper = new Class({ gl.disable(gl.STENCIL_TEST); } } - }, + } /** * Updates the stencil function state. @@ -790,7 +788,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateStencilFunc: function (state, force) + updateStencilFunc(state, force) { var func = state.stencil.func; @@ -807,7 +805,7 @@ var WebGLGlobalWrapper = new Class({ var gl = this.renderer.gl; gl.stencilFunc(func.func, func.ref, func.mask); } - }, + } /** * Updates the stencil operation state. @@ -817,7 +815,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateStencilOp: function (state, force) + updateStencilOp(state, force) { var op = state.stencil.op; @@ -834,7 +832,7 @@ var WebGLGlobalWrapper = new Class({ var gl = this.renderer.gl; gl.stencilOp(op.fail, op.zfail, op.zpass); } - }, + } /** * Updates the texturing state, which takes effect when creating a texture. @@ -845,7 +843,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateTexturing: function (state, force) + updateTexturing(state, force) { var texturing = state.texturing; if (texturing.flipY !== undefined) @@ -856,7 +854,7 @@ var WebGLGlobalWrapper = new Class({ { this.updateTexturingPremultiplyAlpha(state, force); } - }, + } /** * Updates the texture flipY state. @@ -866,7 +864,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateTexturingFlipY: function (state, force) + updateTexturingFlipY(state, force) { var flipY = state.texturing.flipY; @@ -881,7 +879,7 @@ var WebGLGlobalWrapper = new Class({ var gl = this.renderer.gl; gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); } - }, + } /** * Updates the texture premultiplyAlpha state. @@ -891,7 +889,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateTexturingPremultiplyAlpha: function (state, force) + updateTexturingPremultiplyAlpha(state, force) { var premultiplyAlpha = state.texturing.premultiplyAlpha; @@ -906,7 +904,7 @@ var WebGLGlobalWrapper = new Class({ var gl = this.renderer.gl; gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiplyAlpha); } - }, + } /** * Updates the vertex array object state. @@ -922,7 +920,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateVAO: function (state, force) + updateVAO(state, force) { var vao = state.vao; @@ -945,7 +943,7 @@ var WebGLGlobalWrapper = new Class({ extVAO.bindVertexArrayOES(null); } } - }, + } /** * Updates the viewport state. @@ -955,7 +953,7 @@ var WebGLGlobalWrapper = new Class({ * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set. * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state. */ - updateViewport: function (state, force) + updateViewport(state, force) { var viewport = state.viewport; var x = viewport[0]; @@ -977,6 +975,6 @@ var WebGLGlobalWrapper = new Class({ this.renderer.gl.viewport(x, y, width, height); } } -}); +}; module.exports = WebGLGlobalWrapper; diff --git a/src/renderer/webgl/wrappers/WebGLProgramWrapper.js b/src/renderer/webgl/wrappers/WebGLProgramWrapper.js index a6fd1e2dfb..157e4daeb7 100644 --- a/src/renderer/webgl/wrappers/WebGLProgramWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLProgramWrapper.js @@ -40,11 +40,9 @@ function isDifferent (a, b) * @param {string} vertexSource - The vertex shader source code as a string. * @param {string} fragmentShader - The fragment shader source code as a string. */ -var WebGLProgramWrapper = new Class({ +var WebGLProgramWrapper = class { - initialize: - - function WebGLProgramWrapper (renderer, vertexSource, fragmentSource) + constructor(renderer, vertexSource, fragmentSource) { /** * The WebGLRenderer instance that owns this wrapper. @@ -209,7 +207,7 @@ var WebGLProgramWrapper = new Class({ this.uniformRequests = new Map(); this.createResource(); - }, + } /** * Creates a WebGLProgram from the given vertex and fragment shaders. @@ -221,7 +219,7 @@ var WebGLProgramWrapper = new Class({ * @throws {Error} If the shaders failed to compile or link. * @since 3.80.0 */ - createResource: function () + createResource() { var renderer = this.renderer; var gl = renderer.gl; @@ -275,7 +273,7 @@ var WebGLProgramWrapper = new Class({ { this._completeProgram(); } - }, + } /** * Poll shader compilation status, and complete the program if it is ready. @@ -285,7 +283,7 @@ var WebGLProgramWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper#checkParallelCompile * @since 4.0.0 */ - checkParallelCompile: function () + checkParallelCompile() { var renderer = this.renderer; var gl = renderer.gl; @@ -297,7 +295,7 @@ var WebGLProgramWrapper = new Class({ } this._completeProgram(); - }, + } /** * Complete the program after the shaders have compiled. @@ -308,7 +306,7 @@ var WebGLProgramWrapper = new Class({ * @private * @since 4.0.0 */ - _completeProgram: function () + _completeProgram() { var program = this.webGLProgram; var renderer = this.renderer; @@ -339,7 +337,7 @@ var WebGLProgramWrapper = new Class({ this.compileTimeMs = performance.now() - this._compileStartTime; this.compiling = false; - }, + } /** * Set up the attributes and uniforms for this program. @@ -349,7 +347,7 @@ var WebGLProgramWrapper = new Class({ * @private * @since 4.0.0 */ - _setupAttributesAndUniforms: function () + _setupAttributesAndUniforms() { var program = this.webGLProgram; var renderer = this.renderer; @@ -409,7 +407,7 @@ var WebGLProgramWrapper = new Class({ value: initialValue }); } - }, + } /** * Set a uniform value for this WebGLProgram. @@ -423,10 +421,10 @@ var WebGLProgramWrapper = new Class({ * @param {string} name - The name of the uniform. * @param {number|number[]|Int32Array|Float32Array} value - The value to set. */ - setUniform: function (name, value) + setUniform(name, value) { this.uniformRequests.set(name, value); - }, + } /** * Set this program as the active program in the WebGL context. @@ -436,14 +434,14 @@ var WebGLProgramWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper#bind * @since 4.0.0 */ - bind: function () + bind() { this.renderer.glWrapper.updateBindingsProgram(this.glState); this.uniformRequests.each(this._processUniformRequest.bind(this)); this.uniformRequests.clear(); - }, + } /** * Process a request to update a uniform value. @@ -463,7 +461,7 @@ var WebGLProgramWrapper = new Class({ * @param {string} name - The name of the uniform. * @param {number|number[]|Int32Array|Float32Array} value - The value to set. */ - _processUniformRequest: function (name, value) + _processUniformRequest(name, value) { var renderer = this.renderer; var gl = renderer.gl; @@ -527,7 +525,7 @@ var WebGLProgramWrapper = new Class({ break; } } - }, + } /** * Remove this WebGLProgram from the GL context. @@ -535,7 +533,7 @@ var WebGLProgramWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper#destroy * @since 3.80.0 */ - destroy: function () + destroy() { if (!this.webGLProgram) { @@ -572,6 +570,6 @@ var WebGLProgramWrapper = new Class({ this.webGLProgram = null; this.renderer = null; } -}); +}; module.exports = WebGLProgramWrapper; diff --git a/src/renderer/webgl/wrappers/WebGLShaderSetterWrapper.js b/src/renderer/webgl/wrappers/WebGLShaderSetterWrapper.js index c5bb9c8ff0..9d57ee2b30 100644 --- a/src/renderer/webgl/wrappers/WebGLShaderSetterWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLShaderSetterWrapper.js @@ -19,8 +19,8 @@ var Class = require('../../../utils/Class'); * * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The WebGLRenderer instance that owns this WebGLShaderSetterWrapper. */ -var WebGLShaderSetterWrapper = new Class({ - initialize: function WebGLShaderSetterWrapper (renderer) +var WebGLShaderSetterWrapper = class { + constructor(renderer) { var gl = renderer.gl; @@ -233,6 +233,6 @@ var WebGLShaderSetterWrapper = new Class({ } }; } -}); +}; module.exports = WebGLShaderSetterWrapper; diff --git a/src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js b/src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js index a7a9c41ccb..a0d6149f56 100644 --- a/src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js @@ -18,11 +18,9 @@ var Class = require('../../../utils/Class'); * @since 4.0.0 * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The WebGLRenderer instance that owns this wrapper. */ -var WebGLTextureUnitsWrapper = new Class({ +var WebGLTextureUnitsWrapper = class { - initialize: - - function WebGLTextureUnitsWrapper (renderer) + constructor(renderer) { /** * The WebGLRenderer instance that owns this wrapper. @@ -53,7 +51,7 @@ var WebGLTextureUnitsWrapper = new Class({ this.unitIndices = []; this.init(); - }, + } /** * Initializes the texture units to `null`. The active texture unit @@ -67,7 +65,7 @@ var WebGLTextureUnitsWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLTextureUnitsWrapper#init * @since 4.0.0 */ - init: function () + init() { var gl = this.renderer.gl; @@ -92,7 +90,7 @@ var WebGLTextureUnitsWrapper = new Class({ this.unitIndices[unit] = unit; } gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([ 0, 0, 255, 255 ])); - }, + } /** * Binds a texture to a texture unit. @@ -109,7 +107,7 @@ var WebGLTextureUnitsWrapper = new Class({ * @param {boolean} [force=false] - If true, it will bind the texture even if it is already bound. * @param {boolean} [forceActive=true] - If true, it will change the active texture unit to the given unit even if it is already active. Otherwise, it will only change the active texture unit if it is not already active. */ - bind: function (texture, unit, force, forceActive) + bind(texture, unit, force, forceActive) { var needsBind = this.units[unit] !== texture; if (force || (forceActive !== false) || needsBind) @@ -126,7 +124,7 @@ var WebGLTextureUnitsWrapper = new Class({ var glTexture = texture ? texture.webGLTexture : null; var gl = this.renderer.gl; gl.bindTexture(gl.TEXTURE_2D, glTexture); - }, + } /** * Set specific texture units to specific textures. @@ -138,7 +136,7 @@ var WebGLTextureUnitsWrapper = new Class({ * @param {Array} textures - The textures to bind. Null values will be unbound. Undefined values will be skipped. * @param {boolean} [force=false] - If true, it will bind all textures, even if they are already bound. */ - bindUnits: function (textures, force) + bindUnits(textures, force) { var length = Math.min(textures.length, this.renderer.maxTextures); for (var i = length - 1; i >= 0; i--) @@ -148,7 +146,7 @@ var WebGLTextureUnitsWrapper = new Class({ this.bind(textures[i], i, force, false); } } - }, + } /** * Unbinds all textures from all texture units. @@ -157,13 +155,13 @@ var WebGLTextureUnitsWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLTextureUnitsWrapper#unbindAllUnits * @since 4.0.0 */ - unbindAllUnits: function () + unbindAllUnits() { for (var i = this.units.length - 1; i >= 0; i--) { this.bind(null, i, true, false); } } -}); +}; module.exports = WebGLTextureUnitsWrapper; diff --git a/src/renderer/webgl/wrappers/WebGLTextureWrapper.js b/src/renderer/webgl/wrappers/WebGLTextureWrapper.js index b8c9510de3..b854d51a4e 100644 --- a/src/renderer/webgl/wrappers/WebGLTextureWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLTextureWrapper.js @@ -36,11 +36,9 @@ var IsSizePowerOfTwo = require('../../../math/pow2/IsSizePowerOfTwo'); * @param {boolean} [forceSize=false] - If `true` it will use the width and height passed to this method, regardless of the pixels dimension. * @param {boolean} [flipY=true] - Sets the `UNPACK_FLIP_Y_WEBGL` flag the WebGL Texture uses during upload. */ -var WebGLTextureWrapper = new Class({ +var WebGLTextureWrapper = class { - initialize: - - function WebGLTextureWrapper (renderer, mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma, forceSize, flipY) + constructor(renderer, mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma, forceSize, flipY) { if (flipY === undefined) { flipY = true; } @@ -213,7 +211,7 @@ var WebGLTextureWrapper = new Class({ this.batchUnit = -1; this.createResource(); - }, + } /** * Creates a WebGLTexture from the given parameters. @@ -224,7 +222,7 @@ var WebGLTextureWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper#createResource * @since 3.80.0 */ - createResource: function () + createResource() { var gl = this.renderer.gl; @@ -252,7 +250,7 @@ var WebGLTextureWrapper = new Class({ this.webGLTexture = texture; this._processTexture(); - }, + } /** * Resizes the WebGLTexture to the new dimensions. @@ -263,7 +261,7 @@ var WebGLTextureWrapper = new Class({ * @param {number} width - The new width of the WebGLTexture. * @param {number} height - The new height of the WebGLTexture. */ - resize: function (width, height) + resize(width, height) { if (this.width === width && this.height === height) { @@ -274,7 +272,7 @@ var WebGLTextureWrapper = new Class({ this.height = height; this._processTexture(); - }, + } /** * Updates the WebGLTexture from an updated source. @@ -297,7 +295,7 @@ var WebGLTextureWrapper = new Class({ * @param {number} magFilter - The new magnification filter for the WebGLTexture. * @param {number} format - The new format for the WebGLTexture. */ - update: function (source, width, height, flipY, wrapS, wrapT, minFilter, magFilter, format) + update(source, width, height, flipY, wrapS, wrapT, minFilter, magFilter, format) { if (width === 0 || height === 0) { @@ -316,7 +314,7 @@ var WebGLTextureWrapper = new Class({ this.format = format; this._processTexture(); - }, + } /** * Set all parameters of this WebGLTexture per the stored values. @@ -326,7 +324,7 @@ var WebGLTextureWrapper = new Class({ * @since 4.0.0 * @ignore */ - _processTexture: function () + _processTexture() { var gl = this.renderer.gl; @@ -392,7 +390,7 @@ var WebGLTextureWrapper = new Class({ { gl.generateMipmap(gl.TEXTURE_2D); } - }, + } /** * The `__SPECTOR_Metadata` property of the `WebGLTexture`, @@ -402,22 +400,20 @@ var WebGLTextureWrapper = new Class({ * @type {object} * @since 3.80.0 */ - spectorMetadata: { - get: function () - { - return this.__SPECTOR_Metadata; - }, + get spectorMetadata() + { + return this.__SPECTOR_Metadata; + } - set: function (value) - { - // eslint-disable-next-line camelcase - this.__SPECTOR_Metadata = value; + set spectorMetadata(value) + { + // eslint-disable-next-line camelcase + this.__SPECTOR_Metadata = value; - // eslint-disable-next-line camelcase - this.webGLTexture.__SPECTOR_Metadata = value; - } - }, + // eslint-disable-next-line camelcase + this.webGLTexture.__SPECTOR_Metadata = value; + } /** * Deletes the WebGLTexture from the GPU, if it has not been already. @@ -425,7 +421,7 @@ var WebGLTextureWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper#destroy * @since 3.80.0 */ - destroy: function () + destroy() { if (this.webGLTexture === null) { @@ -442,6 +438,6 @@ var WebGLTextureWrapper = new Class({ this.webGLTexture = null; this.renderer = null; } -}); +}; module.exports = WebGLTextureWrapper; diff --git a/src/renderer/webgl/wrappers/WebGLVAOWrapper.js b/src/renderer/webgl/wrappers/WebGLVAOWrapper.js index 2fca472847..e808fff096 100644 --- a/src/renderer/webgl/wrappers/WebGLVAOWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLVAOWrapper.js @@ -23,8 +23,8 @@ var Class = require('../../../utils/Class'); * @param {?Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper} indexBuffer - The index buffer used in this VAO, if any. * @param {Phaser.Renderer.WebGL.Wrappers.WebGLVertexBufferLayoutWrapper[]} attributeBufferLayouts - The vertex buffers containing attribute data for this VAO, alongside the relevant attribute layout. */ -var WebGLVAOWrapper = new Class({ - initialize: function WebGLVAOWrapper (renderer, program, indexBuffer, attributeBufferLayouts) +var WebGLVAOWrapper = class { + constructor(renderer, program, indexBuffer, attributeBufferLayouts) { /** * The WebGLRenderer instance that owns this wrapper. @@ -90,7 +90,7 @@ var WebGLVAOWrapper = new Class({ }; this.createResource(); - }, + } /** * Creates a new WebGLVertexArrayObject. @@ -98,7 +98,7 @@ var WebGLVAOWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLVAOWrapper#createResource * @since 4.0.0 */ - createResource: function () + createResource() { var gl = this.renderer.gl; var extVAO = this.renderer.vaoExtension; @@ -197,7 +197,7 @@ var WebGLVAOWrapper = new Class({ elementArrayBuffer: null } }); - }, + } /** * Binds this WebGLVAOWrapper to the current WebGLRenderingContext. @@ -205,10 +205,10 @@ var WebGLVAOWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLVAOWrapper#bind * @since 4.0.0 */ - bind: function () + bind() { this.renderer.glWrapper.updateVAO(this.glState); - }, + } /** * Destroys this WebGLVAOWrapper and removes all associated resources. @@ -216,7 +216,7 @@ var WebGLVAOWrapper = new Class({ * @method Phaser.Renderer.WebGL.Wrappers.WebGLVAOWrapper#destroy * @since 4.0.0 */ - destroy: function () + destroy() { var extVAO = this.renderer.vaoExtension; @@ -231,6 +231,6 @@ var WebGLVAOWrapper = new Class({ this.glState = null; this.renderer = null; } -}); +}; module.exports = WebGLVAOWrapper; diff --git a/src/renderer/webgl/wrappers/WebGLVertexBufferLayoutWrapper.js b/src/renderer/webgl/wrappers/WebGLVertexBufferLayoutWrapper.js index a3e804c9c9..1b5e075ad3 100644 --- a/src/renderer/webgl/wrappers/WebGLVertexBufferLayoutWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLVertexBufferLayoutWrapper.js @@ -22,8 +22,8 @@ var Class = require('../../../utils/Class'); * @param {Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper} [buffer] - The buffer that this layout should use. If not provided, a new buffer will be created. If the buffer is too small, an exception is thrown. * @throws {Error} If the buffer is too small for the layout. */ -var WebGLVertexBufferLayoutWrapper = new Class({ - initialize: function WebGLVertexBufferLayoutWrapper (renderer, layout, buffer) +var WebGLVertexBufferLayoutWrapper = class { + constructor(renderer, layout, buffer) { /** * The WebGLRenderer instance that owns this wrapper. @@ -61,7 +61,7 @@ var WebGLVertexBufferLayoutWrapper = new Class({ * @since 4.0.0 */ this.buffer = buffer || renderer.createVertexBuffer(new ArrayBuffer(bufferSize), layout.usage); - }, + } /** * Complete the layout of the provided attribute buffer layout. @@ -76,7 +76,7 @@ var WebGLVertexBufferLayoutWrapper = new Class({ * @since 4.0.0 * @param {Phaser.Types.Renderer.WebGL.WebGLAttributeBufferLayout} attributeBufferLayout - The layout to complete. */ - completeLayout: function (attributeBufferLayout) + completeLayout(attributeBufferLayout) { var gl = this.renderer.gl; var layout = attributeBufferLayout.layout; @@ -117,6 +117,6 @@ var WebGLVertexBufferLayoutWrapper = new Class({ // Now that we know the total stride, we can set it. attributeBufferLayout.stride = offset; } -}); +}; module.exports = WebGLVertexBufferLayoutWrapper; diff --git a/src/scale/ScaleManager.js b/src/scale/ScaleManager.js index b18f3261a4..f294ee631c 100644 --- a/src/scale/ScaleManager.js +++ b/src/scale/ScaleManager.js @@ -123,15 +123,11 @@ var Camera = require('../cameras/2d/Camera'); * * @param {Phaser.Game} game - A reference to the Phaser.Game instance. */ -var ScaleManager = new Class({ +var ScaleManager = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function ScaleManager (game) + constructor(game) { - EventEmitter.call(this); + super(); /** * A reference to the Phaser.Game instance. @@ -397,7 +393,7 @@ var ScaleManager = new Class({ fullScreenError: NOOP }; - }, + } /** * Called _before_ the canvas object is created and added to the DOM. @@ -407,13 +403,13 @@ var ScaleManager = new Class({ * @listens Phaser.Core.Events#BOOT * @since 3.16.0 */ - preBoot: function () + preBoot() { // Parse the config to get the scaling values we need this.parseConfig(this.game.config); this.game.events.once(GameEvents.BOOT, this.boot, this); - }, + } /** * The Boot handler is called by Phaser.Game when it first starts up. @@ -424,7 +420,7 @@ var ScaleManager = new Class({ * @fires Phaser.Scale.Events#RESIZE * @since 3.16.0 */ - boot: function () + boot() { var game = this.game; @@ -461,7 +457,7 @@ var ScaleManager = new Class({ game.events.once(GameEvents.DESTROY, this.destroy, this); this.startListeners(); - }, + } /** * Parses the game configuration to set-up the scale defaults. @@ -472,7 +468,7 @@ var ScaleManager = new Class({ * * @param {Phaser.Types.Core.GameConfig} config - The Game configuration object. */ - parseConfig: function (config) + parseConfig(config) { // Get the parent element, if any this.getParent(config); @@ -594,7 +590,7 @@ var ScaleManager = new Class({ } this.orientation = GetScreenOrientation(width, height); - }, + } /** * Determines the parent element of the game canvas, if any, based on the game configuration. @@ -604,7 +600,7 @@ var ScaleManager = new Class({ * * @param {Phaser.Types.Core.GameConfig} config - The Game configuration object. */ - getParent: function (config) + getParent(config) { var parent = config.parent; @@ -644,7 +640,7 @@ var ScaleManager = new Class({ { this.fullscreenTarget = GetTarget(config.fullscreenTarget); } - }, + } /** * Calculates the size of the parent bounds and updates the `parentSize` @@ -655,7 +651,7 @@ var ScaleManager = new Class({ * * @return {boolean} `true` if the parent bounds have changed size or position, otherwise `false`. */ - getParentBounds: function () + getParentBounds() { if (!this.parent) { @@ -699,7 +695,7 @@ var ScaleManager = new Class({ } return false; - }, + } /** * Attempts to lock the orientation of the web browser using the Screen Orientation API. @@ -714,7 +710,7 @@ var ScaleManager = new Class({ * * @return {boolean} `true` if the orientation was successfully locked, otherwise `false`. */ - lockOrientation: function (orientation) + lockOrientation(orientation) { var lock = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation; @@ -724,7 +720,7 @@ var ScaleManager = new Class({ } return false; - }, + } /** * This method will set the size of the Parent Size component, which is used in scaling @@ -741,12 +737,12 @@ var ScaleManager = new Class({ * * @return {this} The Scale Manager instance. */ - setParentSize: function (width, height) + setParentSize(width, height) { this.parentSize.setSize(width, height); return this.refresh(); - }, + } /** * This method will set a new size for your game. @@ -764,7 +760,7 @@ var ScaleManager = new Class({ * * @return {this} The Scale Manager instance. */ - setGameSize: function (width, height) + setGameSize(width, height) { var autoRound = this.autoRound; @@ -797,7 +793,7 @@ var ScaleManager = new Class({ this.canvas.height = this.baseSize.height; return this.refresh(previousWidth, previousHeight); - }, + } /** * Call this to modify the size of the Phaser canvas element directly. @@ -828,7 +824,7 @@ var ScaleManager = new Class({ * * @return {this} The Scale Manager instance. */ - resize: function (width, height) + resize(width, height) { var zoom = this.zoom; var autoRound = this.autoRound; @@ -879,7 +875,7 @@ var ScaleManager = new Class({ } return this.refresh(previousWidth, previousHeight); - }, + } /** * Sets the zoom value of the Scale Manager. @@ -892,13 +888,13 @@ var ScaleManager = new Class({ * * @return {this} The Scale Manager instance. */ - setZoom: function (value) + setZoom(value) { this.zoom = value; this._resetZoom = true; return this.refresh(); - }, + } /** * Sets the zoom to be the maximum possible based on the _current_ parent size. @@ -909,13 +905,13 @@ var ScaleManager = new Class({ * * @return {this} The Scale Manager instance. */ - setMaxZoom: function () + setMaxZoom() { this.zoom = this.getMaxZoom(); this._resetZoom = true; return this.refresh(); - }, + } /** * By setting a Snap value, when the browser size is modified, its dimensions will automatically @@ -937,7 +933,7 @@ var ScaleManager = new Class({ * * @return {this} The Scale Manager instance. */ - setSnap: function (snapWidth, snapHeight) + setSnap(snapWidth, snapHeight) { if (snapWidth === undefined) { snapWidth = 0; } if (snapHeight === undefined) { snapHeight = snapWidth; } @@ -945,7 +941,7 @@ var ScaleManager = new Class({ this.displaySize.setSnap(snapWidth, snapHeight); return this.refresh(); - }, + } /** * Refreshes the internal scale values, bounds sizes and orientation checks. @@ -964,7 +960,7 @@ var ScaleManager = new Class({ * * @return {this} The Scale Manager instance. */ - refresh: function (previousWidth, previousHeight) + refresh(previousWidth, previousHeight) { if (previousWidth === undefined) { previousWidth = this.width; } if (previousHeight === undefined) { previousHeight = this.height; } @@ -993,7 +989,7 @@ var ScaleManager = new Class({ this.emit(Events.RESIZE, this.gameSize, this.baseSize, this.displaySize, previousWidth, previousHeight); return this; - }, + } /** * Internal method that checks the current screen orientation, only if the internal check flag is set. @@ -1004,7 +1000,7 @@ var ScaleManager = new Class({ * @fires Phaser.Scale.Events#ORIENTATION_CHANGE * @since 3.16.0 */ - updateOrientation: function () + updateOrientation() { if (this._checkOrientation) { @@ -1019,7 +1015,7 @@ var ScaleManager = new Class({ this.emit(Events.ORIENTATION_CHANGE, newOrientation); } } - }, + } /** * Internal method that manages updating the size components based on the scale mode. @@ -1027,7 +1023,7 @@ var ScaleManager = new Class({ * @method Phaser.Scale.ScaleManager#updateScale * @since 3.16.0 */ - updateScale: function () + updateScale() { var style = this.canvas.style; @@ -1169,7 +1165,7 @@ var ScaleManager = new Class({ // Finally, update the centering this.updateCenter(); - }, + } /** * Calculates and returns the largest possible zoom factor, based on the current @@ -1181,13 +1177,13 @@ var ScaleManager = new Class({ * * @return {number} The maximum possible zoom factor. At a minimum this value is always at least 1. */ - getMaxZoom: function () + getMaxZoom() { var zoomH = SnapFloor(this.parentSize.width, this.gameSize.width, 0, true); var zoomV = SnapFloor(this.parentSize.height, this.gameSize.height, 0, true); return Math.max(Math.min(zoomH, zoomV), 1); - }, + } /** * Calculates and updates the canvas CSS style in order to center it within the @@ -1205,7 +1201,7 @@ var ScaleManager = new Class({ * @method Phaser.Scale.ScaleManager#updateCenter * @since 3.16.0 */ - updateCenter: function () + updateCenter() { var autoCenter = this.autoCenter; @@ -1237,7 +1233,7 @@ var ScaleManager = new Class({ style.marginLeft = offsetX + 'px'; style.marginTop = offsetY + 'px'; - }, + } /** * Updates the `canvasBounds` rectangle to match the bounding client rectangle of the @@ -1246,7 +1242,7 @@ var ScaleManager = new Class({ * @method Phaser.Scale.ScaleManager#updateBounds * @since 3.16.0 */ - updateBounds: function () + updateBounds() { var bounds = this.canvasBounds; var clientRect = this.canvas.getBoundingClientRect(); @@ -1255,7 +1251,7 @@ var ScaleManager = new Class({ bounds.y = clientRect.top + (window.pageYOffset || 0) - (document.documentElement.clientTop || 0); bounds.width = clientRect.width; bounds.height = clientRect.height; - }, + } /** * Transforms the pageX value into the scaled coordinate space of the Scale Manager. @@ -1267,10 +1263,10 @@ var ScaleManager = new Class({ * * @return {number} The translated value. */ - transformX: function (pageX) + transformX(pageX) { return (pageX - this.canvasBounds.left) * this.displayScale.x; - }, + } /** * Transforms the pageY value into the scaled coordinate space of the Scale Manager. @@ -1282,10 +1278,10 @@ var ScaleManager = new Class({ * * @return {number} The translated value. */ - transformY: function (pageY) + transformY(pageY) { return (pageY - this.canvasBounds.top) * this.displayScale.y; - }, + } /** * Sends a request to the browser to ask it to go in to full screen mode, using the {@link https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API Fullscreen API}. @@ -1320,7 +1316,7 @@ var ScaleManager = new Class({ * * @param {object} [fullscreenOptions] - The FullscreenOptions dictionary is used to provide configuration options when entering full screen. */ - startFullscreen: function (fullscreenOptions) + startFullscreen(fullscreenOptions) { if (fullscreenOptions === undefined) { fullscreenOptions = { navigationUI: 'hide' }; } @@ -1346,7 +1342,7 @@ var ScaleManager = new Class({ fsTarget[fullscreen.request](fullscreenOptions); } } - }, + } /** * The browser has successfully entered fullscreen mode. @@ -1357,14 +1353,14 @@ var ScaleManager = new Class({ * @fires Phaser.Scale.Events#RESIZE * @since 3.17.0 */ - fullscreenSuccessHandler: function () + fullscreenSuccessHandler() { this.getParentBounds(); this.refresh(); this.emit(Events.ENTER_FULLSCREEN); - }, + } /** * The browser failed to enter fullscreen mode. @@ -1377,12 +1373,12 @@ var ScaleManager = new Class({ * * @param {any} error - The DOM error event. */ - fullscreenErrorHandler: function (error) + fullscreenErrorHandler(error) { this.removeFullscreenTarget(); this.emit(Events.FULLSCREEN_FAILED, error); - }, + } /** * An internal method that gets the target element that is used when entering fullscreen mode. @@ -1392,7 +1388,7 @@ var ScaleManager = new Class({ * * @return {object} The fullscreen target element. */ - getFullscreenTarget: function () + getFullscreenTarget() { if (!this.fullscreenTarget) { @@ -1418,7 +1414,7 @@ var ScaleManager = new Class({ } return this.fullscreenTarget; - }, + } /** * Removes the fullscreen target that was added to the DOM. @@ -1426,7 +1422,7 @@ var ScaleManager = new Class({ * @method Phaser.Scale.ScaleManager#removeFullscreenTarget * @since 3.17.0 */ - removeFullscreenTarget: function () + removeFullscreenTarget() { if (this._createdFullscreenTarget) { @@ -1441,7 +1437,7 @@ var ScaleManager = new Class({ parent.removeChild(fsTarget); } } - }, + } /** * Calling this method will cancel fullscreen mode, if the browser has entered it. @@ -1450,7 +1446,7 @@ var ScaleManager = new Class({ * @fires Phaser.Scale.Events#FULLSCREEN_UNSUPPORTED * @since 3.16.0 */ - stopFullscreen: function () + stopFullscreen() { var fullscreen = this.fullscreen; @@ -1467,7 +1463,7 @@ var ScaleManager = new Class({ } this.removeFullscreenTarget(); - }, + } /** * The browser has successfully left fullscreen mode. @@ -1476,7 +1472,7 @@ var ScaleManager = new Class({ * @fires Phaser.Scale.Events#LEAVE_FULLSCREEN * @since 3.85.0 */ - leaveFullScreenSuccessHandler: function () + leaveFullScreenSuccessHandler() { // Get the parent size again as it will have changed this.getParentBounds(); @@ -1484,7 +1480,7 @@ var ScaleManager = new Class({ this.emit(Events.LEAVE_FULLSCREEN); this.refresh(); - }, + } /** * Toggles the fullscreen mode. If already in fullscreen, calling this will cancel it. @@ -1505,7 +1501,7 @@ var ScaleManager = new Class({ * * @param {object} [fullscreenOptions] - The FullscreenOptions dictionary is used to provide configuration options when entering full screen. */ - toggleFullscreen: function (fullscreenOptions) + toggleFullscreen(fullscreenOptions) { if (this.fullscreen.active) { @@ -1515,7 +1511,7 @@ var ScaleManager = new Class({ { this.startFullscreen(fullscreenOptions); } - }, + } /** * An internal method that starts the different DOM event listeners running. @@ -1523,7 +1519,7 @@ var ScaleManager = new Class({ * @method Phaser.Scale.ScaleManager#startListeners * @since 3.16.0 */ - startListeners: function () + startListeners() { var _this = this; var listeners = this.domlisteners; @@ -1581,7 +1577,7 @@ var ScaleManager = new Class({ document.addEventListener('MSFullscreenChange', listeners.fullScreenChange, false); document.addEventListener('MSFullscreenError', listeners.fullScreenError, false); } - }, + } /** * Triggered when a fullscreenchange event is dispatched by the DOM. @@ -1590,7 +1586,7 @@ var ScaleManager = new Class({ * @protected * @since 3.16.0 */ - onFullScreenChange: function () + onFullScreenChange() { if (document.fullscreenElement || document.webkitFullscreenElement || document.msFullscreenElement || document.mozFullScreenElement) { @@ -1602,7 +1598,7 @@ var ScaleManager = new Class({ this.stopFullscreen(); this.leaveFullScreenSuccessHandler(); } - }, + } /** * Triggered when a fullscreenerror event is dispatched by the DOM. @@ -1610,10 +1606,10 @@ var ScaleManager = new Class({ * @method Phaser.Scale.ScaleManager#onFullScreenError * @since 3.16.0 */ - onFullScreenError: function () + onFullScreenError() { this.removeFullscreenTarget(); - }, + } /** * Get Rectange of visible area. @@ -1626,7 +1622,7 @@ var ScaleManager = new Class({ * * @return {Phaser.Geom.Rectangle} The Rectangle of visible area. */ - getViewPort: function (camera, out) + getViewPort(camera, out) { if (!(camera instanceof Camera)) { @@ -1679,7 +1675,7 @@ var ScaleManager = new Class({ } return out; - }, + } /** * Internal method, called automatically by the game step. @@ -1691,7 +1687,7 @@ var ScaleManager = new Class({ * @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) + step(time, delta) { if (!this.parent) { @@ -1711,7 +1707,7 @@ var ScaleManager = new Class({ this.dirty = false; this._lastCheck = 0; } - }, + } /** * Stops all DOM event listeners. @@ -1719,7 +1715,7 @@ var ScaleManager = new Class({ * @method Phaser.Scale.ScaleManager#stopListeners * @since 3.16.0 */ - stopListeners: function () + stopListeners() { var listeners = this.domlisteners; @@ -1745,7 +1741,7 @@ var ScaleManager = new Class({ // MS Specific document.removeEventListener('MSFullscreenChange', listeners.fullScreenChange, false); document.removeEventListener('MSFullscreenError', listeners.fullScreenError, false); - }, + } /** * Destroys this Scale Manager, releasing all references to external resources. @@ -1754,7 +1750,7 @@ var ScaleManager = new Class({ * @method Phaser.Scale.ScaleManager#destroy * @since 3.16.0 */ - destroy: function () + destroy() { this.removeAllListeners(); @@ -1770,7 +1766,7 @@ var ScaleManager = new Class({ this.gameSize.destroy(); this.baseSize.destroy(); this.displaySize.destroy(); - }, + } /** * Is the browser currently in fullscreen mode or not? @@ -1780,14 +1776,11 @@ var ScaleManager = new Class({ * @readonly * @since 3.16.0 */ - isFullscreen: { - - get: function () - { - return this.fullscreen.active; - } - }, + get isFullscreen() + { + return this.fullscreen.active; + } /** * The game width. @@ -1799,14 +1792,11 @@ var ScaleManager = new Class({ * @readonly * @since 3.16.0 */ - width: { - - get: function () - { - return this.gameSize.width; - } - }, + get width() + { + return this.gameSize.width; + } /** * The game height. @@ -1818,14 +1808,11 @@ var ScaleManager = new Class({ * @readonly * @since 3.16.0 */ - height: { - get: function () - { - return this.gameSize.height; - } - - }, + get height() + { + return this.gameSize.height; + } /** * Is the device in a portrait orientation as reported by the Orientation API? @@ -1836,14 +1823,11 @@ var ScaleManager = new Class({ * @readonly * @since 3.16.0 */ - isPortrait: { - - get: function () - { - return (this.orientation === CONST.ORIENTATION.PORTRAIT); - } - }, + get isPortrait() + { + return (this.orientation === CONST.ORIENTATION.PORTRAIT); + } /** * Is the device in a landscape orientation as reported by the Orientation API? @@ -1854,14 +1838,11 @@ var ScaleManager = new Class({ * @readonly * @since 3.16.0 */ - isLandscape: { - get: function () - { - return (this.orientation === CONST.ORIENTATION.LANDSCAPE); - } - - }, + get isLandscape() + { + return (this.orientation === CONST.ORIENTATION.LANDSCAPE); + } /** * Are the game dimensions portrait? (i.e. taller than they are wide) @@ -1873,14 +1854,11 @@ var ScaleManager = new Class({ * @readonly * @since 3.16.0 */ - isGamePortrait: { - get: function () - { - return (this.height > this.width); - } - - }, + get isGamePortrait() + { + return (this.height > this.width); + } /** * Are the game dimensions landscape? (i.e. wider than they are tall) @@ -1892,15 +1870,12 @@ var ScaleManager = new Class({ * @readonly * @since 3.16.0 */ - isGameLandscape: { - - get: function () - { - return (this.width > this.height); - } + get isGameLandscape() + { + return (this.width > this.height); } -}); +}; module.exports = ScaleManager; diff --git a/src/scene/Scene.js b/src/scene/Scene.js index ef6a842ff2..c4b12434db 100644 --- a/src/scene/Scene.js +++ b/src/scene/Scene.js @@ -20,11 +20,9 @@ var Systems = require('./Systems'); * * @param {(string|Phaser.Types.Scenes.SettingsConfig)} [config] - The scene key or scene specific configuration settings. */ -var Scene = new Class({ +var Scene = class { - initialize: - - function Scene (config) + constructor(config) { /** * The Scene Systems. You must never overwrite this property, or all hell will break loose. @@ -288,7 +286,7 @@ var Scene = new Class({ * @since 3.50.0 */ this.renderer; - }, + } /** * This method should be overridden by your own Scenes. @@ -301,10 +299,10 @@ var Scene = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - update: function () + update() { } -}); +}; module.exports = Scene; diff --git a/src/scene/SceneManager.js b/src/scene/SceneManager.js index 8cf3e0e478..ca25933598 100644 --- a/src/scene/SceneManager.js +++ b/src/scene/SceneManager.js @@ -36,11 +36,9 @@ var Systems = require('./Systems'); * @param {Phaser.Game} game - The Phaser.Game instance this Scene Manager belongs to. * @param {object} sceneConfig - Scene specific configuration settings. */ -var SceneManager = new Class({ +var SceneManager = class { - initialize: - - function SceneManager (game, sceneConfig) + constructor(game, sceneConfig) { /** * The Game that this SceneManager belongs to. @@ -174,7 +172,7 @@ var SceneManager = new Class({ } game.events.once(GameEvents.READY, this.bootQueue, this); - }, + } /** * Internal first-time Scene boot handler. @@ -184,7 +182,7 @@ var SceneManager = new Class({ * @fires Phaser.Core.Events#SYSTEM_READY * @since 3.2.0 */ - bootQueue: function () + bootQueue() { if (this.isBooted) { @@ -263,7 +261,7 @@ var SceneManager = new Class({ } this._start.length = 0; - }, + } /** * Process the Scene operations queue. @@ -271,7 +269,7 @@ var SceneManager = new Class({ * @method Phaser.Scenes.SceneManager#processQueue * @since 3.0.0 */ - processQueue: function () + processQueue() { var pendingLength = this._pending.length; var queueLength = this._queue.length; @@ -314,7 +312,7 @@ var SceneManager = new Class({ } this._queue.length = 0; - }, + } /** * Adds a new Scene into the SceneManager. @@ -340,7 +338,7 @@ var SceneManager = new Class({ * * @return {?Phaser.Scene} The added Scene, if it was added immediately, otherwise `null`. */ - add: function (key, sceneConfig, autoStart, data) + add(key, sceneConfig, autoStart, data) { if (autoStart === undefined) { autoStart = false; } if (data === undefined) { data = {}; } @@ -405,7 +403,7 @@ var SceneManager = new Class({ } return newScene; - }, + } /** * Removes a Scene from the SceneManager. @@ -423,7 +421,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - remove: function (key) + remove(key) { if (this.isProcessing) { @@ -455,7 +453,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Boot the given Scene. @@ -467,7 +465,7 @@ var SceneManager = new Class({ * * @param {Phaser.Scene} scene - The Scene to boot. */ - bootScene: function (scene) + bootScene(scene) { var sys = scene.sys; var settings = sys.settings; @@ -511,7 +509,7 @@ var SceneManager = new Class({ // No preload? Then there was nothing to load either this.create(scene); } - }, + } /** * Handles load completion for a Scene's Loader. @@ -524,10 +522,10 @@ var SceneManager = new Class({ * * @param {Phaser.Loader.LoaderPlugin} loader - The loader that has completed loading. */ - loadComplete: function (loader) + loadComplete(loader) { this.create(loader.scene); - }, + } /** * Handle payload completion for a Scene. @@ -538,10 +536,10 @@ var SceneManager = new Class({ * * @param {Phaser.Loader.LoaderPlugin} loader - The loader that has completed loading its Scene's payload. */ - payloadComplete: function (loader) + payloadComplete(loader) { this.bootScene(loader.scene); - }, + } /** * Updates the Scenes. @@ -552,7 +550,7 @@ var SceneManager = new Class({ * @param {number} time - Time elapsed. * @param {number} delta - Delta time from the last update. */ - update: function (time, delta) + update(time, delta) { this.processQueue(); @@ -573,7 +571,7 @@ var SceneManager = new Class({ sys.scenePlugin.step(time, delta); } } - }, + } /** * Renders the Scenes. @@ -583,7 +581,7 @@ var SceneManager = new Class({ * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The renderer to use. */ - render: function (renderer) + render(renderer) { // Loop through the scenes in forward order for (var i = 0; i < this.scenes.length; i++) @@ -597,7 +595,7 @@ var SceneManager = new Class({ } this.isProcessing = false; - }, + } /** * Calls the given Scene's {@link Phaser.Scene#create} method and updates its status. @@ -610,7 +608,7 @@ var SceneManager = new Class({ * * @param {Phaser.Scene} scene - The Scene to create. */ - create: function (scene) + create(scene) { var sys = scene.sys; var settings = sys.settings; @@ -641,7 +639,7 @@ var SceneManager = new Class({ settings.status = CONST.RUNNING; sys.events.emit(Events.CREATE, scene); - }, + } /** * Creates and initializes a Scene from a function. @@ -655,7 +653,7 @@ var SceneManager = new Class({ * * @return {Phaser.Scene} The created Scene. */ - createSceneFromFunction: function (key, scene) + createSceneFromFunction(key, scene) { var newScene = new scene(); @@ -685,7 +683,7 @@ var SceneManager = new Class({ return newScene; } - }, + } /** * Creates and initializes a Scene instance. @@ -699,7 +697,7 @@ var SceneManager = new Class({ * * @return {Phaser.Scene} The created Scene. */ - createSceneFromInstance: function (key, newScene) + createSceneFromInstance(key, newScene) { var configKey = newScene.sys.settings.key; @@ -711,7 +709,7 @@ var SceneManager = new Class({ newScene.sys.init(this.game); return newScene; - }, + } /** * Creates and initializes a Scene from an Object definition. @@ -725,7 +723,7 @@ var SceneManager = new Class({ * * @return {Phaser.Scene} The created Scene. */ - createSceneFromObject: function (key, sceneConfig) + createSceneFromObject(key, sceneConfig) { var newScene = new Scene(sceneConfig); @@ -794,7 +792,7 @@ var SceneManager = new Class({ } return newScene; - }, + } /** * Retrieves the key of a Scene from a Scene config. @@ -808,7 +806,7 @@ var SceneManager = new Class({ * * @return {string} The Scene key. */ - getKey: function (key, sceneConfig) + getKey(key, sceneConfig) { if (!key) { key = 'default'; } @@ -835,7 +833,7 @@ var SceneManager = new Class({ { return key; } - }, + } /** * Returns an array of all the current Scenes being managed by this Scene Manager. @@ -854,7 +852,7 @@ var SceneManager = new Class({ * * @return {Phaser.Scene[]} An array containing all of the Scenes in the Scene Manager. */ - getScenes: function (isActive, inReverse) + getScenes(isActive, inReverse) { if (isActive === undefined) { isActive = true; } if (inReverse === undefined) { inReverse = false; } @@ -873,7 +871,7 @@ var SceneManager = new Class({ } return (inReverse) ? out.reverse() : out; - }, + } /** * Retrieves a Scene based on the given key. @@ -892,7 +890,7 @@ var SceneManager = new Class({ * * @return {?Phaser.Scene} The Scene, or `null` if no matching Scene was found. */ - getScene: function (key) + getScene(key) { if (typeof key === 'string') { @@ -913,7 +911,7 @@ var SceneManager = new Class({ } return null; - }, + } /** * Determines whether a Scene is running. @@ -928,7 +926,7 @@ var SceneManager = new Class({ * * @return {boolean} Whether the Scene is running, or `null` if no matching Scene was found. */ - isActive: function (key) + isActive(key) { var scene = this.getScene(key); @@ -938,7 +936,7 @@ var SceneManager = new Class({ } return null; - }, + } /** * Determines whether a Scene is paused. @@ -953,7 +951,7 @@ var SceneManager = new Class({ * * @return {boolean} Whether the Scene is paused, or `null` if no matching Scene was found. */ - isPaused: function (key) + isPaused(key) { var scene = this.getScene(key); @@ -963,7 +961,7 @@ var SceneManager = new Class({ } return null; - }, + } /** * Determines whether a Scene is visible. @@ -978,7 +976,7 @@ var SceneManager = new Class({ * * @return {boolean} Whether the Scene is visible, or `null` if no matching Scene was found. */ - isVisible: function (key) + isVisible(key) { var scene = this.getScene(key); @@ -988,7 +986,7 @@ var SceneManager = new Class({ } return null; - }, + } /** * Determines whether a Scene is sleeping. @@ -1003,7 +1001,7 @@ var SceneManager = new Class({ * * @return {boolean} Whether the Scene is sleeping, or `null` if no matching Scene was found. */ - isSleeping: function (key) + isSleeping(key) { var scene = this.getScene(key); @@ -1013,7 +1011,7 @@ var SceneManager = new Class({ } return null; - }, + } /** * Pauses the given Scene. @@ -1029,7 +1027,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - pause: function (key, data) + pause(key, data) { var scene = this.getScene(key); @@ -1039,7 +1037,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Resumes the given Scene. @@ -1055,7 +1053,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - resume: function (key, data) + resume(key, data) { var scene = this.getScene(key); @@ -1065,7 +1063,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Puts the given Scene to sleep. @@ -1081,7 +1079,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - sleep: function (key, data) + sleep(key, data) { var scene = this.getScene(key); @@ -1091,7 +1089,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Awakens the given Scene. @@ -1107,7 +1105,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - wake: function (key, data) + wake(key, data) { var scene = this.getScene(key); @@ -1117,7 +1115,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Runs the given Scene. @@ -1139,7 +1137,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - run: function (key, data) + run(key, data) { var scene = this.getScene(key); @@ -1171,7 +1169,7 @@ var SceneManager = new Class({ // Not actually running? this.start(key, data); } - }, + } /** * Starts the given Scene, if it is not starting, loading, or creating. @@ -1189,7 +1187,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - start: function (key, data) + start(key, data) { // If the Scene Manager is not running, then put the Scene into a holding pattern if (!this.isBooted) @@ -1267,7 +1265,7 @@ var SceneManager = new Class({ this.bootScene(scene); return this; - }, + } /** * Stops the given Scene. @@ -1283,7 +1281,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - stop: function (key, data) + stop(key, data) { var scene = this.getScene(key); @@ -1301,7 +1299,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Sleeps one one Scene and starts the other. @@ -1318,7 +1316,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - switch: function (from, to, data) + switch(from, to, data) { var sceneA = this.getScene(from); var sceneB = this.getScene(to); @@ -1338,7 +1336,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Retrieves a Scene by numeric index. @@ -1353,10 +1351,10 @@ var SceneManager = new Class({ * * @return {(Phaser.Scene|undefined)} The Scene. */ - getAt: function (index) + getAt(index) { return this.scenes[index]; - }, + } /** * Retrieves the numeric index of a Scene. @@ -1371,12 +1369,12 @@ var SceneManager = new Class({ * * @return {number} The index of the Scene. */ - getIndex: function (key) + getIndex(key) { var scene = this.getScene(key); return this.scenes.indexOf(scene); - }, + } /** * Brings a Scene to the top of the Scenes list. @@ -1393,7 +1391,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - bringToTop: function (key) + bringToTop(key) { if (this.isProcessing) { @@ -1412,7 +1410,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Sends a Scene to the back of the Scenes list. @@ -1429,7 +1427,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - sendToBack: function (key) + sendToBack(key) { if (this.isProcessing) { @@ -1447,7 +1445,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Moves a Scene down one position in the Scenes list. @@ -1462,7 +1460,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - moveDown: function (key) + moveDown(key) { if (this.isProcessing) { @@ -1482,7 +1480,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Moves a Scene up one position in the Scenes list. @@ -1497,7 +1495,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - moveUp: function (key) + moveUp(key) { if (this.isProcessing) { @@ -1517,7 +1515,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Moves a Scene so it is immediately above another Scene in the Scenes list. @@ -1536,7 +1534,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - moveAbove: function (keyA, keyB) + moveAbove(keyA, keyB) { if (keyA === keyB) { @@ -1563,7 +1561,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Moves a Scene so it is immediately below another Scene in the Scenes list. @@ -1582,7 +1580,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - moveBelow: function (keyA, keyB) + moveBelow(keyA, keyB) { if (keyA === keyB) { @@ -1616,7 +1614,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Queue a Scene operation for the next update. @@ -1632,12 +1630,12 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - queueOp: function (op, keyA, keyB, data) + queueOp(op, keyA, keyB, data) { this._queue.push({ op: op, keyA: keyA, keyB: keyB, data: data }); return this; - }, + } /** * Swaps the positions of two Scenes in the Scenes list. @@ -1653,7 +1651,7 @@ var SceneManager = new Class({ * * @return {this} This Scene Manager instance. */ - swapPosition: function (keyA, keyB) + swapPosition(keyA, keyB) { if (keyA === keyB) { @@ -1677,7 +1675,7 @@ var SceneManager = new Class({ } return this; - }, + } /** * Dumps debug information about each Scene to the developer console. @@ -1685,7 +1683,7 @@ var SceneManager = new Class({ * @method Phaser.Scenes.SceneManager#dump * @since 3.2.0 */ - dump: function () + dump() { var out = []; var map = [ 'pending', 'init', 'start', 'loading', 'creating', 'running', 'paused', 'sleeping', 'shutdown', 'destroyed' ]; @@ -1701,7 +1699,7 @@ var SceneManager = new Class({ } console.log(out.join('\n')); - }, + } /** * Destroy this Scene Manager and all of its systems. @@ -1713,7 +1711,7 @@ var SceneManager = new Class({ * @method Phaser.Scenes.SceneManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { for (var i = 0; i < this.scenes.length; i++) { @@ -1736,6 +1734,6 @@ var SceneManager = new Class({ this.systemScene = null; } -}); +}; module.exports = SceneManager; diff --git a/src/scene/ScenePlugin.js b/src/scene/ScenePlugin.js index b20d71d2ad..4cb444a1cc 100644 --- a/src/scene/ScenePlugin.js +++ b/src/scene/ScenePlugin.js @@ -29,11 +29,9 @@ var PluginCache = require('../plugins/PluginCache'); * * @param {Phaser.Scene} scene - The Scene that this ScenePlugin belongs to. */ -var ScenePlugin = new Class({ +var ScenePlugin = class { - initialize: - - function ScenePlugin (scene) + constructor(scene) { /** * The Scene that this ScenePlugin belongs to. @@ -162,7 +160,7 @@ var ScenePlugin = new Class({ scene.sys.events.once(Events.BOOT, this.boot, this); scene.sys.events.on(Events.START, this.pluginStart, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -172,10 +170,10 @@ var ScenePlugin = new Class({ * @private * @since 3.0.0 */ - boot: function () + boot() { this.systems.events.once(Events.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -186,12 +184,12 @@ var ScenePlugin = new Class({ * @private * @since 3.5.0 */ - pluginStart: function () + pluginStart() { this._target = null; this.systems.events.once(Events.SHUTDOWN, this.shutdown, this); - }, + } /** * Shutdown this Scene and run the given one. @@ -209,7 +207,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - start: function (key, data) + start(key, data) { if (key === undefined) { key = this.key; } @@ -217,7 +215,7 @@ var ScenePlugin = new Class({ this.manager.queueOp('start', key, data); return this; - }, + } /** * Restarts this Scene. @@ -231,7 +229,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - restart: function (data) + restart(data) { var key = this.key; @@ -239,7 +237,7 @@ var ScenePlugin = new Class({ this.manager.queueOp('start', key, data); return this; - }, + } /** * This will start a transition from the current Scene to the target Scene given. @@ -281,7 +279,7 @@ var ScenePlugin = new Class({ * * @return {boolean} `true` is the transition was started, otherwise `false`. */ - transition: function (config) + transition(config) { if (config === undefined) { config = {}; } @@ -351,7 +349,7 @@ var ScenePlugin = new Class({ this.systems.events.emit(Events.TRANSITION_OUT, target, duration); return true; - }, + } /** * Checks to see if this Scene can transition to the target Scene or not. @@ -364,7 +362,7 @@ var ScenePlugin = new Class({ * * @return {boolean} `true` if this Scene can transition, otherwise `false`. */ - checkValidTransition: function (target) + checkValidTransition(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()) @@ -373,7 +371,7 @@ var ScenePlugin = new Class({ } return true; - }, + } /** * A single game step. This is only called if the parent Scene is transitioning @@ -386,7 +384,7 @@ var ScenePlugin = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - step: function (time, delta) + step(time, delta) { this._elapsed += delta; @@ -401,7 +399,7 @@ var ScenePlugin = new Class({ { this.transitionComplete(); } - }, + } /** * Called by `step` when the transition out of this scene to another is over. @@ -411,7 +409,7 @@ var ScenePlugin = new Class({ * @fires Phaser.Scenes.Events#TRANSITION_COMPLETE * @since 3.5.0 */ - transitionComplete: function () + transitionComplete() { var targetSys = this._target.sys; var targetSettings = this._target.sys.settings; @@ -442,7 +440,7 @@ var ScenePlugin = new Class({ { 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. @@ -457,10 +455,10 @@ var ScenePlugin = new Class({ * * @return {?Phaser.Scene} The added Scene, if it was added immediately, otherwise `null`. */ - add: function (key, sceneConfig, autoStart, data) + add(key, sceneConfig, autoStart, data) { return this.manager.add(key, sceneConfig, autoStart, data); - }, + } /** * Launch the given Scene and run it in parallel with this one. @@ -478,7 +476,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - launch: function (key, data) + launch(key, data) { if (key && key !== this.key) { @@ -486,7 +484,7 @@ var ScenePlugin = new Class({ } return this; - }, + } /** * Runs the given Scene, but does not change the state of this Scene. @@ -510,7 +508,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - run: function (key, data) + run(key, data) { if (key && key !== this.key) { @@ -518,7 +516,7 @@ var ScenePlugin = new Class({ } return this; - }, + } /** * Pause the Scene - this stops the update step from happening but it still renders. @@ -536,14 +534,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - pause: function (key, data) + pause(key, data) { if (key === undefined) { key = this.key; } this.manager.queueOp('pause', key, data); return this; - }, + } /** * Resume the Scene - starts the update loop again. @@ -561,14 +559,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - resume: function (key, data) + resume(key, data) { if (key === undefined) { key = this.key; } this.manager.queueOp('resume', key, data); return this; - }, + } /** * Makes the Scene sleep (no update, no render) but doesn't shutdown. @@ -586,14 +584,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - sleep: function (key, data) + sleep(key, data) { if (key === undefined) { key = this.key; } this.manager.queueOp('sleep', key, data); return this; - }, + } /** * Makes the Scene wake-up (starts update and render) @@ -611,14 +609,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - wake: function (key, data) + wake(key, data) { if (key === undefined) { key = this.key; } this.manager.queueOp('wake', key, data); return this; - }, + } /** * Makes this Scene sleep then starts the Scene given. @@ -636,7 +634,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - switch: function (key, data) + switch(key, data) { if (key !== this.key) { @@ -644,7 +642,7 @@ var ScenePlugin = new Class({ } return this; - }, + } /** * Shutdown the Scene, clearing display list, timers, etc. @@ -662,14 +660,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - stop: function (key, data) + stop(key, data) { if (key === undefined) { key = this.key; } this.manager.queueOp('stop', key, data); return this; - }, + } /** * Sets the active state of the given Scene. @@ -686,7 +684,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - setActive: function (value, key, data) + setActive(value, key, data) { if (key === undefined) { key = this.key; } @@ -698,7 +696,7 @@ var ScenePlugin = new Class({ } return this; - }, + } /** * Sets the visible state of the given Scene. @@ -714,7 +712,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - setVisible: function (value, key) + setVisible(value, key) { if (key === undefined) { key = this.key; } @@ -726,7 +724,7 @@ var ScenePlugin = new Class({ } return this; - }, + } /** * Checks if the given Scene is sleeping or not? @@ -741,12 +739,12 @@ var ScenePlugin = new Class({ * * @return {boolean} Whether the Scene is sleeping, or `null` if no matching Scene was found. */ - isSleeping: function (key) + isSleeping(key) { if (key === undefined) { key = this.key; } return this.manager.isSleeping(key); - }, + } /** * Checks if the given Scene is running or not? @@ -761,12 +759,12 @@ var ScenePlugin = new Class({ * * @return {boolean} Whether the Scene is running, or `null` if no matching Scene was found. */ - isActive: function (key) + isActive(key) { if (key === undefined) { key = this.key; } return this.manager.isActive(key); - }, + } /** * Checks if the given Scene is paused or not? @@ -781,12 +779,12 @@ var ScenePlugin = new Class({ * * @return {boolean} Whether the Scene is paused, or `null` if no matching Scene was found. */ - isPaused: function (key) + isPaused(key) { if (key === undefined) { key = this.key; } return this.manager.isPaused(key); - }, + } /** * Checks if the given Scene is visible or not? @@ -801,12 +799,12 @@ var ScenePlugin = new Class({ * * @return {boolean} Whether the Scene is visible, or `null` if no matching Scene was found. */ - isVisible: function (key) + isVisible(key) { if (key === undefined) { key = this.key; } return this.manager.isVisible(key); - }, + } /** * Swaps the position of two scenes in the Scenes list. @@ -824,7 +822,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - swapPosition: function (keyA, keyB) + swapPosition(keyA, keyB) { if (keyB === undefined) { keyB = this.key; } @@ -834,7 +832,7 @@ var ScenePlugin = new Class({ } return this; - }, + } /** * Moves a Scene so it is immediately above another Scene in the Scenes list. @@ -853,7 +851,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - moveAbove: function (keyA, keyB) + moveAbove(keyA, keyB) { if (keyB === undefined) { keyB = this.key; } @@ -863,7 +861,7 @@ var ScenePlugin = new Class({ } return this; - }, + } /** * Moves a Scene so it is immediately below another Scene in the Scenes list. @@ -882,7 +880,7 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - moveBelow: function (keyA, keyB) + moveBelow(keyA, keyB) { if (keyB === undefined) { keyB = this.key; } @@ -892,7 +890,7 @@ var ScenePlugin = new Class({ } return this; - }, + } /** * Removes a Scene from the SceneManager. @@ -913,14 +911,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - remove: function (key) + remove(key) { if (key === undefined) { key = this.key; } this.manager.remove(key); return this; - }, + } /** * Moves a Scene up one position in the Scenes list. @@ -935,14 +933,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - moveUp: function (key) + moveUp(key) { if (key === undefined) { key = this.key; } this.manager.moveUp(key); return this; - }, + } /** * Moves a Scene down one position in the Scenes list. @@ -957,14 +955,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - moveDown: function (key) + moveDown(key) { if (key === undefined) { key = this.key; } this.manager.moveDown(key); return this; - }, + } /** * Brings a Scene to the top of the Scenes list. @@ -981,14 +979,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - bringToTop: function (key) + bringToTop(key) { if (key === undefined) { key = this.key; } this.manager.bringToTop(key); return this; - }, + } /** * Sends a Scene to the back of the Scenes list. @@ -1005,14 +1003,14 @@ var ScenePlugin = new Class({ * * @return {this} This Scene Plugin instance. */ - sendToBack: function (key) + sendToBack(key) { if (key === undefined) { key = this.key; } this.manager.sendToBack(key); return this; - }, + } /** * Retrieves a Scene based on the given key. @@ -1031,10 +1029,10 @@ var ScenePlugin = new Class({ * * @return {Phaser.Scene} The Scene. */ - get: function (key) + get(key) { return this.manager.getScene(key); - }, + } /** * Return the status of the Scene. @@ -1049,7 +1047,7 @@ var ScenePlugin = new Class({ * * @return {number} The Scene status. This maps to the `Phaser.Scene` constants, such as `Phaser.Scene.LOADING`. */ - getStatus: function (key) + getStatus(key) { var scene = this.manager.getScene(key); @@ -1057,7 +1055,7 @@ var ScenePlugin = new Class({ { return scene.sys.getStatus(); } - }, + } /** * Retrieves the numeric index of a Scene in the Scenes list. @@ -1072,12 +1070,12 @@ var ScenePlugin = new Class({ * * @return {number} The index of the Scene. */ - getIndex: function (key) + getIndex(key) { if (key === undefined) { key = this.key; } return this.manager.getIndex(key); - }, + } /** * The Scene that owns this plugin is shutting down. @@ -1088,13 +1086,13 @@ var ScenePlugin = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { var eventEmitter = this.systems.events; eventEmitter.off(Events.SHUTDOWN, this.shutdown, this); eventEmitter.off(Events.TRANSITION_OUT); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -1105,7 +1103,7 @@ var ScenePlugin = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -1117,7 +1115,7 @@ var ScenePlugin = new Class({ this.manager = null; } -}); +}; PluginCache.register('ScenePlugin', ScenePlugin, 'scenePlugin'); diff --git a/src/scene/Systems.js b/src/scene/Systems.js index 0a48656830..df4d4ae614 100644 --- a/src/scene/Systems.js +++ b/src/scene/Systems.js @@ -29,11 +29,9 @@ var Settings = require('./Settings'); * @param {Phaser.Scene} scene - The Scene that owns this Systems instance. * @param {(string|Phaser.Types.Scenes.SettingsConfig)} config - Scene specific configuration settings. */ -var Systems = new Class({ +var Systems = class { - initialize: - - function Systems (scene, config) + constructor(scene, config) { /** * A reference to the Scene that these Systems belong to. @@ -290,7 +288,7 @@ var Systems = new Class({ * @since 3.10.0 */ this.sceneUpdate = NOOP; - }, + } /** * This method is called only once by the Scene Manager when the Scene is instantiated. @@ -304,7 +302,7 @@ var Systems = new Class({ * * @param {Phaser.Game} game - A reference to the Phaser Game instance. */ - init: function (game) + init(game) { this.settings.status = CONST.INIT; @@ -326,7 +324,7 @@ var Systems = new Class({ this.events.emit(Events.BOOT, this); this.settings.isBooted = true; - }, + } /** * A single game step. Called automatically by the Scene Manager as a result of a Request Animation @@ -341,7 +339,7 @@ var Systems = new Class({ * @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) + step(time, delta) { var events = this.events; @@ -352,7 +350,7 @@ var Systems = new Class({ this.sceneUpdate.call(this.scene, time, delta); events.emit(Events.POST_UPDATE, time, delta); - }, + } /** * Called automatically by the Scene Manager. @@ -365,7 +363,7 @@ var Systems = new Class({ * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The renderer that invoked the render call. */ - render: function (renderer) + render(renderer) { var displayList = this.displayList; @@ -376,7 +374,7 @@ var Systems = new Class({ this.cameras.render(renderer, displayList); this.events.emit(Events.RENDER, renderer); - }, + } /** * Force a sort of the display list on the next render. @@ -384,10 +382,10 @@ var Systems = new Class({ * @method Phaser.Scenes.Systems#queueDepthSort * @since 3.0.0 */ - queueDepthSort: function () + queueDepthSort() { this.displayList.queueDepthSort(); - }, + } /** * Immediately sorts the display list if the flag is set. @@ -395,10 +393,10 @@ var Systems = new Class({ * @method Phaser.Scenes.Systems#depthSort * @since 3.0.0 */ - depthSort: function () + depthSort() { this.displayList.depthSort(); - }, + } /** * Pause this Scene. @@ -413,7 +411,7 @@ var Systems = new Class({ * * @return {Phaser.Scenes.Systems} This Systems object. */ - pause: function (data) + pause(data) { var settings = this.settings; var status = this.getStatus(); @@ -432,7 +430,7 @@ var Systems = new Class({ } return this; - }, + } /** * Resume this Scene from a paused state. @@ -445,7 +443,7 @@ var Systems = new Class({ * * @return {Phaser.Scenes.Systems} This Systems object. */ - resume: function (data) + resume(data) { var events = this.events; var settings = this.settings; @@ -460,7 +458,7 @@ var Systems = new Class({ } return this; - }, + } /** * Send this Scene to sleep. @@ -478,7 +476,7 @@ var Systems = new Class({ * * @return {Phaser.Scenes.Systems} This Systems object. */ - sleep: function (data) + sleep(data) { var settings = this.settings; var status = this.getStatus(); @@ -498,7 +496,7 @@ var Systems = new Class({ } return this; - }, + } /** * Wake-up this Scene if it was previously asleep. @@ -511,7 +509,7 @@ var Systems = new Class({ * * @return {Phaser.Scenes.Systems} This Systems object. */ - wake: function (data) + wake(data) { var events = this.events; var settings = this.settings; @@ -529,7 +527,7 @@ var Systems = new Class({ } return this; - }, + } /** * Returns any data that was sent to this Scene by another Scene. @@ -542,10 +540,10 @@ var Systems = new Class({ * * @return {any} The Scene Data. */ - getData: function () + getData() { return this.settings.data; - }, + } /** * Returns the current status of this Scene. @@ -555,10 +553,10 @@ var Systems = new Class({ * * @return {number} The status of this Scene. One of the `Phaser.Scene` constants. */ - getStatus: function () + getStatus() { return this.settings.status; - }, + } /** * Can this Scene receive Input events? @@ -568,12 +566,12 @@ var Systems = new Class({ * * @return {boolean} `true` if this Scene can receive Input events. */ - canInput: function () + canInput() { var status = this.settings.status; return (status > CONST.PENDING && status <= CONST.RUNNING); - }, + } /** * Is this Scene sleeping? @@ -583,10 +581,10 @@ var Systems = new Class({ * * @return {boolean} `true` if this Scene is asleep, otherwise `false`. */ - isSleeping: function () + isSleeping() { return (this.settings.status === CONST.SLEEPING); - }, + } /** * Is this Scene running? @@ -596,10 +594,10 @@ var Systems = new Class({ * * @return {boolean} `true` if this Scene is running, otherwise `false`. */ - isActive: function () + isActive() { return (this.settings.status === CONST.RUNNING); - }, + } /** * Is this Scene paused? @@ -609,10 +607,10 @@ var Systems = new Class({ * * @return {boolean} `true` if this Scene is paused, otherwise `false`. */ - isPaused: function () + isPaused() { return (this.settings.status === CONST.PAUSED); - }, + } /** * Is this Scene currently transitioning out to, or in from another Scene? @@ -622,10 +620,10 @@ var Systems = new Class({ * * @return {boolean} `true` if this Scene is currently transitioning, otherwise `false`. */ - isTransitioning: function () + isTransitioning() { return (this.settings.isTransition || this.scenePlugin._target !== null); - }, + } /** * Is this Scene currently transitioning out from itself to another Scene? @@ -635,10 +633,10 @@ var Systems = new Class({ * * @return {boolean} `true` if this Scene is in transition to another Scene, otherwise `false`. */ - isTransitionOut: function () + isTransitionOut() { return (this.scenePlugin._target !== null && this.scenePlugin._duration > 0); - }, + } /** * Is this Scene currently transitioning in from another Scene? @@ -648,10 +646,10 @@ var Systems = new Class({ * * @return {boolean} `true` if this Scene is transitioning in from another Scene, otherwise `false`. */ - isTransitionIn: function () + isTransitionIn() { return (this.settings.isTransition); - }, + } /** * Is this Scene visible and rendering? @@ -661,10 +659,10 @@ var Systems = new Class({ * * @return {boolean} `true` if this Scene is visible, otherwise `false`. */ - isVisible: function () + isVisible() { return this.settings.visible; - }, + } /** * Sets the visible state of this Scene. @@ -677,12 +675,12 @@ var Systems = new Class({ * * @return {Phaser.Scenes.Systems} This Systems object. */ - setVisible: function (value) + setVisible(value) { this.settings.visible = value; return this; - }, + } /** * Set the active state of this Scene. @@ -697,7 +695,7 @@ var Systems = new Class({ * * @return {Phaser.Scenes.Systems} This Systems object. */ - setActive: function (value, data) + setActive(value, data) { if (value) { @@ -707,7 +705,7 @@ var Systems = new Class({ { return this.pause(data); } - }, + } /** * Start this Scene running and rendering. @@ -720,7 +718,7 @@ var Systems = new Class({ * * @param {object} data - Optional data object that may have been passed to this Scene from another. */ - start: function (data) + start(data) { var events = this.events; var settings = this.settings; @@ -740,7 +738,7 @@ var Systems = new Class({ // For user-land code to listen out for events.emit(Events.READY, this, data); - }, + } /** * Shutdown this Scene and send a shutdown event to all of its systems. @@ -755,7 +753,7 @@ var Systems = new Class({ * * @param {object} [data] - A data object that will be passed in the 'shutdown' event. */ - shutdown: function (data) + shutdown(data) { var events = this.events; var settings = this.settings; @@ -771,7 +769,7 @@ var Systems = new Class({ settings.visible = false; events.emit(Events.SHUTDOWN, this, data); - }, + } /** * Destroy this Scene and send a destroy event to all of its systems. @@ -783,7 +781,7 @@ var Systems = new Class({ * @fires Phaser.Scenes.Events#DESTROY * @since 3.0.0 */ - destroy: function () + destroy() { var events = this.events; var settings = this.settings; @@ -805,6 +803,6 @@ var Systems = new Class({ } } -}); +}; module.exports = Systems; diff --git a/src/sound/BaseSound.js b/src/sound/BaseSound.js index 2c172945b1..4e4b00749a 100644 --- a/src/sound/BaseSound.js +++ b/src/sound/BaseSound.js @@ -24,15 +24,11 @@ var Extend = require('../utils/object/Extend'); * @param {string} key - Asset key for the sound. * @param {Phaser.Types.Sound.SoundConfig} [config] - An optional config object containing default sound settings. */ -var BaseSound = new Class({ +var BaseSound = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function BaseSound (manager, key, config) + constructor(manager, key, config) { - EventEmitter.call(this); + super(); /** * Local reference to the sound manager. @@ -176,7 +172,7 @@ var BaseSound = new Class({ * @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. @@ -189,7 +185,7 @@ var BaseSound = new Class({ * * @return {boolean} Whether the marker was added successfully. */ - addMarker: function (marker) + addMarker(marker) { if (!marker || !marker.name || typeof marker.name !== 'string') { @@ -223,7 +219,7 @@ var BaseSound = new Class({ this.markers[marker.name] = marker; return true; - }, + } /** * Updates previously added marker. @@ -235,7 +231,7 @@ var BaseSound = new Class({ * * @return {boolean} Whether the marker was updated successfully. */ - updateMarker: function (marker) + updateMarker(marker) { if (!marker || !marker.name || typeof marker.name !== 'string') { @@ -253,7 +249,7 @@ var BaseSound = new Class({ this.markers[marker.name] = Extend(true, this.markers[marker.name], marker); return true; - }, + } /** * Removes a marker from the sound. @@ -265,7 +261,7 @@ var BaseSound = new Class({ * * @return {?Phaser.Types.Sound.SoundMarker} Removed marker object or 'null' if there was no marker with provided name. */ - removeMarker: function (markerName) + removeMarker(markerName) { var marker = this.markers[markerName]; @@ -277,7 +273,7 @@ var BaseSound = new Class({ this.markers[markerName] = null; return marker; - }, + } /** * Play this sound, or a marked section of it. @@ -293,7 +289,7 @@ var BaseSound = new Class({ * * @return {boolean} Whether the sound started playing successfully. */ - play: function (markerName, config) + play(markerName, config) { if (markerName === undefined) { markerName = ''; } @@ -337,7 +333,7 @@ var BaseSound = new Class({ this.isPaused = false; return true; - }, + } /** * Pauses the sound. This only works if the sound is currently playing. @@ -349,7 +345,7 @@ var BaseSound = new Class({ * * @return {boolean} Whether the sound was paused successfully. */ - pause: function () + pause() { if (this.isPaused || !this.isPlaying) { @@ -360,7 +356,7 @@ var BaseSound = new Class({ this.isPaused = true; return true; - }, + } /** * Resumes the sound. This only works if the sound is paused and not already playing. @@ -372,7 +368,7 @@ var BaseSound = new Class({ * * @return {boolean} Whether the sound was resumed successfully. */ - resume: function () + resume() { if (!this.isPaused || this.isPlaying) { @@ -383,7 +379,7 @@ var BaseSound = new Class({ this.isPaused = false; return true; - }, + } /** * Stop playing this sound. @@ -393,7 +389,7 @@ var BaseSound = new Class({ * * @return {boolean} Whether the sound was stopped successfully. */ - stop: function () + stop() { if (!this.isPaused && !this.isPlaying) { @@ -406,7 +402,7 @@ var BaseSound = new Class({ this.resetConfig(); return true; - }, + } /** * Method used internally for applying config values to some of the sound properties. @@ -414,7 +410,7 @@ var BaseSound = new Class({ * @method Phaser.Sound.BaseSound#applyConfig * @since 3.0.0 */ - applyConfig: function () + applyConfig() { this.mute = this.currentConfig.mute; this.volume = this.currentConfig.volume; @@ -422,7 +418,7 @@ var BaseSound = new Class({ this.detune = this.currentConfig.detune; this.loop = this.currentConfig.loop; this.pan = this.currentConfig.pan; - }, + } /** * Method used internally for resetting values of some of the config properties. @@ -430,11 +426,11 @@ var BaseSound = new Class({ * @method Phaser.Sound.BaseSound#resetConfig * @since 3.0.0 */ - resetConfig: function () + resetConfig() { this.currentConfig.seek = 0; this.currentConfig.delay = 0; - }, + } /** * Update method called automatically by sound manager on every game step. @@ -445,9 +441,9 @@ var BaseSound = new Class({ * @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 () + update() { - }, + } /** * Method used internally to calculate total playback rate of the sound. @@ -455,14 +451,14 @@ var BaseSound = new Class({ * @method Phaser.Sound.BaseSound#calculateRate * @since 3.0.0 */ - calculateRate: function () + calculateRate() { 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. @@ -471,7 +467,7 @@ var BaseSound = new Class({ * @fires Phaser.Sound.Events#DESTROY * @since 3.0.0 */ - destroy: function () + destroy() { if (this.pendingRemove) { @@ -493,6 +489,6 @@ var BaseSound = new Class({ this.currentMarker = null; } -}); +}; module.exports = BaseSound; diff --git a/src/sound/BaseSoundManager.js b/src/sound/BaseSoundManager.js index d77d7bd8fb..b82c498b6c 100644 --- a/src/sound/BaseSoundManager.js +++ b/src/sound/BaseSoundManager.js @@ -30,15 +30,11 @@ var Vector2 = require('../math/Vector2'); * @see Phaser.Sound.NoAudioSoundManager * @see Phaser.Sound.WebAudioSoundManager */ -var BaseSoundManager = new Class({ +var BaseSoundManager = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function BaseSoundManager (game) + constructor(game) { - EventEmitter.call(this); + super(); /** * Local reference to game. @@ -178,7 +174,7 @@ var BaseSoundManager = new Class({ ee.on(GameEvents.FOCUS, this.onGameFocus, this); ee.on(GameEvents.PRE_STEP, this.update, this); ee.once(GameEvents.DESTROY, this.destroy, this); - }, + } /** * Adds a new sound into the sound manager. @@ -192,9 +188,9 @@ var BaseSoundManager = new Class({ * * @return {Phaser.Sound.BaseSound} The new sound instance. */ - add: function () + add() { - }, + } /** * Adds a new audio sprite sound into the sound manager. @@ -209,7 +205,7 @@ var BaseSoundManager = new Class({ * * @return {(Phaser.Sound.NoAudioSound|Phaser.Sound.HTML5AudioSound|Phaser.Sound.WebAudioSound)} The new audio sprite sound instance. */ - addAudioSprite: function (key, config) + addAudioSprite(key, config) { if (config === undefined) { config = {}; } @@ -239,7 +235,7 @@ var BaseSoundManager = new Class({ } return sound; - }, + } /** * Gets the first sound in this Sound Manager that matches the given key. @@ -255,10 +251,10 @@ var BaseSoundManager = new Class({ * * @return {?Phaser.Sound.BaseSound} - The sound, or null. */ - get: function (key) + get(key) { return GetFirst(this.sounds, 'key', key); - }, + } /** * Gets all sounds in this Sound Manager. @@ -276,7 +272,7 @@ var BaseSoundManager = new Class({ * * @return {Phaser.Sound.BaseSound[]} - The sounds, or an empty array. */ - getAll: function (key) + getAll(key) { if (key) { @@ -286,7 +282,7 @@ var BaseSoundManager = new Class({ { return GetAll(this.sounds); } - }, + } /** * Returns all sounds from this Sound Manager that are currently @@ -301,10 +297,10 @@ var BaseSoundManager = new Class({ * * @return {Phaser.Sound.BaseSound[]} - All currently playing sounds, or an empty array. */ - getAllPlaying: function () + getAllPlaying() { return GetAll(this.sounds, 'isPlaying', true); - }, + } /** * Adds a new sound to the sound manager and plays it. @@ -322,7 +318,7 @@ var BaseSoundManager = new Class({ * * @return {boolean} Whether the sound started playing successfully. */ - play: function (key, extra) + play(key, extra) { var sound = this.add(key); @@ -345,7 +341,7 @@ var BaseSoundManager = new Class({ { return sound.play(); } - }, + } /** * Adds a new audio sprite sound to the sound manager and plays it. @@ -362,14 +358,14 @@ var BaseSoundManager = new Class({ * * @return {boolean} Whether the audio sprite sound started playing successfully. */ - playAudioSprite: function (key, spriteName, config) + playAudioSprite(key, spriteName, config) { var sound = this.addAudioSprite(key); sound.once(Events.COMPLETE, sound.destroy, sound); return sound.play(spriteName, config); - }, + } /** * Removes a sound from the sound manager. @@ -382,7 +378,7 @@ var BaseSoundManager = new Class({ * * @return {boolean} True if the sound was removed successfully, otherwise false. */ - remove: function (sound) + remove(sound) { var index = this.sounds.indexOf(sound); @@ -396,7 +392,7 @@ var BaseSoundManager = new Class({ } return false; - }, + } /** * Removes all sounds from the manager, destroying the sounds. @@ -404,7 +400,7 @@ var BaseSoundManager = new Class({ * @method Phaser.Sound.BaseSoundManager#removeAll * @since 3.23.0 */ - removeAll: function () + removeAll() { this.sounds.forEach(function (sound) { @@ -412,7 +408,7 @@ var BaseSoundManager = new Class({ }); this.sounds.length = 0; - }, + } /** * Removes all sounds from the sound manager that have an asset key matching the given value. @@ -425,7 +421,7 @@ var BaseSoundManager = new Class({ * * @return {number} The number of matching sound objects that were removed. */ - removeByKey: function (key) + removeByKey(key) { var removed = 0; @@ -444,7 +440,7 @@ var BaseSoundManager = new Class({ } return removed; - }, + } /** * Pauses all the sounds in the game. @@ -453,7 +449,7 @@ var BaseSoundManager = new Class({ * @fires Phaser.Sound.Events#PAUSE_ALL * @since 3.0.0 */ - pauseAll: function () + pauseAll() { this.forEachActiveSound(function (sound) { @@ -461,7 +457,7 @@ var BaseSoundManager = new Class({ }); this.emit(Events.PAUSE_ALL, this); - }, + } /** * Resumes all the sounds in the game. @@ -470,7 +466,7 @@ var BaseSoundManager = new Class({ * @fires Phaser.Sound.Events#RESUME_ALL * @since 3.0.0 */ - resumeAll: function () + resumeAll() { this.forEachActiveSound(function (sound) { @@ -478,7 +474,7 @@ var BaseSoundManager = new Class({ }); this.emit(Events.RESUME_ALL, this); - }, + } /** * Sets the X and Y position of the Spatial Audio listener on this Web Audios context. @@ -495,9 +491,9 @@ var BaseSoundManager = new Class({ * @param {number} [x] - The x position of the Spatial Audio listener. * @param {number} [y] - The y position of the Spatial Audio listener. */ - setListenerPosition: function () + setListenerPosition() { - }, + } /** * Stops all the sounds in the game. @@ -506,7 +502,7 @@ var BaseSoundManager = new Class({ * @fires Phaser.Sound.Events#STOP_ALL * @since 3.0.0 */ - stopAll: function () + stopAll() { this.forEachActiveSound(function (sound) { @@ -514,7 +510,7 @@ var BaseSoundManager = new Class({ }); this.emit(Events.STOP_ALL, this); - }, + } /** * Stops any sounds matching the given key. @@ -526,7 +522,7 @@ var BaseSoundManager = new Class({ * * @return {number} - How many sounds were stopped. */ - stopByKey: function (key) + stopByKey(key) { var stopped = 0; @@ -536,7 +532,7 @@ var BaseSoundManager = new Class({ }); return stopped; - }, + } /** * When a key is given, returns true if any sound with that key is playing. @@ -550,7 +546,7 @@ var BaseSoundManager = new Class({ * * @return {boolean} - Per the key argument, true if any matching sound is playing, otherwise false. */ - isPlaying: function (key) + isPlaying(key) { var sounds = this.sounds; var i = sounds.length - 1; @@ -582,7 +578,7 @@ var BaseSoundManager = new Class({ } return false; - }, + } /** * Method used internally for unlocking audio playback on devices that @@ -595,9 +591,9 @@ var BaseSoundManager = new Class({ * @protected * @since 3.0.0 */ - unlock: function () + unlock() { - }, + } /** * Method used internally for pausing sound manager if @@ -608,9 +604,9 @@ var BaseSoundManager = new Class({ * @protected * @since 3.0.0 */ - onBlur: function () + onBlur() { - }, + } /** * Method used internally for resuming sound manager if @@ -621,9 +617,9 @@ var BaseSoundManager = new Class({ * @protected * @since 3.0.0 */ - onFocus: function () + onFocus() { - }, + } /** * Internal handler for Phaser.Core.Events#BLUR. @@ -632,7 +628,7 @@ var BaseSoundManager = new Class({ * @private * @since 3.23.0 */ - onGameBlur: function () + onGameBlur() { this.gameLostFocus = true; @@ -640,7 +636,7 @@ var BaseSoundManager = new Class({ { this.onBlur(); } - }, + } /** * Internal handler for Phaser.Core.Events#FOCUS. @@ -649,7 +645,7 @@ var BaseSoundManager = new Class({ * @private * @since 3.23.0 */ - onGameFocus: function () + onGameFocus() { this.gameLostFocus = false; @@ -657,7 +653,7 @@ var BaseSoundManager = new Class({ { this.onFocus(); } - }, + } /** * Update method called on every game step. @@ -671,7 +667,7 @@ var BaseSoundManager = new Class({ * @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) + update(time, delta) { if (this.unlocked) { @@ -693,7 +689,7 @@ var BaseSoundManager = new Class({ { sound.update(time, delta); }); - }, + } /** * Destroys all the sounds in the game and all associated events. @@ -701,7 +697,7 @@ var BaseSoundManager = new Class({ * @method Phaser.Sound.BaseSoundManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.game.events.off(GameEvents.BLUR, this.onGameBlur, this); this.game.events.off(GameEvents.FOCUS, this.onGameFocus, this); @@ -715,7 +711,7 @@ var BaseSoundManager = new Class({ this.sounds = null; this.listenerPosition = null; this.game = null; - }, + } /** * Method used internally for iterating only over active sounds and skipping sounds that are marked for removal. @@ -727,7 +723,7 @@ var BaseSoundManager = new Class({ * @param {Phaser.Types.Sound.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) + forEachActiveSound(callback, scope) { var _this = this; @@ -738,7 +734,7 @@ var BaseSoundManager = new Class({ callback.call(scope || _this, sound, index, _this.sounds); } }); - }, + } /** * Sets the global playback rate at which all the sounds will be played. @@ -754,12 +750,12 @@ var BaseSoundManager = new Class({ * * @return {this} This Sound Manager. */ - setRate: function (value) + setRate(value) { this.rate = value; return this; - }, + } /** * Global playback rate at which all the sounds will be played. @@ -771,26 +767,23 @@ var BaseSoundManager = new Class({ * @default 1 * @since 3.0.0 */ - rate: { - - get: function () - { - return this._rate; - }, - set: function (value) - { - this._rate = value; + get rate() + { + return this._rate; + } - this.forEachActiveSound(function (sound) - { - sound.calculateRate(); - }); + set rate(value) + { + this._rate = value; - this.emit(Events.GLOBAL_RATE, this, value); - } + this.forEachActiveSound(function (sound) + { + sound.calculateRate(); + }); - }, + this.emit(Events.GLOBAL_RATE, this, value); + } /** * Sets the global detuning of all sounds in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -804,12 +797,12 @@ var BaseSoundManager = new Class({ * * @return {this} This Sound Manager. */ - setDetune: function (value) + setDetune(value) { this.detune = value; return this; - }, + } /** * Global detuning of all sounds in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -820,27 +813,24 @@ var BaseSoundManager = new Class({ * @default 0 * @since 3.0.0 */ - detune: { - - get: function () - { - return this._detune; - }, - set: function (value) - { - this._detune = value; + get detune() + { + return this._detune; + } - this.forEachActiveSound(function (sound) - { - sound.calculateRate(); - }); + set detune(value) + { + this._detune = value; - this.emit(Events.GLOBAL_DETUNE, this, value); - } + this.forEachActiveSound(function (sound) + { + sound.calculateRate(); + }); + this.emit(Events.GLOBAL_DETUNE, this, value); } -}); +}; module.exports = BaseSoundManager; diff --git a/src/sound/html5/HTML5AudioSound.js b/src/sound/html5/HTML5AudioSound.js index d6dc264cb3..802b65299d 100644 --- a/src/sound/html5/HTML5AudioSound.js +++ b/src/sound/html5/HTML5AudioSound.js @@ -24,13 +24,9 @@ var Clamp = require('../../math/Clamp'); * @param {string} key - Asset key for the sound. * @param {Phaser.Types.Sound.SoundConfig} [config={}] - An optional config object containing default sound settings. */ -var HTML5AudioSound = new Class({ +var HTML5AudioSound = class extends BaseSound { - Extends: BaseSound, - - initialize: - - function HTML5AudioSound (manager, key, config) + constructor(manager, key, config) { if (config === undefined) { config = {}; } @@ -87,8 +83,8 @@ var HTML5AudioSound = new Class({ this.totalDuration = this.tags[0].duration; - BaseSound.call(this, manager, key, config); - }, + super(manager, key, config); + } /** * Play this sound, or a marked section of it. @@ -109,7 +105,7 @@ var HTML5AudioSound = new Class({ * * @return {boolean} Whether the sound started playing successfully. */ - play: function (markerName, config) + play(markerName, config) { if (this.manager.isLocked(this, 'play', [ markerName, config ])) { @@ -130,7 +126,7 @@ var HTML5AudioSound = new Class({ this.emit(Events.PLAY, this); return true; - }, + } /** * Pauses the sound. @@ -141,7 +137,7 @@ var HTML5AudioSound = new Class({ * * @return {boolean} Whether the sound was paused successfully. */ - pause: function () + pause() { if (this.manager.isLocked(this, 'pause')) { @@ -166,7 +162,7 @@ var HTML5AudioSound = new Class({ this.emit(Events.PAUSE, this); return true; - }, + } /** * Resumes the sound. @@ -177,7 +173,7 @@ var HTML5AudioSound = new Class({ * * @return {boolean} Whether the sound was resumed successfully. */ - resume: function () + resume() { if (this.manager.isLocked(this, 'resume')) { @@ -203,7 +199,7 @@ var HTML5AudioSound = new Class({ this.emit(Events.RESUME, this); return true; - }, + } /** * Stop playing this sound. @@ -214,7 +210,7 @@ var HTML5AudioSound = new Class({ * * @return {boolean} Whether the sound was stopped successfully. */ - stop: function () + stop() { if (this.manager.isLocked(this, 'stop')) { @@ -232,7 +228,7 @@ var HTML5AudioSound = new Class({ this.emit(Events.STOP, this); return true; - }, + } /** * This method is used internally to pick and play the next available audio tag. @@ -242,7 +238,7 @@ var HTML5AudioSound = new Class({ * * @return {boolean} Whether the sound was assigned an audio tag successfully. */ - pickAndPlayAudioTag: function () + pickAndPlayAudioTag() { if (!this.pickAudioTag()) { @@ -281,7 +277,7 @@ var HTML5AudioSound = new Class({ this.resetConfig(); return true; - }, + } /** * This method performs the audio tag pooling logic. It first looks for @@ -295,7 +291,7 @@ var HTML5AudioSound = new Class({ * * @return {boolean} Whether the sound was assigned an audio tag successfully. */ - pickAudioTag: function () + pickAudioTag() { if (this.audio) { @@ -349,7 +345,7 @@ var HTML5AudioSound = new Class({ selectedSound.previousTime = 0; return true; - }, + } /** * Method used for playing audio tag and catching possible exceptions @@ -358,7 +354,7 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#playCatchPromise * @since 3.0.0 */ - playCatchPromise: function () + playCatchPromise() { var playPromise = this.audio.play(); @@ -370,7 +366,7 @@ var HTML5AudioSound = new Class({ console.warn(reason); }); } - }, + } /** * This method is used internally to stop and release the current audio tag. @@ -378,7 +374,7 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#stopAndReleaseAudioTag * @since 3.0.0 */ - stopAndReleaseAudioTag: function () + stopAndReleaseAudioTag() { this.startTime = 0; this.previousTime = 0; @@ -389,7 +385,7 @@ var HTML5AudioSound = new Class({ this.audio.dataset.used = 'false'; this.audio = null; } - }, + } /** * Method used internally to reset sound state, usually when stopping sound @@ -398,10 +394,10 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#reset * @since 3.0.0 */ - reset: function () + reset() { BaseSound.prototype.stop.call(this); - }, + } /** * Method used internally by sound manager for pausing sound if @@ -410,7 +406,7 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#onBlur * @since 3.0.0 */ - onBlur: function () + onBlur() { this.isPlaying = false; this.isPaused = true; @@ -420,7 +416,7 @@ var HTML5AudioSound = new Class({ this.currentConfig.delay = Math.max(0, (this.startTime - window.performance.now()) / 1000); this.stopAndReleaseAudioTag(); - }, + } /** * Method used internally by sound manager for resuming sound if @@ -429,12 +425,12 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#onFocus * @since 3.0.0 */ - onFocus: function () + onFocus() { this.isPlaying = true; this.isPaused = false; this.pickAndPlayAudioTag(); - }, + } /** * Update method called automatically by sound manager on every game step. @@ -446,7 +442,7 @@ var HTML5AudioSound = new Class({ * * @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout. */ - update: function (time) + update(time) { if (!this.isPlaying) { @@ -502,7 +498,7 @@ var HTML5AudioSound = new Class({ } this.previousTime = currentTime; - }, + } /** * Calls Phaser.Sound.BaseSound#destroy method @@ -511,7 +507,7 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#destroy * @since 3.0.0 */ - destroy: function () + destroy() { BaseSound.prototype.destroy.call(this); @@ -521,7 +517,7 @@ var HTML5AudioSound = new Class({ { this.stopAndReleaseAudioTag(); } - }, + } /** * This method is used internally to update the mute setting of this sound. @@ -529,13 +525,13 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#updateMute * @since 3.0.0 */ - updateMute: function () + updateMute() { if (this.audio) { this.audio.muted = this.currentConfig.mute || this.manager.mute; } - }, + } /** * This method is used internally to update the volume of this sound. @@ -543,13 +539,13 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#updateVolume * @since 3.0.0 */ - updateVolume: function () + updateVolume() { if (this.audio) { this.audio.volume = Clamp(this.currentConfig.volume * this.manager.volume, 0, 1); } - }, + } /** * This method is used internally to update the playback rate of this sound. @@ -557,7 +553,7 @@ var HTML5AudioSound = new Class({ * @method Phaser.Sound.HTML5AudioSound#calculateRate * @since 3.0.0 */ - calculateRate: function () + calculateRate() { BaseSound.prototype.calculateRate.call(this); @@ -565,7 +561,7 @@ var HTML5AudioSound = new Class({ { this.audio.playbackRate = this.totalRate; } - }, + } /** * Boolean indicating whether the sound is muted or not. @@ -577,27 +573,25 @@ var HTML5AudioSound = new Class({ * @fires Phaser.Sound.Events#MUTE * @since 3.0.0 */ - mute: { - get: function () - { - return this.currentConfig.mute; - }, + get mute() + { + return this.currentConfig.mute; + } - set: function (value) - { - this.currentConfig.mute = value; + set mute(value) + { + this.currentConfig.mute = value; - if (this.manager.isLocked(this, 'mute', value)) - { - return; - } + if (this.manager.isLocked(this, 'mute', value)) + { + return; + } - this.updateMute(); + this.updateMute(); - this.emit(Events.MUTE, this, value); - } - }, + this.emit(Events.MUTE, this, value); + } /** * Sets the muted state of this Sound. @@ -610,12 +604,12 @@ var HTML5AudioSound = new Class({ * * @return {this} This Sound instance. */ - setMute: function (value) + setMute(value) { this.mute = value; return this; - }, + } /** * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). @@ -626,27 +620,25 @@ var HTML5AudioSound = new Class({ * @fires Phaser.Sound.Events#VOLUME * @since 3.0.0 */ - volume: { - get: function () - { - return this.currentConfig.volume; - }, + get volume() + { + return this.currentConfig.volume; + } - set: function (value) - { - this.currentConfig.volume = value; + set volume(value) + { + this.currentConfig.volume = value; - if (this.manager.isLocked(this, 'volume', value)) - { - return; - } + if (this.manager.isLocked(this, 'volume', value)) + { + return; + } - this.updateVolume(); + this.updateVolume(); - this.emit(Events.VOLUME, this, value); - } - }, + this.emit(Events.VOLUME, this, value); + } /** * Sets the volume of this Sound. @@ -659,12 +651,12 @@ var HTML5AudioSound = new Class({ * * @return {this} This Sound instance. */ - setVolume: function (value) + setVolume(value) { this.volume = value; return this; - }, + } /** * Rate at which this Sound will be played. @@ -677,30 +669,27 @@ var HTML5AudioSound = new Class({ * @fires Phaser.Sound.Events#RATE * @since 3.0.0 */ - rate: { - - get: function () - { - return this.currentConfig.rate; - }, - set: function (value) - { - this.currentConfig.rate = value; + get rate() + { + return this.currentConfig.rate; + } - if (this.manager.isLocked(this, Events.RATE, value)) - { - return; - } - else - { - this.calculateRate(); + set rate(value) + { + this.currentConfig.rate = value; - this.emit(Events.RATE, this, value); - } + if (this.manager.isLocked(this, Events.RATE, value)) + { + return; } + else + { + this.calculateRate(); - }, + this.emit(Events.RATE, this, value); + } + } /** * Sets the playback rate of this Sound. @@ -716,12 +705,12 @@ var HTML5AudioSound = new Class({ * * @return {this} This Sound instance. */ - setRate: function (value) + setRate(value) { this.rate = value; return this; - }, + } /** * The detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -733,30 +722,27 @@ var HTML5AudioSound = new Class({ * @fires Phaser.Sound.Events#DETUNE * @since 3.0.0 */ - detune: { - - get: function () - { - return this.currentConfig.detune; - }, - set: function (value) - { - this.currentConfig.detune = value; + get detune() + { + return this.currentConfig.detune; + } - if (this.manager.isLocked(this, Events.DETUNE, value)) - { - return; - } - else - { - this.calculateRate(); + set detune(value) + { + this.currentConfig.detune = value; - this.emit(Events.DETUNE, this, value); - } + if (this.manager.isLocked(this, Events.DETUNE, value)) + { + return; } + else + { + this.calculateRate(); - }, + this.emit(Events.DETUNE, this, value); + } + } /** * Sets the detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -770,12 +756,12 @@ var HTML5AudioSound = new Class({ * * @return {this} This Sound instance. */ - setDetune: function (value) + setDetune(value) { this.detune = value; return this; - }, + } /** * Property representing the position of playback for this sound, in seconds. @@ -788,54 +774,52 @@ var HTML5AudioSound = new Class({ * @fires Phaser.Sound.Events#SEEK * @since 3.0.0 */ - seek: { - get: function () + get seek() + { + if (this.isPlaying) { - if (this.isPlaying) - { - return this.audio.currentTime - (this.currentMarker ? this.currentMarker.start : 0); - } - else if (this.isPaused) - { - return this.currentConfig.seek; - } - else - { - return 0; - } - }, + return this.audio.currentTime - (this.currentMarker ? this.currentMarker.start : 0); + } + else if (this.isPaused) + { + return this.currentConfig.seek; + } + else + { + return 0; + } + } - set: function (value) + set seek(value) + { + if (this.manager.isLocked(this, 'seek', value)) { - if (this.manager.isLocked(this, 'seek', value)) - { - return; - } + return; + } + + if (this.startTime > 0) + { + return; + } - if (this.startTime > 0) + if (this.isPlaying || this.isPaused) + { + value = Math.min(Math.max(0, value), this.duration); + + if (this.isPlaying) { - return; + this.previousTime = value; + this.audio.currentTime = value; } - - if (this.isPlaying || this.isPaused) + else if (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(Events.SEEK, this, value); + this.currentConfig.seek = value; } + + this.emit(Events.SEEK, this, value); } - }, + } /** * Seeks to a specific point in this sound. @@ -848,12 +832,12 @@ var HTML5AudioSound = new Class({ * * @return {this} This Sound instance. */ - setSeek: function (value) + setSeek(value) { this.seek = value; return this; - }, + } /** * Flag indicating whether or not the sound or current sound marker will loop. @@ -864,31 +848,28 @@ var HTML5AudioSound = new Class({ * @fires Phaser.Sound.Events#LOOP * @since 3.0.0 */ - loop: { - - get: function () - { - return this.currentConfig.loop; - }, - set: function (value) - { - this.currentConfig.loop = value; + get loop() + { + return this.currentConfig.loop; + } - if (this.manager.isLocked(this, 'loop', value)) - { - return; - } + set loop(value) + { + this.currentConfig.loop = value; - if (this.audio) - { - this.audio.loop = value; - } + if (this.manager.isLocked(this, 'loop', value)) + { + return; + } - this.emit(Events.LOOP, this, value); + if (this.audio) + { + this.audio.loop = value; } - }, + this.emit(Events.LOOP, this, value); + } /** * Sets the loop state of this Sound. @@ -901,12 +882,12 @@ var HTML5AudioSound = new Class({ * * @return {Phaser.Sound.HTML5AudioSound} This Sound instance. */ - setLoop: function (value) + setLoop(value) { this.loop = value; return this; - }, + } /** * Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). @@ -919,20 +900,18 @@ var HTML5AudioSound = new Class({ * @fires Phaser.Sound.Events#PAN * @since 3.50.0 */ - pan: { - get: function () - { - return this.currentConfig.pan; - }, + get pan() + { + return this.currentConfig.pan; + } - set: function (value) - { - this.currentConfig.pan = value; + set pan(value) + { + this.currentConfig.pan = value; - this.emit(Events.PAN, this, value); - } - }, + this.emit(Events.PAN, this, value); + } /** * Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). @@ -947,13 +926,13 @@ var HTML5AudioSound = new Class({ * * @return {this} This Sound instance. */ - setPan: function (value) + setPan(value) { this.pan = value; return this; } -}); +}; module.exports = HTML5AudioSound; diff --git a/src/sound/html5/HTML5AudioSoundManager.js b/src/sound/html5/HTML5AudioSoundManager.js index b3ab2d1084..26b5ddee95 100644 --- a/src/sound/html5/HTML5AudioSoundManager.js +++ b/src/sound/html5/HTML5AudioSoundManager.js @@ -34,13 +34,9 @@ var HTML5AudioSound = require('./HTML5AudioSound'); * * @param {Phaser.Game} game - Reference to the current game instance. */ -var HTML5AudioSoundManager = new Class({ +var HTML5AudioSoundManager = class extends BaseSoundManager { - Extends: BaseSoundManager, - - initialize: - - function HTML5AudioSoundManager (game) + constructor(game) { /** * Flag indicating whether if there are no idle instances of HTML5 Audio tag, @@ -136,8 +132,8 @@ var HTML5AudioSoundManager = new Class({ */ this._volume = 1; - BaseSoundManager.call(this, game); - }, + super(game); + } /** * Adds a new sound into the sound manager. @@ -150,14 +146,14 @@ var HTML5AudioSoundManager = new Class({ * * @return {Phaser.Sound.HTML5AudioSound} The new sound instance. */ - add: function (key, config) + add(key, config) { var sound = new HTML5AudioSound(this, key, config); this.sounds.push(sound); return sound; - }, + } /** * Unlocks HTML5 Audio loading and playback on mobile @@ -166,7 +162,7 @@ var HTML5AudioSoundManager = new Class({ * @method Phaser.Sound.HTML5AudioSoundManager#unlock * @since 3.0.0 */ - unlock: function () + unlock() { this.locked = false; @@ -282,7 +278,7 @@ var HTML5AudioSoundManager = new Class({ document.body.addEventListener('touchmove', detectMove, false); document.body.addEventListener('touchend', unlock, false); - }, + } /** * Method used internally for pausing sound manager if @@ -292,7 +288,7 @@ var HTML5AudioSoundManager = new Class({ * @protected * @since 3.0.0 */ - onBlur: function () + onBlur() { this.forEachActiveSound(function (sound) { @@ -302,7 +298,7 @@ var HTML5AudioSoundManager = new Class({ sound.onBlur(); } }); - }, + } /** * Method used internally for resuming sound manager if @@ -312,7 +308,7 @@ var HTML5AudioSoundManager = new Class({ * @protected * @since 3.0.0 */ - onFocus: function () + onFocus() { this.onBlurPausedSounds.forEach(function (sound) { @@ -320,7 +316,7 @@ var HTML5AudioSoundManager = new Class({ }); this.onBlurPausedSounds.length = 0; - }, + } /** * Calls Phaser.Sound.BaseSoundManager#destroy method @@ -329,13 +325,13 @@ var HTML5AudioSoundManager = new Class({ * @method Phaser.Sound.HTML5AudioSoundManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { BaseSoundManager.prototype.destroy.call(this); this.onBlurPausedSounds.length = 0; this.onBlurPausedSounds = null; - }, + } /** * Method used internally by Phaser.Sound.HTML5AudioSound class methods and property setters @@ -352,7 +348,7 @@ var HTML5AudioSoundManager = new Class({ * * @return {boolean} Whether the sound manager is locked. */ - isLocked: function (sound, prop, value) + isLocked(sound, prop, value) { if (sound.tags[0].dataset.locked === 'true') { @@ -366,7 +362,7 @@ var HTML5AudioSoundManager = new Class({ } return false; - }, + } /** * Sets the muted state of all this Sound Manager. @@ -379,12 +375,12 @@ var HTML5AudioSoundManager = new Class({ * * @return {Phaser.Sound.HTML5AudioSoundManager} This Sound Manager. */ - setMute: function (value) + setMute(value) { this.mute = value; return this; - }, + } /** * @name Phaser.Sound.HTML5AudioSoundManager#mute @@ -392,26 +388,23 @@ var HTML5AudioSoundManager = new Class({ * @fires Phaser.Sound.Events#GLOBAL_MUTE * @since 3.0.0 */ - mute: { - get: function () - { - return this._mute; - }, - - set: function (value) - { - this._mute = value; + get mute() + { + return this._mute; + } - this.forEachActiveSound(function (sound) - { - sound.updateMute(); - }); + set mute(value) + { + this._mute = value; - this.emit(Events.GLOBAL_MUTE, this, value); - } + this.forEachActiveSound(function (sound) + { + sound.updateMute(); + }); - }, + this.emit(Events.GLOBAL_MUTE, this, value); + } /** * Sets the volume of this Sound Manager. @@ -424,12 +417,12 @@ var HTML5AudioSoundManager = new Class({ * * @return {Phaser.Sound.HTML5AudioSoundManager} This Sound Manager. */ - setVolume: function (value) + setVolume(value) { this.volume = value; return this; - }, + } /** * @name Phaser.Sound.HTML5AudioSoundManager#volume @@ -437,27 +430,24 @@ var HTML5AudioSoundManager = new Class({ * @fires Phaser.Sound.Events#GLOBAL_VOLUME * @since 3.0.0 */ - volume: { - - get: function () - { - return this._volume; - }, - set: function (value) - { - this._volume = value; + get volume() + { + return this._volume; + } - this.forEachActiveSound(function (sound) - { - sound.updateVolume(); - }); + set volume(value) + { + this._volume = value; - this.emit(Events.GLOBAL_VOLUME, this, value); - } + this.forEachActiveSound(function (sound) + { + sound.updateVolume(); + }); + this.emit(Events.GLOBAL_VOLUME, this, value); } -}); +}; module.exports = HTML5AudioSoundManager; diff --git a/src/sound/noaudio/NoAudioSound.js b/src/sound/noaudio/NoAudioSound.js index 550c8520b1..9886150c3c 100644 --- a/src/sound/noaudio/NoAudioSound.js +++ b/src/sound/noaudio/NoAudioSound.js @@ -29,17 +29,13 @@ var Extend = require('../../utils/object/Extend'); * @param {string} key - Asset key for the sound. * @param {Phaser.Types.Sound.SoundConfig} [config={}] - An optional config object containing default sound settings. */ -var NoAudioSound = new Class({ +var NoAudioSound = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function NoAudioSound (manager, key, config) + constructor(manager, key, config) { if (config === void 0) { config = {}; } - EventEmitter.call(this); + super(); /** * Local reference to the sound manager. @@ -262,7 +258,7 @@ var NoAudioSound = new Class({ * @since 3.0.0 */ this.pendingRemove = false; - }, + } /** * @method Phaser.Sound.NoAudioSound#addMarker @@ -272,10 +268,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - addMarker: function () + addMarker() { return false; - }, + } /** * @method Phaser.Sound.NoAudioSound#updateMarker @@ -285,10 +281,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - updateMarker: function () + updateMarker() { return false; - }, + } /** * @method Phaser.Sound.NoAudioSound#removeMarker @@ -298,10 +294,10 @@ var NoAudioSound = new Class({ * * @return {null} null */ - removeMarker: function () + removeMarker() { return null; - }, + } /** * @method Phaser.Sound.NoAudioSound#play @@ -312,10 +308,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - play: function () + play() { return false; - }, + } /** * @method Phaser.Sound.NoAudioSound#pause @@ -323,10 +319,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - pause: function () + pause() { return false; - }, + } /** * Resumes the sound. @@ -336,10 +332,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - resume: function () + resume() { return false; - }, + } /** * Stop playing this sound. @@ -349,10 +345,10 @@ var NoAudioSound = new Class({ * * @return {boolean} false */ - stop: function () + stop() { return false; - }, + } /** * Sets the muted state of this Sound. @@ -364,10 +360,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setMute: function () + setMute() { return this; - }, + } /** * Sets the volume of this Sound. @@ -379,10 +375,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setVolume: function () + setVolume() { return this; - }, + } /** * Sets the playback rate of this Sound. @@ -397,10 +393,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setRate: function () + setRate() { return this; - }, + } /** * Sets the detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -413,10 +409,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setDetune: function () + setDetune() { return this; - }, + } /** * Seeks to a specific point in this sound. @@ -428,10 +424,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setSeek: function () + setSeek() { return this; - }, + } /** * Sets the loop state of this Sound. @@ -443,10 +439,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setLoop: function () + setLoop() { return this; - }, + } /** * Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). @@ -460,10 +456,10 @@ var NoAudioSound = new Class({ * * @return {this} This Sound instance. */ - setPan: function () + setPan() { return this; - }, + } /** * Method used internally for applying config values to some of the sound properties. @@ -471,10 +467,10 @@ var NoAudioSound = new Class({ * @method Phaser.Sound.NoAudioSound#applyConfig * @since 3.0.0 */ - applyConfig: function () + applyConfig() { return null; - }, + } /** * Method used internally for resetting values of some of the config properties. @@ -482,10 +478,10 @@ var NoAudioSound = new Class({ * @method Phaser.Sound.NoAudioSound#resetConfig * @since 3.0.0 */ - resetConfig: function () + resetConfig() { return null; - }, + } /** * Update method called automatically by sound manager on every game step. @@ -497,9 +493,9 @@ var NoAudioSound = new Class({ * @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 () + update() { - }, + } /** * Method used internally to calculate total playback rate of the sound. @@ -507,10 +503,10 @@ var NoAudioSound = new Class({ * @method Phaser.Sound.NoAudioSound#calculateRate * @since 3.0.0 */ - calculateRate: function () + calculateRate() { return null; - }, + } /** * Destroys this sound and all associated events and marks it for removal from the sound manager. @@ -519,11 +515,11 @@ var NoAudioSound = new Class({ * @fires Phaser.Sound.Events#DESTROY * @since 3.0.0 */ - destroy: function () + destroy() { BaseSound.prototype.destroy.call(this); } -}); +}; module.exports = NoAudioSound; diff --git a/src/sound/noaudio/NoAudioSoundManager.js b/src/sound/noaudio/NoAudioSoundManager.js index cfc8095b38..0960482c1b 100644 --- a/src/sound/noaudio/NoAudioSoundManager.js +++ b/src/sound/noaudio/NoAudioSoundManager.js @@ -27,15 +27,11 @@ var NoAudioSound = require('./NoAudioSound'); * * @param {Phaser.Game} game - Reference to the current game instance. */ -var NoAudioSoundManager = new Class({ +var NoAudioSoundManager = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function NoAudioSoundManager (game) + constructor(game) { - EventEmitter.call(this); + super(); this.game = game; this.sounds = []; @@ -45,7 +41,7 @@ var NoAudioSoundManager = new Class({ this.detune = 0; this.pauseOnBlur = true; this.locked = false; - }, + } /** * Adds a new sound into the sound manager. @@ -58,14 +54,14 @@ var NoAudioSoundManager = new Class({ * * @return {Phaser.Sound.NoAudioSound} The new sound instance. */ - add: function (key, config) + add(key, config) { var sound = new NoAudioSound(this, key, config); this.sounds.push(sound); return sound; - }, + } /** * Adds a new audio sprite sound into the sound manager. @@ -80,14 +76,14 @@ var NoAudioSoundManager = new Class({ * * @return {Phaser.Sound.NoAudioSound} The new audio sprite sound instance. */ - addAudioSprite: function (key, config) + addAudioSprite(key, config) { var sound = this.add(key, config); sound.spritemap = {}; return sound; - }, + } /** * Gets the first sound in the manager matching the given key, if any. @@ -102,10 +98,10 @@ var NoAudioSoundManager = new Class({ * * @return {?Phaser.Sound.BaseSound} - The sound, or null. */ - get: function (key) + get(key) { return BaseSoundManager.prototype.get.call(this, key); - }, + } /** * Gets any sounds in the manager matching the given key. @@ -120,10 +116,10 @@ var NoAudioSoundManager = new Class({ * * @return {Phaser.Sound.BaseSound[]} - The sounds, or an empty array. */ - getAll: function (key) + getAll(key) { return BaseSoundManager.prototype.getAll.call(this, key); - }, + } /** * This method does nothing but return 'false' for the No Audio Sound Manager, to maintain @@ -138,10 +134,10 @@ var NoAudioSoundManager = new Class({ * @return {boolean} Always 'false' for the No Audio Sound Manager. */ // eslint-disable-next-line no-unused-vars - play: function (key, extra) + play(key, extra) { return false; - }, + } /** * This method does nothing but return 'false' for the No Audio Sound Manager, to maintain @@ -157,10 +153,10 @@ var NoAudioSoundManager = new Class({ * @return {boolean} Always 'false' for the No Audio Sound Manager. */ // eslint-disable-next-line no-unused-vars - playAudioSprite: function (key, spriteName, config) + playAudioSprite(key, spriteName, config) { return false; - }, + } /** * Removes a sound from the sound manager. @@ -173,10 +169,10 @@ var NoAudioSoundManager = new Class({ * * @return {boolean} True if the sound was removed successfully, otherwise false. */ - remove: function (sound) + remove(sound) { return BaseSoundManager.prototype.remove.call(this, sound); - }, + } /** * Removes all sounds from the manager, destroying the sounds. @@ -184,10 +180,10 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#removeAll * @since 3.23.0 */ - removeAll: function () + removeAll() { return BaseSoundManager.prototype.removeAll.call(this); - }, + } /** * Removes all sounds from the sound manager that have an asset key matching the given value. @@ -200,10 +196,10 @@ var NoAudioSoundManager = new Class({ * * @return {number} The number of matching sound objects that were removed. */ - removeByKey: function (key) + removeByKey(key) { return BaseSoundManager.prototype.removeByKey.call(this, key); - }, + } /** * Stops any sounds matching the given key. @@ -215,10 +211,10 @@ var NoAudioSoundManager = new Class({ * * @return {number} - How many sounds were stopped. */ - stopByKey: function (key) + stopByKey(key) { return BaseSoundManager.prototype.stopByKey.call(this, key); - }, + } /** * Empty function for the No Audio Sound Manager. @@ -226,9 +222,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#onBlur * @since 3.0.0 */ - onBlur: function () + onBlur() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -236,9 +232,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#onFocus * @since 3.0.0 */ - onFocus: function () + onFocus() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -246,9 +242,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#onGameBlur * @since 3.0.0 */ - onGameBlur: function () + onGameBlur() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -256,9 +252,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#onGameFocus * @since 3.0.0 */ - onGameFocus: function () + onGameFocus() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -266,9 +262,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#pauseAll * @since 3.0.0 */ - pauseAll: function () + pauseAll() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -276,9 +272,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#resumeAll * @since 3.0.0 */ - resumeAll: function () + resumeAll() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -286,9 +282,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#stopAll * @since 3.0.0 */ - stopAll: function () + stopAll() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -296,9 +292,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#update * @since 3.0.0 */ - update: function () + update() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -308,9 +304,9 @@ var NoAudioSoundManager = new Class({ * * @return {this} This Sound Manager. */ - setRate: function () + setRate() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -320,9 +316,9 @@ var NoAudioSoundManager = new Class({ * * @return {this} This Sound Manager. */ - setDetune: function () + setDetune() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -330,9 +326,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#setMute * @since 3.0.0 */ - setMute: function () + setMute() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -340,9 +336,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#setVolume * @since 3.0.0 */ - setVolume: function () + setVolume() { - }, + } /** * Empty function for the No Audio Sound Manager. @@ -350,9 +346,9 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#unlock * @since 3.0.0 */ - unlock: function () + unlock() { - }, + } /** * Method used internally for iterating only over active sounds and skipping sounds that are marked for removal. @@ -364,10 +360,10 @@ var NoAudioSoundManager = new Class({ * @param {Phaser.Types.Sound.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 (callbackfn, scope) + forEachActiveSound(callbackfn, scope) { BaseSoundManager.prototype.forEachActiveSound.call(this, callbackfn, scope); - }, + } /** * Destroys all the sounds in the game and all associated events. @@ -375,11 +371,11 @@ var NoAudioSoundManager = new Class({ * @method Phaser.Sound.NoAudioSoundManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { BaseSoundManager.prototype.destroy.call(this); } -}); +}; module.exports = NoAudioSoundManager; diff --git a/src/sound/webaudio/WebAudioSound.js b/src/sound/webaudio/WebAudioSound.js index f69374e71b..7059fc67ea 100644 --- a/src/sound/webaudio/WebAudioSound.js +++ b/src/sound/webaudio/WebAudioSound.js @@ -24,13 +24,9 @@ var GetFastValue = require('../../utils/object/GetFastValue'); * @param {string} key - Asset key for the sound. * @param {Phaser.Types.Sound.SoundConfig} [config={}] - An optional config object containing default sound settings. */ -var WebAudioSound = new Class({ +var WebAudioSound = class extends BaseSound { - Extends: BaseSound, - - initialize: - - function WebAudioSound (manager, key, config) + constructor(manager, key, config) { if (config === undefined) { config = {}; } @@ -232,8 +228,8 @@ var WebAudioSound = new Class({ this.totalDuration = this.audioBuffer.duration; - BaseSound.call(this, manager, key, config); - }, + super(manager, key, config); + } /** * Play this sound, or a marked section of it. @@ -253,7 +249,7 @@ var WebAudioSound = new Class({ * * @return {boolean} Whether the sound started playing successfully. */ - play: function (markerName, config) + play(markerName, config) { if (!BaseSound.prototype.play.call(this, markerName, config)) { @@ -267,7 +263,7 @@ var WebAudioSound = new Class({ this.emit(Events.PLAY, this); return true; - }, + } /** * Pauses the sound. @@ -278,7 +274,7 @@ var WebAudioSound = new Class({ * * @return {boolean} Whether the sound was paused successfully. */ - pause: function () + pause() { if (this.manager.context.currentTime < this.startTime) { @@ -297,7 +293,7 @@ var WebAudioSound = new Class({ this.emit(Events.PAUSE, this); return true; - }, + } /** * Resumes the sound. @@ -308,7 +304,7 @@ var WebAudioSound = new Class({ * * @return {boolean} Whether the sound was resumed successfully. */ - resume: function () + resume() { if (this.manager.context.currentTime < this.startTime) { @@ -326,7 +322,7 @@ var WebAudioSound = new Class({ this.emit(Events.RESUME, this); return true; - }, + } /** * Stop playing this sound. @@ -337,7 +333,7 @@ var WebAudioSound = new Class({ * * @return {boolean} Whether the sound was stopped successfully. */ - stop: function () + stop() { if (!BaseSound.prototype.stop.call(this)) { @@ -350,7 +346,7 @@ var WebAudioSound = new Class({ this.emit(Events.STOP, this); return true; - }, + } /** * Used internally. @@ -359,7 +355,7 @@ var WebAudioSound = new Class({ * @private * @since 3.0.0 */ - createAndStartBufferSource: function () + createAndStartBufferSource() { var seek = this.currentConfig.seek; var delay = this.currentConfig.delay; @@ -376,7 +372,7 @@ var WebAudioSound = new Class({ this.source.start(Math.max(0, when), Math.max(0, offset), Math.max(0, duration)); this.resetConfig(); - }, + } /** * This method is only used internally and it creates a looping buffer source. @@ -384,7 +380,7 @@ var WebAudioSound = new Class({ * @method Phaser.Sound.WebAudioSound#createAndStartLoopBufferSource * @since 3.0.0 */ - createAndStartLoopBufferSource: function () + createAndStartLoopBufferSource() { var when = this.getLoopTime(); var offset = this.currentMarker ? this.currentMarker.start : 0; @@ -394,7 +390,7 @@ var WebAudioSound = new Class({ 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)); - }, + } /** * This method is only used internally and it creates a buffer source. @@ -404,7 +400,7 @@ var WebAudioSound = new Class({ * * @return {AudioBufferSourceNode} */ - createBufferSource: function () + createBufferSource() { var _this = this; var source = this.manager.context.createBufferSource(); @@ -434,7 +430,7 @@ var WebAudioSound = new Class({ }; return source; - }, + } /** * This method is only used internally and it stops and removes a buffer source. @@ -442,7 +438,7 @@ var WebAudioSound = new Class({ * @method Phaser.Sound.WebAudioSound#stopAndRemoveBufferSource * @since 3.0.0 */ - stopAndRemoveBufferSource: function () + stopAndRemoveBufferSource() { if (this.source) { @@ -459,7 +455,7 @@ var WebAudioSound = new Class({ this.hasEnded = false; this.stopAndRemoveLoopBufferSource(); - }, + } /** * This method is only used internally and it stops and removes a looping buffer source. @@ -467,7 +463,7 @@ var WebAudioSound = new Class({ * @method Phaser.Sound.WebAudioSound#stopAndRemoveLoopBufferSource * @since 3.0.0 */ - stopAndRemoveLoopBufferSource: function () + stopAndRemoveLoopBufferSource() { if (this.loopSource) { @@ -477,7 +473,7 @@ var WebAudioSound = new Class({ } this.loopTime = 0; - }, + } /** * Method used internally for applying config values to some of the sound properties. @@ -485,7 +481,7 @@ var WebAudioSound = new Class({ * @method Phaser.Sound.WebAudioSound#applyConfig * @since 3.0.0 */ - applyConfig: function () + applyConfig() { this.rateUpdates.length = 0; @@ -523,7 +519,7 @@ var WebAudioSound = new Class({ } BaseSound.prototype.applyConfig.call(this); - }, + } /** * Sets the x position of this Sound in Spatial Audio space. @@ -540,28 +536,26 @@ var WebAudioSound = new Class({ * @type {number} * @since 3.60.0 */ - x: { - get: function () + get x() + { + if (this.spatialNode) { - if (this.spatialNode) - { - return this.spatialNode.positionX; - } - else - { - return 0; - } - }, + return this.spatialNode.positionX; + } + else + { + return 0; + } + } - set: function (value) + set x(value) + { + if (this.spatialNode) { - if (this.spatialNode) - { - this.spatialNode.positionX.value = value; - } + this.spatialNode.positionX.value = value; } - }, + } /** * Sets the y position of this Sound in Spatial Audio space. @@ -578,28 +572,26 @@ var WebAudioSound = new Class({ * @type {number} * @since 3.60.0 */ - y: { - get: function () + get y() + { + if (this.spatialNode) { - if (this.spatialNode) - { - return this.spatialNode.positionY; - } - else - { - return 0; - } - }, + return this.spatialNode.positionY; + } + else + { + return 0; + } + } - set: function (value) + set y(value) + { + if (this.spatialNode) { - if (this.spatialNode) - { - this.spatialNode.positionY.value = value; - } + this.spatialNode.positionY.value = value; } - }, + } /** * Update method called automatically by sound manager on every game step. @@ -609,7 +601,7 @@ var WebAudioSound = new Class({ * @fires Phaser.Sound.Events#LOOPED * @since 3.0.0 */ - update: function () + update() { if (this.isPlaying && this.spatialSource) { @@ -651,7 +643,7 @@ var WebAudioSound = new Class({ this.emit(Events.LOOPED, this); } - }, + } /** * Calls Phaser.Sound.BaseSound#destroy method @@ -660,7 +652,7 @@ var WebAudioSound = new Class({ * @method Phaser.Sound.WebAudioSound#destroy * @since 3.0.0 */ - destroy: function () + destroy() { if (this.pendingRemove) { @@ -691,7 +683,7 @@ var WebAudioSound = new Class({ this.rateUpdates.length = 0; this.rateUpdates = null; - }, + } /** * Method used internally to calculate total playback rate of the sound. @@ -699,7 +691,7 @@ var WebAudioSound = new Class({ * @method Phaser.Sound.WebAudioSound#calculateRate * @since 3.0.0 */ - calculateRate: function () + calculateRate() { BaseSound.prototype.calculateRate.call(this); @@ -723,7 +715,7 @@ var WebAudioSound = new Class({ this.createAndStartLoopBufferSource(); } } - }, + } /** * Method used internally for calculating current playback time of a playing sound. @@ -731,7 +723,7 @@ var WebAudioSound = new Class({ * @method Phaser.Sound.WebAudioSound#getCurrentTime * @since 3.0.0 */ - getCurrentTime: function () + getCurrentTime() { var currentTime = 0; @@ -752,7 +744,7 @@ var WebAudioSound = new Class({ } return currentTime; - }, + } /** * Method used internally for calculating the time @@ -761,7 +753,7 @@ var WebAudioSound = new Class({ * @method Phaser.Sound.WebAudioSound#getLoopTime * @since 3.0.0 */ - getLoopTime: function () + getLoopTime() { var lastRateUpdateCurrentTime = 0; @@ -773,7 +765,7 @@ var WebAudioSound = new Class({ var lastRateUpdate = this.rateUpdates[this.rateUpdates.length - 1]; return this.playTime + lastRateUpdate.time + (this.duration - lastRateUpdateCurrentTime) / lastRateUpdate.rate; - }, + } /** * Rate at which this Sound will be played. @@ -786,23 +778,20 @@ var WebAudioSound = new Class({ * @fires Phaser.Sound.Events#RATE * @since 3.0.0 */ - rate: { - get: function () - { - return this.currentConfig.rate; - }, - - set: function (value) - { - this.currentConfig.rate = value; + get rate() + { + return this.currentConfig.rate; + } - this.calculateRate(); + set rate(value) + { + this.currentConfig.rate = value; - this.emit(Events.RATE, this, value); - } + this.calculateRate(); - }, + this.emit(Events.RATE, this, value); + } /** * Sets the playback rate of this Sound. @@ -818,12 +807,12 @@ var WebAudioSound = new Class({ * * @return {this} This Sound instance. */ - setRate: function (value) + setRate(value) { this.rate = value; return this; - }, + } /** * The detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -835,23 +824,20 @@ var WebAudioSound = new Class({ * @fires Phaser.Sound.Events#DETUNE * @since 3.0.0 */ - detune: { - - get: function () - { - return this.currentConfig.detune; - }, - set: function (value) - { - this.currentConfig.detune = value; + get detune() + { + return this.currentConfig.detune; + } - this.calculateRate(); + set detune(value) + { + this.currentConfig.detune = value; - this.emit(Events.DETUNE, this, value); - } + this.calculateRate(); - }, + this.emit(Events.DETUNE, this, value); + } /** * Sets the detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -865,12 +851,12 @@ var WebAudioSound = new Class({ * * @return {this} This Sound instance. */ - setDetune: function (value) + setDetune(value) { this.detune = value; return this; - }, + } /** * Boolean indicating whether the sound is muted or not. @@ -882,22 +868,19 @@ var WebAudioSound = new Class({ * @fires Phaser.Sound.Events#MUTE * @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); + get mute() + { + return (this.muteNode.gain.value === 0); + } - this.emit(Events.MUTE, this, value); - } + set mute(value) + { + this.currentConfig.mute = value; + this.muteNode.gain.setValueAtTime(value ? 0 : 1, 0); - }, + this.emit(Events.MUTE, this, value); + } /** * Sets the muted state of this Sound. @@ -910,12 +893,12 @@ var WebAudioSound = new Class({ * * @return {this} This Sound instance. */ - setMute: function (value) + setMute(value) { this.mute = value; return this; - }, + } /** * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). @@ -926,21 +909,19 @@ var WebAudioSound = new Class({ * @fires Phaser.Sound.Events#VOLUME * @since 3.0.0 */ - volume: { - get: function () - { - return this.volumeNode.gain.value; - }, + get volume() + { + return this.volumeNode.gain.value; + } - set: function (value) - { - this.currentConfig.volume = value; - this.volumeNode.gain.setValueAtTime(value, 0); + set volume(value) + { + this.currentConfig.volume = value; + this.volumeNode.gain.setValueAtTime(value, 0); - this.emit(Events.VOLUME, this, value); - } - }, + this.emit(Events.VOLUME, this, value); + } /** * Sets the volume of this Sound. @@ -953,12 +934,12 @@ var WebAudioSound = new Class({ * * @return {this} This Sound instance. */ - setVolume: function (value) + setVolume(value) { this.volume = value; return this; - }, + } /** * Property representing the position of playback for this sound, in seconds. @@ -971,52 +952,50 @@ var WebAudioSound = new Class({ * @fires Phaser.Sound.Events#SEEK * @since 3.0.0 */ - seek: { - get: function () + get seek() + { + if (this.isPlaying) { - 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 + if (this.manager.context.currentTime < this.startTime) { - return 0; + return this.startTime - this.playTime; } - }, - set: function (value) + return this.getCurrentTime(); + } + else if (this.isPaused) { - if (this.manager.context.currentTime < this.startTime) - { - return; - } + return this.currentConfig.seek; + } + else + { + return 0; + } + } - if (this.isPlaying || this.isPaused) - { - value = Math.min(Math.max(0, value), this.duration); + set seek(value) + { + if (this.manager.context.currentTime < this.startTime) + { + return; + } - this.currentConfig.seek = value; + if (this.isPlaying || this.isPaused) + { + value = Math.min(Math.max(0, value), this.duration); - if (this.isPlaying) - { - this.stopAndRemoveBufferSource(); - this.createAndStartBufferSource(); - } + this.currentConfig.seek = value; - this.emit(Events.SEEK, this, value); + if (this.isPlaying) + { + this.stopAndRemoveBufferSource(); + this.createAndStartBufferSource(); } + + this.emit(Events.SEEK, this, value); } - }, + } /** * Seeks to a specific point in this sound. @@ -1029,12 +1008,12 @@ var WebAudioSound = new Class({ * * @return {this} This Sound instance. */ - setSeek: function (value) + setSeek(value) { this.seek = value; return this; - }, + } /** * Flag indicating whether or not the sound or current sound marker will loop. @@ -1045,30 +1024,28 @@ var WebAudioSound = new Class({ * @fires Phaser.Sound.Events#LOOP * @since 3.0.0 */ - loop: { - get: function () - { - return this.currentConfig.loop; - }, + get loop() + { + return this.currentConfig.loop; + } - set: function (value) + set loop(value) + { + this.currentConfig.loop = value; + + if (this.isPlaying) { - this.currentConfig.loop = value; + this.stopAndRemoveLoopBufferSource(); - if (this.isPlaying) + if (value) { - this.stopAndRemoveLoopBufferSource(); - - if (value) - { - this.createAndStartLoopBufferSource(); - } + this.createAndStartLoopBufferSource(); } - - this.emit(Events.LOOP, this, value); } - }, + + this.emit(Events.LOOP, this, value); + } /** * Sets the loop state of this Sound. @@ -1081,12 +1058,12 @@ var WebAudioSound = new Class({ * * @return {this} This Sound instance. */ - setLoop: function (value) + setLoop(value) { this.loop = value; return this; - }, + } /** * Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). @@ -1099,32 +1076,30 @@ var WebAudioSound = new Class({ * @fires Phaser.Sound.Events#PAN * @since 3.50.0 */ - pan: { - get: function () + get pan() + { + if (this.pannerNode) { - if (this.pannerNode) - { - return this.pannerNode.pan.value; - } - else - { - return 0; - } - }, - - set: function (value) + return this.pannerNode.pan.value; + } + else { - this.currentConfig.pan = value; + return 0; + } + } - if (this.pannerNode) - { - this.pannerNode.pan.setValueAtTime(value, this.manager.context.currentTime); - } + set pan(value) + { + this.currentConfig.pan = value; - this.emit(Events.PAN, this, value); + if (this.pannerNode) + { + this.pannerNode.pan.setValueAtTime(value, this.manager.context.currentTime); } - }, + + this.emit(Events.PAN, this, value); + } /** * Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). @@ -1139,13 +1114,13 @@ var WebAudioSound = new Class({ * * @return {this} This Sound instance. */ - setPan: function (value) + setPan(value) { this.pan = value; return this; } -}); +}; module.exports = WebAudioSound; diff --git a/src/sound/webaudio/WebAudioSoundManager.js b/src/sound/webaudio/WebAudioSoundManager.js index 4e8d83219a..ace9571fda 100644 --- a/src/sound/webaudio/WebAudioSoundManager.js +++ b/src/sound/webaudio/WebAudioSoundManager.js @@ -29,13 +29,9 @@ var GetFastValue = require('../../utils/object/GetFastValue'); * * @param {Phaser.Game} game - Reference to the current game instance. */ -var WebAudioSoundManager = new Class({ +var WebAudioSoundManager = class extends BaseSoundManager { - Extends: BaseSoundManager, - - initialize: - - function WebAudioSoundManager (game) + constructor(game) { /** * The AudioContext being used for playback. @@ -79,7 +75,7 @@ var WebAudioSoundManager = new Class({ this.locked = this.context.state === 'suspended'; - BaseSoundManager.call(this, game); + super(game); if (this.locked) { @@ -94,7 +90,7 @@ var WebAudioSoundManager = new Class({ } game.events.on(GameEvents.VISIBLE, this.onGameVisible, this); - }, + } /** * Internal handler for Phaser.Core.Events#VISIBLE. @@ -106,7 +102,7 @@ var WebAudioSoundManager = new Class({ * @private * @since 3.88.0 */ - onGameVisible: function () + onGameVisible() { var context = this.context; @@ -120,7 +116,7 @@ var WebAudioSoundManager = new Class({ } }, 100); - }, + } /** * Method responsible for instantiating and returning AudioContext instance. @@ -136,7 +132,7 @@ var WebAudioSoundManager = new Class({ * * @return {AudioContext} The AudioContext instance to be used for playback. */ - createAudioContext: function (game) + createAudioContext(game) { var audioConfig = game.config.audio; @@ -155,7 +151,7 @@ var WebAudioSoundManager = new Class({ { return new window.webkitAudioContext(); } - }, + } /** * This method takes a new AudioContext reference and then sets @@ -171,7 +167,7 @@ var WebAudioSoundManager = new Class({ * * @return {this} The WebAudioSoundManager instance. */ - setAudioContext: function (context) + setAudioContext(context) { if (this.context) { @@ -199,7 +195,7 @@ var WebAudioSoundManager = new Class({ this.destination = this.masterMuteNode; return this; - }, + } /** * Adds a new sound into the sound manager. @@ -212,14 +208,14 @@ var WebAudioSoundManager = new Class({ * * @return {Phaser.Sound.WebAudioSound} The new sound instance. */ - add: function (key, config) + add(key, config) { var sound = new WebAudioSound(this, key, config); this.sounds.push(sound); return sound; - }, + } /** * Decode audio data into a format ready for playback via Web Audio. @@ -243,7 +239,7 @@ var WebAudioSoundManager = new Class({ * @param {(Phaser.Types.Sound.DecodeAudioConfig[]|string)} [audioKey] - The string-based key to be used to reference the decoded audio in the audio cache, or an array of audio config objects. * @param {(ArrayBuffer|string)} [audioData] - The audio data, either a base64 encoded string, an audio media-type data uri, or an ArrayBuffer instance. */ - decodeAudio: function (audioKey, audioData) + decodeAudio(audioKey, audioData) { var audioFiles; @@ -300,7 +296,7 @@ var WebAudioSoundManager = new Class({ this.context.decodeAudioData(data, success, failure); } - }, + } /** * Sets the X and Y position of the Spatial Audio listener on this Web Audios context. @@ -317,7 +313,7 @@ var WebAudioSoundManager = new Class({ * @param {number} [x] - The x position of the Spatial Audio listener. * @param {number} [y] - The y position of the Spatial Audio listener. */ - setListenerPosition: function (x, y) + setListenerPosition(x, y) { if (x === undefined) { x = this.game.scale.width / 2; } if (y === undefined) { y = this.game.scale.height / 2; } @@ -325,7 +321,7 @@ var WebAudioSoundManager = new Class({ this.listenerPosition.set(x, y); return this; - }, + } /** * Unlocks Web Audio API on the initial input event. @@ -335,7 +331,7 @@ var WebAudioSoundManager = new Class({ * @method Phaser.Sound.WebAudioSoundManager#unlock * @since 3.0.0 */ - unlock: function () + unlock() { var _this = this; @@ -376,7 +372,7 @@ var WebAudioSoundManager = new Class({ body.addEventListener('mouseup', unlockHandler, false); body.addEventListener('keydown', unlockHandler, false); } - }, + } /** * Method used internally for pausing sound manager if @@ -386,13 +382,13 @@ var WebAudioSoundManager = new Class({ * @protected * @since 3.0.0 */ - onBlur: function () + onBlur() { if (!this.locked) { this.context.suspend(); } - }, + } /** * Method used internally for resuming sound manager if @@ -402,7 +398,7 @@ var WebAudioSoundManager = new Class({ * @protected * @since 3.0.0 */ - onFocus: function () + onFocus() { var context = this.context; @@ -410,7 +406,7 @@ var WebAudioSoundManager = new Class({ { context.resume(); } - }, + } /** * Update method called on every game step. @@ -425,7 +421,7 @@ var WebAudioSoundManager = new Class({ * @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) + update(time, delta) { var listener = this.context.listener; @@ -451,7 +447,7 @@ var WebAudioSoundManager = new Class({ { this.onFocus(); } - }, + } /** * Calls Phaser.Sound.BaseSoundManager#destroy method @@ -460,7 +456,7 @@ var WebAudioSoundManager = new Class({ * @method Phaser.Sound.WebAudioSoundManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.destination = null; this.masterVolumeNode.disconnect(); @@ -485,7 +481,7 @@ var WebAudioSoundManager = new Class({ this.game.events.off(GameEvents.VISIBLE, this.onGameVisible, this); BaseSoundManager.prototype.destroy.call(this); - }, + } /** * Sets the muted state of all this Sound Manager. @@ -498,12 +494,12 @@ var WebAudioSoundManager = new Class({ * * @return {Phaser.Sound.WebAudioSoundManager} This Sound Manager. */ - setMute: function (value) + setMute(value) { this.mute = value; return this; - }, + } /** * @name Phaser.Sound.WebAudioSoundManager#mute @@ -511,21 +507,18 @@ var WebAudioSoundManager = new Class({ * @fires Phaser.Sound.Events#GLOBAL_MUTE * @since 3.0.0 */ - mute: { - get: function () - { - return (this.masterMuteNode.gain.value === 0); - }, - - set: function (value) - { - this.masterMuteNode.gain.setValueAtTime(value ? 0 : 1, 0); + get mute() + { + return (this.masterMuteNode.gain.value === 0); + } - this.emit(Events.GLOBAL_MUTE, this, value); - } + set mute(value) + { + this.masterMuteNode.gain.setValueAtTime(value ? 0 : 1, 0); - }, + this.emit(Events.GLOBAL_MUTE, this, value); + } /** * Sets the volume of this Sound Manager. @@ -538,12 +531,12 @@ var WebAudioSoundManager = new Class({ * * @return {Phaser.Sound.WebAudioSoundManager} This Sound Manager. */ - setVolume: function (value) + setVolume(value) { this.volume = value; return this; - }, + } /** * @name Phaser.Sound.WebAudioSoundManager#volume @@ -551,22 +544,19 @@ var WebAudioSoundManager = new Class({ * @fires Phaser.Sound.Events#GLOBAL_VOLUME * @since 3.0.0 */ - volume: { - get: function () - { - return this.masterVolumeNode.gain.value; - }, - - set: function (value) - { - this.masterVolumeNode.gain.setValueAtTime(value, 0); + get volume() + { + return this.masterVolumeNode.gain.value; + } - this.emit(Events.GLOBAL_VOLUME, this, value); - } + set volume(value) + { + this.masterVolumeNode.gain.setValueAtTime(value, 0); + this.emit(Events.GLOBAL_VOLUME, this, value); } -}); +}; module.exports = WebAudioSoundManager; diff --git a/src/structs/List.js b/src/structs/List.js index e3d6b861fb..cbc9a718f1 100644 --- a/src/structs/List.js +++ b/src/structs/List.js @@ -29,11 +29,9 @@ var StableSort = require('../utils/array/StableSort'); * * @param {*} parent - The parent of this list. */ -var List = new Class({ +var List = class { - initialize: - - function List (parent) + constructor(parent) { /** * The parent of this list. @@ -94,7 +92,7 @@ var List = new Class({ * @since 3.4.0 */ this._sortKey = ''; - }, + } /** * Adds the given item to the end of the list. Each item must be unique. @@ -107,7 +105,7 @@ var List = new Class({ * * @return {*} The list's underlying array. */ - add: function (child, skipCallback) + add(child, skipCallback) { if (skipCallback) { @@ -117,7 +115,7 @@ var List = new Class({ { return ArrayUtils.Add(this.list, child, 0, this.addCallback, this); } - }, + } /** * Adds an item to list, starting at a specified index. Each item must be unique within the list. @@ -133,7 +131,7 @@ var List = new Class({ * * @return {*} The List's underlying array. */ - addAt: function (child, index, skipCallback) + addAt(child, index, skipCallback) { if (skipCallback) { @@ -143,7 +141,7 @@ var List = new Class({ { return ArrayUtils.AddAt(this.list, child, index, 0, this.addCallback, this); } - }, + } /** * Retrieves the item at a given position inside the List. @@ -157,10 +155,10 @@ var List = new Class({ * * @return {*} The retrieved item, or `undefined` if it's outside the List's bounds. */ - getAt: function (index) + getAt(index) { return this.list[index]; - }, + } /** * Locates an item within the List and returns its index. @@ -174,11 +172,11 @@ var List = new Class({ * * @return {number} The index of the item within the List, or -1 if it's not in the List. */ - getIndex: function (child) + getIndex(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. @@ -194,7 +192,7 @@ var List = new Class({ * * @return {Phaser.Structs.List} This List object. */ - sort: function (property, handler) + sort(property, handler) { if (!property) { @@ -212,7 +210,7 @@ var List = new Class({ StableSort(this.list, handler); return this; - }, + } /** * Searches for the first instance of a child with its `name` @@ -228,10 +226,10 @@ var List = new Class({ * * @return {?*} The first child with a matching name, or null if none were found. */ - getByName: function (name) + getByName(name) { return ArrayUtils.GetFirst(this.list, 'name', name); - }, + } /** * Returns a random child from the group. @@ -246,10 +244,10 @@ var List = new Class({ * * @return {?*} A random child of this Group. */ - getRandom: function (startIndex, length) + getRandom(startIndex, length) { return ArrayUtils.GetRandom(this.list, startIndex, length); - }, + } /** * Returns the first element in a given part of the List which matches a specific criterion. @@ -266,10 +264,10 @@ var List = new Class({ * * @return {?*} The first item which matches the given criterion, or `null` if no such item exists. */ - getFirst: function (property, value, startIndex, endIndex) + getFirst(property, value, startIndex, endIndex) { return ArrayUtils.GetFirst(this.list, property, value, startIndex, endIndex); - }, + } /** * Returns all children in this List. @@ -298,10 +296,10 @@ var List = new Class({ * * @return {Array.<*>} All items of the List which match the given criterion, if any. */ - getAll: function (property, value, startIndex, endIndex) + getAll(property, value, startIndex, endIndex) { return ArrayUtils.GetAll(this.list, property, value, startIndex, endIndex); - }, + } /** * Returns the total number of items in the List which have a property matching the given value. @@ -316,10 +314,10 @@ var List = new Class({ * * @return {number} The total number of matching elements. */ - count: function (property, value) + count(property, value) { return ArrayUtils.CountAllMatching(this.list, property, value); - }, + } /** * Swaps the positions of two items in the list. @@ -332,10 +330,10 @@ var List = new Class({ * @param {*} child1 - The first item to swap. * @param {*} child2 - The second item to swap. */ - swap: function (child1, child2) + swap(child1, child2) { ArrayUtils.Swap(this.list, child1, child2); - }, + } /** * Moves an item in the List to a new position. @@ -350,10 +348,10 @@ var List = new Class({ * * @return {*} The item that was moved. */ - moveTo: function (child, index) + moveTo(child, index) { return ArrayUtils.MoveTo(this.list, child, index); - }, + } /** * Moves an item above another one in the List. @@ -368,10 +366,10 @@ var List = new Class({ * @param {*} child1 - The element to move above base element. * @param {*} child2 - The base element. */ - moveAbove: function (child1, child2) + moveAbove(child1, child2) { return ArrayUtils.MoveAbove(this.list, child1, child2); - }, + } /** * Moves an item below another one in the List. @@ -386,10 +384,10 @@ var List = new Class({ * @param {*} child1 - The element to move below base element. * @param {*} child2 - The base element. */ - moveBelow: function (child1, child2) + moveBelow(child1, child2) { return ArrayUtils.MoveBelow(this.list, child1, child2); - }, + } /** * Removes one or many items from the List. @@ -402,7 +400,7 @@ var List = new Class({ * * @return {*} The item, or array of items, which were successfully removed from the List. */ - remove: function (child, skipCallback) + remove(child, skipCallback) { if (skipCallback) { @@ -412,7 +410,7 @@ var List = new Class({ { return ArrayUtils.Remove(this.list, child, this.removeCallback, this); } - }, + } /** * Removes the item at the given position in the List. @@ -427,7 +425,7 @@ var List = new Class({ * * @return {*} The item that was removed. */ - removeAt: function (index, skipCallback) + removeAt(index, skipCallback) { if (skipCallback) { @@ -437,7 +435,7 @@ var List = new Class({ { return ArrayUtils.RemoveAt(this.list, index, this.removeCallback, this); } - }, + } /** * Removes the items within the given range in the List. @@ -453,7 +451,7 @@ var List = new Class({ * * @return {Array.<*>} An array of the items which were removed. */ - removeBetween: function (startIndex, endIndex, skipCallback) + removeBetween(startIndex, endIndex, skipCallback) { if (skipCallback) { @@ -463,7 +461,7 @@ var List = new Class({ { return ArrayUtils.RemoveBetween(this.list, startIndex, endIndex, this.removeCallback, this); } - }, + } /** * Removes all the items. @@ -475,7 +473,7 @@ var List = new Class({ * * @return {this} This List object. */ - removeAll: function (skipCallback) + removeAll(skipCallback) { var i = this.list.length; @@ -485,7 +483,7 @@ var List = new Class({ } return this; - }, + } /** * Brings the given child to the top of this List. @@ -499,10 +497,10 @@ var List = new Class({ * * @return {*} The item which was moved. */ - bringToTop: function (child) + bringToTop(child) { return ArrayUtils.BringToTop(this.list, child); - }, + } /** * Sends the given child to the bottom of this List. @@ -516,10 +514,10 @@ var List = new Class({ * * @return {*} The item which was moved. */ - sendToBack: function (child) + sendToBack(child) { return ArrayUtils.SendToBack(this.list, child); - }, + } /** * Moves the given child up one place in this group unless it's already at the top. @@ -533,12 +531,12 @@ var List = new Class({ * * @return {*} The item which was moved. */ - moveUp: function (child) + moveUp(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. @@ -552,12 +550,12 @@ var List = new Class({ * * @return {*} The item which was moved. */ - moveDown: function (child) + moveDown(child) { ArrayUtils.MoveDown(this.list, child); return child; - }, + } /** * Reverses the order of all children in this List. @@ -569,12 +567,12 @@ var List = new Class({ * * @return {Phaser.Structs.List} This List object. */ - reverse: function () + reverse() { this.list.reverse(); return this; - }, + } /** * Shuffles the items in the list. @@ -586,12 +584,12 @@ var List = new Class({ * * @return {Phaser.Structs.List} This List object. */ - shuffle: function () + shuffle() { 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. @@ -606,10 +604,10 @@ var List = new Class({ * * @return {*} Returns the oldChild that was replaced within this group. */ - replace: function (oldChild, newChild) + replace(oldChild, newChild) { return ArrayUtils.Replace(this.list, oldChild, newChild); - }, + } /** * Checks if an item exists within the List. @@ -623,10 +621,10 @@ var List = new Class({ * * @return {boolean} `true` if the item is found in the list, otherwise `false`. */ - exists: function (child) + exists(child) { return (this.list.indexOf(child) > -1); - }, + } /** * Sets the property `key` to the given value on all members of this List. @@ -641,12 +639,12 @@ var List = new Class({ * @param {number} [startIndex] - The first child index to start the search from. * @param {number} [endIndex] - The last child index to search up until. */ - setAll: function (property, value, startIndex, endIndex) + setAll(property, value, startIndex, endIndex) { ArrayUtils.SetAll(this.list, property, value, startIndex, endIndex); return this; - }, + } /** * Passes all children to the given callback. @@ -660,7 +658,7 @@ var List = new Class({ * @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) + each(callback, context) { var args = [ null ]; @@ -675,7 +673,7 @@ var List = new Class({ callback.apply(context, args); } - }, + } /** * Clears the List and recreates its internal array. @@ -683,12 +681,12 @@ var List = new Class({ * @method Phaser.Structs.List#shutdown * @since 3.0.0 */ - shutdown: function () + shutdown() { this.removeAll(); this.list = []; - }, + } /** * Destroys this List. @@ -696,14 +694,14 @@ var List = new Class({ * @method Phaser.Structs.List#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.removeAll(); this.parent = null; this.addCallback = null; this.removeCallback = null; - }, + } /** * The number of items inside the List. @@ -713,14 +711,11 @@ var List = new Class({ * @readonly * @since 3.0.0 */ - length: { - get: function () - { - return this.list.length; - } - - }, + get length() + { + return this.list.length; + } /** * The first item in the List or `null` for an empty List. @@ -731,23 +726,20 @@ var List = new Class({ * @readonly * @since 3.0.0 */ - first: { - get: function () - { - this.position = 0; + get first() + { + this.position = 0; - if (this.list.length > 0) - { - return this.list[0]; - } - else - { - return null; - } + if (this.list.length > 0) + { + return this.list[0]; } - - }, + else + { + return null; + } + } /** * The last item in the List, or `null` for an empty List. @@ -758,23 +750,20 @@ var List = new Class({ * @readonly * @since 3.0.0 */ - last: { - get: function () + get last() + { + if (this.list.length > 0) { - if (this.list.length > 0) - { - this.position = this.list.length - 1; + this.position = this.list.length - 1; - return this.list[this.position]; - } - else - { - return null; - } + return this.list[this.position]; } - - }, + else + { + return null; + } + } /** * The next item in the List, or `null` if the entire List has been traversed. @@ -787,23 +776,20 @@ var List = new Class({ * @readonly * @since 3.0.0 */ - next: { - get: function () + get next() + { + if (this.position < this.list.length) { - if (this.position < this.list.length) - { - this.position++; + this.position++; - return this.list[this.position]; - } - else - { - return null; - } + return this.list[this.position]; } - - }, + else + { + return null; + } + } /** * The previous item in the List, or `null` if the entire List has been traversed. @@ -816,24 +802,21 @@ var List = new Class({ * @readonly * @since 3.0.0 */ - previous: { - get: function () + get previous() + { + if (this.position > 0) { - if (this.position > 0) - { - this.position--; + this.position--; - return this.list[this.position]; - } - else - { - return null; - } + return this.list[this.position]; + } + else + { + return null; } - } -}); +}; module.exports = List; diff --git a/src/structs/Map.js b/src/structs/Map.js index 17bb6df9f7..2ce84860c2 100644 --- a/src/structs/Map.js +++ b/src/structs/Map.js @@ -38,11 +38,9 @@ var Class = require('../utils/Class'); * * @param {Array.<*>} elements - An optional array of key-value pairs to populate this Map with. */ -var Map = new Class({ +var Map = class { - initialize: - - function Map (elements) + constructor(elements) { /** * The entries in this Map. @@ -67,7 +65,7 @@ var Map = new Class({ this.size = 0; this.setAll(elements); - }, + } /** * Adds all the elements in the given array to this Map. @@ -85,7 +83,7 @@ var Map = new Class({ * * @return {this} This Map object. */ - setAll: function (elements) + setAll(elements) { if (Array.isArray(elements)) { @@ -96,7 +94,7 @@ var Map = new Class({ } return this; - }, + } /** * Adds an element with a specified `key` and `value` to this Map. @@ -117,7 +115,7 @@ var Map = new Class({ * * @return {this} This Map object. */ - set: function (key, value) + set(key, value) { if (!this.has(key)) { @@ -127,7 +125,7 @@ var Map = new Class({ this.entries[key] = value; return this; - }, + } /** * Returns the value associated to the `key`, or `undefined` if there is none. @@ -142,13 +140,13 @@ var Map = new Class({ * * @return {*} The element associated with the specified key or `undefined` if the key can't be found in this Map object. */ - get: function (key) + get(key) { if (this.has(key)) { return this.entries[key]; } - }, + } /** * Returns an `Array` of all the values stored in this Map. @@ -160,7 +158,7 @@ var Map = new Class({ * * @return {Array.<*>} An array of the values stored in this Map. */ - getArray: function () + getArray() { var output = []; var entries = this.entries; @@ -171,7 +169,7 @@ var Map = new Class({ } return output; - }, + } /** * Returns a boolean indicating whether an element with the specified key exists or not. @@ -185,10 +183,10 @@ var Map = new Class({ * * @return {boolean} Returns `true` if an element with the specified key exists in this Map, otherwise `false`. */ - has: function (key) + has(key) { return (this.entries.hasOwnProperty(key)); - }, + } /** * Delete the specified element from this Map. @@ -203,7 +201,7 @@ var Map = new Class({ * * @return {this} This Map object. */ - delete: function (key) + delete(key) { if (this.has(key)) { @@ -212,7 +210,7 @@ var Map = new Class({ } return this; - }, + } /** * Delete all entries from this Map. @@ -224,7 +222,7 @@ var Map = new Class({ * * @return {this} This Map object. */ - clear: function () + clear() { Object.keys(this.entries).forEach(function (prop) { @@ -235,7 +233,7 @@ var Map = new Class({ this.size = 0; return this; - }, + } /** * Returns all entries keys in this Map. @@ -247,10 +245,10 @@ var Map = new Class({ * * @return {string[]} Array containing entries' keys. */ - keys: function () + keys() { return Object.keys(this.entries); - }, + } /** * Returns an `Array` of all entries. @@ -262,7 +260,7 @@ var Map = new Class({ * * @return {Array.<*>} An `Array` of entries. */ - values: function () + values() { var output = []; var entries = this.entries; @@ -273,7 +271,7 @@ var Map = new Class({ } return output; - }, + } /** * Dumps the contents of this Map to the console via `console.group`. @@ -281,7 +279,7 @@ var Map = new Class({ * @method Phaser.Structs.Map#dump * @since 3.0.0 */ - dump: function () + dump() { var entries = this.entries; @@ -295,7 +293,7 @@ var Map = new Class({ // eslint-disable-next-line no-console console.groupEnd(); - }, + } /** * Iterates through all entries in this Map, passing each one to the given callback. @@ -312,7 +310,7 @@ var Map = new Class({ * * @return {this} This Map object. */ - each: function (callback) + each(callback) { var entries = this.entries; @@ -325,7 +323,7 @@ var Map = new Class({ } return this; - }, + } /** * Returns `true` if the value exists within this Map. Otherwise, returns `false`. @@ -339,7 +337,7 @@ var Map = new Class({ * * @return {boolean} `true` if the value is found, otherwise `false`. */ - contains: function (value) + contains(value) { var entries = this.entries; @@ -352,7 +350,7 @@ var Map = new Class({ } return false; - }, + } /** * Merges all new keys from the given Map into this one. @@ -368,7 +366,7 @@ var Map = new Class({ * * @return {this} This Map object. */ - merge: function (map, override) + merge(map, override) { if (override === undefined) { override = false; } @@ -390,6 +388,6 @@ var Map = new Class({ return this; } -}); +}; module.exports = Map; diff --git a/src/structs/ProcessQueue.js b/src/structs/ProcessQueue.js index 222715dfdd..9b79097141 100644 --- a/src/structs/ProcessQueue.js +++ b/src/structs/ProcessQueue.js @@ -29,15 +29,11 @@ var Events = require('./events'); * * @generic T */ -var ProcessQueue = new Class({ +var ProcessQueue = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function ProcessQueue () + constructor() { - EventEmitter.call(this); + super(); /** * The `pending` list is a selection of items which are due to be made 'active' in the next update. @@ -97,7 +93,7 @@ var ProcessQueue = new Class({ * @since 3.50.0 */ this.checkQueue = false; - }, + } /** * Checks the given item to see if it is already active within this Process Queue. @@ -112,10 +108,10 @@ var ProcessQueue = new Class({ * * @return {boolean} `true` if the item is active, otherwise `false`. */ - isActive: function (item) + isActive(item) { return (this._active.indexOf(item) > -1); - }, + } /** * Checks the given item to see if it is already pending addition to this Process Queue. @@ -130,10 +126,10 @@ var ProcessQueue = new Class({ * * @return {boolean} `true` if the item is pending insertion, otherwise `false`. */ - isPending: function (item) + isPending(item) { return (this._toProcess > 0 && this._pending.indexOf(item) > -1); - }, + } /** * Checks the given item to see if it is already pending destruction from this Process Queue. @@ -148,10 +144,10 @@ var ProcessQueue = new Class({ * * @return {boolean} `true` if the item is pending destruction, otherwise `false`. */ - isDestroying: function (item) + isDestroying(item) { return (this._destroy.indexOf(item) > -1); - }, + } /** * Adds a new item to the Process Queue. @@ -168,7 +164,7 @@ var ProcessQueue = new Class({ * * @return {*} The item that was added. */ - add: function (item) + add(item) { // Don't add if already active or pending, but DO add if active AND in the destroy list if (this.checkQueue && (this.isActive(item) && !this.isDestroying(item)) || this.isPending(item)) @@ -181,7 +177,7 @@ var ProcessQueue = new Class({ this._toProcess++; return item; - }, + } /** * Removes an item from the Process Queue. @@ -198,7 +194,7 @@ var ProcessQueue = new Class({ * * @return {*} The item that was removed. */ - remove: function (item) + remove(item) { // Check if it's in the _pending list if (this.isPending(item)) @@ -225,7 +221,7 @@ var ProcessQueue = new Class({ // or isn't pending or active, so cannot be removed anyway return item; - }, + } /** * Removes all active items from this Process Queue. @@ -237,7 +233,7 @@ var ProcessQueue = new Class({ * * @return {this} This Process Queue object. */ - removeAll: function () + removeAll() { var list = this._active; var destroy = this._destroy; @@ -251,7 +247,7 @@ var ProcessQueue = new Class({ } return this; - }, + } /** * Update this queue. First it will process any items awaiting destruction, and remove them. @@ -266,7 +262,7 @@ var ProcessQueue = new Class({ * * @return {Array.<*>} A list of active items. */ - update: function () + update() { if (this._toProcess === 0) { @@ -320,7 +316,7 @@ var ProcessQueue = new Class({ // The owner of this queue can now safely do whatever it needs to with the active list return active; - }, + } /** * Returns the current list of active items. @@ -335,10 +331,10 @@ var ProcessQueue = new Class({ * * @return {Array.<*>} A list of active items. */ - getActive: function () + getActive() { return this._active; - }, + } /** * The number of entries in the active list. @@ -348,14 +344,11 @@ var ProcessQueue = new Class({ * @readonly * @since 3.20.0 */ - length: { - - get: function () - { - return this._active.length; - } - }, + get length() + { + return this._active.length; + } /** * Immediately destroys this process queue, clearing all of its internal arrays and resetting the process totals. @@ -363,7 +356,7 @@ var ProcessQueue = new Class({ * @method Phaser.Structs.ProcessQueue#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this._toProcess = 0; @@ -372,6 +365,6 @@ var ProcessQueue = new Class({ this._destroy = []; } -}); +}; module.exports = ProcessQueue; diff --git a/src/structs/Size.js b/src/structs/Size.js index f4c2bb7bdc..1fe039f186 100644 --- a/src/structs/Size.js +++ b/src/structs/Size.js @@ -27,11 +27,9 @@ var Vector2 = require('../math/Vector2'); * @param {number} [aspectMode=0] - The aspect mode of the Size component. Defaults to 0, no mode. * @param {any} [parent=null] - The parent of this Size component. Can be any object with public `width` and `height` properties. Dimensions are clamped to keep them within the parent bounds where possible. */ -var Size = new Class({ +var Size = class { - initialize: - - function Size (width, height, aspectMode, parent) + constructor(width, height, aspectMode, parent) { if (width === undefined) { width = 0; } if (height === undefined) { height = width; } @@ -151,7 +149,7 @@ var Size = new Class({ * @since 3.16.0 */ this.snapTo = new Vector2(); - }, + } /** * Sets the aspect mode of this Size component. @@ -175,14 +173,14 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setAspectMode: function (value) + setAspectMode(value) { if (value === undefined) { value = 0; } this.aspectMode = value; return this.setSize(this._width, this._height); - }, + } /** * By setting snap values, when this Size component is modified its dimensions will automatically @@ -204,7 +202,7 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setSnap: function (snapWidth, snapHeight) + setSnap(snapWidth, snapHeight) { if (snapWidth === undefined) { snapWidth = 0; } if (snapHeight === undefined) { snapHeight = snapWidth; } @@ -212,7 +210,7 @@ var Size = new Class({ this.snapTo.set(snapWidth, snapHeight); return this.setSize(this._width, this._height); - }, + } /** * Sets, or clears, the parent of this Size component. @@ -237,12 +235,12 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setParent: function (parent) + setParent(parent) { this._parent = parent; return this.setSize(this._width, this._height); - }, + } /** * Set the minimum width and height values this Size component will allow. @@ -262,7 +260,7 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setMin: function (width, height) + setMin(width, height) { if (width === undefined) { width = 0; } if (height === undefined) { height = width; } @@ -271,7 +269,7 @@ var Size = new Class({ this.minHeight = Clamp(height, 0, this.maxHeight); return this.setSize(this._width, this._height); - }, + } /** * Set the maximum width and height values this Size component will allow. @@ -289,7 +287,7 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setMax: function (width, height) + setMax(width, height) { if (width === undefined) { width = Number.MAX_VALUE; } if (height === undefined) { height = width; } @@ -298,7 +296,7 @@ var Size = new Class({ this.maxHeight = Clamp(height, this.minHeight, Number.MAX_VALUE); return this.setSize(this._width, this._height); - }, + } /** * Sets the width and height of this Size component based on the aspect mode. @@ -323,7 +321,7 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setSize: function (width, height) + setSize(width, height) { if (width === undefined) { width = 0; } if (height === undefined) { height = width; } @@ -356,7 +354,7 @@ var Size = new Class({ } return this; - }, + } /** * Sets a new aspect ratio, overriding what was there previously. @@ -370,12 +368,12 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setAspectRatio: function (ratio) + setAspectRatio(ratio) { this.aspectRatio = ratio; return this.setSize(this._width, this._height); - }, + } /** * Sets a new width and height for this Size component and updates the aspect ratio based on them. @@ -390,14 +388,14 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - resize: function (width, height) + resize(width, height) { this._width = this.getNewWidth(SnapFloor(width, this.snapTo.x)); this._height = this.getNewHeight(SnapFloor(height, this.snapTo.y)); this.aspectRatio = (this._height === 0) ? 1 : this._width / this._height; return this; - }, + } /** * Takes a new width and passes it through the min/max clamp and then checks it doesn't exceed the parent width. @@ -410,7 +408,7 @@ var Size = new Class({ * * @return {number} The modified width value. */ - getNewWidth: function (value, checkParent) + getNewWidth(value, checkParent) { if (checkParent === undefined) { checkParent = true; } @@ -422,7 +420,7 @@ var Size = new Class({ } return value; - }, + } /** * Takes a new height and passes it through the min/max clamp and then checks it doesn't exceed the parent height. @@ -435,7 +433,7 @@ var Size = new Class({ * * @return {number} The modified height value. */ - getNewHeight: function (value, checkParent) + getNewHeight(value, checkParent) { if (checkParent === undefined) { checkParent = true; } @@ -447,7 +445,7 @@ var Size = new Class({ } return value; - }, + } /** * The current `width` and `height` are adjusted to fit inside the given dimensions, while keeping the aspect ratio. @@ -467,7 +465,7 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - constrain: function (width, height, fit) + constrain(width, height, fit) { if (width === undefined) { width = 0; } if (height === undefined) { height = width; } @@ -516,7 +514,7 @@ var Size = new Class({ this._height = height; return this; - }, + } /** * The current `width` and `height` are adjusted to fit inside the given dimensions, while keeping the aspect ratio. @@ -534,10 +532,10 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - fitTo: function (width, height) + fitTo(width, height) { return this.constrain(width, height, true); - }, + } /** * The current `width` and `height` are adjusted so that they fully envelope the given dimensions, while keeping the aspect ratio. @@ -555,10 +553,10 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - envelop: function (width, height) + envelop(width, height) { return this.constrain(width, height, false); - }, + } /** * Sets the width of this Size component. @@ -572,10 +570,10 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setWidth: function (value) + setWidth(value) { return this.setSize(value, this._height); - }, + } /** * Sets the height of this Size component. @@ -589,10 +587,10 @@ var Size = new Class({ * * @return {this} This Size component instance. */ - setHeight: function (value) + setHeight(value) { return this.setSize(this._width, value); - }, + } /** * Returns a string representation of this Size component. @@ -602,10 +600,10 @@ var Size = new Class({ * * @return {string} A string representation of this Size component. */ - toString: function () + toString() { return '[{ Size (width=' + this._width + ' height=' + this._height + ' aspectRatio=' + this.aspectRatio + ' aspectMode=' + this.aspectMode + ') }]'; - }, + } /** * Sets the values of this Size component to the `element.style.width` and `height` @@ -616,14 +614,14 @@ var Size = new Class({ * * @param {HTMLElement} element - The DOM Element to set the CSS style on. */ - setCSS: function (element) + setCSS(element) { if (element && element.style) { element.style.width = this._width + 'px'; element.style.height = this._height + 'px'; } - }, + } /** * Copies the aspect mode, aspect ratio, width and height from this Size component @@ -636,14 +634,14 @@ var Size = new Class({ * * @return {Phaser.Structs.Size} The updated destination Size component. */ - copy: function (destination) + copy(destination) { destination.setAspectMode(this.aspectMode); destination.aspectRatio = this.aspectRatio; return destination.setSize(this.width, this.height); - }, + } /** * Destroys this Size component. @@ -655,11 +653,11 @@ var Size = new Class({ * @method Phaser.Structs.Size#destroy * @since 3.16.0 */ - destroy: function () + destroy() { this._parent = null; this.snapTo = null; - }, + } /** * The width of this Size component. @@ -675,19 +673,16 @@ var Size = new Class({ * @type {number} * @since 3.16.0 */ - width: { - - get: function () - { - return this._width; - }, - set: function (value) - { - this.setSize(value, this._height); - } + get width() + { + return this._width; + } - }, + set width(value) + { + this.setSize(value, this._height); + } /** * The height of this Size component. @@ -703,21 +698,18 @@ var Size = new Class({ * @type {number} * @since 3.16.0 */ - height: { - get: function () - { - return this._height; - }, - - set: function (value) - { - this.setSize(this._width, value); - } + get height() + { + return this._height; + } + set height(value) + { + this.setSize(this._width, value); } -}); +}; /** * Do not make the size fit the aspect ratio. Change the ratio when the size changes. diff --git a/src/textures/CanvasTexture.js b/src/textures/CanvasTexture.js index 801284d3d3..bf07a8138d 100644 --- a/src/textures/CanvasTexture.js +++ b/src/textures/CanvasTexture.js @@ -43,15 +43,11 @@ var Texture = require('./Texture'); * @param {number} width - The width of the canvas. * @param {number} height - The height of the canvas. */ -var CanvasTexture = new Class({ +var CanvasTexture = class extends Texture { - Extends: Texture, - - initialize: - - function CanvasTexture (manager, key, source, width, height) + constructor(manager, key, source, width, height) { - Texture.call(this, manager, key, source, width, height); + super(manager, key, source, width, height); this.add('__BASE', 0, 0, 0, width, height); @@ -168,7 +164,7 @@ var CanvasTexture = new Class({ this.pixels = this.imageData.data; } } - }, + } /** * This re-creates the `imageData` from the current context. @@ -181,7 +177,7 @@ var CanvasTexture = new Class({ * * @return {Phaser.Textures.CanvasTexture} This CanvasTexture. */ - update: function () + update() { this.imageData = this.context.getImageData(0, 0, this.width, this.height); @@ -208,7 +204,7 @@ var CanvasTexture = new Class({ } return this; - }, + } /** * Draws the given Image or Canvas element to this CanvasTexture, then updates the internal @@ -224,7 +220,7 @@ var CanvasTexture = new Class({ * * @return {Phaser.Textures.CanvasTexture} This CanvasTexture. */ - draw: function (x, y, source, update) + draw(x, y, source, update) { if (update === undefined) { update = true; } @@ -236,7 +232,7 @@ var CanvasTexture = new Class({ } return this; - }, + } /** * Draws the given texture frame to this CanvasTexture, then updates the internal @@ -253,7 +249,7 @@ var CanvasTexture = new Class({ * * @return {Phaser.Textures.CanvasTexture} This CanvasTexture. */ - drawFrame: function (key, frame, x, y, update) + drawFrame(key, frame, x, y, update) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -286,7 +282,7 @@ var CanvasTexture = new Class({ } return this; - }, + } /** * Sets a pixel in the CanvasTexture to the given color and alpha values. @@ -305,7 +301,7 @@ var CanvasTexture = new Class({ * * @return {this} This CanvasTexture. */ - setPixel: function (x, y, red, green, blue, alpha) + setPixel(x, y, red, green, blue, alpha) { if (alpha === undefined) { alpha = 255; } @@ -327,7 +323,7 @@ var CanvasTexture = new Class({ } return this; - }, + } /** * Puts the ImageData into the context of this CanvasTexture at the given coordinates. @@ -345,7 +341,7 @@ var CanvasTexture = new Class({ * * @return {this} This CanvasTexture. */ - putData: function (imageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) + putData(imageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) { if (dirtyX === undefined) { dirtyX = 0; } if (dirtyY === undefined) { dirtyY = 0; } @@ -355,7 +351,7 @@ var CanvasTexture = new Class({ this.context.putImageData(imageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight); return this; - }, + } /** * Gets an ImageData region from this CanvasTexture from the position and size specified. @@ -371,7 +367,7 @@ var CanvasTexture = new Class({ * * @return {ImageData} The ImageData extracted from this CanvasTexture. */ - getData: function (x, y, width, height) + getData(x, y, width, height) { x = Clamp(Math.floor(x), 0, this.width - 1); y = Clamp(Math.floor(y), 0, this.height - 1); @@ -381,7 +377,7 @@ var CanvasTexture = new Class({ var imageData = this.context.getImageData(x, y, width, height); return imageData; - }, + } /** * Get the color of a specific pixel from this texture and store it in a Color object. @@ -398,7 +394,7 @@ var CanvasTexture = new Class({ * * @return {Phaser.Display.Color} An object with the red, green, blue and alpha values set in the r, g, b and a properties. */ - getPixel: function (x, y, out) + getPixel(x, y, out) { if (!out) { @@ -420,7 +416,7 @@ var CanvasTexture = new Class({ } return out; - }, + } /** * Returns an array containing all of the pixels in the given region. @@ -441,7 +437,7 @@ var CanvasTexture = new Class({ * * @return {Phaser.Types.Textures.PixelConfig[][]} A 2d array of Pixel objects. */ - getPixels: function (x, y, width, height) + getPixels(x, y, width, height) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -475,7 +471,7 @@ var CanvasTexture = new Class({ } return out; - }, + } /** * Returns the Image Data index for the given pixel in this CanvasTexture. @@ -493,7 +489,7 @@ var CanvasTexture = new Class({ * * @return {number} */ - getIndex: function (x, y) + getIndex(x, y) { x = Math.abs(Math.round(x)); y = Math.abs(Math.round(y)); @@ -506,7 +502,7 @@ var CanvasTexture = new Class({ { return -1; } - }, + } /** * This should be called manually if you are running under WebGL. @@ -518,12 +514,12 @@ var CanvasTexture = new Class({ * * @return {Phaser.Textures.CanvasTexture} This CanvasTexture. */ - refresh: function () + refresh() { this._source.update(); return this; - }, + } /** * Gets the Canvas Element. @@ -533,10 +529,10 @@ var CanvasTexture = new Class({ * * @return {HTMLCanvasElement} The Canvas DOM element this texture is using. */ - getCanvas: function () + getCanvas() { return this.canvas; - }, + } /** * Gets the 2D Canvas Rendering Context. @@ -546,10 +542,10 @@ var CanvasTexture = new Class({ * * @return {CanvasRenderingContext2D} The Canvas Rendering Context this texture is using. */ - getContext: function () + getContext() { return this.context; - }, + } /** * Clears the given region of this Canvas Texture, resetting it back to transparent. @@ -566,7 +562,7 @@ var CanvasTexture = new Class({ * * @return {Phaser.Textures.CanvasTexture} The Canvas Texture. */ - clear: function (x, y, width, height, update) + clear(x, y, width, height, update) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -582,7 +578,7 @@ var CanvasTexture = new Class({ } return this; - }, + } /** * Changes the size of this Canvas Texture. @@ -595,7 +591,7 @@ var CanvasTexture = new Class({ * * @return {Phaser.Textures.CanvasTexture} The Canvas Texture. */ - setSize: function (width, height) + setSize(width, height) { if (height === undefined) { height = width; } @@ -621,7 +617,7 @@ var CanvasTexture = new Class({ } return this; - }, + } /** * Destroys this Texture and releases references to its sources and frames. @@ -629,7 +625,7 @@ var CanvasTexture = new Class({ * @method Phaser.Textures.CanvasTexture#destroy * @since 3.16.0 */ - destroy: function () + destroy() { Texture.prototype.destroy.call(this); @@ -642,6 +638,6 @@ var CanvasTexture = new Class({ this.buffer = null; } -}); +}; module.exports = CanvasTexture; diff --git a/src/textures/DynamicTexture.js b/src/textures/DynamicTexture.js index 6405172fc4..6e9628d2c1 100644 --- a/src/textures/DynamicTexture.js +++ b/src/textures/DynamicTexture.js @@ -61,13 +61,9 @@ var TransformMatrix = require('../gameobjects/components/TransformMatrix'); * @param {number} [height=256] - The height of this Dymamic Texture in pixels. Defaults to 256 x 256. * @param {boolean} [forceEven=true] - Force the given width and height to be rounded to even values. This significantly improves the rendering quality. Set to false if you know you need an odd sized texture. */ -var DynamicTexture = new Class({ +var DynamicTexture = class extends Texture { - Extends: Texture, - - initialize: - - function DynamicTexture (manager, key, width, height, forceEven) + constructor(manager, key, width, height, forceEven) { if (width === undefined) { width = 256; } if (height === undefined) { height = 256; } @@ -89,7 +85,7 @@ var DynamicTexture = new Class({ var source = (isCanvas) ? CanvasPool.create2D(this, width, height) : [ this ]; - Texture.call(this, manager, key, source, width, height); + super(manager, key, source, width, height); this.add('__BASE', 0, 0, 0, width, height); @@ -190,7 +186,7 @@ var DynamicTexture = new Class({ } this.setSize(width, height, forceEven); - }, + } /** * Resizes this Dynamic Texture to the new dimensions given. @@ -211,7 +207,7 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture. */ - setSize: function (width, height, forceEven) + setSize(width, height, forceEven) { if (height === undefined) { height = width; } if (forceEven === undefined) { forceEven = true; } @@ -279,7 +275,7 @@ var DynamicTexture = new Class({ } return this; - }, + } /** * Render the buffered drawing commands to this Dynamic Texture. @@ -289,7 +285,7 @@ var DynamicTexture = new Class({ * @since 4.0.0 * @return {this} This Dynamic Texture instance. */ - render: function () + render() { if (this.commandBuffer.length === 0) { @@ -308,7 +304,7 @@ var DynamicTexture = new Class({ } return this; - }, + } /** * Render the DynamicTexture using the WebGL render system. @@ -317,10 +313,10 @@ var DynamicTexture = new Class({ * @since 4.0.0 * @private */ - _renderWebGL: function () + _renderWebGL() { this.renderer.renderNodes.getNode('DynamicTextureHandler').run(this); - }, + } /** * Render the DynamicTexture using the Canvas render system. @@ -329,7 +325,7 @@ var DynamicTexture = new Class({ * @since 4.0.0 * @private */ - _renderCanvas: function () + _renderCanvas() { var camera = this.camera; var context = this.context; @@ -564,7 +560,7 @@ var DynamicTexture = new Class({ // Finish rendering. renderer.setContext(); - }, + } /** * Fills this Dynamic Texture with the given color. @@ -586,7 +582,7 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - fill: function (rgb, alpha, x, y, width, height) + fill(rgb, alpha, x, y, width, height) { if (alpha === undefined) { alpha = 1; } if (x === undefined) { x = 0; } @@ -607,7 +603,7 @@ var DynamicTexture = new Class({ ); return this; - }, + } /** * Clears a portion or everything from this Dynamic Texture by erasing it and resetting it back to @@ -623,7 +619,7 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - clear: function (x, y, width, height) + clear(x, y, width, height) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -633,7 +629,7 @@ var DynamicTexture = new Class({ this.commandBuffer.push(DynamicTextureCommands.CLEAR, x, y, width, height); return this; - }, + } /** * Takes the given texture key and frame and then stamps it at the given @@ -659,7 +655,7 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - stamp: function (key, frame, x, y, config) + stamp(key, frame, x, y, config) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -688,7 +684,7 @@ var DynamicTexture = new Class({ ); return this; - }, + } /** * Draws the given object, or an array of objects, to this Dynamic Texture using a blend mode of ERASE. @@ -708,7 +704,7 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - erase: function (entries, x, y, alpha, tint) + erase(entries, x, y, alpha, tint) { var commandBuffer = this.commandBuffer; var commandBufferLength = commandBuffer.length; @@ -731,7 +727,7 @@ var DynamicTexture = new Class({ commandBuffer.push(DynamicTextureCommands.SET_ERASE, false); return this; - }, + } /** * Draws the given object, or an array of objects, to this Dynamic Texture. @@ -783,7 +779,7 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - draw: function (entries, x, y, alpha, tint) + draw(entries, x, y, alpha, tint) { if (!Array.isArray(entries)) { @@ -838,7 +834,7 @@ var DynamicTexture = new Class({ } return this; - }, + } /** * Draws the given object to this Dynamic Texture. @@ -853,14 +849,14 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - capture: function (entry, config) + capture(entry, config) { if (!config) { config = {}; } this.commandBuffer.push(DynamicTextureCommands.CAPTURE, entry, config); return this; - }, + } /** * Prepares an object to be rendered using the `capture` method. @@ -875,7 +871,7 @@ var DynamicTexture = new Class({ * * @return {Phaser.Types.Textures.CaptureConfig} A configuration object containing the appropriate parent transform in `transform`, and the cached object properties in any fields that were overridden. */ - startCapture: function (entry, config) + startCapture(entry, config) { var cacheConfig = {}; @@ -973,7 +969,7 @@ var DynamicTexture = new Class({ } return cacheConfig; - }, + } /** * Restores the object properties that were overridden during the `capture` method. @@ -986,7 +982,7 @@ var DynamicTexture = new Class({ * @param {Phaser.GameObjects.GameObject} entry - The GameObject to restore the properties on. * @param {Phaser.Types.Textures.CaptureConfig} cacheConfig - The cached properties to restore. */ - finishCapture: function (entry, cacheConfig) + finishCapture(entry, cacheConfig) { // Restore the object properties. if (cacheConfig.x !== undefined) @@ -1029,7 +1025,7 @@ var DynamicTexture = new Class({ { entry.blendMode = cacheConfig.blendMode; } - }, + } /** * Takes the given Texture Frame and draws it to this Dynamic Texture as a fill pattern, @@ -1059,7 +1055,7 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - repeat: function (key, frame, x, y, width, height, config) + repeat(key, frame, x, y, width, height, config) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -1098,7 +1094,7 @@ var DynamicTexture = new Class({ ); return this; - }, + } /** * Sets the preserve flag for this Dynamic Texture. @@ -1114,12 +1110,12 @@ var DynamicTexture = new Class({ * @param {boolean} preserve - Whether to preserve the command buffer after rendering. * @returns {this} This Dynamic Texture instance. */ - preserve: function (preserve) + preserve(preserve) { this.commandBuffer.push(DynamicTextureCommands.PRESERVE, preserve); return this; - }, + } /** * Adds a callback to run during the render process. @@ -1133,12 +1129,12 @@ var DynamicTexture = new Class({ * @param {Function} callback - A callback function to run during the render process. * @returns {this} This Dynamic Texture instance. */ - callback: function (callback) + callback(callback) { this.commandBuffer.push(DynamicTextureCommands.CALLBACK, callback); return this; - }, + } /** * Takes a snapshot of the given area of this Dynamic Texture. @@ -1168,7 +1164,7 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - snapshotArea: function (x, y, width, height, callback, type, encoderOptions) + snapshotArea(x, y, width, height, callback, type, encoderOptions) { if (this.drawingContext) { @@ -1180,7 +1176,7 @@ var DynamicTexture = new Class({ } return this; - }, + } /** * Takes a snapshot of the whole of this Dynamic Texture. @@ -1206,10 +1202,10 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - snapshot: function (callback, type, encoderOptions) + snapshot(callback, type, encoderOptions) { return this.snapshotArea(0, 0, this.width, this.height, callback, type, encoderOptions); - }, + } /** * Takes a snapshot of the given pixel from this Dynamic Texture. @@ -1232,10 +1228,10 @@ var DynamicTexture = new Class({ * * @return {this} This Dynamic Texture instance. */ - snapshotPixel: function (x, y, callback) + snapshotPixel(x, y, callback) { return this.snapshotArea(x, y, 1, 1, callback, 'pixel'); - }, + } /** * Returns the underlying WebGLTextureWrapper, if not running in Canvas mode. @@ -1245,13 +1241,13 @@ var DynamicTexture = new Class({ * * @return {?Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The underlying WebGLTextureWrapper, if not running in Canvas mode. */ - getWebGLTexture: function () + getWebGLTexture() { if (this.drawingContext) { return this.drawingContext.texture; } - }, + } /** * Sets this Dynamic Texture onto the TextureManager.Stamp @@ -1265,7 +1261,7 @@ var DynamicTexture = new Class({ * @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 */ - renderWebGL: function (renderer, src, camera, parentMatrix) + renderWebGL(renderer, src, camera, parentMatrix) { var stamp = this.manager.resetStamp(); @@ -1273,7 +1269,7 @@ var DynamicTexture = new Class({ stamp.setOrigin(0); stamp.renderWebGLStep(renderer, stamp, camera, parentMatrix); - }, + } /** * This is a NOOP method. Bitmap Masks are not supported by the Canvas Renderer. @@ -1285,10 +1281,10 @@ var DynamicTexture = new Class({ * @param {Phaser.GameObjects.GameObject} mask - The masked Game Object which would be rendered. * @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to render to. */ - renderCanvas: function () + renderCanvas() { // NOOP - }, + } /** * Destroys this Texture and releases references to its sources and frames. @@ -1296,7 +1292,7 @@ var DynamicTexture = new Class({ * @method Phaser.Textures.DynamicTexture#destroy * @since 3.60.0 */ - destroy: function () + destroy() { var stamp = this.manager.stamp; @@ -1321,6 +1317,6 @@ var DynamicTexture = new Class({ this.renderer = null; } -}); +}; module.exports = DynamicTexture; diff --git a/src/textures/Frame.js b/src/textures/Frame.js index 77571f1bb2..75f676b942 100644 --- a/src/textures/Frame.js +++ b/src/textures/Frame.js @@ -25,11 +25,9 @@ var Extend = require('../utils/object/Extend'); * @param {number} width - The width of this Frame. * @param {number} height - The height of this Frame. */ -var Frame = new Class({ +var Frame = class { - initialize: - - function Frame (texture, name, sourceIndex, x, y, width, height) + constructor(texture, name, sourceIndex, x, y, width, height) { /** * The Texture this Frame is a part of. @@ -334,7 +332,7 @@ var Frame = new Class({ }; this.setSize(width, height, x, y); - }, + } /** * Sets the x and y position within the source image to cut from. @@ -347,7 +345,7 @@ var Frame = new Class({ * * @return {this} This Frame object. */ - setCutPosition: function (x, y) + setCutPosition(x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -356,7 +354,7 @@ var Frame = new Class({ this.cutY = y; return this.updateUVs(); - }, + } /** * Sets the width, and height of the area in the source image to cut. @@ -369,13 +367,13 @@ var Frame = new Class({ * * @return {this} This Frame object. */ - setCutSize: function (width, height) + setCutSize(width, height) { this.cutWidth = width; this.cutHeight = height; return this.updateUVs(); - }, + } /** * Sets the width, height, x and y of this Frame. @@ -393,7 +391,7 @@ var Frame = new Class({ * * @return {this} This Frame object. */ - setSize: function (width, height, x, y) + setSize(width, height, x, y) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -436,7 +434,7 @@ var Frame = new Class({ drawImage.height = height; return this.updateUVs(); - }, + } /** * If the frame was trimmed when added to the Texture Atlas, this records the trim and source data. @@ -453,7 +451,7 @@ var Frame = new Class({ * * @return {this} This Frame object. */ - setTrim: function (actualWidth, actualHeight, destX, destY, destWidth, destHeight) + setTrim(actualWidth, actualHeight, destX, destY, destWidth, destHeight) { var data = this.data; var ss = data.spriteSourceSize; @@ -486,7 +484,7 @@ var Frame = new Class({ this.centerY = Math.floor(destHeight / 2); return this.updateUVs(); - }, + } /** * Sets the scale9 center rectangle values. @@ -505,7 +503,7 @@ var Frame = new Class({ * * @return {this} This Frame object. */ - setScale9: function (x, y, width, height) + setScale9(x, y, width, height) { var data = this.data; @@ -518,7 +516,7 @@ var Frame = new Class({ data.scale9Borders.h = height; return this; - }, + } /** * Takes a crop data object and, based on the rectangular region given, calculates the @@ -542,7 +540,7 @@ var Frame = new Class({ * * @return {object} The updated crop data object. */ - setCropUVs: function (crop, x, y, width, height, flipX, flipY) + setCropUVs(crop, x, y, width, height, flipX, flipY) { // Clamp the input values @@ -661,7 +659,7 @@ var Frame = new Class({ crop.flipY = flipY; return crop; - }, + } /** * Takes a crop data object and recalculates the UVs based on the dimensions inside the crop object. @@ -676,10 +674,10 @@ var Frame = new Class({ * * @return {object} The updated crop data object. */ - updateCropUVs: function (crop, flipX, flipY) + updateCropUVs(crop, flipX, flipY) { return this.setCropUVs(crop, crop.x, crop.y, crop.width, crop.height, flipX, flipY); - }, + } /** * Directly sets the canvas and WebGL UV data for this frame. @@ -699,7 +697,7 @@ var Frame = new Class({ * * @return {this} This Frame object. */ - setUVs: function (width, height, u0, v0, u1, v1) + setUVs(width, height, u0, v0, u1, v1) { // Canvas data @@ -717,7 +715,7 @@ var Frame = new Class({ this.v1 = v1; return this; - }, + } /** * Updates the internal WebGL UV cache and the drawImage cache. @@ -727,7 +725,7 @@ var Frame = new Class({ * * @return {this} This Frame object. */ - updateUVs: function () + updateUVs() { var cx = this.cutX; var cy = this.cutY; @@ -753,7 +751,7 @@ var Frame = new Class({ this.v1 = 1 - (cy + ch) / th; return this; - }, + } /** * Updates the internal WebGL UV cache. @@ -763,7 +761,7 @@ var Frame = new Class({ * * @return {this} This Frame object. */ - updateUVsInverted: function () + updateUVsInverted() { var tw = this.source.width; var th = this.source.height; @@ -775,7 +773,7 @@ var Frame = new Class({ this.v1 = 1 - (this.cutY + this.cutWidth) / th; return this; - }, + } /** * Clones this Frame into a new Frame object. @@ -785,7 +783,7 @@ var Frame = new Class({ * * @return {Phaser.Textures.Frame} A clone of this Frame. */ - clone: function () + clone() { var clone = new Frame(this.texture, this.name, this.sourceIndex); @@ -813,7 +811,7 @@ var Frame = new Class({ clone.updateUVs(); return clone; - }, + } /** * Destroys this Frame by nulling its reference to the parent Texture and and data objects. @@ -821,13 +819,13 @@ var Frame = new Class({ * @method Phaser.Textures.Frame#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.texture = null; this.source = null; this.customData = null; this.data = null; - }, + } /** * A reference to the Texture Source WebGL Texture that this Frame is using. @@ -837,13 +835,11 @@ var Frame = new Class({ * @readonly * @since 3.11.0 */ - glTexture: { - get: function () - { - return this.source.glTexture; - } - }, + get glTexture() + { + return this.source.glTexture; + } /** * The width of the Frame in its un-trimmed, un-padded state, as prepared in the art package, @@ -854,14 +850,11 @@ var Frame = new Class({ * @readonly * @since 3.0.0 */ - realWidth: { - get: function () - { - return this.data.sourceSize.w; - } - - }, + get realWidth() + { + return this.data.sourceSize.w; + } /** * The height of the Frame in its un-trimmed, un-padded state, as prepared in the art package, @@ -872,14 +865,11 @@ var Frame = new Class({ * @readonly * @since 3.0.0 */ - realHeight: { - - get: function () - { - return this.data.sourceSize.h; - } - }, + get realHeight() + { + return this.data.sourceSize.h; + } /** * The radius of the Frame (derived from sqrt(w * w + h * h) / 2) @@ -889,14 +879,11 @@ var Frame = new Class({ * @readonly * @since 3.0.0 */ - radius: { - get: function () - { - return this.data.radius; - } - - }, + get radius() + { + return this.data.radius; + } /** * Is the Frame trimmed or not? @@ -906,14 +893,11 @@ var Frame = new Class({ * @readonly * @since 3.0.0 */ - trimmed: { - get: function () - { - return this.data.trim; - } - - }, + get trimmed() + { + return this.data.trim; + } /** * Does the Frame have scale9 border data? @@ -923,14 +907,11 @@ var Frame = new Class({ * @readonly * @since 3.70.0 */ - scale9: { - - get: function () - { - return this.data.scale9; - } - }, + get scale9() + { + return this.data.scale9; + } /** * If the Frame has scale9 border data, is it 3-slice or 9-slice data? @@ -940,14 +921,11 @@ var Frame = new Class({ * @readonly * @since 3.70.0 */ - is3Slice: { - - get: function () - { - return this.data.is3Slice; - } - }, + get is3Slice() + { + return this.data.is3Slice; + } /** * The Canvas drawImage data object. @@ -957,15 +935,12 @@ var Frame = new Class({ * @readonly * @since 3.0.0 */ - canvasData: { - - get: function () - { - return this.data.drawImage; - } + get canvasData() + { + return this.data.drawImage; } -}); +}; module.exports = Frame; diff --git a/src/textures/Texture.js b/src/textures/Texture.js index 3669325f03..81d9c0c978 100644 --- a/src/textures/Texture.js +++ b/src/textures/Texture.js @@ -36,11 +36,9 @@ var TEXTURE_MISSING_ERROR = 'Texture "%s" has no frame "%s"'; * @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({ +var Texture = class { - initialize: - - function Texture (manager, key, source, width, height) + constructor(manager, key, source, width, height) { if (!Array.isArray(source)) { @@ -144,7 +142,7 @@ var Texture = new Class({ { this.source.push(new TextureSource(this, source[i], width, height)); } - }, + } /** * Adds a new Frame to this Texture. @@ -165,7 +163,7 @@ var Texture = new Class({ * * @return {?Phaser.Textures.Frame} The Frame that was added to this Texture, or `null` if the given name already exists. */ - add: function (name, sourceIndex, x, y, width, height) + add(name, sourceIndex, x, y, width, height) { if (this.has(name)) { @@ -188,7 +186,7 @@ var Texture = new Class({ this.frameTotal++; return frame; - }, + } /** * Removes the given Frame from this Texture. The Frame is destroyed immediately. @@ -203,7 +201,7 @@ var Texture = new Class({ * * @return {boolean} True if a Frame with the matching key was removed from this Texture. */ - remove: function (name) + remove(name) { if (this.has(name)) { @@ -217,7 +215,7 @@ var Texture = new Class({ } return false; - }, + } /** * Checks to see if a Frame matching the given key exists within this Texture. @@ -229,10 +227,10 @@ var Texture = new Class({ * * @return {boolean} True if a Frame with the matching key exists in this Texture. */ - has: function (name) + has(name) { return this.frames.hasOwnProperty(name); - }, + } /** * Gets a Frame from this Texture based on either the key or the index of the Frame. @@ -248,7 +246,7 @@ var Texture = new Class({ * * @return {Phaser.Textures.Frame} The Texture Frame. */ - get: function (name) + get(name) { // null, undefined, empty string, zero if (!name) @@ -266,7 +264,7 @@ var Texture = new Class({ } return frame; - }, + } /** * Takes the given TextureSource and returns the index of it within this Texture. @@ -281,7 +279,7 @@ var Texture = new Class({ * * @return {number} The index of the TextureSource within this Texture, or -1 if not in this Texture. */ - getTextureSourceIndex: function (source) + getTextureSourceIndex(source) { for (var i = 0; i < this.source.length; i++) { @@ -292,7 +290,7 @@ var Texture = new Class({ } return -1; - }, + } /** * Returns an array of all the Frames in the given TextureSource. @@ -305,7 +303,7 @@ var Texture = new Class({ * * @return {Phaser.Textures.Frame[]} An array of Texture Frames. */ - getFramesFromTextureSource: function (sourceIndex, includeBase) + getFramesFromTextureSource(sourceIndex, includeBase) { if (includeBase === undefined) { includeBase = false; } @@ -327,7 +325,7 @@ var Texture = new Class({ } return out; - }, + } /** * Based on the given Texture Source Index, this method will get all of the Frames using @@ -343,7 +341,7 @@ var Texture = new Class({ * * @return {Phaser.Types.Math.RectangleLike} An object containing the bounds of the Frames using the given Texture Source Index. */ - getFrameBounds: function (sourceIndex) + getFrameBounds(sourceIndex) { if (sourceIndex === undefined) { sourceIndex = 0; } @@ -382,7 +380,7 @@ var Texture = new Class({ } return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }; - }, + } /** * Returns an array with all of the names of the Frames in this Texture. @@ -397,7 +395,7 @@ var Texture = new Class({ * * @return {string[]} An array of all Frame names in this Texture. */ - getFrameNames: function (includeBase) + getFrameNames(includeBase) { if (includeBase === undefined) { includeBase = false; } @@ -414,7 +412,7 @@ var Texture = new Class({ } return out; - }, + } /** * Given a Frame name, return the source image it uses to render with. @@ -428,7 +426,7 @@ var Texture = new Class({ * * @return {(HTMLImageElement|HTMLCanvasElement|Phaser.GameObjects.RenderTexture)} The DOM Image, Canvas Element or Render Texture. */ - getSourceImage: function (name) + getSourceImage(name) { if (name === undefined || name === null || this.frameTotal === 1) { @@ -447,7 +445,7 @@ var Texture = new Class({ return this.frames['__BASE'].source.image; } - }, + } /** * Given a Frame name, return the data source image it uses to render with. @@ -462,7 +460,7 @@ var Texture = new Class({ * * @return {(HTMLImageElement|HTMLCanvasElement)} The DOM Image or Canvas Element. */ - getDataSourceImage: function (name) + getDataSourceImage(name) { if (name === undefined || name === null || this.frameTotal === 1) { @@ -484,7 +482,7 @@ var Texture = new Class({ } return this.dataSource[idx].image; - }, + } /** * Adds a data source image to this Texture. @@ -497,7 +495,7 @@ var Texture = new Class({ * * @param {(HTMLImageElement|HTMLCanvasElement|HTMLImageElement[]|HTMLCanvasElement[])} data - The source image. */ - setDataSource: function (data) + setDataSource(data) { if (!Array.isArray(data)) { @@ -510,7 +508,7 @@ var Texture = new Class({ this.dataSource.push(new TextureSource(this, data[i], source.width, source.height)); } - }, + } /** * Sets the Filter Mode for this Texture. @@ -526,7 +524,7 @@ var Texture = new Class({ * * @param {Phaser.Textures.FilterMode} filterMode - The Filter Mode. */ - setFilter: function (filterMode) + setFilter(filterMode) { var i; @@ -539,7 +537,7 @@ var Texture = new Class({ { this.dataSource[i].setFilter(filterMode); } - }, + } /** * Set the `smoothPixelArt` property for this Texture. @@ -552,7 +550,7 @@ var Texture = new Class({ * @since 4.0.0 * @param {boolean|null} value - The value of the smoothPixelArt property. */ - setSmoothPixelArt: function (value) + setSmoothPixelArt(value) { this.smoothPixelArt = value; @@ -560,7 +558,7 @@ var Texture = new Class({ { this.setFilter(Phaser.Textures.FilterMode.LINEAR); } - }, + } /** * Destroys this Texture and releases references to its sources and frames. @@ -568,7 +566,7 @@ var Texture = new Class({ * @method Phaser.Textures.Texture#destroy * @since 3.0.0 */ - destroy: function () + destroy() { var i; var source = this.source; @@ -609,6 +607,6 @@ var Texture = new Class({ this.manager = null; } -}); +}; module.exports = Texture; diff --git a/src/textures/TextureManager.js b/src/textures/TextureManager.js index f6e60707ba..b308f6616a 100644 --- a/src/textures/TextureManager.js +++ b/src/textures/TextureManager.js @@ -50,15 +50,11 @@ var TileSpriteGameObject = require('../gameobjects/tilesprite/TileSprite'); * * @param {Phaser.Game} game - The Phaser.Game instance this Texture Manager belongs to. */ -var TextureManager = new Class({ +var TextureManager = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function TextureManager (game) + constructor(game) { - EventEmitter.call(this); + super(); /** * The Game that the Texture Manager belongs to. @@ -182,7 +178,7 @@ var TextureManager = new Class({ this.silentWarnings = false; game.events.once(GameEvents.BOOT, this.boot, this); - }, + } /** * The Boot Handler called by Phaser.Game when it first starts up. @@ -191,7 +187,7 @@ var TextureManager = new Class({ * @private * @since 3.0.0 */ - boot: function () + boot() { this._pending = 3; @@ -228,7 +224,7 @@ var TextureManager = new Class({ this.tileSprite = new TileSpriteGameObject(scene, 0, 0, 256, 256, '__WHITE').setOrigin(0); }, this); - }, + } /** * After 'onload' or 'onerror' invoked twice, emit 'ready' event. @@ -237,7 +233,7 @@ var TextureManager = new Class({ * @private * @since 3.0.0 */ - updatePending: function () + updatePending() { this._pending--; @@ -248,7 +244,7 @@ var TextureManager = new Class({ this.emit(Events.READY); } - }, + } /** * Checks the given texture key and throws a console.warn if the key is already in use, then returns false. @@ -262,7 +258,7 @@ var TextureManager = new Class({ * * @return {boolean} `true` if it's safe to use the texture key, otherwise `false`. */ - checkKey: function (key) + checkKey(key) { if (!key || typeof key !== 'string' || this.exists(key)) { @@ -276,7 +272,7 @@ var TextureManager = new Class({ } return true; - }, + } /** * Removes a Texture from the Texture Manager and destroys it. This will immediately @@ -295,7 +291,7 @@ var TextureManager = new Class({ * * @return {Phaser.Textures.TextureManager} The Texture Manager. */ - remove: function (key) + remove(key) { if (typeof key === 'string') { @@ -326,7 +322,7 @@ var TextureManager = new Class({ } return this; - }, + } /** * Removes a key from the Texture Manager but does not destroy the Texture that was using the key. @@ -338,7 +334,7 @@ var TextureManager = new Class({ * * @return {Phaser.Textures.TextureManager} The Texture Manager. */ - removeKey: function (key) + removeKey(key) { if (this.list.hasOwnProperty(key)) { @@ -346,7 +342,7 @@ var TextureManager = new Class({ } return this; - }, + } /** * Adds a new Texture to the Texture Manager created from the given Base64 encoded data. @@ -366,7 +362,7 @@ var TextureManager = new Class({ * * @return {this} This Texture Manager instance. */ - addBase64: function (key, data) + addBase64(key, data) { if (this.checkKey(key)) { @@ -399,7 +395,7 @@ var TextureManager = new Class({ } return this; - }, + } /** * Gets an existing texture frame and converts it into a base64 encoded image and returns the base64 data. @@ -420,7 +416,7 @@ var TextureManager = new Class({ * * @return {string} The base64 encoded data, or an empty string if the texture frame could not be found. */ - getBase64: function (key, frame, type, encoderOptions) + getBase64(key, frame, type, encoderOptions) { if (type === undefined) { type = 'image/png'; } if (encoderOptions === undefined) { encoderOptions = 0.92; } @@ -464,7 +460,7 @@ var TextureManager = new Class({ } return data; - }, + } /** * Adds a new Texture to the Texture Manager created from the given Image element. @@ -479,7 +475,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addImage: function (key, source, dataSource) + addImage(key, source, dataSource) { var texture = null; @@ -499,7 +495,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Takes a WebGLTextureWrapper and creates a Phaser Texture from it, which is added to the Texture Manager using the given key. @@ -521,7 +517,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addGLTexture: function (key, glTexture) + addGLTexture(key, glTexture) { var texture = null; @@ -539,7 +535,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Adds a Compressed Texture to this Texture Manager. @@ -560,7 +556,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addCompressedTexture: function (key, textureData, atlasData) + addCompressedTexture(key, textureData, atlasData) { var texture = null; @@ -601,7 +597,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Adds a Render Texture to the Texture Manager using the given key. @@ -616,7 +612,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addRenderTexture: function (key, renderTexture) + addRenderTexture(key, renderTexture) { var texture = null; @@ -631,7 +627,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Creates a new Texture using a blank Canvas element of the size given. @@ -648,7 +644,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.CanvasTexture} The Canvas Texture that was created, or `null` if the key is already in use. */ - createCanvas: function (key, width, height) + createCanvas(key, width, height) { if (width === undefined) { width = 256; } if (height === undefined) { height = 256; } @@ -661,7 +657,7 @@ var TextureManager = new Class({ } return null; - }, + } /** * Creates a new Canvas Texture object from an existing Canvas element @@ -677,7 +673,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.CanvasTexture} The Canvas Texture that was created, or `null` if the key is already in use. */ - addCanvas: function (key, source, skipCache) + addCanvas(key, source, skipCache) { if (skipCache === undefined) { skipCache = false; } @@ -698,7 +694,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Creates a Dynamic Texture instance and adds itself to this Texture Manager. @@ -729,7 +725,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.DynamicTexture} The Dynamic Texture that was created, or `null` if the key is already in use. */ - addDynamicTexture: function (key, width, height, forceEven) + addDynamicTexture(key, width, height, forceEven) { var texture = null; @@ -757,7 +753,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Adds a Texture Atlas to this Texture Manager. @@ -779,7 +775,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addAtlas: function (key, source, data, dataSource) + addAtlas(key, source, data, dataSource) { // New Texture Packer format? if (Array.isArray(data.textures) || Array.isArray(data.frames)) @@ -790,7 +786,7 @@ var TextureManager = new Class({ { return this.addAtlasJSONHash(key, source, data, dataSource); } - }, + } /** * Adds a Texture Atlas to this Texture Manager. @@ -815,7 +811,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addAtlasJSONArray: function (key, source, data, dataSource) + addAtlasJSONArray(key, source, data, dataSource) { var texture = null; @@ -859,7 +855,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Adds a Texture Atlas to this Texture Manager. @@ -884,7 +880,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addAtlasJSONHash: function (key, source, data, dataSource) + addAtlasJSONHash(key, source, data, dataSource) { var texture = null; @@ -922,7 +918,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Adds a Texture Atlas to this Texture Manager. @@ -945,7 +941,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addAtlasXML: function (key, source, data, dataSource) + addAtlasXML(key, source, data, dataSource) { var texture = null; @@ -973,7 +969,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Adds a Unity Texture Atlas to this Texture Manager. @@ -996,7 +992,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addUnityAtlas: function (key, source, data, dataSource) + addUnityAtlas(key, source, data, dataSource) { var texture = null; @@ -1024,7 +1020,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Adds a Sprite Sheet to this Texture Manager. @@ -1047,7 +1043,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created or updated, or `null` if the key is already in use. */ - addSpriteSheet: function (key, source, config, dataSource) + addSpriteSheet(key, source, config, dataSource) { var texture = null; @@ -1078,7 +1074,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Adds a Sprite Sheet to this Texture Manager, where the Sprite Sheet exists as a Frame within a Texture Atlas. @@ -1095,7 +1091,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addSpriteSheetFromAtlas: function (key, config) + addSpriteSheetFromAtlas(key, config) { if (!this.checkKey(key)) { @@ -1137,7 +1133,7 @@ var TextureManager = new Class({ return texture; } - }, + } /** * Creates a texture from an array of colour data. @@ -1158,7 +1154,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - addUint8Array: function (key, data, width, height) + addUint8Array(key, data, width, height) { if ( !this.checkKey(key) || @@ -1176,7 +1172,7 @@ var TextureManager = new Class({ this.emit(Events.ADD_KEY + key, texture); return texture; - }, + } /** * Creates a new Texture using the given source and dimensions. @@ -1191,7 +1187,7 @@ var TextureManager = new Class({ * * @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use. */ - create: function (key, source, width, height) + create(key, source, width, height) { var texture = null; @@ -1203,7 +1199,7 @@ var TextureManager = new Class({ } return texture; - }, + } /** * Checks the given key to see if a Texture using it exists within this Texture Manager. @@ -1215,10 +1211,10 @@ var TextureManager = new Class({ * * @return {boolean} Returns `true` if a Texture matching the given key exists in this Texture Manager. */ - exists: function (key) + exists(key) { return (this.list.hasOwnProperty(key)); - }, + } /** * Returns a Texture from the Texture Manager that matches the given key. @@ -1238,7 +1234,7 @@ var TextureManager = new Class({ * * @return {Phaser.Textures.Texture} The Texture matching the given key. */ - get: function (key) + get(key) { if (key === undefined) { key = '__DEFAULT'; } @@ -1258,7 +1254,7 @@ var TextureManager = new Class({ { return this.list['__MISSING']; } - }, + } /** * Takes a Texture key and Frame name and returns a clone of that Frame if found. @@ -1271,13 +1267,13 @@ var TextureManager = new Class({ * * @return {Phaser.Textures.Frame} A Clone of the given Frame. */ - cloneFrame: function (key, frame) + cloneFrame(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. @@ -1290,13 +1286,13 @@ var TextureManager = new Class({ * * @return {Phaser.Textures.Frame} A Texture Frame object. */ - getFrame: function (key, frame) + getFrame(key, frame) { if (this.list[key]) { return this.list[key].get(frame); } - }, + } /** * Parses the 'key' parameter and returns a Texture Frame instance. @@ -1316,7 +1312,7 @@ var TextureManager = new Class({ * * @return {Phaser.Textures.Frame} A Texture Frame object, if found, or undefined if not. */ - parseFrame: function (key) + parseFrame(key) { if (!key) { @@ -1342,7 +1338,7 @@ var TextureManager = new Class({ { return key; } - }, + } /** * Returns an array with all of the keys of all Textures in this Texture Manager. @@ -1353,7 +1349,7 @@ var TextureManager = new Class({ * * @return {string[]} An array containing all of the Texture keys stored in this Texture Manager. */ - getTextureKeys: function () + getTextureKeys() { var output = []; @@ -1366,7 +1362,7 @@ var TextureManager = new Class({ } return output; - }, + } /** * Given a Texture and an `x` and `y` coordinate this method will return a new @@ -1384,7 +1380,7 @@ var TextureManager = new Class({ * @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) + getPixel(x, y, key, frame) { var textureFrame = this.getFrame(key, frame); @@ -1421,7 +1417,7 @@ var TextureManager = new Class({ } return null; - }, + } /** * Given a Texture and an `x` and `y` coordinate this method will return a value between 0 and 255 @@ -1438,7 +1434,7 @@ var TextureManager = new Class({ * * @return {number} A value between 0 and 255, or `null` if the coordinates were out of bounds. */ - getPixelAlpha: function (x, y, key, frame) + getPixelAlpha(x, y, key, frame) { var textureFrame = this.getFrame(key, frame); @@ -1475,7 +1471,7 @@ var TextureManager = new Class({ } return null; - }, + } /** * Sets the given Game Objects `texture` and `frame` properties so that it uses @@ -1490,7 +1486,7 @@ var TextureManager = new Class({ * * @return {Phaser.GameObjects.GameObject} The Game Object the texture was set on. */ - setTexture: function (gameObject, key, frame) + setTexture(gameObject, key, frame) { if (this.list[key]) { @@ -1499,7 +1495,7 @@ var TextureManager = new Class({ } return gameObject; - }, + } /** * Changes the key being used by a Texture to the new key provided. @@ -1517,7 +1513,7 @@ var TextureManager = new Class({ * * @return {boolean} `true` if the Texture key was successfully renamed, otherwise `false`. */ - renameTexture: function (currentKey, newKey) + renameTexture(currentKey, newKey) { var texture = this.get(currentKey); @@ -1533,7 +1529,7 @@ var TextureManager = new Class({ } return false; - }, + } /** * Passes all Textures to the given callback. @@ -1545,7 +1541,7 @@ var TextureManager = new Class({ * @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) + each(callback, scope) { var args = [ null ]; @@ -1560,7 +1556,7 @@ var TextureManager = new Class({ callback.apply(scope, args); } - }, + } /** * Resets the internal Stamp object, ready for drawing and returns it. @@ -1573,7 +1569,7 @@ var TextureManager = new Class({ * * @return {Phaser.GameObjects.Image} A reference to the Stamp Game Object. */ - resetStamp: function (alpha, tint) + resetStamp(alpha, tint) { if (alpha === undefined) { alpha = 1; } if (tint === undefined) { tint = 0xffffff; } @@ -1589,7 +1585,7 @@ var TextureManager = new Class({ stamp.setTexture('__WHITE'); return stamp; - }, + } /** * Resets the internal Tile Sprite object, ready for drawing, and returns it. @@ -1602,7 +1598,7 @@ var TextureManager = new Class({ * * @return {Phaser.GameObjects.TileSprite} A reference to the Tile Sprite Game Object. */ - resetTileSprite: function (alpha, tint) + resetTileSprite(alpha, tint) { if (alpha === undefined) { alpha = 1; } if (tint === undefined) { tint = 0xffffff; } @@ -1618,7 +1614,7 @@ var TextureManager = new Class({ tileSprite.setTexture('__WHITE'); return tileSprite; - }, + } /** * Destroys the Texture Manager and all Textures stored within it. @@ -1626,7 +1622,7 @@ var TextureManager = new Class({ * @method Phaser.Textures.TextureManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { for (var texture in this.list) { @@ -1643,6 +1639,6 @@ var TextureManager = new Class({ CanvasPool.remove(this._tempCanvas); } -}); +}; module.exports = TextureManager; diff --git a/src/textures/TextureSource.js b/src/textures/TextureSource.js index 887b2cb5e1..e262faaa78 100644 --- a/src/textures/TextureSource.js +++ b/src/textures/TextureSource.js @@ -29,11 +29,9 @@ var WebGLTextureWrapper = require('../renderer/webgl/wrappers/WebGLTextureWrappe * @param {number} [height] - Optional height of the source image. If not given it's derived from the source itself. * @param {boolean} [flipY=true] - Sets the `UNPACK_FLIP_Y_WEBGL` flag the WebGL Texture uses during upload. */ -var TextureSource = new Class({ +var TextureSource = class { - initialize: - - function TextureSource (texture, source, width, height, flipY) + constructor(texture, source, width, height, flipY) { if (flipY === undefined) { flipY = true; } @@ -200,7 +198,7 @@ var TextureSource = new Class({ this.flipY = flipY; this.init(game); - }, + } /** * Creates a WebGL Texture, if required, and sets the Texture filter mode. @@ -210,7 +208,7 @@ var TextureSource = new Class({ * * @param {Phaser.Game} game - A reference to the Phaser Game instance. */ - init: function (game) + init(game) { var renderer = this.renderer; @@ -270,7 +268,7 @@ var TextureSource = new Class({ { this.setFilter(1); } - }, + } /** * Sets the Filter Mode for this Texture. @@ -284,7 +282,7 @@ var TextureSource = new Class({ * * @param {Phaser.Textures.FilterMode} filterMode - The Filter Mode. */ - setFilter: function (filterMode) + setFilter(filterMode) { if (this.renderer && this.renderer.gl) { @@ -292,7 +290,7 @@ var TextureSource = new Class({ } this.scaleMode = filterMode; - }, + } /** * Sets the `UNPACK_FLIP_Y_WEBGL` flag for the WebGL Texture during texture upload. @@ -302,7 +300,7 @@ var TextureSource = new Class({ * * @param {boolean} [value=true] - Should the WebGL Texture be flipped on the Y axis on texture upload or not? */ - setFlipY: function (value) + setFlipY(value) { if (value === undefined) { value = true; } @@ -312,7 +310,7 @@ var TextureSource = new Class({ this.update(); return this; - }, + } /** * If this TextureSource is backed by a Canvas and is running under WebGL, @@ -321,7 +319,7 @@ var TextureSource = new Class({ * @method Phaser.Textures.TextureSource#update * @since 3.7.0 */ - update: function () + update() { var renderer = this.renderer; var image = this.image; @@ -354,7 +352,7 @@ var TextureSource = new Class({ ); } } - }, + } /** * Updates the dimensions of this Texture Source. @@ -366,7 +364,7 @@ var TextureSource = new Class({ * @param {number} width - The new width of the source image. * @param {number} height - The new height of the source image. */ - updateSize: function (width, height) + updateSize(width, height) { if (this.width === width && this.height === height) { @@ -375,7 +373,7 @@ var TextureSource = new Class({ this.width = width; this.height = height; this.isPowerOf2 = IsSizePowerOfTwo(width, height); - }, + } /** * Destroys this Texture Source and nulls the references. @@ -383,7 +381,7 @@ var TextureSource = new Class({ * @method Phaser.Textures.TextureSource#destroy * @since 3.0.0 */ - destroy: function () + destroy() { if (this.glTexture) { @@ -402,6 +400,6 @@ var TextureSource = new Class({ this.glTexture = null; } -}); +}; module.exports = TextureSource; diff --git a/src/tilemaps/ImageCollection.js b/src/tilemaps/ImageCollection.js index aa2a2d3bda..60313f2a88 100644 --- a/src/tilemaps/ImageCollection.js +++ b/src/tilemaps/ImageCollection.js @@ -25,11 +25,9 @@ var Class = require('../utils/Class'); * @param {number} [spacing=0] - The spacing between each image in the collection (in pixels). * @param {object} [properties={}] - Custom Image Collection properties. */ -var ImageCollection = new Class({ +var ImageCollection = class { - initialize: - - function ImageCollection (name, firstgid, width, height, margin, spacing, properties) + constructor(name, firstgid, width, height, margin, spacing, properties) { if (width === undefined || width <= 0) { width = 32; } if (height === undefined || height <= 0) { height = 32; } @@ -125,7 +123,7 @@ var ImageCollection = new Class({ * @since 3.0.0 */ this.total = 0; - }, + } /** * Returns true if and only if this image collection contains the given image index. @@ -137,10 +135,10 @@ var ImageCollection = new Class({ * * @return {boolean} True if this Image Collection contains the given index. */ - containsImageIndex: function (imageIndex) + containsImageIndex(imageIndex) { return (imageIndex >= this.firstgid && imageIndex < (this.firstgid + this.total)); - }, + } /** * Add an image to this Image Collection. @@ -155,7 +153,7 @@ var ImageCollection = new Class({ * * @return {Phaser.Tilemaps.ImageCollection} This ImageCollection object. */ - addImage: function (gid, image, width, height) + addImage(gid, image, width, height) { this.images.push({ gid: gid, image: image, width: width, height: height }); this.total++; @@ -163,6 +161,6 @@ var ImageCollection = new Class({ return this; } -}); +}; module.exports = ImageCollection; diff --git a/src/tilemaps/ObjectHelper.js b/src/tilemaps/ObjectHelper.js index 50aa61494a..f3eda5ed7c 100644 --- a/src/tilemaps/ObjectHelper.js +++ b/src/tilemaps/ObjectHelper.js @@ -18,11 +18,9 @@ var Class = require('../utils/Class'); * * @param {Phaser.Tilemaps.Tileset[]} tilesets - The backing tileset data. */ -var ObjectHelper = new Class({ +var ObjectHelper = class { - initialize: - - function ObjectHelper (tilesets) + constructor(tilesets) { /** * The Tile GIDs array. @@ -55,7 +53,7 @@ var ObjectHelper = new Class({ * @since 3.60.0 */ this._gids = this.gids; - }, + } /** * Enabled if the object helper reaches in to tilesets for data. @@ -65,19 +63,16 @@ var ObjectHelper = new Class({ * @type {boolean} * @since 3.60.0 */ - enabled: { - - get: function () - { - return !!this.gids; - }, - set: function (v) - { - this.gids = v ? this._gids : undefined; - } + get enabled() + { + return !!this.gids; + } - }, + set enabled(v) + { + this.gids = v ? this._gids : undefined; + } /** * Gets the Tiled `type` field value from the object or the `gid` behind it. @@ -89,7 +84,7 @@ var ObjectHelper = new Class({ * * @return {?string} The `type` of the object, the tile behind the `gid` of the object, or `undefined`. */ - getTypeIncludingTile: function (obj) + getTypeIncludingTile(obj) { if (obj.type !== undefined && obj.type !== '') { @@ -116,7 +111,7 @@ var ObjectHelper = new Class({ } return tileData.type; - }, + } /** * Sets the sprite texture data as specified (usually in a config) or, failing that, @@ -134,7 +129,7 @@ var ObjectHelper = new Class({ * @param {string|number|Phaser.Textures.Frame} [frame] - The frames key to set (or else the `obj.gid`'s tile is used if available). * @param {Phaser.Types.Tilemaps.TiledObject} [obj] - The Tiled object for fallback. */ - setTextureAndFrame: function (sprite, key, frame, obj) + setTextureAndFrame(sprite, key, frame, obj) { if ((key === null) && this.gids && obj.gid !== undefined) { @@ -163,7 +158,7 @@ var ObjectHelper = new Class({ } sprite.setTexture(key, frame); - }, + } /** * Sets the `sprite.data` field from the tiled properties on the object and its tile (if any). @@ -174,7 +169,7 @@ var ObjectHelper = new Class({ * @param {Phaser.GameObjects.GameObject} sprite * @param {Phaser.Types.Tilemaps.TiledObject} obj */ - setPropertiesFromTiledObject: function (sprite, obj) + setPropertiesFromTiledObject(sprite, obj) { if (this.gids !== undefined && obj.gid !== undefined) { @@ -187,7 +182,7 @@ var ObjectHelper = new Class({ } this.setFromJSON(sprite, obj.properties); - }, + } /** * Sets the sprite data from the JSON object. @@ -199,7 +194,7 @@ var ObjectHelper = new Class({ * @param {Phaser.GameObjects.GameObject} sprite - The object for which to populate `data`. * @param {(Object.|Object[])} properties - The properties to set in either JSON object format or else a list of objects with `name` and `value` fields. */ - setFromJSON: function (sprite, properties) + setFromJSON(sprite, properties) { if (!properties) { @@ -237,6 +232,6 @@ var ObjectHelper = new Class({ } } } -}); +}; module.exports = ObjectHelper; diff --git a/src/tilemaps/Tile.js b/src/tilemaps/Tile.js index 6e44050d29..0779ee8de6 100644 --- a/src/tilemaps/Tile.js +++ b/src/tilemaps/Tile.js @@ -38,17 +38,18 @@ var Rectangle = require('../geom/rectangle'); * support multiple tileset sizes within one map, but they are still placed at intervals of the * base tile height. */ -var Tile = new Class({ +var Tile = class { - Mixins: [ - Components.AlphaSingle, - Components.Flip, - Components.Visible - ], - - initialize: + static + { + Class.mixin(this, [ + Components.AlphaSingle, + Components.Flip, + Components.Visible + ], false); + } - function Tile (layer, index, x, y, width, height, baseWidth, baseHeight) + constructor(layer, index, x, y, width, height, baseWidth, baseHeight) { /** * The LayerData in the Tilemap data that this tile belongs to. @@ -323,7 +324,7 @@ var Tile = new Class({ * @since 3.0.0 */ this.physics = {}; - }, + } /** * Check if the given x and y world coordinates are within this Tile. This does not factor in @@ -337,10 +338,10 @@ var Tile = new Class({ * * @return {boolean} True if the coordinates are within this Tile, otherwise false. */ - containsPoint: function (x, y) + containsPoint(x, y) { return !(x < this.pixelX || y < this.pixelY || x > this.right || y > this.bottom); - }, + } /** * Copies the tile data and properties from the given Tile to this Tile. This copies everything @@ -353,7 +354,7 @@ var Tile = new Class({ * * @return {this} This Tile object instance. */ - copy: function (tile) + copy(tile) { this.index = tile.index; this.alpha = tile.alpha; @@ -370,7 +371,7 @@ var Tile = new Class({ this.collisionCallbackContext = tile.collisionCallbackContext; return this; - }, + } /** * The collision group for this Tile, defined within the Tileset. This returns a reference to @@ -382,10 +383,10 @@ var Tile = new Class({ * * @return {?object} The collision group for this Tile, as defined in the Tileset, or `null` if no group was defined. */ - getCollisionGroup: function () + getCollisionGroup() { return this.tileset ? this.tileset.getTileCollisionGroup(this.index) : null; - }, + } /** * The tile data for this Tile, defined within the Tileset. This typically contains Tiled @@ -398,10 +399,10 @@ var Tile = new Class({ * * @return {?object} The tile data for this Tile, as defined in the Tileset, or `null` if no data was defined. */ - getTileData: function () + getTileData() { return this.tileset ? this.tileset.getTileData(this.index) : null; - }, + } /** * Gets the world X position of the left side of the tile, factoring in the layers position, @@ -414,7 +415,7 @@ var Tile = new Class({ * * @return {number} The left (x) value of this tile. */ - getLeft: function (camera) + getLeft(camera) { var tilemapLayer = this.tilemapLayer; @@ -426,7 +427,7 @@ var Tile = new Class({ } return this.x * this.baseWidth; - }, + } /** * Gets the world X position of the right side of the tile, factoring in the layer's position, @@ -439,12 +440,12 @@ var Tile = new Class({ * * @return {number} The right (x) value of this tile. */ - getRight: function (camera) + getRight(camera) { var tilemapLayer = this.tilemapLayer; return (tilemapLayer) ? this.getLeft(camera) + this.width * tilemapLayer.scaleX : this.getLeft(camera) + this.width; - }, + } /** * Gets the world Y position of the top side of the tile, factoring in the layer's position, @@ -457,7 +458,7 @@ var Tile = new Class({ * * @return {number} The top (y) value of this tile. */ - getTop: function (camera) + getTop(camera) { var tilemapLayer = this.tilemapLayer; @@ -472,7 +473,7 @@ var Tile = new Class({ } return this.y * this.baseWidth - (this.height - this.baseHeight); - }, + } /** * Gets the world Y position of the bottom side of the tile, factoring in the layer's position, @@ -485,14 +486,14 @@ var Tile = new Class({ * * @return {number} The bottom (y) value of this tile. */ - getBottom: function (camera) + getBottom(camera) { var tilemapLayer = this.tilemapLayer; return tilemapLayer ? this.getTop(camera) + this.height * tilemapLayer.scaleY : this.getTop(camera) + this.height; - }, + } /** * Gets the world rectangle bounding box for the tile, factoring in the layers position, @@ -506,7 +507,7 @@ var Tile = new Class({ * * @return {(Phaser.Geom.Rectangle|object)} The bounds of this Tile. */ - getBounds: function (camera, output) + getBounds(camera, output) { if (output === undefined) { output = new Rectangle(); } @@ -516,7 +517,7 @@ var Tile = new Class({ output.height = this.getBottom(camera) - output.y; return output; - }, + } /** * Gets the world X position of the center of the tile, factoring in the layer's position, @@ -529,10 +530,10 @@ var Tile = new Class({ * * @return {number} The center x position of this Tile. */ - getCenterX: function (camera) + getCenterX(camera) { return (this.getLeft(camera) + this.getRight(camera)) / 2; - }, + } /** * Gets the world Y position of the center of the tile, factoring in the layer's position, @@ -545,10 +546,10 @@ var Tile = new Class({ * * @return {number} The center y position of this Tile. */ - getCenterY: function (camera) + getCenterY(camera) { return (this.getTop(camera) + this.getBottom(camera)) / 2; - }, + } /** * Check for intersection with this tile. This does not factor in camera scroll, layer scale or @@ -564,13 +565,13 @@ var Tile = new Class({ * * @return {boolean} `true` if the Tile intersects with the given dimensions, otherwise `false`. */ - intersects: function (x, y, right, bottom) + intersects(x, y, right, bottom) { return !( right <= this.pixelX || bottom <= this.pixelY || x >= this.right || y >= this.bottom ); - }, + } /** * Checks if the tile is interesting. @@ -583,7 +584,7 @@ var Tile = new Class({ * * @return {boolean} True if the Tile is interesting, otherwise false. */ - isInteresting: function (collides, faces) + isInteresting(collides, faces) { if (collides && faces) { @@ -599,7 +600,7 @@ var Tile = new Class({ } return false; - }, + } /** * Reset collision status flags. @@ -611,7 +612,7 @@ var Tile = new Class({ * * @return {this} This Tile object instance. */ - resetCollision: function (recalculateFaces) + resetCollision(recalculateFaces) { if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -636,7 +637,7 @@ var Tile = new Class({ } return this; - }, + } /** * Reset faces. @@ -646,7 +647,7 @@ var Tile = new Class({ * * @return {this} This Tile object instance. */ - resetFaces: function () + resetFaces() { this.faceTop = false; this.faceBottom = false; @@ -654,7 +655,7 @@ var Tile = new Class({ this.faceRight = false; return this; - }, + } /** * Sets the collision flags for each side of this tile and updates the interesting faces list. @@ -670,7 +671,7 @@ var Tile = new Class({ * * @return {this} This Tile object instance. */ - setCollision: function (left, right, up, down, recalculateFaces) + setCollision(left, right, up, down, recalculateFaces) { if (right === undefined) { right = left; } if (up === undefined) { up = left; } @@ -698,7 +699,7 @@ var Tile = new Class({ } return this; - }, + } /** * Set a callback to be called when this tile is hit by an object. The callback must true for @@ -712,7 +713,7 @@ var Tile = new Class({ * * @return {this} This Tile object instance. */ - setCollisionCallback: function (callback, context) + setCollisionCallback(callback, context) { if (callback === null) { @@ -726,7 +727,7 @@ var Tile = new Class({ } return this; - }, + } /** * Sets the size of the tile and updates its pixelX and pixelY. @@ -741,7 +742,7 @@ var Tile = new Class({ * * @return {this} This Tile object instance. */ - setSize: function (tileWidth, tileHeight, baseWidth, baseHeight) + setSize(tileWidth, tileHeight, baseWidth, baseHeight) { if (tileWidth !== undefined) { this.width = tileWidth; } if (tileHeight !== undefined) { this.height = tileHeight; } @@ -751,7 +752,7 @@ var Tile = new Class({ this.updatePixelXY(); return this; - }, + } /** * Used internally. Updates the tiles world XY position based on the current tile size. @@ -761,7 +762,7 @@ var Tile = new Class({ * * @return {this} This Tile object instance. */ - updatePixelXY: function () + updatePixelXY() { var orientation = this.layer.orientation; @@ -831,7 +832,7 @@ var Tile = new Class({ this.bottom = this.pixelY + this.baseHeight; return this; - }, + } /** * Clean up memory. @@ -839,12 +840,12 @@ var Tile = new Class({ * @method Phaser.Tilemaps.Tile#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.collisionCallback = undefined; this.collisionCallbackContext = undefined; this.properties = undefined; - }, + } /** * True if this tile can collide on any of its faces or has a collision callback set. @@ -854,14 +855,11 @@ var Tile = new Class({ * @readonly * @since 3.0.0 */ - canCollide: { - - get: function () - { - return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown || (this.collisionCallback !== undefined)); - } - }, + get canCollide() + { + return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown || (this.collisionCallback !== undefined)); + } /** * True if this tile can collide on any of its faces. @@ -871,14 +869,11 @@ var Tile = new Class({ * @readonly * @since 3.0.0 */ - collides: { - get: function () - { - return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown); - } - - }, + get collides() + { + return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown); + } /** * True if this tile has any interesting faces. @@ -888,14 +883,11 @@ var Tile = new Class({ * @readonly * @since 3.0.0 */ - hasInterestingFace: { - get: function () - { - return (this.faceTop || this.faceBottom || this.faceLeft || this.faceRight); - } - - }, + get hasInterestingFace() + { + return (this.faceTop || this.faceBottom || this.faceLeft || this.faceRight); + } /** * The tileset that contains this Tile. This is null if accessed from a LayerData instance @@ -907,26 +899,23 @@ var Tile = new Class({ * @readonly * @since 3.0.0 */ - tileset: { - get: function () + get tileset() + { + var tilemapLayer = this.layer.tilemapLayer; + + if (tilemapLayer) { - var tilemapLayer = this.layer.tilemapLayer; + var tileset = tilemapLayer.gidMap[this.index]; - if (tilemapLayer) + if (tileset) { - var tileset = tilemapLayer.gidMap[this.index]; - - if (tileset) - { - return tileset; - } + return tileset; } - - return null; } - }, + return null; + } /** * The tilemap layer that contains this Tile. This will only return null if accessed from a @@ -937,14 +926,11 @@ var Tile = new Class({ * @readonly * @since 3.0.0 */ - tilemapLayer: { - get: function () - { - return this.layer.tilemapLayer; - } - - }, + get tilemapLayer() + { + return this.layer.tilemapLayer; + } /** * The tilemap that contains this Tile. This will only return null if accessed from a LayerData @@ -955,17 +941,14 @@ var Tile = new Class({ * @readonly * @since 3.0.0 */ - tilemap: { - - get: function () - { - var tilemapLayer = this.tilemapLayer; - return tilemapLayer ? tilemapLayer.tilemap : null; - } + get tilemap() + { + var tilemapLayer = this.tilemapLayer; + return tilemapLayer ? tilemapLayer.tilemap : null; } -}); +}; module.exports = Tile; diff --git a/src/tilemaps/Tilemap.js b/src/tilemaps/Tilemap.js index 5969fadae1..41a121ccbe 100644 --- a/src/tilemaps/Tilemap.js +++ b/src/tilemaps/Tilemap.js @@ -101,11 +101,9 @@ var Tileset = require('./Tileset'); * @param {Phaser.Scene} scene - The Scene to which this Tilemap belongs. * @param {Phaser.Tilemaps.MapData} mapData - A MapData instance containing Tilemap data. */ -var Tilemap = new Class({ +var Tilemap = class { - initialize: - - function Tilemap (scene, mapData) + constructor(scene, mapData) { /** * @name Phaser.Tilemaps.Tilemap#scene @@ -321,7 +319,7 @@ var Tilemap = new Class({ TileToWorldY: TilemapComponents.GetTileToWorldYFunction(orientation), GetTileCorners: TilemapComponents.GetTileCornersFunction(orientation) }; - }, + } /** * Sets the rendering (draw) order of the tiles in this map. @@ -352,7 +350,7 @@ var Tilemap = new Class({ * * @return {this} This Tilemap object. */ - setRenderOrder: function (renderOrder) + setRenderOrder(renderOrder) { var orders = [ 'right-down', 'left-down', 'right-up', 'left-up' ]; @@ -367,7 +365,7 @@ var Tilemap = new Class({ } return this; - }, + } /** * Adds an image to the map to be used as a tileset. A single map may use multiple tilesets. @@ -398,7 +396,7 @@ var Tilemap = new Class({ * @return {?Phaser.Tilemaps.Tileset} Returns the Tileset object that was created or updated, or null if it * failed. */ - addTilesetImage: function (tilesetName, key, tileWidth, tileHeight, tileMargin, tileSpacing, gid, tileOffset) + addTilesetImage(tilesetName, key, tileWidth, tileHeight, tileMargin, tileSpacing, gid, tileOffset) { if (tilesetName === undefined) { return null; } if (key === undefined || key === null) { key = tilesetName; } @@ -456,7 +454,7 @@ var Tilemap = new Class({ this.tiles = BuildTilesetIndex(this); return tileset; - }, + } /** * Copies the tiles in the source rectangular area to a new destination (all specified in tile @@ -479,7 +477,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer) + copy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer) { layer = this.getLayer(layer); @@ -498,7 +496,7 @@ var Tilemap = new Class({ { return null; } - }, + } /** * Creates a new and empty Tilemap Layer. The currently selected layer in the map is set to this new layer. @@ -519,7 +517,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.TilemapLayer} Returns the new layer that was created, or `null` if it failed. */ - createBlankLayer: function (name, tileset, x, y, width, height, tileWidth, tileHeight) + createBlankLayer(name, tileset, x, y, width, height, tileWidth, tileHeight) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } @@ -571,7 +569,7 @@ var Tilemap = new Class({ this.scene.sys.displayList.add(layer); return layer; - }, + } /** * Creates a new Tilemap Layer that renders the LayerData associated with the given @@ -594,7 +592,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.TilemapLayer|?Phaser.Tilemaps.TilemapGPULayer} Returns the new layer was created, or null if it failed. */ - createLayer: function (layerID, tileset, x, y, gpu) + createLayer(layerID, tileset, x, y, gpu) { var index = this.getLayerIndex(layerID); @@ -650,7 +648,7 @@ var Tilemap = new Class({ this.scene.sys.displayList.add(layer); return layer; - }, + } /** * This method will iterate through all of the objects defined in a Tiled Object Layer and then @@ -794,7 +792,7 @@ var Tilemap = new Class({ * * @return {Phaser.GameObjects.GameObject[]} An array containing the Game Objects that were created. Empty if invalid object layer, or no matching id/gid/name was found. */ - createFromObjects: function (objectLayerName, config, useTileset) + createFromObjects(objectLayerName, config, useTileset) { if (useTileset === undefined) { useTileset = true; } @@ -934,7 +932,7 @@ var Tilemap = new Class({ } return results; - }, + } /** * Creates a Sprite for every tile matching the given tile indexes in the layer. You can @@ -972,14 +970,14 @@ var Tilemap = new Class({ * * @return {?Phaser.GameObjects.Sprite[]} Returns an array of Tiles, or null if the layer given was invalid. */ - createFromTiles: function (indexes, replacements, spriteConfig, scene, camera, layer) + createFromTiles(indexes, replacements, spriteConfig, scene, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.CreateFromTiles(indexes, replacements, spriteConfig, scene, camera, layer); - }, + } /** * Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the @@ -1002,7 +1000,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - fill: function (index, tileX, tileY, width, height, recalculateFaces, layer) + fill(index, tileX, tileY, width, height, recalculateFaces, layer) { if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -1013,7 +1011,7 @@ var Tilemap = new Class({ TilemapComponents.Fill(index, tileX, tileY, width, height, recalculateFaces, layer); return this; - }, + } /** * For each object in the given object layer, run the given filter callback function. Any @@ -1029,7 +1027,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Types.Tilemaps.TiledObject[]} An array of object that match the search, or null if the objectLayer given was invalid. */ - filterObjects: function (objectLayer, callback, context) + filterObjects(objectLayer, callback, context) { if (typeof objectLayer === 'string') { @@ -1045,7 +1043,7 @@ var Tilemap = new Class({ } return objectLayer.objects.filter(callback, context); - }, + } /** * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given @@ -1069,14 +1067,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile[]} Returns an array of Tiles, or null if the layer given was invalid. */ - filterTiles: function (callback, context, tileX, tileY, width, height, filteringOptions, layer) + filterTiles(callback, context, tileX, tileY, width, height, filteringOptions, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.FilterTiles(callback, context, tileX, tileY, width, height, filteringOptions, layer); - }, + } /** * Searches the entire map layer for the first tile matching the given index, then returns that Tile @@ -1096,14 +1094,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile} Returns a Tiles, or null if the layer given was invalid. */ - findByIndex: function (findIndex, skip, reverse, layer) + findByIndex(findIndex, skip, reverse, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.FindByIndex(findIndex, skip, reverse, layer); - }, + } /** * Find the first object in the given object layer that satisfies the provided testing function. @@ -1119,7 +1117,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Types.Tilemaps.TiledObject} An object that matches the search, or null if no object found. */ - findObject: function (objectLayer, callback, context) + findObject(objectLayer, callback, context) { if (typeof objectLayer === 'string') { @@ -1135,7 +1133,7 @@ var Tilemap = new Class({ } return objectLayer.objects.find(callback, context) || null; - }, + } /** * Find the first tile in the given rectangular area (in tile coordinates) of the layer that @@ -1157,14 +1155,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile} Returns a Tiles, or null if the layer given was invalid. */ - findTile: function (callback, context, tileX, tileY, width, height, filteringOptions, layer) + findTile(callback, context, tileX, tileY, width, height, filteringOptions, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.FindTile(callback, context, tileX, tileY, width, height, filteringOptions, layer); - }, + } /** * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given @@ -1186,7 +1184,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - forEachTile: function (callback, context, tileX, tileY, width, height, filteringOptions, layer) + forEachTile(callback, context, tileX, tileY, width, height, filteringOptions, layer) { layer = this.getLayer(layer); @@ -1195,7 +1193,7 @@ var Tilemap = new Class({ TilemapComponents.ForEachTile(callback, context, tileX, tileY, width, height, filteringOptions, layer); return this; - }, + } /** * Gets the image layer index based on its name. @@ -1207,10 +1205,10 @@ var Tilemap = new Class({ * * @return {number} The index of the image in this tilemap, or null if not found. */ - getImageIndex: function (name) + getImageIndex(name) { return this.getIndex(this.images, name); - }, + } /** * Return a list of all valid imagelayer names loaded in this Tilemap. @@ -1220,7 +1218,7 @@ var Tilemap = new Class({ * * @return {string[]} Array of valid imagelayer names / IDs loaded into this Tilemap. */ - getImageLayerNames: function () + getImageLayerNames() { if (!this.images || !Array.isArray(this.images)) { @@ -1231,7 +1229,7 @@ var Tilemap = new Class({ { return image.name; }); - }, + } /** * Internally used. Returns the index of the object in one of the Tilemaps arrays whose name @@ -1245,7 +1243,7 @@ var Tilemap = new Class({ * * @return {number} The index of the element in the array, or null if not found. */ - getIndex: function (location, name) + getIndex(location, name) { for (var i = 0; i < location.length; i++) { @@ -1256,7 +1254,7 @@ var Tilemap = new Class({ } return null; - }, + } /** * Gets the LayerData from `this.layers` that is associated with the given `layer`, or null if the layer is invalid. @@ -1268,12 +1266,12 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.LayerData} The corresponding `LayerData` within `this.layers`, or null. */ - getLayer: function (layer) + getLayer(layer) { var index = this.getLayerIndex(layer); return (index !== null) ? this.layers[ index ] : null; - }, + } /** * Gets the ObjectLayer from `this.objects` that has the given `name`, or null if no ObjectLayer is found with that name. @@ -1285,12 +1283,12 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.ObjectLayer} The corresponding `ObjectLayer` within `this.objects`, or null. */ - getObjectLayer: function (name) + getObjectLayer(name) { var index = this.getIndex(this.objects, name); return (index !== null) ? this.objects[ index ] : null; - }, + } /** * Return a list of all valid objectgroup names loaded in this Tilemap. @@ -1300,7 +1298,7 @@ var Tilemap = new Class({ * * @return {string[]} Array of valid objectgroup names / IDs loaded into this Tilemap. */ - getObjectLayerNames: function () + getObjectLayerNames() { if (!this.objects || !Array.isArray(this.objects)) { @@ -1311,7 +1309,7 @@ var Tilemap = new Class({ { return object.name; }); - }, + } /** * Gets the LayerData index of the given `layer` within this.layers, or null if an invalid @@ -1324,7 +1322,7 @@ var Tilemap = new Class({ * * @return {number} The LayerData index within this.layers. */ - getLayerIndex: function (layer) + getLayerIndex(layer) { if (layer === undefined) { @@ -1346,7 +1344,7 @@ var Tilemap = new Class({ { return null; } - }, + } /** * Gets the index of the LayerData within this.layers that has the given `name`, or null if an @@ -1359,10 +1357,10 @@ var Tilemap = new Class({ * * @return {number} The LayerData index within this.layers. */ - getLayerIndexByName: function (name) + getLayerIndexByName(name) { return this.getIndex(this.layers, name); - }, + } /** * Gets a tile at the given tile coordinates from the given layer. @@ -1379,14 +1377,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid. */ - getTileAt: function (tileX, tileY, nonNull, layer) + getTileAt(tileX, tileY, nonNull, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.GetTileAt(tileX, tileY, nonNull, layer); - }, + } /** * Gets a tile at the given world coordinates from the given layer. @@ -1404,14 +1402,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid. */ - getTileAtWorldXY: function (worldX, worldY, nonNull, camera, layer) + getTileAtWorldXY(worldX, worldY, nonNull, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, layer); - }, + } /** * Return a list of all valid tilelayer names loaded in this Tilemap. @@ -1421,7 +1419,7 @@ var Tilemap = new Class({ * * @return {string[]} Array of valid tilelayer names / IDs loaded into this Tilemap. */ - getTileLayerNames: function () + getTileLayerNames() { if (!this.layers || !Array.isArray(this.layers)) { @@ -1432,7 +1430,7 @@ var Tilemap = new Class({ { return layer.name; }); - }, + } /** * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. @@ -1451,14 +1449,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile[]} Returns an array of Tiles, or null if the layer given was invalid. */ - getTilesWithin: function (tileX, tileY, width, height, filteringOptions, layer) + getTilesWithin(tileX, tileY, width, height, filteringOptions, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.GetTilesWithin(tileX, tileY, width, height, filteringOptions, layer); - }, + } /** * Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, @@ -1476,14 +1474,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile[]} Returns an array of Tiles, or null if the layer given was invalid. */ - getTilesWithinShape: function (shape, filteringOptions, camera, layer) + getTilesWithinShape(shape, filteringOptions, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.GetTilesWithinShape(shape, filteringOptions, camera, layer); - }, + } /** * Gets the tiles in the given rectangular area (in world coordinates) of the layer. @@ -1503,14 +1501,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile[]} Returns an array of Tiles, or null if the layer given was invalid. */ - getTilesWithinWorldXY: function (worldX, worldY, width, height, filteringOptions, camera, layer) + getTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.GetTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, layer); - }, + } /** * Gets the Tileset that has the given `name`, or null if an invalid `name` is given. @@ -1522,12 +1520,12 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tileset} The Tileset, or `null` if no matching named tileset was found. */ - getTileset: function (name) + getTileset(name) { var index = this.getIndex(this.tilesets, name); return (index !== null) ? this.tilesets[ index ] : null; - }, + } /** * Gets the index of the Tileset within this.tilesets that has the given `name`, or null if an @@ -1540,10 +1538,10 @@ var Tilemap = new Class({ * * @return {number} The Tileset index within this.tilesets. */ - getTilesetIndex: function (name) + getTilesetIndex(name) { return this.getIndex(this.tilesets, name); - }, + } /** * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns @@ -1560,14 +1558,14 @@ var Tilemap = new Class({ * * @return {?boolean} Returns a boolean, or null if the layer given was invalid. */ - hasTileAt: function (tileX, tileY, layer) + hasTileAt(tileX, tileY, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.HasTileAt(tileX, tileY, layer); - }, + } /** * Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns @@ -1585,14 +1583,14 @@ var Tilemap = new Class({ * * @return {?boolean} Returns a boolean, or null if the layer given was invalid. */ - hasTileAtWorldXY: function (worldX, worldY, camera, layer) + hasTileAtWorldXY(worldX, worldY, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, layer); - }, + } /** * The LayerData object that is currently selected in the map. You can set this property using @@ -1602,17 +1600,16 @@ var Tilemap = new Class({ * @type {Phaser.Tilemaps.LayerData} * @since 3.0.0 */ - layer: { - get: function () - { - return this.layers[ this.currentLayerIndex ]; - }, - set: function (layer) - { - this.setLayer(layer); - } - }, + get layer() + { + return this.layers[ this.currentLayerIndex ]; + } + + set layer(layer) + { + this.setLayer(layer); + } /** * Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index @@ -1633,7 +1630,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid or the coordinates were out of bounds. */ - putTileAt: function (tile, tileX, tileY, recalculateFaces, layer) + putTileAt(tile, tileX, tileY, recalculateFaces, layer) { if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -1642,7 +1639,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } return TilemapComponents.PutTileAt(tile, tileX, tileY, recalculateFaces, layer); - }, + } /** * Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either @@ -1664,7 +1661,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid. */ - putTileAtWorldXY: function (tile, worldX, worldY, recalculateFaces, camera, layer) + putTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, layer) { if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -1673,7 +1670,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } return TilemapComponents.PutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, layer); - }, + } /** * Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified @@ -1695,7 +1692,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - putTilesAt: function (tilesArray, tileX, tileY, recalculateFaces, layer) + putTilesAt(tilesArray, tileX, tileY, recalculateFaces, layer) { if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -1706,7 +1703,7 @@ var Tilemap = new Class({ TilemapComponents.PutTilesAt(tilesArray, tileX, tileY, recalculateFaces, layer); return this; - }, + } /** * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the @@ -1729,7 +1726,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - randomize: function (tileX, tileY, width, height, indexes, layer) + randomize(tileX, tileY, width, height, indexes, layer) { layer = this.getLayer(layer); @@ -1738,7 +1735,7 @@ var Tilemap = new Class({ TilemapComponents.Randomize(tileX, tileY, width, height, indexes, layer); return this; - }, + } /** * Calculates interesting faces at the given tile coordinates of the specified layer. Interesting @@ -1756,7 +1753,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - calculateFacesAt: function (tileX, tileY, layer) + calculateFacesAt(tileX, tileY, layer) { layer = this.getLayer(layer); @@ -1765,7 +1762,7 @@ var Tilemap = new Class({ TilemapComponents.CalculateFacesAt(tileX, tileY, layer); return this; - }, + } /** * Calculates interesting faces within the rectangular area specified (in tile coordinates) of the @@ -1785,7 +1782,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - calculateFacesWithin: function (tileX, tileY, width, height, layer) + calculateFacesWithin(tileX, tileY, width, height, layer) { layer = this.getLayer(layer); @@ -1794,7 +1791,7 @@ var Tilemap = new Class({ TilemapComponents.CalculateFacesWithin(tileX, tileY, width, height, layer); return this; - }, + } /** * Removes the given TilemapLayer from this Tilemap without destroying it. @@ -1808,7 +1805,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - removeLayer: function (layer) + removeLayer(layer) { var index = this.getLayerIndex(layer); @@ -1835,7 +1832,7 @@ var Tilemap = new Class({ { return null; } - }, + } /** * Destroys the given TilemapLayer and removes it from this Tilemap. @@ -1849,7 +1846,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid. */ - destroyLayer: function (layer) + destroyLayer(layer) { var index = this.getLayerIndex(layer); @@ -1872,7 +1869,7 @@ var Tilemap = new Class({ { return null; } - }, + } /** * Removes all Tilemap Layers from this Tilemap and calls `destroy` on each of them. @@ -1882,7 +1879,7 @@ var Tilemap = new Class({ * * @return {this} This Tilemap object. */ - removeAllLayers: function () + removeAllLayers() { var layers = this.layers; @@ -1899,7 +1896,7 @@ var Tilemap = new Class({ this.currentLayerIndex = 0; return this; - }, + } /** * Removes the given Tile, or an array of Tiles, from the layer to which they belong, @@ -1914,7 +1911,7 @@ var Tilemap = new Class({ * * @return {Phaser.Tilemaps.Tile[]} Returns an array of Tiles that were removed. */ - removeTile: function (tiles, replaceIndex, recalculateFaces) + removeTile(tiles, replaceIndex, recalculateFaces) { if (replaceIndex === undefined) { replaceIndex = -1; } if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -1939,7 +1936,7 @@ var Tilemap = new Class({ } return removed; - }, + } /** * Removes the tile at the given tile coordinates in the specified layer and updates the layers collision information. @@ -1957,7 +1954,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile} Returns the Tile that was removed, or null if the layer given was invalid. */ - removeTileAt: function (tileX, tileY, replaceWithNull, recalculateFaces, layer) + removeTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer) { if (replaceWithNull === undefined) { replaceWithNull = true; } if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -1967,7 +1964,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } return TilemapComponents.RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer); - }, + } /** * Removes the tile at the given world coordinates in the specified layer and updates the layers collision information. @@ -1986,7 +1983,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid. */ - removeTileAtWorldXY: function (worldX, worldY, replaceWithNull, recalculateFaces, camera, layer) + removeTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, layer) { if (replaceWithNull === undefined) { replaceWithNull = true; } if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -1996,7 +1993,7 @@ var Tilemap = new Class({ if (layer === null) { return null; } return TilemapComponents.RemoveTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, layer); - }, + } /** * Draws a debug representation of the layer to the given Graphics object. This is helpful when you want to @@ -2017,7 +2014,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - renderDebug: function (graphics, styleConfig, layer) + renderDebug(graphics, styleConfig, layer) { layer = this.getLayer(layer); @@ -2029,7 +2026,7 @@ var Tilemap = new Class({ } return this; - }, + } /** * Draws a debug representation of all layers within this Tilemap to the given Graphics object. @@ -2046,7 +2043,7 @@ var Tilemap = new Class({ * * @return {this} This Tilemap instance. */ - renderDebugFull: function (graphics, styleConfig) + renderDebugFull(graphics, styleConfig) { var layers = this.layers; @@ -2056,7 +2053,7 @@ var Tilemap = new Class({ } return this; - }, + } /** * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching @@ -2078,7 +2075,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height, layer) + replaceByIndex(findIndex, newIndex, tileX, tileY, width, height, layer) { layer = this.getLayer(layer); @@ -2087,7 +2084,7 @@ var Tilemap = new Class({ TilemapComponents.ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, layer); return this; - }, + } /** * Sets collision on the given tile or tiles within a layer by index. You can pass in either a @@ -2107,7 +2104,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - setCollision: function (indexes, collides, recalculateFaces, layer, updateLayer) + setCollision(indexes, collides, recalculateFaces, layer, updateLayer) { if (collides === undefined) { collides = true; } if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -2120,7 +2117,7 @@ var Tilemap = new Class({ TilemapComponents.SetCollision(indexes, collides, recalculateFaces, layer, updateLayer); return this; - }, + } /** * Sets collision on a range of tiles in a layer whose index is between the specified `start` and @@ -2141,7 +2138,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - setCollisionBetween: function (start, stop, collides, recalculateFaces, layer) + setCollisionBetween(start, stop, collides, recalculateFaces, layer) { if (collides === undefined) { collides = true; } if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -2153,7 +2150,7 @@ var Tilemap = new Class({ TilemapComponents.SetCollisionBetween(start, stop, collides, recalculateFaces, layer); return this; - }, + } /** * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property @@ -2176,7 +2173,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - setCollisionByProperty: function (properties, collides, recalculateFaces, layer) + setCollisionByProperty(properties, collides, recalculateFaces, layer) { if (collides === undefined) { collides = true; } if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -2188,7 +2185,7 @@ var Tilemap = new Class({ TilemapComponents.SetCollisionByProperty(properties, collides, recalculateFaces, layer); return this; - }, + } /** * Sets collision on all tiles in the given layer, except for tiles that have an index specified in @@ -2207,7 +2204,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - setCollisionByExclusion: function (indexes, collides, recalculateFaces, layer) + setCollisionByExclusion(indexes, collides, recalculateFaces, layer) { if (collides === undefined) { collides = true; } if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -2219,7 +2216,7 @@ var Tilemap = new Class({ TilemapComponents.SetCollisionByExclusion(indexes, collides, recalculateFaces, layer); return this; - }, + } /** * Sets collision on the tiles within a layer by checking each tiles collision group data @@ -2238,7 +2235,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - setCollisionFromCollisionGroup: function (collides, recalculateFaces, layer) + setCollisionFromCollisionGroup(collides, recalculateFaces, layer) { if (collides === undefined) { collides = true; } if (recalculateFaces === undefined) { recalculateFaces = true; } @@ -2250,7 +2247,7 @@ var Tilemap = new Class({ TilemapComponents.SetCollisionFromCollisionGroup(collides, recalculateFaces, layer); return this; - }, + } /** * Sets a global collision callback for the given tile index within the layer. This will affect all @@ -2270,7 +2267,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - setTileIndexCallback: function (indexes, callback, callbackContext, layer) + setTileIndexCallback(indexes, callback, callbackContext, layer) { layer = this.getLayer(layer); @@ -2279,7 +2276,7 @@ var Tilemap = new Class({ TilemapComponents.SetTileIndexCallback(indexes, callback, callbackContext, layer); return this; - }, + } /** * Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. @@ -2301,7 +2298,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - setTileLocationCallback: function (tileX, tileY, width, height, callback, callbackContext, layer) + setTileLocationCallback(tileX, tileY, width, height, callback, callbackContext, layer) { layer = this.getLayer(layer); @@ -2310,7 +2307,7 @@ var Tilemap = new Class({ TilemapComponents.SetTileLocationCallback(tileX, tileY, width, height, callback, callbackContext, layer); return this; - }, + } /** * Sets the current layer to the LayerData associated with `layer`. @@ -2322,7 +2319,7 @@ var Tilemap = new Class({ * * @return {this} This Tilemap object. */ - setLayer: function (layer) + setLayer(layer) { var index = this.getLayerIndex(layer); @@ -2332,7 +2329,7 @@ var Tilemap = new Class({ } return this; - }, + } /** * Sets the base tile size for the map. Note: this does not necessarily match the tileWidth and @@ -2346,7 +2343,7 @@ var Tilemap = new Class({ * * @return {this} This Tilemap object. */ - setBaseTileSize: function (tileWidth, tileHeight) + setBaseTileSize(tileWidth, tileHeight) { this.tileWidth = tileWidth; this.tileHeight = tileHeight; @@ -2378,7 +2375,7 @@ var Tilemap = new Class({ } return this; - }, + } /** * Sets the tile size for a specific `layer`. Note: this does not necessarily match the maps @@ -2394,7 +2391,7 @@ var Tilemap = new Class({ * * @return {this} This Tilemap object. */ - setLayerTileSize: function (tileWidth, tileHeight, layer) + setLayerTileSize(tileWidth, tileHeight, layer) { layer = this.getLayer(layer); @@ -2421,7 +2418,7 @@ var Tilemap = new Class({ } return this; - }, + } /** * Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given @@ -2442,7 +2439,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - shuffle: function (tileX, tileY, width, height, layer) + shuffle(tileX, tileY, width, height, layer) { layer = this.getLayer(layer); @@ -2451,7 +2448,7 @@ var Tilemap = new Class({ TilemapComponents.Shuffle(tileX, tileY, width, height, layer); return this; - }, + } /** * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching @@ -2473,7 +2470,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - swapByIndex: function (indexA, indexB, tileX, tileY, width, height, layer) + swapByIndex(indexA, indexB, tileX, tileY, width, height, layer) { layer = this.getLayer(layer); @@ -2482,7 +2479,7 @@ var Tilemap = new Class({ TilemapComponents.SwapByIndex(indexA, indexB, tileX, tileY, width, height, layer); return this; - }, + } /** * Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the @@ -2499,14 +2496,14 @@ var Tilemap = new Class({ * * @return {?number} Returns a number, or null if the layer given was invalid. */ - tileToWorldX: function (tileX, camera, layer) + tileToWorldX(tileX, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return this._convert.TileToWorldX(tileX, camera, layer); - }, + } /** * Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the @@ -2523,14 +2520,14 @@ var Tilemap = new Class({ * * @return {?number} Returns a number, or null if the layer given was invalid. */ - tileToWorldY: function (tileY, camera, layer) + tileToWorldY(tileY, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return this._convert.TileToWorldY(tileY, camera, layer); - }, + } /** * Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the @@ -2550,14 +2547,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Math.Vector2} Returns a Vector2, or null if the layer given was invalid. */ - tileToWorldXY: function (tileX, tileY, vec2, camera, layer) + tileToWorldXY(tileX, tileY, vec2, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return this._convert.TileToWorldXY(tileX, tileY, vec2, camera, layer); - }, + } /** * Returns an array of Vector2s where each entry corresponds to the corner of the requested tile. @@ -2583,14 +2580,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Math.Vector2[]} Returns an array of Vector2s, or null if the layer given was invalid. */ - getTileCorners: function (tileX, tileY, camera, layer) + getTileCorners(tileX, tileY, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return this._convert.GetTileCorners(tileX, tileY, camera, layer); - }, + } /** * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the @@ -2621,7 +2618,7 @@ var Tilemap = new Class({ * * @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid. */ - weightedRandomize: function (weightedIndexes, tileX, tileY, width, height, layer) + weightedRandomize(weightedIndexes, tileX, tileY, width, height, layer) { layer = this.getLayer(layer); @@ -2630,7 +2627,7 @@ var Tilemap = new Class({ TilemapComponents.WeightedRandomize(tileX, tileY, width, height, weightedIndexes, layer); return this; - }, + } /** * Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the @@ -2652,14 +2649,14 @@ var Tilemap = new Class({ * * @return {?number} Returns a number, or null if the layer given was invalid. */ - worldToTileX: function (worldX, snapToFloor, camera, layer) + worldToTileX(worldX, snapToFloor, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return this._convert.WorldToTileX(worldX, snapToFloor, camera, layer); - }, + } /** * Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the @@ -2681,14 +2678,14 @@ var Tilemap = new Class({ * * @return {?number} Returns a number, or null if the layer given was invalid. */ - worldToTileY: function (worldY, snapToFloor, camera, layer) + worldToTileY(worldY, snapToFloor, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return this._convert.WorldToTileY(worldY, snapToFloor, camera, layer); - }, + } /** * Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the @@ -2709,14 +2706,14 @@ var Tilemap = new Class({ * * @return {?Phaser.Math.Vector2} Returns a vec2, or null if the layer given was invalid. */ - worldToTileXY: function (worldX, worldY, snapToFloor, vec2, camera, layer) + worldToTileXY(worldX, worldY, snapToFloor, vec2, camera, layer) { layer = this.getLayer(layer); if (layer === null) { return null; } return this._convert.WorldToTileXY(worldX, worldY, snapToFloor, vec2, camera, layer); - }, + } /** * Removes all layer data from this Tilemap and nulls the scene reference. This will destroy any @@ -2725,7 +2722,7 @@ var Tilemap = new Class({ * @method Phaser.Tilemaps.Tilemap#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.removeAllLayers(); @@ -2736,6 +2733,6 @@ var Tilemap = new Class({ this.scene = null; } -}); +}; module.exports = Tilemap; diff --git a/src/tilemaps/TilemapGPULayer.js b/src/tilemaps/TilemapGPULayer.js index 891bf9247c..d6af676ac8 100644 --- a/src/tilemaps/TilemapGPULayer.js +++ b/src/tilemaps/TilemapGPULayer.js @@ -75,16 +75,18 @@ var TilemapGPULayerRender = require('./TilemapGPULayerRender'); * @param {number} [x] - The world x position where the top left of this layer will be placed. * @param {number} [y] - The world y position where the top left of this layer will be placed. */ -var TilemapGPULayer = new Class({ - Extends: TilemapLayerBase, +var TilemapGPULayer = class extends TilemapLayerBase { - Mixins: [ - TilemapGPULayerRender - ], + static + { + Class.mixin(this, [ + TilemapGPULayerRender + ], false); + } - initialize: function TilemapGPULayer (scene, tilemap, layerIndex, tileset, x, y) + constructor(scene, tilemap, layerIndex, tileset, x, y) { - TilemapLayerBase.call(this, 'TilemapGPULayer', scene, tilemap, layerIndex, x, y); + super('TilemapGPULayer', scene, tilemap, layerIndex, x, y); /** * The `Tileset` associated with this layer. @@ -119,7 +121,7 @@ var TilemapGPULayer = new Class({ this.setTileset(tileset); this.initRenderNodes(this._defaultRenderNodesMap); - }, + } /** * The default render nodes for this Game Object. @@ -131,12 +133,11 @@ var TilemapGPULayer = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultTilemapGPULayerNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultTilemapGPULayerNodes; + } /** * Populates data structures to render this tilemap layer. @@ -147,7 +148,7 @@ var TilemapGPULayer = new Class({ * * @param {(string|Phaser.Tilemaps.Tileset)} tileset - The tileset used to render this layer. Can be a string or a Tileset object. */ - setTileset: function (tileset) + setTileset(tileset) { if (typeof tileset === 'string') { @@ -158,7 +159,7 @@ var TilemapGPULayer = new Class({ // Convert layer into a data texture. this.generateLayerDataTexture(); - }, + } /** * Generate the data textures for this game object. @@ -167,7 +168,7 @@ var TilemapGPULayer = new Class({ * @method Phaser.Tilemaps.TilemapGPULayer#generateLayerDataTexture * @since 4.0.0 */ - generateLayerDataTexture: function () + generateLayerDataTexture() { var layer = this.layer; var tileset = this.tileset; @@ -229,6 +230,6 @@ var TilemapGPULayer = new Class({ var u8 = new Uint8Array(u32.buffer); this.layerDataTexture = renderer.createUint8ArrayTexture(u8, layer.width, layer.height, false, true); } -}); +}; module.exports = TilemapGPULayer; diff --git a/src/tilemaps/TilemapLayer.js b/src/tilemaps/TilemapLayer.js index 01453d7010..c287ff6c2c 100644 --- a/src/tilemaps/TilemapLayer.js +++ b/src/tilemaps/TilemapLayer.js @@ -32,19 +32,18 @@ var TilemapLayerBase = require('./TilemapLayerBase'); * @param {number} [x=0] - The world x position where the top left of this layer will be placed. * @param {number} [y=0] - The world y position where the top left of this layer will be placed. */ -var TilemapLayer = new Class({ +var TilemapLayer = class extends TilemapLayerBase { - Extends: TilemapLayerBase, - - Mixins: [ - TilemapLayerRender - ], - - initialize: + static + { + Class.mixin(this, [ + TilemapLayerRender + ], false); + } - function TilemapLayer (scene, tilemap, layerIndex, tileset, x, y) + constructor(scene, tilemap, layerIndex, tileset, x, y) { - TilemapLayerBase.call(this, 'TilemapLayer', scene, tilemap, layerIndex, x, y); + super('TilemapLayer', scene, tilemap, layerIndex, x, y); /** * An array of `Tileset` objects associated with this layer. @@ -175,7 +174,7 @@ var TilemapLayer = new Class({ this.setTilesets(tileset); this.initRenderNodes(this._defaultRenderNodesMap); - }, + } /** * The default render nodes for this Game Object. @@ -187,12 +186,11 @@ var TilemapLayer = new Class({ * @readonly * @since 4.0.0 */ - _defaultRenderNodesMap: { - get: function () - { - return DefaultTilemapLayerNodes; - } - }, + + get _defaultRenderNodesMap() + { + return DefaultTilemapLayerNodes; + } /** * Populates the internal `tileset` array with the Tileset references this Layer requires for rendering. @@ -203,7 +201,7 @@ var TilemapLayer = new Class({ * * @param {(string|string[]|Phaser.Tilemaps.Tileset|Phaser.Tilemaps.Tileset[])} tileset - The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. */ - setTilesets: function (tilesets) + setTilesets(tilesets) { var gidMap = []; var setList = []; @@ -238,7 +236,7 @@ var TilemapLayer = new Class({ this.gidMap = gidMap; this.tileset = setList; - }, + } /** * Sets the rendering (draw) order of the tiles in this layer. @@ -265,7 +263,7 @@ var TilemapLayer = new Class({ * * @return {this} This Tilemap Layer object. */ - setRenderOrder: function (renderOrder) + setRenderOrder(renderOrder) { var orders = [ 'right-down', 'left-down', 'right-up', 'left-up' ]; @@ -280,7 +278,7 @@ var TilemapLayer = new Class({ } return this; - }, + } /** * Returns the tiles in the given layer that are within the cameras viewport. @@ -293,10 +291,10 @@ var TilemapLayer = new Class({ * * @return {Phaser.Tilemaps.Tile[]} An array of Tile objects to render. */ - cull: function (camera) + cull(camera) { return this.cullCallback(this.layer, camera, this.culledTiles, this._renderOrder); - }, + } /** * You can control if the Cameras should cull tiles before rendering them or not. @@ -312,14 +310,14 @@ var TilemapLayer = new Class({ * * @return {this} This Tilemap Layer object. */ - setSkipCull: function (value) + setSkipCull(value) { if (value === undefined) { value = true; } this.skipCull = value; return this; - }, + } /** * When a Camera culls the tiles in this layer it does so using its view into the world, building up a @@ -336,7 +334,7 @@ var TilemapLayer = new Class({ * * @return {this} This Tilemap Layer object. */ - setCullPadding: function (paddingX, paddingY) + setCullPadding(paddingX, paddingY) { if (paddingX === undefined) { paddingX = 1; } if (paddingY === undefined) { paddingY = 1; } @@ -345,7 +343,7 @@ var TilemapLayer = new Class({ this.cullPaddingY = paddingY; return this; - }, + } /** * Sets an additive tint on each Tile within the given area. @@ -372,7 +370,7 @@ var TilemapLayer = new Class({ * * @return {this} This Tilemap Layer object. */ - setTint: function (tint, tileX, tileY, width, height, filteringOptions) + setTint(tint, tileX, tileY, width, height, filteringOptions) { if (tint === undefined) { tint = 0xffffff; } @@ -383,7 +381,7 @@ var TilemapLayer = new Class({ }; return this.forEachTile(tintTile, this, tileX, tileY, width, height, filteringOptions); - }, + } /** * Sets a fill-based tint on each Tile within the given area. @@ -410,7 +408,7 @@ var TilemapLayer = new Class({ * * @return {this} This Tilemap Layer object. */ - setTintFill: function (tint, tileX, tileY, width, height, filteringOptions) + setTintFill(tint, tileX, tileY, width, height, filteringOptions) { if (tint === undefined) { tint = 0xffffff; } @@ -421,15 +419,15 @@ var TilemapLayer = new Class({ }; return this.forEachTile(tintTile, this, tileX, tileY, width, height, filteringOptions); - }, + } - destroy: function (removeFromTilemap) + destroy(removeFromTilemap) { this.culledTiles.length = 0; this.cullCallback = null; TilemapLayerBase.prototype.destroy.call(this, removeFromTilemap); } -}); +}; module.exports = TilemapLayer; diff --git a/src/tilemaps/TilemapLayerBase.js b/src/tilemaps/TilemapLayerBase.js index 3137d46c54..a2403ca96b 100644 --- a/src/tilemaps/TilemapLayerBase.js +++ b/src/tilemaps/TilemapLayerBase.js @@ -49,33 +49,32 @@ var Vector2 = require('../math/Vector2'); * @param {number} [x=0] - The world x position where the top left of this layer will be placed. * @param {number} [y=0] - The world y position where the top left of this layer will be placed. */ -var TilemapLayerBase = new Class({ - - Extends: GameObject, - - Mixins: [ - Components.Alpha, - Components.BlendMode, - Components.ComputedSize, - Components.Depth, - Components.ElapseTimer, - Components.Flip, - Components.GetBounds, - Components.Lighting, - Components.Mask, - Components.Origin, - Components.RenderNodes, - Components.Transform, - Components.Visible, - Components.ScrollFactor, - CollisionComponent - ], - - initialize: - - function TilemapLayerBase (type, scene, tilemap, layerIndex, x, y) +var TilemapLayerBase = class extends GameObject { + + static + { + Class.mixin(this, [ + Components.Alpha, + Components.BlendMode, + Components.ComputedSize, + Components.Depth, + Components.ElapseTimer, + Components.Flip, + Components.GetBounds, + Components.Lighting, + Components.Mask, + Components.Origin, + Components.RenderNodes, + Components.Transform, + Components.Visible, + Components.ScrollFactor, + CollisionComponent + ], false); + } + + constructor(type, scene, tilemap, layerIndex, x, y) { - GameObject.call(this, scene, type); + super(scene, type); /** * Used internally by physics system to perform fast type checks. @@ -209,24 +208,24 @@ var TilemapLayerBase = new Class({ this.setPosition(x, y); this.setOrigin(0, 0); this.setSize(tilemap.tileWidth * this.layer.width, tilemap.tileHeight * this.layer.height); - }, + } // Overrides Game Object method - addedToScene: function () + addedToScene() { this.scene.sys.updateList.add(this); - }, + } // Overrides Game Object method - removedFromScene: function () + removedFromScene() { this.scene.sys.updateList.remove(this); - }, + } - preUpdate: function (time, delta) + preUpdate(time, delta) { this.updateTimer(time, delta); - }, + } /** * Calculates interesting faces at the given tile coordinates of the specified layer. Interesting @@ -241,12 +240,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - calculateFacesAt: function (tileX, tileY) + calculateFacesAt(tileX, tileY) { TilemapComponents.CalculateFacesAt(tileX, tileY, this.layer); return this; - }, + } /** * Calculates interesting faces within the rectangular area specified (in tile coordinates) of the @@ -263,12 +262,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - calculateFacesWithin: function (tileX, tileY, width, height) + calculateFacesWithin(tileX, tileY, width, height) { TilemapComponents.CalculateFacesWithin(tileX, tileY, width, height, this.layer); return this; - }, + } /** * Creates a Sprite for every object matching the given tile indexes in the layer. You can @@ -290,10 +289,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.GameObjects.Sprite[]} An array of the Sprites that were created. */ - createFromTiles: function (indexes, replacements, spriteConfig, scene, camera) + createFromTiles(indexes, replacements, spriteConfig, scene, camera) { return TilemapComponents.CreateFromTiles(indexes, replacements, spriteConfig, scene, camera, this.layer); - }, + } /** * Copies the tiles in the source rectangular area to a new destination (all specified in tile @@ -313,12 +312,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces) + copy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces) { TilemapComponents.Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, this.layer); return this; - }, + } /** * Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the @@ -337,12 +336,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - fill: function (index, tileX, tileY, width, height, recalculateFaces) + fill(index, tileX, tileY, width, height, recalculateFaces) { TilemapComponents.Fill(index, tileX, tileY, width, height, recalculateFaces, this.layer); return this; - }, + } /** * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given @@ -364,10 +363,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile[]} An array of Tile objects. */ - filterTiles: function (callback, context, tileX, tileY, width, height, filteringOptions) + filterTiles(callback, context, tileX, tileY, width, height, filteringOptions) { return TilemapComponents.FilterTiles(callback, context, tileX, tileY, width, height, filteringOptions, this.layer); - }, + } /** * Searches the entire map layer for the first tile matching the given index, then returns that Tile @@ -385,10 +384,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile} The first matching Tile object. */ - findByIndex: function (findIndex, skip, reverse) + findByIndex(findIndex, skip, reverse) { return TilemapComponents.FindByIndex(findIndex, skip, reverse, this.layer); - }, + } /** * Find the first tile in the given rectangular area (in tile coordinates) of the layer that @@ -408,10 +407,10 @@ var TilemapLayerBase = new Class({ * * @return {?Phaser.Tilemaps.Tile} The first Tile found at the given location. */ - findTile: function (callback, context, tileX, tileY, width, height, filteringOptions) + findTile(callback, context, tileX, tileY, width, height, filteringOptions) { return TilemapComponents.FindTile(callback, context, tileX, tileY, width, height, filteringOptions, this.layer); - }, + } /** * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given @@ -430,12 +429,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - forEachTile: function (callback, context, tileX, tileY, width, height, filteringOptions) + forEachTile(callback, context, tileX, tileY, width, height, filteringOptions) { TilemapComponents.ForEachTile(callback, context, tileX, tileY, width, height, filteringOptions, this.layer); return this; - }, + } /** * Gets a tile at the given tile coordinates from the given layer. @@ -449,10 +448,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile} The Tile at the given coordinates or null if no tile was found or the coordinates were invalid. */ - getTileAt: function (tileX, tileY, nonNull) + getTileAt(tileX, tileY, nonNull) { return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer); - }, + } /** * Gets a tile at the given world coordinates from the given layer. @@ -467,10 +466,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile} The tile at the given coordinates or null if no tile was found or the coordinates were invalid. */ - getTileAtWorldXY: function (worldX, worldY, nonNull, camera) + getTileAtWorldXY(worldX, worldY, nonNull, camera) { return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, this.layer); - }, + } /** * Gets a tile at the given world coordinates from the given isometric layer. @@ -486,7 +485,7 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile} The tile at the given coordinates or null if no tile was found or the coordinates were invalid. */ - getIsoTileAtWorldXY: function (worldX, worldY, originTop, nonNull, camera) + getIsoTileAtWorldXY(worldX, worldY, originTop, nonNull, camera) { if (originTop === undefined) { originTop = true; } @@ -495,7 +494,7 @@ var TilemapLayerBase = new Class({ TilemapComponents.IsometricWorldToTileXY(worldX, worldY, true, point, camera, this.layer, originTop); return this.getTileAt(point.x, point.y, nonNull); - }, + } /** * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. @@ -511,10 +510,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile[]} An array of Tile objects found within the area. */ - getTilesWithin: function (tileX, tileY, width, height, filteringOptions) + getTilesWithin(tileX, tileY, width, height, filteringOptions) { return TilemapComponents.GetTilesWithin(tileX, tileY, width, height, filteringOptions, this.layer); - }, + } /** * Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, @@ -529,10 +528,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile[]} An array of Tile objects found within the shape. */ - getTilesWithinShape: function (shape, filteringOptions, camera) + getTilesWithinShape(shape, filteringOptions, camera) { return TilemapComponents.GetTilesWithinShape(shape, filteringOptions, camera, this.layer); - }, + } /** * Gets the tiles in the given rectangular area (in world coordinates) of the layer. @@ -549,10 +548,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile[]} An array of Tile objects found within the area. */ - getTilesWithinWorldXY: function (worldX, worldY, width, height, filteringOptions, camera) + getTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera) { return TilemapComponents.GetTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, this.layer); - }, + } /** * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns @@ -566,10 +565,10 @@ var TilemapLayerBase = new Class({ * * @return {boolean} `true` if a tile was found at the given location, otherwise `false`. */ - hasTileAt: function (tileX, tileY) + hasTileAt(tileX, tileY) { return TilemapComponents.HasTileAt(tileX, tileY, this.layer); - }, + } /** * Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns @@ -584,10 +583,10 @@ var TilemapLayerBase = new Class({ * * @return {boolean} `true` if a tile was found at the given location, otherwise `false`. */ - hasTileAtWorldXY: function (worldX, worldY, camera) + hasTileAtWorldXY(worldX, worldY, camera) { return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer); - }, + } /** * Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index @@ -605,10 +604,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile} The Tile object that was inserted at the given coordinates. */ - putTileAt: function (tile, tileX, tileY, recalculateFaces) + putTileAt(tile, tileX, tileY, recalculateFaces) { return TilemapComponents.PutTileAt(tile, tileX, tileY, recalculateFaces, this.layer); - }, + } /** * Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either @@ -627,10 +626,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile} The Tile object that was inserted at the given coordinates. */ - putTileAtWorldXY: function (tile, worldX, worldY, recalculateFaces, camera) + putTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera) { return TilemapComponents.PutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, this.layer); - }, + } /** * Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified @@ -649,12 +648,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - putTilesAt: function (tilesArray, tileX, tileY, recalculateFaces) + putTilesAt(tilesArray, tileX, tileY, recalculateFaces) { TilemapComponents.PutTilesAt(tilesArray, tileX, tileY, recalculateFaces, this.layer); return this; - }, + } /** * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the @@ -674,12 +673,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - randomize: function (tileX, tileY, width, height, indexes) + randomize(tileX, tileY, width, height, indexes) { TilemapComponents.Randomize(tileX, tileY, width, height, indexes, this.layer); return this; - }, + } /** * Removes the tile at the given tile coordinates in the specified layer and updates the layers @@ -695,10 +694,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile} A Tile object. */ - removeTileAt: function (tileX, tileY, replaceWithNull, recalculateFaces) + removeTileAt(tileX, tileY, replaceWithNull, recalculateFaces) { return TilemapComponents.RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, this.layer); - }, + } /** * Removes the tile at the given world coordinates in the specified layer and updates the layers @@ -715,10 +714,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Tilemaps.Tile} The Tile object that was removed from the given location. */ - removeTileAtWorldXY: function (worldX, worldY, replaceWithNull, recalculateFaces, camera) + removeTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera) { return TilemapComponents.RemoveTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, this.layer); - }, + } /** * Draws a debug representation of the layer to the given Graphics. This is helpful when you want to @@ -734,12 +733,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - renderDebug: function (graphics, styleConfig) + renderDebug(graphics, styleConfig) { TilemapComponents.RenderDebug(graphics, styleConfig, this.layer); return this; - }, + } /** * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching @@ -758,12 +757,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height) + replaceByIndex(findIndex, newIndex, tileX, tileY, width, height) { TilemapComponents.ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, this.layer); return this; - }, + } /** * Sets collision on the given tile or tiles within a layer by index. You can pass in either a @@ -780,12 +779,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - setCollision: function (indexes, collides, recalculateFaces, updateLayer) + setCollision(indexes, collides, recalculateFaces, updateLayer) { TilemapComponents.SetCollision(indexes, collides, recalculateFaces, this.layer, updateLayer); return this; - }, + } /** * Sets collision on a range of tiles in a layer whose index is between the specified `start` and @@ -803,12 +802,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - setCollisionBetween: function (start, stop, collides, recalculateFaces) + setCollisionBetween(start, stop, collides, recalculateFaces) { TilemapComponents.SetCollisionBetween(start, stop, collides, recalculateFaces, this.layer); return this; - }, + } /** * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property @@ -828,12 +827,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - setCollisionByProperty: function (properties, collides, recalculateFaces) + setCollisionByProperty(properties, collides, recalculateFaces) { TilemapComponents.SetCollisionByProperty(properties, collides, recalculateFaces, this.layer); return this; - }, + } /** * Sets collision on all tiles in the given layer, except for tiles that have an index specified in @@ -849,12 +848,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - setCollisionByExclusion: function (indexes, collides, recalculateFaces) + setCollisionByExclusion(indexes, collides, recalculateFaces) { TilemapComponents.SetCollisionByExclusion(indexes, collides, recalculateFaces, this.layer); return this; - }, + } /** * Sets collision on the tiles within a layer by checking each tiles collision group data @@ -870,12 +869,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - setCollisionFromCollisionGroup: function (collides, recalculateFaces) + setCollisionFromCollisionGroup(collides, recalculateFaces) { TilemapComponents.SetCollisionFromCollisionGroup(collides, recalculateFaces, this.layer); return this; - }, + } /** * Sets a global collision callback for the given tile index within the layer. This will affect all @@ -892,12 +891,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - setTileIndexCallback: function (indexes, callback, callbackContext) + setTileIndexCallback(indexes, callback, callbackContext) { TilemapComponents.SetTileIndexCallback(indexes, callback, callbackContext, this.layer); return this; - }, + } /** * Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. @@ -916,12 +915,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - setTileLocationCallback: function (tileX, tileY, width, height, callback, callbackContext) + setTileLocationCallback(tileX, tileY, width, height, callback, callbackContext) { TilemapComponents.SetTileLocationCallback(tileX, tileY, width, height, callback, callbackContext, this.layer); return this; - }, + } /** * Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given @@ -939,12 +938,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - shuffle: function (tileX, tileY, width, height) + shuffle(tileX, tileY, width, height) { TilemapComponents.Shuffle(tileX, tileY, width, height, this.layer); return this; - }, + } /** * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching @@ -963,12 +962,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - swapByIndex: function (indexA, indexB, tileX, tileY, width, height) + swapByIndex(indexA, indexB, tileX, tileY, width, height) { TilemapComponents.SwapByIndex(indexA, indexB, tileX, tileY, width, height, this.layer); return this; - }, + } /** * Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the @@ -982,10 +981,10 @@ var TilemapLayerBase = new Class({ * * @return {number} The Tile X coordinate converted to pixels. */ - tileToWorldX: function (tileX, camera) + tileToWorldX(tileX, camera) { return this.tilemap.tileToWorldX(tileX, camera, this); - }, + } /** * Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the @@ -999,10 +998,10 @@ var TilemapLayerBase = new Class({ * * @return {number} The Tile Y coordinate converted to pixels. */ - tileToWorldY: function (tileY, camera) + tileToWorldY(tileY, camera) { return this.tilemap.tileToWorldY(tileY, camera, this); - }, + } /** * Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the @@ -1019,10 +1018,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 containing the world coordinates of the Tile. */ - tileToWorldXY: function (tileX, tileY, point, camera) + tileToWorldXY(tileX, tileY, point, camera) { return this.tilemap.tileToWorldXY(tileX, tileY, point, camera, this); - }, + } /** * Returns an array of Vector2s where each entry corresponds to the corner of the requested tile. @@ -1045,10 +1044,10 @@ var TilemapLayerBase = new Class({ * * @return {?Phaser.Math.Vector2[]} Returns an array of Vector2s, or null if the layer given was invalid. */ - getTileCorners: function (tileX, tileY, camera) + getTileCorners(tileX, tileY, camera) { return this.tilemap.getTileCorners(tileX, tileY, camera, this); - }, + } /** * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the @@ -1076,12 +1075,12 @@ var TilemapLayerBase = new Class({ * * @return {this} This Tilemap Layer object. */ - weightedRandomize: function (weightedIndexes, tileX, tileY, width, height) + weightedRandomize(weightedIndexes, tileX, tileY, width, height) { TilemapComponents.WeightedRandomize(tileX, tileY, width, height, weightedIndexes, this.layer); return this; - }, + } /** * Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the @@ -1100,10 +1099,10 @@ var TilemapLayerBase = new Class({ * * @return {number} The tile X coordinate based on the world value. */ - worldToTileX: function (worldX, snapToFloor, camera) + worldToTileX(worldX, snapToFloor, camera) { return this.tilemap.worldToTileX(worldX, snapToFloor, camera, this); - }, + } /** * Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the @@ -1122,10 +1121,10 @@ var TilemapLayerBase = new Class({ * * @return {number} The tile Y coordinate based on the world value. */ - worldToTileY: function (worldY, snapToFloor, camera) + worldToTileY(worldY, snapToFloor, camera) { return this.tilemap.worldToTileY(worldY, snapToFloor, camera, this); - }, + } /** * Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the @@ -1143,10 +1142,10 @@ var TilemapLayerBase = new Class({ * * @return {Phaser.Math.Vector2} A Vector2 containing the tile coordinates of the world values. */ - worldToTileXY: function (worldX, worldY, snapToFloor, point, camera) + worldToTileXY(worldX, worldY, snapToFloor, point, camera) { return this.tilemap.worldToTileXY(worldX, worldY, snapToFloor, point, camera, this); - }, + } /** * Destroys this TilemapLayer and removes its link to the associated LayerData. @@ -1156,7 +1155,7 @@ var TilemapLayerBase = new Class({ * * @param {boolean} [removeFromTilemap=true] - Remove this layer from the parent Tilemap? */ - destroy: function (removeFromTilemap) + destroy(removeFromTilemap) { if (removeFromTilemap === undefined) { removeFromTilemap = true; } @@ -1186,6 +1185,6 @@ var TilemapLayerBase = new Class({ GameObject.prototype.destroy.call(this); } -}); +}; module.exports = TilemapLayerBase; diff --git a/src/tilemaps/Tileset.js b/src/tilemaps/Tileset.js index a6f1cf23c1..e36a59ad65 100644 --- a/src/tilemaps/Tileset.js +++ b/src/tilemaps/Tileset.js @@ -28,11 +28,9 @@ var Vector2 = require('../math/Vector2'); * @param {object} [tileData={}] - Data stored per tile. These typically are created in Tiled when editing a tileset, e.g. from Tiled's tile collision editor or terrain editor. * @param {object} [tileOffset={x: 0, y: 0}] - Tile texture drawing offset. */ -var Tileset = new Class({ +var Tileset = class { - initialize: - - function Tileset (name, firstgid, tileWidth, tileHeight, tileMargin, tileSpacing, tileProperties, tileData, tileOffset) + constructor(name, firstgid, tileWidth, tileHeight, tileMargin, tileSpacing, tileProperties, tileData, tileOffset) { if (tileWidth === undefined || tileWidth <= 0) { tileWidth = 32; } if (tileHeight === undefined || tileHeight <= 0) { tileHeight = 32; } @@ -251,7 +249,7 @@ var Tileset = new Class({ * @private */ this._animationDataIndexMap = null; - }, + } /** * Get a tiles properties that are stored in the Tileset. Returns null if tile index is not @@ -264,12 +262,12 @@ var Tileset = new Class({ * * @return {?(object|undefined)} */ - getTileProperties: function (tileIndex) + getTileProperties(tileIndex) { if (!this.containsTileIndex(tileIndex)) { return null; } return this.tileProperties[tileIndex - this.firstgid]; - }, + } /** * Get a tile's data that is stored in the Tileset. Returns null if tile index is not contained @@ -283,12 +281,12 @@ var Tileset = new Class({ * * @return {?object|undefined} */ - getTileData: function (tileIndex) + getTileData(tileIndex) { if (!this.containsTileIndex(tileIndex)) { return null; } return this.tileData[tileIndex - this.firstgid]; - }, + } /** * Get a tile's collision group that is stored in the Tileset. Returns null if tile index is not @@ -301,12 +299,12 @@ var Tileset = new Class({ * * @return {?object} */ - getTileCollisionGroup: function (tileIndex) + getTileCollisionGroup(tileIndex) { var data = this.getTileData(tileIndex); return (data && data.objectgroup) ? data.objectgroup : null; - }, + } /** * Returns true if and only if this Tileset contains the given tile index. @@ -318,13 +316,13 @@ var Tileset = new Class({ * * @return {boolean} */ - containsTileIndex: function (tileIndex) + containsTileIndex(tileIndex) { return ( tileIndex >= this.firstgid && tileIndex < (this.firstgid + this.total) ); - }, + } /** * Returns the ID of the tile to use, given a base tile and time, @@ -338,7 +336,7 @@ var Tileset = new Class({ * @param {number} milliseconds - The current time in milliseconds. * @return {?number} The tile ID to use, or null if the tile is not contained in this tileset. */ - getAnimatedTileId: function (tileIndex, milliseconds) + getAnimatedTileId(tileIndex, milliseconds) { if (!this.containsTileIndex(tileIndex)) { return null; } @@ -379,7 +377,7 @@ var Tileset = new Class({ } return null; - }, + } /** * Returns the texture coordinates (UV in pixels) in the Tileset image for the given tile index. @@ -393,12 +391,12 @@ var Tileset = new Class({ * @return {?object} Object in the form { x, y } representing the top-left UV coordinate * within the Tileset image. */ - getTileTextureCoordinates: function (tileIndex) + getTileTextureCoordinates(tileIndex) { if (!this.containsTileIndex(tileIndex)) { return null; } return this.texCoordinates[tileIndex - this.firstgid]; - }, + } /** * Sets the image associated with this Tileset and updates the tile data (rows, columns, etc.). @@ -410,7 +408,7 @@ var Tileset = new Class({ * * @return {Phaser.Tilemaps.Tileset} This Tileset object. */ - setImage: function (texture) + setImage(texture) { this.image = texture; @@ -430,7 +428,7 @@ var Tileset = new Class({ } return this; - }, + } /** * Sets the tile width & height and updates the tile data (rows, columns, etc.). @@ -443,7 +441,7 @@ var Tileset = new Class({ * * @return {Phaser.Tilemaps.Tileset} This Tileset object. */ - setTileSize: function (tileWidth, tileHeight) + setTileSize(tileWidth, tileHeight) { if (tileWidth !== undefined) { this.tileWidth = tileWidth; } if (tileHeight !== undefined) { this.tileHeight = tileHeight; } @@ -454,7 +452,7 @@ var Tileset = new Class({ } return this; - }, + } /** * Sets the tile margin and spacing and updates the tile data (rows, columns, etc.). @@ -467,7 +465,7 @@ var Tileset = new Class({ * * @return {Phaser.Tilemaps.Tileset} This Tileset object. */ - setSpacing: function (margin, spacing) + setSpacing(margin, spacing) { if (margin !== undefined) { this.tileMargin = margin; } if (spacing !== undefined) { this.tileSpacing = spacing; } @@ -478,7 +476,7 @@ var Tileset = new Class({ } return this; - }, + } /** * Updates tile texture coordinates and tileset data. @@ -493,7 +491,7 @@ var Tileset = new Class({ * * @return {Phaser.Tilemaps.Tileset} This Tileset object. */ - updateTileData: function (imageWidth, imageHeight, offsetX, offsetY) + updateTileData(imageWidth, imageHeight, offsetX, offsetY) { if (offsetX === undefined) { offsetX = 0; } if (offsetY === undefined) { offsetY = 0; } @@ -541,7 +539,7 @@ var Tileset = new Class({ } return this; - }, + } /** * Get or create the texture containing the animation data for this tileset. @@ -552,7 +550,7 @@ var Tileset = new Class({ * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer to use. * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The animation data texture. */ - getAnimationDataTexture: function (renderer) + getAnimationDataTexture(renderer) { if (!this._animationDataTexture) { @@ -560,7 +558,7 @@ var Tileset = new Class({ } return this._animationDataTexture; - }, + } /** * Get or create the map from tile index to animation data index. @@ -571,7 +569,7 @@ var Tileset = new Class({ * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - The renderer to use. * @return {Map} The map from tile index to animation data index. */ - getAnimationDataIndexMap: function (renderer) + getAnimationDataIndexMap(renderer) { if (!this._animationDataIndexMap) { @@ -579,7 +577,7 @@ var Tileset = new Class({ } return this._animationDataIndexMap; - }, + } /** * Creates a new WebGLTexture for the tileset's animation data. @@ -591,7 +589,7 @@ var Tileset = new Class({ * * @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The new WebGLTexture. */ - createAnimationDataTexture: function (renderer) + createAnimationDataTexture(renderer) { var tileData = this.tileData; var total = this.total; @@ -678,6 +676,6 @@ var Tileset = new Class({ this.maxAnimationLength = maxLength; } -}); +}; module.exports = Tileset; diff --git a/src/tilemaps/mapdata/LayerData.js b/src/tilemaps/mapdata/LayerData.js index 5fbc3440be..613c7edbde 100644 --- a/src/tilemaps/mapdata/LayerData.js +++ b/src/tilemaps/mapdata/LayerData.js @@ -21,11 +21,9 @@ var GetFastValue = require('../../utils/object/GetFastValue'); * * @param {Phaser.Types.Tilemaps.LayerDataConfig} [config] - The Layer Data configuration object. */ -var LayerData = new Class({ +var LayerData = class { - initialize: - - function LayerData (config) + constructor(config) { if (config === undefined) { config = {}; } @@ -264,6 +262,6 @@ var LayerData = new Class({ this.staggerIndex = GetFastValue(config, 'staggerIndex', 'odd'); } -}); +}; module.exports = LayerData; diff --git a/src/tilemaps/mapdata/MapData.js b/src/tilemaps/mapdata/MapData.js index 146bf314c3..d2805670c6 100644 --- a/src/tilemaps/mapdata/MapData.js +++ b/src/tilemaps/mapdata/MapData.js @@ -21,11 +21,9 @@ var GetFastValue = require('../../utils/object/GetFastValue'); * * @param {Phaser.Types.Tilemaps.MapDataConfig} [config] - The Map configuration object. */ -var MapData = new Class({ +var MapData = class { - initialize: - - function MapData (config) + constructor(config) { if (config === undefined) { config = {}; } @@ -256,6 +254,6 @@ var MapData = new Class({ this.staggerIndex = GetFastValue(config, 'staggerIndex', 'odd'); } -}); +}; module.exports = MapData; diff --git a/src/tilemaps/mapdata/ObjectLayer.js b/src/tilemaps/mapdata/ObjectLayer.js index 81a9e5933d..c4b8801ef9 100644 --- a/src/tilemaps/mapdata/ObjectLayer.js +++ b/src/tilemaps/mapdata/ObjectLayer.js @@ -23,11 +23,9 @@ var GetFastValue = require('../../utils/object/GetFastValue'); * * @param {Phaser.Types.Tilemaps.ObjectLayerConfig} [config] - The data for the layer from the Tiled JSON object. */ -var ObjectLayer = new Class({ +var ObjectLayer = class { - initialize: - - function ObjectLayer (config) + constructor(config) { if (config === undefined) { config = {}; } @@ -126,6 +124,6 @@ var ObjectLayer = new Class({ } } -}); +}; module.exports = ObjectLayer; diff --git a/src/time/Clock.js b/src/time/Clock.js index df953d5144..047a134649 100644 --- a/src/time/Clock.js +++ b/src/time/Clock.js @@ -21,11 +21,9 @@ var Remove = require('../utils/array/Remove'); * * @param {Phaser.Scene} scene - The Scene which owns this Clock. */ -var Clock = new Class({ +var Clock = class { - initialize: - - function Clock (scene) + constructor(scene) { /** * The Scene which owns this Clock. @@ -126,7 +124,7 @@ var Clock = new Class({ scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -136,13 +134,13 @@ var Clock = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { // Sync with the TimeStep this.now = this.systems.game.loop.time; this.systems.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -153,7 +151,7 @@ var Clock = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { this.startTime = this.systems.game.loop.time; @@ -162,7 +160,7 @@ var Clock = new Class({ eventEmitter.on(SceneEvents.PRE_UPDATE, this.preUpdate, this); eventEmitter.on(SceneEvents.UPDATE, this.update, this); eventEmitter.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * Creates a Timer Event and adds it to this Clock at the start of the next frame. @@ -184,7 +182,7 @@ var Clock = new Class({ * * @return {Phaser.Time.TimerEvent} The Timer Event which was created, or passed in. */ - addEvent: function (config) + addEvent(config) { var event; @@ -211,7 +209,7 @@ var Clock = new Class({ this._pendingInsertion.push(event); return event; - }, + } /** * Creates a Timer Event and adds it to the Clock at the start of the frame. @@ -228,10 +226,10 @@ var Clock = new Class({ * * @return {Phaser.Time.TimerEvent} The Timer Event which was created. */ - delayedCall: function (delay, callback, args, callbackScope) + delayedCall(delay, callback, args, callbackScope) { return this.addEvent({ delay: delay, callback: callback, args: args, callbackScope: callbackScope }); - }, + } /** * Clears and recreates the array of pending Timer Events. @@ -241,12 +239,12 @@ var Clock = new Class({ * * @return {this} - This Clock instance. */ - clearPendingEvents: function () + clearPendingEvents() { this._pendingInsertion = []; return this; - }, + } /** * Removes the given Timer Event, or an array of Timer Events, from this Clock. @@ -261,7 +259,7 @@ var Clock = new Class({ * * @return {this} - This Clock instance. */ - removeEvent: function (events) + removeEvent(events) { if (!Array.isArray(events)) { @@ -278,7 +276,7 @@ var Clock = new Class({ } return this; - }, + } /** * Schedules all active Timer Events for removal at the start of the frame. @@ -288,12 +286,12 @@ var Clock = new Class({ * * @return {this} - This Clock instance. */ - removeAllEvents: function () + removeAllEvents() { this._pendingRemoval = this._pendingRemoval.concat(this._active); return this; - }, + } /** * Updates the arrays of active and pending Timer Events. Called at the start of the frame. @@ -304,7 +302,7 @@ var Clock = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - preUpdate: function () + preUpdate() { var toRemove = this._pendingRemoval.length; var toInsert = this._pendingInsertion.length; @@ -344,7 +342,7 @@ var Clock = new Class({ // Clear the lists this._pendingRemoval.length = 0; this._pendingInsertion.length = 0; - }, + } /** * Updates the Clock's internal time and all of its Timer Events. @@ -355,7 +353,7 @@ var Clock = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - update: function (time, delta) + update(time, delta) { this.now = time; @@ -423,7 +421,7 @@ var Clock = new Class({ } } } - }, + } /** * The Scene that owns this plugin is shutting down. @@ -433,7 +431,7 @@ var Clock = new Class({ * @private * @since 3.0.0 */ - shutdown: function () + shutdown() { var i; @@ -461,7 +459,7 @@ var Clock = new Class({ eventEmitter.off(SceneEvents.PRE_UPDATE, this.preUpdate, this); eventEmitter.off(SceneEvents.UPDATE, this.update, this); eventEmitter.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -471,7 +469,7 @@ var Clock = new Class({ * @private * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -481,7 +479,7 @@ var Clock = new Class({ this.systems = null; } -}); +}; PluginCache.register('Clock', Clock, 'time'); diff --git a/src/time/Timeline.js b/src/time/Timeline.js index c46ccba4b0..c371d5da41 100644 --- a/src/time/Timeline.js +++ b/src/time/Timeline.js @@ -94,15 +94,11 @@ var Events = require('./events'); * @param {Phaser.Scene} scene - The Scene which owns this Timeline. * @param {Phaser.Types.Time.TimelineEventConfig|Phaser.Types.Time.TimelineEventConfig[]} [config] - The configuration object for this Timeline Event, or an array of them. */ -var Timeline = new Class({ +var Timeline = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function Timeline (scene, config) + constructor(scene, config) { - EventEmitter.call(this); + super(); /** * The Scene to which this Timeline belongs. @@ -239,7 +235,7 @@ var Timeline = new Class({ { this.add(config); } - }, + } /** * Updates the elapsed time counter, if this Timeline is not paused. @@ -250,7 +246,7 @@ var Timeline = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - preUpdate: function (time, delta) + preUpdate(time, delta) { if (this.paused) { @@ -258,7 +254,7 @@ var Timeline = new Class({ } this.elapsed += delta * this.timeScale; - }, + } /** * Called automatically by the Scene update step. @@ -284,7 +280,7 @@ var Timeline = new Class({ * @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} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - update: function () + update() { if (this.paused || this.complete) { @@ -407,7 +403,7 @@ var Timeline = new Class({ { this.emit(Events.COMPLETE, this); } - }, + } /** * Starts this Timeline running. @@ -424,7 +420,7 @@ var Timeline = new Class({ * * @return {this} This Timeline instance. */ - play: function (fromStart) + play(fromStart) { if (fromStart === undefined) { fromStart = true; } @@ -438,7 +434,7 @@ var Timeline = new Class({ } return this; - }, + } /** * Pauses this Timeline. @@ -456,7 +452,7 @@ var Timeline = new Class({ * * @return {this} This Timeline instance. */ - pause: function () + pause() { this.paused = true; @@ -473,7 +469,7 @@ var Timeline = new Class({ } return this; - }, + } /** * Repeats this Timeline. @@ -493,7 +489,7 @@ var Timeline = new Class({ * * @return {this} This Timeline instance. */ - repeat: function (amount) + repeat(amount) { if (amount === undefined || amount === true) { amount = -1; } if (amount === false) { amount = 0; } @@ -501,7 +497,7 @@ var Timeline = new Class({ this.loop = amount; return this; - }, + } /** * Resumes this Timeline from a paused state. @@ -515,7 +511,7 @@ var Timeline = new Class({ * * @return {this} This Timeline instance. */ - resume: function () + resume() { this.paused = false; @@ -532,7 +528,7 @@ var Timeline = new Class({ } return this; - }, + } /** * Stops this Timeline. @@ -546,13 +542,13 @@ var Timeline = new Class({ * * @return {this} This Timeline instance. */ - stop: function () + stop() { this.paused = true; this.complete = true; return this; - }, + } /** * Resets this Timeline back to the start. @@ -574,7 +570,7 @@ var Timeline = new Class({ * * @return {this} This Timeline instance. */ - reset: function (loop) + reset(loop) { if (loop === undefined) { loop = false; } @@ -605,7 +601,7 @@ var Timeline = new Class({ } return this.play(false); - }, + } /** * Adds one or more events to this Timeline. @@ -628,7 +624,7 @@ var Timeline = new Class({ * * @return {this} This Timeline instance. */ - add: function (config) + add(config) { if (!Array.isArray(config)) { @@ -688,7 +684,7 @@ var Timeline = new Class({ this.complete = false; return this; - }, + } /** * Removes all events from this Timeline, resets the elapsed time to zero @@ -701,7 +697,7 @@ var Timeline = new Class({ * * @return {this} This Timeline instance. */ - clear: function () + clear() { var events = this.events; @@ -721,7 +717,7 @@ var Timeline = new Class({ this.paused = true; return this; - }, + } /** * Returns `true` if this Timeline is currently playing. @@ -733,10 +729,10 @@ var Timeline = new Class({ * * @return {boolean} `true` if this Timeline is playing, otherwise `false`. */ - isPlaying: function () + isPlaying() { return (!this.paused && !this.complete); - }, + } /** * Returns a number between 0 and 1 representing the progress of this Timeline. @@ -756,12 +752,12 @@ var Timeline = new Class({ * * @return {number} A number between 0 and 1 representing the progress of this Timeline. */ - getProgress: function () + getProgress() { var total = Math.min(this.totalComplete, this.events.length); return total / this.events.length; - }, + } /** * Destroys this Timeline. @@ -776,7 +772,7 @@ var Timeline = new Class({ * @method Phaser.Time.Timeline#destroy * @since 3.60.0 */ - destroy: function () + destroy() { var eventEmitter = this.systems.events; @@ -790,7 +786,7 @@ var Timeline = new Class({ this.systems = null; } -}); +}; /** * A Timeline is a way to schedule events to happen at specific times in the future. diff --git a/src/time/TimerEvent.js b/src/time/TimerEvent.js index 30d4a66e33..6cc3945e12 100644 --- a/src/time/TimerEvent.js +++ b/src/time/TimerEvent.js @@ -20,11 +20,9 @@ var GetFastValue = require('../utils/object/GetFastValue'); * * @param {Phaser.Types.Time.TimerEventConfig} config - The configuration for the Timer Event, including its delay and callback. */ -var TimerEvent = new Class({ +var TimerEvent = class { - initialize: - - function TimerEvent (config) + constructor(config) { /** * The delay in ms at which this TimerEvent fires. @@ -151,7 +149,7 @@ var TimerEvent = new Class({ this.hasDispatched = false; this.reset(config); - }, + } /** * Completely reinitializes the Timer Event, regardless of its current state, according to a configuration object. @@ -163,7 +161,7 @@ var TimerEvent = new Class({ * * @return {Phaser.Time.TimerEvent} This TimerEvent object. */ - reset: function (config) + reset(config) { this.delay = GetFastValue(config, 'delay', 0); @@ -194,7 +192,7 @@ var TimerEvent = new Class({ } return this; - }, + } /** * Gets the progress of the current iteration, not factoring in repeats. @@ -204,10 +202,10 @@ var TimerEvent = new Class({ * * @return {number} A number between 0 and 1 representing the current progress. */ - getProgress: function () + getProgress() { return (this.elapsed / this.delay); - }, + } /** * Gets the progress of the timer overall, factoring in repeats. @@ -217,7 +215,7 @@ var TimerEvent = new Class({ * * @return {number} The overall progress of the Timer Event, between 0 and 1. */ - getOverallProgress: function () + getOverallProgress() { if (this.repeat > 0) { @@ -230,7 +228,7 @@ var TimerEvent = new Class({ { return this.getProgress(); } - }, + } /** * Returns the number of times this Timer Event will repeat before finishing. @@ -242,10 +240,10 @@ var TimerEvent = new Class({ * * @return {number} How many times the Timer Event will repeat. */ - getRepeatCount: function () + getRepeatCount() { return this.repeatCount; - }, + } /** * Returns the local elapsed time for the current iteration of the Timer Event. @@ -255,10 +253,10 @@ var TimerEvent = new Class({ * * @return {number} The local elapsed time in milliseconds. */ - getElapsed: function () + getElapsed() { return this.elapsed; - }, + } /** * Returns the local elapsed time for the current iteration of the Timer Event in seconds. @@ -268,10 +266,10 @@ var TimerEvent = new Class({ * * @return {number} The local elapsed time in seconds. */ - getElapsedSeconds: function () + getElapsedSeconds() { return this.elapsed * 0.001; - }, + } /** * Returns the time interval until the next iteration of the Timer Event. @@ -281,10 +279,10 @@ var TimerEvent = new Class({ * * @return {number} The time interval in milliseconds. */ - getRemaining: function () + getRemaining() { return this.delay - this.elapsed; - }, + } /** * Returns the time interval until the next iteration of the Timer Event in seconds. @@ -294,10 +292,10 @@ var TimerEvent = new Class({ * * @return {number} The time interval in seconds. */ - getRemainingSeconds: function () + getRemainingSeconds() { return this.getRemaining() * 0.001; - }, + } /** * Returns the time interval until the last iteration of the Timer Event. @@ -307,10 +305,10 @@ var TimerEvent = new Class({ * * @return {number} The time interval in milliseconds. */ - getOverallRemaining: function () + getOverallRemaining() { return this.delay * (1 + this.repeatCount) - this.elapsed; - }, + } /** * Returns the time interval until the last iteration of the Timer Event in seconds. @@ -320,10 +318,10 @@ var TimerEvent = new Class({ * * @return {number} The time interval in seconds. */ - getOverallRemainingSeconds: function () + getOverallRemainingSeconds() { return this.getOverallRemaining() * 0.001; - }, + } /** * Forces the Timer Event to immediately expire, thus scheduling its removal in the next frame. @@ -333,7 +331,7 @@ var TimerEvent = new Class({ * * @param {boolean} [dispatchCallback=false] - If `true`, the function of the Timer Event will be called before its removal. */ - remove: function (dispatchCallback) + remove(dispatchCallback) { if (dispatchCallback === undefined) { dispatchCallback = false; } @@ -342,7 +340,7 @@ var TimerEvent = new Class({ this.hasDispatched = !dispatchCallback; this.repeatCount = 0; - }, + } /** * Destroys all object references in the Timer Event, i.e. its callback, scope, and arguments. @@ -352,13 +350,13 @@ var TimerEvent = new Class({ * @method Phaser.Time.TimerEvent#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.callback = undefined; this.callbackScope = undefined; this.args = []; } -}); +}; module.exports = TimerEvent; diff --git a/src/tweens/TweenManager.js b/src/tweens/TweenManager.js index 62e79f8f54..7891dbea3a 100644 --- a/src/tweens/TweenManager.js +++ b/src/tweens/TweenManager.js @@ -56,11 +56,9 @@ var TweenChainBuilder = require('./builders/TweenChainBuilder'); * * @param {Phaser.Scene} scene - The Scene which owns this Tween Manager. */ -var TweenManager = new Class({ +var TweenManager = class { - initialize: - - function TweenManager (scene) + constructor(scene) { /** * The Scene which owns this Tween Manager. @@ -201,7 +199,7 @@ var TweenManager = new Class({ this.events.once(SceneEvents.BOOT, this.boot, this); this.events.on(SceneEvents.START, this.start, this); - }, + } /** * This method is called automatically, only once, when the Scene is first created. @@ -211,10 +209,10 @@ var TweenManager = new Class({ * @private * @since 3.5.1 */ - boot: function () + boot() { this.events.once(SceneEvents.DESTROY, this.destroy, this); - }, + } /** * This method is called automatically by the Scene when it is starting up. @@ -225,7 +223,7 @@ var TweenManager = new Class({ * @private * @since 3.5.0 */ - start: function () + start() { this.timeScale = 1; this.paused = false; @@ -236,7 +234,7 @@ var TweenManager = new Class({ this.events.on(SceneEvents.UPDATE, this.update, this); this.events.once(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * Create a Tween and return it, but does not add it to this Tween Manager. @@ -256,7 +254,7 @@ var TweenManager = new Class({ * * @return {Phaser.Tweens.Tween|Phaser.Tweens.Tween[]} The created Tween, or an array of Tweens if an array of tween configs was provided. */ - create: function (config) + create(config) { if (!Array.isArray(config)) { @@ -285,7 +283,7 @@ var TweenManager = new Class({ } return (result.length === 1) ? result[0] : result; - }, + } /** * Create a Tween and add it to this Tween Manager by passing a Tween Configuration object. @@ -324,7 +322,7 @@ var TweenManager = new Class({ * * @return {Phaser.Tweens.Tween} The created Tween. */ - add: function (config) + add(config) { var tween = config; var tweens = this.tweens; @@ -348,7 +346,7 @@ var TweenManager = new Class({ } return tween; - }, + } /** * Create multiple Tweens and add them all to this Tween Manager, by passing an array of Tween Configuration objects. @@ -374,7 +372,7 @@ var TweenManager = new Class({ * * @return {Phaser.Tweens.Tween[]} An array of created Tweens. */ - addMultiple: function (configs) + addMultiple(configs) { var tween; var result = []; @@ -406,7 +404,7 @@ var TweenManager = new Class({ } return result; - }, + } /** * Create a sequence of Tweens, chained to one-another, and add them to this Tween Manager. @@ -427,14 +425,14 @@ var TweenManager = new Class({ * * @return {Phaser.Tweens.TweenChain} The Tween Chain instance. */ - chain: function (config) + chain(config) { var chain = TweenChainBuilder(this, config); this.tweens.push(chain.init()); return chain; - }, + } /** * Returns an array containing this Tween and all Tweens chained to it, @@ -449,10 +447,10 @@ var TweenManager = new Class({ * * @return {Phaser.Tweens.Tween[]} An array of the chained tweens, or an empty array if there aren't any. */ - getChainedTweens: function (tween) + getChainedTweens(tween) { return tween.getChainedTweens(); - }, + } /** * Check to see if the given Tween instance exists within this Tween Manager. @@ -468,10 +466,10 @@ var TweenManager = new Class({ * * @return {boolean} `true` if the Tween exists within this Tween Manager, otherwise `false`. */ - has: function (tween) + has(tween) { return (this.tweens.indexOf(tween) > -1); - }, + } /** * Add an existing Tween to this Tween Manager. @@ -485,7 +483,7 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - existing: function (tween) + existing(tween) { if (!this.has(tween)) { @@ -493,7 +491,7 @@ var TweenManager = new Class({ } return this; - }, + } /** * Create a Number Tween and add it to the active Tween list. @@ -515,14 +513,14 @@ var TweenManager = new Class({ * * @return {Phaser.Tweens.Tween} The created Number Tween. */ - addCounter: function (config) + addCounter(config) { var tween = NumberTweenBuilder(this, config); this.tweens.push(tween.reset()); return tween; - }, + } /** * Creates a Stagger function to be used by a Tween property. @@ -565,10 +563,10 @@ var TweenManager = new Class({ * * @return {function} The stagger function. */ - stagger: function (value, options) + stagger(value, options) { return StaggerBuilder(value, options); - }, + } /** * Set the limits that are used when a browser encounters lag, or delays that cause the elapsed @@ -592,7 +590,7 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - setLagSmooth: function (limit, skip) + setLagSmooth(limit, skip) { if (limit === undefined) { limit = 1 / 1e-8; } if (skip === undefined) { skip = 0; } @@ -601,7 +599,7 @@ var TweenManager = new Class({ this.lagSkip = Math.min(skip, this.maxLag); return this; - }, + } /** * Limits the Tween system to run at a particular frame rate. @@ -617,7 +615,7 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - setFps: function (fps) + setFps(fps) { if (fps === undefined) { fps = 240; } @@ -625,7 +623,7 @@ var TweenManager = new Class({ this.nextTime = this.time * 1000 + this.gap; return this; - }, + } /** * Internal method that calculates the delta value, along with the other timing values, @@ -640,7 +638,7 @@ var TweenManager = new Class({ * * @return {number} The new delta value. */ - getDelta: function (tick) + getDelta(tick) { var elapsed = Date.now() - this.prevTime; @@ -667,7 +665,7 @@ var TweenManager = new Class({ } return delta; - }, + } /** * Manually advance the Tween system by one step. @@ -680,12 +678,12 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - tick: function () + tick() { this.step(true); return this; - }, + } /** * Internal update handler. @@ -696,13 +694,13 @@ var TweenManager = new Class({ * @method Phaser.Tweens.TweenManager#update * @since 3.0.0 */ - update: function () + update() { if (!this.paused) { this.step(false); } - }, + } /** * Updates all Tweens belonging to this Tween Manager. @@ -714,7 +712,7 @@ var TweenManager = new Class({ * * @param {boolean} [tick=false] - Is this a manual tick, or an automated tick? */ - step: function (tick) + step(tick) { if (tick === undefined) { tick = false; } @@ -770,7 +768,7 @@ var TweenManager = new Class({ } this.processing = false; - }, + } /** * Removes the given Tween from this Tween Manager, even if it hasn't started @@ -787,7 +785,7 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - remove: function (tween) + remove(tween) { if (this.processing) { @@ -803,7 +801,7 @@ var TweenManager = new Class({ } return this; - }, + } /** * Resets the given Tween. @@ -819,7 +817,7 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - reset: function (tween) + reset(tween) { this.existing(tween); @@ -828,7 +826,7 @@ var TweenManager = new Class({ tween.setActiveState(); return this; - }, + } /** * Checks if a Tween is active and adds it to the Tween Manager at the start of the frame if it isn't. @@ -840,14 +838,14 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - makeActive: function (tween) + makeActive(tween) { this.existing(tween); tween.setActiveState(); return this; - }, + } /** * Passes all Tweens to the given callback. @@ -861,7 +859,7 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - each: function (callback, scope) + each(callback, scope) { var i; var args = [ null ]; @@ -879,7 +877,7 @@ var TweenManager = new Class({ }); return this; - }, + } /** * Returns an array containing references to all Tweens in this Tween Manager. @@ -895,10 +893,10 @@ var TweenManager = new Class({ * * @return {Phaser.Tweens.Tween[]} A new array containing references to all Tweens. */ - getTweens: function () + getTweens() { return this.tweens.slice(); - }, + } /** * Returns an array of all Tweens in the Tween Manager which affect the given target, or array of targets. @@ -914,7 +912,7 @@ var TweenManager = new Class({ * * @return {Phaser.Tweens.Tween[]} A new array containing all Tweens which affect the given target(s). */ - getTweensOf: function (target) + getTweensOf(target) { var output = []; var list = this.tweens; @@ -944,7 +942,7 @@ var TweenManager = new Class({ } return output; - }, + } /** * Returns the scale of the time delta for all Tweens owned by this Tween Manager. @@ -954,10 +952,10 @@ var TweenManager = new Class({ * * @return {number} The scale of the time delta, usually 1. */ - getGlobalTimeScale: function () + getGlobalTimeScale() { return this.timeScale; - }, + } /** * Sets a new scale of the time delta for this Tween Manager. @@ -971,12 +969,12 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - setGlobalTimeScale: function (value) + setGlobalTimeScale(value) { this.timeScale = value; return this; - }, + } /** * Checks if the given object is being affected by a _playing_ Tween. @@ -990,7 +988,7 @@ var TweenManager = new Class({ * * @return {boolean} Returns `true` if a tween is active on the given target, otherwise `false`. */ - isTweening: function (target) + isTweening(target) { var list = this.tweens; var tween; @@ -1006,7 +1004,7 @@ var TweenManager = new Class({ } return false; - }, + } /** * Destroys all Tweens in this Tween Manager. @@ -1023,7 +1021,7 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - killAll: function () + killAll() { var tweens = (this.processing) ? this.getTweens() : this.tweens; @@ -1038,7 +1036,7 @@ var TweenManager = new Class({ } return this; - }, + } /** * Stops all Tweens which affect the given target or array of targets. @@ -1059,7 +1057,7 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - killTweensOf: function (target) + killTweensOf(target) { var tweens = this.getTweensOf(target); @@ -1069,7 +1067,7 @@ var TweenManager = new Class({ } return this; - }, + } /** * Pauses this Tween Manager. No Tweens will update while paused. @@ -1085,12 +1083,12 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - pauseAll: function () + pauseAll() { this.paused = true; return this; - }, + } /** * Resumes playback of this Tween Manager. @@ -1106,12 +1104,12 @@ var TweenManager = new Class({ * * @return {this} This Tween Manager instance. */ - resumeAll: function () + resumeAll() { this.paused = false; return this; - }, + } /** * The Scene that owns this plugin is shutting down. @@ -1121,7 +1119,7 @@ var TweenManager = new Class({ * @method Phaser.Tweens.TweenManager#shutdown * @since 3.0.0 */ - shutdown: function () + shutdown() { this.killAll(); @@ -1129,7 +1127,7 @@ var TweenManager = new Class({ this.events.off(SceneEvents.UPDATE, this.update, this); this.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); - }, + } /** * The Scene that owns this plugin is being destroyed. @@ -1138,7 +1136,7 @@ var TweenManager = new Class({ * @method Phaser.Tweens.TweenManager#destroy * @since 3.0.0 */ - destroy: function () + destroy() { this.shutdown(); @@ -1148,7 +1146,7 @@ var TweenManager = new Class({ this.events = null; } -}); +}; PluginCache.register('TweenManager', TweenManager, 'tweens'); diff --git a/src/tweens/tween/BaseTween.js b/src/tweens/tween/BaseTween.js index b059800991..0f06f3f36a 100644 --- a/src/tweens/tween/BaseTween.js +++ b/src/tweens/tween/BaseTween.js @@ -25,15 +25,11 @@ var TWEEN_CONST = require('./const'); * * @param {(Phaser.Tweens.TweenManager|Phaser.Tweens.TweenChain)} parent - A reference to the Tween Manager, or Tween Chain, that owns this Tween. */ -var BaseTween = new Class({ +var BaseTween = class extends EventEmitter { - Extends: EventEmitter, - - initialize: - - function BaseTween (parent) + constructor(parent) { - EventEmitter.call(this); + super(); /** * A reference to the Tween Manager, or Tween Chain, that owns this Tween. @@ -258,7 +254,7 @@ var BaseTween = new Class({ * @since 3.60.0 */ this.persist = false; - }, + } /** * Sets the value of the time scale applied to this Tween. A value of 1 runs in real-time. @@ -275,12 +271,12 @@ var BaseTween = new Class({ * * @return {this} This Tween instance. */ - setTimeScale: function (value) + setTimeScale(value) { this.timeScale = value; return this; - }, + } /** * Gets the value of the time scale applied to this Tween. A value of 1 runs in real-time. @@ -291,10 +287,10 @@ var BaseTween = new Class({ * * @return {number} The value of the time scale applied to this Tween. */ - getTimeScale: function () + getTimeScale() { return this.timeScale; - }, + } /** * Checks if this Tween is currently playing. @@ -306,10 +302,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if the Tween is playing, otherwise `false`. */ - isPlaying: function () + isPlaying() { return (!this.paused && this.isActive()); - }, + } /** * Checks if the Tween is currently paused. @@ -321,10 +317,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if the Tween is paused, otherwise `false`. */ - isPaused: function () + isPaused() { return this.paused; - }, + } /** * Pauses the Tween immediately. Use `resume` to continue playback. @@ -337,7 +333,7 @@ var BaseTween = new Class({ * * @return {this} This Tween instance. */ - pause: function () + pause() { if (!this.paused) { @@ -347,7 +343,7 @@ var BaseTween = new Class({ } return this; - }, + } /** * Resumes the playback of a previously paused Tween. @@ -360,7 +356,7 @@ var BaseTween = new Class({ * * @return {this} This Tween instance. */ - resume: function () + resume() { if (this.paused) { @@ -370,7 +366,7 @@ var BaseTween = new Class({ } return this; - }, + } /** * Internal method that makes this Tween active within the TweenManager @@ -380,12 +376,12 @@ var BaseTween = new Class({ * @fires Phaser.Tweens.Events#TWEEN_ACTIVE * @since 3.60.0 */ - makeActive: function () + makeActive() { this.parent.makeActive(this); this.dispatchEvent(Events.TWEEN_ACTIVE, 'onActive'); - }, + } /** * Internal method that handles this tween completing and emitting the onComplete event @@ -394,12 +390,12 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#onCompleteHandler * @since 3.60.0 */ - onCompleteHandler: function () + onCompleteHandler() { this.setPendingRemoveState(); this.dispatchEvent(Events.TWEEN_COMPLETE, 'onComplete'); - }, + } /** * Flags the Tween as being complete, whatever stage of progress it is at. @@ -417,7 +413,7 @@ var BaseTween = new Class({ * * @return {this} This Tween instance. */ - complete: function (delay) + complete(delay) { if (delay === undefined) { delay = 0; } @@ -433,7 +429,7 @@ var BaseTween = new Class({ } return this; - }, + } /** * Flags the Tween as being complete only once the current loop has finished. @@ -451,7 +447,7 @@ var BaseTween = new Class({ * * @return {this} This Tween instance. */ - completeAfterLoop: function (loops) + completeAfterLoop(loops) { if (loops === undefined) { loops = 0; } @@ -461,7 +457,7 @@ var BaseTween = new Class({ } return this; - }, + } /** * Immediately removes this Tween from the TweenManager and all of its internal arrays, @@ -475,7 +471,7 @@ var BaseTween = new Class({ * * @return {this} This Tween instance. */ - remove: function () + remove() { if (this.parent) { @@ -483,7 +479,7 @@ var BaseTween = new Class({ } return this; - }, + } /** * Stops the Tween immediately, whatever stage of progress it is at. @@ -504,7 +500,7 @@ var BaseTween = new Class({ * * @return {this} This Tween instance. */ - stop: function () + stop() { if (this.parent && !this.isRemoved() && !this.isPendingRemove() && !this.isDestroyed()) { @@ -514,7 +510,7 @@ var BaseTween = new Class({ } return this; - }, + } /** * Internal method that handles the processing of the loop delay countdown timer and @@ -525,7 +521,7 @@ var BaseTween = new Class({ * * @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - updateLoopCountdown: function (delta) + updateLoopCountdown(delta) { this.countdown -= delta; @@ -535,7 +531,7 @@ var BaseTween = new Class({ this.dispatchEvent(Events.TWEEN_LOOP, 'onLoop'); } - }, + } /** * Internal method that handles the processing of the start delay countdown timer and @@ -546,7 +542,7 @@ var BaseTween = new Class({ * * @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - updateStartCountdown: function (delta) + updateStartCountdown(delta) { this.countdown -= delta; @@ -563,7 +559,7 @@ var BaseTween = new Class({ } return delta; - }, + } /** * Internal method that handles the processing of the complete delay countdown timer and @@ -574,7 +570,7 @@ var BaseTween = new Class({ * * @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - updateCompleteDelay: function (delta) + updateCompleteDelay(delta) { this.countdown -= delta; @@ -582,7 +578,7 @@ var BaseTween = new Class({ { this.onCompleteHandler(); } - }, + } /** * Sets an event based callback to be invoked during playback. @@ -614,7 +610,7 @@ var BaseTween = new Class({ * * @return {this} This Tween instance. */ - setCallback: function (type, callback, params) + setCallback(type, callback, params) { if (params === undefined) { params = []; } @@ -624,7 +620,7 @@ var BaseTween = new Class({ } return this; - }, + } /** * Sets this Tween state to PENDING. @@ -632,10 +628,10 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setPendingState * @since 3.60.0 */ - setPendingState: function () + setPendingState() { this.state = TWEEN_CONST.PENDING; - }, + } /** * Sets this Tween state to ACTIVE. @@ -643,12 +639,12 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setActiveState * @since 3.60.0 */ - setActiveState: function () + setActiveState() { this.state = TWEEN_CONST.ACTIVE; this.hasStarted = false; - }, + } /** * Sets this Tween state to LOOP_DELAY. @@ -656,10 +652,10 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setLoopDelayState * @since 3.60.0 */ - setLoopDelayState: function () + setLoopDelayState() { this.state = TWEEN_CONST.LOOP_DELAY; - }, + } /** * Sets this Tween state to COMPLETE_DELAY. @@ -667,10 +663,10 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setCompleteDelayState * @since 3.60.0 */ - setCompleteDelayState: function () + setCompleteDelayState() { this.state = TWEEN_CONST.COMPLETE_DELAY; - }, + } /** * Sets this Tween state to START_DELAY. @@ -678,14 +674,14 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setStartDelayState * @since 3.60.0 */ - setStartDelayState: function () + setStartDelayState() { this.state = TWEEN_CONST.START_DELAY; this.countdown = this.startDelay; this.hasStarted = false; - }, + } /** * Sets this Tween state to PENDING_REMOVE. @@ -693,10 +689,10 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setPendingRemoveState * @since 3.60.0 */ - setPendingRemoveState: function () + setPendingRemoveState() { this.state = TWEEN_CONST.PENDING_REMOVE; - }, + } /** * Sets this Tween state to REMOVED. @@ -704,10 +700,10 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setRemovedState * @since 3.60.0 */ - setRemovedState: function () + setRemovedState() { this.state = TWEEN_CONST.REMOVED; - }, + } /** * Sets this Tween state to FINISHED. @@ -715,10 +711,10 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setFinishedState * @since 3.60.0 */ - setFinishedState: function () + setFinishedState() { this.state = TWEEN_CONST.FINISHED; - }, + } /** * Sets this Tween state to DESTROYED. @@ -726,10 +722,10 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#setDestroyedState * @since 3.60.0 */ - setDestroyedState: function () + setDestroyedState() { this.state = TWEEN_CONST.DESTROYED; - }, + } /** * Returns `true` if this Tween has a _current_ state of PENDING, otherwise `false`. @@ -739,10 +735,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of PENDING, otherwise `false`. */ - isPending: function () + isPending() { return (this.state === TWEEN_CONST.PENDING); - }, + } /** * Returns `true` if this Tween has a _current_ state of ACTIVE, otherwise `false`. @@ -752,10 +748,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of ACTIVE, otherwise `false`. */ - isActive: function () + isActive() { return (this.state === TWEEN_CONST.ACTIVE); - }, + } /** * Returns `true` if this Tween has a _current_ state of LOOP_DELAY, otherwise `false`. @@ -765,10 +761,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of LOOP_DELAY, otherwise `false`. */ - isLoopDelayed: function () + isLoopDelayed() { return (this.state === TWEEN_CONST.LOOP_DELAY); - }, + } /** * Returns `true` if this Tween has a _current_ state of COMPLETE_DELAY, otherwise `false`. @@ -778,10 +774,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of COMPLETE_DELAY, otherwise `false`. */ - isCompleteDelayed: function () + isCompleteDelayed() { return (this.state === TWEEN_CONST.COMPLETE_DELAY); - }, + } /** * Returns `true` if this Tween has a _current_ state of START_DELAY, otherwise `false`. @@ -791,10 +787,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of START_DELAY, otherwise `false`. */ - isStartDelayed: function () + isStartDelayed() { return (this.state === TWEEN_CONST.START_DELAY); - }, + } /** * Returns `true` if this Tween has a _current_ state of PENDING_REMOVE, otherwise `false`. @@ -804,10 +800,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of PENDING_REMOVE, otherwise `false`. */ - isPendingRemove: function () + isPendingRemove() { return (this.state === TWEEN_CONST.PENDING_REMOVE); - }, + } /** * Returns `true` if this Tween has a _current_ state of REMOVED, otherwise `false`. @@ -817,10 +813,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of REMOVED, otherwise `false`. */ - isRemoved: function () + isRemoved() { return (this.state === TWEEN_CONST.REMOVED); - }, + } /** * Returns `true` if this Tween has a _current_ state of FINISHED, otherwise `false`. @@ -830,10 +826,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of FINISHED, otherwise `false`. */ - isFinished: function () + isFinished() { return (this.state === TWEEN_CONST.FINISHED); - }, + } /** * Returns `true` if this Tween has a _current_ state of DESTROYED, otherwise `false`. @@ -843,10 +839,10 @@ var BaseTween = new Class({ * * @return {boolean} `true` if this Tween has a _current_ state of DESTROYED, otherwise `false`. */ - isDestroyed: function () + isDestroyed() { return (this.state === TWEEN_CONST.DESTROYED); - }, + } /** * Handles the destroy process of this Tween, clearing out the @@ -856,7 +852,7 @@ var BaseTween = new Class({ * @method Phaser.Tweens.BaseTween#destroy * @since 3.60.0 */ - destroy: function () + destroy() { if (this.data) { @@ -875,7 +871,7 @@ var BaseTween = new Class({ this.setDestroyedState(); } -}); +}; BaseTween.TYPES = [ 'onActive', diff --git a/src/tweens/tween/BaseTweenData.js b/src/tweens/tween/BaseTweenData.js index b98258736a..06675efaa2 100644 --- a/src/tweens/tween/BaseTweenData.js +++ b/src/tweens/tween/BaseTweenData.js @@ -40,11 +40,9 @@ var TWEEN_CONST = require('./const'); * @param {?function} interpolation - The interpolation function to be used for arrays of data. Defaults to 'null'. * @param {?number[]} interpolationData - The array of interpolation data to be set. Defaults to 'null'. */ -var BaseTweenData = new Class({ +var BaseTweenData = class { - initialize: - - function BaseTweenData (tween, targetIndex, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY) + constructor(tween, targetIndex, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY) { /** * A reference to the Tween that this TweenData instance belongs to. @@ -215,7 +213,7 @@ var BaseTweenData = new Class({ * @since 3.60.0 */ this.isCountdown = false; - }, + } /** * Returns a reference to the target object belonging to this TweenData. @@ -225,10 +223,10 @@ var BaseTweenData = new Class({ * * @return {object} The target object. Can be any JavaScript object, but is typically a Game Object. */ - getTarget: function () + getTarget() { return this.tween.targets[this.targetIndex]; - }, + } /** * Sets this TweenData's target object property to be the given value. @@ -238,12 +236,12 @@ var BaseTweenData = new Class({ * * @param {number} [value] - The value to set on the target. If not given, sets it to the last `current` value. */ - setTargetValue: function (value) + setTargetValue(value) { if (value === undefined) { value = this.current; } this.tween.targets[this.targetIndex][this.key] = value; - }, + } /** * Sets this TweenData state to CREATED. @@ -251,11 +249,11 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#setCreatedState * @since 3.60.0 */ - setCreatedState: function () + setCreatedState() { this.state = TWEEN_CONST.CREATED; this.isCountdown = false; - }, + } /** * Sets this TweenData state to DELAY. @@ -263,11 +261,11 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#setDelayState * @since 3.60.0 */ - setDelayState: function () + setDelayState() { this.state = TWEEN_CONST.DELAY; this.isCountdown = true; - }, + } /** * Sets this TweenData state to PENDING_RENDER. @@ -275,11 +273,11 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#setPendingRenderState * @since 3.60.0 */ - setPendingRenderState: function () + setPendingRenderState() { this.state = TWEEN_CONST.PENDING_RENDER; this.isCountdown = false; - }, + } /** * Sets this TweenData state to PLAYING_FORWARD. @@ -287,11 +285,11 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#setPlayingForwardState * @since 3.60.0 */ - setPlayingForwardState: function () + setPlayingForwardState() { this.state = TWEEN_CONST.PLAYING_FORWARD; this.isCountdown = false; - }, + } /** * Sets this TweenData state to PLAYING_BACKWARD. @@ -299,11 +297,11 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#setPlayingBackwardState * @since 3.60.0 */ - setPlayingBackwardState: function () + setPlayingBackwardState() { this.state = TWEEN_CONST.PLAYING_BACKWARD; this.isCountdown = false; - }, + } /** * Sets this TweenData state to HOLD_DELAY. @@ -311,11 +309,11 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#setHoldState * @since 3.60.0 */ - setHoldState: function () + setHoldState() { this.state = TWEEN_CONST.HOLD_DELAY; this.isCountdown = true; - }, + } /** * Sets this TweenData state to REPEAT_DELAY. @@ -323,11 +321,11 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#setRepeatState * @since 3.60.0 */ - setRepeatState: function () + setRepeatState() { this.state = TWEEN_CONST.REPEAT_DELAY; this.isCountdown = true; - }, + } /** * Sets this TweenData state to COMPLETE. @@ -335,11 +333,11 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#setCompleteState * @since 3.60.0 */ - setCompleteState: function () + setCompleteState() { this.state = TWEEN_CONST.COMPLETE; this.isCountdown = false; - }, + } /** * Returns `true` if this TweenData has a _current_ state of CREATED, otherwise `false`. @@ -349,10 +347,10 @@ var BaseTweenData = new Class({ * * @return {boolean} `true` if this TweenData has a _current_ state of CREATED, otherwise `false`. */ - isCreated: function () + isCreated() { return (this.state === TWEEN_CONST.CREATED); - }, + } /** * Returns `true` if this TweenData has a _current_ state of DELAY, otherwise `false`. @@ -362,10 +360,10 @@ var BaseTweenData = new Class({ * * @return {boolean} `true` if this TweenData has a _current_ state of DELAY, otherwise `false`. */ - isDelayed: function () + isDelayed() { return (this.state === TWEEN_CONST.DELAY); - }, + } /** * Returns `true` if this TweenData has a _current_ state of PENDING_RENDER, otherwise `false`. @@ -375,10 +373,10 @@ var BaseTweenData = new Class({ * * @return {boolean} `true` if this TweenData has a _current_ state of PENDING_RENDER, otherwise `false`. */ - isPendingRender: function () + isPendingRender() { return (this.state === TWEEN_CONST.PENDING_RENDER); - }, + } /** * Returns `true` if this TweenData has a _current_ state of PLAYING_FORWARD, otherwise `false`. @@ -388,10 +386,10 @@ var BaseTweenData = new Class({ * * @return {boolean} `true` if this TweenData has a _current_ state of PLAYING_FORWARD, otherwise `false`. */ - isPlayingForward: function () + isPlayingForward() { return (this.state === TWEEN_CONST.PLAYING_FORWARD); - }, + } /** * Returns `true` if this TweenData has a _current_ state of PLAYING_BACKWARD, otherwise `false`. @@ -401,10 +399,10 @@ var BaseTweenData = new Class({ * * @return {boolean} `true` if this TweenData has a _current_ state of PLAYING_BACKWARD, otherwise `false`. */ - isPlayingBackward: function () + isPlayingBackward() { return (this.state === TWEEN_CONST.PLAYING_BACKWARD); - }, + } /** * Returns `true` if this TweenData has a _current_ state of HOLD_DELAY, otherwise `false`. @@ -414,10 +412,10 @@ var BaseTweenData = new Class({ * * @return {boolean} `true` if this TweenData has a _current_ state of HOLD_DELAY, otherwise `false`. */ - isHolding: function () + isHolding() { return (this.state === TWEEN_CONST.HOLD_DELAY); - }, + } /** * Returns `true` if this TweenData has a _current_ state of REPEAT_DELAY, otherwise `false`. @@ -427,10 +425,10 @@ var BaseTweenData = new Class({ * * @return {boolean} `true` if this TweenData has a _current_ state of REPEAT_DELAY, otherwise `false`. */ - isRepeating: function () + isRepeating() { return (this.state === TWEEN_CONST.REPEAT_DELAY); - }, + } /** * Returns `true` if this TweenData has a _current_ state of COMPLETE, otherwise `false`. @@ -440,10 +438,10 @@ var BaseTweenData = new Class({ * * @return {boolean} `true` if this TweenData has a _current_ state of COMPLETE, otherwise `false`. */ - isComplete: function () + isComplete() { return (this.state === TWEEN_CONST.COMPLETE); - }, + } /** * Internal method used as part of the playback process that checks if this @@ -456,7 +454,7 @@ var BaseTweenData = new Class({ * * @param {number} diff - Any extra time that needs to be accounted for in the elapsed and progress values. */ - setStateFromEnd: function (diff) + setStateFromEnd(diff) { if (this.yoyo) { @@ -470,7 +468,7 @@ var BaseTweenData = new Class({ { this.setCompleteState(); } - }, + } /** * Internal method used as part of the playback process that checks if this @@ -482,7 +480,7 @@ var BaseTweenData = new Class({ * * @param {number} diff - Any extra time that needs to be accounted for in the elapsed and progress values. */ - setStateFromStart: function (diff) + setStateFromStart(diff) { if (this.repeatCounter > 0) { @@ -492,7 +490,7 @@ var BaseTweenData = new Class({ { this.setCompleteState(); } - }, + } /** * Internal method that resets this Tween Data entirely, including the progress and elapsed values. @@ -502,7 +500,7 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#reset * @since 3.60.0 */ - reset: function () + reset() { var tween = this.tween; var totalTargets = tween.totalTargets; @@ -565,7 +563,7 @@ var BaseTweenData = new Class({ this.setDelayState(); } - }, + } /** * Internal method that handles repeating or yoyo'ing this TweenData. @@ -581,7 +579,7 @@ var BaseTweenData = new Class({ * @param {boolean} setStart - Set the TweenData start values? * @param {boolean} isYoyo - Is this call a Yoyo check? */ - onRepeat: function (diff, setStart, isYoyo) + onRepeat(diff, setStart, isYoyo) { var tween = this.tween; var totalTargets = tween.totalTargets; @@ -648,7 +646,7 @@ var BaseTweenData = new Class({ this.dispatchEvent(Events.TWEEN_REPEAT, 'onRepeat'); } - }, + } /** * Immediately destroys this TweenData, nulling of all its references. @@ -656,13 +654,13 @@ var BaseTweenData = new Class({ * @method Phaser.Tweens.BaseTweenData#destroy * @since 3.60.0 */ - destroy: function () + destroy() { this.tween = null; this.getDelay = null; this.setCompleteState(); } -}); +}; module.exports = BaseTweenData; diff --git a/src/tweens/tween/Tween.js b/src/tweens/tween/Tween.js index 908f36249d..0df34fb0d0 100644 --- a/src/tweens/tween/Tween.js +++ b/src/tweens/tween/Tween.js @@ -31,15 +31,11 @@ var TweenFrameData = require('./TweenFrameData'); * @param {Phaser.Tweens.TweenManager} parent - A reference to the Tween Manager that owns this Tween. * @param {object[]} targets - An array of targets to be tweened. This array should not be manipulated outside of this Tween. */ -var Tween = new Class({ +var Tween = class extends BaseTween { - Extends: BaseTween, - - initialize: - - function Tween (parent, targets) + constructor(parent, targets) { - BaseTween.call(this, parent); + super(parent); /** * An array of references to the target/s this Tween is operating on. @@ -164,7 +160,7 @@ var Tween = new Class({ * @since 3.88.0 */ this.isNumberTween = false; - }, + } /** * Adds a new TweenData to this Tween. Typically, this method is called @@ -193,14 +189,14 @@ var Tween = new Class({ * * @return {Phaser.Tweens.TweenData} The TweenData instance that was added. */ - add: function (targetIndex, key, getEnd, getStart, getActive, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY, interpolation, interpolationData) + add(targetIndex, key, getEnd, getStart, getActive, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY, interpolation, interpolationData) { var tweenData = new TweenData(this, targetIndex, key, getEnd, getStart, getActive, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY, interpolation, interpolationData); this.totalData = this.data.push(tweenData); return tweenData; - }, + } /** * Adds a new TweenFrameData to this Tween. Typically, this method is called @@ -223,14 +219,14 @@ var Tween = new Class({ * * @return {Phaser.Tweens.TweenFrameData} The TweenFrameData instance that was added. */ - addFrame: function (targetIndex, texture, frame, delay, duration, hold, repeat, repeatDelay, flipX, flipY) + addFrame(targetIndex, texture, frame, delay, duration, hold, repeat, repeatDelay, flipX, flipY) { var tweenData = new TweenFrameData(this, targetIndex, texture, frame, delay, duration, hold, repeat, repeatDelay, flipX, flipY); this.totalData = this.data.push(tweenData); return tweenData; - }, + } /** * Returns the current value of the specified Tween Data. @@ -244,7 +240,7 @@ var Tween = new Class({ * * @return {number} The value of the requested Tween Data, or `null` if this Tween has been destroyed. */ - getValue: function (index) + getValue(index) { if (index === undefined) { index = 0; } @@ -256,7 +252,7 @@ var Tween = new Class({ } return value; - }, + } /** * See if this Tween is currently acting upon the given target. @@ -268,10 +264,10 @@ var Tween = new Class({ * * @return {boolean} `true` if the given target is a target of this Tween, otherwise `false`. */ - hasTarget: function (target) + hasTarget(target) { return (this.targets && this.targets.indexOf(target) !== -1); - }, + } /** * Updates the 'end' value of the given property across all matching targets, as long @@ -295,7 +291,7 @@ var Tween = new Class({ * * @return {this} This Tween instance. */ - updateTo: function (key, value, startToCurrent) + updateTo(key, value, startToCurrent) { if (startToCurrent === undefined) { startToCurrent = false; } @@ -318,7 +314,7 @@ var Tween = new Class({ } return this; - }, + } /** * Restarts the Tween from the beginning. @@ -332,7 +328,7 @@ var Tween = new Class({ * * @return {this} This Tween instance. */ - restart: function () + restart() { switch (this.state) { @@ -360,7 +356,7 @@ var Tween = new Class({ this.hasStarted = false; return this; - }, + } /** * Internal method that advances to the next state of the Tween during playback. @@ -372,7 +368,7 @@ var Tween = new Class({ * * @return {boolean} `true` if this Tween has completed, otherwise `false`. */ - nextState: function () + nextState() { if (this.loopCounter > 0) { @@ -409,7 +405,7 @@ var Tween = new Class({ } return false; - }, + } /** * Internal method that handles this tween completing and starting @@ -418,13 +414,13 @@ var Tween = new Class({ * @method Phaser.Tweens.Tween#onCompleteHandler * @since 3.60.0 */ - onCompleteHandler: function () + onCompleteHandler() { this.progress = 1; this.totalProgress = 1; BaseTween.prototype.onCompleteHandler.call(this); - }, + } /** * Starts a Tween playing. @@ -442,7 +438,7 @@ var Tween = new Class({ * * @return {this} This Tween instance. */ - play: function () + play() { if (this.isDestroyed()) { @@ -461,7 +457,7 @@ var Tween = new Class({ this.setActiveState(); return this; - }, + } /** * Seeks to a specific point in the Tween. @@ -497,7 +493,7 @@ var Tween = new Class({ * * @return {this} This Tween instance. */ - seek: function (amount, delta, emit) + seek(amount, delta, emit) { if (amount === undefined) { amount = 0; } if (delta === undefined) { delta = 16.6; } @@ -548,7 +544,7 @@ var Tween = new Class({ this.isSeeking = false; return this; - }, + } /** * Initialises all of the Tween Data and Tween values. @@ -560,7 +556,7 @@ var Tween = new Class({ * * @param {boolean} [isSeeking=false] - Is the Tween Data being reset as part of a seek? */ - initTweenData: function (isSeeking) + initTweenData(isSeeking) { if (isSeeking === undefined) { isSeeking = false; } @@ -591,7 +587,7 @@ var Tween = new Class({ { this.totalDuration = duration + completeDelay; } - }, + } /** * Resets this Tween ready for another play-through. @@ -609,7 +605,7 @@ var Tween = new Class({ * * @return {this} This Tween instance. */ - reset: function (skipInit) + reset(skipInit) { if (skipInit === undefined) { skipInit = false; } @@ -635,7 +631,7 @@ var Tween = new Class({ } return this; - }, + } /** * Internal method that advances the Tween based on the time values. @@ -650,7 +646,7 @@ var Tween = new Class({ * * @return {boolean} Returns `true` if this Tween has finished and should be removed from the Tween Manager, otherwise returns `false`. */ - update: function (delta) + update(delta) { if (this.isPendingRemove() || this.isDestroyed()) { @@ -736,7 +732,7 @@ var Tween = new Class({ } return remove; - }, + } /** * Moves this Tween forward by the given amount of milliseconds. @@ -754,12 +750,12 @@ var Tween = new Class({ * * @return {this} This Tween instance. */ - forward: function (ms) + forward(ms) { this.update(ms); return this; - }, + } /** * Moves this Tween backward by the given amount of milliseconds. @@ -777,12 +773,12 @@ var Tween = new Class({ * * @return {this} This Tween instance. */ - rewind: function (ms) + rewind(ms) { this.update(-ms); return this; - }, + } /** * Internal method that will emit a Tween based Event and invoke the given callback. @@ -793,7 +789,7 @@ var Tween = new Class({ * @param {Phaser.Types.Tweens.Event} event - The Event to be dispatched. * @param {Phaser.Types.Tweens.TweenCallbackTypes} [callback] - The name of the callback to be invoked. Can be `null` or `undefined` to skip invocation. */ - dispatchEvent: function (event, callback) + dispatchEvent(event, callback) { if (!this.isSeeking) { @@ -811,7 +807,7 @@ var Tween = new Class({ handler.func.apply(this.callbackScope, [ this, this.targets ].concat(handler.params)); } } - }, + } /** * Handles the destroy process of this Tween, clearing out the @@ -821,14 +817,14 @@ var Tween = new Class({ * @method Phaser.Tweens.Tween#destroy * @since 3.60.0 */ - destroy: function () + destroy() { BaseTween.prototype.destroy.call(this); this.targets = null; } -}); +}; /** * Creates a new Tween object. diff --git a/src/tweens/tween/TweenChain.js b/src/tweens/tween/TweenChain.js index df12aa858f..5da35699ac 100644 --- a/src/tweens/tween/TweenChain.js +++ b/src/tweens/tween/TweenChain.js @@ -34,15 +34,11 @@ var TWEEN_CONST = require('./const'); * * @param {(Phaser.Tweens.TweenManager|Phaser.Tweens.TweenChain)} parent - A reference to the Tween Manager, or TweenChain, that owns this TweenChain. */ -var TweenChain = new Class({ +var TweenChain = class extends BaseTween { - Extends: BaseTween, - - initialize: - - function TweenChain (parent) + constructor(parent) { - BaseTween.call(this, parent); + super(parent); /** * A reference to the Tween that this TweenChain is currently playing. @@ -61,7 +57,7 @@ var TweenChain = new Class({ * @since 3.60.0 */ this.currentIndex = 0; - }, + } /** * Prepares this TweenChain for playback. @@ -74,7 +70,7 @@ var TweenChain = new Class({ * * @return {this} This TweenChain instance. */ - init: function () + init() { this.loopCounter = (this.loop === -1) ? TWEEN_CONST.MAX : this.loop; @@ -90,7 +86,7 @@ var TweenChain = new Class({ } return this; - }, + } /** * Create a sequence of Tweens, chained to one-another, and add them to this Tween Manager. @@ -111,7 +107,7 @@ var TweenChain = new Class({ * * @return {this} This TweenChain instance. */ - add: function (tweens) + add(tweens) { var newTweens = this.parent.create(tweens); @@ -134,7 +130,7 @@ var TweenChain = new Class({ this.totalData = data.length; return this; - }, + } /** * Removes the given Tween from this Tween Chain. @@ -152,7 +148,7 @@ var TweenChain = new Class({ * * @return {this} This Tween Chain instance. */ - remove: function (tween) + remove(tween) { // Remove it immediately ArrayRemove(this.data, tween); @@ -167,7 +163,7 @@ var TweenChain = new Class({ this.totalData = this.data.length; return this; - }, + } /** * See if any of the tweens in this Tween Chain is currently acting upon the given target. @@ -179,7 +175,7 @@ var TweenChain = new Class({ * * @return {boolean} `true` if the given target is a target of this TweenChain, otherwise `false`. */ - hasTarget: function (target) + hasTarget(target) { var data = this.data; @@ -192,7 +188,7 @@ var TweenChain = new Class({ } return false; - }, + } /** * Restarts the TweenChain from the beginning. @@ -206,7 +202,7 @@ var TweenChain = new Class({ * * @return {this} This TweenChain instance. */ - restart: function () + restart() { if (this.isDestroyed()) { @@ -225,7 +221,7 @@ var TweenChain = new Class({ this.paused = false; return this.init(); - }, + } /** * Resets the given Tween. @@ -239,14 +235,14 @@ var TweenChain = new Class({ * * @return {this} This TweenChain instance. */ - reset: function (tween) + reset(tween) { tween.seek(); tween.setActiveState(); return this; - }, + } /** * Re-initialises the given Tween and sets it to the Active state. @@ -259,14 +255,14 @@ var TweenChain = new Class({ * * @return {this} This TweenChain instance. */ - makeActive: function (tween) + makeActive(tween) { tween.reset(); tween.setActiveState(); return this; - }, + } /** * Internal method that advances to the next state of the TweenChain playback. @@ -278,7 +274,7 @@ var TweenChain = new Class({ * * @return {boolean} `true` if this TweenChain has completed, otherwise `false`. */ - nextState: function () + nextState() { if (this.loopCounter > 0) { @@ -313,7 +309,7 @@ var TweenChain = new Class({ } return false; - }, + } /** * Starts this TweenChain playing. @@ -330,7 +326,7 @@ var TweenChain = new Class({ * * @return {this} This TweenChain instance. */ - play: function () + play() { if (this.isDestroyed()) { @@ -356,7 +352,7 @@ var TweenChain = new Class({ } return this; - }, + } /** * Internal method that resets all of the Tweens and the current index pointer. @@ -364,7 +360,7 @@ var TweenChain = new Class({ * @method Phaser.Tweens.TweenChain#resetTweens * @since 3.60.0 */ - resetTweens: function () + resetTweens() { var data = this.data; var total = this.totalData; @@ -375,7 +371,7 @@ var TweenChain = new Class({ } this.setCurrentTween(0); - }, + } /** * Internal method that advances the TweenChain based on the time values. @@ -390,7 +386,7 @@ var TweenChain = new Class({ * * @return {boolean} Returns `true` if this TweenChain has finished and should be removed from the Tween Manager, otherwise returns `false`. */ - update: function (delta) + update(delta) { if (this.isPendingRemove() || this.isDestroyed()) { @@ -463,7 +459,7 @@ var TweenChain = new Class({ } return remove; - }, + } /** * Immediately advances to the next Tween in the chain. @@ -476,7 +472,7 @@ var TweenChain = new Class({ * * @return {boolean} `true` if there are no more Tweens in the chain, otherwise `false`. */ - nextTween: function () + nextTween() { this.currentIndex++; @@ -490,7 +486,7 @@ var TweenChain = new Class({ } return false; - }, + } /** * Sets the current active Tween to the given index, based on its @@ -501,14 +497,14 @@ var TweenChain = new Class({ * * @param {number} index - The index of the Tween to be made current. */ - setCurrentTween: function (index) + setCurrentTween(index) { this.currentIndex = index; this.currentTween = this.data[index]; this.currentTween.setActiveState(); - }, + } /** * Internal method that will emit a TweenChain based Event and invoke the given callback. @@ -519,7 +515,7 @@ var TweenChain = new Class({ * @param {Phaser.Types.Tweens.Event} event - The Event to be dispatched. * @param {Phaser.Types.Tweens.TweenCallbackTypes} [callback] - The name of the callback to be invoked. Can be `null` or `undefined` to skip invocation. */ - dispatchEvent: function (event, callback) + dispatchEvent(event, callback) { this.emit(event, this); @@ -529,7 +525,7 @@ var TweenChain = new Class({ { handler.func.apply(this.callbackScope, [ this ].concat(handler.params)); } - }, + } /** * Immediately destroys this TweenChain, nulling of all its references. @@ -537,14 +533,14 @@ var TweenChain = new Class({ * @method Phaser.Tweens.TweenChain#destroy * @since 3.60.0 */ - destroy: function () + destroy() { BaseTween.prototype.destroy.call(this); this.currentTween = null; } -}); +}; /** * Creates a new TweenChain object and adds it to the Tween Manager. diff --git a/src/tweens/tween/TweenData.js b/src/tweens/tween/TweenData.js index c73c9fc163..c45b3aed1c 100644 --- a/src/tweens/tween/TweenData.js +++ b/src/tweens/tween/TweenData.js @@ -47,15 +47,11 @@ var Events = require('../events'); * @param {?function} interpolation - The interpolation function to be used for arrays of data. Defaults to 'null'. * @param {?number[]} interpolationData - The array of interpolation data to be set. Defaults to 'null'. */ -var TweenData = new Class({ +var TweenData = class extends BaseTweenData { - Extends: BaseTweenData, - - initialize: - - function TweenData (tween, targetIndex, key, getEnd, getStart, getActive, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY, interpolation, interpolationData) + constructor(tween, targetIndex, key, getEnd, getStart, getActive, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY, interpolation, interpolationData) { - BaseTweenData.call(this, tween, targetIndex, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY); + super(tween, targetIndex, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY); /** * The property of the target to be tweened. @@ -168,7 +164,7 @@ var TweenData = new Class({ * @since 3.60.0 */ this.interpolationData = interpolationData; - }, + } /** * Internal method that resets this Tween Data entirely, including the progress and elapsed values. @@ -180,7 +176,7 @@ var TweenData = new Class({ * * @param {boolean} [isSeeking=false] - Is the Tween Data being reset as part of a Tween seek? */ - reset: function (isSeeking) + reset(isSeeking) { BaseTweenData.prototype.reset.call(this); @@ -201,7 +197,7 @@ var TweenData = new Class({ { target[key] = this.getActiveValue(target, key, 0); } - }, + } /** * Internal method that advances this TweenData based on the delta value given. @@ -215,7 +211,7 @@ var TweenData = new Class({ * * @return {boolean} `true` if this TweenData is still playing, or `false` if it has finished entirely. */ - update: function (delta) + update(delta) { var tween = this.tween; var totalTargets = tween.totalTargets; @@ -361,7 +357,7 @@ var TweenData = new Class({ // Return TRUE if this TweenData still playing, otherwise FALSE return !this.isComplete(); - }, + } /** * Internal method that will emit a TweenData based Event on the @@ -373,7 +369,7 @@ var TweenData = new Class({ * @param {Phaser.Types.Tweens.Event} event - The Event to be dispatched. * @param {Phaser.Types.Tweens.TweenCallbackTypes} [callback] - The name of the callback to be invoked. Can be `null` or `undefined` to skip invocation. */ - dispatchEvent: function (event, callback) + dispatchEvent(event, callback) { var tween = this.tween; @@ -394,7 +390,7 @@ var TweenData = new Class({ handler.func.apply(tween.callbackScope, [ tween, target, key, current, previous ].concat(handler.params)); } } - }, + } /** * Immediately destroys this TweenData, nulling of all its references. @@ -402,7 +398,7 @@ var TweenData = new Class({ * @method Phaser.Tweens.TweenData#destroy * @since 3.60.0 */ - destroy: function () + destroy() { BaseTweenData.prototype.destroy.call(this); @@ -412,6 +408,6 @@ var TweenData = new Class({ this.ease = null; } -}); +}; module.exports = TweenData; diff --git a/src/tweens/tween/TweenFrameData.js b/src/tweens/tween/TweenFrameData.js index 4fc681c830..67b06f18be 100644 --- a/src/tweens/tween/TweenFrameData.js +++ b/src/tweens/tween/TweenFrameData.js @@ -41,15 +41,11 @@ var Events = require('../events'); * @param {boolean} flipX - Should toggleFlipX be called when yoyo or repeat happens? * @param {boolean} flipY - Should toggleFlipY be called when yoyo or repeat happens? */ -var TweenFrameData = new Class({ +var TweenFrameData = class extends BaseTweenData { - Extends: BaseTweenData, - - initialize: - - function TweenFrameData (tween, targetIndex, texture, frame, delay, duration, hold, repeat, repeatDelay, flipX, flipY) + constructor(tween, targetIndex, texture, frame, delay, duration, hold, repeat, repeatDelay, flipX, flipY) { - BaseTweenData.call(this, tween, targetIndex, delay, duration, false, hold, repeat, repeatDelay, flipX, flipY); + super(tween, targetIndex, delay, duration, false, hold, repeat, repeatDelay, flipX, flipY); /** * The property of the target to be tweened. @@ -108,7 +104,7 @@ var TweenFrameData = new Class({ * @since 3.60.0 */ this.yoyo = (repeat !== 0) ? true : false; - }, + } /** * Internal method that resets this Tween Data entirely, including the progress and elapsed values. @@ -120,7 +116,7 @@ var TweenFrameData = new Class({ * * @param {boolean} [isSeeking=false] - Is the Tween Data being reset as part of a Tween seek? */ - reset: function (isSeeking) + reset(isSeeking) { BaseTweenData.prototype.reset.call(this); @@ -136,7 +132,7 @@ var TweenFrameData = new Class({ { target.setTexture(this.startTexture, this.startFrame); } - }, + } /** * Internal method that advances this TweenData based on the delta value given. @@ -150,7 +146,7 @@ var TweenFrameData = new Class({ * * @return {boolean} `true` if this TweenData is still playing, or `false` if it has finished entirely. */ - update: function (delta) + update(delta) { var tween = this.tween; var targetIndex = this.targetIndex; @@ -263,7 +259,7 @@ var TweenFrameData = new Class({ // Return TRUE if this TweenData still playing, otherwise FALSE return !this.isComplete(); - }, + } /** * Internal method that will emit a TweenData based Event on the @@ -275,7 +271,7 @@ var TweenFrameData = new Class({ * @param {Phaser.Types.Tweens.Event} event - The Event to be dispatched. * @param {Phaser.Types.Tweens.TweenCallbackTypes} [callback] - The name of the callback to be invoked. Can be `null` or `undefined` to skip invocation. */ - dispatchEvent: function (event, callback) + dispatchEvent(event, callback) { var tween = this.tween; @@ -293,7 +289,7 @@ var TweenFrameData = new Class({ handler.func.apply(tween.callbackScope, [ tween, target, key ].concat(handler.params)); } } - }, + } /** * Immediately destroys this TweenData, nulling of all its references. @@ -301,7 +297,7 @@ var TweenFrameData = new Class({ * @method Phaser.Tweens.TweenFrameData#destroy * @since 3.60.0 */ - destroy: function () + destroy() { BaseTweenData.prototype.destroy.call(this); @@ -311,6 +307,6 @@ var TweenFrameData = new Class({ this.endFrame = null; } -}); +}; module.exports = TweenFrameData; From 5f10f0220d69c6f058821a103fb2f3f17c3ac9cb Mon Sep 17 00:00:00 2001 From: redmi Date: Thu, 17 Apr 2025 01:36:07 +0800 Subject: [PATCH 10/11] remove `src/a.php` --- src/a.php | 77 ------------------------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 src/a.php diff --git a/src/a.php b/src/a.php deleted file mode 100644 index dd293dea29..0000000000 --- a/src/a.php +++ /dev/null @@ -1,77 +0,0 @@ - Date: Thu, 17 Apr 2025 11:26:41 +0800 Subject: [PATCH 11/11] defaultConfig move to constructor --- .../renderNodes/BatchHandlerPointLight.js | 84 +++---- .../webgl/renderNodes/BatchHandlerQuad.js | 110 ++++----- .../webgl/renderNodes/BatchHandlerStrip.js | 102 ++++---- .../renderNodes/BatchHandlerTileSprite.js | 108 ++++----- .../webgl/renderNodes/BatchHandlerTriFlat.js | 60 ++--- .../renderNodes/submitter/SubmitterQuad.js | 24 +- .../submitter/SubmitterSpriteGPULayer.js | 224 +++++++++--------- .../renderNodes/submitter/SubmitterTile.js | 24 +- .../submitter/SubmitterTileSprite.js | 24 +- .../submitter/SubmitterTilemapGPULayer.js | 76 +++--- .../transformer/TransformerImage.js | 10 +- .../transformer/TransformerStamp.js | 10 +- .../transformer/TransformerTile.js | 10 +- .../transformer/TransformerTileSprite.js | 10 +- 14 files changed, 438 insertions(+), 438 deletions(-) diff --git a/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js b/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js index 6323947847..8915a72161 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerPointLight.js @@ -25,6 +25,48 @@ var BatchHandlerPointLight = class extends BatchHandler { constructor(manager, config) { + /** + * The default configuration for this handler. + * + * @name Phaser.Renderer.WebGL.RenderNodes.BatchHandlerPointLight#defaultConfig + * @type {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} + * @since 4.0.0 + * @readonly + */ + this.defaultConfig = { + name: 'BatchHandlerPointLight', + verticesPerInstance: 4, + indicesPerInstance: 6, + shaderName: 'POINTLIGHT', + vertexSource: ShaderSourceVS, + fragmentSource: ShaderSourceFS, + vertexBufferLayout: { + usage: 'DYNAMIC_DRAW', + layout: [ + { + name: 'inPosition', + size: 2 + }, + { + name: 'inLightPosition', + size: 2 + }, + { + name: 'inLightRadius', + size: 1 + }, + { + name: 'inLightAttenuation', + size: 1 + }, + { + name: 'inLightColor', + size: 4 + } + ] + } + }; + super(manager, this.defaultConfig, config); /** @@ -40,48 +82,6 @@ var BatchHandlerPointLight = class extends BatchHandler { this._emptyTextures = []; } - /** - * The default configuration for this handler. - * - * @name Phaser.Renderer.WebGL.RenderNodes.BatchHandlerPointLight#defaultConfig - * @type {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} - * @since 4.0.0 - * @readonly - */ - defaultConfig: { - name: 'BatchHandlerPointLight', - verticesPerInstance: 4, - indicesPerInstance: 6, - shaderName: 'POINTLIGHT', - vertexSource: ShaderSourceVS, - fragmentSource: ShaderSourceFS, - vertexBufferLayout: { - usage: 'DYNAMIC_DRAW', - layout: [ - { - name: 'inPosition', - size: 2 - }, - { - name: 'inLightPosition', - size: 2 - }, - { - name: 'inLightRadius', - size: 1 - }, - { - name: 'inLightAttenuation', - size: 1 - }, - { - name: 'inLightColor', - size: 4 - } - ] - } - } - /** * Generate element indices for the instance vertices. * This is called automatically when the node is initialized. diff --git a/src/renderer/webgl/renderNodes/BatchHandlerQuad.js b/src/renderer/webgl/renderNodes/BatchHandlerQuad.js index 8c98a46934..564d37caaa 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerQuad.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerQuad.js @@ -39,6 +39,61 @@ var BatchHandlerQuad = class extends BatchHandler { constructor(manager, config) { + /** + * The default configuration object for this handler. + * This is merged with the `config` object passed in the constructor. + * + * @name Phaser.Renderer.WebGL.RenderNodes.BatchHandlerQuad#defaultConfig + * @type {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} + * @since 4.0.0 + */ + this.defaultConfig = { + name: 'BatchHandlerQuad', + verticesPerInstance: 4, + indicesPerInstance: 6, + shaderName: 'STANDARD', + vertexSource: ShaderSourceVS, + fragmentSource: ShaderSourceFS, + shaderAdditions: [ + MakeGetTexCoordOut(), + MakeGetTexRes(true), + MakeSmoothPixelArt(true), + MakeDefineTexCount(1), + MakeGetTexture(), + MakeApplyTint(), + MakeDefineLights(true), + MakeRotationDatum(true), + MakeOutInverseRotation(true), + MakeGetNormalFromMap(true), + MakeApplyLighting(true) + ], + vertexBufferLayout: { + usage: 'DYNAMIC_DRAW', + layout: [ + { + name: 'inPosition', + size: 2 + }, + { + name: 'inTexCoord', + size: 2 + }, + { + name: 'inTexDatum' + }, + { + name: 'inTintEffect' + }, + { + name: 'inTint', + size: 4, + type: 'UNSIGNED_BYTE', + normalized: true + } + ] + } + }; + // Placed before super call because the constructor needs it. /** * The current render options to which the batch is built. @@ -98,61 +153,6 @@ var BatchHandlerQuad = class extends BatchHandler { this._lightVector = new Vector2(); } - /** - * The default configuration object for this handler. - * This is merged with the `config` object passed in the constructor. - * - * @name Phaser.Renderer.WebGL.RenderNodes.BatchHandlerQuad#defaultConfig - * @type {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} - * @since 4.0.0 - */ - defaultConfig: { - name: 'BatchHandlerQuad', - verticesPerInstance: 4, - indicesPerInstance: 6, - shaderName: 'STANDARD', - vertexSource: ShaderSourceVS, - fragmentSource: ShaderSourceFS, - shaderAdditions: [ - MakeGetTexCoordOut(), - MakeGetTexRes(true), - MakeSmoothPixelArt(true), - MakeDefineTexCount(1), - MakeGetTexture(), - MakeApplyTint(), - MakeDefineLights(true), - MakeRotationDatum(true), - MakeOutInverseRotation(true), - MakeGetNormalFromMap(true), - MakeApplyLighting(true) - ], - vertexBufferLayout: { - usage: 'DYNAMIC_DRAW', - layout: [ - { - name: 'inPosition', - size: 2 - }, - { - name: 'inTexCoord', - size: 2 - }, - { - name: 'inTexDatum' - }, - { - name: 'inTintEffect' - }, - { - name: 'inTint', - size: 4, - type: 'UNSIGNED_BYTE', - normalized: true - } - ] - } - } - /** * Generate element indices for the instance vertices. * This is called automatically when the node is initialized. diff --git a/src/renderer/webgl/renderNodes/BatchHandlerStrip.js b/src/renderer/webgl/renderNodes/BatchHandlerStrip.js index fb344eac36..3717d26838 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerStrip.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerStrip.js @@ -25,7 +25,7 @@ var getTint = Utils.getTintAppendFloatAlpha; * * If a strip is submitted with too many vertices (usually >32,768), * it will throw an error. - * + * * Note that you should call `batchStrip` instead of `batch` to add strips. * * @class BatchHandlerStrip @@ -40,62 +40,62 @@ var BatchHandlerStrip = class extends BatchHandlerQuad { constructor(manager, config) { + /** + * The default configuration object for this handler. + * This is merged with the `config` object passed in the constructor. + * + * @name Phaser.Renderer.WebGL.RenderNodes.BatchHandlerStrip#defaultConfig + * @type {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} + * @since 4.0.0 + */ + this.defaultConfig = { + name: 'BatchHandlerStrip', + verticesPerInstance: 2, + indicesPerInstance: 2, + shaderName: 'STRIP', + vertexSource: ShaderSourceVS, + fragmentSource: ShaderSourceFS, + shaderAdditions: [ + MakeGetTexCoordOut(), + MakeGetTexRes(true), + MakeSmoothPixelArt(true), + MakeDefineTexCount(1), + MakeGetTexture(), + MakeApplyTint() + ], + vertexBufferLayout: { + usage: 'DYNAMIC_DRAW', + layout: [ + { + name: 'inPosition', + size: 2 + }, + { + name: 'inTexCoord', + size: 2 + }, + { + name: 'inTexDatum' + }, + { + name: 'inTintEffect' + }, + { + name: 'inTint', + size: 4, + type: 'UNSIGNED_BYTE', + normalized: true + } + ] + } + }; + super(manager, config); // We do not expect to use extra textures. this.renderOptions.multiTexturing = true; } - /** - * The default configuration object for this handler. - * This is merged with the `config` object passed in the constructor. - * - * @name Phaser.Renderer.WebGL.RenderNodes.BatchHandlerStrip#defaultConfig - * @type {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} - * @since 4.0.0 - */ - defaultConfig: { - name: 'BatchHandlerStrip', - verticesPerInstance: 2, - indicesPerInstance: 2, - shaderName: 'STRIP', - vertexSource: ShaderSourceVS, - fragmentSource: ShaderSourceFS, - shaderAdditions: [ - MakeGetTexCoordOut(), - MakeGetTexRes(true), - MakeSmoothPixelArt(true), - MakeDefineTexCount(1), - MakeGetTexture(), - MakeApplyTint() - ], - vertexBufferLayout: { - usage: 'DYNAMIC_DRAW', - layout: [ - { - name: 'inPosition', - size: 2 - }, - { - name: 'inTexCoord', - size: 2 - }, - { - name: 'inTexDatum' - }, - { - name: 'inTintEffect' - }, - { - name: 'inTint', - size: 4, - type: 'UNSIGNED_BYTE', - normalized: true - } - ] - } - } - /** * Generate element indices for the instance vertices. * This is called automatically when the node is initialized. diff --git a/src/renderer/webgl/renderNodes/BatchHandlerTileSprite.js b/src/renderer/webgl/renderNodes/BatchHandlerTileSprite.js index 92acb7352d..0ea8cd157f 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerTileSprite.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerTileSprite.js @@ -41,61 +41,61 @@ var BatchHandlerTileSprite = class extends BatchHandlerQuad { constructor(manager, config) { - super(manager, config); - } + this.defaultConfig = { + name: 'BatchHandlerTileSprite', + verticesPerInstance: 4, + indicesPerInstance: 6, + shaderName: 'TILESPRITE', + vertexSource: ShaderSourceVS, + fragmentSource: ShaderSourceFS, + shaderAdditions: [ + MakeOutFrame(), + MakeGetTexCoordOut(), + MakeGetTexRes(true), + MakeTexCoordFrameWrap(true), + MakeTexCoordFrameClamp(true), + MakeSmoothPixelArt(true), + MakeDefineTexCount(1), + MakeGetTexture(), + MakeApplyTint(), + MakeDefineLights(true), + MakeRotationDatum(true), + MakeOutInverseRotation(true), + MakeGetNormalFromMap(true), + MakeApplyLighting(true) + ], + vertexBufferLayout: { + usage: 'DYNAMIC_DRAW', + layout: [ + { + name: 'inPosition', + size: 2 + }, + { + name: 'inTexCoord', + size: 2 + }, + { + name: 'inFrame', + size: 4 + }, + { + name: 'inTexDatum' + }, + { + name: 'inTintEffect' + }, + { + name: 'inTint', + size: 4, + type: 'UNSIGNED_BYTE', + normalized: true + } + ] + } + }; - defaultConfig: { - name: 'BatchHandlerTileSprite', - verticesPerInstance: 4, - indicesPerInstance: 6, - shaderName: 'TILESPRITE', - vertexSource: ShaderSourceVS, - fragmentSource: ShaderSourceFS, - shaderAdditions: [ - MakeOutFrame(), - MakeGetTexCoordOut(), - MakeGetTexRes(true), - MakeTexCoordFrameWrap(true), - MakeTexCoordFrameClamp(true), - MakeSmoothPixelArt(true), - MakeDefineTexCount(1), - MakeGetTexture(), - MakeApplyTint(), - MakeDefineLights(true), - MakeRotationDatum(true), - MakeOutInverseRotation(true), - MakeGetNormalFromMap(true), - MakeApplyLighting(true) - ], - vertexBufferLayout: { - usage: 'DYNAMIC_DRAW', - layout: [ - { - name: 'inPosition', - size: 2 - }, - { - name: 'inTexCoord', - size: 2 - }, - { - name: 'inFrame', - size: 4 - }, - { - name: 'inTexDatum' - }, - { - name: 'inTintEffect' - }, - { - name: 'inTint', - size: 4, - type: 'UNSIGNED_BYTE', - normalized: true - } - ] - } + super(manager, config); } updateRenderOptions(renderOptions) diff --git a/src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js b/src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js index 3d4c9ae8e2..96adf8884e 100644 --- a/src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js +++ b/src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js @@ -30,6 +30,36 @@ var BatchHandlerTriFlat = class extends BatchHandler { constructor(manager, config) { + this.defaultConfig = { + name: 'BatchHandlerTriFlat', + verticesPerInstance: 3, + indicesPerInstance: 3, + shaderName: 'FLAT', + vertexSource: ShaderSourceVS, + fragmentSource: ShaderSourceFS, + shaderAdditions: [ + MakeDefineLights(true), + MakeFlatNormal(true), + MakeApplyLighting(true) + ], + indexBufferDynamic: true, + vertexBufferLayout: { + usage: 'DYNAMIC_DRAW', + layout: [ + { + name: 'inPosition', + size: 2 + }, + { + name: 'inTint', + size: 4, + type: 'UNSIGNED_BYTE', + normalized: true + } + ] + } + }; + super(manager, this.defaultConfig, config); /** @@ -97,36 +127,6 @@ var BatchHandlerTriFlat = class extends BatchHandler { this._renderOptionsChanged = false; } - defaultConfig: { - name: 'BatchHandlerTriFlat', - verticesPerInstance: 3, - indicesPerInstance: 3, - shaderName: 'FLAT', - vertexSource: ShaderSourceVS, - fragmentSource: ShaderSourceFS, - shaderAdditions: [ - MakeDefineLights(true), - MakeFlatNormal(true), - MakeApplyLighting(true) - ], - indexBufferDynamic: true, - vertexBufferLayout: { - usage: 'DYNAMIC_DRAW', - layout: [ - { - name: 'inPosition', - size: 2 - }, - { - name: 'inTint', - size: 4, - type: 'UNSIGNED_BYTE', - normalized: true - } - ] - } - } - /** * Generate element indices for the instance vertices. * This is called automatically when the node is initialized. diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js b/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js index 19bc2c9c54..a1ad00c807 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterQuad.js @@ -35,6 +35,18 @@ var SubmitterQuad = class extends RenderNode { constructor(manager, config) { + /** + * The default configuration for this RenderNode. + * + * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterQuad#defaultConfig + * @type {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} + */ + this.defaultConfig = { + name: 'SubmitterQuad', + role: 'Submitter', + batchHandler: 'BatchHandler' + }; + config = Merge(config || {}, this.defaultConfig); super(config.name, manager); @@ -82,18 +94,6 @@ var SubmitterQuad = class extends RenderNode { }; } - /** - * The default configuration for this RenderNode. - * - * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterQuad#defaultConfig - * @type {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} - */ - defaultConfig: { - name: 'SubmitterQuad', - role: 'Submitter', - batchHandler: 'BatchHandler' - } - /** * Submit data for rendering. * diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterSpriteGPULayer.js b/src/renderer/webgl/renderNodes/submitter/SubmitterSpriteGPULayer.js index efd37e5e45..b00b76d78f 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterSpriteGPULayer.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterSpriteGPULayer.js @@ -50,6 +50,118 @@ var SubmitterSpriteGPULayer = class extends RenderNode { constructor(manager, config, gameObject) { + /** + * Default configuration of this RenderNode. + * + * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterSpriteGPULayer#defaultConfig + * @type {object} + * @since 4.0.0 + * @readonly + * @property {string} name - The name of this RenderNode. + * @property {string} vertexSource - The vertex shader source. + * @property {string} fragmentSource - The fragment shader source. + */ + this.defaultConfig = { + name: 'SubmitterSpriteGPULayer', + count: 0, + shaderName: 'SpriteGPULayer', + vertexSource: ShaderSourceVS, + fragmentSource: ShaderSourceFS, + shaderAdditions: [ + MakeGetTexCoordOut(), + MakeGetTexRes(), + MakeSmoothPixelArt(true), + MakeDefineTexCount(1), + MakeGetTexture(), + MakeApplyTint(), + MakeDefineLights(true), + MakeOutInverseRotation(true), + MakeGetNormalFromMap(true), + MakeApplyLighting(true) + ], + instanceBufferLayout: { + usage: 'STATIC_DRAW', + instanceDivisor: 1, + layout: [ + { + name: 'inPositionX', + size: 4 + }, + { + name: 'inPositionY', + size: 4 + }, + { + name: 'inRotation', + size: 4 + }, + { + name: 'inScaleX', + size: 4 + }, + { + name: 'inScaleY', + size: 4 + }, + { + name: 'inAlpha', + size: 4 + }, + { + name: 'inFrame', + size: 4 + }, + { + name: 'inTintBlend', + size: 4 + }, + { + name: 'inTintBL', + size: 4, + type: 'UNSIGNED_BYTE', + normalized: true + }, + { + name: 'inTintTL', + size: 4, + type: 'UNSIGNED_BYTE', + normalized: true + }, + { + name: 'inTintBR', + size: 4, + type: 'UNSIGNED_BYTE', + normalized: true + }, + { + name: 'inTintTR', + size: 4, + type: 'UNSIGNED_BYTE', + normalized: true + }, + { + name: 'inOriginAndTintFillAndCreationTime', + size: 4 + }, + { + name: 'inScrollFactor', + size: 2 + } + ] + }, + vertexBufferLayout: { + usage: 'STATIC_DRAW', + count: 4, + layout: [ + { + // The vertex index, 0-3. + name: 'inVertex', + type: 'UNSIGNED_BYTE' + } + ] + } + }; + var renderer = manager.renderer; var finalConfig = Merge(config || {}, this.defaultConfig); @@ -173,118 +285,6 @@ var SubmitterSpriteGPULayer = class extends RenderNode { this._lightVector = new Vector2(); } - /** - * Default configuration of this RenderNode. - * - * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterSpriteGPULayer#defaultConfig - * @type {object} - * @since 4.0.0 - * @readonly - * @property {string} name - The name of this RenderNode. - * @property {string} vertexSource - The vertex shader source. - * @property {string} fragmentSource - The fragment shader source. - */ - defaultConfig: { - name: 'SubmitterSpriteGPULayer', - count: 0, - shaderName: 'SpriteGPULayer', - vertexSource: ShaderSourceVS, - fragmentSource: ShaderSourceFS, - shaderAdditions: [ - MakeGetTexCoordOut(), - MakeGetTexRes(), - MakeSmoothPixelArt(true), - MakeDefineTexCount(1), - MakeGetTexture(), - MakeApplyTint(), - MakeDefineLights(true), - MakeOutInverseRotation(true), - MakeGetNormalFromMap(true), - MakeApplyLighting(true) - ], - instanceBufferLayout: { - usage: 'STATIC_DRAW', - instanceDivisor: 1, - layout: [ - { - name: 'inPositionX', - size: 4 - }, - { - name: 'inPositionY', - size: 4 - }, - { - name: 'inRotation', - size: 4 - }, - { - name: 'inScaleX', - size: 4 - }, - { - name: 'inScaleY', - size: 4 - }, - { - name: 'inAlpha', - size: 4 - }, - { - name: 'inFrame', - size: 4 - }, - { - name: 'inTintBlend', - size: 4 - }, - { - name: 'inTintBL', - size: 4, - type: 'UNSIGNED_BYTE', - normalized: true - }, - { - name: 'inTintTL', - size: 4, - type: 'UNSIGNED_BYTE', - normalized: true - }, - { - name: 'inTintBR', - size: 4, - type: 'UNSIGNED_BYTE', - normalized: true - }, - { - name: 'inTintTR', - size: 4, - type: 'UNSIGNED_BYTE', - normalized: true - }, - { - name: 'inOriginAndTintFillAndCreationTime', - size: 4 - }, - { - name: 'inScrollFactor', - size: 2 - } - ] - }, - vertexBufferLayout: { - usage: 'STATIC_DRAW', - count: 4, - layout: [ - { - // The vertex index, 0-3. - name: 'inVertex', - type: 'UNSIGNED_BYTE' - } - ] - } - } - /** * Fill out the configuration object with default values where needed. * diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterTile.js b/src/renderer/webgl/renderNodes/submitter/SubmitterTile.js index d989d95160..07502c53cf 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterTile.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterTile.js @@ -23,23 +23,23 @@ var SubmitterTile = class extends SubmitterQuad { constructor(manager, config) { + /** + * The default configuration for this RenderNode. + * + * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterTile#defaultConfig + * @type {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} + */ + this.defaultConfig = { + name: 'SubmitterTile', + role: 'Submitter', + batchHandler: 'BatchHandler' + }; + super(manager, config); this._renderOptions.clampFrame = true; } - /** - * The default configuration for this RenderNode. - * - * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterTile#defaultConfig - * @type {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} - */ - defaultConfig: { - name: 'SubmitterTile', - role: 'Submitter', - batchHandler: 'BatchHandler' - } - /** * Submit data for rendering. * diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterTileSprite.js b/src/renderer/webgl/renderNodes/submitter/SubmitterTileSprite.js index bc39eb5f6f..8ff5d833c5 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterTileSprite.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterTileSprite.js @@ -34,23 +34,23 @@ var SubmitterTileSprite = class extends SubmitterQuad { constructor(manager, config) { + /** + * The default configuration for this RenderNode. + * + * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterTileSprite#defaultConfig + * @type {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} + */ + this.defaultConfig = { + name: 'SubmitterTileSprite', + role: 'Submitter', + batchHandler: 'BatchHandler' + }; + super(manager, config); this._renderOptions.wrapFrame = true; } - /** - * The default configuration for this RenderNode. - * - * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterTileSprite#defaultConfig - * @type {Phaser.Types.Renderer.WebGL.RenderNodes.SubmitterQuadConfig} - */ - defaultConfig: { - name: 'SubmitterTileSprite', - role: 'Submitter', - batchHandler: 'BatchHandler' - } - /** * Submit data for rendering. * diff --git a/src/renderer/webgl/renderNodes/submitter/SubmitterTilemapGPULayer.js b/src/renderer/webgl/renderNodes/submitter/SubmitterTilemapGPULayer.js index a215b8dcfc..526bae8840 100644 --- a/src/renderer/webgl/renderNodes/submitter/SubmitterTilemapGPULayer.js +++ b/src/renderer/webgl/renderNodes/submitter/SubmitterTilemapGPULayer.js @@ -39,6 +39,44 @@ var SubmitterTilemapGPULayer = class extends RenderNode { constructor(manager, config) { + /** + * Default configuration of this RenderNode. + * + * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterTilemapGPULayer#defaultConfig + * @type {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} + * @since 4.0.0 + * @readonly + * @property {string} name - The name of this RenderNode. + * @property {string} vertexSource - The vertex shader source. + * @property {string} fragmentSource - The fragment shader source. + */ + this.defaultConfig = { + name: 'SubmitterTilemapGPULayer', + shaderName: 'TilemapGPULayer', + vertexSource: ShaderSourceVS, + fragmentSource: ShaderSourceFS, + shaderAdditions: [ + MakeSmoothPixelArt(true), + MakeSampleNormal(true), + MakeDefineLights(true), + MakeApplyLighting(true) + ], + vertexBufferLayout: { + usage: 'DYNAMIC_DRAW', + count: 4, + layout: [ + { + name: 'inPosition', + size: 2 + }, + { + name: 'inTexCoord', + size: 2 + } + ] + } + }; + var renderer = manager.renderer; var finalConfig = Merge(config || {}, this.defaultConfig); @@ -159,44 +197,6 @@ var SubmitterTilemapGPULayer = class extends RenderNode { this._quad = new Float32Array(8); } - /** - * Default configuration of this RenderNode. - * - * @name Phaser.Renderer.WebGL.RenderNodes.SubmitterTilemapGPULayer#defaultConfig - * @type {Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig} - * @since 4.0.0 - * @readonly - * @property {string} name - The name of this RenderNode. - * @property {string} vertexSource - The vertex shader source. - * @property {string} fragmentSource - The fragment shader source. - */ - defaultConfig: { - name: 'SubmitterTilemapGPULayer', - shaderName: 'TilemapGPULayer', - vertexSource: ShaderSourceVS, - fragmentSource: ShaderSourceFS, - shaderAdditions: [ - MakeSmoothPixelArt(true), - MakeSampleNormal(true), - MakeDefineLights(true), - MakeApplyLighting(true) - ], - vertexBufferLayout: { - usage: 'DYNAMIC_DRAW', - count: 4, - layout: [ - { - name: 'inPosition', - size: 2 - }, - { - name: 'inTexCoord', - size: 2 - } - ] - } - } - /** * Fill out the configuration object with default values where needed. * diff --git a/src/renderer/webgl/renderNodes/transformer/TransformerImage.js b/src/renderer/webgl/renderNodes/transformer/TransformerImage.js index f8e33ec199..ee45fa1d18 100644 --- a/src/renderer/webgl/renderNodes/transformer/TransformerImage.js +++ b/src/renderer/webgl/renderNodes/transformer/TransformerImage.js @@ -25,6 +25,11 @@ var TransformerImage = class extends RenderNode { constructor(manager, config) { + this.defaultConfig = { + name: 'TransformerImage', + role: 'Transformer' + }; + config = Merge(config || {}, this.defaultConfig); super(config.name, manager); @@ -68,11 +73,6 @@ var TransformerImage = class extends RenderNode { this._calcMatrix = new TransformMatrix(); } - defaultConfig: { - name: 'TransformerImage', - role: 'Transformer' - } - /** * Stores the transform data for rendering. * diff --git a/src/renderer/webgl/renderNodes/transformer/TransformerStamp.js b/src/renderer/webgl/renderNodes/transformer/TransformerStamp.js index 19cc25a7a3..5212b1d1a8 100644 --- a/src/renderer/webgl/renderNodes/transformer/TransformerStamp.js +++ b/src/renderer/webgl/renderNodes/transformer/TransformerStamp.js @@ -28,6 +28,11 @@ var TransformerStamp = class extends RenderNode { constructor(manager, config) { + this.defaultConfig = { + name: 'TransformerStamp', + role: 'Transformer' + }; + config = Merge(config || {}, this.defaultConfig); super(config.name, manager); @@ -61,11 +66,6 @@ var TransformerStamp = class extends RenderNode { this.onlyTranslate = false; } - defaultConfig: { - name: 'TransformerStamp', - role: 'Transformer' - } - /** * Stores the transform data for rendering. * diff --git a/src/renderer/webgl/renderNodes/transformer/TransformerTile.js b/src/renderer/webgl/renderNodes/transformer/TransformerTile.js index a1fc5dd3bf..39cb61df39 100644 --- a/src/renderer/webgl/renderNodes/transformer/TransformerTile.js +++ b/src/renderer/webgl/renderNodes/transformer/TransformerTile.js @@ -23,12 +23,12 @@ var TransformerTile = class extends TransformerImage { constructor(manager, config) { - super(manager, config); - } + this.defaultConfig = { + name: 'TransformerTile', + role: 'Transformer' + }; - defaultConfig: { - name: 'TransformerTile', - role: 'Transformer' + super(manager, config); } /** diff --git a/src/renderer/webgl/renderNodes/transformer/TransformerTileSprite.js b/src/renderer/webgl/renderNodes/transformer/TransformerTileSprite.js index a1a70fa004..f0103326ff 100644 --- a/src/renderer/webgl/renderNodes/transformer/TransformerTileSprite.js +++ b/src/renderer/webgl/renderNodes/transformer/TransformerTileSprite.js @@ -23,12 +23,12 @@ var TransformerTileSprite = class extends TransformerImage { constructor(manager, config) { - super(manager, config); - } + this.defaultConfig = { + name: 'TransformerTileSprite', + role: 'Transformer' + }; - defaultConfig: { - name: 'TransformerTileSprite', - role: 'Transformer' + super(manager, config); } /**